< prev index next >

test/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaField.java

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
  27  * @library ../../../../../
  28  * @modules jdk.vm.ci/jdk.vm.ci.meta
  29  *          jdk.vm.ci/jdk.vm.ci.runtime
  30  *          java.base/jdk.internal.misc
  31  * @build jdk.vm.ci.runtime.test.TestResolvedJavaField
  32  * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI jdk.vm.ci.runtime.test.TestResolvedJavaField
  33  */
  34 
  35 package jdk.vm.ci.runtime.test;
  36 
  37 import static org.junit.Assert.assertArrayEquals;
  38 import static org.junit.Assert.assertEquals;
  39 import static org.junit.Assert.assertFalse;
  40 import static org.junit.Assert.assertNull;
  41 import static org.junit.Assert.assertTrue;
  42 
  43 import java.lang.annotation.Annotation;
  44 import java.lang.reflect.Field;
  45 import java.lang.reflect.Method;
  46 import java.util.Arrays;
  47 import java.util.HashSet;
  48 import java.util.List;
  49 import java.util.Map;
  50 import java.util.Set;
  51 
  52 import jdk.vm.ci.meta.JavaConstant;

  53 import jdk.vm.ci.meta.LocationIdentity;
  54 import jdk.vm.ci.meta.ResolvedJavaField;
  55 import jdk.vm.ci.meta.ResolvedJavaMethod;
  56 
  57 import org.junit.Test;
  58 
  59 /**
  60  * Tests for {@link ResolvedJavaField}.
  61  */
  62 public class TestResolvedJavaField extends FieldUniverse {
  63 
  64     public TestResolvedJavaField() {
  65     }
  66 
  67     @Test
  68     public void getModifiersTest() {
  69         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {
  70             int expected = e.getKey().getModifiers();
  71             int actual = e.getValue().getModifiers();
  72             assertEquals(expected, actual);
  73         }
  74     }
  75 
  76     @Test
  77     public void isSyntheticTest() {
  78         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {


  91         }
  92     }
  93 
  94     @Test
  95     public void getAnnotationTest() {
  96         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {
  97             for (Annotation expected : e.getKey().getAnnotations()) {
  98                 if (expected != null) {
  99                     Annotation actual = e.getValue().getAnnotation(expected.annotationType());
 100                     assertEquals(expected, actual);
 101                 }
 102             }
 103         }
 104     }
 105 
 106     @Test
 107     public void getLocationIdentityTest() {
 108         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {
 109             LocationIdentity identity = e.getValue().getLocationIdentity();
 110             assertTrue(identity != null);
 111         }
 112     }
 113 
 114     static class ReadConstantValueTestConstants {
 115         String stringField = "field";
 116         final String constantStringField = "constantField";
 117 
 118         static final Object CONST1 = new ReadConstantValueTestConstants();
 119         static final Object CONST2 = null;
 120         static final Object CONST3 = new String();
 121     }
 122 
 123     @Test
 124     public void readConstantValueTest() throws NoSuchFieldException {
 125         ResolvedJavaField field = metaAccess.lookupJavaField(ReadConstantValueTestConstants.class.getDeclaredField("stringField"));
 126         List<ConstantValue> receiverConstants = readConstants(ReadConstantValueTestConstants.class);
 127         for (ConstantValue receiver : receiverConstants) {
 128             JavaConstant value = constantReflection.readConstantFieldValue(field, receiver.value);
 129             assertNull(value);
 130         }
 131 
 132         ResolvedJavaField constField = metaAccess.lookupJavaField(ReadConstantValueTestConstants.class.getDeclaredField("constantStringField"));
 133         for (ConstantValue receiver : receiverConstants) {
 134             JavaConstant value = constantReflection.readConstantFieldValue(constField, receiver.value);
 135             if (value != null) {
 136                 Object expected = "constantField";
 137                 String actual = ((ReadConstantValueTestConstants) receiver.boxed).constantStringField;
 138                 assertTrue(actual + " != " + expected, actual == expected);
 139             }
 140         }
 141     }
 142 
 143     private Method findTestMethod(Method apiMethod) {
 144         String testName = apiMethod.getName() + "Test";
 145         for (Method m : getClass().getDeclaredMethods()) {
 146             if (m.getName().equals(testName) && m.getAnnotation(Test.class) != null) {
 147                 return m;
 148             }
 149         }
 150         return null;
 151     }
 152 
 153     // @formatter:off
 154     private static final String[] untestedApiMethods = {
 155         "getDeclaringClass",
 156         "isInternal",
 157         "isFinal"
 158     };
 159     // @formatter:on


  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
  27  * @library ../../../../../
  28  * @modules jdk.vm.ci/jdk.vm.ci.meta
  29  *          jdk.vm.ci/jdk.vm.ci.runtime
  30  *          java.base/jdk.internal.misc
  31  * @build jdk.vm.ci.runtime.test.TestResolvedJavaField
  32  * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI jdk.vm.ci.runtime.test.TestResolvedJavaField
  33  */
  34 
  35 package jdk.vm.ci.runtime.test;
  36 
  37 import static org.junit.Assert.assertArrayEquals;
  38 import static org.junit.Assert.assertEquals;
  39 import static org.junit.Assert.assertFalse;

  40 import static org.junit.Assert.assertTrue;
  41 
  42 import java.lang.annotation.Annotation;
  43 import java.lang.reflect.Field;
  44 import java.lang.reflect.Method;
  45 import java.util.Arrays;
  46 import java.util.HashSet;

  47 import java.util.Map;
  48 import java.util.Set;
  49 
  50 import org.junit.Test;
  51 
  52 import jdk.vm.ci.meta.LocationIdentity;
  53 import jdk.vm.ci.meta.ResolvedJavaField;
  54 import jdk.vm.ci.meta.ResolvedJavaMethod;
  55 


  56 /**
  57  * Tests for {@link ResolvedJavaField}.
  58  */
  59 public class TestResolvedJavaField extends FieldUniverse {
  60 
  61     public TestResolvedJavaField() {
  62     }
  63 
  64     @Test
  65     public void getModifiersTest() {
  66         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {
  67             int expected = e.getKey().getModifiers();
  68             int actual = e.getValue().getModifiers();
  69             assertEquals(expected, actual);
  70         }
  71     }
  72 
  73     @Test
  74     public void isSyntheticTest() {
  75         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {


  88         }
  89     }
  90 
  91     @Test
  92     public void getAnnotationTest() {
  93         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {
  94             for (Annotation expected : e.getKey().getAnnotations()) {
  95                 if (expected != null) {
  96                     Annotation actual = e.getValue().getAnnotation(expected.annotationType());
  97                     assertEquals(expected, actual);
  98                 }
  99             }
 100         }
 101     }
 102 
 103     @Test
 104     public void getLocationIdentityTest() {
 105         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {
 106             LocationIdentity identity = e.getValue().getLocationIdentity();
 107             assertTrue(identity != null);





























 108         }
 109     }
 110 
 111     private Method findTestMethod(Method apiMethod) {
 112         String testName = apiMethod.getName() + "Test";
 113         for (Method m : getClass().getDeclaredMethods()) {
 114             if (m.getName().equals(testName) && m.getAnnotation(Test.class) != null) {
 115                 return m;
 116             }
 117         }
 118         return null;
 119     }
 120 
 121     // @formatter:off
 122     private static final String[] untestedApiMethods = {
 123         "getDeclaringClass",
 124         "isInternal",
 125         "isFinal"
 126     };
 127     // @formatter:on
< prev index next >