< prev index next >

test/compiler/jvmci/jdk.vm.ci.hotspot.test/src/jdk/vm/ci/hotspot/test/HotSpotConstantReflectionProviderTest.java

Print this page




  83     }
  84 
  85     @Test(dataProvider = "readArrayElementDataProvider", dataProviderClass = ReadArrayElementDataProvider.class)
  86     public void testReadArrayElement(JavaConstant array, int index, Object expected) {
  87         Assert.assertEquals(CONSTANT_REFLECTION_PROVIDER.readArrayElement(array, index), expected,
  88                         "Unexpected result:");
  89     }
  90 
  91     @Test(dataProvider = "readFieldValueDataProvider", dataProviderClass = ReadFieldValueDataProvider.class)
  92     public void testReadFieldValue(ResolvedJavaField field, JavaConstant receiver, JavaConstant expected) {
  93         JavaConstant actual = CONSTANT_REFLECTION_PROVIDER.readFieldValue(field, receiver);
  94         Assert.assertEquals(actual == null ? "null" : actual.toString(),
  95                         expected == null ? "null" : expected.toString(), "Unexpected result:");
  96     }
  97 
  98     @Test(dataProvider = "readFieldValueNegativeDataProvider", dataProviderClass = ReadFieldValueDataProvider.class, expectedExceptions = {NullPointerException.class})
  99     public void testNegativeReadFieldValue(ResolvedJavaField field, JavaConstant receiver) {
 100         CONSTANT_REFLECTION_PROVIDER.readFieldValue(field, receiver);
 101     }
 102 
 103     @Test(dataProvider = "readStableFieldValueDataProvider", dataProviderClass = ReadStableFieldValueDataProvider.class)
 104     public void testReadStableFieldValue(ResolvedJavaField field, JavaConstant receiver, boolean isDefStab,
 105                     JavaConstant expected) {
 106         Assert.assertEquals(
 107                         CONSTANT_REFLECTION_PROVIDER.readStableFieldValue(field, receiver, isDefStab),
 108                         expected,
 109                         "Unexpected result:");
 110     }
 111 
 112     @Test(dataProvider = "readStableFieldValueArrayDataProvider", dataProviderClass = ReadStableFieldValueDataProvider.class)
 113     public void testReadStableFieldValueForArray(ResolvedJavaField field, JavaConstant receiver, boolean isDefStab,
 114                     int arrayDim, JavaConstant expected) {
 115         JavaConstant result = CONSTANT_REFLECTION_PROVIDER.readStableFieldValue(field, receiver,
 116                         isDefStab);
 117         boolean resultDefStab = false;
 118         int resultStableDim = -1;
 119         try {
 120             Class<?> hotSpotObjectConstantImplClass = Class.forName(
 121                             "jdk.vm.ci.hotspot.HotSpotObjectConstantImpl");
 122             Method getStableDimensionMethod = hotSpotObjectConstantImplClass.getDeclaredMethod(
 123                             "getStableDimension");
 124             Method isDefaultStableMethod = hotSpotObjectConstantImplClass.getDeclaredMethod(
 125                             "isDefaultStable");
 126             getStableDimensionMethod.setAccessible(true);
 127             isDefaultStableMethod.setAccessible(true);
 128             resultDefStab = (boolean) isDefaultStableMethod.invoke(result);
 129             resultStableDim = (int) getStableDimensionMethod.invoke(result);
 130         } catch (ReflectiveOperationException e) {
 131             throw new Error("Unexpected error: " + e, e);
 132         }
 133         Assert.assertEquals(resultDefStab, isDefStab,
 134                         "Wrong default stable value for " + result.toString());
 135         Assert.assertEquals(resultStableDim, arrayDim,
 136                         "Wrong array dimension for " + result.toString());
 137         Assert.assertEquals(result.toString(), expected.toString(), "Unexpected result:");
 138     }
 139 
 140     @Test(dataProvider = "readStableFieldValueNegativeDataProvider", dataProviderClass = ReadStableFieldValueDataProvider.class, expectedExceptions = {NullPointerException.class})
 141     public void testNegativeReadStableFieldValue(ResolvedJavaField field, JavaConstant receiver, boolean isDefStab) {
 142         CONSTANT_REFLECTION_PROVIDER.readStableFieldValue(field, receiver, isDefStab);
 143     }
 144 
 145     @Test(dataProvider = "readConstantFieldValueDataProvider", dataProviderClass = ReadConstantFieldValueDataProvider.class)
 146     public void testReadConstantFieldValue(ResolvedJavaField field, JavaConstant receiver, JavaConstant expected,
 147                     String testInfo) {
 148         String msg = String.format("Unexpected result for %s. Field is stable = %s.", testInfo,
 149                         ((HotSpotResolvedJavaField) field).isStable());
 150         Assert.assertEquals(CONSTANT_REFLECTION_PROVIDER.readConstantFieldValue(field, receiver),
 151                         expected, msg);
 152     }
 153 
 154     @Test(dataProvider = "readConstantFieldValueNegativeDataProvider", dataProviderClass = ReadConstantFieldValueDataProvider.class, expectedExceptions = {NullPointerException.class})
 155     public void testNegativeReadConstantFieldValue(ResolvedJavaField field, JavaConstant receiver) {
 156         CONSTANT_REFLECTION_PROVIDER.readConstantFieldValue(field, receiver);
 157     }
 158 
 159     @Test(dataProvider = "readConstantArrayElementDataProvider", dataProviderClass = ReadConstantArrayElementDataProvider.class)
 160     public void testReadConstantArrayElement(JavaConstant array, int index, JavaConstant expected, String testInfo) {
 161         JavaConstant actual = CONSTANT_REFLECTION_PROVIDER.readConstantArrayElement(array, index);
 162         Assert.assertEquals(actual == null ? "null" : actual.toString(),
 163                         expected == null ? "null" : expected.toString(),
 164                         String.format("Unexpected result while testing %s:", testInfo));
 165     }
 166 
 167     @Test(dataProvider = "readConstantArrayElementForOffsetDataProvider", dataProviderClass = ReadConstantArrayElementDataProvider.class)
 168     public void testReadConstantArrayElementForOffset(JavaConstant array, long offset, JavaConstant expected,
 169                     String testInfo) {
 170         JavaConstant actual = CONSTANT_REFLECTION_PROVIDER.readConstantArrayElementForOffset(array,
 171                         offset);
 172         Assert.assertEquals(actual == null ? "null" : actual.toString(),
 173                         expected == null ? "null" : expected.toString(),
 174                         String.format("Unexpected result while testing %s:", testInfo));
 175     }
 176 
 177     @Test(dataProvider = "asJavaTypeDataProvider", dataProviderClass = AsJavaTypeDataProvider.class)
 178     public void testAsJavaType(JavaConstant constant, String expected) {
 179         ResolvedJavaType actual = CONSTANT_REFLECTION_PROVIDER.asJavaType(constant);
 180         Assert.assertEquals(actual == null ? "null" : actual.toJavaName(),
 181                         expected == null ? "null" : expected,
 182                         "Unexpected result, wrong type returned:");
 183     }
 184 
 185     @Test(dataProvider = "boxPrimitiveDataProvider", dataProviderClass = BoxPrimitiveDataProvider.class)
 186     public void testBoxPrimitive(JavaConstant constant, JavaConstant expected) {
 187         JavaConstant actual = CONSTANT_REFLECTION_PROVIDER.boxPrimitive(constant);
 188         Assert.assertEquals(actual, expected, "Unexpected result:");
 189     }
 190 
 191     @Test(dataProvider = "unboxPrimitiveDataProvider", dataProviderClass = UnboxPrimitiveDataProvider.class)
 192     public void testUnboxPrimitive(JavaConstant constant, JavaConstant expected) {
 193         JavaConstant actual = CONSTANT_REFLECTION_PROVIDER.unboxPrimitive(constant);
 194         Assert.assertEquals(actual, expected, "Unexpected result:");
 195     }
 196 


  83     }
  84 
  85     @Test(dataProvider = "readArrayElementDataProvider", dataProviderClass = ReadArrayElementDataProvider.class)
  86     public void testReadArrayElement(JavaConstant array, int index, Object expected) {
  87         Assert.assertEquals(CONSTANT_REFLECTION_PROVIDER.readArrayElement(array, index), expected,
  88                         "Unexpected result:");
  89     }
  90 
  91     @Test(dataProvider = "readFieldValueDataProvider", dataProviderClass = ReadFieldValueDataProvider.class)
  92     public void testReadFieldValue(ResolvedJavaField field, JavaConstant receiver, JavaConstant expected) {
  93         JavaConstant actual = CONSTANT_REFLECTION_PROVIDER.readFieldValue(field, receiver);
  94         Assert.assertEquals(actual == null ? "null" : actual.toString(),
  95                         expected == null ? "null" : expected.toString(), "Unexpected result:");
  96     }
  97 
  98     @Test(dataProvider = "readFieldValueNegativeDataProvider", dataProviderClass = ReadFieldValueDataProvider.class, expectedExceptions = {NullPointerException.class})
  99     public void testNegativeReadFieldValue(ResolvedJavaField field, JavaConstant receiver) {
 100         CONSTANT_REFLECTION_PROVIDER.readFieldValue(field, receiver);
 101     }
 102 










































































 103     @Test(dataProvider = "asJavaTypeDataProvider", dataProviderClass = AsJavaTypeDataProvider.class)
 104     public void testAsJavaType(JavaConstant constant, String expected) {
 105         ResolvedJavaType actual = CONSTANT_REFLECTION_PROVIDER.asJavaType(constant);
 106         Assert.assertEquals(actual == null ? "null" : actual.toJavaName(),
 107                         expected == null ? "null" : expected,
 108                         "Unexpected result, wrong type returned:");
 109     }
 110 
 111     @Test(dataProvider = "boxPrimitiveDataProvider", dataProviderClass = BoxPrimitiveDataProvider.class)
 112     public void testBoxPrimitive(JavaConstant constant, JavaConstant expected) {
 113         JavaConstant actual = CONSTANT_REFLECTION_PROVIDER.boxPrimitive(constant);
 114         Assert.assertEquals(actual, expected, "Unexpected result:");
 115     }
 116 
 117     @Test(dataProvider = "unboxPrimitiveDataProvider", dataProviderClass = UnboxPrimitiveDataProvider.class)
 118     public void testUnboxPrimitive(JavaConstant constant, JavaConstant expected) {
 119         JavaConstant actual = CONSTANT_REFLECTION_PROVIDER.unboxPrimitive(constant);
 120         Assert.assertEquals(actual, expected, "Unexpected result:");
 121     }
 122 
< prev index next >