< prev index next >

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

Print this page




  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         }


  83     }
  84 
  85     @Test
  86     public void getAnnotationsTest() {
  87         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {
  88             Annotation[] expected = e.getKey().getAnnotations();
  89             Annotation[] actual = e.getValue().getAnnotations();
  90             assertArrayEquals(expected, actual);
  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         }




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


  82     }
  83 
  84     @Test
  85     public void getAnnotationsTest() {
  86         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {
  87             Annotation[] expected = e.getKey().getAnnotations();
  88             Annotation[] actual = e.getValue().getAnnotations();
  89             assertArrayEquals(expected, actual);
  90         }
  91     }
  92 
  93     @Test
  94     public void getAnnotationTest() {
  95         for (Map.Entry<Field, ResolvedJavaField> e : fields.entrySet()) {
  96             for (Annotation expected : e.getKey().getAnnotations()) {
  97                 if (expected != null) {
  98                     Annotation actual = e.getValue().getAnnotation(expected.annotationType());
  99                     assertEquals(expected, actual);
 100                 }
 101             }








 102         }
 103     }
 104 
 105     static class ReadConstantValueTestConstants {
 106         String stringField = "field";
 107         final String constantStringField = "constantField";
 108 
 109         static final Object CONST1 = new ReadConstantValueTestConstants();
 110         static final Object CONST2 = null;
 111         static final Object CONST3 = new String();
 112     }
 113 
 114     @Test
 115     public void readConstantValueTest() throws NoSuchFieldException {
 116         ResolvedJavaField field = metaAccess.lookupJavaField(ReadConstantValueTestConstants.class.getDeclaredField("stringField"));
 117         List<ConstantValue> receiverConstants = readConstants(ReadConstantValueTestConstants.class);
 118         for (ConstantValue receiver : receiverConstants) {
 119             JavaConstant value = constantReflection.readConstantFieldValue(field, receiver.value);
 120             assertNull(value);
 121         }


< prev index next >