< prev index next >

test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java

Print this page

  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 


 24 /*
 25  * @test
 26  * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessString
 27  */
 28 
 29 import org.testng.annotations.BeforeClass;
 30 import org.testng.annotations.DataProvider;
 31 import org.testng.annotations.Test;
 32 
 33 import java.lang.invoke.MethodHandles;
 34 import java.lang.invoke.VarHandle;
 35 import java.util.ArrayList;
 36 import java.util.Arrays;
 37 import java.util.List;
 38 
 39 import static org.testng.Assert.*;
 40 
 41 public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {


 42     static final String static_final_v = "foo";
 43 
 44     static String static_v;
 45 
 46     final String final_v = "foo";
 47 
 48     String v;
 49 
 50     VarHandle vhFinalField;
 51 
 52     VarHandle vhField;
 53 
 54     VarHandle vhStaticField;
 55 
 56     VarHandle vhStaticFinalField;
 57 
 58     VarHandle vhArray;
 59 

 60     @BeforeClass
 61     public void setup() throws Exception {
 62         vhFinalField = MethodHandles.lookup().findVarHandle(
 63                 VarHandleTestMethodHandleAccessString.class, "final_v", String.class);
 64 
 65         vhField = MethodHandles.lookup().findVarHandle(
 66                 VarHandleTestMethodHandleAccessString.class, "v", String.class);
 67 
 68         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
 69             VarHandleTestMethodHandleAccessString.class, "static_final_v", String.class);
 70 
 71         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
 72             VarHandleTestMethodHandleAccessString.class, "static_v", String.class);
 73 
 74         vhArray = MethodHandles.arrayElementVarHandle(String[].class);

 75     }
 76 
 77 
 78     @DataProvider
 79     public Object[][] accessTestCaseProvider() throws Exception {
 80         List<AccessTestCase<?>> cases = new ArrayList<>();
 81 
 82         for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
 83             cases.add(new MethodHandleAccessTestCase("Instance field",
 84                                                      vhField, f, hs -> testInstanceField(this, hs)));
 85             cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
 86                                                      vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
 87                                                      false));
 88 
 89             cases.add(new MethodHandleAccessTestCase("Static field",
 90                                                      vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticField));
 91             cases.add(new MethodHandleAccessTestCase("Static field unsupported",
 92                                                      vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticFieldUnsupported,
 93                                                      false));
 94 

  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 // -- This file was mechanically generated: Do not edit! -- //
 25 
 26 /*
 27  * @test
 28  * @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessString
 29  */
 30 
 31 import org.testng.annotations.BeforeClass;
 32 import org.testng.annotations.DataProvider;
 33 import org.testng.annotations.Test;
 34 
 35 import java.lang.invoke.MethodHandles;
 36 import java.lang.invoke.VarHandle;
 37 import java.util.ArrayList;
 38 import java.util.Arrays;
 39 import java.util.List;
 40 
 41 import static org.testng.Assert.*;
 42 
 43 public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
 44     static final Class<?> type = String.class;
 45 
 46     static final String static_final_v = "foo";
 47 
 48     static String static_v;
 49 
 50     final String final_v = "foo";
 51 
 52     String v;
 53 
 54     VarHandle vhFinalField;
 55 
 56     VarHandle vhField;
 57 
 58     VarHandle vhStaticField;
 59 
 60     VarHandle vhStaticFinalField;
 61 
 62     VarHandle vhArray;
 63 
 64 
 65     @BeforeClass
 66     public void setup() throws Exception {
 67         vhFinalField = MethodHandles.lookup().findVarHandle(
 68                 VarHandleTestMethodHandleAccessString.class, "final_v", type);
 69 
 70         vhField = MethodHandles.lookup().findVarHandle(
 71                 VarHandleTestMethodHandleAccessString.class, "v", type);
 72 
 73         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
 74             VarHandleTestMethodHandleAccessString.class, "static_final_v", type);
 75 
 76         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
 77             VarHandleTestMethodHandleAccessString.class, "static_v", type);
 78 
 79         vhArray = MethodHandles.arrayElementVarHandle(String[].class);
 80 
 81     }
 82 
 83 
 84     @DataProvider
 85     public Object[][] accessTestCaseProvider() throws Exception {
 86         List<AccessTestCase<?>> cases = new ArrayList<>();
 87 
 88         for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
 89             cases.add(new MethodHandleAccessTestCase("Instance field",
 90                                                      vhField, f, hs -> testInstanceField(this, hs)));
 91             cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
 92                                                      vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
 93                                                      false));
 94 
 95             cases.add(new MethodHandleAccessTestCase("Static field",
 96                                                      vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticField));
 97             cases.add(new MethodHandleAccessTestCase("Static field unsupported",
 98                                                      vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticFieldUnsupported,
 99                                                      false));
100 
< prev index next >