From 8bd4a949673d40cae0b79e75564182f32da39237 Mon Sep 17 00:00:00 2001 From: binaryfz Date: Sat, 12 Dec 2020 10:08:25 +0800 Subject: [PATCH 1/2] add testsuite --- .../ReflectingGetConstructor1.java | 59 +++ .../ReflectingGetConstructor2.java | 64 +++ .../ReflectingGetConstructors.java | 81 ++++ .../ReflectingGetDeclaredConstructor1.java | 61 +++ .../ReflectingGetDeclaredConstructor2.java | 52 ++ .../ReflectingGetDeclaredConstructors.java | 51 ++ .../ReflectionAsSubclass1.java | 51 ++ .../ReflectionAsSubclass2.java | 38 ++ .../ReflectionAsSubclass3.java | 61 +++ .../ReflectionCast1.java | 38 ++ .../ReflectionCast2.java | 40 ++ .../ReflectionCast3.java | 40 ++ .../ReflectionCast4.java | 35 ++ .../ReflectionDesiredAssertionStatus.java | 31 ++ .../ReflectionForName1.java | 32 ++ .../ReflectionForName4.java | 40 ++ .../ReflectionForName5.java | 62 +++ .../ReflectionGetAnnotation1.java | 58 +++ .../ReflectionGetAnnotation2.java | 74 +++ .../ReflectionGetAnnotation3.java | 86 ++++ .../ReflectionGetAnnotation4.java | 75 +++ .../ReflectionGetAnnotation5.java | 79 +++ .../ReflectionGetAnnotation6.java | 78 +++ .../ReflectionGetAnnotation7.java | 78 +++ .../ReflectionGetAnnotationsByType1.java | 86 ++++ .../ReflectionGetAnnotationsByType2.java | 82 ++++ .../ReflectionGetAnnotationsByType3.java | 80 ++++ .../ReflectionGetCanonicalName.java | 41 ++ .../ReflectionGetComponentType.java | 33 ++ .../ReflectionGetDeclaredAnnotations1.java | 80 ++++ .../ReflectionGetDeclaredAnnotations2.java | 80 ++++ ...flectionGetDeclaredAnnotationsByType1.java | 85 ++++ ...AnnotationsByTypeNullPointerException.java | 77 +++ .../ReflectionGetDeclaredClasses.java | 65 +++ .../ReflectionGetDeclaredField1.java | 58 +++ ...nGetDeclaredFieldNullPointerException.java | 68 +++ .../ReflectionGetDeclaredFields1.java | 61 +++ .../ReflectionGetDeclaredFields.java | 56 +++ .../ReflectionGetDeclaredMethod1.java | 80 ++++ .../ReflectionGetDeclaredMethod2.java | 87 ++++ .../ReflectionGetDeclaredMethod3.java | 52 ++ .../ReflectionGetDeclaredMethods1.java | 84 ++++ .../ReflectionGetDeclaredMethods2.java | 49 ++ .../ReflectionGetDeclaringClass.java | 80 ++++ .../ReflectionGetEnclosingClass1.java | 49 ++ .../ReflectionGetEnclosingClass2.java | 52 ++ .../ReflectionGetEnumConstants.java | 102 ++++ .../ReflectionGetField1.java | 58 +++ .../ReflectionGetField2.java | 68 +++ .../ReflectionGetFields.java | 64 +++ .../ReflectionGetMethod1.java | 85 ++++ .../ReflectionGetMethod2.java | 91 ++++ .../ReflectionGetSigners.java | 38 ++ .../ReflectionGetSimpleName.java | 38 ++ .../ReflectionGetTypeParameters.java | 43 ++ .../ReflectionIsArray.java | 47 ++ .../ReflectionIsAssignableFrom1.java | 51 ++ ...nIsAssignableFromNullPointerException.java | 40 ++ .../ReflectionIsLocalClass.java | 59 +++ .../ReflectionIsMemberClass.java | 59 +++ .../ReflectionIsPrimitive.java | 44 ++ .../ReflectionIsSynthetic.java | 46 ++ .../ReflectionNewInstance1.java | 50 ++ ...iationExceptionIllegalAccessException.java | 63 +++ .../ReflectionToGenericString.java | 46 ++ .../ReflectionToString.java | 45 ++ .../RTConstructorGetAnnotation1.java | 87 ++++ .../RTConstructorGetAnnotation2.java | 102 ++++ .../RTConstructorGetDeclaredAnnotations1.java | 101 ++++ .../RTConstructorGetDeclaredAnnotations2.java | 90 ++++ .../RTConstructorGetExceptionTypes.java | 53 +++ .../RTConstructorGetTypeParameters.java | 61 +++ .../RTConstructorToGenericString1.java | 52 ++ .../RTFieldGet1.java | 76 +++ .../RTFieldGet2.java | 94 ++++ .../RTFieldGet3.java | 56 +++ .../RTFieldGetAnnotation1.java | 70 +++ .../RTFieldGetDeclaredAnnotations1.java | 90 ++++ .../RTFieldGetDeclaredAnnotations2.java | 79 +++ .../RTFieldGetDeclaringClass.java | 51 ++ .../RTFieldGetModifiers.java | 55 +++ .../RTFieldGetName.java | 48 ++ .../RTFieldGetType.java | 52 ++ .../RTFieldSet1.java | 90 ++++ .../RTFieldSet2.java | 102 ++++ .../RTFieldSet3.java | 56 +++ .../RTFieldSet4.java | 54 +++ .../RTFieldToGenericString.java | 51 ++ .../RTFieldToString.java | 51 ++ .../RTMethodGetAnnotation1.java | 87 ++++ .../RTMethodGetAnnotation2.java | 73 +++ .../RTMethodGetDeclaredAnnotations1.java | 101 ++++ .../RTMethodGetDeclaredAnnotations2.java | 85 ++++ .../RTMethodGetDefaultValue1.java | 93 ++++ .../RTMethodGetParameterCount.java | 55 +++ .../RTMethodGetTypeParameters.java | 56 +++ .../RTMethodIsDefault.java | 63 +++ .../RTMethodToGenericString.java | 47 ++ .../RTModifierParameterModifiers.java | 31 ++ .../RTParameterGetAnnotation1.java | 91 ++++ .../RTParameterGetAnnotation2.java | 101 ++++ .../RTParameterGetAnnotations1.java | 78 +++ .../RTParameterGetAnnotationsByType1.java | 96 ++++ .../RTParameterGetAnnotationsByType2.java | 102 ++++ .../RTParameterGetDeclaredAnnotation1.java | 94 ++++ .../RTParameterGetDeclaredAnnotations1.java | 79 +++ .../RTParameterGetDeclaredAnnotations2.java | 103 ++++ ...arameterGetDeclaredAnnotationsByType1.java | 98 ++++ .../RTProxyGetProxyClass1.java | 144 ++++++ .../ClassGetDeclaredAnnotationNPE.java | 58 +++ .../ClassIsAssignableFromNPE.java | 48 ++ .../ClassGetAnnotationsByType.java | 78 +++ .../ClassGetCanonicalName.java | 78 +++ .../ClassGetEnclosingClass.java | 77 +++ .../ClassGetEnumConstants.java | 77 +++ .../ClassGetSimpleName.java | 78 +++ .../ClassGetTypeParameters.java | 80 ++++ .../ClassToGenericString.java | 79 +++ .../ConstructorGetAnnotation.java | 81 ++++ .../ConstructorGetDeclaredAnnotations.java | 80 ++++ .../ConstructorGetExceptionTypes.java | 81 ++++ .../ConstructorGetTypeParameters.java | 82 ++++ .../ConstructorToGenericString.java | 82 ++++ .../FieldGetAnnotation.java | 72 +++ .../FieldGetAnnotationsByType.java | 80 ++++ .../FieldGetDeclaredAnnotations.java | 80 ++++ .../FieldIsAnnotationPresent.java | 80 ++++ .../FieldToGenericString.java | 80 ++++ .../MethodGetAnnotation.java | 70 +++ .../MethodGetDeclaredAnnotations.java | 79 +++ .../MethodGetDefaultValue.java | 63 +++ .../MethodGetParameterCount.java | 79 +++ .../MethodGetTypeParameters.java | 79 +++ .../MethodIsDefault.java | 78 +++ .../MethodToGenericString.java | 78 +++ .../ParameterGetAnnotation.java | 79 +++ .../ParameterGetAnnotations.java | 84 ++++ .../ParameterGetAnnotationsByType.java | 85 ++++ .../ParameterGetDeclaredAnnotation.java | 85 ++++ .../ParameterGetDeclaredAnnotations.java | 84 ++++ ...ParameterGetDeclaredAnnotationsByType.java | 85 ++++ .../ReflectionAnnotationGetClass.java | 65 +++ .../ClassInitClassNewInstance.java | 154 ++++++ .../ClassInitConstructorNewInstance.java | 107 +++++ .../ClassInitFieldGetBooleanStatic.java | 78 +++ .../ClassInitFieldGetByteStatic.java | 78 +++ .../ClassInitFieldGetCharStatic.java | 78 +++ .../ClassInitFieldGetDoubleStatic.java | 78 +++ .../ClassInitFieldGetFloatStatic.java | 77 +++ .../ClassInitFieldGetIntStatic.java | 77 +++ .../ClassInitFieldGetLongStatic.java | 78 +++ .../ClassInitFieldGetShortStatic.java | 77 +++ .../ClassInitFieldGetStatic.java | 81 ++++ .../ClassInitFieldOtherMethod.java | 98 ++++ .../ClassInitFieldSetBooleanStatic.java | 91 ++++ .../ClassInitFieldSetByteStatic.java | 78 +++ .../ClassInitFieldSetCharStatic.java | 78 +++ .../ClassInitFieldSetDoubleStatic.java | 78 +++ .../ClassInitFieldSetFloatStatic.java | 78 +++ .../ClassInitFieldSetIntStatic.java | 78 +++ .../ClassInitFieldSetLongStatic.java | 78 +++ .../ClassInitFieldSetShortStatic.java | 78 +++ .../ClassInitFieldSetStatic.java | 78 +++ .../ClassInitMethodInvokeStatic.java | 108 +++++ .../ClassInitFieldGetBooleanInterface.java | 64 +++ .../ClassInitFieldGetByteInterface.java | 64 +++ .../ClassInitFieldGetCharInterface.java | 64 +++ .../ClassInitFieldGetDoubleInterface.java | 64 +++ .../ClassInitFieldGetFloatInterface.java | 64 +++ .../ClassInitFieldGetInterface.java | 64 +++ .../ClassInitFieldGetIntInterface.java | 64 +++ .../ClassInitFieldGetLongInterface.java | 64 +++ .../ClassInitFieldGetShortInterface.java | 64 +++ .../ClassInitFieldOtherMethodInterface.java | 76 +++ .../ClassInitFieldSetBooleanInterface.java | 66 +++ .../ClassInitFieldSetByteInterface.java | 66 +++ .../ClassInitFieldSetFloatInterface.java | 66 +++ .../ClassInitFieldSetInterface.java | 66 +++ .../ClassInitFieldSetIntInterface.java | 66 +++ .../ClassInitFieldSetLongInterface.java | 66 +++ .../ClassInitFieldSetShortInterface.java | 66 +++ .../ClassInitMethodInvokeInterface.java | 93 ++++ .../FieldMultiThreadTest.java | 100 ++++ .../MethodTest.java | 450 ++++++++++++++++++ .../MethodMultiThreadTest.java | 105 ++++ .../ConstructorTest.java | 376 +++++++++++++++ .../ConstructorMultiThreadTest.java | 104 ++++ .../MethodHandleReflectCombineTest.java | 104 ++++ .../FieldTest.java | 388 +++++++++++++++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationTypeSetTest.java | 75 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationTypeInterfaceSetTest.java | 75 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationTypeEnumSetTest.java | 75 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationFieldSetTest.java | 76 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationStaticFieldSetTest.java | 76 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationMethodSetTest.java | 78 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationParameterSetTest.java | 78 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationConstructorSetTest.java | 78 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 15 + .../AnnotationAnnotationTypeSetTest.java | 66 +++ .../Run.java | 21 + .../com/huawei/AnnoA.java | 36 ++ .../com/huawei/AnnoB.java | 11 + .../com/huawei/AnnotationPackageSetTest.java | 47 ++ .../com/huawei/package-info.java | 32 ++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationTypeParameterSetTest.java | 78 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationTypeUseSetTest.java | 76 +++ .../AnnoA.java | 17 + .../AnnoB.java | 9 + .../AnnoC.java | 17 + .../AnnoD.java | 17 + .../AnnotationMultiThread.java | 185 +++++++ .../ENUMA.java | 5 + .../ReflectClassNameTest.java | 70 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationNotAscii.java | 75 +++ .../AnnoA.java | 53 +++ .../AnnoB.java | 10 + .../AnnotationRepeatable.java | 87 ++++ .../Test.java | 19 + .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationTypeInnerClassSet.java | 79 +++ .../AnnoA.java | 32 ++ .../AnnoB.java | 9 + .../AnnotationTypeLocalClassSet.java | 77 +++ test/testsuite/ouroboros/testlist | 1 + 248 files changed, 16825 insertions(+) create mode 100755 test/testsuite/ouroboros/compact_test/RT0001-rt-compact-ReflectingetConstructor1/ReflectingGetConstructor1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0002-rt-compact-ReflectingetConstructor2/ReflectingGetConstructor2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0003-rt-compact-ReflectingetConstructors/ReflectingGetConstructors.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0004-rt-compact-ReflectingetDeclaredConstructor1/ReflectingGetDeclaredConstructor1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0005-rt-compact-ReflectingetDeclaredConstructor2/ReflectingGetDeclaredConstructor2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0006-rt-compact-ReflectingetDeclaredConstructors/ReflectingGetDeclaredConstructors.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0007-rt-compact-ReflectionasSubclass1/ReflectionAsSubclass1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0008-rt-compact-ReflectionasSubclass2/ReflectionAsSubclass2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0009-rt-compact-ReflectionasSubclass3/ReflectionAsSubclass3.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0010-rt-compact-Reflectioncast1/ReflectionCast1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0011-rt-compact-Reflectioncast2/ReflectionCast2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0012-rt-compact-Reflectioncast3/ReflectionCast3.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0013-rt-compact-Reflectioncast4/ReflectionCast4.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0014-rt-compact-ReflectiondesiredAssertionStatus/ReflectionDesiredAssertionStatus.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0015-rt-compact-ReflectionforName1/ReflectionForName1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0016-rt-compact-ReflectionforName4/ReflectionForName4.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0017-rt-compact-ReflectionforName5/ReflectionForName5.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0018-rt-compact-ReflectiongetAnnotation1/ReflectionGetAnnotation1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0019-rt-compact-ReflectiongetAnnotation2/ReflectionGetAnnotation2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0020-rt-compact-ReflectiongetAnnotation3/ReflectionGetAnnotation3.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0021-rt-compact-ReflectiongetAnnotation4/ReflectionGetAnnotation4.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0022-rt-compact-ReflectiongetAnnotation5/ReflectionGetAnnotation5.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0023-rt-compact-ReflectiongetAnnotation6/ReflectionGetAnnotation6.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0024-rt-compact-ReflectiongetAnnotation7/ReflectionGetAnnotation7.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0025-rt-compact-ReflectiongetAnnotationsByType1/ReflectionGetAnnotationsByType1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0026-rt-compact-ReflectiongetAnnotationsByType2/ReflectionGetAnnotationsByType2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0027-rt-compact-ReflectiongetAnnotationsByType3/ReflectionGetAnnotationsByType3.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0028-rt-compact-ReflectiongetCanonicalName/ReflectionGetCanonicalName.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0029-rt-compact-ReflectiongetComponentType/ReflectionGetComponentType.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0030-rt-compact-ReflectiongetDeclaredAnnotations1/ReflectionGetDeclaredAnnotations1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0031-rt-compact-ReflectiongetDeclaredAnnotations2/ReflectionGetDeclaredAnnotations2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0032-rt-compact-ReflectiongetDeclaredAnnotationsByType1/ReflectionGetDeclaredAnnotationsByType1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0033-rt-compact-ReflectionGetDeclaredAnnotationsByTypeNullPointerException/ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0034-rt-compact-ReflectiongetDeclaredClasses/ReflectionGetDeclaredClasses.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0035-rt-compact-ReflectiongetDeclaredField1/ReflectionGetDeclaredField1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0036-rt-compact-ReflectionGetDeclaredFieldNullPointerException/ReflectionGetDeclaredFieldNullPointerException.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0037-rt-compact-ReflectiongetDeclaredFields1/ReflectionGetDeclaredFields1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0038-rt-compact-ReflectiongetDeclaredFields2/ReflectionGetDeclaredFields.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0039-rt-compact-ReflectiongetDeclaredMethod1/ReflectionGetDeclaredMethod1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0040-rt-compact-ReflectiongetDeclaredMethod2/ReflectionGetDeclaredMethod2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0041-rt-compact-ReflectiongetDeclaredMethod3/ReflectionGetDeclaredMethod3.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0042-rt-compact-ReflectiongetDeclaredMethods1/ReflectionGetDeclaredMethods1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0043-rt-compact-ReflectiongetDeclaredMethods2/ReflectionGetDeclaredMethods2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0044-rt-compact-ReflectiongetDeclaringClass/ReflectionGetDeclaringClass.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0045-rt-compact-ReflectiongetEnclosingClass1/ReflectionGetEnclosingClass1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0046-rt-compact-ReflectiongetEnclosingClass2/ReflectionGetEnclosingClass2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0047-rt-compact-ReflectiongetEnumConstants/ReflectionGetEnumConstants.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0048-rt-compact-ReflectiongetField1/ReflectionGetField1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0049-rt-compact-ReflectiongetField2/ReflectionGetField2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0050-rt-compact-ReflectiongetFields/ReflectionGetFields.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0051-rt-compact-ReflectiongetMethod1/ReflectionGetMethod1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0052-rt-compact-ReflectiongetMethod2/ReflectionGetMethod2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0053-rt-compact-ReflectiongetSigners/ReflectionGetSigners.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0054-rt-compact-ReflectiongetSimpleName/ReflectionGetSimpleName.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0055-rt-compact-ReflectiongetTypeParameters/ReflectionGetTypeParameters.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0056-rt-compact-ReflectionisArray/ReflectionIsArray.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0057-rt-compact-ReflectionisAssignableFrom1/ReflectionIsAssignableFrom1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0058-rt-compact-ReflectionisAssignableFrom2/ReflectionIsAssignableFromNullPointerException.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0059-rt-compact-ReflectionisLocalClass/ReflectionIsLocalClass.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0060-rt-compact-ReflectionisMemberClass/ReflectionIsMemberClass.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0061-rt-compact-ReflectionisPrimitive/ReflectionIsPrimitive.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0062-rt-compact-ReflectionisSynthetic/ReflectionIsSynthetic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0063-rt-compact-ReflectionnewInstance1/ReflectionNewInstance1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0064-rt-compact-ReflectionnewInstance2/ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0065-rt-compact-ReflectiontoGenericString/ReflectionToGenericString.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0066-rt-compact-ReflectiontoString/ReflectionToString.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0067-rt-compact-RTConstructorgetAnnotation1/RTConstructorGetAnnotation1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0068-rt-compact-RTConstructorgetAnnotation2/RTConstructorGetAnnotation2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0069-rt-compact-RTConstructorgetDeclaredAnnotations1/RTConstructorGetDeclaredAnnotations1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0070-rt-compact-RTConstructorgetDeclaredAnnotations2/RTConstructorGetDeclaredAnnotations2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0071-rt-compact-RTConstructorgetExceptionTypes/RTConstructorGetExceptionTypes.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0072-rt-compact-RTConstructorgetTypeParameters/RTConstructorGetTypeParameters.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0073-rt-compact-RTConstructortoGenericString/RTConstructorToGenericString1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0074-rt-compact-RTFieldget1/RTFieldGet1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0075-rt-compact-RTFieldget2/RTFieldGet2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0076-rt-compact-RTFieldget3/RTFieldGet3.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0077-rt-compact-RTFieldgetAnnotation/RTFieldGetAnnotation1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0078-rt-compact-RTFieldgetDeclaredAnnotations1/RTFieldGetDeclaredAnnotations1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0079-rt-compact-RTFieldgetDeclaredAnnotations2/RTFieldGetDeclaredAnnotations2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0080-rt-compact-RTFieldgetDeclaringClass/RTFieldGetDeclaringClass.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0081-rt-compact-RTFieldgetModifiers/RTFieldGetModifiers.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0082-rt-compact-RTFieldgetName/RTFieldGetName.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0083-rt-compact-RTFieldgetType/RTFieldGetType.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0084-rt-compact-RTFieldset1/RTFieldSet1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0085-rt-compact-RTFieldset2/RTFieldSet2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0086-rt-compact-RTFieldset3/RTFieldSet3.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0087-rt-compact-RTFieldset4/RTFieldSet4.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0088-rt-compact-RTFieldtoGenericString/RTFieldToGenericString.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0089-rt-compact-RTFieldtoString/RTFieldToString.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0090-rt-compact-RTMethodgetAnnotation1/RTMethodGetAnnotation1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0091-rt-compact-RTMethodgetAnnotation2/RTMethodGetAnnotation2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0092-rt-compact-RTMethodgetDeclaredAnnotations1/RTMethodGetDeclaredAnnotations1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0093-rt-compact-RTMethodgetDeclaredAnnotations2/RTMethodGetDeclaredAnnotations2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0094-rt-compact-RTMethodgetDefaultValue1/RTMethodGetDefaultValue1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0095-rt-compact-RTMethodgetParameterCount/RTMethodGetParameterCount.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0096-rt-compact-RTMethodgetTypeParameters/RTMethodGetTypeParameters.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0097-rt-compact-RTMethonisDefault/RTMethodIsDefault.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0098-rt-compact-RTMethontoGenericString/RTMethodToGenericString.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0099-rt-compact-RTModifierparameterModifiers/RTModifierParameterModifiers.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0100-rt-compact-RTParametergetAnnotation1/RTParameterGetAnnotation1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0101-rt-compact-RTParametergetAnnotation2/RTParameterGetAnnotation2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0102-rt-compact-RTParametergetAnnotations1/RTParameterGetAnnotations1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0103-rt-compact-RTParametergetAnnotationsByType1/RTParameterGetAnnotationsByType1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0104-rt-compact-RTParametergetAnnotationsByType2/RTParameterGetAnnotationsByType2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0105-rt-compact-RTParametergetDeclaredAnnotation1/RTParameterGetDeclaredAnnotation1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0106-rt-compact-RTParametergetDeclaredAnnotations1/RTParameterGetDeclaredAnnotations1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0107-rt-compact-RTParametergetDeclaredAnnotations2/RTParameterGetDeclaredAnnotations2.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0108-rt-compact-RTParametergetDeclaredAnnotationsByType1/RTParameterGetDeclaredAnnotationsByType1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0109-rt-compact-RTProxygetProxyClass1/RTProxyGetProxyClass1.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0110-rt-compact-ClassgetDeclaredAnnotationNPE/ClassGetDeclaredAnnotationNPE.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0111-rt-compact-reflectClasssetisAssignableFrom/ClassIsAssignableFromNPE.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0112-rt-compact-ClassGetAnnotationsByType/ClassGetAnnotationsByType.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0113-rt-compact-ClassGetCanonicalName/ClassGetCanonicalName.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0114-rt-compact-ClassGetEnclosingClass/ClassGetEnclosingClass.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0115-rt-compact-ClassGetEnumConstants/ClassGetEnumConstants.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0116-rt-compact-ClassGetSimpleName/ClassGetSimpleName.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0117-rt-compact-ClassGetTypeParameters/ClassGetTypeParameters.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0118-rt-compact-ClassToGenericString/ClassToGenericString.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0119-rt-compact-ConstructorGetAnnotation/ConstructorGetAnnotation.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0120-rt-compact-ConstructorGetDeclaredAnnotations/ConstructorGetDeclaredAnnotations.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0121-rt-compact-ConstructorGetExceptionTypes/ConstructorGetExceptionTypes.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0122-rt-compact-ConstructorGetTypeParameters/ConstructorGetTypeParameters.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0123-rt-compact-ConstructorToGenericString/ConstructorToGenericString.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0124-rt-compact-FieldGetAnnotation/FieldGetAnnotation.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0125-rt-compact-FieldGetAnnotationsByType/FieldGetAnnotationsByType.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0126-rt-compact-FieldGetDeclaredAnnotations/FieldGetDeclaredAnnotations.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0127-rt-compact-FieldIsAnnotationPresent/FieldIsAnnotationPresent.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0128-rt-compact-FieldToGenericString/FieldToGenericString.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0129-rt-compact-MethodGetAnnotation/MethodGetAnnotation.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0130-rt-compact-MethodGetDeclaredAnnotations/MethodGetDeclaredAnnotations.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0131-rt-compact-MethodgetDefaultValue/MethodGetDefaultValue.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0132-rt-compact-MethodGetParameterCount/MethodGetParameterCount.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0133-rt-compact-MethodGetTypeParameters/MethodGetTypeParameters.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0134-rt-compact-MethodIsDefault/MethodIsDefault.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0135-rt-compact-MethodToGenericString/MethodToGenericString.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0136-rt-compact-ParameterGetAnnotation/ParameterGetAnnotation.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0137-rt-compact-ParameterGetAnnotations/ParameterGetAnnotations.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0138-rt-compact-ParameterGetAnnotationsByType/ParameterGetAnnotationsByType.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0139-rt-compact-ParameterGetDeclaredAnnotation/ParameterGetDeclaredAnnotation.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0140-rt-compact-ParameterGetDeclaredAnnotations/ParameterGetDeclaredAnnotations.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0141-rt-compact-ParameterGetDeclaredAnnotationsByType/ParameterGetDeclaredAnnotationsByType.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0142-rt-compact-ReflectionAnnotationGetClass/ReflectionAnnotationGetClass.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0143-rt-compact-ClinitClassNewInstance/ClassInitClassNewInstance.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0144-rt-compact-ClinitConstructorNewInstance/ClassInitConstructorNewInstance.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0145-rt-compact-ClinitFieldGetBooleanStatic/ClassInitFieldGetBooleanStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0146-rt-compact-ClinitFieldGetByteStatic/ClassInitFieldGetByteStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0147-rt-compact-ClinitFieldGetCharStatic/ClassInitFieldGetCharStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0148-rt-compact-ClinitFieldGetDoubleStatic/ClassInitFieldGetDoubleStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0149-rt-compact-ClinitFieldGetFloatStatic/ClassInitFieldGetFloatStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0150-rt-compact-ClinitFieldGetIntStatic/ClassInitFieldGetIntStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0151-rt-compact-ClinitFieldGetLongStatic/ClassInitFieldGetLongStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0152-rt-compact-ClinitFieldGetShortStatic/ClassInitFieldGetShortStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0153-rt-compact-ClinitFieldGetStatic/ClassInitFieldGetStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0154-rt-compact-ClinitFieldOtherMethod/ClassInitFieldOtherMethod.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0155-rt-compact-ClinitFieldSetBooleanStatic/ClassInitFieldSetBooleanStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0156-rt-compact-ClinitFieldSetByteStatic/ClassInitFieldSetByteStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0157-rt-compact-ClinitFieldSetCharStatic/ClassInitFieldSetCharStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0158-rt-compact-ClinitFieldSetDoubleStatic/ClassInitFieldSetDoubleStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0159-rt-compact-ClinitFieldSetFloatStatic/ClassInitFieldSetFloatStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0160-rt-compact-ClinitFieldSetIntStatic/ClassInitFieldSetIntStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0161-rt-compact-ClinitFieldSetLongStatic/ClassInitFieldSetLongStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0162-rt-compact-ClinitFieldSetShortStatic/ClassInitFieldSetShortStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0163-rt-compact-ClinitFieldSetStatic/ClassInitFieldSetStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0164-rt-compact-ClinitMethodInvokeStatic/ClassInitMethodInvokeStatic.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0165-rt-compact-ClinitFieldGetBooleanInterface/ClassInitFieldGetBooleanInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0166-rt-compact-ClinitFieldGetByteInterface/ClassInitFieldGetByteInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0167-rt-compact-ClinitFieldGetCharInterface/ClassInitFieldGetCharInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0168-rt-compact-ClinitFieldGetDoubleInterface/ClassInitFieldGetDoubleInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0169-rt-compact-ClinitFieldGetFloatInterface/ClassInitFieldGetFloatInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0170-rt-compact-ClinitFieldGetInterface/ClassInitFieldGetInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0171-rt-compact-ClinitFieldGetIntInterface/ClassInitFieldGetIntInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0172-rt-compact-ClinitFieldGetLongInterface/ClassInitFieldGetLongInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0173-rt-compact-ClinitFieldGetShortInterface/ClassInitFieldGetShortInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0174-rt-compact-ClinitFieldOtherMethodInterface/ClassInitFieldOtherMethodInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0175-rt-compact-ClinitFieldSetBooleanInterface/ClassInitFieldSetBooleanInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0176-rt-compact-ClinitFieldSetByteInterface/ClassInitFieldSetByteInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0177-rt-compact-ClinitFieldSetFloatInterface/ClassInitFieldSetFloatInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0178-rt-compact-ClinitFieldSetInterface/ClassInitFieldSetInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0179-rt-compact-ClinitFieldSetIntInterface/ClassInitFieldSetIntInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0180-rt-compact-ClinitFieldSetLongInterface/ClassInitFieldSetLongInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0181-rt-compact-ClinitFieldSetShortInterface/ClassInitFieldSetShortInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0182-rt-compact-ClinitMethodInvokeInterface/ClassInitMethodInvokeInterface.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0183-rt-compact-FieldMultiThreadTest/FieldMultiThreadTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0184-rt-compact-MethodTest/MethodTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0185-rt-compact-MethodMultiThreadTest/MethodMultiThreadTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0186-rt-compact-ConstructorTest/ConstructorTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0187-rt-compact-ConstructorMultiThreadTest/ConstructorMultiThreadTest.java create mode 100644 test/testsuite/ouroboros/compact_test/RT0188-rt-compact-MethodHandleReflectCombineTest/MethodHandleReflectCombineTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0189-rt-compact-FieldTest/FieldTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0190-rt-compact-AnnotationTypeSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0190-rt-compact-AnnotationTypeSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0190-rt-compact-AnnotationTypeSetTest/AnnotationTypeSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0191-rt-compact-AnnotationTypeInterfaceSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0191-rt-compact-AnnotationTypeInterfaceSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0191-rt-compact-AnnotationTypeInterfaceSetTest/AnnotationTypeInterfaceSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0192-rt-compact-AnnotationTypeEnumSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0192-rt-compact-AnnotationTypeEnumSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0192-rt-compact-AnnotationTypeEnumSetTest/AnnotationTypeEnumSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0193-rt-compact-AnnotationFieldSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0193-rt-compact-AnnotationFieldSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0193-rt-compact-AnnotationFieldSetTest/AnnotationFieldSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0194-rt-compact-AnnotationStaticFieldSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0194-rt-compact-AnnotationStaticFieldSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0194-rt-compact-AnnotationStaticFieldSetTest/AnnotationStaticFieldSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0195-rt-compact-AnnotationMethodSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0195-rt-compact-AnnotationMethodSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0195-rt-compact-AnnotationMethodSetTest/AnnotationMethodSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0196-rt-compact-AnnotationParameterSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0196-rt-compact-AnnotationParameterSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0196-rt-compact-AnnotationParameterSetTest/AnnotationParameterSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0197-rt-compact-AnnotationConstructorSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0197-rt-compact-AnnotationConstructorSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0197-rt-compact-AnnotationConstructorSetTest/AnnotationConstructorSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0198-rt-compact-AnnotationAnnotationTypeSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0198-rt-compact-AnnotationAnnotationTypeSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0198-rt-compact-AnnotationAnnotationTypeSetTest/AnnotationAnnotationTypeSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0199-rt-compact-AnnotationPackageSetTest/Run.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0199-rt-compact-AnnotationPackageSetTest/com/huawei/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0199-rt-compact-AnnotationPackageSetTest/com/huawei/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0199-rt-compact-AnnotationPackageSetTest/com/huawei/AnnotationPackageSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0199-rt-compact-AnnotationPackageSetTest/com/huawei/package-info.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnotationTypeParameterSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnotationTypeUseSetTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoC.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoD.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnotationMultiThread.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/ENUMA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0203-rt-compact-ReflectSpecialClassNameTest/ReflectClassNameTest.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnotationNotAscii.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnotationRepeatable.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/Test.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnotationTypeInnerClassSet.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnoA.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnoB.java create mode 100755 test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnotationTypeLocalClassSet.java diff --git a/test/testsuite/ouroboros/compact_test/RT0001-rt-compact-ReflectingetConstructor1/ReflectingGetConstructor1.java b/test/testsuite/ouroboros/compact_test/RT0001-rt-compact-ReflectingetConstructor1/ReflectingGetConstructor1.java new file mode 100755 index 0000000000..6cc7015419 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0001-rt-compact-ReflectingetConstructor1/ReflectingGetConstructor1.java @@ -0,0 +1,59 @@ +/* + *- @TestCaseID: ReflectingGetConstructor1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectingGetConstructor1.java + *- @Title/Destination: Getting public constructors of different arguments from reflection by calling + * Class.getConstructor() + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName获得GetConstructor1类的一个实例对象getConstructor1; + * -#step2: 分别调用GetConstructor1类的三个构造方法,从而实现从反射中获取不同参数的公共构造函数constructor1、constructor2、 + * constructor3; + * -#step3: 判断三个构造方法获取成功; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectingGetConstructor1.java + *- @ExecuteClass: ReflectingGetConstructor1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +class GetConstructor1 { + public GetConstructor1() { + } + + public GetConstructor1(String name) { + } + + public GetConstructor1(String name, int number) { + } + + GetConstructor1(int number) { + } +} + +public class ReflectingGetConstructor1 { + public static void main(String[] args) { + try { + Class getConstructor1 = Class.forName("GetConstructor1"); + Constructor constructor1 = getConstructor1.getConstructor(String.class); + Constructor constructor2 = getConstructor1.getConstructor(); + Constructor constructor3 = getConstructor1.getConstructor(String.class, int.class); + if (constructor1.toString().equals("public GetConstructor1(java.lang.String)") + && constructor2.toString().equals("public GetConstructor1()") + && constructor3.toString().equals("public GetConstructor1(java.lang.String,int)")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0002-rt-compact-ReflectingetConstructor2/ReflectingGetConstructor2.java b/test/testsuite/ouroboros/compact_test/RT0002-rt-compact-ReflectingetConstructor2/ReflectingGetConstructor2.java new file mode 100755 index 0000000000..6cfe2a7710 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0002-rt-compact-ReflectingetConstructor2/ReflectingGetConstructor2.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ReflectingGetConstructor2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectingGetConstructor2.java + *- @Title/Destination: When the specified constructor could not be found by reflection, NoSuchMethodException is thrown + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获得GetConstructor2类的一个实例对象getConstructor21; + * -#step2: 以int.class为参数,尝试通过getConstructor()方法获取GetConstructor2类的构造函数并记为constructor1; + * -#step3: 通过Class.forName()方法获得GetConstructor2类的一个实例对象getConstructor22; + * -#step4: 以String.class, char.class, int.class为参数,尝试通过getConstructor()方法获取GetConstructor2类的构造函数并记 + * 为constructor2; + * -#step5: 确定step2和step4中的构造函数constructor1、constructor2获取失败,并且会抛出NoSuchMethodException; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectingGetConstructor2.java + *- @ExecuteClass: ReflectingGetConstructor2 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +class GetConstructor2 { + public GetConstructor2() { + } + + public GetConstructor2(String name) { + } + + public GetConstructor2(String name, int number) { + } + + GetConstructor2(int number) { + } +} + +public class ReflectingGetConstructor2 { + public static void main(String[] args) { + try { + Class getConstructor21 = Class.forName("GetConstructor2"); + Constructor constructor1 = getConstructor21.getConstructor(int.class); + System.out.println(2); + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchMethodException e) { + try { + Class getConstructor22 = Class.forName("GetConstructor2"); + Constructor constructor2 = getConstructor22.getConstructor(String.class, char.class, int.class); + System.out.println(2); + } catch (ClassNotFoundException ee) { + System.err.println(ee); + System.out.println(2); + } catch (NoSuchMethodException ee) { + System.out.println(0); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0003-rt-compact-ReflectingetConstructors/ReflectingGetConstructors.java b/test/testsuite/ouroboros/compact_test/RT0003-rt-compact-ReflectingetConstructors/ReflectingGetConstructors.java new file mode 100755 index 0000000000..c03f91b63e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0003-rt-compact-ReflectingetConstructors/ReflectingGetConstructors.java @@ -0,0 +1,81 @@ +/* + *- @TestCaseID: ReflectingGetConstructors + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectingGetConstructors.java + *- @Title/Destination: Call Class.GetConstructors() to get all the public constructors in a class by reflection + *- @Condition: no + *- @Brief:no: + * -#step1: 通过反射的方法获得GetConstructors_a类的一个实例对象getConstructors_a; + * -#step2: 通过调用getConstructors_a的getConstructors()方法,获取到它的所有公共构造函数并记为constructors; + * -#step3: 确定step2中成功获取到getConstructors_a对象的所有公共构造函数constructors,并且其长度等于3,并且对于 + * constructors[i].toString()(此处i < constructors.length = 3)不包含字符串"GetConstructors_a(int)"; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectingGetConstructors.java + *- @ExecuteClass: ReflectingGetConstructors + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +class GetConstructors { + public GetConstructors() { + } + + public GetConstructors(String name) { + } + + public GetConstructors(String name, int number) { + } + + GetConstructors(int number) { + } + + GetConstructors(double id) { + } + + public GetConstructors(double id, String name) { + } +} + +class GetConstructors_a extends GetConstructors { + public GetConstructors_a() { + } + + public GetConstructors_a(String name) { + } + + public GetConstructors_a(String name, int number) { + } + + GetConstructors_a(int number) { + } +} + +public class ReflectingGetConstructors { + public static void main(String[] args) { + try { + Class getConstructors_a = Class.forName("GetConstructors_a"); + Constructor[] constructors = getConstructors_a.getConstructors(); + if (constructors.length == 3) { + for (int i = 0; i < constructors.length; i++) { + if (constructors[i].toString().indexOf("GetConstructors_a(int)") != -1) { + System.out.println(2); + } + } + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (ArrayIndexOutOfBoundsException e1) { + System.err.println(e1); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0004-rt-compact-ReflectingetDeclaredConstructor1/ReflectingGetDeclaredConstructor1.java b/test/testsuite/ouroboros/compact_test/RT0004-rt-compact-ReflectingetDeclaredConstructor1/ReflectingGetDeclaredConstructor1.java new file mode 100755 index 0000000000..db1d9e1e62 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0004-rt-compact-ReflectingetDeclaredConstructor1/ReflectingGetDeclaredConstructor1.java @@ -0,0 +1,61 @@ +/* + *- @TestCaseID: ReflectingGetDeclaredConstructor1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectingGetDeclaredConstructor1.java + *- @Title/Destination: Call Class.getDeclaredConstructor() to get the local constructor of a class by reflection + *- @Condition: no + *- @Brief:no: + * -#step1: 通过反射的方法获得GetDeclaredConstructor1类的一个实例对象getDeclaredConstructor1; + * -#step2: 通过step1中获得的getDeclaredConstructor1分别调用GetDeclaredConstructor1类的三个构造方法,从而实现从反射中获 + * 取不同参数的本地构造函数constructor1、constructor2、constructor3; + * -#step3: step2中所获取到的三个公共构造函数constructor1、constructor2、constructor3分别对应于 + * GetDeclaredConstructor1类的三个构造函数,表明本地构造函数获取成功; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectingGetDeclaredConstructor1.java + *- @ExecuteClass: ReflectingGetDeclaredConstructor1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +class GetDeclaredConstructor1 { + public GetDeclaredConstructor1() { + } + + private GetDeclaredConstructor1(String name) { + } + + protected GetDeclaredConstructor1(String name, int number) { + } + + GetDeclaredConstructor1(int number) { + } +} + +public class ReflectingGetDeclaredConstructor1 { + public static void main(String[] args) { + try { + Class getDeclaredConstructor1 = Class.forName("GetDeclaredConstructor1"); + Constructor constructor1 = getDeclaredConstructor1.getDeclaredConstructor(String.class); + Constructor constructor2 = getDeclaredConstructor1.getDeclaredConstructor(); + Constructor constructor3 = getDeclaredConstructor1.getDeclaredConstructor(String.class, int.class); + Constructor constructor4 = getDeclaredConstructor1.getDeclaredConstructor(int.class); + if (constructor1.toString().equals("private GetDeclaredConstructor1(java.lang.String)") + && constructor2.toString().equals("public GetDeclaredConstructor1()") + && constructor3.toString().equals("protected GetDeclaredConstructor1(java.lang.String,int)") + && constructor4.toString().equals("GetDeclaredConstructor1(int)")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0005-rt-compact-ReflectingetDeclaredConstructor2/ReflectingGetDeclaredConstructor2.java b/test/testsuite/ouroboros/compact_test/RT0005-rt-compact-ReflectingetDeclaredConstructor2/ReflectingGetDeclaredConstructor2.java new file mode 100755 index 0000000000..ab07af12d0 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0005-rt-compact-ReflectingetDeclaredConstructor2/ReflectingGetDeclaredConstructor2.java @@ -0,0 +1,52 @@ +/* + *- @TestCaseID: ReflectingGetDeclaredConstructor2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectingGetDeclaredConstructor2.java + *- @Title/Destination: When the specified local constructor for the class can not be retrieved by reflection using + * Class.getDeclaredConstructors(), NoSuchMethodException will be thrown + *- @Condition: no + *- @Brief:no: + * -#step1: 通过反射的方法获得GetDeclaredConstructor2类的一个实例对象getDeclaredConstructor2; + * -#step2: 尝试通过step1中的getDeclaredConstructor2对象调用GetDeclaredConstructor2类的不存在的本地构造函数; + * -#step3: step2中获取getDeclaredConstructor2对象的不存在的本地构造函数不成功,会抛出NoSuchMethodException; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectingGetDeclaredConstructor2.java + *- @ExecuteClass: ReflectingGetDeclaredConstructor2 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +class GetDeclaredConstructor2 { + public GetDeclaredConstructor2() { + } + + private GetDeclaredConstructor2(String name) { + } + + protected GetDeclaredConstructor2(String name, int number) { + } + + GetDeclaredConstructor2(int number) { + } +} + +public class ReflectingGetDeclaredConstructor2 { + public static void main(String[] args) { + try { + Class getDeclaredConstructor2 = Class.forName("GetDeclaredConstructor2"); + Constructor constructor = getDeclaredConstructor2.getDeclaredConstructor(String.class, char.class, int.class); + System.out.println(2); + } catch (ClassNotFoundException e1) { + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0006-rt-compact-ReflectingetDeclaredConstructors/ReflectingGetDeclaredConstructors.java b/test/testsuite/ouroboros/compact_test/RT0006-rt-compact-ReflectingetDeclaredConstructors/ReflectingGetDeclaredConstructors.java new file mode 100755 index 0000000000..24736160df --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0006-rt-compact-ReflectingetDeclaredConstructors/ReflectingGetDeclaredConstructors.java @@ -0,0 +1,51 @@ +/* + *- @TestCaseID: ReflectingGetDeclaredConstructors + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectingGetDeclaredConstructors.java + *- @Title/Destination: Call Class.getDeclaredConstructors() to get all the local constructors of a class by reflection + *- @Condition: no + *- @Brief:no: + * -#step1: 通过反射的方法获得GetDeclaredConstructors类的一个实例对象getDeclaredConstructors; + * -#step2: 通过调用getDeclaredConstructors的GetDeclaredConstructors()方法,获取到它的所有本地构造函数并记为constructors; + * -#step3: 确定step2中获取getDeclaredConstructors对象的所有本地构造函数constructors成功,并且其长度为4; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectingGetDeclaredConstructors.java + *- @ExecuteClass: ReflectingGetDeclaredConstructors + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +class GetDeclaredConstructors { + public GetDeclaredConstructors() { + } + + private GetDeclaredConstructors(String name) { + } + + protected GetDeclaredConstructors(String name, int number) { + } + + GetDeclaredConstructors(int number) { + } +} + +public class ReflectingGetDeclaredConstructors { + public static void main(String[] args) { + try { + Class getDeclaredConstructors = Class.forName("GetDeclaredConstructors"); + Constructor[] constructors = getDeclaredConstructors.getDeclaredConstructors(); + if (constructors.length == 4) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0007-rt-compact-ReflectionasSubclass1/ReflectionAsSubclass1.java b/test/testsuite/ouroboros/compact_test/RT0007-rt-compact-ReflectionasSubclass1/ReflectionAsSubclass1.java new file mode 100755 index 0000000000..ef1cfaefde --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0007-rt-compact-ReflectionasSubclass1/ReflectionAsSubclass1.java @@ -0,0 +1,51 @@ +/* + *- @TestCaseID: ReflectionAsSubclass1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionAsSubclass1.java + *- @Title/Destination: child class calls Class.asSubclass() on father class/interface. Get the instance of the subclass + * that casts the class to the target class by reflection gets the target + *- @Condition: no + *- @Brief:no: + * -#step1: 通过反射获取A_1类的运行时类,并对其返回值以A.class为参数调用asSubclass()方法,获得a_2;同理,通过反射获取 + * A_2类的运行时类,并对其返回值以A.class为参数调用asSubclass()方法,获得a_1; + * -#step2: 经判断得知a_2.newInstance()是A的一个实例,a_1.newInstance()也是A的一个实例; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionAsSubclass1.java + *- @ExecuteClass: ReflectionAsSubclass1 + *- @ExecuteArgs: + */ + +interface A { +} + +class A1 implements A { +} + +class A2 extends A1 { +} + +public class ReflectionAsSubclass1 { + public static void main(String[] args) { + try { + Class a2 = Class.forName("A1").asSubclass(A.class); + Class a1 = Class.forName("A2").asSubclass(A.class); + if (a2.newInstance() instanceof A) { + if (a1.newInstance() instanceof A) { + System.out.println(0); + } + } + } catch (ClassNotFoundException e1) { + System.out.println(e1); + } catch (InstantiationException e2) { + System.out.println(e2); + } catch (IllegalAccessException e3) { + System.out.println(e3); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0008-rt-compact-ReflectionasSubclass2/ReflectionAsSubclass2.java b/test/testsuite/ouroboros/compact_test/RT0008-rt-compact-ReflectionasSubclass2/ReflectionAsSubclass2.java new file mode 100755 index 0000000000..3d6c25ac24 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0008-rt-compact-ReflectionasSubclass2/ReflectionAsSubclass2.java @@ -0,0 +1,38 @@ +/* + *- @TestCaseID: ReflectionAsSubclass2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionAsSubclass2.java + *- @Title/Destination: To cast a subclass of another class by reflection get a class + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName("B_1"),再对其返回值调用asSubclass()方法可以获得B类的子类B_1类; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionAsSubclass2.java + *- @ExecuteClass: ReflectionAsSubclass2 + *- @ExecuteArgs: + */ + +class B { +} + +class B_1 extends B { +} + +public class ReflectionAsSubclass2 { + public static void main(String[] args) { + try { + Class.forName("B_1").asSubclass(B.class); + } catch (ClassCastException e) { + System.out.println(2); + } catch (ClassNotFoundException e) { + System.out.println(2); + } + System.out.println(0); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0009-rt-compact-ReflectionasSubclass3/ReflectionAsSubclass3.java b/test/testsuite/ouroboros/compact_test/RT0009-rt-compact-ReflectionasSubclass3/ReflectionAsSubclass3.java new file mode 100755 index 0000000000..ed93e3e256 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0009-rt-compact-ReflectionasSubclass3/ReflectionAsSubclass3.java @@ -0,0 +1,61 @@ +/* + *- @TestCaseID: ReflectionAsSubclass3 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionAsSubclass3.java + *- @Title/Destination: class A calls Class.asSubclass on class B, if A is not a subclass of B, throws ClassCastException + *- @Condition: no + *- @Brief:no: + * -#step1: 通过反射C_1类,并对其返回值以D.class为参数调用asSubclass()方法; + * -#step2: 同理,通过反射C_2类,并对其返回值以D.class为参数调用asSubclass()方法; + * -#step3: 通过反射D_1类,并对其返回值以C.class为参数调用asSubclass()方法; + * -#step4: step1、step2、step3中方法均调用失败,即无法获取到对应类的子类,会抛出ClassCastException; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionAsSubclass3.java + *- @ExecuteClass: ReflectionAsSubclass3 + *- @ExecuteArgs: + */ + +interface C { +} + +class C_1 implements C { +} + +class C_2 extends C_1 { +} + +class D { +} + +class D_1 extends D { +} + +public class ReflectionAsSubclass3 { + public static void main(String[] args) { + try { + Class.forName("C_1").asSubclass(D.class); + } catch (ClassCastException e1) { + try { + Class.forName("C_2").asSubclass(D.class); + } catch (ClassCastException e2) { + try { + Class.forName("D_1").asSubclass(C.class); + } catch (ClassCastException e3) { + System.out.println(0); + } catch (ClassNotFoundException e4) { + System.out.println(2); + } + } catch (ClassNotFoundException e5) { + System.out.println(2); + } + } catch (ClassNotFoundException e6) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0010-rt-compact-Reflectioncast1/ReflectionCast1.java b/test/testsuite/ouroboros/compact_test/RT0010-rt-compact-Reflectioncast1/ReflectionCast1.java new file mode 100755 index 0000000000..9a6331ddd7 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0010-rt-compact-Reflectioncast1/ReflectionCast1.java @@ -0,0 +1,38 @@ +/* + *- @TestCaseID: ReflectionCast1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionCast1.java + *- @Title/Destination: Casts an object to the class or interface represented by this Class object + *- @Condition: no + *- @Brief:no: + * -#step1: 创建一个Cast1_a类的实例对象cast1_a,创建一个Cast1类的实例对象cast1; + * -#step2: 将step1中的Cast1类的实例对象cast1强制转换为Cast1_a类型; + * -#step3: 经转换后的cast1对象和Cast1_a类是同一类型; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionCast1.java + *- @ExecuteClass: ReflectionCast1 + *- @ExecuteArgs: + */ + +class Cast1 { +} + +class Cast1_a extends Cast1 { +} + +public class ReflectionCast1 { + public static void main(String[] args) { + Cast1_a cast1_a = new Cast1_a(); + Cast1 cast1 = new Cast1(); + cast1 = Cast1.class.cast(cast1_a); + if (cast1.getClass().toString().equals("class Cast1_a")) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0011-rt-compact-Reflectioncast2/ReflectionCast2.java b/test/testsuite/ouroboros/compact_test/RT0011-rt-compact-Reflectioncast2/ReflectionCast2.java new file mode 100755 index 0000000000..06540ae388 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0011-rt-compact-Reflectioncast2/ReflectionCast2.java @@ -0,0 +1,40 @@ +/* + *- @TestCaseID: ReflectionCast2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionCast2.java + *- @Title/Destination: An exception is reported when the parent object cannot be cast to the class represented by this + * class object + *- @Condition: no + *- @Brief:no: + * -#step1: 创建一个Cast2类的实例对象cast2,创建一个Cast2类的子类Cast2_a类的实例对象cast2_a; + * -#step2: 将Cast2_a类的对象cast2_a强制转换为父类Cast2类型; + * -#step3: step2中的转换不能转换成功,会发生ClassCastException; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionCast2.java + *- @ExecuteClass: ReflectionCast2 + *- @ExecuteArgs: + */ + +class Cast2 { +} + +class Cast2_a extends Cast2 { +} + +public class ReflectionCast2 { + public static void main(String[] args) { + Cast2_a cast2_a = new Cast2_a(); + Cast2 cast2 = new Cast2(); + try { + cast2_a = Cast2_a.class.cast(cast2); + } catch (ClassCastException e) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0012-rt-compact-Reflectioncast3/ReflectionCast3.java b/test/testsuite/ouroboros/compact_test/RT0012-rt-compact-Reflectioncast3/ReflectionCast3.java new file mode 100755 index 0000000000..232a3f4485 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0012-rt-compact-Reflectioncast3/ReflectionCast3.java @@ -0,0 +1,40 @@ +/* + *- @TestCaseID: ReflectionCast3 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionCast3.java + *- @Title/Destination: An exception is reported when a relationship-free object cannot be cast to a class represented + * by this class object + *- @Condition: no + *- @Brief:no: + * -#step1: 创建一个Cast3_a类的实例对象cast3_a,创建一个Cast3类的实例对象cast3; + * -#step2: 将Cast3_a类的对象cast3_a强制转换为Cast3类型; + * -#step3: step2中的转换不能转换成功,会发生ClassCastException; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionCast3.java + *- @ExecuteClass: ReflectionCast3 + *- @ExecuteArgs: + */ + +class Cast3 { +} + +class Cast3_a { +} + +public class ReflectionCast3 { + public static void main(String[] args) { + Cast3_a cast3_a = new Cast3_a(); + Cast3 cast3 = new Cast3(); + try { + cast3_a = Cast3_a.class.cast(cast3); + } catch (ClassCastException e) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0013-rt-compact-Reflectioncast4/ReflectionCast4.java b/test/testsuite/ouroboros/compact_test/RT0013-rt-compact-Reflectioncast4/ReflectionCast4.java new file mode 100755 index 0000000000..d01d544107 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0013-rt-compact-Reflectioncast4/ReflectionCast4.java @@ -0,0 +1,35 @@ +/* + *- @TestCaseID: ReflectionCast4 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionCast4.java + *- @Title/Destination: Object cast to NULL + *- @Condition: no + *- @Brief:no: + * -#step1: 创建一个Cast4类的实例对象cast4,创建一个Object类的变量object,并赋初值为null; + * -#step2: 将Cast4类的实例对象cast4强制转换为null; + * -#step3: step2中成功将cast4对象转换为null; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionCast4.java + *- @ExecuteClass: ReflectionCast4 + *- @ExecuteArgs: + */ + +class Cast4 { +} + +public class ReflectionCast4 { + public static void main(String[] args) { + Object object = null; + Cast4 cast4 = new Cast4(); + cast4 = Cast4.class.cast(object); + if (cast4 == null) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0014-rt-compact-ReflectiondesiredAssertionStatus/ReflectionDesiredAssertionStatus.java b/test/testsuite/ouroboros/compact_test/RT0014-rt-compact-ReflectiondesiredAssertionStatus/ReflectionDesiredAssertionStatus.java new file mode 100755 index 0000000000..cf218ca035 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0014-rt-compact-ReflectiondesiredAssertionStatus/ReflectionDesiredAssertionStatus.java @@ -0,0 +1,31 @@ +/* + *- @TestCaseID: ReflectionDesiredAssertionStatus + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionDesiredAssertionStatus.java + *- @Title/Destination: When a class's assertionStatus is not set, desiredAssertionStatus() return false + *- @Condition: no + *- @Brief:no: + * -#step1: 创建一个ReflectionDesiredAssertionStatus类的实例对象reflectionDesiredAssertionStatus; + * -#step2: 通过reflectionDesiredAssertionStatus的getClass()方法获取其所属的类型并记为clazz; + * -#step3: 调用clazz的desiredAssertionStatus()方法得到的返回值为false; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionDesiredAssertionStatus.java + *- @ExecuteClass: ReflectionDesiredAssertionStatus + *- @ExecuteArgs: + */ + +public class ReflectionDesiredAssertionStatus { + public static void main(String[] args) { + ReflectionDesiredAssertionStatus reflectionDesiredAssertionStatus = new ReflectionDesiredAssertionStatus(); + Class clazz = reflectionDesiredAssertionStatus.getClass(); + if (!clazz.desiredAssertionStatus()) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0015-rt-compact-ReflectionforName1/ReflectionForName1.java b/test/testsuite/ouroboros/compact_test/RT0015-rt-compact-ReflectionforName1/ReflectionForName1.java new file mode 100755 index 0000000000..1e76aa99da --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0015-rt-compact-ReflectionforName1/ReflectionForName1.java @@ -0,0 +1,32 @@ +/* + *- @TestCaseID: ReflectionForName1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionForName1.java + *- @Title/Destination: Use Class.forName() To find a class by class name + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName的方法获取ForName1类的类型clazz; + * -#step2: 确定step1中的clazz与ForName1类是同一类型; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionForName1.java + *- @ExecuteClass: ReflectionForName1 + *- @ExecuteArgs: + */ + +class ForName1 { +} + +public class ReflectionForName1 { + public static void main(String[] args) throws ClassNotFoundException { + Class clazz = Class.forName("ForName1"); + if (clazz.toString().equals("class ForName1")) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0016-rt-compact-ReflectionforName4/ReflectionForName4.java b/test/testsuite/ouroboros/compact_test/RT0016-rt-compact-ReflectionforName4/ReflectionForName4.java new file mode 100755 index 0000000000..bdf2102e50 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0016-rt-compact-ReflectionforName4/ReflectionForName4.java @@ -0,0 +1,40 @@ +/* + *- @TestCaseID: ReflectionForName4 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionForName4.java + *- @Title/Destination: An exception is reported when a class is not found with reflection through a class name + *- @Condition: no + *- @Brief:no: + * -#step1: 以“for*”、true、ForName4_a.class.getClassLoader()为参数,通过Class.forName()获取相关类的运行时类时会 + * 抛出ClassNotFoundException; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionForName4.java + *- @ExecuteClass: ReflectionForName4 + *- @ExecuteArgs: + */ + +class ForName4 { + static { + } +} + +class ForName4_a { + static { + } +} + +public class ReflectionForName4 extends Thread { + public static void main(String[] args) { + try { + Class clazz = Class.forName("for*", true, ForName4_a.class.getClassLoader()); + } catch (ClassNotFoundException e) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0017-rt-compact-ReflectionforName5/ReflectionForName5.java b/test/testsuite/ouroboros/compact_test/RT0017-rt-compact-ReflectionforName5/ReflectionForName5.java new file mode 100755 index 0000000000..2af68e4514 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0017-rt-compact-ReflectionforName5/ReflectionForName5.java @@ -0,0 +1,62 @@ +/* + *- @TestCaseID: ReflectionForName5 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionForName5.java + *- @Title/Destination: Use Class.forName() to get a multilevel inherited class by reflection + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取ForName5类的类型clazz,且clazz和ForName5类是同一类型; + * -#step2: 通过Class.forName()方法获取ForName55类的类型clazz2,且clazz2和ForName55类是同一类型; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionForName5.java + *- @ExecuteClass: ReflectionForName5 + *- @ExecuteArgs: + */ + +interface ForName55_c { +} + +class ForName55_b implements ForName55_c { +} + +class ForName55_a extends ForName55_b { +} + +class ForName55 extends ForName55_a { +} + +class ForName5_e { +} + +class ForName5_d extends ForName5_e { +} + +class ForName5_c extends ForName5_d { +} + +class ForName5_b extends ForName5_c { +} + +class ForName5_a extends ForName5_b { +} + +class ForName5 extends ForName5_a { +} + +public class ReflectionForName5 { + public static void main(String[] args) throws ClassNotFoundException { + Class clazz = Class.forName("ForName5"); + if (clazz.toString().equals("class ForName5")) { + Class clazz2 = Class.forName("ForName55"); + if (clazz2.toString().equals("class ForName55")) { + System.out.println(0); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0018-rt-compact-ReflectiongetAnnotation1/ReflectionGetAnnotation1.java b/test/testsuite/ouroboros/compact_test/RT0018-rt-compact-ReflectiongetAnnotation1/ReflectionGetAnnotation1.java new file mode 100755 index 0000000000..8c7be90abf --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0018-rt-compact-ReflectiongetAnnotation1/ReflectionGetAnnotation1.java @@ -0,0 +1,58 @@ +/* + *- @TestCaseID: ReflectionGetAnnotation1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotation1.java + *- @Title/Destination: call class.getAnnotation to get annotation of a target class according to annotation class by + * reflection + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetAnnotation1_a类的类型clazz1,通过Class.forName()方法获取GetAnnotation1_b类的 + * 类型clazz2; + * -#step2: 以Zzz1.class为参数,通过getAnnotation()方法,分别获取clazz1、clazz2的注解,并且clazz1的注解中包含字符串 + * "t=getAnnotation"和"i=333",而clazz2的注解等于null; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotation1.java + *- @ExecuteClass: ReflectionGetAnnotation1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzz1 { +int i() default 0; + +String t() default ""; +} + +@Zzz1(i = 333, t = "getAnnotation") +class GetAnnotation1_a { +} + +class GetAnnotation1_b { +} + +public class ReflectionGetAnnotation1 { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("GetAnnotation1_a"); + Class clazz2 = Class.forName("GetAnnotation1_b"); + if (clazz1.getAnnotation(Zzz1.class).toString().indexOf("t=getAnnotation") != -1 + && clazz1.getAnnotation(Zzz1.class).toString().indexOf("i=333") != -1 + && clazz2.getAnnotation(Zzz1.class) == null) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0019-rt-compact-ReflectiongetAnnotation2/ReflectionGetAnnotation2.java b/test/testsuite/ouroboros/compact_test/RT0019-rt-compact-ReflectiongetAnnotation2/ReflectionGetAnnotation2.java new file mode 100755 index 0000000000..958e6d340f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0019-rt-compact-ReflectiongetAnnotation2/ReflectionGetAnnotation2.java @@ -0,0 +1,74 @@ +/* + *- @TestCaseID: ReflectionGetAnnotation2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotation2.java + *- @Title/Destination: Call class.getAnnotation to get annotation of a field in class according to annotation class by + * reflection. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含注解的类GetAnnotation2_a,通过调用getField()获取注解成员,调用getAnnotation(Class annotationClass) + * 获取注解,确认获取的注解正确。 + * -#step2:GetAnnotation2_a通过调用getField()获取非注解成员,调用getAnnotation(Class annotationClass) + * 获取注解,确认获取的注解为空。 + * -#step3:定义不含注解的类GetAnnotation2_b,通过调用getField()获取成员,调用getAnnotation(Class annotationClass) + * 获取注解,确认获取的注解为空。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotation2.java + *- @ExecuteClass: ReflectionGetAnnotation2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF2 { + int i() default 0; + String t() default ""; +} + +class GetAnnotation2_a { + @IF2(i = 333, t = "getAnnotation") + public int i_a; + public String t_a; +} + +class GetAnnotation2_b { + public int i_b; + public String t_b; +} + +public class ReflectionGetAnnotation2 { + public static void main(String[] args) { + try { + Class cls1 = Class.forName("GetAnnotation2_a"); + Class cls2 = Class.forName("GetAnnotation2_b"); + Field instance1 = cls1.getField("i_a"); + Field instance2 = cls1.getField("t_a"); + Field instance3 = cls2.getField("i_b"); + if (instance1.getAnnotation(IF2.class).i() == 333 && instance1.getAnnotation(IF2.class). + t().equals("getAnnotation") && instance2.getAnnotation(IF2.class) == null && + instance3.getAnnotation(IF2.class) == null) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchFieldException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0020-rt-compact-ReflectiongetAnnotation3/ReflectionGetAnnotation3.java b/test/testsuite/ouroboros/compact_test/RT0020-rt-compact-ReflectiongetAnnotation3/ReflectionGetAnnotation3.java new file mode 100755 index 0000000000..2c34759e77 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0020-rt-compact-ReflectiongetAnnotation3/ReflectionGetAnnotation3.java @@ -0,0 +1,86 @@ +/* + *- @TestCaseID: ReflectionGetAnnotation3 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotation3.java + *- @Title/Destination: Call Class.getAnnotation in functions of target class to get annotation by reflection, if the + * function does not have the expected annotation, throws exception. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含注解的内部类GetAnnotation3_a。 + * -#step2:通过调用getField()从内部类GetAnnotation3_a中获取成员。 + * -#step3:调用getAnnotation(Class annotationClass)获取GetAnnotation3_a的注解并抛出NullPointerException。 + * -#step4:定义不含注解的类GetAnnotation3_b,通过getAnnotation()方法获取成员方法,并抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotation3.java + *- @ExecuteClass: ReflectionGetAnnotation3 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Method; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzz3 { + int i() default 0; + String t() default ""; +} + +class GetAnnotation3_a { + @Zzz3(i = 333, t = "getAnnotation") + public void qqq() { + }; + + public void rrr() { + }; +} + +class GetAnnotation3_b { + public void www() { + }; +} + +public class ReflectionGetAnnotation3 { + + public static void main(String[] args) { + try { + Class zqp1 = Class.forName("GetAnnotation3_a"); + Method zhu1 = zqp1.getMethod("qqq"); + Method zhu2 = zqp1.getMethod("rrr"); + zhu1.getAnnotation(Zzz3.class).t(); + zhu2.getAnnotation(Zzz3.class).i(); + System.out.println(2); + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchMethodException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + + try { + Class zqp2 = Class.forName("GetAnnotation3_b"); + Method zhu3 = zqp2.getMethod("www"); + zhu3.getAnnotation(Zzz3.class).i(); + System.out.println(2); + } catch (ClassNotFoundException e3) { + System.err.println(e3); + System.out.println(2); + } catch (NoSuchMethodException e4) { + System.err.println(e4); + System.out.println(2); + } catch (NullPointerException e5){ + System.out.println(0); + } + } + } + +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0021-rt-compact-ReflectiongetAnnotation4/ReflectionGetAnnotation4.java b/test/testsuite/ouroboros/compact_test/RT0021-rt-compact-ReflectiongetAnnotation4/ReflectionGetAnnotation4.java new file mode 100755 index 0000000000..b3b1783d6d --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0021-rt-compact-ReflectiongetAnnotation4/ReflectionGetAnnotation4.java @@ -0,0 +1,75 @@ +/* + *- @TestCaseID: ReflectionGetAnnotation4 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotation4.java + *- @Title/Destination: Call Class.getAnnotation in functions of target class to get annotation by reflection, if the + * function does not have the expected annotation, throws exception. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含注解的内部类GetAnnotation4_a。 + * -#step2:通过调用getMethod()从内部类GetAnnotation4_a中获取成员方法。 + * -#step3:调用getAnnotation(Class annotationClass)获取GetAnnotation4_a成员方法的注解并抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotation4.java + *- @ExecuteClass: ReflectionGetAnnotation4 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Method; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzz4 { + int i() default 0; + + String t() default ""; +} + +@interface Zzz4_a { +int ii() default 0; + +String tt() default ""; +} + +class GetAnnotation4_a { + @Zzz4(i = 333, t = "getAnnotation") + public void qqq() { + }; + + @Zzz4_a(ii = 555, tt = "test") + public void rrr() { + }; +} + +public class ReflectionGetAnnotation4 { + + public static void main(String[] args) { + try { + Class zqp1 = Class.forName("GetAnnotation4_a"); + Method zhu1 = zqp1.getMethod("qqq"); + Method zhu2 = zqp1.getMethod("rrr"); + if (zhu1.getAnnotation(Zzz4_a.class) == null && zhu2.getAnnotation(Zzz4.class) == null) { + zhu1.getAnnotation(Zzz4_a.class).ii(); + System.out.println(2); + } + System.out.println(2); + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchMethodException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0022-rt-compact-ReflectiongetAnnotation5/ReflectionGetAnnotation5.java b/test/testsuite/ouroboros/compact_test/RT0022-rt-compact-ReflectiongetAnnotation5/ReflectionGetAnnotation5.java new file mode 100755 index 0000000000..1a9f028168 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0022-rt-compact-ReflectiongetAnnotation5/ReflectionGetAnnotation5.java @@ -0,0 +1,79 @@ +/* + *- @TestCaseID: ReflectionGetAnnotation5 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotation5.java + *- @Title/Destination: Child class call Class.GetAnnotation to get class annotations inherited from parent classes + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含注解的内部类GetAnnotation5。 + * -#step2:创建类GetAnnotation5_a继承GetAnnotation5,创建类GetAnnotation5_a的子类GetAnnotation5_b。 + * -#step3: 通过forName()获取GetAnnotation5_b的类名对象。 + * -#step4:调用getAnnotation(Class annotationClass)获取GetAnnotation5_b的注解。 + * -#step5:对获取的注解结果进行判断 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotation5.java + *- @ExecuteClass: ReflectionGetAnnotation5 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzz5 { + int i() default 0; + + String t() default ""; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzz5_a { + int i_a() default 2; + + String t_a() default ""; +} + +@Zzz5(i = 333, t = "test1") +class GetAnnotation5 { + public int i; + public String t; +} + +@Zzz5_a(i_a = 666, t_a = "right1") +class GetAnnotation5_a extends GetAnnotation5 { + public int i_a; + public String t_a; +} + +class GetAnnotation5_b extends GetAnnotation5_a { +} + +public class ReflectionGetAnnotation5 { + + public static void main(String[] args) { + try { + Class zqp1 = Class.forName("GetAnnotation5_b"); + if (zqp1.getAnnotation(Zzz5.class).toString().indexOf("t=test1") != -1 && zqp1.getAnnotation(Zzz5.class). + toString().indexOf("i=333") != -1) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0023-rt-compact-ReflectiongetAnnotation6/ReflectionGetAnnotation6.java b/test/testsuite/ouroboros/compact_test/RT0023-rt-compact-ReflectiongetAnnotation6/ReflectionGetAnnotation6.java new file mode 100755 index 0000000000..471086dbf5 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0023-rt-compact-ReflectiongetAnnotation6/ReflectionGetAnnotation6.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ReflectionGetAnnotation6 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotation6.java + *- @Title/Destination: Call Class.GetAnnotation() to get annotations of inner classes by reflection + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含注解的类GetAnnotation6的静态内部类GetAnnotation6_a。 + * -#step2: 通过forName()获取GetAnnotation6_a的类名对象。 + * -#step3:调用getAnnotation(Class annotationClass)获取GetAnnotation6_b的注解。 + * -#step4:对获取的注解结果进行判断 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotation6.java + *- @ExecuteClass: ReflectionGetAnnotation6 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzz6 { + int i() default 0; + + String t() default ""; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzz6_a { + int i_a() default 2; + + String t_a() default ""; +} + +@Zzz6(i = 333, t = "test1") +class GetAnnotation6 { + public int i; + public String t; + + @Zzz6_a(i_a = 666, t_a = "right1") + public static class GetAnnotation6_a { + public int j; + } +} + +public class ReflectionGetAnnotation6 { + + public static void main(String[] args) { + try { + Class zqp1 = Class.forName("GetAnnotation6"); + Class[] zhu1 = zqp1.getDeclaredClasses(); + if (zhu1[0].getAnnotation(Zzz6_a.class).toString().indexOf("t_a=right1") != -1 && zhu1[0]. + getAnnotation(Zzz6_a.class).toString().indexOf("i_a=666") != -1) { + if (zhu1[0].getAnnotation(Zzz6.class) == null) { + System.out.println(0); + } + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.err.println(e2); + System.out.println(2); + } + } + +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0024-rt-compact-ReflectiongetAnnotation7/ReflectionGetAnnotation7.java b/test/testsuite/ouroboros/compact_test/RT0024-rt-compact-ReflectiongetAnnotation7/ReflectionGetAnnotation7.java new file mode 100755 index 0000000000..6c02613381 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0024-rt-compact-ReflectiongetAnnotation7/ReflectionGetAnnotation7.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ReflectionGetAnnotation7 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotation7.java + *- @Title/Destination: Use Class.GetAnnotation to get native basic annotations through reflection. + *- @Condition: no + *- @Brief:no: + * -#step1: 创建类GetAnnotation7的子类GetAnnotation7_a且重写父类中废弃的aa()方法。 + * -#step2: 通过forName()获取GetAnnotation7_a的类名对象。 + * -#step3: 通过getMethod()获取GetAnnotation7_a内的方法。 + * -#step4:调用getAnnotation(Class annotationClass)获取Deprecated.class的值。 + * -#step5:对获取的注解结果进行判断 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotation7.java + *- @ExecuteClass: ReflectionGetAnnotation7 + *- @ExecuteArgs: + */ + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +class GetAnnotation7 { + @Deprecated + public int aa(int num) { + return 0; + } +} + +class GetAnnotation7_a extends GetAnnotation7 { + @Override + public int aa(int num) { + return 2; + } +} + +public class ReflectionGetAnnotation7 { + + public static void main(String[] args) { + try { + Class zqp1 = Class.forName("GetAnnotation7_a"); + Method zhu1 = zqp1.getMethod("aa", int.class); + Annotation[] j = zhu1.getAnnotations(); + if (j.length == 0) { + try { + Class zqp2 = Class.forName("GetAnnotation7"); + Method zhu2 = zqp2.getMethod("aa", int.class); + if (zhu2.getAnnotation(Deprecated.class).toString().indexOf("Deprecated") != -1) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NullPointerException e3) { + System.err.println(e3); + System.out.println(2); + } + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NullPointerException e3) { + System.err.println(e3); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0025-rt-compact-ReflectiongetAnnotationsByType1/ReflectionGetAnnotationsByType1.java b/test/testsuite/ouroboros/compact_test/RT0025-rt-compact-ReflectiongetAnnotationsByType1/ReflectionGetAnnotationsByType1.java new file mode 100755 index 0000000000..0358208c69 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0025-rt-compact-ReflectiongetAnnotationsByType1/ReflectionGetAnnotationsByType1.java @@ -0,0 +1,86 @@ +/* + *- @TestCaseID: ReflectionGetAnnotationsByType1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotationsByType1.java + *- @Title/Destination: Call Class.GetAnnotationsByType() to gets the annotation of the field in the target class by + * reflection, returning the annotation array. + *- @Condition: no + *- @Brief:no: + * -#step1: 创建类GetAnnotationsByType1_a,且定义含注解的变量。 + * -#step2: 通过forName()获取GetAnnotationsByType1_a的类名对象。 + * -#step3: 通过getMethod()获取GetAnnotationsByType1_a内对应名称的变量。 + * -#step4:调用getAnnotationsByType(Class annotationClass)获取类型为MyTarget的注解。 + * -#step5:对获取的注解结果进行判断 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotationsByType1.java + *- @ExecuteClass: ReflectionGetAnnotationsByType1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzzz1 { + int i() default 0; + + String t() default ""; +} + +@interface Zzzz1_a { +} + +@interface Zzzz1_b { +} + +class GetAnnotationsByType1_a { + @Zzzz1(i = 333, t = "GetAnnotationsByType") + public int i_a; + @Zzzz1(i = 333, t = "GetAnnotationsByType") + public int i_aa; + @Zzzz1(i = 333, t = "GetAnnotationsByType") + public int i_aaa; + public String t_a; + @Zzzz1_a + public String t_aa; + @Zzzz1_b + public String t_aaa; +} + +public class ReflectionGetAnnotationsByType1 { + + public static void main(String[] args) { + try { + Class zqp1 = Class.forName("GetAnnotationsByType1_a"); + Field zhu1 = zqp1.getField("i_a"); + Field zhu2 = zqp1.getField("t_a"); + if (zqp1.getAnnotationsByType(Zzzz1.class).length == 0) { + if (zhu2.getAnnotationsByType(Zzzz1_a.class).length == 0) { + Annotation[] k = zhu1.getAnnotationsByType(Zzzz1.class); + if (k[0].toString().indexOf("t=GetAnnotationsByType") != -1 && k[0].toString().indexOf("i=333") + != -1) { + System.out.println(0); + } + } + } + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchFieldException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0026-rt-compact-ReflectiongetAnnotationsByType2/ReflectionGetAnnotationsByType2.java b/test/testsuite/ouroboros/compact_test/RT0026-rt-compact-ReflectiongetAnnotationsByType2/ReflectionGetAnnotationsByType2.java new file mode 100755 index 0000000000..359f8cc435 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0026-rt-compact-ReflectiongetAnnotationsByType2/ReflectionGetAnnotationsByType2.java @@ -0,0 +1,82 @@ +/* + *- @TestCaseID: ReflectionGetAnnotationsByType2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotationsByType2.java + *- @Title/Destination: Retrieving an empty annotation of a field in a target class by reflection reports an exception. + * Class.GetAnnotationsByType(null) throws NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: 创建含注解的类GetAnnotationsByType2_a,不含注解的类GetAnnotationsByType2_b。 + * -#step2: 通过forName()获取GetAnnotationsByType2_a的类名对象,通过getField()获取GetAnnotationsByType2_a内对应名称的成员。 + * -#step3: 调用getAnnotationsByType(Class annotationClass)获取类型为MyTarget的数组并抛出NullPointerException。 + * -#step4:通过forName()获取GetAnnotationsByType2_b的类名对象,通过getField()获取GetAnnotationsByType2_b内对应名称的成员。 + * -#step5:调用getAnnotationsByType(Class annotationClass)获取类型为MyTarget的数组并抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotationsByType2.java + *- @ExecuteClass: ReflectionGetAnnotationsByType2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzzz2 { + int i() default 0; + + String t() default ""; +} + +class GetAnnotationsByType2_a { + @Zzzz2(i = 333, t = "GetAnnotationsByType") + public int i_a; + public String t_a; +} + +class GetAnnotationsByType2_b { + public int i_b; + public String t_b; +} + +public class ReflectionGetAnnotationsByType2 { + + public static void main(String[] args) { + try { + Class zqp1 = Class.forName("GetAnnotationsByType2_a"); + Field zhu1 = zqp1.getField("t_a"); + Annotation[] j = zhu1.getAnnotationsByType(null); + System.out.println(2); + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchFieldException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + + try { + Class zqp2 = Class.forName("GetAnnotationsByType2_b"); + Field zhu2 = zqp2.getField("i_b"); + Annotation[] k = zhu2.getAnnotationsByType(null); + System.out.println(2); + } catch (ClassNotFoundException e3) { + System.err.println(e3); + System.out.println(2); + } catch (NoSuchFieldException e4) { + System.err.println(e4); + System.out.println(2); + } catch (NullPointerException e5) { + System.out.println(0); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0027-rt-compact-ReflectiongetAnnotationsByType3/ReflectionGetAnnotationsByType3.java b/test/testsuite/ouroboros/compact_test/RT0027-rt-compact-ReflectiongetAnnotationsByType3/ReflectionGetAnnotationsByType3.java new file mode 100755 index 0000000000..9056f6a092 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0027-rt-compact-ReflectiongetAnnotationsByType3/ReflectionGetAnnotationsByType3.java @@ -0,0 +1,80 @@ +/* + *- @TestCaseID: ReflectionGetAnnotationsByType3 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetAnnotationsByType3.java + *- @Title/Destination: Child class calls Class.GetAnnotationsByType to gets the annotations inherited from parent class + * by reflection, and returns an array of annotations. + *- @Condition: no + *- @Brief:no: + * -#step1: 创建类GetAnnotationsByType3_a继承于含注解的GetAnnotationsByType3的子类GetAnnotationsByType3_a。 + * -#step2: 通过forName()获取GetAnnotationsByType1_a的类名对象。 + * -#step3:调用getAnnotationsByType(Class annotationClass)获取类型为MyTarget的数组。 + * -#step5:对获取的注解结果进行判断。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetAnnotationsByType3.java + *- @ExecuteClass: ReflectionGetAnnotationsByType3 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzzz3 { + int i() default 0; + + String t() default ""; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Zzzz3_a { + int i_a() default 2; + + String t_a() default ""; +} + +@Zzzz3(i = 333, t = "test1") +class GetAnnotationsByType3 { + public int i; + public String t; +} + +@Zzzz3_a(i_a = 666, t_a = "right1") +class GetAnnotationsByType3_a extends GetAnnotationsByType3 { + public int i_a; + public String t_a; +} + +class GetAnnotationsByType3_b extends GetAnnotationsByType3_a { +} + +public class ReflectionGetAnnotationsByType3 { + + public static void main(String[] args) { + try { + Class zqp1 = Class.forName("GetAnnotationsByType3_b"); + Annotation[] j = zqp1.getAnnotationsByType(Zzzz3.class); + if (j[0].toString().indexOf("t=test1") != -1 && j[0].toString().indexOf("i=333") != -1) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.err.println(e2); + System.out.println(2); + } + } + +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0028-rt-compact-ReflectiongetCanonicalName/ReflectionGetCanonicalName.java b/test/testsuite/ouroboros/compact_test/RT0028-rt-compact-ReflectiongetCanonicalName/ReflectionGetCanonicalName.java new file mode 100755 index 0000000000..60a5f94086 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0028-rt-compact-ReflectiongetCanonicalName/ReflectionGetCanonicalName.java @@ -0,0 +1,41 @@ +/* + *- @TestCaseID: ReflectionGetCanonicalName + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetCanonicalName.java + *- @Title/Destination: Class.getCanonicalName() returns class name by reflection. + *- @Condition: no + *- @Brief:no: + * -#step1: Define an empty class. + * -#step2: Get Class instance by calling ForName(String className) + * -#step3: Test getCanonicalName() returns class name correctly. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetCanonicalName.java + *- @ExecuteClass: ReflectionGetCanonicalName + *- @ExecuteArgs: + */ + +class GetCanonicalNameTest { +} + +public class ReflectionGetCanonicalName { + + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + + try { + Class zqp = Class.forName("GetCanonicalNameTest"); + if (zqp.getCanonicalName().equals("GetCanonicalNameTest")) { + result = 0; + } + } catch (ClassNotFoundException e) { + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0029-rt-compact-ReflectiongetComponentType/ReflectionGetComponentType.java b/test/testsuite/ouroboros/compact_test/RT0029-rt-compact-ReflectiongetComponentType/ReflectionGetComponentType.java new file mode 100755 index 0000000000..4141e47d4b --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0029-rt-compact-ReflectiongetComponentType/ReflectionGetComponentType.java @@ -0,0 +1,33 @@ +/* + *- @TestCaseID: ReflectionGetComponentType + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetComponentType.java + *- @Title/Destination: Class.getComponentType() returns the Class representing the component type of an array. If + * this class does not represent an array class ,then this method returns null. + *- @Condition: no + *- @Brief:no: + * -#step1: Test Class.getComponentType() when char,string[] and int[] call it. + * -#step2: Check Class.getComponentType() returns right component type when an array calls it. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetComponentType.java + *- @ExecuteClass: ReflectionGetComponentType + *- @ExecuteArgs: + */ + +public class ReflectionGetComponentType { + + public static void main(String[] args) { + if (char.class.getComponentType() == null && String[].class.getComponentType().toString(). + equals("class java.lang.String") && int[].class.getComponentType().toString().equals("int")) { + System.out.println(0); + }else{ + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0030-rt-compact-ReflectiongetDeclaredAnnotations1/ReflectionGetDeclaredAnnotations1.java b/test/testsuite/ouroboros/compact_test/RT0030-rt-compact-ReflectiongetDeclaredAnnotations1/ReflectionGetDeclaredAnnotations1.java new file mode 100755 index 0000000000..6155348ec8 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0030-rt-compact-ReflectiongetDeclaredAnnotations1/ReflectionGetDeclaredAnnotations1.java @@ -0,0 +1,80 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredAnnotations1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredAnnotations1.java + *- @Title/Destination: Class.GetDeclaredAnnotations() retrieve all annotations from the target class by reflection, + * and result an array of annotations. + *- @Condition: no + *- @Brief:no: + * -#step1: Define two annotations. + * -#step2: Use classloader to load class.R + * -#step3: Return an array of annotations by calling GetDeclaredAnnotations(). + * -#step4: Check that Class.GetDeclaredAnnotations() retrieves all annotations. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredAnnotations1.java + *- @ExecuteClass: ReflectionGetDeclaredAnnotations1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Ddd1 { + int i() default 0; + + String t() default ""; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Ddd1_a { + int i_a() default 2; + + String t_a() default ""; +} + +@Ddd1(i = 333, t = "test1") +class GetDeclaredAnnotations1 { + public int i; + public String t; +} + +@Ddd1_a(i_a = 666, t_a = "right1") +class GetDeclaredAnnotations1_a extends GetDeclaredAnnotations1 { + public int i_a; + public String t_a; +} + +public class ReflectionGetDeclaredAnnotations1 { + + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp1 = Class.forName("GetDeclaredAnnotations1_a"); + if (zqp1.getDeclaredAnnotations().length == 1) { + Annotation[] j = zqp1.getDeclaredAnnotations(); + if (j[0].toString().indexOf("i_a=666") != -1 && j[0].toString().indexOf("t_a=right1") != -1) { + result = 0; + } + } + } catch (ClassNotFoundException e) { + System.err.println(e); + result = -1; + } catch (NullPointerException e2) { + System.err.println(e2); + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0031-rt-compact-ReflectiongetDeclaredAnnotations2/ReflectionGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/compact_test/RT0031-rt-compact-ReflectiongetDeclaredAnnotations2/ReflectionGetDeclaredAnnotations2.java new file mode 100755 index 0000000000..070138c955 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0031-rt-compact-ReflectiongetDeclaredAnnotations2/ReflectionGetDeclaredAnnotations2.java @@ -0,0 +1,80 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredAnnotations2.java + *- @Title/Destination: Class.GetDeclaredAnnotations() does not result annotations that inherited from parent class. + *- @Condition: no + *- @Brief:no: + * -#step1: Define two annotation. + * -#step2:Use classloader to load class. + * -#step3:Return an array of annotations by calling GetDeclaredAnnotations(). + * -#step4: Check that Class.GetDeclaredAnnotations() retrieves all annotations but annotations those inherited from + * parent class. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredAnnotations2.java + *- @ExecuteClass: ReflectionGetDeclaredAnnotations2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Ddd2 { + int i() default 0; + + String t() default ""; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Ddd2_a { + int i_a() default 2; + + String t_a() default ""; +} + +@Ddd2(i = 333, t = "test1") +class GetDeclaredAnnotations2 { + public int i; + public String t; +} + +@Ddd2_a(i_a = 666, t_a = "right1") +class GetDeclaredAnnotations2_a extends GetDeclaredAnnotations2 { + public int i_a; + public String t_a; +} + +class GetDeclaredAnnotations2_b extends GetDeclaredAnnotations2_a { +} + +public class ReflectionGetDeclaredAnnotations2 { + + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp1 = Class.forName("GetDeclaredAnnotations2_b"); + if (zqp1.getDeclaredAnnotations().length == 0) { + result = 0; + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + result = -1; + } catch (NullPointerException e2) { + System.err.println(e2); + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0032-rt-compact-ReflectiongetDeclaredAnnotationsByType1/ReflectionGetDeclaredAnnotationsByType1.java b/test/testsuite/ouroboros/compact_test/RT0032-rt-compact-ReflectiongetDeclaredAnnotationsByType1/ReflectionGetDeclaredAnnotationsByType1.java new file mode 100755 index 0000000000..214812fe1e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0032-rt-compact-ReflectiongetDeclaredAnnotationsByType1/ReflectionGetDeclaredAnnotationsByType1.java @@ -0,0 +1,85 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredAnnotationsByType1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredAnnotationsByType1.java + *- @Title/Destination: Class.GetDeclaredAnnotationsByType() returns the target class local annotation of expected type + * through reflection, and returns the annotation array. + *- @Condition: no + *- @Brief:no: + * -#step1: Define two annotation. + * -#step2: Use classloader to load class. + * -#step3: result an array of annotations by calling GetDeclaredAnnotationsByType(). + * -#step4: Check that Class.GetDeclaredAnnotationsByType() returns all annotations but annotations those inherited from + * parent class. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredAnnotationsByType1.java + *- @ExecuteClass: ReflectionGetDeclaredAnnotationsByType1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Dddd1 { + int i() default 0; + + String t() default ""; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Dddd1_a { + int i_a() default 2; + + String t_a() default ""; +} + +@Dddd1(i = 333, t = "test1") +class GetDeclaredAnnotationsByType1 { + public int i; + public String t; +} + +@Dddd1_a(i_a = 666, t_a = "right1") +class GetDeclaredAnnotationsByType1_a extends GetDeclaredAnnotationsByType1 { + public int i_a; + public String t_a; +} + +class GetDeclaredAnnotationsByType1_b extends GetDeclaredAnnotationsByType1_a { +} + +public class ReflectionGetDeclaredAnnotationsByType1 { + + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp1 = Class.forName("GetDeclaredAnnotationsByType1_b"); + Class zqp2 = Class.forName("GetDeclaredAnnotationsByType1_a"); + if (zqp1.getDeclaredAnnotationsByType(Dddd1.class).length == 0) { + Annotation[] j = zqp2.getDeclaredAnnotationsByType(Dddd1_a.class); + if (j[0].toString().indexOf("i_a=666") != -1 && j[0].toString().indexOf("t_a=right1") != -1) { + result = 0; + } + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + result = -1; + } catch (NullPointerException e2) { + System.err.println(e2); + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0033-rt-compact-ReflectionGetDeclaredAnnotationsByTypeNullPointerException/ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java b/test/testsuite/ouroboros/compact_test/RT0033-rt-compact-ReflectionGetDeclaredAnnotationsByTypeNullPointerException/ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java new file mode 100755 index 0000000000..a6354ccfef --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0033-rt-compact-ReflectionGetDeclaredAnnotationsByTypeNullPointerException/ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java @@ -0,0 +1,77 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredAnnotationsByTypeNullPointerException + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java + *- @Title/Destination: Class.GetDeclaredAnnotationsByType(null) throws NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: Define two annotation. + * -#step2: Use classloader to load class. + * -#step3: Test Class.GetDeclaredAnnotationsByType() with null parameter. + * -#step4: Check that NullPointerException was threw. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java + *- @ExecuteClass: ReflectionGetDeclaredAnnotationsByTypeNullPointerException + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Dddd2 { + int i() default 0; + + String t() default ""; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Dddd2_a { + int i_a() default 2; + + String t_a() default ""; +} + +@Dddd2(i = 333, t = "test1") +class GetDeclaredAnnotationsByType2 { + public int i; + public String t; +} + +@Dddd2_a(i_a = 666, t_a = "right1") +class GetDeclaredAnnotationsByType2_a extends GetDeclaredAnnotationsByType2 { + public int i_a; + public String t_a; +} + +class GetDeclaredAnnotationsByType2_b extends GetDeclaredAnnotationsByType2_a { +} + +public class ReflectionGetDeclaredAnnotationsByTypeNullPointerException { + + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp1 = Class.forName("GetDeclaredAnnotationsByType2_b"); + Annotation[] j = zqp1.getDeclaredAnnotationsByType(null); + result = 0; + } catch (ClassNotFoundException e1) { + System.err.println(e1); + result = -1; + } catch (NullPointerException e2) { + result = 0; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0034-rt-compact-ReflectiongetDeclaredClasses/ReflectionGetDeclaredClasses.java b/test/testsuite/ouroboros/compact_test/RT0034-rt-compact-ReflectiongetDeclaredClasses/ReflectionGetDeclaredClasses.java new file mode 100755 index 0000000000..a63b9f522b --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0034-rt-compact-ReflectiongetDeclaredClasses/ReflectionGetDeclaredClasses.java @@ -0,0 +1,65 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredClasses + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredClasses.java + *- @Title/Destination: Class.getDeclaredClasses() result an array of class objects that represent all declared members + * of this class,includes public, protected, default (package) access, and private classes and + * interfaces,excludes inherited classes and interfaces + *- @Condition: no + *- @Brief:no: + * -#step1: Create a class include inner class. + * -#step2: Use classloader to load class. + * -#step3: Return an array of class objects by calling Class.getDeclaredClasses(). + * -#step4: Check that the array of class objects exclude inherited classes and interfaces. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredClasses.java + *- @ExecuteClass: ReflectionGetDeclaredClasses + *- @ExecuteArgs: + */ + +class ReflectiongetDeclaredClasses_a { + public class getDeclaredClasses_a1 { + } + + private class getDeclaredClasses_a2 { + } + + protected class getDeclaredClasses_a3 { + } +} + +public class ReflectionGetDeclaredClasses extends ReflectiongetDeclaredClasses_a { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp = Class.forName("ReflectionGetDeclaredClasses"); + Class[] j = zqp.getDeclaredClasses(); + if (j.length == 3) { + for (int i = 0; i < j.length; i++) { + if (j[i].getName().indexOf("getDeclaredClasses_a") != -1) { + result = -1; + } + } + } + } catch (ClassNotFoundException e) { + System.err.println(e); + result = -1; + } + System.out.println(result); + } + + public class getDeclaredClassestest1 { + } + + private class getDeclaredClassestest2 { + } + + protected class getDeclaredClassestest3 { + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0035-rt-compact-ReflectiongetDeclaredField1/ReflectionGetDeclaredField1.java b/test/testsuite/ouroboros/compact_test/RT0035-rt-compact-ReflectiongetDeclaredField1/ReflectionGetDeclaredField1.java new file mode 100755 index 0000000000..1a93bbe604 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0035-rt-compact-ReflectiongetDeclaredField1/ReflectionGetDeclaredField1.java @@ -0,0 +1,58 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredField1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredField1.java + *- @Title/Destination: Class.GetDeclaredField() Returns a Field object that reflects the specified declared field of + * the class or interface represented by this Class object. + *- @Condition: no + *- @Brief:no: + * -#step1: Create a test class. + * -#step2: Use classloader to load class. + * -#step3: Check that return field objects are correctly. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredField1.java + *- @ExecuteClass: ReflectionGetDeclaredField1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class GetDeclaredField1 { + public int i = 1; + String s = "aaa"; + private double d = 2.5; + protected float f = -222; +} + +public class ReflectionGetDeclaredField1 { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp = Class.forName("GetDeclaredField1"); + Field zhu1 = zqp.getDeclaredField("i"); + Field zhu2 = zqp.getDeclaredField("s"); + Field zhu3 = zqp.getDeclaredField("d"); + Field zhu4 = zqp.getDeclaredField("f"); + if (zhu1.getName().equals("i") && zhu2.getName().equals("s") && zhu3.getName().equals("d") && + zhu4.getName().equals("f")) { + result = 0; + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + result = -1; + } catch (NoSuchFieldException e2) { + System.err.println(e2); + result = -1; + } catch (NullPointerException e3) { + System.err.println(e3); + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0036-rt-compact-ReflectionGetDeclaredFieldNullPointerException/ReflectionGetDeclaredFieldNullPointerException.java b/test/testsuite/ouroboros/compact_test/RT0036-rt-compact-ReflectionGetDeclaredFieldNullPointerException/ReflectionGetDeclaredFieldNullPointerException.java new file mode 100755 index 0000000000..8f87de6ac5 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0036-rt-compact-ReflectionGetDeclaredFieldNullPointerException/ReflectionGetDeclaredFieldNullPointerException.java @@ -0,0 +1,68 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredFieldNullPointerException. + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredFieldNullPointerException.java + *- @Title/Destination: Class.GetDeclaredField(null) throws NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: Create two test class. + * -#step2: Use classloader to load class. + * -#step3: Test Class.GetDeclaredField() with null parameter. + * -#step4: Check that NullPointerException was threw. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredFieldNullPointerException.java + *- @ExecuteClass: ReflectionGetDeclaredFieldNullPointerException + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class GetDeclaredField2_a { + public int i_a = 5; + String s_a = "bbb"; +} + +class GetDeclaredField2 extends GetDeclaredField2_a { + public int i = 1; + String s = "aaa"; + private double d = 2.5; + protected float f = -222; +} + +public class ReflectionGetDeclaredFieldNullPointerException { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp = Class.forName("GetDeclaredField2"); + Field zhu1 = zqp.getDeclaredField("i_a"); + result = -1; + } catch (ClassNotFoundException e1) { + System.err.println(e1); + result = -1; + } catch (NullPointerException e2) { + System.err.println(e2); + result = -1; + } catch (NoSuchFieldException e3) { + try { + Class zqp = Class.forName("GetDeclaredField2"); + Field zhu1 = zqp.getDeclaredField(null); + result = -1; + } catch (ClassNotFoundException e4) { + System.err.println(e4); + result = -1; + } catch (NoSuchFieldException e5) { + System.err.println(e5); + result = -1; + } catch (NullPointerException e6) { + result = 0; + } + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0037-rt-compact-ReflectiongetDeclaredFields1/ReflectionGetDeclaredFields1.java b/test/testsuite/ouroboros/compact_test/RT0037-rt-compact-ReflectiongetDeclaredFields1/ReflectionGetDeclaredFields1.java new file mode 100755 index 0000000000..8cf8d260e4 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0037-rt-compact-ReflectiongetDeclaredFields1/ReflectionGetDeclaredFields1.java @@ -0,0 +1,61 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredFields1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredFields1.java + *- @Title/Destination: Class.GetDeclaredFields() returns an array of Field objects reflecting all the fields declared + * by the class or interface represented by this Class object. This includes public, protected, + * default (package) access, and private fields, but excludes inherited fields. + *- @Condition: no + *- @Brief:no: + * -#step1: Create test classes and interface. + * -#step2: Use classloader to load class. + * -#step3: Check that return Field objects array correctly by calling GetDeclaredFields(). + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredFields1.java + *- @ExecuteClass: ReflectionGetDeclaredFields1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class GetDeclaredFields1_a { + public int i_a = 5; + String s_a = "bbb"; +} + +class GetDeclaredFields1 extends GetDeclaredFields1_a { + public int i = 1; + String s = "aaa"; + private double d = 2.5; + protected float f = -222; +} + +interface GetDeclaredFields1_b { + public int i_b = 2; + String s_b = "ccc"; +} + +public class ReflectionGetDeclaredFields1 { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp1 = Class.forName("GetDeclaredFields1"); + Class zqp2 = Class.forName("GetDeclaredFields1_b"); + Field[] j = zqp1.getDeclaredFields(); + Field[] k = zqp2.getDeclaredFields(); + if (j.length == 4 && k.length == 2) { + result = 0; + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0038-rt-compact-ReflectiongetDeclaredFields2/ReflectionGetDeclaredFields.java b/test/testsuite/ouroboros/compact_test/RT0038-rt-compact-ReflectiongetDeclaredFields2/ReflectionGetDeclaredFields.java new file mode 100755 index 0000000000..d0835a60fd --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0038-rt-compact-ReflectiongetDeclaredFields2/ReflectionGetDeclaredFields.java @@ -0,0 +1,56 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredFields + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredFields.java + *- @Title/Destination: Class.getDeclaredFields() returns an array of Field objects reflecting all the fields declared + * by the class or interface represented by this Class object. This includes public, protected, + * default (package) access, and private fields, but excludes inherited fields. + *- @Condition: no + *- @Brief:no: + * -#step1: Create test classes and enum. + * -#step2: Use classloader to load class. + * -#step3: Check that return Field objects array which exclude inherited fields which by calling GetDeclaredFields(). + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredFields.java + *- @ExecuteClass: ReflectionGetDeclaredFields + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class GetDeclaredFields_a { + public int i_a = 5; + String s_a = "bbb"; +} + +class GetDeclaredFields extends GetDeclaredFields_a { +} + +enum GetDeclaredFields_b { + i_b, s_b, f_b +} + +public class ReflectionGetDeclaredFields { + public static void main(String[] args) { + int result = 0; + try { + Class zqp1 = Class.forName("GetDeclaredFields"); + Class zqp2 = Class.forName("GetDeclaredFields_b"); + Field[] j = zqp1.getDeclaredFields(); + Field[] k = zqp2.getDeclaredFields(); + if (j.length == 0 && k.length == 4) { + result = 0; + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0039-rt-compact-ReflectiongetDeclaredMethod1/ReflectionGetDeclaredMethod1.java b/test/testsuite/ouroboros/compact_test/RT0039-rt-compact-ReflectiongetDeclaredMethod1/ReflectionGetDeclaredMethod1.java new file mode 100755 index 0000000000..54545d676e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0039-rt-compact-ReflectiongetDeclaredMethod1/ReflectionGetDeclaredMethod1.java @@ -0,0 +1,80 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredMethod1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredMethod1.java + *- @Title/Destination: Class.getDeclaredMethod() Returns a Method object that reflects the specified declared method + * of the class or interface represented by this Class object. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获得GetDeclaredMethod1类的运行时类clazz; + * -#step2: 分别以("empty1", int.class)、"getDd"、"empty1"、"empty2"、"getZero"和("getZero", String.class)为参数,通过 + * clazz的getDeclaredMethod()方法,获取Method类的不同的方法对象method1、method2、method3、method4、method5、method6; + * -#step3: 确定step2中的方法对象method1、method2、method3、method4、method5、method6获取成功,并且分别是 + * GetDeclaredMethod1类的指定的声明方法。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredMethod1.java + *- @ExecuteClass: ReflectionGetDeclaredMethod1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +class GetDeclaredMethod1 { + public void empty1() { + } + + void empty2() { + } + + int getZero() { + return 0; + } + + private String getDd() { + return "dd"; + } + + public void empty1(int number) { + } + + int getZero(String name) { + return 2; + } +} + +public class ReflectionGetDeclaredMethod1 { + public static void main(String[] args) { + try { + Class clazz = Class.forName("GetDeclaredMethod1"); + Method method1 = clazz.getDeclaredMethod("empty1", int.class); + Method method2 = clazz.getDeclaredMethod("getDd"); + Method method3 = clazz.getDeclaredMethod("empty1"); + Method method4 = clazz.getDeclaredMethod("empty2"); + Method method5 = clazz.getDeclaredMethod("getZero"); + Method method6 = clazz.getDeclaredMethod("getZero", String.class); + if (method1.toString().equals("public void GetDeclaredMethod1.empty1(int)") + && method2.toString().equals("private java.lang.String GetDeclaredMethod1.getDd()") + && method3.toString().equals("public void GetDeclaredMethod1.empty1()") + && method4.toString().equals("void GetDeclaredMethod1.empty2()") + && method5.toString().equals("int GetDeclaredMethod1.getZero()") + && method6.toString().equals("int GetDeclaredMethod1.getZero(java.lang.String)")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NullPointerException e3) { + System.err.println(e3); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0040-rt-compact-ReflectiongetDeclaredMethod2/ReflectionGetDeclaredMethod2.java b/test/testsuite/ouroboros/compact_test/RT0040-rt-compact-ReflectiongetDeclaredMethod2/ReflectionGetDeclaredMethod2.java new file mode 100755 index 0000000000..1ba2cf3a01 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0040-rt-compact-ReflectiongetDeclaredMethod2/ReflectionGetDeclaredMethod2.java @@ -0,0 +1,87 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredMethod2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredMethod2.java + *- @Title/Destination: Class.getDeclaredMethod() throws NoSuchMethodException when expected method not found in class; + * Class.getDeclaredMethod(null) throws NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetDeclaredMethod2类的运行时类clazz1; + * -#step2: 以empty1为参数,尝试通过getDeclaredMethod()方法尝试获取clazz1的方法对象并记为method1; + * -#step3: 通过Class.forName()方法获取GetDeclaredMethod2类的运行时类clazz2; + * -#step4: 以null为参数,尝试通过getDeclaredMethod()方法尝试获取clazz2的方法对象并记为method2; + * -#step5: method1和method2获取失败,并且会抛出NullPointerException; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredMethod2.java + *- @ExecuteClass: ReflectionGetDeclaredMethod2 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +class GetDeclaredMethod2_a { + public void empty1() { + } + + public void empty2() { + } +} + +class GetDeclaredMethod2 extends GetDeclaredMethod2_a { + public void void1() { + } + + void void2() { + } + + int getZero() { + return 0; + } + + private String getDd() { + return "dd"; + } + + public void setNumber(int number) { + } + + int setName(String name) { + return 2; + } +} + +public class ReflectionGetDeclaredMethod2 { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("GetDeclaredMethod2"); + Method method1 = clazz1.getDeclaredMethod("empty1"); + System.out.println(2); + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + try { + Class clazz2 = Class.forName("GetDeclaredMethod2"); + Method method2 = clazz2.getDeclaredMethod(null); + System.out.println(2); + } catch (ClassNotFoundException e4) { + System.err.println(e4); + System.out.println(2); + } catch (NoSuchMethodException e5) { + System.err.println(e5); + System.out.println(2); + } catch (NullPointerException e6) { + System.out.println(0); + } + } catch (NullPointerException e3) { + System.err.println(e3); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0041-rt-compact-ReflectiongetDeclaredMethod3/ReflectionGetDeclaredMethod3.java b/test/testsuite/ouroboros/compact_test/RT0041-rt-compact-ReflectiongetDeclaredMethod3/ReflectionGetDeclaredMethod3.java new file mode 100755 index 0000000000..c1eb9c8fa6 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0041-rt-compact-ReflectiongetDeclaredMethod3/ReflectionGetDeclaredMethod3.java @@ -0,0 +1,52 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredMethod3 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredMethod3.java + *- @Title/Destination: Class.getDeclaredMethod() can return abstract methods of target class + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetDeclaredMethod3类的运行时类clazz; + * -#step2: 以aa为参数,通过getDeclaredMethod()方法获取clazz的方法对象method1;同理,以bb为参数,通过getMethod()方法获取 + * clazz的方法对象method2; + * -#step3: 确定method1和method2获取成功,并且是GetDeclaredMethod3类的指定的运行方法; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredMethod3.java + *- @ExecuteClass: ReflectionGetDeclaredMethod3 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +abstract class GetDeclaredMethod3 { + abstract void empty1(); + abstract public int empty2(); +} + +public class ReflectionGetDeclaredMethod3 { + public static void main(String[] args) { + try { + Class clazz = Class.forName("GetDeclaredMethod3"); + Method method1 = clazz.getDeclaredMethod("empty1"); + Method method2 = clazz.getMethod("empty2"); + if (method1.toString().equals("abstract void GetDeclaredMethod3.empty1()") + && method2.toString().equals("public abstract int GetDeclaredMethod3.empty2()")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NullPointerException e3) { + System.err.println(e3); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0042-rt-compact-ReflectiongetDeclaredMethods1/ReflectionGetDeclaredMethods1.java b/test/testsuite/ouroboros/compact_test/RT0042-rt-compact-ReflectiongetDeclaredMethods1/ReflectionGetDeclaredMethods1.java new file mode 100755 index 0000000000..98f2d94027 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0042-rt-compact-ReflectiongetDeclaredMethods1/ReflectionGetDeclaredMethods1.java @@ -0,0 +1,84 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredMethods1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredMethods1.java + *- @Title/Destination: Class.GetDeclaredMethods returns an array containing Method objects reflecting all the declared + * methods of the class or interface represented by this Class object, including public, protected, + * default (package) access, and private methods. If class has multiple declared methods with the + * same name and parameter types but different return types, each method will be returned. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetDeclaredMethods1类的运行时类clazz1; + * -#step2: 通过Class.forName()方法获取GetDeclaredMethods1_b类的运行时类clazz2; + * -#step3: 通过getDeclaredMethods()方法,分别获取clazz1、clazz2的所有的方法对象,返回值分别为methods1和methods2; + * -#step4: 确定step3中methods1和methods2都成功获取,即成功获取到clazz1、clazz2的所有的方法对象,并且methods1、methods2 + * 的长度分别为6和2。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredMethods1.java + *- @ExecuteClass: ReflectionGetDeclaredMethods1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +class GetDeclaredMethods1_a { + public void empty1() { + } + + public void empty2() { + } +} + +class GetDeclaredMethods1 extends GetDeclaredMethods1_a { + public void void1() { + } + + void void2() { + } + + int getZero() { + return 0; + } + + private String getDd() { + return "dd"; + } + + public void setNumber(int number) { + } + + int setName(String name) { + return 2; + } +} + +interface GetDeclaredMethods1_b { + public default void test1() { + } + + default void test2() { + } +} + +public class ReflectionGetDeclaredMethods1 { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("GetDeclaredMethods1"); + Class clazz2 = Class.forName("GetDeclaredMethods1_b"); + Method[] methods1 = clazz1.getDeclaredMethods(); + Method[] methods2 = clazz2.getDeclaredMethods(); + if (methods1.length == 6 && methods2.length == 2) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0043-rt-compact-ReflectiongetDeclaredMethods2/ReflectionGetDeclaredMethods2.java b/test/testsuite/ouroboros/compact_test/RT0043-rt-compact-ReflectiongetDeclaredMethods2/ReflectionGetDeclaredMethods2.java new file mode 100755 index 0000000000..7814e27040 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0043-rt-compact-ReflectiongetDeclaredMethods2/ReflectionGetDeclaredMethods2.java @@ -0,0 +1,49 @@ +/* + *- @TestCaseID: ReflectionGetDeclaredMethods2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaredMethods2.java + *- @Title/Destination: Class.getDeclaredMethods() does not return inherited methods. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetDeclaredMethods2类的运行时类clazz; + * -#step2: 通过getDeclaredMethods()方法获取clazz的所有的方法对象,返回值为一个数组,并记为method; + * -#step3: 确定method的长度为0,即返回的数组为空,证明通过getDeclaredMethods()方法不返回继承的方法。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaredMethods2.java + *- @ExecuteClass: ReflectionGetDeclaredMethods2 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +class GetDeclaredMethods2_a { + public void empty1() { + } + + public void empty2() { + } +} + +class GetDeclaredMethods2 extends GetDeclaredMethods2_a { +} + +public class ReflectionGetDeclaredMethods2 { + public static void main(String[] args) { + try { + Class clazz = Class.forName("GetDeclaredMethods2"); + Method[] method = clazz.getDeclaredMethods(); + if (method.length == 0) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0044-rt-compact-ReflectiongetDeclaringClass/ReflectionGetDeclaringClass.java b/test/testsuite/ouroboros/compact_test/RT0044-rt-compact-ReflectiongetDeclaringClass/ReflectionGetDeclaringClass.java new file mode 100755 index 0000000000..5f25662ff5 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0044-rt-compact-ReflectiongetDeclaringClass/ReflectionGetDeclaringClass.java @@ -0,0 +1,80 @@ +/* + *- @TestCaseID: ReflectionGetDeclaringClass + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetDeclaringClass.java + *- @Title/Destination: If the class or interface represented by this Class object is a member of another class, + * Class.GetDeclaringClass() returns the Class object representing the class in which it was + * declared. This method returns null if this class or interface is not a member of any other class. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetDeclaringClass类的运行时类clazz; + * -#step2: 通过getDeclaredFields()方法获取clazz的所有的成员,返回值为一个数组记为fields; + * -#step3: 通过getDeclaredConstructors()方法获取clazz的所有的构造方法,返回值为一个数组记为constructors; + * -#step4: 对于num < fields.length,fields[i].getDeclaringClass().getName()的返回值与GetDeclaringClass类是同一类型,同时 + * 对于str < constructors.length,constructors[s].getDeclaringClass().getName()的返回值与GetDeclaringClass类是同 + * 一类型; + * -#step5: 在step4的基础上,通过Class.forName()方法获取GetDeclaringClass_a类的运行时类clazz2,并且通过 + * clazz2.getDeclaringClass()的返回值均为null; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetDeclaringClass.java + *- @ExecuteClass: ReflectionGetDeclaringClass + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; + +class GetDeclaringClass { + public int num; + String str; + float fNum; + + public GetDeclaringClass() { + } + + GetDeclaringClass(int number) { + } + + GetDeclaringClass(String name) { + } + + GetDeclaringClass(int number, String name) { + } +} + +class GetDeclaringClass_a { +} + +public class ReflectionGetDeclaringClass { + public static void main(String[] args) { + try { + int num = 0; + Class clazz = Class.forName("GetDeclaringClass"); + Field[] fields = clazz.getDeclaredFields(); + Constructor[] constructors = clazz.getDeclaredConstructors(); + for (int i = 0; i < fields.length; i++) { + if (fields[i].getDeclaringClass().getName().equals("GetDeclaringClass")) { + for (int j = 0; j < constructors.length; j++) { + if (constructors[j].getDeclaringClass().getName().equals("GetDeclaringClass")) { + Class clazz2 = Class.forName("GetDeclaringClass_a"); + if (clazz2.getDeclaringClass() == null) { + num++; + } + } + } + } + } + if (num == 12) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0045-rt-compact-ReflectiongetEnclosingClass1/ReflectionGetEnclosingClass1.java b/test/testsuite/ouroboros/compact_test/RT0045-rt-compact-ReflectiongetEnclosingClass1/ReflectionGetEnclosingClass1.java new file mode 100755 index 0000000000..4f605b4306 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0045-rt-compact-ReflectiongetEnclosingClass1/ReflectionGetEnclosingClass1.java @@ -0,0 +1,49 @@ +/* + *- @TestCaseID: ReflectionGetEnclosingClass1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetEnclosingClass1.java + *- @Title/Destination: Class.getEnclosingClass() Get the immediately enclosing class of the underlying class by + * reflection. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过(new GetEnclosingClassTest1()).test1().getClass()获取ReflectionGetEnclosingClass1类的内部类 + * GetEnclosingClassTest1类并记为clazz1; + * -#step2: 通过(new GetEnclosingClassTest1()).test2().getClass()获取ReflectionGetEnclosingClass1类的内部类 + * GetEnclosingClassTest1类并记为clazz2; + * -#step3: 确定step1和step2中成功获取到ReflectionGetEnclosingClass1类的两个内部类clazz1、clazz2; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetEnclosingClass1.java + *- @ExecuteClass: ReflectionGetEnclosingClass1 + *- @ExecuteArgs: + */ + +public class ReflectionGetEnclosingClass1 { + public static void main(String[] args) { + Class clazz1 = (new GetEnclosingClassTest1()).test1().getClass(); + Class clazz2 = (new GetEnclosingClassTest1()).test2().getClass(); + if (clazz1.getEnclosingClass().getName().equals("ReflectionGetEnclosingClass1$GetEnclosingClassTest1") + && clazz2.getEnclosingClass().getName().equals("ReflectionGetEnclosingClass1$GetEnclosingClassTest1")) { + System.out.println(0); + } + } + + public static class GetEnclosingClassTest1 { + public Object test1() { + class classA { + } + return new classA(); + } + + Object test2() { + class classB { + } + return new classB(); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0046-rt-compact-ReflectiongetEnclosingClass2/ReflectionGetEnclosingClass2.java b/test/testsuite/ouroboros/compact_test/RT0046-rt-compact-ReflectiongetEnclosingClass2/ReflectionGetEnclosingClass2.java new file mode 100755 index 0000000000..1df5a384fa --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0046-rt-compact-ReflectiongetEnclosingClass2/ReflectionGetEnclosingClass2.java @@ -0,0 +1,52 @@ +/* + *- @TestCaseID: ReflectionGetEnclosingClass2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetEnclosingClass2.java + *- @Title/Destination: Returns null if the underlying class is a top-level class. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetEnclosingClassTest2类的运行时类clazz1; + * -#step2: 通过(new GetEnclosingClassTest2()).test2().getClass()获取GetEnclosingClassTest2类的内部类classB类并记 + * 为clazz2; + * -#step3: 通过clazz1.getEnclosingClass()的返回值为null,而通过clazz2.getEnclosingClass().getName()的返回值的类型 + * 与GetEnclosingClassTest2类相同; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetEnclosingClass2.java + *- @ExecuteClass: ReflectionGetEnclosingClass2 + *- @ExecuteArgs: + */ + +class GetEnclosingClassTest2 { + public Object test1() { + class classA { + } + return new classA(); + } + + Object test2() { + class classB { + } + return new classB(); + } +} + +public class ReflectionGetEnclosingClass2 { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("GetEnclosingClassTest2"); + Class clazz2 = (new GetEnclosingClassTest2()).test2().getClass(); + if (clazz1.getEnclosingClass() == null + && clazz2.getEnclosingClass().getName().equals("GetEnclosingClassTest2")) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0047-rt-compact-ReflectiongetEnumConstants/ReflectionGetEnumConstants.java b/test/testsuite/ouroboros/compact_test/RT0047-rt-compact-ReflectiongetEnumConstants/ReflectionGetEnumConstants.java new file mode 100755 index 0000000000..af01f5ce55 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0047-rt-compact-ReflectiongetEnumConstants/ReflectionGetEnumConstants.java @@ -0,0 +1,102 @@ +/* + *- @TestCaseID: ReflectionGetEnumConstants + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetEnumConstants.java + *- @Title/Destination: Returns an array of the values of the enumeration classes that are represented in the order + * declared by this class object. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法分别获取Weekday类、GetEnumConstants类的运行时类clazz1、clazz2; + * -#step2: 分别通过clazz1.getEnumConstants()和clazz2.getEnumConstants()获取枚举类的数组并记为objects1、objects2; + * -#step3: 确定step2中成功获取到枚举类数组objects1、objects2,并且objects1数组的长度为7,objects2数组为null; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetEnumConstants.java + *- @ExecuteClass: ReflectionGetEnumConstants + *- @ExecuteArgs: + */ + +enum Weekday { + MONDAY { + Object test1() { + class classA { + } + + return new classA(); + } + }, + TUESDAY { + Object test2() { + class classB { + } + + return new classB(); + } + }, + WEDNESDAY { + Object test3() { + class classC { + } + + return new classC(); + } + }, + THURSDAY { + Object test4() { + class classD { + } + + return new classD(); + } + }, + FRIDAY { + Object test5() { + class classE { + } + + return new classE(); + } + }, + SATURDAY { + Object test6() { + class classF { + } + + return new classF(); + } + }, + SUNDAY { + Object test7() { + class classG { + } + + return new classG(); + } + } +} + +class GetEnumConstants { +} + +public class ReflectionGetEnumConstants { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("Weekday"); + Class clazz2 = Class.forName("GetEnumConstants"); + Object[] objects1 = clazz1.getEnumConstants(); + Object[] objects2 = clazz2.getEnumConstants(); + if (objects1.length == 7) { + if (objects2 == null) { + System.out.println(0); + } + } + } catch (ClassNotFoundException e) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0048-rt-compact-ReflectiongetField1/ReflectionGetField1.java b/test/testsuite/ouroboros/compact_test/RT0048-rt-compact-ReflectiongetField1/ReflectionGetField1.java new file mode 100755 index 0000000000..178e1457a5 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0048-rt-compact-ReflectiongetField1/ReflectionGetField1.java @@ -0,0 +1,58 @@ +/* + *- @TestCaseID: ReflectionGetField1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetField1.java + *- @Title/Destination: Class.getField() returns a Field object that reflects the specified public member field, + * including the inherited public fields. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetField1类的运行时类clazz; + * -#step2: 分别以num、str为参数,通过getField()方法分别获取GetField1类、GetField1_a类的公共字段并记为field1、field2; + * -#step3: 确定step2中成功获取到两个字段field1、field2,并且field1等于i,field2等于str。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetField1.java + *- @ExecuteClass: ReflectionGetField1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class GetField1_a { + int num2 = 5; + public String str = "bbb"; +} + +class GetField1 extends GetField1_a { + public int num = 1; + String string = "aaa"; + private double dNum = 2.5; + protected float fNum = -222; +} + +public class ReflectionGetField1 { + public static void main(String[] args) { + try { + Class clazz = Class.forName("GetField1"); + Field field1 = clazz.getField("num"); + Field field2 = clazz.getField("str"); + if (field1.getName().equals("num") && field2.getName().equals("str")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchFieldException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NullPointerException e3) { + System.err.println(e3); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0049-rt-compact-ReflectiongetField2/ReflectionGetField2.java b/test/testsuite/ouroboros/compact_test/RT0049-rt-compact-ReflectiongetField2/ReflectionGetField2.java new file mode 100755 index 0000000000..a1c1d69566 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0049-rt-compact-ReflectiongetField2/ReflectionGetField2.java @@ -0,0 +1,68 @@ +/* + *- @TestCaseID: ReflectionGetField2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetField2.java + *- @Title/Destination: If expected Field not found, throws NoSuchFieldException; Class.getField(null) throws + * NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetField2类的运行时类clazz1; + * -#step2: 以s为参数,通过getField()方法尝试获取GetField2类的default类型的字段并记为field1; + * -#step3: 通过Class.forName()方法获取GetField2类的运行时类clazz2; + * -#step4: 以null为参数,通过getField()方法尝试获取GetField2类的字段并记为field2; + * -#step5: 确定step2和step4中field1、field2获取失败,并且会抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetField2.java + *- @ExecuteClass: ReflectionGetField2 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class GetField2_a { + int num = 5; + public String str = "bbb"; +} + +class GetField2 extends GetField2_a { + public int num = 1; + String str2 = "aaa"; + private double dNum = 2.5; + protected float fNum = -222; +} + +public class ReflectionGetField2 { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("GetField2"); + Field field1 = clazz1.getField("str2"); + System.out.println(2); + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchFieldException e2) { + try { + Class clazz2 = Class.forName("GetField2"); + Field field2 = clazz2.getField(null); + System.out.println(2); + } catch (ClassNotFoundException e4) { + System.err.println(e4); + System.out.println(2); + } catch (NoSuchFieldException e5) { + System.err.println(e5); + System.out.println(2); + } catch (NullPointerException e6) { + System.out.println(0); + } + } catch (NullPointerException e3) { + System.err.println(e3); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0050-rt-compact-ReflectiongetFields/ReflectionGetFields.java b/test/testsuite/ouroboros/compact_test/RT0050-rt-compact-ReflectiongetFields/ReflectionGetFields.java new file mode 100755 index 0000000000..b35823bb46 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0050-rt-compact-ReflectiongetFields/ReflectionGetFields.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ReflectionGetFields + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetFields.java + *- @Title/Destination: Class.GetFields() returns an array containing Field objects reflecting all the accessible public + * fields of the class or interface represented by this Class object. Including inherited public + * fields. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法分别获取GetFields类、GetFields_b类、GetFields_c类的运行时类clazz1、clazz2、clazz3; + * -#step2: 通过getFields()方法分别获取clazz1、clazz2、clazz3的所有可访问的公共字段并记为fields1、fields2、fields3; + * -#step3: 确定step2中fields1、fields2、fields3获取成功,并且fields1和fields2的长度为2,fields的长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetFields.java + *- @ExecuteClass: ReflectionGetFields + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class GetFields_a { + public int num = 5; + String str = "bbb"; +} + +class GetFields extends GetFields_a { + public int num = 1; + String str = "aaa"; + private double dNum = 2.5; + protected float fNum = -222; +} + +interface GetFields_b { + public int num = 2; + String str = "ccc"; +} + +class GetFields_c { +} + +public class ReflectionGetFields { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("GetFields"); + Class clazz2 = Class.forName("GetFields_b"); + Class clazz3 = Class.forName("GetFields_c"); + Field[] fields1 = clazz1.getFields(); + Field[] fields2 = clazz2.getFields(); + Field[] fields3 = clazz3.getFields(); + if (fields1.length == 2 && fields2.length == 2 && fields3.length == 0) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0051-rt-compact-ReflectiongetMethod1/ReflectionGetMethod1.java b/test/testsuite/ouroboros/compact_test/RT0051-rt-compact-ReflectiongetMethod1/ReflectionGetMethod1.java new file mode 100755 index 0000000000..2d4330ae28 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0051-rt-compact-ReflectiongetMethod1/ReflectionGetMethod1.java @@ -0,0 +1,85 @@ +/* + *- @TestCaseID: ReflectionGetMethod1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetMethod1.java + *- @Title/Destination: Class.getMethod Returns a Method object that reflects the specified public member method of the + * class or interface represented by this Class object. Include inherited public methods. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetMethod1类的运行时类clazz; + * -#step2: 分别以empty、(empty,int.class)、(setName,String.class)、getStr为参数,获取clazz的指定的公共成员方法并记为 + * method1、method2、method3、method4; + * -#step3: 确定step2中成功获取到method1、method2、method3、method4,并且正好是GetMethod1类的指定的公共成员方法; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetMethod1.java + *- @ExecuteClass: ReflectionGetMethod1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +class GetMethod1_a { + public int setName(String name) { + return 10; + } + + public String getStr() { + return "getDda"; + } +} + +class GetMethod1 extends GetMethod1_a { + public void empty() { + } + + void emptyB() { + } + + int getNum() { + return 0; + } + + private String getDd() { + return "getDd"; + } + + public void empty(int number) { + } + + int getNum(String name) { + return 2; + } +} + +public class ReflectionGetMethod1 { + public static void main(String[] args) { + try { + Class clazz = Class.forName("GetMethod1"); + Method method1 = clazz.getMethod("empty"); + Method method2 = clazz.getMethod("empty", int.class); + Method method3 = clazz.getMethod("setName", String.class); + Method method4 = clazz.getMethod("getStr"); + if (method1.toString().equals("public void GetMethod1.empty()") + && method2.toString().equals("public void GetMethod1.empty(int)") + && method3.toString().equals("public int GetMethod1_a.setName(java.lang.String)") + && method4.toString().equals("public java.lang.String GetMethod1_a.getStr()")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NullPointerException e3) { + System.err.println(e3); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0052-rt-compact-ReflectiongetMethod2/ReflectionGetMethod2.java b/test/testsuite/ouroboros/compact_test/RT0052-rt-compact-ReflectiongetMethod2/ReflectionGetMethod2.java new file mode 100755 index 0000000000..f478a31742 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0052-rt-compact-ReflectiongetMethod2/ReflectionGetMethod2.java @@ -0,0 +1,91 @@ +/* + *- @TestCaseID: ReflectionGetMethod2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetMethod2.java + *- @Title/Destination: If expected method is not found, getMethod throws NoSuchMethodException; Class.getMethod(NULL) + * throws NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetMethod2类的运行时类clazz1; + * -#step2: 以empty为参数,通过getMethod()方法获取clazz1的公共成员方法并记为method1; + * -#step3: 通过Class.forName()方法获取GetMethod2类的运行时类clazz2; + * -#step4: 以null为参数,通过getMethod()方法获取clazz2的公共成员方法并记为method2; + * -#step5: 确定step2和step4中的method1、method2获取失败,并且会抛出NullPointerException; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetMethod2.java + *- @ExecuteClass: ReflectionGetMethod2 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +class GetMethod2_a { + public int getName(String name) { + return 10; + } + + public String getString() { + return "dda"; + } +} + +class GetMethod2 extends GetMethod2_a { + public void getVoid() { + } + + void empty() { + } + + int getZero() { + return 0; + } + + private String getStr() { + return "dd"; + } + + public void setNum(int number) { + } + + int getSecondNum(String name) { + return 2; + } +} + +public class ReflectionGetMethod2 { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("GetMethod2"); + Method method1 = clazz1.getMethod("empty"); + System.out.println(2); + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + // NoSuchMethodException is thrown when method not exist. + try { + Class clazz2 = Class.forName("GetMethod2"); + Method method2 = clazz2.getMethod(null); + System.out.println(2); + } catch (ClassNotFoundException e4) { + System.err.println(e4); + System.out.println(2); + } catch (NoSuchMethodException e5) { + System.err.println(e5); + System.out.println(2); + } catch (NullPointerException e6) { + // Expected result: NullPointerException is thrown when method is null. + System.out.println(0); + } + } catch (NullPointerException e3) { + System.err.println(e3); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0053-rt-compact-ReflectiongetSigners/ReflectionGetSigners.java b/test/testsuite/ouroboros/compact_test/RT0053-rt-compact-ReflectiongetSigners/ReflectionGetSigners.java new file mode 100755 index 0000000000..e3f7cea410 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0053-rt-compact-ReflectiongetSigners/ReflectionGetSigners.java @@ -0,0 +1,38 @@ +/* + *- @TestCaseID: ReflectionGetSigners + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetSigners.java + *- @Title/Destination: Gets the signers of this class. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetSigners类的运行时类clazz; + * -#step2: 通过getSigners()方法获取clazz的所有的标签并记为objects; + * -#step3: 确定step2中成功获取到objects,并且objects等于null; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetSigners.java + *- @ExecuteClass: ReflectionGetSigners + *- @ExecuteArgs: + */ + +class GetSigners { +} + +public class ReflectionGetSigners { + public static void main(String[] args) { + try { + Class clazz = Class.forName("GetSigners"); + Object[] objects = clazz.getSigners(); + if (objects == null) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0054-rt-compact-ReflectiongetSimpleName/ReflectionGetSimpleName.java b/test/testsuite/ouroboros/compact_test/RT0054-rt-compact-ReflectiongetSimpleName/ReflectionGetSimpleName.java new file mode 100755 index 0000000000..cca2066d3b --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0054-rt-compact-ReflectiongetSimpleName/ReflectionGetSimpleName.java @@ -0,0 +1,38 @@ +/* + *- @TestCaseID: ReflectionGetSimpleName + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetSimpleName.java + *- @Title/Destination: Returns the simple name of the underlying class as given in the source code. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetSimpleName类的运行时类clazz; + * -#step2: 通过getSimpleName()方法获取clazz的类名并记为string; + * -#step3: 确定step2中成功获取到string并且其类型与GetSimpleName类是同一类型; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetSimpleName.java + *- @ExecuteClass: ReflectionGetSimpleName + *- @ExecuteArgs: + */ + +class GetSimpleName { +} + +public class ReflectionGetSimpleName { + public static void main(String[] args) { + try { + Class clazz = Class.forName("GetSimpleName"); + String string = clazz.getSimpleName(); + if (string.equals("GetSimpleName")) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0055-rt-compact-ReflectiongetTypeParameters/ReflectionGetTypeParameters.java b/test/testsuite/ouroboros/compact_test/RT0055-rt-compact-ReflectiongetTypeParameters/ReflectionGetTypeParameters.java new file mode 100755 index 0000000000..1f32cb2557 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0055-rt-compact-ReflectiongetTypeParameters/ReflectionGetTypeParameters.java @@ -0,0 +1,43 @@ +/* + *- @TestCaseID: ReflectionGetTypeParameters + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionGetTypeParameters.java + *- @Title/Destination: getTypeParameters() returns an array of TypeVariable objects that represent the type variables + * declared by the generic declaration represented by this GenericDeclaration object, in + * declaration order. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetTypeParameters类的运行时类clazz; + * -#step2: 通过getTypeParameters()方法获取clazz的可变类型参数的数组并记为typeParameters; + * -#step3: 确定step2中成功获取到typeParameters,并且typeParameters的长度为2,其第一个参数与“s”相同,第二个参数与“T”相同; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionGetTypeParameters.java + *- @ExecuteClass: ReflectionGetTypeParameters + *- @ExecuteArgs: + */ + +import java.lang.reflect.TypeVariable; + +class GetTypeParameters { +} + +public class ReflectionGetTypeParameters { + public static void main(String[] args) { + try { + Class clazz = Class.forName("GetTypeParameters"); + TypeVariable[] typeParameters = clazz.getTypeParameters(); + if (typeParameters.length == 2 && typeParameters[0].getName().equals("s") + && typeParameters[1].getName().equals("T")) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0056-rt-compact-ReflectionisArray/ReflectionIsArray.java b/test/testsuite/ouroboros/compact_test/RT0056-rt-compact-ReflectionisArray/ReflectionIsArray.java new file mode 100755 index 0000000000..8b1e700235 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0056-rt-compact-ReflectionisArray/ReflectionIsArray.java @@ -0,0 +1,47 @@ +/* + *- @TestCaseID: ReflectionIsArray + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionIsArray.java + *- @Title/Destination: Determines if this Class object represents an array class. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取IsArray类的运行时类clazz; + * -#step2: 通过getDeclaredFields()方法获取clazz的所有的声明的字段并记为fields; + * -#step3: 通过fields.getClass()获取当前的运行时类并记为clazz1; + * -#step4: 确定step1和step3成功获取clazz和clazz1,并且clazz1是一个数组,而clazz不是一个数组。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionIsArray.java + *- @ExecuteClass: ReflectionIsArray + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class IsArray { + public int num; + String str; + float fNum; +} + +public class ReflectionIsArray { + public static void main(String[] args) { + try { + Class clazz = Class.forName("IsArray"); + Field[] fields = clazz.getDeclaredFields(); + Class clazz1 = fields.getClass(); + if (clazz1.isArray()) { + if (!clazz.isArray()) { + System.out.println(0); + } + } + } catch (ClassNotFoundException e) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0057-rt-compact-ReflectionisAssignableFrom1/ReflectionIsAssignableFrom1.java b/test/testsuite/ouroboros/compact_test/RT0057-rt-compact-ReflectionisAssignableFrom1/ReflectionIsAssignableFrom1.java new file mode 100755 index 0000000000..e54ba81b58 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0057-rt-compact-ReflectionisAssignableFrom1/ReflectionIsAssignableFrom1.java @@ -0,0 +1,51 @@ +/* + *- @TestCaseID: ReflectionIsAssignableFrom1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionIsAssignableFrom1.java + *- @Title/Destination: Class.isAssignableFrom(cls) return true when Class is superclass of cls. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法分别获取AssignableFrom1类、AssignableFrom1_a类、AssignableFromTest1类和 + * AssignableFromTest1_a类的运行时类并记为clazz1、clazz2、clazz3、clazz4; + * -#step2: 调用isAssignableFrom确定step1中成功获取到clazz1、clazz2、clazz3、clazz4并且clazz1是clazz2的父类,而clazz2不是 + * clazz1的父类;同理,clazz3是clazz4的父类,clazz4不是clazz3的父类; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionIsAssignableFrom1.java + *- @ExecuteClass: ReflectionIsAssignableFrom1 + *- @ExecuteArgs: + */ + +class AssignableFrom1 { +} + +class AssignableFrom1_a extends AssignableFrom1 { +} + +interface AssignableFromTest1 { +} + +interface AssignableFromTest1_a extends AssignableFromTest1 { +} + +public class ReflectionIsAssignableFrom1 { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("AssignableFrom1"); + Class clazz2 = Class.forName("AssignableFrom1_a"); + Class clazz3 = Class.forName("AssignableFromTest1"); + Class clazz4 = Class.forName("AssignableFromTest1_a"); + if (clazz1.isAssignableFrom(clazz2) && !clazz2.isAssignableFrom(clazz1) && clazz3.isAssignableFrom(clazz4) + && !clazz4.isAssignableFrom(clazz3)) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0058-rt-compact-ReflectionisAssignableFrom2/ReflectionIsAssignableFromNullPointerException.java b/test/testsuite/ouroboros/compact_test/RT0058-rt-compact-ReflectionisAssignableFrom2/ReflectionIsAssignableFromNullPointerException.java new file mode 100755 index 0000000000..5c4eaa62eb --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0058-rt-compact-ReflectionisAssignableFrom2/ReflectionIsAssignableFromNullPointerException.java @@ -0,0 +1,40 @@ +/* + *- @TestCaseID: ReflectionIsAssignableFromNullPointerException + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionIsAssignableFromNullPointerException.java + *- @Title/Destination: Class.isAssignableFrom(null) throws NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: Use classloader load class. + * -#step2: Test Class.isAssignableFrom() whit null param. + * -#step3: Check that NullPointerException occurs when Class.isAssignableFrom()'s is null. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionIsAssignableFromNullPointerException.java + *- @ExecuteClass: ReflectionIsAssignableFromNullPointerException + *- @ExecuteArgs: + */ + +class AssignableFromNullPointerException { +} + +public class ReflectionIsAssignableFromNullPointerException { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp1 = Class.forName("AssignableFromNullPointerException"); + zqp1.isAssignableFrom(null); + result = -1; + } catch (ClassNotFoundException e1) { + result = -1; + } catch (NullPointerException e2) { + result = 0; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0059-rt-compact-ReflectionisLocalClass/ReflectionIsLocalClass.java b/test/testsuite/ouroboros/compact_test/RT0059-rt-compact-ReflectionisLocalClass/ReflectionIsLocalClass.java new file mode 100755 index 0000000000..53c66b5044 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0059-rt-compact-ReflectionisLocalClass/ReflectionIsLocalClass.java @@ -0,0 +1,59 @@ +/* + *- @TestCaseID: ReflectionIsLocalClass + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionIsLocalClass.java + *- @Title/Destination: isLocalClass() returns true if and only if the underlying class is a local class(defined in the + * body of a method) + *- @Condition: no + *- @Brief:no: + * -#step1: Define a class in method and two class out of the method. + * -#step2: Get Class object of the class. + * -#step3: Test isLocalClass() with different the Class object of the class. + * -#step4: Check that isLocalClass() identifies local class correctly. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionIsLocalClass.java + *- @ExecuteClass: ReflectionIsLocalClass + *- @ExecuteArgs: + */ + +public class ReflectionIsLocalClass { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + class isLocalClass { + } + try { + Class zqp1 = isLocalClass.class; + Class zqp2 = Class.forName("ReflectionIsLocalClass"); + Class zqp3 = IsLocalClass_a.class; + Class zqp4 = IsLocalClass_b.class; + Class zqp5 = (new isLocalClass() { + }).getClass(); + if (!zqp2.isLocalClass()) { + if (!zqp3.isLocalClass()) { + if (!zqp4.isLocalClass()) { + if (!zqp5.isLocalClass()) { + if (zqp1.isLocalClass()) { + result = 0; + } + } + } + } + } + } catch (ClassNotFoundException e) { + result = 2; + } + System.out.println(result); + } + + class IsLocalClass_a { + } + + static class IsLocalClass_b { + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0060-rt-compact-ReflectionisMemberClass/ReflectionIsMemberClass.java b/test/testsuite/ouroboros/compact_test/RT0060-rt-compact-ReflectionisMemberClass/ReflectionIsMemberClass.java new file mode 100755 index 0000000000..86cd06217f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0060-rt-compact-ReflectionisMemberClass/ReflectionIsMemberClass.java @@ -0,0 +1,59 @@ +/* + *- @TestCaseID: ReflectionIsMemberClass + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionIsMemberClass.java + *- @Title/Destination: Class.IsMemberClass() returns true if and only if the underlying class is a member + * class(class inside another class, but not inside a method). + *- @Condition: no + *- @Brief:no: + * -#step1: Define a class in method and two inner class but not inside the method. + * -#step2: Get Class object of the class. + * -#step3: Test isMemberClass() with different the Class object of the class. + * -#step4: Check that isMemberClass() identifies member class correctly. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionIsMemberClass.java + *- @ExecuteClass: ReflectionIsMemberClass + *- @ExecuteArgs: + */ + +public class ReflectionIsMemberClass { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + class IsMemberClass_a { + } + try { + Class zqp1 = IsMemberClass.class; + Class zqp2 = Class.forName("ReflectionIsMemberClass"); + Class zqp3 = IsMemberClass_a.class; + Class zqp4 = IsMemberClass_b.class; + Class zqp5 = (new IsMemberClass_b() { + }).getClass(); + if (!zqp2.isMemberClass()) { + if (!zqp3.isMemberClass()) { + if (zqp4.isMemberClass()) { + if (!zqp5.isMemberClass()) { + if (zqp1.isMemberClass()) { + result = 0; + } + } + } + } + } + } catch (ClassNotFoundException e) { + result = -1; + } + System.out.println(result); + } + + class IsMemberClass { + } + + static class IsMemberClass_b { + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0061-rt-compact-ReflectionisPrimitive/ReflectionIsPrimitive.java b/test/testsuite/ouroboros/compact_test/RT0061-rt-compact-ReflectionisPrimitive/ReflectionIsPrimitive.java new file mode 100755 index 0000000000..f4fec72bc7 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0061-rt-compact-ReflectionisPrimitive/ReflectionIsPrimitive.java @@ -0,0 +1,44 @@ +/* + *- @TestCaseID: ReflectionIsPrimitive + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionIsPrimitive.java + *- @Title/Destination: Determines if the specified Class object represents a primitive type. + *- @Condition: no + *- @Brief:no: + * -#step1: Get nine Class Pre-defined object and a normal Class object of class. + * -#step2: Test isPrimitive() with the 10 primitive type object. + * -#step3: Check that isPrimitive() identifies primitive type of the object correctly. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionIsPrimitive.java + *- @ExecuteClass: ReflectionIsPrimitive + *- @ExecuteArgs: + */ + +public class ReflectionIsPrimitive { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + + Class zqp1 = ReflectionIsPrimitive.class; + Class zqp2 = int.class; + Class zqp3 = boolean.class; + Class zqp4 = byte.class; + Class zqp5 = char.class; + Class zqp6 = short.class; + Class zqp7 = long.class; + Class zqp8 = float.class; + Class zqp9 = double.class; + Class zqp10 = void.class; + if (!zqp1.isPrimitive() && zqp2.isPrimitive() && zqp3.isPrimitive() && zqp4.isPrimitive() && zqp5.isPrimitive() + && zqp6.isPrimitive() && zqp7.isPrimitive() && zqp8.isPrimitive() && zqp9.isPrimitive() && + zqp10.isPrimitive()) { + result = 0; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0062-rt-compact-ReflectionisSynthetic/ReflectionIsSynthetic.java b/test/testsuite/ouroboros/compact_test/RT0062-rt-compact-ReflectionisSynthetic/ReflectionIsSynthetic.java new file mode 100755 index 0000000000..cd53aba101 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0062-rt-compact-ReflectionisSynthetic/ReflectionIsSynthetic.java @@ -0,0 +1,46 @@ +/* + *- @TestCaseID: ReflectionIsSynthetic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionIsSynthetic.java + *- @Title/Destination: Returns true if this class is a synthetic class + *- @Condition: no + *- @Brief:no: + * -#step1: Define a test class IsSynthetic. + * -#step2: Test isSynthetic() with three different type object. + * -#step3: Check that isSynthetic() identifies synthetic class correctly. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionIsSynthetic.java + *- @ExecuteClass: ReflectionIsSynthetic + *- @ExecuteArgs: + */ + +public class ReflectionIsSynthetic { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + new IsSynthetic(); + try { + Class zqp1 = IsSynthetic.class; + Class zqp2 = int.class; + Class zqp3 = Class.forName("ReflectionIsSynthetic$1"); + if (!zqp2.isSynthetic()) { + if (!zqp1.isSynthetic()) { + if (zqp3.isSynthetic()) { + result = 0; + } + } + } + } catch (ClassNotFoundException e) { + result = -1; + } + System.out.println(result); + } + + private static class IsSynthetic { + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0063-rt-compact-ReflectionnewInstance1/ReflectionNewInstance1.java b/test/testsuite/ouroboros/compact_test/RT0063-rt-compact-ReflectionnewInstance1/ReflectionNewInstance1.java new file mode 100755 index 0000000000..2ed02e3c42 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0063-rt-compact-ReflectionnewInstance1/ReflectionNewInstance1.java @@ -0,0 +1,50 @@ +/* + *- @TestCaseID: ReflectionNewInstance1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionNewInstance1.java + *- @Title/Destination: Instantiating a class by reflection:class.newInstance() creates a new instance of the class + * represented by this Class object. The class is instantiated as if by a new expression with an + * empty argument list. + *- @Condition: no + *- @Brief:no: + * -#step1: Use classloader load class. + * -#step2: Instantiating the class by class.newInstance(). + * -#step3: Check that the object is instance of class NewInstance1 + * -#step4: Try to catch exceptions those occurs possibly. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionNewInstance1.java + *- @ExecuteClass: ReflectionNewInstance1 + *- @ExecuteArgs: + */ + +class NewInstance1 { +} + +public class ReflectionNewInstance1 { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp = Class.forName("NewInstance1"); + Object zhu = zqp.newInstance(); + if (zhu.toString().indexOf("NewInstance1@") != -1) { + result = 0; + } + } catch (ClassNotFoundException e) { + System.err.println(e); + result = -1; + } catch (InstantiationException e1) { + System.err.println(e1); + result = -1; + } catch (IllegalAccessException e2) { + System.err.println(e2); + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0064-rt-compact-ReflectionnewInstance2/ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java b/test/testsuite/ouroboros/compact_test/RT0064-rt-compact-ReflectionnewInstance2/ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java new file mode 100755 index 0000000000..1b68acca21 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0064-rt-compact-ReflectionnewInstance2/ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java @@ -0,0 +1,63 @@ +/* + *- @TestCaseID: ReflectionNewInstanceInstantiationExceptionIllegalAccessException + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java + *- @Title/Destination: call newInstance() on an interface object throws InstantiationException; if the class's + * constructor is not accessible, throws IllegalAccessException. + *- @Condition: no + *- @Brief:no: + * -#step1: Create a test class. + * -#step2: Use classloader to load class. + * -#step3: Instantiating the class by class.newInstance(). + * -#step4: It will throw InstantiationException because we used class which dose not exit. + * -#step5: Then check that IllegalAccessException was threw when class constructor is not accessible. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java + *- @ExecuteClass: ReflectionNewInstanceInstantiationExceptionIllegalAccessException + *- @ExecuteArgs: + */ + +interface NewInstance2 { +} + +class NewInstance2_a { + private NewInstance2_a() { + } +} + +public class ReflectionNewInstanceInstantiationExceptionIllegalAccessException { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp1 = Class.forName("NewInstance2"); + Object zhu1 = zqp1.newInstance(); + } catch (ClassNotFoundException e) { + System.err.println(e); + result = -1; + } catch (InstantiationException e1) { + + try { + Class zqp2 = Class.forName("NewInstance2_a"); + Object zhu2 = zqp2.newInstance(); + } catch (ClassNotFoundException e3) { + System.err.println(e3); + result = -1; + } catch (InstantiationException e4) { + System.err.println(e4); + result = -1; + } catch (IllegalAccessException e5) { + result = 0; + } + } catch (IllegalAccessException e2) { + System.err.println(e2); + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0065-rt-compact-ReflectiontoGenericString/ReflectionToGenericString.java b/test/testsuite/ouroboros/compact_test/RT0065-rt-compact-ReflectiontoGenericString/ReflectionToGenericString.java new file mode 100755 index 0000000000..2e4400cb12 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0065-rt-compact-ReflectiontoGenericString/ReflectionToGenericString.java @@ -0,0 +1,46 @@ +/* + *- @TestCaseID: ReflectionToGenericString + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionToGenericString.java + *- @Title/Destination: getGenericString() returns a string description of this class, including information about + * modifiers and type parameters. + *- @Condition: no + *- @Brief:no: + * -#step1: Create a abstract test class. + * -#step2: Use classloader to load class. + * -#step3: Test getGenericString() with Class object of the test class. + * -#step4: Check that getGenericString() returns a string description of class information correctly. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionToGenericString.java + *- @ExecuteClass: ReflectionToGenericString + *- @ExecuteArgs: + */ + +@interface Eee { +} + +@Eee +abstract class ToGenericString { +} + +public class ReflectionToGenericString { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp = Class.forName("ToGenericString"); + String zhu = zqp.toGenericString(); + if (zhu.equals("abstract class ToGenericString")) { + result = 0; + } + } catch (ClassNotFoundException e) { + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0066-rt-compact-ReflectiontoString/ReflectionToString.java b/test/testsuite/ouroboros/compact_test/RT0066-rt-compact-ReflectiontoString/ReflectionToString.java new file mode 100755 index 0000000000..52e1e762a4 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0066-rt-compact-ReflectiontoString/ReflectionToString.java @@ -0,0 +1,45 @@ +/* + *- @TestCaseID: ReflectionToString + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionToString.java + *- @Title/Destination: To obtain a class for string output by reflection. + *- @Condition: no + *- @Brief:no: + * -#step1: Create a test class. + * -#step2: Use classloader to load class. + * -#step3: Test toString() by reflection. + * -#step4: Check that reflection result is correct. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionToString.java + *- @ExecuteClass: ReflectionToString + *- @ExecuteArgs: + */ + +@interface Fff { +} + +@Fff +abstract class ToString_$ { +} + +public class ReflectionToString { + public static void main(String[] args) { + int result = 0; /* STATUS_Success */ + try { + Class zqp = Class.forName("ToString_$"); + String zhu = zqp.toString(); + if (zhu.equals("class ToString_$")) { + result = 0; + } + } catch (ClassNotFoundException e) { + result = -1; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0067-rt-compact-RTConstructorgetAnnotation1/RTConstructorGetAnnotation1.java b/test/testsuite/ouroboros/compact_test/RT0067-rt-compact-RTConstructorgetAnnotation1/RTConstructorGetAnnotation1.java new file mode 100755 index 0000000000..dd151fc0f0 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0067-rt-compact-RTConstructorgetAnnotation1/RTConstructorGetAnnotation1.java @@ -0,0 +1,87 @@ +/* + *- @TestCaseID: RTConstructorGetAnnotation1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTConstructorGetAnnotation1.java + *- @Title/Destination: Use Constructor.getAnnotation() to get the annotation of the target class's constructor by + * reflection. + *- @Condition: no + *- @Brief:no: + * -#step1: Create a class include four constructors with annotation or without. + * -#step2: Use classloader to load class. + * -#step3: Get constructors by getConstructor() and getDeclaredConstructor(Class... parameterTypes) and + * getConstructor(Class... parameterTypes). + * -#step4: Constructor object get the get the annotation of the target class's constructor by calling + * getAnnotation(Class annotationClass) + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTConstructorGetAnnotation1.java + *- @ExecuteClass: RTConstructorGetAnnotation1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; + +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Www1 { + int i() default 0; + + String t() default ""; +} + +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface Www1_a { + int c() default 0; + + String d() default ""; +} + +class ConstructorGetAnnotation1 { + @Www1(i = 333, t = "ConstructorgetAnnotation") + public ConstructorGetAnnotation1() { + } + + public ConstructorGetAnnotation1(String name) { + } + + @Www1_a(c = 666, d = "Constructor") + ConstructorGetAnnotation1(int number) { + } + + ConstructorGetAnnotation1(String name, int number) { + } +} + +public class RTConstructorGetAnnotation1 { + public static void main(String[] args) { + try { + Class zqp = Class.forName("ConstructorGetAnnotation1"); + Constructor zhu1 = zqp.getDeclaredConstructor(int.class); + Constructor zhu2 = zqp.getConstructor(); + Constructor zhu3 = zqp.getConstructor(String.class); + if ((zhu1.getAnnotation(Www1_a.class).toString().indexOf("c=666") != -1 && + zhu1.getAnnotation(Www1_a.class).toString().indexOf("d=Constructor") != -1 && + zhu2.getAnnotation(Www1.class).toString().indexOf("i=333") != -1 && + zhu2.getAnnotation(Www1.class).toString().indexOf("t=ConstructorgetAnnotation") != -1)) { + if (zhu3.getAnnotation(Www1.class) == null) { + System.out.println(0); + } + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0068-rt-compact-RTConstructorgetAnnotation2/RTConstructorGetAnnotation2.java b/test/testsuite/ouroboros/compact_test/RT0068-rt-compact-RTConstructorgetAnnotation2/RTConstructorGetAnnotation2.java new file mode 100755 index 0000000000..f968b325b6 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0068-rt-compact-RTConstructorgetAnnotation2/RTConstructorGetAnnotation2.java @@ -0,0 +1,102 @@ +/* + *- @TestCaseID: RTConstructorGetAnnotation2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTConstructorGetAnnotation2.java + *- @Title/Destination: When try to get annotation of target class's constructor by reflection and the annotation does + * not exist, Constructor.getAnnotation() throws NullPointerException. + *- @Condition: no + *- @Brief:no + * -#step1: 定义类1有含注解的构造方法,类2有无注解的构造方法。 + * -#step2:通过Class.forName获取类1的class。 + * -#step3:通过getDeclaredConstructor(Class... parameterTypes)获取构造方法1,通过getConstructor()获取无参构造方法2、 + * -#step4:构造方法1,2调用getAnnotation(Class annotationClass),annotationClass为不匹配的注解类型,判断返回的注解为空。 + * -#step5:通过Class.forName获取类2的class。 + * -#step6:通过getDeclaredConstructor(Class... parameterTypes)获取构造方法3。 + * -#step7:构造方法3调用getAnnotation(Class annotationClass),annotationClass为注解类型,判断返回的注解为空。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTConstructorGetAnnotation2.java + *- @ExecuteClass: RTConstructorGetAnnotation2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; + +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF2 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF2_a { + int c() default 0; + String d() default ""; +} + +class ConstructorGetAnnotation2 { + @IF2(i = 333, t = "ConstructorGetAnnotation") + public ConstructorGetAnnotation2() { + } + + @IF2_a(c = 666, d = "Constructor") + ConstructorGetAnnotation2(int number) { + } +} + +class ConstructorGetAnnotation2_a { + ConstructorGetAnnotation2_a(String name, int number) { + } +} + +public class RTConstructorGetAnnotation2 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ConstructorGetAnnotation2"); + Constructor instance1 = cls.getDeclaredConstructor(int.class); + Constructor instance2 = cls.getConstructor(); + if (instance1.getAnnotation(IF2.class) == null && instance2.getAnnotation(IF2_a.class) == null) { + instance1.getAnnotation(IF2.class).toString(); + } + System.out.println(1); + return; + } catch (ClassNotFoundException e1) { + System.out.println(1); + return; + } catch (NoSuchMethodException e2) { + System.out.println(1); + return; + } catch (NullPointerException e3) { + try { + Class cls = Class.forName("ConstructorGetAnnotation2_a"); + Constructor instance3 = cls.getDeclaredConstructor(String.class, int.class); + if (instance3.getAnnotation(IF2.class) == null && instance3.getAnnotation(IF2_a.class) == null) { + instance3.getAnnotation(IF2.class).toString(); + } + System.out.println(1); + return; + } catch (ClassNotFoundException e4) { + System.out.println(2); + return; + } catch (NoSuchMethodException e5) { + System.out.println(3); + return; + } catch (NullPointerException e6) { + System.out.println(0); + return; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0069-rt-compact-RTConstructorgetDeclaredAnnotations1/RTConstructorGetDeclaredAnnotations1.java b/test/testsuite/ouroboros/compact_test/RT0069-rt-compact-RTConstructorgetDeclaredAnnotations1/RTConstructorGetDeclaredAnnotations1.java new file mode 100755 index 0000000000..716cbc2e42 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0069-rt-compact-RTConstructorgetDeclaredAnnotations1/RTConstructorGetDeclaredAnnotations1.java @@ -0,0 +1,101 @@ +/* + *- @TestCaseID: RTConstructorGetDeclaredAnnotations1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTConstructorGetDeclaredAnnotations1.java + *- @Title/Destination: Use Constructor.getDeclaredAnnotations() To obtain all annotations for constructor of the target + * class by reflection. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义两个类,有父子关系,都含有注解的构造方法。 + * -#step2:调用getConstructor(Class... parameterTypes)从子类中获取有两个注解的构造方法。 + * -#step3:调用getDeclaredAnnotations()获取注解数组,判断数组长度为2。 + * -#step4:调用getConstructor(Class... parameterTypes)从子类中获取有一个注解的构造方法。 + * -#step5:调用getDeclaredAnnotations()获取注解数组,判断数组长度为1,获取注解成员正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTConstructorGetDeclaredAnnotations1.java + *- @ExecuteClass: RTConstructorGetDeclaredAnnotations1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; + +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF1 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF1_a { + int i_a() default 2; + String t_a() default ""; +} + +class ConstructorGetDeclaredAnnotations1 { + public ConstructorGetDeclaredAnnotations1() { + } + + @IF1(i = 333, t = "test1") + public ConstructorGetDeclaredAnnotations1(String name) { + } + + @IF1(i = 333, t = "test1") + ConstructorGetDeclaredAnnotations1(int number) { + } +} + +class ConstructorGetDeclaredAnnotations1_a extends ConstructorGetDeclaredAnnotations1 { + @IF1_a(i_a = 666, t_a = "right1") + @IF1(i = 333, t = "test1") + public ConstructorGetDeclaredAnnotations1_a(String name) { + } + + @IF1_a(i_a = 666, t_a = "right1") + ConstructorGetDeclaredAnnotations1_a(int number) { + } +} + +public class RTConstructorGetDeclaredAnnotations1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ConstructorGetDeclaredAnnotations1_a"); + Constructor instance1 = cls.getConstructor(String.class); + if (instance1.getDeclaredAnnotations().length == 2) { + Constructor instance2 = cls.getDeclaredConstructor(int.class); + if (instance2.getDeclaredAnnotations().length == 1) { + Annotation[] j = instance2.getDeclaredAnnotations(); + if (j[0].toString().indexOf("i_a=666") != -1 && j[0].toString().indexOf("t_a=right1") != -1) { + System.out.println(0); + return; + } + } + System.out.println(1); + return; + } + System.out.println(2); + return; + } catch (ClassNotFoundException e) { + System.out.println(3); + return; + } catch (NoSuchMethodException e1) { + System.out.println(4); + return; + } catch (NullPointerException e2) { + System.out.println(5); + return; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0070-rt-compact-RTConstructorgetDeclaredAnnotations2/RTConstructorGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/compact_test/RT0070-rt-compact-RTConstructorgetDeclaredAnnotations2/RTConstructorGetDeclaredAnnotations2.java new file mode 100755 index 0000000000..42176d5649 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0070-rt-compact-RTConstructorgetDeclaredAnnotations2/RTConstructorGetDeclaredAnnotations2.java @@ -0,0 +1,90 @@ +/* + *- @TestCaseID: RTConstructorGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTConstructorGetDeclaredAnnotations2.java + *- @Title/Destination: Constructor.getDeclaredAnnotations() does not return annotations inherited from parent class. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义两个类,有父子关系,父类含有注解的构造方法,子类的构造方法没有注解。 + * -#step2:调用getConstructor(Class... parameterTypes)从子类中获取构造方法1。 + * -#step3:调用getDeclaredAnnotations()获取注解数组,判断数组长度为0。 + * -#step4:调用getConstructor(Class... parameterTypes)从子类中获取构造方法2。 + * -#step5:调用getDeclaredAnnotations()获取注解数组,判断数组长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTConstructorGetDeclaredAnnotations2.java + *- @ExecuteClass: RTConstructorGetDeclaredAnnotations2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; + +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF2 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF2_a { + int i_a() default 2; + String t_a() default ""; +} + +class ConstructorGetDeclaredAnnotations2 { + public ConstructorGetDeclaredAnnotations2() { + } + + @IF2(i = 333, t = "test1") + public ConstructorGetDeclaredAnnotations2(String name) { + } + + @IF2(i = 333, t = "test1") + ConstructorGetDeclaredAnnotations2(int number) { + } +} + +class ConstructorGetDeclaredAnnotations2_a extends ConstructorGetDeclaredAnnotations2 { + public ConstructorGetDeclaredAnnotations2_a(String name) { + } + + ConstructorGetDeclaredAnnotations2_a(int number) { + } +} + +public class RTConstructorGetDeclaredAnnotations2 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ConstructorGetDeclaredAnnotations2_a"); + Constructor instance1 = cls.getConstructor(String.class); + Constructor instance2 = cls.getDeclaredConstructor(int.class); + if (instance1.getDeclaredAnnotations().length == 0 && instance2.getDeclaredAnnotations().length == 0) { + System.out.println(0); + return; + } + System.out.println(1); + return; + } catch (ClassNotFoundException e) { + System.out.println(2); + return; + } catch (NoSuchMethodException e1) { + System.out.println(3); + return; + } catch (NullPointerException e2) { + System.out.println(4); + return; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0071-rt-compact-RTConstructorgetExceptionTypes/RTConstructorGetExceptionTypes.java b/test/testsuite/ouroboros/compact_test/RT0071-rt-compact-RTConstructorgetExceptionTypes/RTConstructorGetExceptionTypes.java new file mode 100755 index 0000000000..459955fe86 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0071-rt-compact-RTConstructorgetExceptionTypes/RTConstructorGetExceptionTypes.java @@ -0,0 +1,53 @@ +/* + *- @TestCaseID: RTConstructorGetExceptionTypes + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTConstructorGetExceptionTypes.java + *- @Title/Destination: Constructor.getExceptionTypes() returns an array of Class objects that represent the types of + * exceptions declared to be thrown by the underlying executable represented by this object. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义一个类含有构造方法。 + * -#step2:调用Class.forName获取相应的class. + * -#step3: 使用class调用getDeclaredConstructor()获取相应的构造方法。 + * -#step4:使用构造方法调用getExceptionTypes()获取异常类型的Class对象数组。 + * -#step5:判断数组长度为2。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTConstructorGetExceptionTypes.java + *- @ExecuteClass: RTConstructorGetExceptionTypes + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +class ConstructorGetExceptionTypes { + ConstructorGetExceptionTypes() throws ExceptionInInitializerError, InstantiationException { + } +} + +public class RTConstructorGetExceptionTypes { + public static void main(String[] args) { + try { + Class cls = Class.forName("ConstructorGetExceptionTypes"); + Constructor cons = cls.getDeclaredConstructor(); + Class[] exClass = cons.getExceptionTypes(); + if (exClass.length == 2) { + System.out.println(0); + return; + } + System.out.println(1); + return; + } catch (ClassNotFoundException e1) { + System.out.println(2); + return; + } catch (NoSuchMethodException e2) { + System.out.println(3); + return; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0072-rt-compact-RTConstructorgetTypeParameters/RTConstructorGetTypeParameters.java b/test/testsuite/ouroboros/compact_test/RT0072-rt-compact-RTConstructorgetTypeParameters/RTConstructorGetTypeParameters.java new file mode 100755 index 0000000000..1986ab6367 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0072-rt-compact-RTConstructorgetTypeParameters/RTConstructorGetTypeParameters.java @@ -0,0 +1,61 @@ +/* + *- @TestCaseID: RTConstructorGetTypeParameters + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTConstructorGetTypeParameters.java + *- @Title/Destination: Constructor.getTypeParameters() Returns an array of TypeVariable objects that represent the type + * variables declared by the generic declaration represented by this GenericDeclaration object, in + * declaration order. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义一个类,含有类型变量的有参构造方法和无参的构造方法。 + * -#step2:调用Class.forName获取相应的class. + * -#step3:使用class调用getConstructor(Class... parameterTypes)从类中获取含有类型变量的构造方法1。 + * -#step4:调用getTypeParameters()获取TypeVariable数组,确认数组长度为5。 + * -#step5:使用class调用getDeclaredConstructor()从类中获取无参的构造方法。 + * -#step6:调用getTypeParameters()获取TypeVariable数组,确认数组长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTConstructorGetTypeParameters.java + *- @ExecuteClass: RTConstructorGetTypeParameters + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; +import java.lang.reflect.TypeVariable; + +class ConstructorGetTypeParameters { + public ConstructorGetTypeParameters(int number) { + } + + ConstructorGetTypeParameters() { + } +} + +public class RTConstructorGetTypeParameters { + public static void main(String[] args) { + try { + Class cls = Class.forName("ConstructorGetTypeParameters"); + Constructor instance1 = cls.getConstructor(int.class); + Constructor instance2 = cls.getDeclaredConstructor(); + TypeVariable[] q1 = instance1.getTypeParameters(); + TypeVariable[] q2 = instance2.getTypeParameters(); + if (q1.length == 5 && q2.length == 0) { + System.out.println(0); + return; + } + System.out.println(1); + return; + } catch (ClassNotFoundException e1) { + System.out.println(2); + return; + } catch (NoSuchMethodException e2) { + System.out.println(3); + return; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0073-rt-compact-RTConstructortoGenericString/RTConstructorToGenericString1.java b/test/testsuite/ouroboros/compact_test/RT0073-rt-compact-RTConstructortoGenericString/RTConstructorToGenericString1.java new file mode 100755 index 0000000000..476273cf68 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0073-rt-compact-RTConstructortoGenericString/RTConstructorToGenericString1.java @@ -0,0 +1,52 @@ +/* + *- @TestCaseID: RTConstructorToGenericString + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTConstructorToGenericString1.java + *- @Title/Destination: Constructor.ToGenericString() returns a string describing this Constructor, including type + * parameters. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义一个类,含有类型变量的有参构造方法。 + * -#step2:调用Class.forName获取相应的class. + * -#step3:使用class调用getConstructor(Class... parameterTypes)从类中获取含有类型变量的构造方法。 + * -#step4:调用toGenericString()获取描述此Method的字符串。 + * -#step5:确认返回的描述正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTConstructorToGenericString1.java + *- @ExecuteClass: RTConstructorToGenericString1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +class ConstructorToGenericString1 { + public ConstructorToGenericString1(int number) { + } +} + +public class RTConstructorToGenericString1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ConstructorToGenericString1"); + Constructor instance1 = cls.getConstructor(int.class); + if (instance1.toGenericString().equals("public ConstructorToGenericString1(int)")) { + System.out.println(0); + return; + } + } catch (ClassNotFoundException e1) { + System.out.println(1); + return; + } catch (NoSuchMethodException e2) { + System.out.println(2); + return; + } + System.out.println(3); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0074-rt-compact-RTFieldget1/RTFieldGet1.java b/test/testsuite/ouroboros/compact_test/RT0074-rt-compact-RTFieldget1/RTFieldGet1.java new file mode 100755 index 0000000000..8d754fb294 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0074-rt-compact-RTFieldget1/RTFieldGet1.java @@ -0,0 +1,76 @@ +/* + *- @TestCaseID: RTFieldGet1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGet1.java + *- @Title/Destination: Field.get() returns the value of the field represented by this field on the target object. + *- @Condition: no + *- @Brief:no: + * -#step1: 创建类FieldGet1_a和它的子类FieldGet1。 + * -#step2:通过forName()方法加载FieldGet1并调用newInstance()生成实例对象。 + * -#step3:通过getField()方法获取实例对象中的成员变量,并确认值正确。 + * -#step4:通过forName()方法加载FieldGet1_a并生成实例对象,通过getField()方法获取对应的成员变量并核对值正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGet1.java + *- @ExecuteClass: RTFieldGet1 + *- @ExecuteArgs: + */ + +class FieldGet1_a { + public static String str = "aaa"; + public int num = 2; + public int num1 = 5; + public static boolean aBoolean = false; +} + +class FieldGet1 extends FieldGet1_a { + public static String str = "bbb"; + public int number = 1; + public int test = super.num1 + 1; + public static boolean bBoolean = true; + public char aChar = '国'; +} + +public class RTFieldGet1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldGet1"); + Object obj = cls.newInstance(); + Object q1 = cls.getField("str").get(obj); + Object q2 = cls.getField("number").get(obj); + Object q3 = cls.getField("test").get(obj); + Object q4 = cls.getField("bBoolean").get(obj); + Object q5 = cls.getField("aChar").get(obj); + Object q6 = cls.getField("num").get(obj); + Object q7 = cls.getField("aBoolean").get(null); + if (q1.toString().equals("bbb") && (int) q2 == 1 && (int) q3 == 6 && (boolean) q4 && q5.toString(). + equals("国") && (int) q6 == 2) { + Class cls1 = Class.forName("FieldGet1_a"); + Object instance1 = cls1.newInstance(); + Object q8 = cls1.getField("str").get(instance1); + if (q8.toString().equals("aaa")) { + if (!(boolean) q7) { + System.out.println(0); + } + } + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (InstantiationException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NoSuchFieldException e3) { + System.err.println(e3); + System.out.println(2); + } catch (IllegalAccessException e4) { + System.err.println(e4); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0075-rt-compact-RTFieldget2/RTFieldGet2.java b/test/testsuite/ouroboros/compact_test/RT0075-rt-compact-RTFieldget2/RTFieldGet2.java new file mode 100755 index 0000000000..43a3481f6c --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0075-rt-compact-RTFieldget2/RTFieldGet2.java @@ -0,0 +1,94 @@ +/* + *- @TestCaseID: RTFieldGet2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGet2.java + *- @Title/Destination: Field.get throws IllegalAccessException when the Field is inaccessible; throws + * IllegalArgumentException when the object is not an instance of the class; Field.get(null) throws + * NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: 创建类FieldGet2_a,FieldGet2_a的子类FieldGet2且含有私有成员变量,定义FieldGet2_b。 + * -#step2:通过forName()方法加载FieldGet2并调用newInstance()生成实例对象。 + * -#step3:通过getDeclaredField()方法获取FieldGet2中的私有变量,确认会抛出IllegalAccessException。 + * -#step4:加载FieldGet2实例对象,通过getDeclaredField()方法获取public变量域,构造FieldGet2_b实例,并取对应变量域值。 + * -#step5:确认会抛出IllegalArgumentException异常,通过getDeclaredField()方法获取FieldGet2的public变量域。 + * -#step6:调用get(Object obj)方法,obj为NULL,确认NullPointerException抛出。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGet2.java + *- @ExecuteClass: RTFieldGet2 + *- @ExecuteArgs: + */ + +class FieldGet2_a { + public int num; +} + +class FieldGet2 extends FieldGet2_a { + private int number = 1; + public boolean aBoolean = true; + public int number1 = 8; +} + +class FieldGet2_b { + public int number1 = 18; +} + +public class RTFieldGet2 { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldGet2"); + Object obj = cls.newInstance(); + Object q1 = cls.getDeclaredField("number").get(obj); + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (InstantiationException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NoSuchFieldException e3) { + System.err.println(e3); + System.out.println(2); + } catch (IllegalAccessException e4) { + try { + Class cls = Class.forName("FieldGet2"); + Class cls1 = Class.forName("FieldGet2_b"); + Object instance1 = cls1.newInstance(); + Object q2 = cls.getDeclaredField("number1").get(instance1); + } catch (ClassNotFoundException e5) { + System.err.println(e5); + System.out.println(2); + } catch (InstantiationException e6) { + System.err.println(e6); + System.out.println(2); + } catch (NoSuchFieldException e7) { + System.err.println(e7); + System.out.println(2); + } catch (IllegalAccessException e8) { + System.err.println(e8); + System.out.println(2); + } catch (IllegalArgumentException e9) { + try { + Class cls = Class.forName("FieldGet2"); + Object q3 = cls.getDeclaredField("aBoolean").get(null); + } catch (ClassNotFoundException e10) { + System.err.println(e10); + System.out.println(2); + } catch (NoSuchFieldException e11) { + System.err.println(e11); + System.out.println(2); + } catch (IllegalAccessException e12) { + System.err.println(e12); + System.out.println(2); + } catch (NullPointerException e13) { + System.out.println(0); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0076-rt-compact-RTFieldget3/RTFieldGet3.java b/test/testsuite/ouroboros/compact_test/RT0076-rt-compact-RTFieldget3/RTFieldGet3.java new file mode 100755 index 0000000000..53c4f6eca6 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0076-rt-compact-RTFieldget3/RTFieldGet3.java @@ -0,0 +1,56 @@ +/* + *- @TestCaseID: RTFieldGet3 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGet3.java + *- @Title/Destination: If the filed is not given a value, the default value is returned by reflection。 + *- @Condition: no + *- @Brief:no: + * -#step1: 定义类FieldGet3_a,定义FieldGet3_a的子类FieldGet3。 + * -#step2: 通过调用forName()方法加载类FieldGet3,调用newInstance()生产实例对象。 + * -#step3: 通过调用getField()获取对应名称的未初始化的成员变量。 + * -#step4: 调用get(Object obj)方法作出判断,确认String类型为null,int类型为0。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGet3.java + *- @ExecuteClass: RTFieldGet3 + *- @ExecuteArgs: + */ + +class FieldGet3_a { + public int num; +} + +class FieldGet3 extends FieldGet3_a { + public static String str; +} + +public class RTFieldGet3 { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldGet3"); + Object obj = cls.newInstance(); + Object obj1 = cls.getField("str").get(obj); + Object obj2 = cls.getField("num").get(obj); + if (obj1 == null && (int) obj2 == 0) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (InstantiationException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NoSuchFieldException e3) { + System.err.println(e3); + System.out.println(2); + } catch (IllegalAccessException e4) { + System.err.println(e4); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0077-rt-compact-RTFieldgetAnnotation/RTFieldGetAnnotation1.java b/test/testsuite/ouroboros/compact_test/RT0077-rt-compact-RTFieldgetAnnotation/RTFieldGetAnnotation1.java new file mode 100755 index 0000000000..8dd5ba9d62 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0077-rt-compact-RTFieldgetAnnotation/RTFieldGetAnnotation1.java @@ -0,0 +1,70 @@ +/* + *- @TestCaseID: RTFieldGetAnnotation1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGetAnnotation1.java + *- @Title/Destination: Field.GetAnnotation() returns null when the expected annotation is not present. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含注解类FieldGetAnnotation1。 + * -#step2: 通过调用forName()方法加载类FieldGetAnnotation1。 + * -#step3: 通过调用getField()获取对应名称的成员变量。 + * -#step4: 调用getAnnotation(Class annotationClass),annotationClass为不匹配的类型,确认返回null。 + * -#step5: 调用返回空注解类型进行.number()的调用,确认抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGetAnnotation1.java + *- @ExecuteClass: RTFieldGetAnnotation1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface interface4 { + int num() default 0; + String str() default ""; +} + +@interface interface4_a { + int number() default 0; + String string() default ""; +} + +class FieldGetAnnotation1 { + @interface4(num = 333, str = "GetAnnotation") + public int num1; + @interface4_a(number = 555, string = "test") + public String str1; +} + +public class RTFieldGetAnnotation1 { + public static void main(String[] args) { + try { + Class cls1 = Class.forName("FieldGetAnnotation1"); + Field instance1 = cls1.getField("num1"); + Field instance2 = cls1.getField("str1"); + if (instance1.getAnnotation(interface4_a.class) == null && instance2.getAnnotation(interface4.class) == null) + { + instance1.getAnnotation(interface4_a.class).number(); + } + System.out.println(2); + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchFieldException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0078-rt-compact-RTFieldgetDeclaredAnnotations1/RTFieldGetDeclaredAnnotations1.java b/test/testsuite/ouroboros/compact_test/RT0078-rt-compact-RTFieldgetDeclaredAnnotations1/RTFieldGetDeclaredAnnotations1.java new file mode 100755 index 0000000000..7d1f452f9a --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0078-rt-compact-RTFieldgetDeclaredAnnotations1/RTFieldGetDeclaredAnnotations1.java @@ -0,0 +1,90 @@ +/* + *- @TestCaseID: RTFieldGetDeclaredAnnotations1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGetDeclaredAnnotations1.java + *- @Title/Destination: Field.GetDeclaredAnnotations() returns annotations that are directly present on this element. + * This method ignores inherited annotations. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含注解类FieldGetDeclaredAnnotations1,定义含注解的类FieldGetDeclaredAnnotations1的子类 + * FieldGetDeclaredAnnotations1_a。 + * -#step2: 通过调用forName()方法加载类FieldGetDeclaredAnnotations1_a。 + * -#step3: 通过调用getField()获取对应名称的成员变量。 + * -#step4: 通过调用getAnnotation(Class annotationClass)获取注解,调用indexOf()方法进行判断获取正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGetDeclaredAnnotations1.java + *- @ExecuteClass: RTFieldGetDeclaredAnnotations1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface interface1 { + int num() default 0; + String str() default ""; +} + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface interface1_a { + int num_a() default 2; + String str_a() default ""; +} + +class FieldGetDeclaredAnnotations1 { + @interface1(num = 333, str = "test1") + public int num; + @interface1(num = 333, str = "test1") + public String str; +} + +class FieldGetDeclaredAnnotations1_a extends FieldGetDeclaredAnnotations1 { + @interface1_a(num_a = 666, str_a = "right1") + public int num; + @interface1_a(num_a = 666, str_a = "right1") + public String str; +} + +public class RTFieldGetDeclaredAnnotations1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldGetDeclaredAnnotations1_a"); + Field instance1 = cls.getField("num"); + if (instance1.getDeclaredAnnotations().length == 1) { + Annotation[] j = instance1.getDeclaredAnnotations(); + if (j[0].toString().indexOf("num_a=666") != -1 && j[0].toString().indexOf("str_a=right1") != -1) { + Field instance2 = cls.getDeclaredField("str"); + if (instance2.getDeclaredAnnotations().length == 1) { + Annotation[] k = instance2.getDeclaredAnnotations(); + if (k[0].toString().indexOf("num_a=666") != -1 && k[0].toString().indexOf("str_a=right1") != -1) + { + System.out.println(0); + } + } + } + } + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchFieldException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0079-rt-compact-RTFieldgetDeclaredAnnotations2/RTFieldGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/compact_test/RT0079-rt-compact-RTFieldgetDeclaredAnnotations2/RTFieldGetDeclaredAnnotations2.java new file mode 100755 index 0000000000..57f25c07fb --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0079-rt-compact-RTFieldgetDeclaredAnnotations2/RTFieldGetDeclaredAnnotations2.java @@ -0,0 +1,79 @@ +/* + *- @TestCaseID: RTFieldGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGetDeclaredAnnotations2.java + *- @Title/Destination: Field.GetDeclaredAnnotations() ignores inherited annotations. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含注解类FieldGetDeclaredAnnotations2,定义含注解的类FieldGetDeclaredAnnotations2的子类 + * FieldGetDeclaredAnnotations2_a。 + * -#step2: 通过调用forName()方法加载类FieldGetDeclaredAnnotations2_a。 + * -#step3: 通过调用 getField()获取对应名称的成员变量。 + * -#step4: 通过调用getAnnotation(Class annotationClass)获取注解,调用equals()方法进行判断获取正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGetDeclaredAnnotations2.java + *- @ExecuteClass: RTFieldGetDeclaredAnnotations2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface interface2 { + int num() default 0; + String str() default ""; +} + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface interface2_a { + int i_a() default 2; + String t_a() default ""; +} + +class FieldGetDeclaredAnnotations2 { + @interface2(num = 333, str = "test1") + public int num; + @interface2(num = 333, str = "test1") + public String str; +} + +class FieldGetDeclaredAnnotations2_a extends FieldGetDeclaredAnnotations2 { + @interface2_a(i_a = 666, t_a = "right1") + public int num; + public String str; +} + +public class RTFieldGetDeclaredAnnotations2 { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldGetDeclaredAnnotations2_a"); + Field instance1 = cls.getField("str"); + Field instance2 = cls.getDeclaredField("str"); + if (instance1.getDeclaredAnnotations().length == 0 && instance2.getDeclaredAnnotations().length == 0) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchFieldException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0080-rt-compact-RTFieldgetDeclaringClass/RTFieldGetDeclaringClass.java b/test/testsuite/ouroboros/compact_test/RT0080-rt-compact-RTFieldgetDeclaringClass/RTFieldGetDeclaringClass.java new file mode 100755 index 0000000000..1caca41b1d --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0080-rt-compact-RTFieldgetDeclaringClass/RTFieldGetDeclaringClass.java @@ -0,0 +1,51 @@ +/* + *- @TestCaseID: RTFieldGetDeclaringClass + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGetDeclaringClass.java + *- @Title/Destination: Field.GetDeclaringClass() returns the class object of the class declaring the field represented + * by this Field object. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义类FieldGetDeclaringClass。 + * -#step2: 通过调用forName()方法加载类FieldGetDeclaringClass。 + * -#step3: 通过调用 getField()、getDeclaredField()获取对应名称的成员变量。 + * -#step4: 通过调用FieldGetDeclaringClass()获取类对象,调用equals()方法进行判断获取正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGetDeclaringClass.java + *- @ExecuteClass: RTFieldGetDeclaringClass + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class FieldGetDeclaringClass { + public int num; + char aChar; +} + +public class RTFieldGetDeclaringClass { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldGetDeclaringClass"); + Field instance1 = cls.getField("num"); + Field instance2 = cls.getDeclaredField("aChar"); + Class j = instance1.getDeclaringClass(); + Class k = instance2.getDeclaringClass(); + if (j.getName().equals("FieldGetDeclaringClass") && k.getName().equals("FieldGetDeclaringClass")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchFieldException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0081-rt-compact-RTFieldgetModifiers/RTFieldGetModifiers.java b/test/testsuite/ouroboros/compact_test/RT0081-rt-compact-RTFieldgetModifiers/RTFieldGetModifiers.java new file mode 100755 index 0000000000..a1ec1905ae --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0081-rt-compact-RTFieldgetModifiers/RTFieldGetModifiers.java @@ -0,0 +1,55 @@ +/* + *- @TestCaseID: RTFieldGetModifiers + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGetModifiers.java + *- @Title/Destination: Field.GetModifiers() Returns the Java language modifiers for the field represented by this Field + * object, as an integer. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含受保护的今天成员变量的类FieldGetModifiers。 + * -#step2: 通过调用forName()方法加载类FieldGetModifiers。 + * -#step3: 通过调用getField()、getDeclaredField()获取对应名称的成员变量。 + * -#step4: 通过调用getModifiers()获取对应字段的Java语言修饰符,调用equals()方法进行判断描述正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGetModifiers.java + *- @ExecuteClass: RTFieldGetModifiers + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class FieldGetModifiers { + public static int num; + final String str = "aaa"; + private String string = "ccc"; + protected static int number; +} + +public class RTFieldGetModifiers { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldGetModifiers"); + Field instance1 = cls.getField("num"); + Field instance2 = cls.getDeclaredField("str"); + Field instance3 = cls.getDeclaredField("string"); + Field field = cls.getDeclaredField("number"); + if (instance1.getModifiers() == 9 && instance2.getModifiers() == 16 && instance3.getModifiers() == 2 + && field.getModifiers() + == 12) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchFieldException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0082-rt-compact-RTFieldgetName/RTFieldGetName.java b/test/testsuite/ouroboros/compact_test/RT0082-rt-compact-RTFieldgetName/RTFieldGetName.java new file mode 100755 index 0000000000..6af11968f7 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0082-rt-compact-RTFieldgetName/RTFieldGetName.java @@ -0,0 +1,48 @@ +/* + *- @TestCaseID: RTFieldGetName + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGetName.java + *- @Title/Destination: Field.GetName() Returns the name of the field represented by this Field object. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义类FieldGetName。 + * -#step2: 通过调用forName()方法加载类FieldGetModifiers。 + * -#step3: 通过调用getField()、getDeclaredField()获取对应名称的成员变量。 + * -#step4: 通过调用getName()方法获取对应字段,调用equals()方法进行判断字段值正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGetName.java + *- @ExecuteClass: RTFieldGetName + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class FieldGetName { + public static int num; + final String str = "aaa"; +} + +public class RTFieldGetName { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldGetName"); + Field instance1 = cls.getField("num"); + Field instance2 = cls.getDeclaredField("str"); + if (instance1.getName().equals("num") && instance2.getName().equals("str")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchFieldException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0083-rt-compact-RTFieldgetType/RTFieldGetType.java b/test/testsuite/ouroboros/compact_test/RT0083-rt-compact-RTFieldgetType/RTFieldGetType.java new file mode 100755 index 0000000000..86b869a65b --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0083-rt-compact-RTFieldgetType/RTFieldGetType.java @@ -0,0 +1,52 @@ +/* + *- @TestCaseID: RTFieldGetType + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldGetType.java + *- @Title/Destination: Field.GetType() Returns a Class object that identifies the declared type for the field + * represented by this Field object. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义类FieldGetType。 + * -#step2: 调用forName()方法加载类FieldGetType。 + * -#step3: 调用getField()、getDeclaredField()方法获取对应的成员变量。 + * -#step4: 调用getType().getName()获取相应的类型,调用equals()方法与相应的类型比较,判断通过字段值正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldGetType.java + *- @ExecuteClass: RTFieldGetType + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class FieldGetType { + public static short sNum; + final char aChar = '什'; + private float fNum; +} + +public class RTFieldGetType { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldGetType"); + Field instance1 = cls.getField("sNum"); + Field instance2 = cls.getDeclaredField("aChar"); + Field instance3 = cls.getDeclaredField("fNum"); + if (instance1.getType().getName().equals("short") && instance2.getType().getName().equals("char") + && instance3.getType().getName().equals("float")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchFieldException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0084-rt-compact-RTFieldset1/RTFieldSet1.java b/test/testsuite/ouroboros/compact_test/RT0084-rt-compact-RTFieldset1/RTFieldSet1.java new file mode 100755 index 0000000000..45d1c03bde --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0084-rt-compact-RTFieldset1/RTFieldSet1.java @@ -0,0 +1,90 @@ +/* + *- @TestCaseID: RTFieldSet1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldSet1.java + *- @Title/Destination: Field.set() sets the field on the specified object argument to the new value. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义类FieldSet1_a,定义类FieldSet1_a的子类FieldSet1。 + * -#step2: 通过调用forName()方法加载类FieldSet1,调用newInstance()方法生成实例对象。 + * -#step3: 通过调用getField()获取对应名称的成员变量,调用set()方法设置变量的值。 + * -#step4: 通过调用get()方法获取对应字段的值并作比较,确认字段值正确。 + * -#step5: 通过调用forName()方法加载类FieldSet1_a,调用newInstance()方法生成实例对象。 + * -#step6: 通过调用getDeclaredField()获取对应名称的成员变量,调用set()方法设置变量的值。 + * -#step7: 通过调用get()方法获取对应字段的值并作比较,确认字段值正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldSet1.java + *- @ExecuteClass: RTFieldSet1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class FieldSet1_a { + public static String str = "aaa"; + public int num2 = 2; + public int number = 5; + public static int num1; +} + +class FieldSet1 extends FieldSet1_a { + public static String str = "bbb"; + public int num = 1; + public int test = super.number + 1; + public static boolean aBoolean = true; + public char aChar; +} + +public class RTFieldSet1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldSet1"); + Object obj = cls.newInstance(); + Field f1 = cls.getField("str"); + Field f2 = cls.getField("num"); + Field f3 = cls.getField("aBoolean"); + Field f4 = cls.getField("aChar"); + Field f5 = cls.getField("num1"); + Field f6 = cls.getField("num2"); + Field f7 = cls.getField("number"); + f1.set(obj, "ccc"); + f2.set(obj, 10); + f3.set(obj, false); + f4.set(obj, '国'); + f5.set(obj, 20); + f6.set(obj, 30); + f7.set(obj, 40); + if (f1.get(obj).toString().equals("ccc") && (int) f2.get(obj) == 10 && !(boolean) f3.get(obj) && (int) + f6.get(obj) == 30) { + if (f4.get(obj).toString().equals("国") && (int) f5.get(obj) == 20) { + if ((int) cls.getField("test").get(obj) == 6) { + Class cls1 = Class.forName("FieldSet1_a"); + Object instance1 = cls1.newInstance(); + Object p = cls1.getDeclaredField("str").get(instance1); + if (p.toString().equals("aaa")) { + System.out.println(0); + } + } + } + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (InstantiationException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NoSuchFieldException e3) { + System.err.println(e3); + System.out.println(2); + } catch (IllegalAccessException e4) { + System.err.println(e4); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0085-rt-compact-RTFieldset2/RTFieldSet2.java b/test/testsuite/ouroboros/compact_test/RT0085-rt-compact-RTFieldset2/RTFieldSet2.java new file mode 100755 index 0000000000..1ae8be5462 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0085-rt-compact-RTFieldset2/RTFieldSet2.java @@ -0,0 +1,102 @@ +/* + *- @TestCaseID: RTFieldSet2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldSet2.java + *- @Title/Destination: If this Field object is inaccessible or final, throws IllegalAccessException; if the field + * doesn't exist in the class object, throws IllegalArgumentException; trying to set a non-static + * field on a null object throws NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义类FieldSet2_a的子类FieldSet2,含有私有变量。 + * -#step2: 通过调用forName()方法加载类FieldSet2,调用newInstance()方法生成实例对象,通过调用 getField()获取对应名称的 + * 成员变量,通过set()方法设值,抛出IllegalAccessException。 + * -#step3: 定义类FieldSet2_a,通过调用forName()方法加载类FieldSet2和FieldSet2_b,调用newInstance()方法生成实例对象, + * 通过调用 getField()获取对应名称的成员变量,通过set()方法设值,抛出IllegalArgumentException。 + * -#step4: 通过调用forName()方法加载类FieldSet2,调用getDeclaredField()方法获取对应名称的成员变量,通过set()方法设值, + * 抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldSet2.java + *- @ExecuteClass: RTFieldSet2 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class FieldSet2_a { + public static String str = "aaa"; + public int num; +} + +class FieldSet2 extends FieldSet2_a { + public static String str; + private int num = 1; + public boolean aBoolean = true; + public int num1 = 8; +} + +class FieldSet2_b { + public int num = 18; +} + +public class RTFieldSet2 { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldSet2"); + Object obj = cls.newInstance(); + Field field = cls.getDeclaredField("num"); + field.set(obj, 10); + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (InstantiationException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NoSuchFieldException e3) { + System.err.println(e3); + System.out.println(2); + } catch (IllegalAccessException e4) { + try { + Class cls = Class.forName("FieldSet2"); + Class cls1 = Class.forName("FieldSet2_b"); + Object instance1 = cls1.newInstance(); + Field f1 = cls.getDeclaredField("aBoolean"); + f1.set(instance1, 10); + } catch (ClassNotFoundException e5) { + System.err.println(e5); + System.out.println(2); + } catch (InstantiationException e6) { + System.err.println(e6); + System.out.println(2); + } catch (NoSuchFieldException e7) { + System.err.println(e7); + System.out.println(2); + } catch (IllegalAccessException e8) { + System.err.println(e8); + System.out.println(2); + } catch (IllegalArgumentException e9) { + try { + Class cls = Class.forName("FieldSet2"); + Field f2 = cls.getDeclaredField("aBoolean"); + f2.set(null, false); + } catch (ClassNotFoundException e10) { + System.err.println(e10); + System.out.println(2); + } catch (NoSuchFieldException e11) { + System.err.println(e11); + System.out.println(2); + } catch (IllegalAccessException e12) { + System.err.println(e12); + System.out.println(2); + } catch (NullPointerException e13) { + System.out.println(0); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0086-rt-compact-RTFieldset3/RTFieldSet3.java b/test/testsuite/ouroboros/compact_test/RT0086-rt-compact-RTFieldset3/RTFieldSet3.java new file mode 100755 index 0000000000..545971e964 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0086-rt-compact-RTFieldset3/RTFieldSet3.java @@ -0,0 +1,56 @@ +/* + *- @TestCaseID: RTFieldSet3 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldSet3.java + *- @Title/Destination: Setting on a final field throws IllegalAccessException. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义类FieldSet3_a,包含final修饰的变量。定义类FieldSet3_a的子类FieldSet3,包含final修饰的变量。 + * -#step2: 通过调用forName()方法加载类FieldSet3,调用newInstance()方法生成实例对象。 + * -#step3: 通过调用 getField()获取对应名称的成员变量,调用set()方法设置变量的值,抛出IllegalAccessException。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldSet3.java + *- @ExecuteClass: RTFieldSet3 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class FieldSet3_a { + public final static String str = "aaa"; + public int num = 2; +} + +class FieldSet3 extends FieldSet3_a { + public final int num = 1; +} + +public class RTFieldSet3 { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldSet3"); + Object obj = cls.newInstance(); + Field q1 = cls.getField("str"); + Field q2 = cls.getField("num"); + q1.set(obj, "bbb"); + q2.set(obj, 10); + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (InstantiationException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NoSuchFieldException e3) { + System.err.println(e3); + System.out.println(2); + } catch (IllegalAccessException e4) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0087-rt-compact-RTFieldset4/RTFieldSet4.java b/test/testsuite/ouroboros/compact_test/RT0087-rt-compact-RTFieldset4/RTFieldSet4.java new file mode 100755 index 0000000000..8e65a38c9c --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0087-rt-compact-RTFieldset4/RTFieldSet4.java @@ -0,0 +1,54 @@ +/* + *- @TestCaseID: RTFieldSet4 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldSet4.java + *- @Title/Destination: To set a value with no corresponding object on a static field by reflection. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含私有变量的类FieldSet4。 + * -#step2: 通过调用forName()方法加载类FieldSet4,调用newInstance()方法生成实例对象。 + * -#step3: 通过调用getDeclaredField()获取对应名称的成员变量,调用set()方法设置变量的值。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldSet4.java + *- @ExecuteClass: RTFieldSet4 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +class FieldSet4 { + public static String str; + private int num = 1; + public boolean aBoolean = true; + public int num1 = 8; +} + +public class RTFieldSet4 { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldSet4"); + Object obj = cls.newInstance(); + Field field = cls.getDeclaredField("str"); + field.set(null, "aaa"); + System.out.println(0); + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (InstantiationException e2) { + System.err.println(e2); + System.out.println(2); + } catch (NoSuchFieldException e3) { + System.err.println(e3); + System.out.println(2); + } catch (IllegalAccessException e4) { + System.err.println(e4); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0088-rt-compact-RTFieldtoGenericString/RTFieldToGenericString.java b/test/testsuite/ouroboros/compact_test/RT0088-rt-compact-RTFieldtoGenericString/RTFieldToGenericString.java new file mode 100755 index 0000000000..fb1600a728 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0088-rt-compact-RTFieldtoGenericString/RTFieldToGenericString.java @@ -0,0 +1,51 @@ +/* + *- @TestCaseID: RTFieldToGenericString + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldToGenericString.java + *- @Title/Destination: Field.toGenericString() Returns a string describing this Field, including its generic type. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含私有变量的类FieldToGenericString。 + * -#step2: 通过调用forName()方法加载类FieldToGenericString,调用newInstance()方法生成实例对象。 + * -#step3: 通过调用toGenericString()返回对象的string,确认返回的字符串描述正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldToGenericString.java + *- @ExecuteClass: RTFieldToGenericString + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; +import java.util.List; + +class FieldToGenericString { + public List list1; + private List list2; +} + +public class RTFieldToGenericString { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldToGenericString"); + Field instance1 = cls.getField("list1"); + Field instance2 = cls.getDeclaredField("list2"); + String q1 = instance1.toGenericString(); + String q2 = instance2.toGenericString(); + if (q1.equals("public java.util.List FieldToGenericString.list1") && q2.equals + ("private java.util.List FieldToGenericString.list2")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchFieldException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0089-rt-compact-RTFieldtoString/RTFieldToString.java b/test/testsuite/ouroboros/compact_test/RT0089-rt-compact-RTFieldtoString/RTFieldToString.java new file mode 100755 index 0000000000..ab9b500f34 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0089-rt-compact-RTFieldtoString/RTFieldToString.java @@ -0,0 +1,51 @@ +/* + *- @TestCaseID: RTFieldToString + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTFieldToString.java + *- @Title/Destination: Field.ToString() returns a string describing this Field. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义含私有变量的类FieldToGenericString。 + * -#step2: 通过调用forName()方法加载类FieldToGenericString,调用getField()、getDeclaredField()分别获取相应的成员。 + * -#step3: 通过调用toString()()返回对象的string,确认字符串描述正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTFieldToString.java + *- @ExecuteClass: RTFieldToString + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; +import java.util.List; + +class FieldToString { + public List list1; + private List list2; +} + +public class RTFieldToString { + public static void main(String[] args) { + try { + Class cls = Class.forName("FieldToString"); + Field instance1 = cls.getField("list1"); + Field instance2 = cls.getDeclaredField("list2"); + String q1 = instance1.toString(); + String q2 = instance2.toString(); + if (q1.equals("public java.util.List FieldToString.list1") + && q2.equals("private java.util.List FieldToString.list2")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchFieldException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0090-rt-compact-RTMethodgetAnnotation1/RTMethodGetAnnotation1.java b/test/testsuite/ouroboros/compact_test/RT0090-rt-compact-RTMethodgetAnnotation1/RTMethodGetAnnotation1.java new file mode 100755 index 0000000000..cad562414f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0090-rt-compact-RTMethodgetAnnotation1/RTMethodGetAnnotation1.java @@ -0,0 +1,87 @@ +/* + *- @TestCaseID: RTMethodGetAnnotation1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTMethodGetAnnotation1.java + *- @Title/Destination: Method.getAnnotation() Returns the Method's annotation for the specified type if such an + * annotation is present, else null. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取MethodGetAnnotation1类的运行时类clazz; + * -#step2: 以test3、int.class为参数,通过getDeclaredMethod()方法获取clazz的声明方法并记为method1; + * -#step3: 分别以test1、(test2、String.class)为参数,通过getMethod()方法获取clazz的方法对象method2、method3; + * -#step4: 分别以IF1_a.class、IF1.class为参数,通过getAnnotation()方法获取method1、method2的注解,且因为存在这样的 + * 注解,因此可以返回成功; + * -#step5: 以IF1.class为参数,通过getAnnotation()方法获取method3的注解,因不存在这样的注解,因此返回为null; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTMethodGetAnnotation1.java + *- @ExecuteClass: RTMethodGetAnnotation1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Method; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF1 { + int i_a() default 0; + String t_b() default ""; +} + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF1_a { + int c() default 0; + String d() default ""; +} + +class MethodGetAnnotation1 { + @IF1(i_a = 333, t_b = "MethodGetAnnotation") + public void test1() { + } + + public void test2(String name) { + } + + @IF1_a(c = 666, d = "Method") + void test3(int number) { + } + + void test4(String name, int number) { + } +} + +public class RTMethodGetAnnotation1 { + public static void main(String[] args) { + try { + Class clazz = Class.forName("MethodGetAnnotation1"); + Method method1 = clazz.getDeclaredMethod("test3", int.class); + Method method2 = clazz.getMethod("test1"); + Method method3 = clazz.getMethod("test2", String.class); + if (method1.getAnnotation(IF1_a.class).c() == 666 + && method1.getAnnotation(IF1_a.class).d().equals("Method") + && method2.getAnnotation(IF1.class).i_a() == 333 + && method2.getAnnotation(IF1.class).t_b().equals("MethodGetAnnotation")) { + if (method3.getAnnotation(IF1.class) == null) { + System.out.println(0); + } + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0091-rt-compact-RTMethodgetAnnotation2/RTMethodGetAnnotation2.java b/test/testsuite/ouroboros/compact_test/RT0091-rt-compact-RTMethodgetAnnotation2/RTMethodGetAnnotation2.java new file mode 100755 index 0000000000..fac42fe405 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0091-rt-compact-RTMethodgetAnnotation2/RTMethodGetAnnotation2.java @@ -0,0 +1,73 @@ +/* + *- @TestCaseID: RTMethodGetAnnotation2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTMethodGetAnnotation2.java + *- @Title/Destination: Annotations are not acting at the runtime stage, and the annotation to obtain the target class + * method by reflection is null + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取MethodGetAnnotation2类的运行时类clazz; + * -#step2: 以test3、int.class为参数,通过getDeclaredMethod()方法获取clazz的声明方法并记为method1; + * -#step3: 以test1为参数,通过getMethod()方法获取clazz的方法对象method2; + * -#step4: 以IF2_a.class为参数,通过getAnnotation()方法分别获取method1、method2的注解,其返回值均为null; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTMethodGetAnnotation2.java + *- @ExecuteClass: RTMethodGetAnnotation2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Method; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +@Documented +@Inherited +@interface IF2 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.SOURCE) +@Documented +@Inherited +@interface IF2_a { + int c() default 0; + String d() default ""; +} + +class MethodGetAnnotation2 { + @IF2(i = 333, t = "MethodGetAnnotation") + public void test1() { + } + + @IF2_a(c = 666, d = "Method") + void test3(int number) { + } +} + +public class RTMethodGetAnnotation2 { + public static void main(String[] args) { + try { + Class clazz = Class.forName("MethodGetAnnotation2"); + Method method1 = clazz.getDeclaredMethod("test3", int.class); + Method method2 = clazz.getMethod("test1"); + if (method1.getAnnotation(IF2_a.class) == null && method2.getAnnotation(IF2.class) == null) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0092-rt-compact-RTMethodgetDeclaredAnnotations1/RTMethodGetDeclaredAnnotations1.java b/test/testsuite/ouroboros/compact_test/RT0092-rt-compact-RTMethodgetDeclaredAnnotations1/RTMethodGetDeclaredAnnotations1.java new file mode 100755 index 0000000000..32444d303d --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0092-rt-compact-RTMethodgetDeclaredAnnotations1/RTMethodGetDeclaredAnnotations1.java @@ -0,0 +1,101 @@ +/* + *- @TestCaseID: RTMethodGetDeclaredAnnotations1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTMethodGetDeclaredAnnotations1.java + *- @Title/Destination: Method.getDeclaredAnnotations() returns annotations that are directly present on this element. + * Ignores inherited annotations. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取MethodGetDeclaredAnnotations1_a类的运行时类clazz; + * -#step2: 以ii、String.class为参数,通过getMethod()方法获取clazz的方法对象并记为method1; + * -#step3: 通过判断得出method1.getDeclaredAnnotations().length的返回值为1,并通过getDeclaredAnnotations()方法获取 + * method1的所有被声明的注解并记为annotations1; + * -#step4: 经过判断得出annotations1[0].toString()包含字符串i_a=666和t_a=right1; + * -#step5: 以tt、int.class为参数,通过getDeclaredMethod()方法获取clazz的声明方法并记为method2; + * -#step6: 通过判断得出method2.getDeclaredAnnotations().length的返回值为1,并通过getDeclaredAnnotations()方法获取 + * method2的所有被声明的注解并记为annotations2; + * -#step7: 经过判断得出annotations2[0].toString()包含字符串i_a=666和t_a=right1; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTMethodGetDeclaredAnnotations1.java + *- @ExecuteClass: RTMethodGetDeclaredAnnotations1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Method; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IFw1 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IFw1_a { + int i_a() default 2; + String t_a() default ""; +} + +class MethodGetDeclaredAnnotations1 { + @IFw1(i = 333, t = "test1") + public static void ii(String name) { + } + + @IFw1(i = 333, t = "test1") + void tt(int number) { + } +} + +class MethodGetDeclaredAnnotations1_a extends MethodGetDeclaredAnnotations1 { + @IFw1_a(i_a = 666, t_a = "right1") + public static void ii(String name) { + } + + @IFw1_a(i_a = 666, t_a = "right1") + void tt(int number) { + } +} + +public class RTMethodGetDeclaredAnnotations1 { + public static void main(String[] args) { + try { + Class clazz = Class.forName("MethodGetDeclaredAnnotations1_a"); + Method method1 = clazz.getMethod("ii", String.class); + if (method1.getDeclaredAnnotations().length == 1) { + Annotation[] annotations1 = method1.getDeclaredAnnotations(); + if (annotations1[0].toString().indexOf("i_a=666") != -1 + && annotations1[0].toString().indexOf("t_a=right1") != -1) { + Method method2 = clazz.getDeclaredMethod("tt", int.class); + if (method2.getDeclaredAnnotations().length == 1) { + Annotation[] annotations2 = method2.getDeclaredAnnotations(); + if (annotations2[0].toString().indexOf("i_a=666") != -1 + && annotations2[0].toString().indexOf("t_a=right1") != -1) { + System.out.println(0); + } + } + } + } + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchMethodException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0093-rt-compact-RTMethodgetDeclaredAnnotations2/RTMethodGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/compact_test/RT0093-rt-compact-RTMethodgetDeclaredAnnotations2/RTMethodGetDeclaredAnnotations2.java new file mode 100755 index 0000000000..40327b25fc --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0093-rt-compact-RTMethodgetDeclaredAnnotations2/RTMethodGetDeclaredAnnotations2.java @@ -0,0 +1,85 @@ +/* + *- @TestCaseID: RTMethodGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTMethodGetDeclaredAnnotations2.java + *- @Title/Destination: When the target class method has the same name as its parent class method, it is obtained by + * reflection as the annotation of the method in the target class, not the method of its parent + * class + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取MethodGetDeclaredAnnotations2_a类的运行时类clazz; + * -#step2: 以ii、String.class为参数,通过getMethod()方法获取clazz的方法对象并记为method1; + * -#step3: 以tt为参数,通过getDeclaredMethod()方法获取clazz的声明方法并记为method2; + * -#step4: 经判断得知method1.getDeclaredAnnotations()和method2.getDeclaredAnnotations()的返回值的长度均为0; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTMethodGetDeclaredAnnotations2.java + *- @ExecuteClass: RTMethodGetDeclaredAnnotations2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Method; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IFw2 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IFw2_a { + int i_a() default 2; + String t_a() default ""; +} + +class MethodGetDeclaredAnnotations2 { + @IFw2(i = 333, t = "test1") + public static void ii(String name) { + } + + @IFw2_a(i_a = 666, t_a = "right1") + void tt(int number) { + } +} + +class MethodGetDeclaredAnnotations2_a extends MethodGetDeclaredAnnotations2 { + public static void ii(String name) { + } + + void tt() { + } +} + +public class RTMethodGetDeclaredAnnotations2 { + public static void main(String[] args) { + try { + Class clazz = Class.forName("MethodGetDeclaredAnnotations2_a"); + Method method1 = clazz.getMethod("ii", String.class); + Method method2 = clazz.getDeclaredMethod("tt"); + if (method1.getDeclaredAnnotations().length == 0 && method2.getDeclaredAnnotations().length == 0) { + System.out.println(0); + } + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchMethodException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NullPointerException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0094-rt-compact-RTMethodgetDefaultValue1/RTMethodGetDefaultValue1.java b/test/testsuite/ouroboros/compact_test/RT0094-rt-compact-RTMethodgetDefaultValue1/RTMethodGetDefaultValue1.java new file mode 100755 index 0000000000..e257eebb9d --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0094-rt-compact-RTMethodgetDefaultValue1/RTMethodGetDefaultValue1.java @@ -0,0 +1,93 @@ +/* + *- @TestCaseID: RTMethodGetDefaultValue1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTMethodGetDefaultValue1.java + *- @Title/Destination: Method.getDefaultValue() Returns the default value for the annotation member represented by this + * Method instance. IF no default, return null. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法分别获取IF1_a类、IF1类、MethodGetDefaultValue1类的运行时类clazz1、clazz2、clazz3; + * -#step2: 分别以i_a、t为参数,通过getDeclaredMethod()方法分别获取clazz1、clazz2的声明方法并记为method1、method3; + * -#step3: 以t_a为参数,通过getMethod()方法获取clazz1的方法对象并记为method2; + * -#step4: 通过getMethods()方法获取clazz3的所有的方法对象并记为methods; + * -#step5: 分别以(tt、int.class)和s为参数,通过getDeclaredMethod()方法分别获取clazz3、clazz1的声明方法并记为method5、 + * method6; + * -#step6: 经判断得知method1.getDefaultValue()的返回值为2,method2.getDefaultValue().toString()的返回值与字符串 + * "string default value"相同; + * -#step7: 经判断得知method3.getDefaultValue()的返回值为空; + * -#step8: 经判断得知methods[0].getDefaultValue()、method5.getDefaultValue()的返回值均为null; + * -#step9: 经判断得知method6.getDefaultValue()的返回值为null; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTMethodGetDefaultValue1.java + *- @ExecuteClass: RTMethodGetDefaultValue1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Method; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF1 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF1_a { + public int i_a() default 2; + String t_a() default "string default value"; + String s(); +} + +class MethodGetDefaultValue1 { + @IF1(i = 333, t = "test1") + public static void ii(String name) { + } + + void tt(int number) { + } +} + +public class RTMethodGetDefaultValue1 { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("IF1_a"); + Class clazz2 = Class.forName("IF1"); + Class clazz3 = Class.forName("MethodGetDefaultValue1"); + Method method1 = clazz1.getDeclaredMethod("i_a"); + Method method2 = clazz1.getMethod("t_a"); + Method method3 = clazz2.getDeclaredMethod("t"); + Method[] methods = clazz3.getMethods(); + Method method5 = clazz3.getDeclaredMethod("tt", int.class); + Method method6 = clazz1.getDeclaredMethod("s"); + if ((int) method1.getDefaultValue() == 2 + && method2.getDefaultValue().toString().equals("string default value")) { + if (method3.getDefaultValue().equals("")) { + if (methods[0].getDefaultValue() == null && method5.getDefaultValue() == null) { + if (method6.getDefaultValue() == null) { + System.out.println(0); + } + } + } + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0095-rt-compact-RTMethodgetParameterCount/RTMethodGetParameterCount.java b/test/testsuite/ouroboros/compact_test/RT0095-rt-compact-RTMethodgetParameterCount/RTMethodGetParameterCount.java new file mode 100755 index 0000000000..6cf6620698 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0095-rt-compact-RTMethodgetParameterCount/RTMethodGetParameterCount.java @@ -0,0 +1,55 @@ +/* + *- @TestCaseID: RTMethodGetParameterCount + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTMethodGetParameterCount.java + *- @Title/Destination: Method.GetParameterCount() Returns the number of formal parameters (whether explicitly declared + * or implicitly declared or neither) for the executable represented by this object. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取MethodGetParameterCount2类的运行时类clazz; + * -#step2: 以test1为参数,通过getDeclaredMethod()方法获取clazz的声明方法并记为method1; + * -#step3: 通过getMethods()方法获取clazz的所有的方法对象并记为methods; + * -#step4: 经判断得知method.getParameterCount()的返回值为0,即method的参数个数为0;而methods[0].getParameterCount()的返 + * 回值为9,即methods[0]的所有的参数个数为9; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTMethodGetParameterCount.java + *- @ExecuteClass: RTMethodGetParameterCount + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +class MethodGetParameterCount2 { + void test1() { + } + + public void test2(String name, int number, char c, short s, float f, double d, long l, boolean b, byte bb) { + } +} + +public class RTMethodGetParameterCount { + public static void main(String[] args) { + try { + Class clazz = Class.forName("MethodGetParameterCount2"); + Method method = clazz.getDeclaredMethod("test1"); + Method[] methods = clazz.getMethods(); + if (method.getParameterCount() == 0) { + if (methods[0].getParameterCount() == 9) { + System.out.println(0); + } + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0096-rt-compact-RTMethodgetTypeParameters/RTMethodGetTypeParameters.java b/test/testsuite/ouroboros/compact_test/RT0096-rt-compact-RTMethodgetTypeParameters/RTMethodGetTypeParameters.java new file mode 100755 index 0000000000..45cb699c52 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0096-rt-compact-RTMethodgetTypeParameters/RTMethodGetTypeParameters.java @@ -0,0 +1,56 @@ +/* + *- @TestCaseID: RTMethodGetTypeParameters + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTMethodGetTypeParameters.java + *- @Title/Destination: Method.GetTypeParameters() returns an array of TypeVariable objects that represent the type + * variables declared by the generic declaration in declaration order. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取MethodGetTypeParameters2类的运行时类clazz; + * -#step2: 以ss、int.class为参数,通过getMethod()方法获取clazz的方法对象并记为method1; + * -#step3: 以kk为参数,通过getDeclaredMethod()方法获取clazz的声明方法并记为method2; + * -#step4: 通过getTypeParameters()方法分别获取method1、method2的所有的类型参数并记为typeVariables1、typeVariables2; + * -#step5: 经判断得知typeVariables1的长度为5,typeVariables2的长度为0; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTMethodGetTypeParameters.java + *- @ExecuteClass: RTMethodGetTypeParameters + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; +import java.lang.reflect.TypeVariable; + +class MethodGetTypeParameters2 { + public void ss(int number) { + } + + void kk() { + } +} + +public class RTMethodGetTypeParameters { + public static void main(String[] args) { + try { + Class clazz = Class.forName("MethodGetTypeParameters2"); + Method method1 = clazz.getMethod("ss", int.class); + Method method2 = clazz.getDeclaredMethod("kk"); + TypeVariable[] typeVariables1 = method1.getTypeParameters(); + TypeVariable[] typeVariables2 = method2.getTypeParameters(); + if (typeVariables1.length == 5 && typeVariables2.length == 0) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0097-rt-compact-RTMethonisDefault/RTMethodIsDefault.java b/test/testsuite/ouroboros/compact_test/RT0097-rt-compact-RTMethonisDefault/RTMethodIsDefault.java new file mode 100755 index 0000000000..c8d4318cab --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0097-rt-compact-RTMethonisDefault/RTMethodIsDefault.java @@ -0,0 +1,63 @@ +/* + *- @TestCaseID: RTMethodIsDefault + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTMethodIsDefault.java + *- @Title/Destination: Verify through reflection whether the default method in the interface. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法分别获取MethodIsDefault_A类、MethodIsDefault类的运行时类clazz1、clazz2; + * -#step2: 以run为参数,通过getMethod()方法分别获取clazz1、clazz2的方法对象并记为method1、method2; + * -#step3: 以ss、int.class为参数,通过getDeclaredMethod()方法获取clazz2的声明方法并记为method3; + * -#step4: 经isDefault()判断得知method1是默认的; + * -#step5: 经isDefault()判断得知method2、method3不是默认的; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTMethodIsDefault.java + *- @ExecuteClass: RTMethodIsDefault + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +interface MethodIsDefault_A { + default public void run() { + String i; + } +} + +class MethodIsDefault implements MethodIsDefault_A { + public void run() { + String i = "abc"; + } + + void ss(int number) { + } +} + +public class RTMethodIsDefault { + public static void main(String[] args) { + try { + Class clazz1 = Class.forName("MethodIsDefault_A"); + Class clazz2 = Class.forName("MethodIsDefault"); + Method method1 = clazz1.getMethod("run"); + Method method2 = clazz2.getMethod("run"); + Method method3 = clazz2.getDeclaredMethod("ss", int.class); + if (method1.isDefault()) { + if (!method2.isDefault() && !method3.isDefault()) { + System.out.println(0); + } + } + } catch (ClassNotFoundException e) { + System.err.println(e); + System.out.println(2); + } catch (NoSuchMethodException e) { + System.err.println(e); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0098-rt-compact-RTMethontoGenericString/RTMethodToGenericString.java b/test/testsuite/ouroboros/compact_test/RT0098-rt-compact-RTMethontoGenericString/RTMethodToGenericString.java new file mode 100755 index 0000000000..d6726a6054 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0098-rt-compact-RTMethontoGenericString/RTMethodToGenericString.java @@ -0,0 +1,47 @@ +/* + *- @TestCaseID: RTMethodToGenericString + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTMethodToGenericString.java + *- @Title/Destination: Method.toGenericString() Returns a string describing this Method, including type parameters. + *- @Condition: no + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取MethodToGenericString类的运行时类clazz; + * -#step2: 以ss、int.class为参数,通过getMethod()方法获取clazz的方法对象并记为method; + * -#step3: 通过method.toGenericString()返回的表示method的方法名称和类型参数与字符串 + * “public void MethodToGenericString.ss(int)”相同; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTMethodToGenericString.java + *- @ExecuteClass: RTMethodToGenericString + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +class MethodToGenericString { + public void ss(int number) { + } +} + +public class RTMethodToGenericString { + public static void main(String[] args) { + try { + Class clazz = Class.forName("MethodToGenericString"); + Method method = clazz.getMethod("ss", int.class); + if (method.toGenericString().equals("public void MethodToGenericString.ss(int)")) { + System.out.println(0); + } + } catch (ClassNotFoundException e1) { + System.err.println(e1); + System.out.println(2); + } catch (NoSuchMethodException e2) { + System.err.println(e2); + System.out.println(2); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0099-rt-compact-RTModifierparameterModifiers/RTModifierParameterModifiers.java b/test/testsuite/ouroboros/compact_test/RT0099-rt-compact-RTModifierparameterModifiers/RTModifierParameterModifiers.java new file mode 100755 index 0000000000..23aeb744e0 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0099-rt-compact-RTModifierparameterModifiers/RTModifierParameterModifiers.java @@ -0,0 +1,31 @@ +/* + *- @TestCaseID: RTModifierParameterModifiers + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTModifierParameterModifiers.java + *- @Title/Destination: Verify that the integer value of the parameter modifier for the modifier class is 16. + * Modifier.parameterModifiers() return an int value OR-ing together the source language modifiers + * that can be applied to a parameter. + *- @Condition: no + *- @Brief:no: + * -#step1: 经判断得知Modifier.parameterModifiers()的返回值为16,即修饰符类的参数修饰符的整数值为16; + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTModifierParameterModifiers.java + *- @ExecuteClass: RTModifierParameterModifiers + *- @ExecuteArgs: + */ + +import java.lang.reflect.Modifier; + +public class RTModifierParameterModifiers { + public static void main(String[] args) { + if (Modifier.parameterModifiers() == 16) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0100-rt-compact-RTParametergetAnnotation1/RTParameterGetAnnotation1.java b/test/testsuite/ouroboros/compact_test/RT0100-rt-compact-RTParametergetAnnotation1/RTParameterGetAnnotation1.java new file mode 100755 index 0000000000..e6016177d9 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0100-rt-compact-RTParametergetAnnotation1/RTParameterGetAnnotation1.java @@ -0,0 +1,91 @@ +/* + *- @TestCaseID: RTParameterGetAnnotation1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTParameterGetAnnotation1.java + *- @Title/Destination: Parameter.getAnnotation() returns the method parameter's annotations for the specified type if + * such an annotation is present, else null. + *- @Condition: no + *- @Brief:no: + * -#step1: 自定义一个类,含有注解的构造方法,不含注解的构造方法和有注解的方法。 + * -#step2:通过调用getDeclaredConstructor获取自定义类的构造方法,通过调用getParameters()获取参数数组,调用 + * getAnnotation(Class annotationClass)获取注解,确认获取成功。 + * -#step3:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用 + * getAnnotation(Class annotationClass)获取注解,确认获取成功。 + * -#step4:通过调用getDeclaredConstructor获取自定义类的不含注解的构造方法,通过调用getParameters()获取参数数组,调用 + * getAnnotation(Class annotationClass)获取注解,确认获取为空。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTParameterGetAnnotation1.java + *- @ExecuteClass: RTParameterGetAnnotation1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF1 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF1_a { + int c() default 0; + String d() default ""; +} + +class ParameterGetAnnotation1 { + ParameterGetAnnotation1(@IF1(i = 222, t = "Parameter") int number) { + } + + public ParameterGetAnnotation1(String name) { + } + + public void test1(@IF1_a(c = 666, d = "Happy new year") int age) { + } +} + +public class RTParameterGetAnnotation1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ParameterGetAnnotation1"); + Constructor cons1 = cls.getDeclaredConstructor(int.class); + Constructor cons2 = cls.getConstructor(String.class); + Method method = cls.getMethod("test1", int.class); + Parameter[] p1 = cons1.getParameters(); + Parameter[] p2 = cons2.getParameters(); + Parameter[] p3 = method.getParameters(); + if (p1[0].getAnnotation(IF1.class).i() == 222 && p1[0].getAnnotation(IF1.class).t().equals("Parameter") + && p3[0].getAnnotation(IF1_a.class).c() == 666 + && p3[0].getAnnotation(IF1_a.class).d().equals("Happy new year")) { + if (p2[0].getAnnotation(IF1.class) == null) { + System.out.println(0); + return; + } + System.out.println(2); + return; + } + } catch (ClassNotFoundException e) { + System.out.println(3); + return; + } catch (NoSuchMethodException e1) { + System.out.println(4); + return; + } + System.out.println(5); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0101-rt-compact-RTParametergetAnnotation2/RTParameterGetAnnotation2.java b/test/testsuite/ouroboros/compact_test/RT0101-rt-compact-RTParametergetAnnotation2/RTParameterGetAnnotation2.java new file mode 100755 index 0000000000..cfc775269f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0101-rt-compact-RTParametergetAnnotation2/RTParameterGetAnnotation2.java @@ -0,0 +1,101 @@ +/* + *- @TestCaseID: RTParameterGetAnnotation2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTParameterGetAnnotation2.java + *- @Title/Destination: If expected annotation not exist, getAnnotation() return null; if the given annotation class is + * null, getAnnotation() throws NullPointerException; + *- @Condition: no + *- @Brief:no: + * -#step1: 自定义一个类,含有注解的构造方法,和有注解的方法。 + * -#step2:通过调用getDeclaredConstructor获取自定义类的构造方法,通过调用getParameters()获取参数数组,调用 + * getAnnotation(Class annotationClass)获取注解,参数annotationClass类型与实际注解类型不匹配,确认返回为空。 + * -#step3:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用 + * getAnnotation(Class annotationClass)获取注解,参数annotationClass类型与实际注解类型不匹配,确认返回为空。 + * -#step4:通过调用getDeclaredConstructor获取自定义类的构造方法,通过调用getParameters()获取参数数组,调用 + * getAnnotation(Class annotationClass)并且继续调用注解的方法,参数annotationClass类型与实际注解类型不匹配, + * 确认抛出NullPointerException异常。 + * -#step5:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用 + * getAnnotation(Class annotationClass)获取注解,参数annotationClass为null,确认抛出NullPointerException异常。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTParameterGetAnnotation2.java + *- @ExecuteClass: RTParameterGetAnnotation2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF2 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF2_a { + int c() default 0; + String d() default ""; +} + +class ParameterGetAnnotation2 { + ParameterGetAnnotation2(@IF2(i = 222, t = "Parameter") int number) { + } + + public void test1(@IF2_a(c = 666, d = "Happy new year") int age) { + } +} + +public class RTParameterGetAnnotation2 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ParameterGetAnnotation2"); + Constructor cons = cls.getDeclaredConstructor(int.class); + Method method = cls.getMethod("test1", int.class); + Parameter[] p1 = cons.getParameters(); + Parameter[] p2 = method.getParameters(); + if (p1[0].getAnnotation(IF2_a.class) == null && p2[0].getAnnotation(IF2.class) == null) { + p1[0].getAnnotation(IF2_a.class).c(); + } + } catch (ClassNotFoundException e) { + System.out.println(1); + return; + } catch (NoSuchMethodException e1) { + System.out.println(2); + return; + } catch (NullPointerException e2) { + try { + Class cls1 = Class.forName("ParameterGetAnnotation2"); + Method method2 = cls1.getMethod("test1", int.class); + Parameter[] p3 = method2.getParameters(); + p3[0].getAnnotation(null); + System.out.println(3); + return; + } catch (ClassNotFoundException e3) { + System.out.println(4); + return; + } catch (NoSuchMethodException e4) { + System.out.println(5); + return; + } catch (NullPointerException e5) { + System.out.println(0); + return; + } + } + System.out.println(6); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0102-rt-compact-RTParametergetAnnotations1/RTParameterGetAnnotations1.java b/test/testsuite/ouroboros/compact_test/RT0102-rt-compact-RTParametergetAnnotations1/RTParameterGetAnnotations1.java new file mode 100755 index 0000000000..e9a5be1c41 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0102-rt-compact-RTParametergetAnnotations1/RTParameterGetAnnotations1.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: RTParameterGetAnnotations1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTParameterGetAnnotations1.java + *- @Title/Destination: Get all annotations of target class method parameters by reflection. + *- @Condition: no + *- @Brief:no: + * -#step1: 自定义一个类,含有注解的构造方法,和不含注解的方法。 + * -#step2:通过调用getDeclaredConstructor获取自定义类的构造方法,通过调用getParameters()获取参数数组,调用getAnnotations()获 + * 取注解数组,确认注解数组长度为2。 + * -#step3:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用getAnnotations()获取注解数组,确认注 + * 解数组长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTParameterGetAnnotations1.java + *- @ExecuteClass: RTParameterGetAnnotations1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF3 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF3_a { + int c() default 0; + String d() default ""; +} + +class ParameterGetAnnotations1 { + ParameterGetAnnotations1(@IF3(i = 222, t = "Parameter") @IF3_a(c = 666, d = "Happy new year") int number) { + } + + public void test1(String name) { + } +} + +public class RTParameterGetAnnotations1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ParameterGetAnnotations1"); + Constructor cons = cls.getDeclaredConstructor(int.class); + Method method = cls.getMethod("test1", String.class); + Parameter[] p1 = cons.getParameters(); + Parameter[] p2 = method.getParameters(); + if (p1[0].getAnnotations().length == 2 && p2[0].getAnnotations().length == 0) { + System.out.println(0); + return; + } + } catch (ClassNotFoundException e) { + System.out.println(1); + return; + } catch (NoSuchMethodException e1) { + System.out.println(2); + return; + } + System.out.println(3); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0103-rt-compact-RTParametergetAnnotationsByType1/RTParameterGetAnnotationsByType1.java b/test/testsuite/ouroboros/compact_test/RT0103-rt-compact-RTParametergetAnnotationsByType1/RTParameterGetAnnotationsByType1.java new file mode 100755 index 0000000000..27181e125d --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0103-rt-compact-RTParametergetAnnotationsByType1/RTParameterGetAnnotationsByType1.java @@ -0,0 +1,96 @@ +/* + *- @TestCaseID: RTParameterGetAnnotationsByType1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTParameterGetAnnotationsByType1.java + *- @Title/Destination: Parameters.getAnnotationsByType returns all this element's annotations for the specified + * annotation type if associated with this element, else an array of length zero。 + *- @Condition: no + *- @Brief:no: + * -#step1: 自定义一个类,含有注解的构造方法,不含注解的构造方法,含注解的方法。 + * -#step2:通过调用getConstructor获取自定义类的不含注解的构造方法,通过调用getParameters()获取参数数组,调用 + * getAnnotationsByType(Class annotationClass)获取注解数组,annotationClass为注解类型,确认注解数组长度为0。 + * -#step3:通过调用getDeclaredConstructor获取自定义类的含注解的构造方法,通过调用getParameters()获取参数数组,调用 + * getAnnotationsByType(Class annotationClass)获取注解数组,annotationClass为对应的注解类型,对注解数组调用 + * toString().indexOf(str)判断注解的值是否正确。 + * -#step4:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用 + * getAnnotationsByType(Class annotationClass)获取注解数组,annotationClass为对应的注解类型,对注解数组调用 + * toString().indexOf(str)判断注解的值是否正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTParameterGetAnnotationsByType1.java + *- @ExecuteClass: RTParameterGetAnnotationsByType1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF7 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF7_a { + int c() default 0; + String d() default ""; +} + +class ParameterGetAnnotationsByType1 { + ParameterGetAnnotationsByType1(@IF7(i = 222, t = "Parameter") int number) { + } + + public ParameterGetAnnotationsByType1(String name) { + } + + public void test1(@IF7_a(c = 666, d = "Happy new year") int age) { + } +} + +public class RTParameterGetAnnotationsByType1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ParameterGetAnnotationsByType1"); + Constructor cons1 = cls.getDeclaredConstructor(int.class); + Constructor cons2 = cls.getConstructor(String.class); + Method method = cls.getMethod("test1", int.class); + Parameter[] p1 = cons1.getParameters(); + Parameter[] p2 = cons2.getParameters(); + Parameter[] p3 = method.getParameters(); + Annotation[] q1 = p1[0].getAnnotationsByType(IF7.class); + Annotation[] q3 = p3[0].getAnnotationsByType(IF7_a.class); + if (p2[0].getAnnotationsByType(IF7.class).length == 0) { + if (q1[0].toString().indexOf("i=222") != -1 && q1[0].toString().indexOf("t=Parameter") != -1 + && q3[0].toString().indexOf("c=666") != -1 + && q3[0].toString().indexOf("d=Happy new year") != -1) { + System.out.println(0); + return; + } + System.out.println(1); + return; + } + } catch (ClassNotFoundException e) { + System.out.println(2); + return; + } catch (NoSuchMethodException e1) { + System.out.println(3); + return; + } + System.out.println(4); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0104-rt-compact-RTParametergetAnnotationsByType2/RTParameterGetAnnotationsByType2.java b/test/testsuite/ouroboros/compact_test/RT0104-rt-compact-RTParametergetAnnotationsByType2/RTParameterGetAnnotationsByType2.java new file mode 100755 index 0000000000..9f09e26dd6 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0104-rt-compact-RTParametergetAnnotationsByType2/RTParameterGetAnnotationsByType2.java @@ -0,0 +1,102 @@ +/* + *- @TestCaseID: RTParameterGetAnnotationsByType2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTParameterGetAnnotationsByType2.java + *- @Title/Destination:Parameter.getAnnotationsByType() return an array of length zero if no expected annotation found; + * getAnnotationsByType(null) throws NullPointerException. + *- @Condition: no + *- @Brief:no: + * -#step1: 自定义一个类,含有注解的构造方法,和不含注解的方法。 + * -#step2:通过调用getDeclaredConstructor获取自定义类的构造方法,通过调用getParameters()获取参数数组,调用 + * getAnnotationsByType(Class annotationClass)获取注解数组,annotationClass为非对应的注解类型,对注解数组q1 + * 调用q1[0].toString(), 检查会有ArrayIndexOutOfBoundsException抛出。 + * -#step3:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用 + * getAnnotationsByType(Class annotationClass)获取注解数组,annotationClass为非对应的注解类型,对注解数组q2 + * 调用q2[0].toString(), 检查会有ArrayIndexOutOfBoundsException抛出。 + * -#step4:通过调用getDeclaredConstructor获取自定义类的构造方法,通过调用getParameters()获取参数数组,调用 + * getAnnotationsByType(Class annotationClass)获取注解数组,annotationClass为null,检查会有 + * NullPointerException抛出。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTParameterGetAnnotationsByType2.java + *- @ExecuteClass: RTParameterGetAnnotationsByType2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF8 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF8_a { + int c() default 0; + String d() default ""; +} + +class ParameterGetAnnotationsByType2 { + ParameterGetAnnotationsByType2(@IF8(i = 222, t = "Parameter") int number) { + } + + public void test1(@IF8_a(c = 666, d = "Happy new year") int age) { + } +} + +public class RTParameterGetAnnotationsByType2 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ParameterGetAnnotationsByType2"); + Constructor cons = cls.getDeclaredConstructor(int.class); + Method method = cls.getMethod("test1", int.class); + Parameter[] p1 = cons.getParameters(); + Parameter[] p2 = method.getParameters(); + Annotation[] q1 = p1[0].getAnnotationsByType(IF8_a.class); + Annotation[] q2 = p2[0].getAnnotationsByType(IF8.class); + q1[0].toString(); + q2[0].toString(); + } catch (ClassNotFoundException e) { + System.out.println(1); + return; + } catch (NoSuchMethodException e1) { + System.out.println(2); + return; + } catch (ArrayIndexOutOfBoundsException e2) { + try { + Class cls1 = Class.forName("ParameterGetAnnotationsByType2"); + Constructor cons1 = cls1.getDeclaredConstructor(int.class); + Parameter[] p3 = cons1.getParameters(); + Annotation[] q3 = p3[0].getAnnotationsByType(null); + System.out.println(3); + return; + } catch (ClassNotFoundException e3) { + System.out.println(4); + return; + } catch (NoSuchMethodException e4) { + System.out.println(5); + return; + } catch (NullPointerException e5) { + System.out.println(0); + return; + } + } + System.out.println(6); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0105-rt-compact-RTParametergetDeclaredAnnotation1/RTParameterGetDeclaredAnnotation1.java b/test/testsuite/ouroboros/compact_test/RT0105-rt-compact-RTParametergetDeclaredAnnotation1/RTParameterGetDeclaredAnnotation1.java new file mode 100755 index 0000000000..100c7b6bef --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0105-rt-compact-RTParametergetDeclaredAnnotation1/RTParameterGetDeclaredAnnotation1.java @@ -0,0 +1,94 @@ +/* + *- @TestCaseID: RTParameterGetDeclaredAnnotation1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTParameterGetDeclaredAnnotation1.java + *- @Title/Destination: Parameter.getDeclaredAnnotation() Returns this element's annotation for the specified type if + * such an annotation is directly present, else null. This method ignores inherited annotations. + *- @Condition: no + *- @Brief:no: + * -#step1: 自定义一个类,含有注解的构造方法,不含注解的构造方法和含注解的方法。 + * -#step2:通过调用getDeclaredConstructor获取有注解的构造方法,通过调用getParameters()获取参数数组,调用 + * getDeclaredAnnotation(Class annotationClass)获取注解,annotationClass为对应的注解类型,确认获取的注解内容 + * 正确。 + * -#step3:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用 + * getDeclaredAnnotation(Class annotationClass)获取注解,annotationClass为对应的注解类型,确认获取的注解内容 + * 正确。 + * -#step4:通过调用getDeclaredConstructor获取不含注解的构造方法,通过调用getParameters()获取参数数组,调用 + * getDeclaredAnnotation(Class annotationClass)获取注解,annotationClass为注解类型,确认返回为空。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTParameterGetDeclaredAnnotation1.java + *- @ExecuteClass: RTParameterGetDeclaredAnnotation1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF6 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF6_a { + int c() default 0; + String d() default ""; +} + +class ParameterGetDeclaredAnnotation1 { + ParameterGetDeclaredAnnotation1(@IF6(i = 222, t = "Parameter") int number) { + } + + public ParameterGetDeclaredAnnotation1(String name) { + } + + public void test1(@IF6_a(c = 666, d = "Happy new year") int age) { + } +} + +public class RTParameterGetDeclaredAnnotation1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ParameterGetDeclaredAnnotation1"); + Constructor cons1 = cls.getDeclaredConstructor(int.class); + Constructor cons2 = cls.getConstructor(String.class); + Method method = cls.getMethod("test1", int.class); + Parameter[] p1 = cons1.getParameters(); + Parameter[] p2 = cons2.getParameters(); + Parameter[] p3 = method.getParameters(); + if (p1[0].getDeclaredAnnotation(IF6.class).i() == 222 && p1[0].getDeclaredAnnotation(IF6.class).t() + .equals("Parameter") && p3[0].getDeclaredAnnotation(IF6_a.class).c() == 666 + && p3[0].getDeclaredAnnotation(IF6_a.class).d().equals("Happy new year")) { + if (p2[0].getDeclaredAnnotation(IF6.class) == null) { + System.out.println(0); + return; + } + System.out.println(1); + return; + } + } catch (ClassNotFoundException e) { + System.out.println(2); + return; + } catch (NoSuchMethodException e1) { + System.out.println(3); + return; + } + System.out.println(4); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0106-rt-compact-RTParametergetDeclaredAnnotations1/RTParameterGetDeclaredAnnotations1.java b/test/testsuite/ouroboros/compact_test/RT0106-rt-compact-RTParametergetDeclaredAnnotations1/RTParameterGetDeclaredAnnotations1.java new file mode 100755 index 0000000000..2dc36e8e03 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0106-rt-compact-RTParametergetDeclaredAnnotations1/RTParameterGetDeclaredAnnotations1.java @@ -0,0 +1,79 @@ +/* + *- @TestCaseID: RTParameterGetDeclaredAnnotations1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTParameterGetDeclaredAnnotations1.java + *- @Title/Destination: Parameter.getDeclaredAnnotations() returns annotations that are directly present on this element. + * This method ignores inherited annotations. + *- @Condition: no + *- @Brief:no: + * -#step1: 自定义一个类,含有注解的构造方法和不含注解的方法。 + * -#step2:通过调用getDeclaredConstructor获取自定义类的构造方法,通过调用getParameters()获取参数数组,调用 + * getDeclaredAnnotations()获取注解数组,检查数组长度为2。 + * -#step3:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用getDeclaredAnnotations()获取注 + * 解数组,检查数组长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTParameterGetDeclaredAnnotations1.java + *- @ExecuteClass: RTParameterGetDeclaredAnnotations1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF5 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF5_a { + int c() default 0; + String d() default ""; +} + +class ParameterGetDeclaredAnnotations1 { + ParameterGetDeclaredAnnotations1(@IF5(i = 222, t = "Parameter") @IF5_a(c = 666, d = "Happy new year") int number) { + } + + public void test1(String name) { + } +} + +public class RTParameterGetDeclaredAnnotations1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ParameterGetDeclaredAnnotations1"); + Constructor cons = cls.getDeclaredConstructor(int.class); + Method method = cls.getMethod("test1", String.class); + Parameter[] p1 = cons.getParameters(); + Parameter[] p2 = method.getParameters(); + if (p1[0].getDeclaredAnnotations().length == 2 && p2[0].getDeclaredAnnotations().length == 0) { + System.out.println(0); + return; + } + } catch (ClassNotFoundException e) { + System.out.println(1); + return; + } catch (NoSuchMethodException e1) { + System.out.println(2); + return; + } + System.out.println(3); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0107-rt-compact-RTParametergetDeclaredAnnotations2/RTParameterGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/compact_test/RT0107-rt-compact-RTParametergetDeclaredAnnotations2/RTParameterGetDeclaredAnnotations2.java new file mode 100755 index 0000000000..48baeff31a --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0107-rt-compact-RTParametergetDeclaredAnnotations2/RTParameterGetDeclaredAnnotations2.java @@ -0,0 +1,103 @@ +/* + *- @TestCaseID: RTParameterGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTParameterGetDeclaredAnnotations2.java + *- @Title/Destination: Parameter.getDeclaredAnnotations() returns annotations that are directly present on this element. + * This method ignores inherited annotations. If there are no annotations directly present on this + * element, the return value is an array of length 0. + *- @Condition: no + *- @Brief:no: + * -#step1:创建一个类1,含有注解和无注解的构造方法和有注解方法。创建一个子类2继承类1,含有注解和无注解的构造方法和有注 + * 解方法。创建子类3继承类2,重写构造方法和方法,均为无注解。 + * -#step2:通过调用getDeclaredConstructor获取自定义类3的构造方法,通过调用getParameters()获取参数数组,调用 + * getDeclaredAnnotations()获取注解数组,检查数组长度为0。 + * -#step3:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用getDeclaredAnnotations()获取注 + * 解数组,检查数组长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTParameterGetDeclaredAnnotations2.java + *- @ExecuteClass: RTParameterGetDeclaredAnnotations2 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF4 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF4_a { + int c() default 0; + String d() default ""; +} + +class ParameterGetDeclaredAnnotations2 { + ParameterGetDeclaredAnnotations2() { + } + + ParameterGetDeclaredAnnotations2(@IF4(i = 222, t = "Parameter") int number) { + } + + public void test1(@IF4(i = 222, t = "Parameter") String name) { + } +} + +class ParameterGetDeclaredAnnotations2_a extends ParameterGetDeclaredAnnotations2 { + ParameterGetDeclaredAnnotations2_a() { + } + + ParameterGetDeclaredAnnotations2_a(@IF4_a(c = 666, d = "Happy new year") int number) { + } + + public void test1(@IF4_a(c = 666, d = "Happy new year") String name) { + } +} + +class ParameterGetDeclaredAnnotations2_b extends ParameterGetDeclaredAnnotations2_a { + ParameterGetDeclaredAnnotations2_b(int number) { + } + + public void test1(String name) { + } +} + +public class RTParameterGetDeclaredAnnotations2 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ParameterGetDeclaredAnnotations2_b"); + Constructor cons = cls.getDeclaredConstructor(int.class); + Method method = cls.getMethod("test1", String.class); + Parameter[] p1 = cons.getParameters(); + Parameter[] p2 = method.getParameters(); + if (p1[0].getDeclaredAnnotations().length == 0 && p2[0].getDeclaredAnnotations().length == 0) { + System.out.println(0); + return; + } + } catch (ClassNotFoundException e) { + System.out.println(1); + return; + } catch (NoSuchMethodException e1) { + System.out.println(2); + return; + } + System.out.println(3); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0108-rt-compact-RTParametergetDeclaredAnnotationsByType1/RTParameterGetDeclaredAnnotationsByType1.java b/test/testsuite/ouroboros/compact_test/RT0108-rt-compact-RTParametergetDeclaredAnnotationsByType1/RTParameterGetDeclaredAnnotationsByType1.java new file mode 100755 index 0000000000..e6d4cf7723 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0108-rt-compact-RTParametergetDeclaredAnnotationsByType1/RTParameterGetDeclaredAnnotationsByType1.java @@ -0,0 +1,98 @@ +/* + *- @TestCaseID: RTParameterGetDeclaredAnnotationsByType1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTParameterGetDeclaredAnnotationsByType1.java + *- @Title/Destination: Parameter.getDeclaredAnnotationsByType() returns this element's annotation(s) for the specified + * type if such annotations are either directly present or indirectly present. This method ignores + * inherited annotations. + *- @Condition: no + *- @Brief:no: + * -#step1: 自定义一个类,含有注解的构造方法,不含注解的构造方法和含注解的方法。 + * -#step2:通过调用getConstructor获取自定义类的不含注解的构造方法,通过调用getParameters()获取参数数组,调用 + * getDeclaredAnnotationsByType(Class annotationClass)获取注解数组,annotationClass为注解类型,确认注解数组长度 + * 为0。 + * -#step3:通过调用getDeclaredConstructor获取自定义类的含注解的构造方法,通过调用getParameters()获取参数数组,调用 + * getDeclaredAnnotationsByType(Class annotationClass)获取注解数组,annotationClass为对应的注解类型,对注解 + * 数组调用toString().indexOf(str)判断注解的值是否正确。 + * -#step4:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用 + * getDeclaredAnnotationsByType(Class annotationClass)获取注解数组,annotationClass为对应的注解类型,对注解 + * 数组调用toString().indexOf(str)判断注解的值是否正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTParameterGetDeclaredAnnotationsByType1.java + *- @ExecuteClass: RTParameterGetDeclaredAnnotationsByType1 + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF9 { + int i() default 0; + String t() default ""; +} + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@interface IF9_a { + int c() default 0; + String d() default ""; +} + +class ParameterGetDeclaredAnnotationsByType1 { + ParameterGetDeclaredAnnotationsByType1(@IF9(i = 222, t = "Parameter") int number) { + } + + public ParameterGetDeclaredAnnotationsByType1(String name) { + } + + public void test1(@IF9_a(c = 666, d = "Happy new year") int age) { + } +} + +public class RTParameterGetDeclaredAnnotationsByType1 { + public static void main(String[] args) { + try { + Class cls = Class.forName("ParameterGetDeclaredAnnotationsByType1"); + Constructor cons1 = cls.getDeclaredConstructor(int.class); + Constructor cons2 = cls.getConstructor(String.class); + Method method = cls.getMethod("test1", int.class); + Parameter[] p1 = cons1.getParameters(); + Parameter[] p2 = cons2.getParameters(); + Parameter[] p3 = method.getParameters(); + Annotation[] q1 = p1[0].getDeclaredAnnotationsByType(IF9.class); + Annotation[] q3 = p3[0].getDeclaredAnnotationsByType(IF9_a.class); + if (p2[0].getDeclaredAnnotationsByType(IF9.class).length == 0) { + if (q1[0].toString().indexOf("i=222") != -1 && q1[0].toString().indexOf("t=Parameter") != -1 + && q3[0].toString().indexOf("c=666") != -1 + && q3[0].toString().indexOf("d=Happy new year") != -1) { + System.out.println(0); + return; + } + System.out.println(1); + return; + } + } catch (ClassNotFoundException e) { + System.out.println(2); + return; + } catch (NoSuchMethodException e1) { + System.out.println(3); + return; + } + System.out.println(4); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0109-rt-compact-RTProxygetProxyClass1/RTProxyGetProxyClass1.java b/test/testsuite/ouroboros/compact_test/RT0109-rt-compact-RTProxygetProxyClass1/RTProxyGetProxyClass1.java new file mode 100755 index 0000000000..ba24db6743 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0109-rt-compact-RTProxygetProxyClass1/RTProxyGetProxyClass1.java @@ -0,0 +1,144 @@ +/* + *- @TestCaseID: RTProxyGetProxyClass1 + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:RTProxyGetProxyClass1.java + *- @Title/Destination: Verify that there are more than 30 methods in the class that perform the proxy, and you can + * construct the proxy function normally. + *- @Condition: no + *- @Brief:no: + * -#step1: 构造接口1有30个default方法,接口2继承接口1,接口3有1个方法。 + * -#step2:创建参数1loader为接口1的类加载器,参数2interfaces为class数组,成员为接口1的class,接口2的class。 + * -#step3:调用Proxy的静态方法getProxyClass(ClassLoader loader, Class... interfaces)。 + * -#step4:确认无异常抛出。 + * -#step5:创建参数1loader为接口1的类加载器,参数2interfaces为class数组,成员为接口1的class,接口3的class。 + * -#step6:调用Proxy的静态方法getProxyClass(ClassLoader loader, Class... interfaces)。 + * -#step7:确认无异常抛出。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: RTProxyGetProxyClass1.java + *- @ExecuteClass: RTProxyGetProxyClass1 + *- @ExecuteArgs: + */ + +import java.lang.reflect.Proxy; + +interface ProxyGetProxyClass1_1 { + default void test1() { + } + + default void test2() { + } + + default void test3() { + } + + default void test4() { + } + + default void test5() { + } + + default void test6() { + } + + default void test7() { + } + + default void test8() { + } + + default void test9() { + } + + default void test10() { + } + + default void test11() { + } + + default void test12() { + } + + default void test13() { + } + + default void test14() { + } + + default void test15() { + } + + default void test16() { + } + + default void test17() { + } + + default void test18() { + } + + default void test19() { + } + + default void test20() { + } + + default void test21() { + } + + default void test22() { + } + + default void test23() { + } + + default void test24() { + } + + default void test25() { + } + + default void test26() { + } + + default void test27() { + } + + default void test28() { + } + + default void test29() { + } + + default void test30() { + } +} + +interface ProxyGetProxyClass1_2 extends ProxyGetProxyClass1_1 { + default void test30() { + } +} + +interface ProxyGetProxyClass1_3 { + default void test31() { + } +} + +public class RTProxyGetProxyClass1 { + public static void main(String[] args) { + try { + Proxy.getProxyClass(ProxyGetProxyClass1_1.class.getClassLoader(), new Class[] {ProxyGetProxyClass1_1.class, + ProxyGetProxyClass1_2.class}); + Proxy.getProxyClass(ProxyGetProxyClass1_1.class.getClassLoader(), new Class[] {ProxyGetProxyClass1_1.class, + ProxyGetProxyClass1_3.class}); + } catch (IllegalArgumentException e) { + System.err.println(e); + } + System.out.println(0); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0110-rt-compact-ClassgetDeclaredAnnotationNPE/ClassGetDeclaredAnnotationNPE.java b/test/testsuite/ouroboros/compact_test/RT0110-rt-compact-ClassgetDeclaredAnnotationNPE/ClassGetDeclaredAnnotationNPE.java new file mode 100755 index 0000000000..de4bb54a65 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0110-rt-compact-ClassgetDeclaredAnnotationNPE/ClassGetDeclaredAnnotationNPE.java @@ -0,0 +1,58 @@ +/* + *- @TestCaseID: ClassGetDeclaredAnnotationNPE + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassGetDeclaredAnnotationNPE.java + *- @Title/Destination: Class.getDeclaredAnnotation(null) throws NullPointerException + *- @Condition: no + *- @Brief:no: + * -#step1: 定义内部类MyClass, 获取class MyClass。 + * -#step2:调用getDeclaredAnnotation(Class annotationClass), annotationClass为Deprecated.class。 + * -#step3:确认无异常抛出。 + * -#step4:调用getDeclaredAnnotation(Class annotationClass), annotationClass为null。 + * -#step5:确认抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassGetDeclaredAnnotationNPE.java + *- @ExecuteClass: ClassGetDeclaredAnnotationNPE + *- @ExecuteArgs: + */ + +import java.lang.annotation.Annotation; + +public class ClassGetDeclaredAnnotationNPE { + public static void main(String argv[]) { + int result = 2; /* STATUS_FAILED */ + try { + result = ClassGetDeclaredAnnotationNPE_1(); + } catch (Exception e) { + result = 3; + } + System.out.println(result); + } + + public static int ClassGetDeclaredAnnotationNPE_1() { + try { + Annotation a = MyClass.class.getDeclaredAnnotation(Deprecated.class); + a = MyClass.class.getDeclaredAnnotation(null); + } catch (NullPointerException e) { + return 0; + } + return 4; + } + + @Deprecated + class MyClass extends MySuperClass { + } + + @MyAnnotation + class MySuperClass { + } + + @interface MyAnnotation { + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0111-rt-compact-reflectClasssetisAssignableFrom/ClassIsAssignableFromNPE.java b/test/testsuite/ouroboros/compact_test/RT0111-rt-compact-reflectClasssetisAssignableFrom/ClassIsAssignableFromNPE.java new file mode 100755 index 0000000000..a186e156bc --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0111-rt-compact-reflectClasssetisAssignableFrom/ClassIsAssignableFromNPE.java @@ -0,0 +1,48 @@ +/* + *- @TestCaseID: ClassIsAssignableFromNPE + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassIsAssignableFromNPE.java + *- @Title/Destination: Test isAssignableFrom( null ) throws NullPointerException of class. + *- @Condition: no + *- @Brief:no: + * -#step1: 定义一个int数组intArray,获取intArray的class。 + * -#step2:调用isAssignableFrom(Class cls), cls为null。 + * -#step3:确认抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassIsAssignableFromNPE.java + *- @ExecuteClass: ClassIsAssignableFromNPE + *- @ExecuteArgs: + */ + +public class ClassIsAssignableFromNPE { + public static void main(String argv[]) { + int result = 2; /* STATUS_FAILED */ + try { + result = ClassIsAssignableFromNPE_1(); + } catch (Exception e) { + System.out.println(e); + result = 3; + } + System.out.println(result); + } + + public static int ClassIsAssignableFromNPE_1() { + int result1 = 4; /* STATUS_FAILED */ + int intArray[] = {1, 2, 3, 4, 5}; + Class cl = null; + try { + intArray.getClass().isAssignableFrom(cl); + } catch (SecurityException e) { + return 1; + } catch (NullPointerException e) { + return 0; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0112-rt-compact-ClassGetAnnotationsByType/ClassGetAnnotationsByType.java b/test/testsuite/ouroboros/compact_test/RT0112-rt-compact-ClassGetAnnotationsByType/ClassGetAnnotationsByType.java new file mode 100755 index 0000000000..f0c2f92fab --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0112-rt-compact-ClassGetAnnotationsByType/ClassGetAnnotationsByType.java @@ -0,0 +1,78 @@ +/* + * - @TestCaseID: ClassGetAnnotationsByType + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassGetAnnotationsByType.java + * - @Title/Destination: Class have no Annotation and method have annotation, Class.getAnnotationsByType() return an + * array of length 0. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest0。 + * -#step2:获取class MyTargetTest0。 + * -#step3:调用getAnnotationsByType(Class annotationClass)获取类型为MyTarget的注解数组。 + * -#step4:确认获取的注解数组个数大于0。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ClassGetAnnotationsByType.java + * - @ExecuteClass: ClassGetAnnotationsByType + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class ClassGetAnnotationsByType { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ClassGetAnnotationsByType1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ClassGetAnnotationsByType1() { + Class m; + try { + m = MyTargetTest0.class; + MyTarget[] Target = m.getAnnotationsByType(MyTarget.class); + if (Target.length == 0) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest0 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest0(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0113-rt-compact-ClassGetCanonicalName/ClassGetCanonicalName.java b/test/testsuite/ouroboros/compact_test/RT0113-rt-compact-ClassGetCanonicalName/ClassGetCanonicalName.java new file mode 100755 index 0000000000..bbb5d83a1f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0113-rt-compact-ClassGetCanonicalName/ClassGetCanonicalName.java @@ -0,0 +1,78 @@ +/* + * - @TestCaseID: ClassGetCanonicalName + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassGetCanonicalName.java + * - @Title/Destination: Class.getCanonicalName() Returns the canonical name of the underlying class as defined by the + * Java Language Specification. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest1。 + * -#step2:获取class MyTargetTest1。 + * -#step3:调用getCanonicalName()获取所定义的底层类的规范化名称。 + * -#step4:确认返回的规范化名称正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ClassGetCanonicalName.java + * - @ExecuteClass: ClassGetCanonicalName + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class ClassGetCanonicalName { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ClassGetCanonicalName1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ClassGetCanonicalName1() { + Class m; + try { + m = MyTargetTest1.class; + String str = m.getCanonicalName(); + if ("ClassGetCanonicalName.MyTargetTest1".equals(str)) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest1 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest1(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0114-rt-compact-ClassGetEnclosingClass/ClassGetEnclosingClass.java b/test/testsuite/ouroboros/compact_test/RT0114-rt-compact-ClassGetEnclosingClass/ClassGetEnclosingClass.java new file mode 100755 index 0000000000..1ef7a29336 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0114-rt-compact-ClassGetEnclosingClass/ClassGetEnclosingClass.java @@ -0,0 +1,77 @@ +/* + * - @TestCaseID: ClassGetEnclosingClass + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassGetEnclosingClass.java + * - @Title/Destination: Class.getEnclosingClass() Returns the immediately enclosing class of the underlying class. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest2。 + * -#step2:获取class MyTargetTest2。 + * -#step3:调用getEnclosingClass()获取底层类的立即封闭类。 + * -#step4:确认返回不为空。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ClassGetEnclosingClass.java + * - @ExecuteClass: ClassGetEnclosingClass + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class ClassGetEnclosingClass { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ClassGetEnclosingClass1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ClassGetEnclosingClass1() { + Class m; + try { + m = MyTargetTest2.class; + Class cl = m.getEnclosingClass(); + if (cl != null) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest2 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest2(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0115-rt-compact-ClassGetEnumConstants/ClassGetEnumConstants.java b/test/testsuite/ouroboros/compact_test/RT0115-rt-compact-ClassGetEnumConstants/ClassGetEnumConstants.java new file mode 100755 index 0000000000..5fc17a64f1 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0115-rt-compact-ClassGetEnumConstants/ClassGetEnumConstants.java @@ -0,0 +1,77 @@ +/* + * - @TestCaseID: ClassGetEnumConstants + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassGetEnumConstants.java + * - @Title/Destination: Class getEnumConstants() return null when there is no enum in the class。 + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest3。 + * -#step2:获取class MyTargetTest3。 + * -#step3:调用getEnumConstants()获取枚举类的元素。 + * -#step4:确认返回为空。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ClassGetEnumConstants.java + * - @ExecuteClass: ClassGetEnumConstants + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class ClassGetEnumConstants { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ClassGetEnumConstants1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ClassGetEnumConstants1() { + Class m; + try { + m = MyTargetTest3.class; + MyTargetTest3[] target = m.getEnumConstants(); + if (target == null) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest3 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest3(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0116-rt-compact-ClassGetSimpleName/ClassGetSimpleName.java b/test/testsuite/ouroboros/compact_test/RT0116-rt-compact-ClassGetSimpleName/ClassGetSimpleName.java new file mode 100755 index 0000000000..ec136fa745 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0116-rt-compact-ClassGetSimpleName/ClassGetSimpleName.java @@ -0,0 +1,78 @@ +/* + * - @TestCaseID: ClassGetSimpleName + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassGetSimpleName.java + * - @Title/Destination: Class.getSimpleName() return Returns the simple name of the underlying class as given in the + * source code。 + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest4。 + * -#step2:获取class MyTargetTest4。 + * -#step3:调用getSimpleName()获取底层类的简称。 + * -#step4:确认返回的名称正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ClassGetSimpleName.java + * - @ExecuteClass: ClassGetSimpleName + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class ClassGetSimpleName { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ClassGetSimpleName1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ClassGetSimpleName1() { + Class m; + try { + m = MyTargetTest4.class; + String str = m.getSimpleName(); + if ("MyTargetTest4".equals(str)) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest4 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest4(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0117-rt-compact-ClassGetTypeParameters/ClassGetTypeParameters.java b/test/testsuite/ouroboros/compact_test/RT0117-rt-compact-ClassGetTypeParameters/ClassGetTypeParameters.java new file mode 100755 index 0000000000..b69f5a81ba --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0117-rt-compact-ClassGetTypeParameters/ClassGetTypeParameters.java @@ -0,0 +1,80 @@ +/* + * - @TestCaseID: ClassGetTypeParameters + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassGetTypeParameters.java + * - @Title/Destination: Class.getTypeParameters() return an array of TypeVariable objects that represent the type + * variables declared by the generic declaration represented by this GenericDeclaration object, + * in declaration order. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest5。 + * -#step2:获取class MyTargetTest5。 + * -#step3:调用getTypeParameters()获取TypeVariable对象的一个数组。 + * -#step4:确认返回的数组的长度为0。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ClassGetTypeParameters.java + * - @ExecuteClass: ClassGetTypeParameters + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.TypeVariable; + +public class ClassGetTypeParameters { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ClassGetTypeParameters1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ClassGetTypeParameters1() { + Class m; + try { + m = MyTargetTest5.class; + TypeVariable>[] target = m.getTypeParameters(); + if (target.length == 0) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest5 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest5(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0118-rt-compact-ClassToGenericString/ClassToGenericString.java b/test/testsuite/ouroboros/compact_test/RT0118-rt-compact-ClassToGenericString/ClassToGenericString.java new file mode 100755 index 0000000000..350b8843ca --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0118-rt-compact-ClassToGenericString/ClassToGenericString.java @@ -0,0 +1,79 @@ +/* + * - @TestCaseID: ClassToGenericString + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassToGenericString.java + * - @Title/Destination: Class.toGenericString() returns a string describing this Class, including information about + * modifiers and type parameters. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest5。 + * -#step2:获取class MyTargetTest5。 + * -#step3:调用toGenericString()获取描述此class的字符串。 + * -#step4:确认返回的描述正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ClassToGenericString.java + * - @ExecuteClass: ClassToGenericString + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class ClassToGenericString { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + + try { + result = ClassToGenericString1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ClassToGenericString1() { + Class m; + try { + m = MyTargetTest6.class; + String str = m.toGenericString(); + if ("class ClassToGenericString$MyTargetTest6".equals(str)) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest6 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest6(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0119-rt-compact-ConstructorGetAnnotation/ConstructorGetAnnotation.java b/test/testsuite/ouroboros/compact_test/RT0119-rt-compact-ConstructorGetAnnotation/ConstructorGetAnnotation.java new file mode 100755 index 0000000000..394b7effb1 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0119-rt-compact-ConstructorGetAnnotation/ConstructorGetAnnotation.java @@ -0,0 +1,81 @@ +/* + * - @TestCaseID: ConstructorGetAnnotation.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ConstructorGetAnnotation.java + * - @Title/Destination: Constructor.getAnnotation() return the annotation as expected. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest00。 + * -#step2:通过调用getConstructor(Class[])从内部类MyTargetTest00中获取对应的构造方法。 + * -#step3:调用getAnnotation(Class annotationClass)从构造方法中获取类型为MyTarget的注解。 + * -#step4:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ConstructorGetAnnotation.java + * - @ExecuteClass: ConstructorGetAnnotation + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Constructor; + +public class ConstructorGetAnnotation { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + + try { + result = ConstructorAnnotation1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ConstructorAnnotation1() { + Constructor m; + try { + m = MyTargetTest00.class.getConstructor(new Class[] {ConstructorGetAnnotation.class, String.class}); + MyTarget Target = m.getAnnotation(MyTarget.class); + if ("@ConstructorGetAnnotation$MyTarget(name=cons, value=constructor)".equals(Target.toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest00 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest00(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0120-rt-compact-ConstructorGetDeclaredAnnotations/ConstructorGetDeclaredAnnotations.java b/test/testsuite/ouroboros/compact_test/RT0120-rt-compact-ConstructorGetDeclaredAnnotations/ConstructorGetDeclaredAnnotations.java new file mode 100755 index 0000000000..e139086ae9 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0120-rt-compact-ConstructorGetDeclaredAnnotations/ConstructorGetDeclaredAnnotations.java @@ -0,0 +1,80 @@ +/* + * - @TestCaseID: ConstructorGetDeclaredAnnotations.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ConstructorGetDeclaredAnnotations.java + * - @Title/Destination: Constructor.getDeclaredAnnotation() returns this element's annotation for the specified type if such an annotation is directly present. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest01。 + * -#step2:通过调用getConstructor(Class[])从内部类MyTargetTest01中获取对应的构造方法。 + * -#step3:调用getDeclaredAnnotation(Class annotationClass)从构造方法中获取类型为MyTarget的注解。 + * -#step4:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ConstructorGetDeclaredAnnotations.java + * - @ExecuteClass: ConstructorGetDeclaredAnnotations + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Constructor; + +public class ConstructorGetDeclaredAnnotations { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ConstructorGetDeclaredAnnotations1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ConstructorGetDeclaredAnnotations1() { + Constructor m; + try { + m = MyTargetTest01.class.getConstructor(new Class[] {ConstructorGetDeclaredAnnotations.class, String.class}); + MyTarget Target = m.getDeclaredAnnotation(MyTarget.class); + if ("@ConstructorGetDeclaredAnnotations$MyTarget(name=cons, value=constructor)".equals(Target.toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest01 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest01(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0121-rt-compact-ConstructorGetExceptionTypes/ConstructorGetExceptionTypes.java b/test/testsuite/ouroboros/compact_test/RT0121-rt-compact-ConstructorGetExceptionTypes/ConstructorGetExceptionTypes.java new file mode 100755 index 0000000000..ffaf0ef1bf --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0121-rt-compact-ConstructorGetExceptionTypes/ConstructorGetExceptionTypes.java @@ -0,0 +1,81 @@ +/* + * - @TestCaseID: ConstructorGetExceptionTypes.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ConstructorGetExceptionTypes.java + * - @Title/Destination: Constructor.getExceptionTypes() returns an array of length 0 if the executable declares no + * exceptions in its throws clause. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest02。 + * -#step2:通过调用getConstructor(Class[])从内部类MyTargetTest02中获取对应的构造方法。 + * -#step3:调用getExceptionTypes()获取抛出的异常类型的Class对象的数组。 + * -#step4:确认返回的数组长度是0。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ConstructorGetExceptionTypes.java + * - @ExecuteClass: ConstructorGetExceptionTypes + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Constructor; + +public class ConstructorGetExceptionTypes { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ConstructorGetExceptionTypes1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ConstructorGetExceptionTypes1() { + Constructor m; + try { + m = MyTargetTest02.class.getConstructor(new Class[] {ConstructorGetExceptionTypes.class, String.class}); + Class[] Target = m.getExceptionTypes(); + if (Target.length == 0) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest02 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest02(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0122-rt-compact-ConstructorGetTypeParameters/ConstructorGetTypeParameters.java b/test/testsuite/ouroboros/compact_test/RT0122-rt-compact-ConstructorGetTypeParameters/ConstructorGetTypeParameters.java new file mode 100755 index 0000000000..0009de70c4 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0122-rt-compact-ConstructorGetTypeParameters/ConstructorGetTypeParameters.java @@ -0,0 +1,82 @@ +/* + * - @TestCaseID: ConstructorGetTypeParameters.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ConstructorGetTypeParameters.java + * - @Title/Destination: Constructor.getTypeParameters() returns an array of length 0 if the underlying generic + * declaration declares no type variables. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest03。 + * -#step2:通过调用getConstructor(Class[])从内部类MyTargetTest03中获取对应的构造方法。 + * -#step3:调用getTypeParameters()获取TypeVariable对象的数组。 + * -#step4:确认返回的数组长度是0。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ConstructorGetTypeParameters.java + * - @ExecuteClass: ConstructorGetTypeParameters + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Constructor; +import java.lang.reflect.TypeVariable; + +public class ConstructorGetTypeParameters { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ConstructorGetTypeParameters1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ConstructorGetTypeParameters1() { + Constructor m; + try { + m = MyTargetTest03.class.getConstructor(new Class[] {ConstructorGetTypeParameters.class, String.class}); + TypeVariable>[] Target = m.getTypeParameters(); + if (Target.length == 0) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest03 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest03(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0123-rt-compact-ConstructorToGenericString/ConstructorToGenericString.java b/test/testsuite/ouroboros/compact_test/RT0123-rt-compact-ConstructorToGenericString/ConstructorToGenericString.java new file mode 100755 index 0000000000..5769f5834b --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0123-rt-compact-ConstructorToGenericString/ConstructorToGenericString.java @@ -0,0 +1,82 @@ +/* + * - @TestCaseID: ConstructorToGenericString.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ConstructorToGenericString.java + * - @Title/Destination: Constructor.toGenericString() returns a string describing this Constructor, including type + * parameters. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest04。 + * -#step2:通过调用getConstructor(Class[])从内部类MyTargetTest04中获取对应的构造方法。 + * -#step3:调用toGenericString()获取描述此Field的字符串。 + * -#step4:确认返回的描述正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ConstructorToGenericString.java + * - @ExecuteClass: ConstructorToGenericString + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Constructor; + +public class ConstructorToGenericString { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ConstructorToGenericString1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ConstructorToGenericString1() { + Constructor m; + try { + m = MyTargetTest04.class.getConstructor(new Class[] {ConstructorToGenericString.class, String.class}); + String str = m.toGenericString(); + if ("public ConstructorToGenericString$MyTargetTest04(ConstructorToGenericString,java.lang.String)" + .equals(str)) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest04 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest04(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0124-rt-compact-FieldGetAnnotation/FieldGetAnnotation.java b/test/testsuite/ouroboros/compact_test/RT0124-rt-compact-FieldGetAnnotation/FieldGetAnnotation.java new file mode 100755 index 0000000000..a7d47f8652 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0124-rt-compact-FieldGetAnnotation/FieldGetAnnotation.java @@ -0,0 +1,72 @@ +/* + * - @TestCaseID: FieldGetAnnotation.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:FieldGetAnnotation.java + * - @Title/Destination: Field.getAnnotation() Returns the Field's annotation for the specified type if such an + * annotation is present. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest06。 + * -#step2:通过调用getField()从内部类MyTargetTest06中获取home。 + * -#step3:调用getAnnotation(Class annotationClass)获取类型为MyTarget的注解。 + * -#step4:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: FieldGetAnnotation.java + * - @ExecuteClass: FieldGetAnnotation + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Field; + +public class FieldGetAnnotation { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = FieldGetAnnotation1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int FieldGetAnnotation1() { + Field m; + try { + m = MyTargetTest06.class.getField("home"); + MyTarget Target = m.getAnnotation(MyTarget.class); + if ("@FieldGetAnnotation$MyTarget(name=newName, value=newValue)".equals(Target.toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest06 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0125-rt-compact-FieldGetAnnotationsByType/FieldGetAnnotationsByType.java b/test/testsuite/ouroboros/compact_test/RT0125-rt-compact-FieldGetAnnotationsByType/FieldGetAnnotationsByType.java new file mode 100755 index 0000000000..44d19ffaad --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0125-rt-compact-FieldGetAnnotationsByType/FieldGetAnnotationsByType.java @@ -0,0 +1,80 @@ +/* + * - @TestCaseID: FieldGetAnnotationsByType.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:FieldGetAnnotationsByType.java + * - @Title/Destination: Field.getAnnotationsByType() returns annotations that are associated with this element. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest07。 + * -#step2:通过调用getField()从内部类MyTargetTest07中获取home。 + * -#step3:调用getAnnotationsByType(Class annotationClass)获取类型为MyTarget的注解数组。 + * -#step4:确认获取的注解数组个数大于0。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: FieldGetAnnotationsByType.java + * - @ExecuteClass: FieldGetAnnotationsByType + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Field; + +public class FieldGetAnnotationsByType { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = FieldGetAnnotationsByType1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int FieldGetAnnotationsByType1() { + Field m; + try { + m = MyTargetTest07.class.getField("home"); + MyTarget[] Target = m.getAnnotationsByType(MyTarget.class); + if (Target.length > 0) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest07 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest07(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0126-rt-compact-FieldGetDeclaredAnnotations/FieldGetDeclaredAnnotations.java b/test/testsuite/ouroboros/compact_test/RT0126-rt-compact-FieldGetDeclaredAnnotations/FieldGetDeclaredAnnotations.java new file mode 100755 index 0000000000..c5ad4e6640 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0126-rt-compact-FieldGetDeclaredAnnotations/FieldGetDeclaredAnnotations.java @@ -0,0 +1,80 @@ +/* + * - @TestCaseID: FieldGetDeclaredAnnotations.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:FieldGetDeclaredAnnotations.java + * - @Title/Destination: Field.getDeclaredAnnotation returns annotations that are directly present on this element. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest08。 + * -#step2:通过调用getField()从内部类MyTargetTest08中获取home。 + * -#step3:调用getDeclaredAnnotation(Class annotationClass)获取类型为MyTarget的注解。 + * -#step4:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: FieldGetDeclaredAnnotations.java + * - @ExecuteClass: FieldGetDeclaredAnnotations + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Field; + +public class FieldGetDeclaredAnnotations { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = MethodGetDeclaredAnnotations1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int MethodGetDeclaredAnnotations1() { + Field m; + try { + m = MyTargetTest08.class.getField("home"); + MyTarget Target = m.getDeclaredAnnotation(MyTarget.class); + if ("@FieldGetDeclaredAnnotations$MyTarget(name=newName, value=newValue)".equals(Target.toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest08 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest08(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0127-rt-compact-FieldIsAnnotationPresent/FieldIsAnnotationPresent.java b/test/testsuite/ouroboros/compact_test/RT0127-rt-compact-FieldIsAnnotationPresent/FieldIsAnnotationPresent.java new file mode 100755 index 0000000000..a84ffed06e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0127-rt-compact-FieldIsAnnotationPresent/FieldIsAnnotationPresent.java @@ -0,0 +1,80 @@ +/* + * - @TestCaseID: FieldIsAnnotationPresent.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:FieldIsAnnotationPresent.java + * - @Title/Destination: Field.isAnnotationPresent() Returns true if an annotation for the specified type is present on this element, else false + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest09。 + * -#step2:通过调用getField()从内部类MyTargetTest08中获取home。 + * -#step3:调用isAnnotationPresent(Class annotationClass)判断是否存在类型为MyTarget的注解。 + * -#step4:确认返回true。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: FieldIsAnnotationPresent.java + * - @ExecuteClass: FieldIsAnnotationPresent + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Field; + +public class FieldIsAnnotationPresent { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = MethodIsAnnotationPresent1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int MethodIsAnnotationPresent1() { + Field m; + try { + m = MyTargetTest09.class.getField("home"); + boolean flag = m.isAnnotationPresent(MyTarget.class); + if (flag) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest09 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest09(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0128-rt-compact-FieldToGenericString/FieldToGenericString.java b/test/testsuite/ouroboros/compact_test/RT0128-rt-compact-FieldToGenericString/FieldToGenericString.java new file mode 100755 index 0000000000..949696013f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0128-rt-compact-FieldToGenericString/FieldToGenericString.java @@ -0,0 +1,80 @@ +/* + * - @TestCaseID: FieldToGenericString + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:FieldToGenericString.java + * - @Title/Destination: Field.toGenericString() returns a string describing this Field, including its generic type. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest10。 + * -#step2:通过调用getField()从内部类MyTargetTest10中获取home。 + * -#step3:调用toGenericString()获取描述此Field的字符串。 + * -#step4:确认返回的描述正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: FieldToGenericString.java + * - @ExecuteClass: FieldToGenericString + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Field; + +public class FieldToGenericString { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = FieldToGenericString1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int FieldToGenericString1() { + Field m; + try { + m = MyTargetTest10.class.getField("home"); + String str = m.toGenericString(); + if ("public java.lang.String FieldToGenericString$MyTargetTest10.home".equals(str)) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest10 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest10(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0129-rt-compact-MethodGetAnnotation/MethodGetAnnotation.java b/test/testsuite/ouroboros/compact_test/RT0129-rt-compact-MethodGetAnnotation/MethodGetAnnotation.java new file mode 100755 index 0000000000..fa3602c7fc --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0129-rt-compact-MethodGetAnnotation/MethodGetAnnotation.java @@ -0,0 +1,70 @@ +/* + * - @TestCaseID: MethodGetAnnotation + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodGetAnnotation.java + * - @Title/Destination: Method.getAnnotation Returns this element's annotation for the specified type if such an + * annotation is present, else null. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest11。 + * -#step2:通过调用getMethod()从内部类MyTargetTest11中获取MyTargetTest_1。 + * -#step3:调用getAnnotation(Class annotationClass)获取类型为MyTarget的注解。 + * -#step4:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: MethodGetAnnotation.java + * - @ExecuteClass: MethodGetAnnotation + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; + +public class MethodGetAnnotation { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = MethodGetAnnotation1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int MethodGetAnnotation1() { + Method m; + try { + m = MyTargetTest11.class.getMethod("MyTargetTest_1"); + MyTarget Target = m.getAnnotation(MyTarget.class); + if ("@MethodGetAnnotation$MyTarget(name=name, value=value)".equals(Target.toString())) { + return 0; + } + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest11 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0130-rt-compact-MethodGetDeclaredAnnotations/MethodGetDeclaredAnnotations.java b/test/testsuite/ouroboros/compact_test/RT0130-rt-compact-MethodGetDeclaredAnnotations/MethodGetDeclaredAnnotations.java new file mode 100755 index 0000000000..4ab360c3f2 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0130-rt-compact-MethodGetDeclaredAnnotations/MethodGetDeclaredAnnotations.java @@ -0,0 +1,79 @@ +/* + * - @TestCaseID: MethodGetDeclaredAnnotations + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodGetDeclaredAnnotations.java + * - @Title/Destination: Method.getDeclaredAnnotation() returns this element's annotation for the specified type if such + * an annotation is directly present。 + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest12。 + * -#step2:通过调用getMethod()从内部类MyTargetTest12中获取MyTargetTest_1。 + * -#step3:调用getDeclaredAnnotation(Class annotationClass)获取类型为MyTarget的注解。 + * -#step4:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: MethodGetDeclaredAnnotations.java + * - @ExecuteClass: MethodGetDeclaredAnnotations + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; + +public class MethodGetDeclaredAnnotations { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = MethodGetDeclaredAnnotations1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int MethodGetDeclaredAnnotations1() { + Method m; + try { + m = MyTargetTest12.class.getMethod("MyTargetTest_1"); + MyTarget Target = m.getDeclaredAnnotation(MyTarget.class); + if ("@MethodGetDeclaredAnnotations$MyTarget(name=name, value=value)".equals(Target.toString())) { + return 0; + } + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest12 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest12(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0131-rt-compact-MethodgetDefaultValue/MethodGetDefaultValue.java b/test/testsuite/ouroboros/compact_test/RT0131-rt-compact-MethodgetDefaultValue/MethodGetDefaultValue.java new file mode 100755 index 0000000000..87a7d52494 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0131-rt-compact-MethodgetDefaultValue/MethodGetDefaultValue.java @@ -0,0 +1,63 @@ +/* + * - @TestCaseID: MethodGetDefaultValue + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodGetDefaultValue.java + * - @Title/Destination: Method.getDefaultValue returns the default value for the annotation member represented by this + * Method instance. Returns null if no default is associated with the member。 + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest13。 + * -#step2:通过调用getMethod()从内部类MyTargetTest13中获取MyTargetTest_1。 + * -#step3:调用getDefaultValue()获取注解成员的默认值。 + * -#step4:确认获取为null,无异常抛出。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: MethodGetDefaultValue.java + * - @ExecuteClass: MethodGetDefaultValue + * - @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Method; + +public class MethodGetDefaultValue { + public static void main(String[] argv) { + int result = 2/* STATUS_FAILED */; + try { + result = MethodGetDefaultValueTypeNotPresent_1(); + } catch (Exception e) { + result = 3; + } + System.out.println(result); + } + + public static int MethodGetDefaultValueTypeNotPresent_1() { + try { + Method m = MyTargetTest13.class.getMethod("MyTargetTest_1"); + Object a = m.getDefaultValue(); + } catch (TypeNotPresentException e) { + return 3; + } catch (NoSuchMethodException e) { + return 4; + } + return 0; + } + + @Target(ElementType.TYPE) + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + Class style() default String.class; + } + + @MyTarget() + class MyTargetTest13 { + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0132-rt-compact-MethodGetParameterCount/MethodGetParameterCount.java b/test/testsuite/ouroboros/compact_test/RT0132-rt-compact-MethodGetParameterCount/MethodGetParameterCount.java new file mode 100755 index 0000000000..b505f49595 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0132-rt-compact-MethodGetParameterCount/MethodGetParameterCount.java @@ -0,0 +1,79 @@ +/* + * - @TestCaseID: MethodGetParameterCount + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodGetParameterCount.java + * - @Title/Destination: Method.getParameterCount() returns the number of formal parameters. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest14。 + * -#step2:通过调用getMethod()从内部类MyTargetTest14中获取MyTargetTest_1。 + * -#step3:调用getParameterCount()获取参数个数。 + * -#step4:确认返回的参数个数是0。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: MethodGetParameterCount.java + * - @ExecuteClass: MethodGetParameterCount + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; + +public class MethodGetParameterCount { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + + try { + result = MethodGetParameterCount1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int MethodGetParameterCount1() { + Method m; + try { + m = MyTargetTest14.class.getMethod("MyTargetTest_1"); + int num = m.getParameterCount(); + if (num == 0) { + return 0; + } + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest14 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest14(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0133-rt-compact-MethodGetTypeParameters/MethodGetTypeParameters.java b/test/testsuite/ouroboros/compact_test/RT0133-rt-compact-MethodGetTypeParameters/MethodGetTypeParameters.java new file mode 100755 index 0000000000..885a4f7b94 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0133-rt-compact-MethodGetTypeParameters/MethodGetTypeParameters.java @@ -0,0 +1,79 @@ +/* + * - @TestCaseID: MethodGetTypeParameters + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodGetTypeParameters.java + * - @Title/Destination: Method.getTypeParameters() returns an array of TypeVariable objects. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest15。 + * -#step2:通过调用getMethod()从内部类MyTargetTest15中获取MyTargetTest_1。 + * -#step3:调用getTypeParameters()获取TypeVariable对象的数组。 + * -#step4:确认返回的数组长度是0。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: MethodGetTypeParameters.java + * - @ExecuteClass: MethodGetTypeParameters + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; +import java.lang.reflect.TypeVariable; + +public class MethodGetTypeParameters { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = MethodGetTypeParameters1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int MethodGetTypeParameters1() { + Method m; + try { + m = MyTargetTest15.class.getMethod("MyTargetTest_1"); + TypeVariable[] Target = m.getTypeParameters(); + if (Target.length == 0) { + return 0; + } + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest15 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest15(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0134-rt-compact-MethodIsDefault/MethodIsDefault.java b/test/testsuite/ouroboros/compact_test/RT0134-rt-compact-MethodIsDefault/MethodIsDefault.java new file mode 100755 index 0000000000..10b6ec5773 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0134-rt-compact-MethodIsDefault/MethodIsDefault.java @@ -0,0 +1,78 @@ +/* + * - @TestCaseID: MethodIsDefault + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodIsDefault.java + * - @Title/Destination: Method.isDefault() Returns true if this method is a default method。 + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest16。 + * -#step2:通过调用getMethod()从内部类MyTargetTest16中获取MyTargetTest_1。 + * -#step3:调用isDefault()判断是否是default method。 + * -#step4:确认返回false。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: MethodIsDefault.java + * - @ExecuteClass: MethodIsDefault + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; + +public class MethodIsDefault { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = MethodIsDefault1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int MethodIsDefault1() { + Method m; + try { + m = MyTargetTest16.class.getMethod("MyTargetTest_1"); + boolean flag = m.isDefault(); + if (!flag) { + return 0; + } + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest16 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest16(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0135-rt-compact-MethodToGenericString/MethodToGenericString.java b/test/testsuite/ouroboros/compact_test/RT0135-rt-compact-MethodToGenericString/MethodToGenericString.java new file mode 100755 index 0000000000..6c6f3c3c9b --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0135-rt-compact-MethodToGenericString/MethodToGenericString.java @@ -0,0 +1,78 @@ +/* + * - @TestCaseID: MethodToGenericString + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodToGenericString.java + * - @Title/Destination: Method.toGenericString() Returns a string describing this Method, including type parameters. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest15。 + * -#step2:通过调用getMethod()从内部类MyTargetTest15中获取MyTargetTest_1。 + * -#step3:调用toGenericString()获取描述此Method的字符串。 + * -#step4:确认返回的描述正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: MethodToGenericString.java + * - @ExecuteClass: MethodToGenericString + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; + +public class MethodToGenericString { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = MethodToGenericString1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int MethodToGenericString1() { + Method m; + try { + m = MyTargetTest17.class.getMethod("MyTargetTest_1"); + String str = m.toGenericString(); + if ("public void MethodToGenericString$MyTargetTest17.MyTargetTest_1()".equals(str)) { + return 0; + } + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest17 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest17(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0136-rt-compact-ParameterGetAnnotation/ParameterGetAnnotation.java b/test/testsuite/ouroboros/compact_test/RT0136-rt-compact-ParameterGetAnnotation/ParameterGetAnnotation.java new file mode 100755 index 0000000000..95db4dea68 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0136-rt-compact-ParameterGetAnnotation/ParameterGetAnnotation.java @@ -0,0 +1,79 @@ +/* + * - @TestCaseID: ParameterGetAnnotation + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ParameterGetAnnotation.java + * - @Title/Destination: Parameter.getAnnotation() Returns this element's annotation for the specified type if such an + * annotation is present, else null. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest18。 + * -#step2:通过调用getMethod()从内部类MyTargetTest18中获取newMethod。 + * -#step3:调用getParameters()获取所有的参数。 + * -#step4:调用getAnnotation(Class annotationClass)获取类型为MyTarget的注解。 + * -#step5:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ParameterGetAnnotation.java + * - @ExecuteClass: ParameterGetAnnotation + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterGetAnnotation { + public static void main(String[] args) { + int result = 2; + try { + result = ParameterGetAnnotation1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ParameterGetAnnotation1() { + Method m; + try { + m = MyTargetTest18.class.getMethod("newMethod", new Class[] {String.class}); + Parameter[] parameters = m.getParameters(); + MyTarget Target = parameters[0].getAnnotation(MyTarget.class); + if ("@ParameterGetAnnotation$MyTarget(name=name1, value=value1)".equals(Target.toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest18 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0137-rt-compact-ParameterGetAnnotations/ParameterGetAnnotations.java b/test/testsuite/ouroboros/compact_test/RT0137-rt-compact-ParameterGetAnnotations/ParameterGetAnnotations.java new file mode 100755 index 0000000000..6fe4853d7c --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0137-rt-compact-ParameterGetAnnotations/ParameterGetAnnotations.java @@ -0,0 +1,84 @@ +/* + * - @TestCaseID: ParameterGetAnnotations + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ParameterGetAnnotations.java + * - @Title/Destination: Parameter.getAnnotations() Returns annotations that are present on this element. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest19。 + * -#step2:通过调用getMethod()从内部类MyTargetTest19中获取newMethod。 + * -#step3:调用getParameters()获取所有的参数。 + * -#step4:调用getAnnotations()获取类型为MyTarget的注解。 + * -#step5:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ParameterGetAnnotations.java + * - @ExecuteClass: ParameterGetAnnotations + * - @ExecuteArgs: + */ + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.lang.annotation.Annotation; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class ParameterGetAnnotations { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ParameterGetAnnotations1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ParameterGetAnnotations1() { + Method m; + try { + m = MyTargetTest19.class.getMethod("newMethod", new Class[] {String.class}); + Parameter[] parameters = m.getParameters(); + Annotation[] Target = parameters[0].getAnnotations(); + if ("@ParameterGetAnnotations$MyTarget(name=name1, value=value1)".equals(Target[0].toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest19 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest19(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0138-rt-compact-ParameterGetAnnotationsByType/ParameterGetAnnotationsByType.java b/test/testsuite/ouroboros/compact_test/RT0138-rt-compact-ParameterGetAnnotationsByType/ParameterGetAnnotationsByType.java new file mode 100755 index 0000000000..7417dc914e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0138-rt-compact-ParameterGetAnnotationsByType/ParameterGetAnnotationsByType.java @@ -0,0 +1,85 @@ +/* + * - @TestCaseID: ParameterGetAnnotationsByType.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ParameterGetAnnotationsByType.java + * - @Title/Destination: Parameter.getAnnotationsByType(Class annotationClass) Returns annotations that are + * associated with this element. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest20。 + * -#step2:通过调用getMethod()从内部类MyTargetTest20中获取newMethod。 + * -#step3:调用getParameters()获取所有的参数。 + * -#step4:调用getAnnotationsByType(Class annotationClass)获取所有类型为MyTarget的注解。 + * -#step5:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ParameterGetAnnotationsByType.java + * - @ExecuteClass: ParameterGetAnnotationsByType + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterGetAnnotationsByType { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + + try { + result = ParameterGetAnnotationsByType1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ParameterGetAnnotationsByType1() { + Method m; + try { + m = MyTargetTest20.class.getMethod("newMethod", new Class[] {String.class}); + Parameter[] parameters = m.getParameters(); + MyTarget[] Target = parameters[0].getAnnotationsByType(MyTarget.class); + if ("@ParameterGetAnnotationsByType$MyTarget(name=name1, value=value1)".equals(Target[0].toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest20 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest20(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0139-rt-compact-ParameterGetDeclaredAnnotation/ParameterGetDeclaredAnnotation.java b/test/testsuite/ouroboros/compact_test/RT0139-rt-compact-ParameterGetDeclaredAnnotation/ParameterGetDeclaredAnnotation.java new file mode 100755 index 0000000000..f2e8ebe0b9 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0139-rt-compact-ParameterGetDeclaredAnnotation/ParameterGetDeclaredAnnotation.java @@ -0,0 +1,85 @@ +/* + * - @TestCaseID: ParameterGetDeclaredAnnotation.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ParameterGetDeclaredAnnotation.java + * - @Title/Destination: Parameter.getDeclaredAnnotation(Class annotationClass) returns this element's annotation for + * the specified type if such an annotation is directly present, else null. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest21。 + * -#step2:通过调用getMethod()从内部类MyTargetTest21中获取newMethod。 + * -#step3:调用getParameters()获取所有的参数。 + * -#step4:调用getDeclaredAnnotation(Class annotationClass)获取所有类型为MyTarget的注解。 + * -#step5:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ParameterGetDeclaredAnnotation.java + * - @ExecuteClass: ParameterGetDeclaredAnnotation + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterGetDeclaredAnnotation { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + + try { + result = ParameterGetDeclaredAnnotation1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ParameterGetDeclaredAnnotation1() { + Method m; + try { + m = MyTargetTest21.class.getMethod("newMethod", new Class[] {String.class}); + Parameter[] parameters = m.getParameters(); + MyTarget Target = parameters[0].getDeclaredAnnotation(MyTarget.class); + if ("@ParameterGetDeclaredAnnotation$MyTarget(name=name1, value=value1)".equals(Target.toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest21 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest21(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0140-rt-compact-ParameterGetDeclaredAnnotations/ParameterGetDeclaredAnnotations.java b/test/testsuite/ouroboros/compact_test/RT0140-rt-compact-ParameterGetDeclaredAnnotations/ParameterGetDeclaredAnnotations.java new file mode 100755 index 0000000000..15027aec94 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0140-rt-compact-ParameterGetDeclaredAnnotations/ParameterGetDeclaredAnnotations.java @@ -0,0 +1,84 @@ +/* + * - @TestCaseID: ParameterGetDeclaredAnnotations.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ParameterGetDeclaredAnnotations.java + * - @Title/Destination: Parameter.getDeclaredAnnotations() return annotations that are directly present on this element. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest22。 + * -#step2:通过调用getMethod()从内部类MyTargetTest22中获取newMethod。 + * -#step3:调用getParameters()获取所有的参数。 + * -#step4:调用getDeclaredAnnotations()获取所有注解。 + * -#step5:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ParameterGetDeclaredAnnotations.java + * - @ExecuteClass: ParameterGetDeclaredAnnotations + * - @ExecuteArgs: + */ + +import java.lang.annotation.Annotation; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterGetDeclaredAnnotations { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ParameterGetDeclaredAnnotations1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ParameterGetDeclaredAnnotations1() { + Method m; + try { + m = MyTargetTest22.class.getMethod("newMethod", new Class[] {String.class}); + Parameter[] parameters = m.getParameters(); + Annotation[] Target = parameters[0].getDeclaredAnnotations(); + if ("@ParameterGetDeclaredAnnotations$MyTarget(name=name1, value=value1)".equals(Target[0].toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest22 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest22(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0141-rt-compact-ParameterGetDeclaredAnnotationsByType/ParameterGetDeclaredAnnotationsByType.java b/test/testsuite/ouroboros/compact_test/RT0141-rt-compact-ParameterGetDeclaredAnnotationsByType/ParameterGetDeclaredAnnotationsByType.java new file mode 100755 index 0000000000..ea06f447dd --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0141-rt-compact-ParameterGetDeclaredAnnotationsByType/ParameterGetDeclaredAnnotationsByType.java @@ -0,0 +1,85 @@ +/* + * - @TestCaseID: ParameterGetDeclaredAnnotationsByType.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ParameterGetDeclaredAnnotationsByType.java + * - @Title/Destination: Parameter.getDeclaredAnnotationsByType(Class annotationClass) Returns this element's + * annotation(s) for the specified type if such annotations are either directly present or + * indirectly present. + * - @Condition: no + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest22。 + * -#step2:通过调用getMethod()从内部类MyTargetTest22中获取newMethod。 + * -#step3:调用getParameters()获取所有的参数。 + * -#step4:调用getDeclaredAnnotationsByType(Class annotationClass)获取类型为MyTarget的注解。 + * -#step5:确认获取的注解正确。 + * - @Expect: 0\n + * - @Priority: High + * - @Remark: + * - @Source: ParameterGetDeclaredAnnotationsByType.java + * - @ExecuteClass: ParameterGetDeclaredAnnotationsByType + * - @ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterGetDeclaredAnnotationsByType { + @Retention(RetentionPolicy.RUNTIME) + public @interface MyTarget { + public String name(); + public String value(); + } + + public static void main(String[] args) { + int result = 2; + try { + result = ParameterGetDeclaredAnnotationsByType1(); + } catch (Exception e) { + e.printStackTrace(); + result = 3; + } + System.out.println(result); + } + + public static int ParameterGetDeclaredAnnotationsByType1() { + Method m; + try { + m = MyTargetTest23.class.getMethod("newMethod", new Class[] {String.class}); + Parameter[] parameters = m.getParameters(); + MyTarget[] Target = parameters[0].getDeclaredAnnotationsByType(MyTarget.class); + if ("@ParameterGetDeclaredAnnotationsByType$MyTarget(name=name1, value=value1)".equals(Target[0].toString())) { + return 0; + } + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return 2; + } + + class MyTargetTest23 { + @MyTarget(name = "newName", value = "newValue") + public String home; + + @MyTarget(name = "name", value = "value") + public void MyTargetTest_1() { + System.out.println("This is Example:hello world"); + } + + public void newMethod(@MyTarget(name = "name1", value = "value1") String home) { + System.out.println("my home at:" + home); + } + + @MyTarget(name = "cons", value = "constructor") + public MyTargetTest23(String home) { + this.home = home; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0142-rt-compact-ReflectionAnnotationGetClass/ReflectionAnnotationGetClass.java b/test/testsuite/ouroboros/compact_test/RT0142-rt-compact-ReflectionAnnotationGetClass/ReflectionAnnotationGetClass.java new file mode 100755 index 0000000000..0eec1a947c --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0142-rt-compact-ReflectionAnnotationGetClass/ReflectionAnnotationGetClass.java @@ -0,0 +1,65 @@ +/* + *- @testCaseID: ReflectionAnnotationGetClass + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectionAnnotationGetClass.java + *- @Title/Destination: Try to getClass of an Annotation, the result should contain "class $Proxy". add for + * DTS2018122012009. + *- @Condition: no + *- @Brief:no: + * -#step1: Define an Annotation A0 and define Class Two has one annotation A0. + * -#step2: Get class by forName("Two"), call getAnnotations() of the get class. + * -#step3: Check the Class of get annotation is "class $Proxy0". + * -#step4: Get class by forName("java.lang.annotation.Documented"), call getAnnotations() of the get class. + * -#step5: Check the three Class of get annotation is "class $Proxy1", "class $Proxy2", "class $Proxy3". + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ReflectionAnnotationGetClass.java + *- @ExecuteClass: ReflectionAnnotationGetClass + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.util.Arrays; + +public class ReflectionAnnotationGetClass { + public static void main(String[] args) { + int result = 2; + try{ + // Check point 1 : only 1 annotation in user-defined Class Two. + Annotation[] annotations1 = Class.forName("Two").getAnnotations(); + if (annotations1.length == 1){ + if (annotations1[0].getClass().toString().startsWith("class $Proxy")) { + result --; + } + } + + // Check point 2 : 3 annotations in Class java.lang.annotation.Documented. + Annotation[] annotations2 = Class.forName("java.lang.annotation.Documented").getAnnotations(); + String [] annoClazz = new String[annotations2.length]; + for (int i = 0; i < annoClazz.length; i++) { + annoClazz[i] = annotations2[i].getClass().toString(); + } + Arrays.sort(annoClazz); + if (annotations2.length == 3) { + if (annoClazz[0].startsWith("class $Proxy") && annoClazz[1] + .startsWith("class $Proxy") + && annoClazz[2].startsWith("class $Proxy")) { + result --; + } + } + }catch (Exception e) { + result = 3; + } + System.out.println(result); + } +} + +@A0 +class Two{} + +@Retention(RetentionPolicy.RUNTIME) @interface A0 {} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0143-rt-compact-ClinitClassNewInstance/ClassInitClassNewInstance.java b/test/testsuite/ouroboros/compact_test/RT0143-rt-compact-ClinitClassNewInstance/ClassInitClassNewInstance.java new file mode 100755 index 0000000000..f900cbc338 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0143-rt-compact-ClinitClassNewInstance/ClassInitClassNewInstance.java @@ -0,0 +1,154 @@ +/* + *- @TestCaseID: ClassInitClassNewInstance + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitClassNewInstance.java + *- @Title/Destination: When call Class.newInstance, class is initialized; when call other methods of Class, class is + * not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) to get the class One. + * -#step2: Call methods of Class except newInstance() and forName(), class One is not initialized. + * -#step3: call method newInstance(), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitClassNewInstance.java + *- @ExecuteClass: ClassInitClassNewInstance + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; + +public class ClassInitClassNewInstance { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try{ + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + + /* Check point 1: no class initialization when calling following methods of Class + * not test clazz.cast(Object obj) because it success only when obj is an instance of One or Two, + * and need to call new One(), which result in Class initialization. */ + clazz.asSubclass(clazz); + clazz.desiredAssertionStatus(); + clazz.getAnnotation(A.class); + clazz.getAnnotations(); + clazz.getAnnotationsByType(A.class); + clazz.getCanonicalName(); + clazz.getClasses(); + clazz.getClassLoader(); + clazz.getComponentType(); + clazz.getConstructor(String.class); + clazz.getConstructors(); + clazz.getDeclaredAnnotation(A.class); + clazz.getDeclaredAnnotations(); + clazz.getDeclaredAnnotationsByType(A.class); + clazz.getDeclaredClasses(); + clazz.getDeclaredConstructor(String.class); + clazz.getDeclaredConstructors(); + clazz.getDeclaredField("what"); + clazz.getDeclaredFields(); + clazz.getDeclaredMethod("testOne", String.class); + clazz.getDeclaredMethods(); + clazz.getDeclaringClass(); + clazz.getEnclosingClass(); + clazz.getEnclosingConstructor(); + clazz.getEnclosingMethod(); + clazz.getEnumConstants(); + clazz.getField("hi"); + clazz.getFields(); + clazz.getGenericInterfaces(); + clazz.getGenericSuperclass(); + clazz.getInterfaces(); + clazz.getMethod("testOne",String.class); + clazz.getMethods(); + clazz.getModifiers(); + clazz.getName(); + clazz.getPackage(); + clazz.getProtectionDomain(); + clazz.getSigners(); + clazz.getSimpleName(); + clazz.getSuperclass(); + clazz.getTypeName(); + clazz.getTypeParameters(); + clazz.isAnnotation(); + clazz.isAnnotationPresent(A.class); + clazz.isAnonymousClass(); + clazz.isArray(); + clazz.isAssignableFrom(clazz); + clazz.isEnum(); + clazz.isInstance(new Object()); + clazz.isInterface(); + clazz.isLocalClass(); + clazz.isMemberClass(); + clazz.isPrimitive(); + clazz.isSynthetic(); + clazz.toString(); + clazz.toGenericString(); + clazz.getResource("hi"); + clazz.getResourceAsStream("hi"); + + // Check point 2: when call newInstance, start class initialization + if (result.toString().compareTo("") == 0) { + clazz.newInstance(); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitClassNewInstance.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitClassNewInstance.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitClassNewInstance.result.append("One"); + } + + String what = "lala"; + public String hi = ""; + One(){} + + public One(String s){ + what = s; + System.out.println(s); + } + + public int testOne(String a){ + System.out.println(a); + return 0; + } +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitClassNewInstance.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitClassNewInstance.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0144-rt-compact-ClinitConstructorNewInstance/ClassInitConstructorNewInstance.java b/test/testsuite/ouroboros/compact_test/RT0144-rt-compact-ClinitConstructorNewInstance/ClassInitConstructorNewInstance.java new file mode 100755 index 0000000000..8b282ae9cc --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0144-rt-compact-ClinitConstructorNewInstance/ClassInitConstructorNewInstance.java @@ -0,0 +1,107 @@ +/* + *- @TestCaseID: ClassInitConstructorNewInstance + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitConstructorNewInstance.java + *- @Title/Destination: When call Constructor.newInstance, class is initialized; when call other methods of Constructor, + * class is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getConstructor to get Constructor of + * class One. + * -#step2: Call methods of Class except newInstance(), class One is not initialized. + * -#step3: call method newInstance(), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: getAnnotatedReceiverType and getAnnotatedReturnType not support in Android + *- @Source: ClassInitConstructorNewInstance.java + *- @ExecuteClass: ClassInitConstructorNewInstance + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Constructor; + +public class ClassInitConstructorNewInstance { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Constructor constructor = clazz.getConstructor(String.class); + //check point 1: calling following methods, class not initialized + constructor.equals(constructor); + constructor.getAnnotation(A.class); + constructor.getDeclaredAnnotations(); + constructor.getDeclaringClass(); + constructor.getExceptionTypes(); + constructor.getGenericExceptionTypes(); + constructor.getGenericParameterTypes(); + constructor.getModifiers(); + constructor.getName(); + constructor.getParameterAnnotations(); + constructor.getParameterCount(); + constructor.getParameterTypes(); + constructor.hashCode(); + constructor.isSynthetic(); + constructor.isVarArgs(); + constructor.toString(); + constructor.toGenericString(); + + //check point 2: after call newInstance(), class initialized + if (result.toString().compareTo("") == 0) { + constructor.newInstance("newInstance"); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitConstructorNewInstance.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitConstructorNewInstance.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitConstructorNewInstance.result.append("One"); + } + + String what = "lala"; + + One(){} + + public One(String s){ + what = s; + } +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitConstructorNewInstance.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitConstructorNewInstance.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0145-rt-compact-ClinitFieldGetBooleanStatic/ClassInitFieldGetBooleanStatic.java b/test/testsuite/ouroboros/compact_test/RT0145-rt-compact-ClinitFieldGetBooleanStatic/ClassInitFieldGetBooleanStatic.java new file mode 100755 index 0000000000..d725d9b397 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0145-rt-compact-ClinitFieldGetBooleanStatic/ClassInitFieldGetBooleanStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldGetBooleanStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetBooleanStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getBoolean(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.getBoolean(null), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetBooleanStatic.java + *- @ExecuteClass: ClassInitFieldGetBooleanStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldGetBooleanStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiBoolean"); + if (result.toString().compareTo("") == 0) { + f.getBoolean(null); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldGetBooleanStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldGetBooleanStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldGetBooleanStatic.result.append("One"); + } + + public static boolean hiBoolean = false; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldGetBooleanStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldGetBooleanStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0146-rt-compact-ClinitFieldGetByteStatic/ClassInitFieldGetByteStatic.java b/test/testsuite/ouroboros/compact_test/RT0146-rt-compact-ClinitFieldGetByteStatic/ClassInitFieldGetByteStatic.java new file mode 100755 index 0000000000..0c1e9f530a --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0146-rt-compact-ClinitFieldGetByteStatic/ClassInitFieldGetByteStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldGetByteStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetByteStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getByte(), class One is initialized + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.getByte(null), class One is initialized + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetByteStatic.java + *- @ExecuteClass: ClassInitFieldGetByteStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldGetByteStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiByte"); + if (result.toString().compareTo("") == 0) { + f.getByte(null); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldGetByteStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldGetByteStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldGetByteStatic.result.append("One"); + } + + public static byte hiByte = (byte)0; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldGetByteStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldGetByteStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0147-rt-compact-ClinitFieldGetCharStatic/ClassInitFieldGetCharStatic.java b/test/testsuite/ouroboros/compact_test/RT0147-rt-compact-ClinitFieldGetCharStatic/ClassInitFieldGetCharStatic.java new file mode 100755 index 0000000000..fd1b6522ed --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0147-rt-compact-ClinitFieldGetCharStatic/ClassInitFieldGetCharStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldGetCharStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetCharStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getChar(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.getChar(null), class One is initialized + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetCharStatic.java + *- @ExecuteClass: ClassInitFieldGetCharStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldGetCharStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiChar"); + if (result.toString().compareTo("") == 0) { + f.getChar(null); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldGetCharStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldGetCharStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldGetCharStatic.result.append("One"); + } + + public static char hiChar = (char)45; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldGetCharStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldGetCharStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0148-rt-compact-ClinitFieldGetDoubleStatic/ClassInitFieldGetDoubleStatic.java b/test/testsuite/ouroboros/compact_test/RT0148-rt-compact-ClinitFieldGetDoubleStatic/ClassInitFieldGetDoubleStatic.java new file mode 100755 index 0000000000..1de0037098 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0148-rt-compact-ClinitFieldGetDoubleStatic/ClassInitFieldGetDoubleStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldGetDoubleStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetDoubleStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getDouble(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.getDouble(null), class One is initialized + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetDoubleStatic.java + *- @ExecuteClass: ClassInitFieldGetDoubleStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldGetDoubleStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiDouble"); + if (result.toString().compareTo("") == 0) { + f.getDouble(null); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldGetDoubleStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldGetDoubleStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldGetDoubleStatic.result.append("One"); + } + + public static double hiDouble = 4.5; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldGetDoubleStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldGetDoubleStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0149-rt-compact-ClinitFieldGetFloatStatic/ClassInitFieldGetFloatStatic.java b/test/testsuite/ouroboros/compact_test/RT0149-rt-compact-ClinitFieldGetFloatStatic/ClassInitFieldGetFloatStatic.java new file mode 100755 index 0000000000..205f645d06 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0149-rt-compact-ClinitFieldGetFloatStatic/ClassInitFieldGetFloatStatic.java @@ -0,0 +1,77 @@ +/* + *- @TestCaseID: ClassInitFieldGetFloatStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetFloatStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getFloat(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.getFloat(null), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetFloatStatic.java + *- @ExecuteClass: ClassInitFieldGetFloatStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldGetFloatStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiFloat"); + if (result.toString().compareTo("") == 0) { + f.getFloat(null); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldGetFloatStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldGetFloatStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldGetFloatStatic.result.append("One"); + } + public static float hiFloat = 0.25f; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldGetFloatStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldGetFloatStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0150-rt-compact-ClinitFieldGetIntStatic/ClassInitFieldGetIntStatic.java b/test/testsuite/ouroboros/compact_test/RT0150-rt-compact-ClinitFieldGetIntStatic/ClassInitFieldGetIntStatic.java new file mode 100755 index 0000000000..b27b36faf9 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0150-rt-compact-ClinitFieldGetIntStatic/ClassInitFieldGetIntStatic.java @@ -0,0 +1,77 @@ +/* + *- @TestCaseID: ClassInitFieldGetIntStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetIntStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getInt(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.getInt(null), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetIntStatic.java + *- @ExecuteClass: ClassInitFieldGetIntStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldGetIntStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiInt"); + if (result.toString().compareTo("") == 0) { + f.getInt(null); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldGetIntStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldGetIntStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldGetIntStatic.result.append("One"); + } + public static int hiInt = 0; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldGetIntStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldGetIntStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0151-rt-compact-ClinitFieldGetLongStatic/ClassInitFieldGetLongStatic.java b/test/testsuite/ouroboros/compact_test/RT0151-rt-compact-ClinitFieldGetLongStatic/ClassInitFieldGetLongStatic.java new file mode 100755 index 0000000000..b29c8d3976 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0151-rt-compact-ClinitFieldGetLongStatic/ClassInitFieldGetLongStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldGetLongStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetLongStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getLong(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.getLong(null), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetLongStatic.java + *- @ExecuteClass: ClassInitFieldGetLongStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldGetLongStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiLong"); + if (result.toString().compareTo("") == 0) { + f.getLong(null); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldGetLongStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldGetLongStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldGetLongStatic.result.append("One"); + } + + public static long hiLong = 4859l; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldGetLongStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldGetLongStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0152-rt-compact-ClinitFieldGetShortStatic/ClassInitFieldGetShortStatic.java b/test/testsuite/ouroboros/compact_test/RT0152-rt-compact-ClinitFieldGetShortStatic/ClassInitFieldGetShortStatic.java new file mode 100755 index 0000000000..545c8d6cb9 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0152-rt-compact-ClinitFieldGetShortStatic/ClassInitFieldGetShortStatic.java @@ -0,0 +1,77 @@ +/* + *- @TestCaseID: ClassInitFieldGetShortStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetShortStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getShort(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class. + * -#step2: Call method f.getShort(null), class One is initialized + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetShortStatic.java + *- @ExecuteClass: ClassInitFieldGetShortStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldGetShortStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiShort"); + if (result.toString().compareTo("") == 0) { + f.getShort(null); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldGetShortStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldGetShortStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldGetShortStatic.result.append("One"); + } + + public static short hiShort = 48; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldGetShortStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldGetShortStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0153-rt-compact-ClinitFieldGetStatic/ClassInitFieldGetStatic.java b/test/testsuite/ouroboros/compact_test/RT0153-rt-compact-ClinitFieldGetStatic/ClassInitFieldGetStatic.java new file mode 100755 index 0000000000..de1f5ac8af --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0153-rt-compact-ClinitFieldGetStatic/ClassInitFieldGetStatic.java @@ -0,0 +1,81 @@ +/* + *- @TestCaseID: ClassInitFieldGetStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetStatic.java + *- @Title/Destination: When f is a static field of class One and call f.get(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class. + * -#step2: Call method f.get(null), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetStatic.java + *- @ExecuteClass: ClassInitFieldGetStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Field; + +public class ClassInitFieldGetStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + String fValue = ""; + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hi"); + if (result.toString().compareTo("") == 0) { + fValue = (String)f.get(null); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0 && fValue.compareTo("hi") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldGetStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldGetStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldGetStatic.result.append("One"); + } + + public static String hi = "hi"; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldGetStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldGetStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0154-rt-compact-ClinitFieldOtherMethod/ClassInitFieldOtherMethod.java b/test/testsuite/ouroboros/compact_test/RT0154-rt-compact-ClinitFieldOtherMethod/ClassInitFieldOtherMethod.java new file mode 100755 index 0000000000..cf93997494 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0154-rt-compact-ClinitFieldOtherMethod/ClassInitFieldOtherMethod.java @@ -0,0 +1,98 @@ +/* + *- @TestCaseID: ClassInitFieldOtherMethod + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldOtherMethod.java + *- @Title/Destination: When f is a static field of class One and call method except setXX/getXX, class is not + * initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class. + * -#step2: Call method of Field except setXX/getXX, class One is not initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldOtherMethod.java + *- @ExecuteClass: ClassInitFieldOtherMethod + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldOtherMethod { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hi"); + + f.equals(f); + f.getAnnotation(B.class); + f.getAnnotationsByType(B.class); + f.getDeclaredAnnotations(); + f.getDeclaringClass(); + f.getGenericType(); + f.getModifiers(); + f.getName(); + f.getType(); + f.hashCode(); + f.isEnumConstant(); + f.isSynthetic(); + f.toGenericString(); + f.toString(); + } catch (Exception e) { + System.out.println(e); + } + + if(result.toString().compareTo("") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldOtherMethod.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldOtherMethod.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldOtherMethod.result.append("One"); + } + + @B("hello") + public static String hi = "value"; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldOtherMethod.result.append("|InterfaceA|").toString(); +} + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@interface B{ + String value() default "hi"; +} + +class Two extends One { + static { + ClassInitFieldOtherMethod.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0155-rt-compact-ClinitFieldSetBooleanStatic/ClassInitFieldSetBooleanStatic.java b/test/testsuite/ouroboros/compact_test/RT0155-rt-compact-ClinitFieldSetBooleanStatic/ClassInitFieldSetBooleanStatic.java new file mode 100755 index 0000000000..8689833f94 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0155-rt-compact-ClinitFieldSetBooleanStatic/ClassInitFieldSetBooleanStatic.java @@ -0,0 +1,91 @@ +/* + *- @TestCaseID: ClassInitFieldSetBooleanStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetBooleanStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setBoolean(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.setBoolean(null, newValue), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetBooleanStatic.java + *- @ExecuteClass: ClassInitFieldSetBooleanStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldSetBooleanStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiBoolean"); + if (result.toString().compareTo("") == 0) { + f.setBoolean(null, false); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + + +@A +class Super { + static { + ClassInitFieldSetBooleanStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldSetBooleanStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldSetBooleanStatic.result.append("One"); + } + + String what = "lala"; + public static boolean hiBoolean = false; + One(){} + + public One(String s){ + what = s; + System.out.println(s); + } + + public int testOne(String a){ + System.out.println(a); + return 0; + } +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldSetBooleanStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldSetBooleanStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0156-rt-compact-ClinitFieldSetByteStatic/ClassInitFieldSetByteStatic.java b/test/testsuite/ouroboros/compact_test/RT0156-rt-compact-ClinitFieldSetByteStatic/ClassInitFieldSetByteStatic.java new file mode 100755 index 0000000000..937769cbd9 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0156-rt-compact-ClinitFieldSetByteStatic/ClassInitFieldSetByteStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldSetByteStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetByteStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setByte(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.setByte(null, newValue), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetByteStatic.java + *- @ExecuteClass: ClassInitFieldSetByteStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldSetByteStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiByte"); + if (result.toString().compareTo("") == 0) { + f.setByte(null, (byte)1); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldSetByteStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldSetByteStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldSetByteStatic.result.append("One"); + } + + public static byte hiByte = (byte)0; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldSetByteStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldSetByteStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0157-rt-compact-ClinitFieldSetCharStatic/ClassInitFieldSetCharStatic.java b/test/testsuite/ouroboros/compact_test/RT0157-rt-compact-ClinitFieldSetCharStatic/ClassInitFieldSetCharStatic.java new file mode 100755 index 0000000000..9393eeba2c --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0157-rt-compact-ClinitFieldSetCharStatic/ClassInitFieldSetCharStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldSetCharStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetCharStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setChar(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.setChar(null, newValue), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetCharStatic.java + *- @ExecuteClass: ClassInitFieldSetCharStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldSetCharStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiChar"); + if (result.toString().compareTo("") == 0) { + f.setChar(null, (char)1); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldSetCharStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldSetCharStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldSetCharStatic.result.append("One"); + } + + public static char hiChar = (char)45; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldSetCharStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldSetCharStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0158-rt-compact-ClinitFieldSetDoubleStatic/ClassInitFieldSetDoubleStatic.java b/test/testsuite/ouroboros/compact_test/RT0158-rt-compact-ClinitFieldSetDoubleStatic/ClassInitFieldSetDoubleStatic.java new file mode 100755 index 0000000000..b4a4bfb816 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0158-rt-compact-ClinitFieldSetDoubleStatic/ClassInitFieldSetDoubleStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldSetDoubleStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetDoubleStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setDouble(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.setDouble(null, newValue), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetDoubleStatic.java + *- @ExecuteClass: ClassInitFieldSetDoubleStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldSetDoubleStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiDouble"); + if (result.toString().compareTo("") == 0) { + f.setDouble(null, 0.2589); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldSetDoubleStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldSetDoubleStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldSetDoubleStatic.result.append("One"); + } + + public static double hiDouble = 4.5; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldSetDoubleStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldSetDoubleStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0159-rt-compact-ClinitFieldSetFloatStatic/ClassInitFieldSetFloatStatic.java b/test/testsuite/ouroboros/compact_test/RT0159-rt-compact-ClinitFieldSetFloatStatic/ClassInitFieldSetFloatStatic.java new file mode 100755 index 0000000000..6d27b8abb4 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0159-rt-compact-ClinitFieldSetFloatStatic/ClassInitFieldSetFloatStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldSetFloatStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetFloatStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setFloat(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.setFloat(null, newValue), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetFloatStatic.java + *- @ExecuteClass: ClassInitFieldSetFloatStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldSetFloatStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiFloat"); + if (result.toString().compareTo("") == 0) { + f.setFloat(null, 0.2589f); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldSetFloatStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldSetFloatStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldSetFloatStatic.result.append("One"); + } + + public static float hiFloat = 0.25f; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldSetFloatStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldSetFloatStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0160-rt-compact-ClinitFieldSetIntStatic/ClassInitFieldSetIntStatic.java b/test/testsuite/ouroboros/compact_test/RT0160-rt-compact-ClinitFieldSetIntStatic/ClassInitFieldSetIntStatic.java new file mode 100755 index 0000000000..8064ba36c6 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0160-rt-compact-ClinitFieldSetIntStatic/ClassInitFieldSetIntStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldSetIntStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetIntStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setInt(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.setInt(null, newValue), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetIntStatic.java + *- @ExecuteClass: ClassInitFieldSetIntStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldSetIntStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiInt"); + if (result.toString().compareTo("") == 0) { + f.setInt(null, 25); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldSetIntStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldSetIntStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldSetIntStatic.result.append("One"); + } + + public static int hiInt = 0; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldSetIntStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldSetIntStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0161-rt-compact-ClinitFieldSetLongStatic/ClassInitFieldSetLongStatic.java b/test/testsuite/ouroboros/compact_test/RT0161-rt-compact-ClinitFieldSetLongStatic/ClassInitFieldSetLongStatic.java new file mode 100755 index 0000000000..43be5a429b --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0161-rt-compact-ClinitFieldSetLongStatic/ClassInitFieldSetLongStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldSetLongStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetLongStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setLong(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.setLong(null, newValue), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetLongStatic.java + *- @ExecuteClass: ClassInitFieldSetLongStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldSetLongStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiLong"); + if (result.toString().compareTo("") == 0) { + f.setLong(null, 25l); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldSetLongStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldSetLongStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldSetLongStatic.result.append("One"); + } + + public static long hiLong = 4859l; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldSetLongStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldSetLongStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0162-rt-compact-ClinitFieldSetShortStatic/ClassInitFieldSetShortStatic.java b/test/testsuite/ouroboros/compact_test/RT0162-rt-compact-ClinitFieldSetShortStatic/ClassInitFieldSetShortStatic.java new file mode 100755 index 0000000000..97f9848460 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0162-rt-compact-ClinitFieldSetShortStatic/ClassInitFieldSetShortStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldSetShortStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetShortStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setShort(), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One. + * -#step2: Call method f.setShort(null, newValue), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetShortStatic.java + *- @ExecuteClass: ClassInitFieldSetShortStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldSetShortStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hiShort"); + if (result.toString().compareTo("") == 0) { + f.setShort(null, (short)25); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldSetShortStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldSetShortStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldSetShortStatic.result.append("One"); + } + + public static short hiShort = 48; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldSetShortStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldSetShortStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0163-rt-compact-ClinitFieldSetStatic/ClassInitFieldSetStatic.java b/test/testsuite/ouroboros/compact_test/RT0163-rt-compact-ClinitFieldSetStatic/ClassInitFieldSetStatic.java new file mode 100755 index 0000000000..fcce4284d8 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0163-rt-compact-ClinitFieldSetStatic/ClassInitFieldSetStatic.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: ClassInitFieldSetStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetStatic.java + *- @Title/Destination: When f is a static field of class One and call f.set(), class One is initialized + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getField to get a static field f of class + * One + * -#step2: Call method f.set(null, newValue), class One is initialized + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetStatic.java + *- @ExecuteClass: ClassInitFieldSetStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Field; + +public class ClassInitFieldSetStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Field f = clazz.getField("hi"); + if (result.toString().compareTo("") == 0) { + f.set(null, "what"); + } + } catch (Exception e) { + System.out.println(e); + } + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitFieldSetStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitFieldSetStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitFieldSetStatic.result.append("One"); + } + + public static String hi = "hi"; +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitFieldSetStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitFieldSetStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0164-rt-compact-ClinitMethodInvokeStatic/ClassInitMethodInvokeStatic.java b/test/testsuite/ouroboros/compact_test/RT0164-rt-compact-ClinitMethodInvokeStatic/ClassInitMethodInvokeStatic.java new file mode 100755 index 0000000000..eecb58c010 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0164-rt-compact-ClinitMethodInvokeStatic/ClassInitMethodInvokeStatic.java @@ -0,0 +1,108 @@ +/* + *- @TestCaseID: ClassInitMethodInvokeStatic + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitMethodInvokeStatic.java + *- @Title/Destination: When m is a static method of class One and call m.invoke(null, args), class One is initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("One" , false, One.class.getClassLoader()) and clazz.getDeclaredMethod to get a static method + * m of class One. + * -#step2: Call methods of Method except invoke(), class One is not initialized. + * -#step3: Call method invoke(), class One is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitMethodInvokeStatic.java + *- @ExecuteClass: ClassInitMethodInvokeStatic + *- @ExecuteArgs: + */ + +import java.lang.annotation.*; +import java.lang.reflect.Method; + +public class ClassInitMethodInvokeStatic { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("One", false, One.class.getClassLoader()); + Method m = clazz.getDeclaredMethod("testOne", String.class); + // Check point 1: calling following methods, class not initialized. + m.equals(m); + m.getAnnotation(A.class); + m.getDeclaredAnnotations(); + m.getDeclaringClass(); + m.getDefaultValue(); + m.getExceptionTypes(); + m.getGenericExceptionTypes(); + m.getGenericParameterTypes(); + m.getGenericReturnType(); + m.getModifiers(); + m.getName(); + m.getParameterAnnotations(); + m.getParameterCount(); + m.getParameterTypes(); + m.getReturnType(); + m.getTypeParameters(); + m.hashCode(); + m.isBridge(); + m.isDefault(); + m.isSynthetic(); + m.isVarArgs(); + m.toString(); + m.toGenericString(); + + // Check point 2: after newInstance, class initialized. + if (result.toString().compareTo("") == 0) { + m.invoke(null, "hi"); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("SuperOne") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +@A +class Super { + static { + ClassInitMethodInvokeStatic.result.append("Super"); + } +} + +interface InterfaceSuper { + String a = ClassInitMethodInvokeStatic.result.append("|InterfaceSuper|").toString(); +} + +@A(i=1) +class One extends Super implements InterfaceSuper { + static { + ClassInitMethodInvokeStatic.result.append("One"); + } + + public static int testOne(String a){ + return 0; + } +} + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@interface A { + int i() default 0; + String a = ClassInitMethodInvokeStatic.result.append("|InterfaceA|").toString(); +} + +class Two extends One { + static { + ClassInitMethodInvokeStatic.result.append("Two"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0165-rt-compact-ClinitFieldGetBooleanInterface/ClassInitFieldGetBooleanInterface.java b/test/testsuite/ouroboros/compact_test/RT0165-rt-compact-ClinitFieldGetBooleanInterface/ClassInitFieldGetBooleanInterface.java new file mode 100755 index 0000000000..14b4ba6147 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0165-rt-compact-ClinitFieldGetBooleanInterface/ClassInitFieldGetBooleanInterface.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ClassInitFieldGetBooleanInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetBooleanInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.getBoolean(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.getBoolean(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetBooleanInterface.java + *- @ExecuteClass: ClassInitFieldGetBooleanInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldGetBooleanInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiBoolean"); + if (result.toString().compareTo("") == 0) { + f.getBoolean(null); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("One") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldGetBooleanInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldGetBooleanInterface.result.append("One").toString(); + boolean hiBoolean = false; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldGetBooleanInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldGetBooleanInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0166-rt-compact-ClinitFieldGetByteInterface/ClassInitFieldGetByteInterface.java b/test/testsuite/ouroboros/compact_test/RT0166-rt-compact-ClinitFieldGetByteInterface/ClassInitFieldGetByteInterface.java new file mode 100755 index 0000000000..2f8b9ff396 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0166-rt-compact-ClinitFieldGetByteInterface/ClassInitFieldGetByteInterface.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ClassInitFieldGetByteInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetByteInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.getByte(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.getByte(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetByteInterface.java + *- @ExecuteClass: ClassInitFieldGetByteInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldGetByteInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiByte"); + if (result.toString().compareTo("") == 0) { + f.getByte(null); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("One") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldGetByteInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldGetByteInterface.result.append("One").toString(); + byte hiByte = (byte)1; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldGetByteInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldGetByteInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0167-rt-compact-ClinitFieldGetCharInterface/ClassInitFieldGetCharInterface.java b/test/testsuite/ouroboros/compact_test/RT0167-rt-compact-ClinitFieldGetCharInterface/ClassInitFieldGetCharInterface.java new file mode 100755 index 0000000000..9a2002e368 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0167-rt-compact-ClinitFieldGetCharInterface/ClassInitFieldGetCharInterface.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ClassInitFieldGetCharInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetCharInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.getChar(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.getChar(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetCharInterface.java + *- @ExecuteClass: ClassInitFieldGetCharInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldGetCharInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiChar"); + if (result.toString().compareTo("") == 0) { + f.getChar(null); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("One") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldGetCharInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldGetCharInterface.result.append("One").toString(); + char hiChar = (char)45; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldGetCharInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldGetCharInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0168-rt-compact-ClinitFieldGetDoubleInterface/ClassInitFieldGetDoubleInterface.java b/test/testsuite/ouroboros/compact_test/RT0168-rt-compact-ClinitFieldGetDoubleInterface/ClassInitFieldGetDoubleInterface.java new file mode 100755 index 0000000000..9446574085 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0168-rt-compact-ClinitFieldGetDoubleInterface/ClassInitFieldGetDoubleInterface.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ClassInitFieldGetDoubleInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetDoubleInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.getDouble(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.getDouble(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetDoubleInterface.java + *- @ExecuteClass: ClassInitFieldGetDoubleInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldGetDoubleInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiDouble"); + if (result.toString().compareTo("") == 0) { + f.getDouble(null); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("One") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldGetDoubleInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldGetDoubleInterface.result.append("One").toString(); + double hiDouble = 0.1532; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldGetDoubleInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldGetDoubleInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0169-rt-compact-ClinitFieldGetFloatInterface/ClassInitFieldGetFloatInterface.java b/test/testsuite/ouroboros/compact_test/RT0169-rt-compact-ClinitFieldGetFloatInterface/ClassInitFieldGetFloatInterface.java new file mode 100755 index 0000000000..a84927d150 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0169-rt-compact-ClinitFieldGetFloatInterface/ClassInitFieldGetFloatInterface.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ClassInitFieldGetFloatInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetFloatInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.getFloat(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.getFloat(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetFloatInterface.java + *- @ExecuteClass: ClassInitFieldGetFloatInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldGetFloatInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiFloat"); + if (result.toString().compareTo("") == 0) { + f.getFloat(null); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("One") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldGetFloatInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldGetFloatInterface.result.append("One").toString(); + float hiFloat = 0.25f; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldGetFloatInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldGetFloatInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0170-rt-compact-ClinitFieldGetInterface/ClassInitFieldGetInterface.java b/test/testsuite/ouroboros/compact_test/RT0170-rt-compact-ClinitFieldGetInterface/ClassInitFieldGetInterface.java new file mode 100755 index 0000000000..8fe272d19f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0170-rt-compact-ClinitFieldGetInterface/ClassInitFieldGetInterface.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ClassInitFieldGetInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.get(), OneInterface is initialized, it's + * parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.get(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetInterface.java + *- @ExecuteClass: ClassInitFieldGetInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldGetInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hi"); + if (result.toString().compareTo("") == 0) { + f.get(null); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("One") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldGetInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldGetInterface.result.append("One").toString(); + String hi = "hiField"; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldGetInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldGetInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0171-rt-compact-ClinitFieldGetIntInterface/ClassInitFieldGetIntInterface.java b/test/testsuite/ouroboros/compact_test/RT0171-rt-compact-ClinitFieldGetIntInterface/ClassInitFieldGetIntInterface.java new file mode 100755 index 0000000000..e085ca8fd5 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0171-rt-compact-ClinitFieldGetIntInterface/ClassInitFieldGetIntInterface.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ClassInitFieldGetIntInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetIntInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.getInt(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.getInt(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetIntInterface.java + *- @ExecuteClass: ClassInitFieldGetIntInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldGetIntInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiInt"); + if (result.toString().compareTo("") == 0) { + f.getInt(null); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("One") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldGetIntInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldGetIntInterface.result.append("One").toString(); + int hiInt = 125; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldGetIntInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldGetIntInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0172-rt-compact-ClinitFieldGetLongInterface/ClassInitFieldGetLongInterface.java b/test/testsuite/ouroboros/compact_test/RT0172-rt-compact-ClinitFieldGetLongInterface/ClassInitFieldGetLongInterface.java new file mode 100755 index 0000000000..abd590c158 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0172-rt-compact-ClinitFieldGetLongInterface/ClassInitFieldGetLongInterface.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ClassInitFieldGetLongInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetLongInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.getLong(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.getLong(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetLongInterface.java + *- @ExecuteClass: ClassInitFieldGetLongInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldGetLongInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiLong"); + if (result.toString().compareTo("") == 0) { + f.getLong(null); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("One") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldGetLongInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldGetLongInterface.result.append("One").toString(); + long hiLong = 4859l; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldGetLongInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldGetLongInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0173-rt-compact-ClinitFieldGetShortInterface/ClassInitFieldGetShortInterface.java b/test/testsuite/ouroboros/compact_test/RT0173-rt-compact-ClinitFieldGetShortInterface/ClassInitFieldGetShortInterface.java new file mode 100755 index 0000000000..0c4473af0d --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0173-rt-compact-ClinitFieldGetShortInterface/ClassInitFieldGetShortInterface.java @@ -0,0 +1,64 @@ +/* + *- @TestCaseID: ClassInitFieldGetShortInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldGetShortInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.getShort(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.getShort(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldGetShortInterface.java + *- @ExecuteClass: ClassInitFieldGetShortInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldGetShortInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiShort"); + if (result.toString().compareTo("") == 0) { + f.getShort(null); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("One") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldGetShortInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldGetShortInterface.result.append("One").toString(); + short hiShort = 14; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldGetShortInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldGetShortInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0174-rt-compact-ClinitFieldOtherMethodInterface/ClassInitFieldOtherMethodInterface.java b/test/testsuite/ouroboros/compact_test/RT0174-rt-compact-ClinitFieldOtherMethodInterface/ClassInitFieldOtherMethodInterface.java new file mode 100755 index 0000000000..7caa109c8e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0174-rt-compact-ClinitFieldOtherMethodInterface/ClassInitFieldOtherMethodInterface.java @@ -0,0 +1,76 @@ +/* + *- @TestCaseID: ClassInitFieldOtherMethodInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldOtherMethodInterface.java + *- @Title/Destination: When f is a field of of interface OneInterface and call method except setXX/getXX, class is not + * initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method of Field except setXX/getXX, class One is not initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldOtherMethodInterface.java + *- @ExecuteClass: ClassInitFieldOtherMethodInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldOtherMethodInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hi"); + + f.equals(f); + f.getAnnotation(A.class); + f.getAnnotationsByType(A.class); + f.getDeclaredAnnotations(); + f.getDeclaringClass(); + f.getGenericType(); + f.getModifiers(); + f.getName(); + f.getType(); + f.hashCode(); + f.isEnumConstant(); + f.isSynthetic(); + f.toGenericString(); + f.toString(); + } catch (Exception e) { + System.out.println(e); + } + + if(result.toString().compareTo("") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldOtherMethodInterface.result.append("Super").toString(); +} + +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldOtherMethodInterface.result.append("One").toString(); + @A + short hi = 14; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldOtherMethodInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldOtherMethodInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0175-rt-compact-ClinitFieldSetBooleanInterface/ClassInitFieldSetBooleanInterface.java b/test/testsuite/ouroboros/compact_test/RT0175-rt-compact-ClinitFieldSetBooleanInterface/ClassInitFieldSetBooleanInterface.java new file mode 100755 index 0000000000..33698ad977 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0175-rt-compact-ClinitFieldSetBooleanInterface/ClassInitFieldSetBooleanInterface.java @@ -0,0 +1,66 @@ +/* + *- @TestCaseID: ClassInitFieldSetBooleanInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetBooleanInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.setBoolean(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.setBoolean(null, true), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetBooleanInterface.java + *- @ExecuteClass: ClassInitFieldSetBooleanInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldSetBooleanInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiBoolean"); + if (result.toString().compareTo("") == 0) { + f.setBoolean(null, true); + } + }catch (IllegalAccessException e){ + result.append("IllegalAccessException"); + }catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("OneIllegalAccessException") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldSetBooleanInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldSetBooleanInterface.result.append("One").toString(); + boolean hiBoolean = false; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldSetBooleanInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldSetBooleanInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0176-rt-compact-ClinitFieldSetByteInterface/ClassInitFieldSetByteInterface.java b/test/testsuite/ouroboros/compact_test/RT0176-rt-compact-ClinitFieldSetByteInterface/ClassInitFieldSetByteInterface.java new file mode 100755 index 0000000000..bacc9d5764 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0176-rt-compact-ClinitFieldSetByteInterface/ClassInitFieldSetByteInterface.java @@ -0,0 +1,66 @@ +/* + *- @TestCaseID: ClassInitFieldSetByteInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetByteInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.setByte(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.setByte(null, (byte)0), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetByteInterface.java + *- @ExecuteClass: ClassInitFieldSetByteInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldSetByteInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiByte"); + if (result.toString().compareTo("") == 0) { + f.setByte(null, (byte)0); + } + }catch (IllegalAccessException e){ + result.append("IllegalAccessException"); + }catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("OneIllegalAccessException") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldSetByteInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldSetByteInterface.result.append("One").toString(); + byte hiByte = (byte)1; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldSetByteInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldSetByteInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0177-rt-compact-ClinitFieldSetFloatInterface/ClassInitFieldSetFloatInterface.java b/test/testsuite/ouroboros/compact_test/RT0177-rt-compact-ClinitFieldSetFloatInterface/ClassInitFieldSetFloatInterface.java new file mode 100755 index 0000000000..a111fba5a0 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0177-rt-compact-ClinitFieldSetFloatInterface/ClassInitFieldSetFloatInterface.java @@ -0,0 +1,66 @@ +/* + *- @TestCaseID: ClassInitFieldSetFloatInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetFloatInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.setFloat(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.setFloat(null, 0.654f), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetFloatInterface.java + *- @ExecuteClass: ClassInitFieldSetFloatInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldSetFloatInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiFloat"); + if (result.toString().compareTo("") == 0) { + f.setFloat(null, 0.654f); + } + }catch (IllegalAccessException e){ + result.append("IllegalAccessException"); + }catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("OneIllegalAccessException") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldSetFloatInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldSetFloatInterface.result.append("One").toString(); + float hiFloat = 0.25f; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldSetFloatInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldSetFloatInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0178-rt-compact-ClinitFieldSetInterface/ClassInitFieldSetInterface.java b/test/testsuite/ouroboros/compact_test/RT0178-rt-compact-ClinitFieldSetInterface/ClassInitFieldSetInterface.java new file mode 100755 index 0000000000..3b604e7456 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0178-rt-compact-ClinitFieldSetInterface/ClassInitFieldSetInterface.java @@ -0,0 +1,66 @@ +/* + *- @TestCaseID: ClassInitFieldSetInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.set(), OneInterface is initialized, it's + * parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.set(null, newValue), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetInterface.java + *- @ExecuteClass: ClassInitFieldSetInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldSetInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hi"); + if (result.toString().compareTo("") == 0) { + f.set(null, "newString"); + } + }catch (IllegalAccessException e){ + result.append("IllegalAccessException"); + }catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("OneIllegalAccessException") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldSetInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldSetInterface.result.append("One").toString(); + String hi = "hiField"; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldSetInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldSetInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0179-rt-compact-ClinitFieldSetIntInterface/ClassInitFieldSetIntInterface.java b/test/testsuite/ouroboros/compact_test/RT0179-rt-compact-ClinitFieldSetIntInterface/ClassInitFieldSetIntInterface.java new file mode 100755 index 0000000000..61ba9f1393 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0179-rt-compact-ClinitFieldSetIntInterface/ClassInitFieldSetIntInterface.java @@ -0,0 +1,66 @@ +/* + *- @TestCaseID: ClassInitFieldSetIntInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetIntInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.setInt(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.setInt(null, 98), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetIntInterface.java + *- @ExecuteClass: ClassInitFieldSetIntInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldSetIntInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiInt"); + if (result.toString().compareTo("") == 0) { + f.setInt(null, 98); + } + }catch (IllegalAccessException e){ + result.append("IllegalAccessException"); + }catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("OneIllegalAccessException") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldSetIntInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldSetIntInterface.result.append("One").toString(); + int hiInt = 125; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldSetIntInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldSetIntInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0180-rt-compact-ClinitFieldSetLongInterface/ClassInitFieldSetLongInterface.java b/test/testsuite/ouroboros/compact_test/RT0180-rt-compact-ClinitFieldSetLongInterface/ClassInitFieldSetLongInterface.java new file mode 100755 index 0000000000..e1f0652963 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0180-rt-compact-ClinitFieldSetLongInterface/ClassInitFieldSetLongInterface.java @@ -0,0 +1,66 @@ +/* + *- @TestCaseID: ClassInitFieldSetLongInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetLongInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.setLong(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.setLong(null, 7456l), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetLongInterface.java + *- @ExecuteClass: ClassInitFieldSetLongInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldSetLongInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiLong"); + if (result.toString().compareTo("") == 0) { + f.setLong(null, 7456l); + } + }catch (IllegalAccessException e){ + result.append("IllegalAccessException"); + }catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("OneIllegalAccessException") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldSetLongInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldSetLongInterface.result.append("One").toString(); + long hiLong = 4859l; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldSetLongInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldSetLongInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0181-rt-compact-ClinitFieldSetShortInterface/ClassInitFieldSetShortInterface.java b/test/testsuite/ouroboros/compact_test/RT0181-rt-compact-ClinitFieldSetShortInterface/ClassInitFieldSetShortInterface.java new file mode 100755 index 0000000000..2b1b456bb4 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0181-rt-compact-ClinitFieldSetShortInterface/ClassInitFieldSetShortInterface.java @@ -0,0 +1,66 @@ +/* + *- @TestCaseID: ClassInitFieldSetShortInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitFieldSetShortInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.setShort(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.setShort(null, 124), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitFieldSetShortInterface.java + *- @ExecuteClass: ClassInitFieldSetShortInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldSetShortInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Field f = clazz.getField("hiShort"); + if (result.toString().compareTo("") == 0) { + f.setShort(null, (short)124); + } + }catch (IllegalAccessException e){ + result.append("IllegalAccessException"); + }catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("OneIllegalAccessException") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitFieldSetShortInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface{ + String aOne = ClassInitFieldSetShortInterface.result.append("One").toString(); + short hiShort = 14; +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitFieldSetShortInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldSetShortInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0182-rt-compact-ClinitMethodInvokeInterface/ClassInitMethodInvokeInterface.java b/test/testsuite/ouroboros/compact_test/RT0182-rt-compact-ClinitMethodInvokeInterface/ClassInitMethodInvokeInterface.java new file mode 100755 index 0000000000..069cd30d3e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0182-rt-compact-ClinitMethodInvokeInterface/ClassInitMethodInvokeInterface.java @@ -0,0 +1,93 @@ +/* + *- @TestCaseID: ClassInitMethodInvokeInterface + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ClassInitMethodInvokeInterface.java + *- @Title/Destination: When m is a static method of interface OneInterface and call m.invoke(), OneInterface is + * initialized, it's parent interface is not initialized. + *- @Condition: no + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getDeclaredMethod to get + * a static method m of OneInterface. + * -#step2: Call methods of Method except invoke(), class One is not initialized. + * -#step3: Call method invoke(), class One is initialized + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ClassInitMethodInvokeInterface.java + *- @ExecuteClass: ClassInitMethodInvokeInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +public class ClassInitMethodInvokeInterface { + static StringBuffer result = new StringBuffer(""); + + public static void main(String[] args) { + try { + Class clazz = Class.forName("OneInterface", false, OneInterface.class.getClassLoader()); + Method m = clazz.getDeclaredMethod("runInterface", String.class); + //check point 1: calling following methods, class not initialized + m.equals(m); + m.getAnnotation(A.class); + m.getDeclaredAnnotations(); + m.getDeclaringClass(); + m.getDefaultValue(); + m.getExceptionTypes(); + m.getGenericExceptionTypes(); + m.getGenericParameterTypes(); + m.getGenericReturnType(); + m.getModifiers(); + m.getName(); + m.getParameterAnnotations(); + m.getParameterCount(); + m.getParameterTypes(); + m.getReturnType(); + m.getTypeParameters(); + m.hashCode(); + m.isBridge(); + m.isDefault(); + m.isSynthetic(); + m.isVarArgs(); + m.toString(); + m.toGenericString(); + + //check point 2: after newInstance, class initialized + if (result.toString().compareTo("") == 0) { + m.invoke(null, "hi"); + } + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("OneRunInterface") == 0) { + System.out.println(0); + } else { + System.out.println(2); + } + } +} + +interface SuperInterface{ + String aSuper = ClassInitMethodInvokeInterface.result.append("Super").toString(); +} + +interface OneInterface extends SuperInterface{ + String aOne = ClassInitMethodInvokeInterface.result.append("One").toString(); + @A + static void runInterface(String a){ + ClassInitMethodInvokeInterface.result.append("RunInterface"); + } +} + +interface TwoInterface extends OneInterface{ + String aTwo = ClassInitMethodInvokeInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitMethodInvokeInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0183-rt-compact-FieldMultiThreadTest/FieldMultiThreadTest.java b/test/testsuite/ouroboros/compact_test/RT0183-rt-compact-FieldMultiThreadTest/FieldMultiThreadTest.java new file mode 100755 index 0000000000..6600b48357 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0183-rt-compact-FieldMultiThreadTest/FieldMultiThreadTest.java @@ -0,0 +1,100 @@ +/* + *- @TestCaseID: FieldMultiThreadTest.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:FieldMultiThreadTest.java + *- @Title/Destination: when one thread changes the accessiblity of field by Field object A, the other thread will not know if it access the field by another Field object B + *- @Condition: no + *- @Brief:no: + * -#step1. TestMultiThread have fields with different access modifier(public/protected/default/private), thread A keep setAccessible(true) for Field object of these fields + * -#step2. thread B get new Field object for same field in TestMultiThread, and verify isAccessible() return false. + *- @Expect:0\n + *- @Priority: High + *- @Remark: + *- @Source: FieldMultiThreadTest.java + *- @ExecuteClass: FieldMultiThreadTest + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class FieldMultiThreadTest { + volatile static boolean keepRunning = true; + static int passCnt = 0; + static int executeCnt = 0; + + public static void main(String[] args) { + try { + fieldMultithread(); + System.out.println(passCnt/executeCnt - 10); + } catch (Exception e) { + System.out.println(e); + } + } + + private static int fieldMultithread() throws Exception { + Class clazz = Class.forName("TestMultiThread"); + String[] allFields = new String[] {"charPub", "fieldIntPri", "fieldIntPro", "fieldString"}; + Thread writer = new Thread(() -> { + try { + while (keepRunning) { + for (String s : allFields) { + Field field = clazz.getDeclaredField(s); + field.setAccessible(true); + } + for (Field f: clazz.getDeclaredFields()) { + f.setAccessible(true); + } + Field field = clazz.getField("charPub"); + field.setAccessible(true); + for (Field f: clazz.getFields()) { + f.setAccessible(true); + } + } + } catch (Exception e) { + System.out.println(e); + } + }); + + Thread reader = new Thread(() -> { + try { + while (keepRunning) { + for (String s : allFields) { + Field field = clazz.getDeclaredField(s); + passCnt += field.isAccessible()== false ? 1 : 0; + } + for (Field f: clazz.getDeclaredFields()) { + passCnt += f.isAccessible()== false ? 1 : 0; + } + Field field = clazz.getField("charPub"); + passCnt += field.isAccessible()== false ? 1 : 0; + for (Field f: clazz.getFields()) { + passCnt += f.isAccessible()== false ? 1 : 0; + } + executeCnt++; + } + } catch (Exception e) { + System.out.println(e); + } + }); + + writer.start(); + reader.start(); + Thread.sleep(100); + keepRunning = false; + Thread.sleep(100); + writer.join(); + reader.join(); + return passCnt; + } +} + +class TestMultiThread { + public char charPub = 'a'; + private int fieldIntPri = 416; + protected int[] fieldIntPro = {123}; + String fieldString = "hey, hello"; +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0184-rt-compact-MethodTest/MethodTest.java b/test/testsuite/ouroboros/compact_test/RT0184-rt-compact-MethodTest/MethodTest.java new file mode 100755 index 0000000000..80b845210f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0184-rt-compact-MethodTest/MethodTest.java @@ -0,0 +1,450 @@ +/* + *- @TestCaseID: MethodTest.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodTest.java + *- @Title/Destination: for the same method, different Method object is return when call following API twice: Class.getMethods(), Class.getEnclosingMethod(), Class.getDeclaredMethods(), Class.getMethod(String name, Class... parameterTypes), Class.getDeclaredMethod(String name, Class... parameterTypes). tests method with different return return type, parameter type, modifier, annotation and declaring class + *- @Condition: no + *- @Brief:no: see steps of separate test cases + *- @Expect:0\n + *- @Priority: High + *- @Remark: + *- @Source: MethodTest.java + *- @ExecuteClass: MethodTest + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +public class MethodTest { + /** + * Verify that for the same method, different Method object is return when call following API twice: + * - Class.getMethods(), + * - Class.getEnclosingMethod(), + * - Class.getDeclaredMethods(), + * - Class.getMethod(String name, Class... parameterTypes), + * - Class.getDeclaredMethod(String name, Class... parameterTypes), + * if any Method failed the check, will print error message including testcase and method name; + * after all check is pass, casePassed will be increased; + */ + private static void classAllMethodTest(Class clazz, String caseName) throws Exception { + // checkpoint 1. Class.getMethods() + Method[] methods1 = clazz.getMethods(); + Method[] methods2 = clazz.getMethods(); + checkMethods(methods1, methods2); + for (Method m : methods1) { + // checkpoint 2. Class.getMethod(String name) + Method m1 = clazz.getMethod(m.getName(), m.getParameterTypes()); + Method m2 = clazz.getMethod(m.getName(), m.getParameterTypes()); + if (singleMethodCheck(m1, m2) != 3) { + System.out.println(caseName + ": " + m1.toGenericString() + " failed"); + } + } + + // checkpoint 3. Class.getDeclaredMethods() + methods1 = clazz.getDeclaredMethods(); + methods2 = clazz.getDeclaredMethods(); + checkMethods(methods1, methods2); + for (Method m : methods1) { + // checkpoint 4. Class.getDeclaredMethod(String name) + Method m1 = clazz.getDeclaredMethod(m.getName(), m.getParameterTypes()); + Method m2 = clazz.getDeclaredMethod(m.getName(), m.getParameterTypes()); + if (singleMethodCheck(m1, m2) != 3) { + System.out.println(caseName + ": " + m1.toGenericString() + " failed for declared method"); + } + } + + // checkpoint 5. Class.getEnclosingMethod() + if (clazz.getEnclosingMethod() != null) { + Method m1 = clazz.getEnclosingMethod(); + Method m2 = clazz.getEnclosingMethod(); + if (singleMethodCheck(m1, m2) != 3) { + System.out.println(caseName + ": " + m1.toGenericString() + " failed for Enclosing method"); + } + } + + casesPassed++; + } + + private static void checkMethods(Method[] methods1, Method[] methods2) { + for (Method m1: methods1) { + for (Method m2: methods2) { + // only when modifers and class and name is same, two Method object is for same method + if(m1.toString().equals(m2.toString())) { + if (singleMethodCheck(m1, m2) != 3) { + System.out.println(m1.getName()+" failed in checkMethods"); + } + } + } + } + } + + private static int singleMethodCheck(Method m1, Method m2) { + int passCnt = 0; + passCnt += m1 == m2 ? 0 : 1; + passCnt += m1.equals(m2) ? 1 : 0; + passCnt += m1.hashCode() == m2.hashCode() ? 1 : 0; + return passCnt; + } + + static int casesPassed = 0; + + public static void main(String [] args) { + method01(); + method02(); + method03(); + method04(); + method05(); + method06(); + method07(); + method08(); + method09(); + method10(); + method11(); + System.out.println(casesPassed - 11); + } + + /** + *- @TestCaseID: method01 + *- @Title/Destination: for same method in pre-defined class, certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. all test in classAllMethodTest() passed for pre-defined class java.lang.Thread + */ + private static void method01() { + try { + classAllMethodTest(Class.forName("java.lang.Thread"), "method01"); + } catch (Exception e) { + System.out.println("Case method01 failed with exception" + e); + } + } + + /** + *- @TestCaseID: method02 + *- @Title/Destination: for same method in user-defined class with different return_type/parameter_type/modifier/annotation, certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. classAllMethodTest() passed for methods with different return type and parameter type + * -#step2. classAllMethodTest() passed for methods with different access modifier: public, private, protected + * -#step3. classAllMethodTest() passed for methods with different modifier: transient, final, volatile, static + * -#step4. classAllMethodTest() passed for methods with annotation + */ + private static void method02() { + try { + classAllMethodTest(Class.forName("TestMethod02"), "method02"); + } catch (Exception e) { + System.out.println("Case method02 failed with exception" + e); + } + } + + /** + *- @TestCaseID: method03 + *- @Title/Destination: check all test in classAllMethodTest passed for methods in interface + *- @Condition: no + *- @Brief:no: + * -step1. check all test in classAllMethodTest passed for methods in interface + */ + private static void method03() { + try { + classAllMethodTest(Class.forName("TestMethod03"), "method03"); + } catch (Exception e) { + System.out.println("Case method03 failed with exception" + e); + } + } + + /** + *- @TestCaseID: method04 + *- @Title/Destination: for same method in abstract class, certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllMethodTest passed for methods in abstract class + */ + private static void method04() { + try { + classAllMethodTest(Class.forName("TestMethod04"), "method04"); + } catch (Exception e) { + System.out.println("Case method04 failed with exception" + e); + } + } + + /** + *- @TestCaseID: method05 + *- @Title/Destination: for same method in anonymous class, certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. get the class instance of anonymous class + * -#step2. check all test in classAllMethodTest passed for methods in anonymous class + */ + private static void method05() { + try { + // step 1 + Class clazz = Class.forName("MethodTest"); + MethodTest mainClass = new MethodTest(); + Field method = clazz.getDeclaredField("testMethod05"); + + classAllMethodTest(method.get(mainClass).getClass(), "method05"); + } catch (Exception e) { + System.out.println("Case method05 failed with exception" + e); + } + } + + private Runnable testMethod05 = new Runnable() { + private final synchronized int intRunnable() { + return 1; + } + + @Override + public void run() { + for (int i = 0; i < 10; i++) { + } + } + }; + + /** + *- @TestCaseID: method06 + *- @Title/Destination: for same method in local class(class in a function), certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllMethodTest passed for methods in local class + */ + private static void method06() { + class TestMethod06 { + private final int intLocalMethod() { + return 9; + } + public synchronized String stringLocal() { + return "a fake behind the fear"; + } + } + try { + classAllMethodTest(Class.forName("MethodTest$1TestMethod06"), "method06"); + } catch (Exception e) { + System.out.println("Case method06 failed with exception" + e); + } + } + + /** + *- @TestCaseID: method07 + *- @Title/Destination: for same method in inner class, certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllMethodTest passed for methods in inner class + */ + private static void method07() { + try { + classAllMethodTest(Class.forName("MethodTest$TestMethod07"), "method07"); + } catch (Exception e) { + System.out.println("Case method07 failed with exception" + e); + } + } + + class TestMethod07 { + private char charInnerMethod(int a, double... b) { + return 'l'; + } + final public double doubleInnerMethod() { + return 1988.0416; + } + } + + /** + *- @TestCaseID: method08 + *- @Title/Destination: for same method in enum class, certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllMethodTest passed for methods in enum class + */ + private static void method08() { + try { + classAllMethodTest(Class.forName("TestMethod08"), "method08"); + } catch (Exception e) { + System.out.println("Case method08 failed with exception" + e); + } + } + + /** + *- @TestCaseID: method09 + *- @Title/Destination: for same method in parent class, certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllMethodTest passed for methods in parent class + */ + private static void method09() { + try { + classAllMethodTest(Class.forName("TestMethod09"), "method09"); + } catch (Exception e) { + System.out.println("Case method09 failed with exception" + e); + } + } + + /** + *- @TestCaseID: method10 + *- @Title/Destination: for same method in child class with implemented interface, certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllMethodTest passed for methods in child class with implemented interface + */ + private static void method10() { + try { + classAllMethodTest(Class.forName("TestMethod10"), "method10"); + } catch (Exception e) { + System.out.println("Case method10 failed with exception" + e); + } + } + + /** + *- @TestCaseID: method11 + *- @Title/Destination: for same method in interface implemented by another class, certain APIs return different Method object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllMethodTest passed for methods in interface implemented by another class + */ + private static void method11() { + try { + classAllMethodTest(Class.forName("TestMethod11"), "method11"); + } catch (Exception e) { + System.out.println("Case method11 failed with exception" + e); + } + } +} + +class TestMethod02 { + // step1 + void voidMethod() {} + boolean booleanMethod() { + return true; + } + byte byteMethod() { + return (byte)1; + } + short shortMethod() { + return (short)2; + } + int intMethod() { + return 3; + } + long longMethod() { + return 4l; + } + char charMethod() { + return 'a'; + } + float floatMethod() { + return 0.9f; + } + double doubleMethod() { + return 0.416; + } + String stringMethod() { + return "The queerest of the queer"; + } + Runnable[] rArrayMethod() { + return null; + } + boolean[][][][][][][] booleanArray7Method() { + return new boolean[][][][][][][] {{{{{{{true, false}}}}}}}; + } + String[][][] stringArray3Method() { + return new String[][][] {{{"the strangest of the strange"}}}; + } + + int parameterMethod(boolean a, byte b, short c, int d, long e, char f, float g, double h, + boolean[] aa, byte[] bb, short[] cc, int[] dd, long[] ee, char[] ff, float[] gg, double[] hh, + String i, String[][][] iii, Runnable j, Byte k, Double l, Thread.State m, int... o) { + return 1; + } + + // step2 + public int publicIntMethod(boolean a) { + return 88; + } + protected double protectedDoubleMethod(byte a) { + return 99; + } + private String privateStringMethod(String a) { + return "the coldest of the cool"; + } + + // step3 + strictfp double[][] transientDoubleArrayMethod(float[][] a) { + return new double[][] {{1988, 4.16}}; + } + final int finalIntMethod() { + return 9876; + } + synchronized String volatileStringMethod() { + return "the lamest of the lame"; + } + static Character staticCharacterMethod(Thread.State a) { + return 'd'; + } + + //step 4 + @Deprecated + String[][] stringsAnnotationMethod() { + return new String[][] {{"the numbest of the dumb"}}; + } +} + +interface TestMethod03 { + String stringInterfaceMethod(int[] a); + char[][][] charArrayInterfaceMethod(double... a); +} + +abstract class TestMethod04 { + public static final synchronized String[] stringsAbstractArrayMethod() { + return new String[] {"i hate to see you here", "you choke behind a smile"}; + } + abstract Runnable runnableAbstractMethod(); +} + +enum TestMethod08 { + WHISKY, VODKA, BRANDY, GIN, RUM, TEQUILA; + private static short shortEnumMethod() { + return (short)6; + } + public final String stringEnumMethod(int... a) { + return "Dry Martini"; + } +} + +class TestMethod09 { + public int int09Method() { + return 1; + } + protected boolean boolean09Method() { + return false; + } + char[] chars09Method() { + return new char[] {'a', 'b', 'c'}; + } + private String string09Method() { + return "I'm only happy when it rains"; + } +} + +class TestMethod10 extends TestMethod09 implements TestMethod11 { + public boolean boolean09Method() { + return true; + } + public double double10Method() { + return 0.416; + } + public char[] chars09Method() { + return new char[] {'a'}; + } + public String string09Method() { + return "SHALALALA"; + } +} + +interface TestMethod11 { + int int09Method(); + boolean boolean09Method(); + char[] chars09Method(); + String string09Method(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0185-rt-compact-MethodMultiThreadTest/MethodMultiThreadTest.java b/test/testsuite/ouroboros/compact_test/RT0185-rt-compact-MethodMultiThreadTest/MethodMultiThreadTest.java new file mode 100755 index 0000000000..847cea630e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0185-rt-compact-MethodMultiThreadTest/MethodMultiThreadTest.java @@ -0,0 +1,105 @@ +/* + *- @TestCaseID: MethodMultiThreadTest.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodMultiThreadTest.java + *- @Title/Destination: when one thread changes the accessiblity of method by Method object A, the other thread will not know if it access the method by another Method object B + *- @Condition: no + *- @Brief:no: + * -#step1. MethodMultiThreadTest have methods with different access modifier(public/protected/default/private), thread A keep setAccessible(true) for Method object of these methods + * -#step2. thread B get new Method object for same method in MethodMultiThreadTest, and verify isAccessible() return false. + *- @Expect:0\n + *- @Priority: High + *- @Remark: + *- @Source: MethodMultiThreadTest.java + *- @ExecuteClass: MethodMultiThreadTest + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +public class MethodMultiThreadTest { + volatile static boolean keepRunning = true; + static int passCnt = 0; + static int executeCnt = 0; + + public static void main(String[] args) { + try { + methodMultithread(); + System.out.println(passCnt/executeCnt - 28); + } catch (Exception e) { + System.out.println(e); + } + } + + private static int methodMultithread() throws Exception { + Class clazz = Class.forName("TestMultiThreadM"); + Thread writer = new Thread(() -> { + try { + while (keepRunning) { + for (Method m: clazz.getDeclaredMethods()) { + m.setAccessible(true); + Method method = clazz.getDeclaredMethod(m.getName(), m.getParameterTypes()); + method.setAccessible(true); + } + for (Method m: clazz.getMethods()) { + m.setAccessible(true); + Method method = clazz.getMethod(m.getName(), m.getParameterTypes()); + method.setAccessible(true); + } + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println(e); + } + }); + + Thread reader = new Thread(() -> { + try { + while (keepRunning) { + for (Method m: clazz.getDeclaredMethods()) { + passCnt += m.isAccessible()== false ? 1 : 0; + Method method = clazz.getDeclaredMethod(m.getName(), m.getParameterTypes()); + passCnt += method.isAccessible()== false ? 1 : 0; + } + for (Method m: clazz.getMethods()) { + passCnt += m.isAccessible()== false ? 1 : 0; + Method method = clazz.getMethod(m.getName(), m.getParameterTypes()); + passCnt += method.isAccessible()== false ? 1 : 0; + } + executeCnt++; + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println(e); + } + }); + + writer.start(); + reader.start(); + Thread.sleep(100); + keepRunning = false; + Thread.sleep(100); + writer.join(); + reader.join(); + return passCnt; + } +} + +class TestMultiThreadM { + public char charPubMethod(int... a) { + return 'a'; + } + private int intPriMethod() { + return 416; + } + protected int[] intProMethod(Double... b) { + return new int[] {123}; + } + String stringMethod() { + return "hey, hello"; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0186-rt-compact-ConstructorTest/ConstructorTest.java b/test/testsuite/ouroboros/compact_test/RT0186-rt-compact-ConstructorTest/ConstructorTest.java new file mode 100755 index 0000000000..498c10e0da --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0186-rt-compact-ConstructorTest/ConstructorTest.java @@ -0,0 +1,376 @@ +/* + *- @TestCaseID: ConstructorTest.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ConstructorTest.java + *- @Title/Destination: for the same constructor, different Constructor object is return when call following API twice: Class.getConstructors(), Class.getEnclosingConstructor(), Class.getDeclaredConstructors(), Class.getConstructor(String name, Class... parameterTypes), Class.getDeclaredConstructor(String name, Class... parameterTypes) + *- @Condition: no + *- @Brief:no: see steps of separate test cases + *- @Expect:0\n + *- @Priority: High + *- @Remark: + *- @Source: ConstructorTest.java + *- @ExecuteClass: ConstructorTest + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; +import java.lang.reflect.Constructor; + +public class ConstructorTest { + /** + * Verify that for the same constructor, different Constructor object is return when call following API twice: + * - Class.getConstructors(), + * - Class.getEnclosingConstructor(), + * - Class.getDeclaredConstructors(), + * - Class.getConstructor(String name, Class... parameterTypes), + * - Class.getDeclaredConstructor(String name, Class... parameterTypes), + * if any Constructor failed the check, will print error message including testcase and constructor name; + * after all check is pass, casePassed will be increased; + */ + private static void classAllConstructorTest(Class clazz, String caseName) throws Exception { + // checkpoint 1. Class.getConstructors() + Constructor[] constructors1 = clazz.getConstructors(); + Constructor[] constructors2 = clazz.getConstructors(); + checkConstructors(constructors1, constructors2); + for (Constructor c : constructors1) { + // checkpoint 2. Class.getConstructor(String name) + Constructor c1 = clazz.getConstructor(c.getParameterTypes()); + Constructor c2 = clazz.getConstructor(c.getParameterTypes()); + if (singleConstructorCheck(c1, c2) != 3) { + System.out.println(caseName + ": " + c1.toGenericString() + " failed"); + } + } + + // checkpoint 3. Class.getDeclaredConstructors() + constructors1 = clazz.getDeclaredConstructors(); + constructors2 = clazz.getDeclaredConstructors(); + checkConstructors(constructors1, constructors2); + for (Constructor c : constructors1) { + // checkpoint 4. Class.getDeclaredConstructor(String name) + Constructor c1 = clazz.getDeclaredConstructor(c.getParameterTypes()); + Constructor c2 = clazz.getDeclaredConstructor(c.getParameterTypes()); + if (singleConstructorCheck(c1, c2) != 3) { + System.out.println(caseName + ": " + c1.toGenericString() + " failed for declared constructor"); + } + } + + // checkpoint 5. Class.getEnclosingConstructor() + if (clazz.getEnclosingConstructor() != null) { + Constructor c1 = clazz.getEnclosingConstructor(); + Constructor c2 = clazz.getEnclosingConstructor(); + if (singleConstructorCheck(c1, c2) != 3) { + System.out.println(caseName + ": " + c1.toGenericString() + " failed for Enclosing constructor"); + } + } + + casesPassed++; + } + + private static void checkConstructors(Constructor[] constructors1, Constructor[] constructors2) { + for (Constructor c1: constructors1) { + for (Constructor c2: constructors2) { + // only when modifers and class and name is same, two Constructor object is for same constructor + if(c1.toString().equals(c2.toString())) { + if (singleConstructorCheck(c1, c2) != 3) { + System.out.println(c1.getName()+" failed in checkConstructors"); + } + } + } + } + } + + private static int singleConstructorCheck(Constructor c1, Constructor c2) { + int passCnt = 0; + passCnt += c1 == c2 ? 0 : 1; + passCnt += c1.equals(c2) ? 1 : 0; + passCnt += c1.hashCode() == c2.hashCode() ? 1 : 0; + return passCnt; + } + + static int casesPassed = 0; + + public static void main(String [] args) { + constructor01(); + constructor02(); + constructor03(); + constructor04(); + constructor05(); + constructor06(); + constructor07(); + constructor08(); + constructor09(); + constructor10(); + constructor11(); + System.out.println(casesPassed - 11); + } + + /** + *- @TestCaseID: constructor01 + *- @Title/Destination: for same constructor in pre-defined class, certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. all test in classAllConstructorTest() passed for pre-defined class java.lang.Thread + */ + private static void constructor01() { + try { + classAllConstructorTest(Class.forName("java.lang.Thread"), "constructor01"); + } catch (Exception e) { + System.out.println("Case constructor01 failed with exception" + e); + } + } + + /** + *- @TestCaseID: constructor02 + *- @Title/Destination: for same constructor in user-defined class with different parameter_type/modifier/annotation, certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. classAllConstructorTest() passed for constructors with different parameter type + * -#step2. classAllConstructorTest() passed for constructors with different access modifier: public, private, protected + * -#step3. classAllConstructorTest() passed for constructors with annotation + */ + private static void constructor02() { + try { + classAllConstructorTest(Class.forName("TestConstructor02"), "constructor02"); + } catch (Exception e) { + System.out.println("Case constructor02 failed with exception" + e); + } + } + + /** + *- @TestCaseID: constructor03 + *- @Title/Destination: check all test in classAllConstructorTest passed for constructors in class with modifier strictfp + *- @Condition: no + *- @Brief:no: + * -step1. check all test in classAllConstructorTest passed for constructors in class with modifier strictfp + */ + private static void constructor03() { + try { + classAllConstructorTest(Class.forName("TestConstructor03"), "constructor03"); + } catch (Exception e) { + System.out.println("Case constructor03 failed with exception" + e); + } + } + + /** + *- @TestCaseID: constructor04 + *- @Title/Destination: for same constructor in abstract class, certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllConstructorTest passed for constructors in abstract class + */ + private static void constructor04() { + try { + classAllConstructorTest(Class.forName("TestConstructor04"), "constructor04"); + } catch (Exception e) { + System.out.println("Case constructor04 failed with exception" + e); + } + } + + /** + *- @TestCaseID: constructor05 + *- @Title/Destination: for same constructor in anonymous class, certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. get the class instance of anonymous class by getting constructor value of otter class instance + * -#step2. check all test in classAllConstructorTest passed for constructors in anonymous class + */ + private static void constructor05() { + try { + Class clazz = Class.forName("ConstructorTest"); + ConstructorTest mainClass = new ConstructorTest(); + Field constructor = clazz.getDeclaredField("testConstructor05"); + + classAllConstructorTest(constructor.get(mainClass).getClass(), "constructor05"); + } catch (Exception e) { + System.out.println("Case constructor05 failed with exception" + e); + } + } + + private Runnable testConstructor05 = new Runnable() { + @Override + public void run() { + for (int i = 0; i < 10; i++) { + } + } + }; + + /** + *- @TestCaseID: constructor06 + *- @Title/Destination: for same constructor in local class(class in a function), certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllConstructorTest passed for constructors in local class + */ + private static void constructor06() { + class TestConstructor06 { + private TestConstructor06(int a) { + } + public TestConstructor06(String[][][] a) { + } + } + try { + classAllConstructorTest(Class.forName("ConstructorTest$1TestConstructor06"), "constructor06"); + } catch (Exception e) { + System.out.println("Case constructor06 failed with exception" + e); + } + } + + /** + *- @TestCaseID: constructor07 + *- @Title/Destination: for same constructor in inner class, certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllConstructorTest passed for constructors in inner class + */ + private static void constructor07() { + try { + classAllConstructorTest(Class.forName("ConstructorTest$TestConstructor07"), "constructor07"); + } catch (Exception e) { + System.out.println("Case constructor07 failed with exception" + e); + } + } + + class TestConstructor07 { + private TestConstructor07(int a, double... b) { + } + public TestConstructor07() { + } + } + + /** + *- @TestCaseID: constructor08 + *- @Title/Destination: for same constructor in user-defined class, certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllConstructorTest passed for constructors in + */ + private static void constructor08() { + try { + classAllConstructorTest(Class.forName("TestConstructor08"), "constructor08"); + } catch (Exception e) { + System.out.println("Case constructor08 failed with exception" + e); + } + } + + /** + *- @TestCaseID: constructor09 + *- @Title/Destination: for same constructor in father class, certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllConstructorTest passed for constructors in father class + */ + private static void constructor09() { + try { + classAllConstructorTest(Class.forName("TestConstructor09"), "constructor09"); + } catch (Exception e) { + System.out.println("Case constructor09 failed with exception" + e); + } + } + + /** + *- @TestCaseID: constructor10 + *- @Title/Destination: for same constructor in class extends another class and implements interface, certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllConstructorTest passed for constructors in class extends another class and implements interface + */ + private static void constructor10() { + try { + classAllConstructorTest(Class.forName("TestConstructor10"), "constructor10"); + } catch (Exception e) { + System.out.println("Case constructor10 failed with exception" + e); + } + } + + /** + *- @TestCaseID: constructor11 + *- @Title/Destination: for same constructor in interface implemented by another class, certain APIs return different Constructor object when called twice + *- @Condition: no + *- @Brief:no: + * -#step1. check all test in classAllConstructorTest passed for constructors in interface implemented by another class + */ + private static void constructor11() { + try { + Class clazz = (new TestConstructor11()).c.getClass(); + classAllConstructorTest(clazz, "constructor11"); + } catch (Exception e) { + System.out.println("Case constructor11 failed with exception" + e); + } + } +} + +class TestConstructor02 { + // step1 + TestConstructor02() { + } + TestConstructor02(boolean a, byte b, short c, int d, long e, char f, float g, double h, + boolean[] aa, byte[] bb, short[] cc, int[] dd, long[] ee, char[] ff, float[] gg, double[] hh, + String i, String[][][] iii, Runnable j, Byte k, Double l, Thread.State m, int... o) { + } + + // step2 + public TestConstructor02(int a) {} + TestConstructor02(byte a) {} + protected TestConstructor02(String a) {} + private TestConstructor02(Runnable[] a) {} + + // step3 + @Deprecated + TestConstructor02(int... a) {} +} + +strictfp class TestConstructor03 { + public TestConstructor03(float... a) { + } + TestConstructor03(float a, double b) { + } +} + +abstract class TestConstructor04 { + public TestConstructor04() { + } + TestConstructor04(int a) { + } +} + +enum TestConstructor08 { + WHISKY, VODKA, BRANDY, GIN, RUM, TEQUILA; + TestConstructor08() { + } + TestConstructor08(String a) { + } +} + +class TestConstructor09 { + public TestConstructor09() { + } + TestConstructor09(int... a) { + } + protected TestConstructor09(double[] a) { + } + private TestConstructor09(int a) { + } +} + +class TestConstructor10 extends TestConstructor09 { + public TestConstructor10() { + } + TestConstructor10(int... a) { + } + protected TestConstructor10(double[] a) { + } + private TestConstructor10(int a) { + } +} + +class TestConstructor11 { + public Object c; + public TestConstructor11( ) { + class ClassA { } + c = new ClassA( ); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0187-rt-compact-ConstructorMultiThreadTest/ConstructorMultiThreadTest.java b/test/testsuite/ouroboros/compact_test/RT0187-rt-compact-ConstructorMultiThreadTest/ConstructorMultiThreadTest.java new file mode 100755 index 0000000000..7e2c78b8a6 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0187-rt-compact-ConstructorMultiThreadTest/ConstructorMultiThreadTest.java @@ -0,0 +1,104 @@ +/* + *- @TestCaseID: ConstructorMultiThreadTest.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ConstructorMultiThreadTest.java + *- @Title/Destination: when one thread changes the accessiblity of constructor by Constructor object A, the other thread will not know if it access the constructor by another Constructor object B + *- @Condition: no + *- @Brief:no: + * -#step1. ConstructorMultiThreadTest have constructors with different access modifier(public/protected/default/private), thread A keep setAccessible(true) for Constructor object of these constructors + * -#step2. thread B get new Constructor object for same constructor in ConstructorMultiThreadTest, and verify isAccessible() return false. + *- @Expect:0\n + *- @Priority: High + *- @Remark: + *- @Source: ConstructorMultiThreadTest.java + *- @ExecuteClass: ConstructorMultiThreadTest + *- @ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +public class ConstructorMultiThreadTest { + volatile static boolean keepRunning = true; + static int passCnt = 0; + static int executeCnt = 0; + + public static void main(String[] args) { + try { + constructorMultithread(); + System.out.println(passCnt/executeCnt - 10); + } catch (Exception e) { + System.out.println(e); + } + } + + private static int constructorMultithread() throws Exception { + Class clazz = Class.forName("TestMultiThreadC"); + Thread writer = new Thread(() -> { + try { + while (keepRunning) { + for (Constructor c: clazz.getDeclaredConstructors()) { + c.setAccessible(true); + Constructor constructor = clazz.getDeclaredConstructor(c.getParameterTypes()); + constructor.setAccessible(true); + } + for (Constructor c: clazz.getConstructors()) { + c.setAccessible(true); + Constructor constructor = clazz.getConstructor(c.getParameterTypes()); + constructor.setAccessible(true); + } + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println(e); + } + }); + + Thread reader = new Thread(() -> { + try { + while (keepRunning) { + for (Constructor c: clazz.getDeclaredConstructors()) { + passCnt += c.isAccessible()== false ? 1 : 0; + Constructor constructor = clazz.getDeclaredConstructor(c.getParameterTypes()); + passCnt += constructor.isAccessible()== false ? 1 : 0; + } + for (Constructor c: clazz.getConstructors()) { + passCnt += c.isAccessible()== false ? 1 : 0; + Constructor constructor = clazz.getConstructor(c.getParameterTypes()); + passCnt += constructor.isAccessible()== false ? 1 : 0; + } + executeCnt++; + } + } catch (Exception e) { + e.printStackTrace(); + System.out.println(e); + } + }); + + writer.start(); + reader.start(); + Thread.sleep(100); + keepRunning = false; + Thread.sleep(100); + writer.join(); + reader.join(); + return passCnt; + } +} + +class TestMultiThreadC { + public TestMultiThreadC(int... a) { + } + + private TestMultiThreadC(String a) { + } + + protected TestMultiThreadC(Double... a) { + } + + TestMultiThreadC() { + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0188-rt-compact-MethodHandleReflectCombineTest/MethodHandleReflectCombineTest.java b/test/testsuite/ouroboros/compact_test/RT0188-rt-compact-MethodHandleReflectCombineTest/MethodHandleReflectCombineTest.java new file mode 100644 index 0000000000..a2ba98c2e7 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0188-rt-compact-MethodHandleReflectCombineTest/MethodHandleReflectCombineTest.java @@ -0,0 +1,104 @@ +/* + *- @TestCaseID: MethodHandleReflectCombineTest.java + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:MethodHandleReflectCombineTest.java + *- @Title/Destination: Test Field/Method/Constructor object return by MethodHandles.reflectAs(Class expected, MethodHandle target) is heap object + *- @Condition: no + *- @Brief:no: + * -#step1. testData including methodHandles for virtual method, static method, private method, constructor with primitive parameter and array parameter, field with primitive type, array type, static field; + * -#step2. for methodHandles in testData, call reflectAs(Member.class, methodhandle) twice, the Field/Constructor/Method returned is two object + * -#step3. for private constructor, try to setAccessible(true) for it first and then get method handle for it and check reflectAs return a new Constructor object + *- @Expect:0\n + *- @Priority: High + *- @Remark: + *- @Source: MethodHandleReflectCombineTest.java + *- @ExecuteClass: MethodHandleReflectCombineTest + *- @ExecuteArgs: + */ + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Member; + +import static java.lang.invoke.MethodHandles.lookup; +import static java.lang.invoke.MethodHandles.reflectAs; +import static java.lang.invoke.MethodType.methodType; + +public class MethodHandleReflectCombineTest { + static int passCnt = 0; + + private static int singleMethodCheck(T m1, T m2) { + int passCnt = 0; + passCnt += m1 == m2 ? 0 : 1; + passCnt += m1.equals(m2) ? 1 : 0; + passCnt += m1.hashCode() == m2.hashCode() ? 1 : 0; + return passCnt; + } + + public static void main(String[] args) { + try { + System.out.println(run()); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + private static int run() throws Throwable { + Object[][] testData = new Object[][] { + {Member.class, lookup().findVirtual(String.class, "concat", methodType(String.class, String.class))}, + {Member.class, lookup().findStatic(String.class, "copyValueOf", methodType(String.class, char[].class))}, + {Member.class, RATest.LOOKUP().findSpecial(RATest.class, "mhVar", methodType(int.class, Object[].class), RATest.class)}, + {Constructor.class, lookup().findConstructor(RATest.class, methodType(void.class, int.class))}, + {Constructor.class, lookup().findConstructor(RATest.class, methodType(void.class, double[].class))}, + {Field.class, lookup().findStaticGetter(RATest.class, "svi", int.class)}, + {Field.class, lookup().findStaticSetter(RATest.class, "svi", int.class)}, + {Field.class, RATest.LOOKUP().findGetter(RATest.class, "vd", double.class)}, + {Field.class, lookup().findGetter(RATest.class, "vs", String[].class)}, + {Field.class, lookup().findSetter(RATest.class, "vs", String[].class)} + }; + + for (int i = 0; i{ + private T obj; + + public void setObj(T obj) { + this.obj = obj; + } + public void say(){ + System.out.println("hello "+obj); + } +} + +interface PackageInfoInterface { + void test(); +} + +class PackageInfoConst { + public static final String MESSAGE="Annotation Study"; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnoA.java b/test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnoA.java new file mode 100755 index 0000000000..8c2ab1b397 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnoA.java @@ -0,0 +1,32 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE_PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoA { + int intA(); + byte byteA(); + char charA(); + double doubleA(); + boolean booleanA(); + long longA(); + float floatA(); + short shortA(); + int[] intAA(); + byte[] byteAA(); + char[] charAA(); + double[] doubleAA(); + boolean[] booleanAA(); + long[] longAA(); + float[] floatAA(); + short[] shortAA(); + String stringA(); + String[] stringAA(); + Class classA(); + Class[] classAA(); + Thread.State stateA(); + Thread.State[] stateAA(); + AnnoB annoBA(); + AnnoB[] annoBAA(); +} diff --git a/test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnoB.java b/test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnoB.java new file mode 100755 index 0000000000..70a77a033f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnoB.java @@ -0,0 +1,9 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoB { + int intB() default 999; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnotationTypeParameterSetTest.java b/test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnotationTypeParameterSetTest.java new file mode 100755 index 0000000000..c0b1d69b32 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0200-rt-compact-AnnotationTypeParameterSetTest/AnnotationTypeParameterSetTest.java @@ -0,0 +1,78 @@ +/* + *- @TestCaseID: Maple_Annotation_invoke_AnnotationSetTest + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:AnnotationTypeParameterSetTest.java + *- @TestCaseName: AnnotationTypeParameterSetTest + *- @TestCaseType: Function Testing + *- @RequirementID: AR000D0OR6 + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation with @Target(ElementType.TYPE_PARAMETER) + *- @Condition: no + *- @Brief:no: + * -#step1. User-defined Annotation with @Target(ElementType.TYPE_PARAMETER) has field with primitive type, String, ENUM, annotation, class and their array + * -#step2. verify able to set and get value + *- @Expect:0\n + *- @Priority: Level 1 + *- @Remark: + *- @Source: AnnotationTypeParameterSetTest.java AnnoA.java AnnoB.java + *- @ExecuteClass: AnnotationTypeParameterSetTest + *- @ExecuteArgs: + */ + +import java.util.Arrays; + +public class AnnotationTypeParameterSetTest { + static int[] passCnt; + public static void main(String[] args) { + + System.out.println(Test.class.getAnnotations().length); +// TypeVeriable.getAnnotation not supported in ART +/* AnnoA anno = Test.class.getTypeParameters()[0].getAnnotation(AnnoA.class); + passCnt = new int[24]; + // 基本数据类型 + int i = 0; + passCnt[i++] = anno.intA() == Integer.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.byteA() == Byte.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.charA() == Character.MAX_VALUE ? 1: 0; + passCnt[i++] += Double.isNaN(anno.doubleA()) ? 1: 0; + passCnt[i++] += anno.booleanA() ? 1: 0; + passCnt[i++] += anno.longA() == Long.MAX_VALUE ? 1: 0; + passCnt[i++] += Float.isNaN(anno.floatA())? 1: 0; + passCnt[i++] += anno.shortA() == Short.MAX_VALUE ? 1: 0; + + //enum, string, annotation, class + passCnt[i++] += anno.stateA() == Thread.State.BLOCKED ? 1: 0; + passCnt[i++] += anno.stringA().compareTo("") == 0 ? 1: 0; + passCnt[i++] += anno.classA() == Thread.class ? 1: 0; + passCnt[i++] += Arrays.toString(anno.intAA()).compareTo("[1, 2]") == 0 ? 1: 0; + + //基本类型数组 + passCnt[i++] += (anno.byteAA().length == 1 && anno.byteAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.charAA().length == 1 && anno.charAA()[0] == ' ') ? 1: 0; + passCnt[i++] += (anno.doubleAA().length == 3 && Double.isNaN(anno.doubleAA()[0]) && Double.isInfinite(anno.doubleAA()[1]) && Double.isInfinite(anno.doubleAA()[2]))? 1: 0; + passCnt[i++] += (anno.booleanAA().length == 1 && anno.booleanAA()[0]) ? 1: 0; + passCnt[i++] += (anno.longAA().length == 1 && anno.longAA()[0] == Long.MAX_VALUE) ? 1: 0; + passCnt[i++] += (anno.floatAA().length == 3 && Float.isNaN(anno.floatAA()[0]) && Float.isInfinite(anno.floatAA()[1]) && Float.isInfinite(anno.floatAA()[2])) ? 1: 0; + passCnt[i++] += (anno.shortAA().length == 1 && anno.shortAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.stringAA().length == 1 && anno.stringAA()[0].compareTo("")==0) ? 1: 0; + passCnt[i++] += (anno.classAA().length == 1 && anno.classAA()[0] == Thread.class)? 1: 0; + passCnt[i++] += (anno.stateAA().length == 1 && anno.stateAA()[0] == Thread.State.NEW) ? 1: 0; + passCnt[i++] += anno.annoBA().toString().compareTo("@AnnoB(intB=999)")==0 ? 1: 0; + passCnt[i++] += Arrays.toString(anno.annoBAA()).compareTo("[@AnnoB(intB=999), @AnnoB(intB=999)]") == 0 ? 1: 0; + System.out.println(Arrays.toString(passCnt).compareTo("[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]"));*/ + } +} + +class Test<@AnnoA(intA = Integer.MAX_VALUE, byteA = Byte.MAX_VALUE, charA = Character.MAX_VALUE, doubleA = Double.NaN, + booleanA = true, longA = Long.MAX_VALUE, floatA = Float.NaN, shortA = Short.MAX_VALUE, + intAA = {1,2}, byteAA = {0}, charAA = {' '}, doubleAA = {Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, + booleanAA = {true}, longAA = {Long.MAX_VALUE}, floatAA = {Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY}, shortAA = {0}, + stringA = "", stringAA = "", classA = Thread.class, classAA = Thread.class, stateA = Thread.State.BLOCKED, + stateAA = Thread.State.NEW, annoBA = @AnnoB, annoBAA = {@AnnoB, @AnnoB}) T> { + +} +// DEPENDENCE: AnnoA.java AnnoB.java +// EXEC:%maple %f AnnoA.java AnnoB.java %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnoA.java b/test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnoA.java new file mode 100755 index 0000000000..063bd56943 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnoA.java @@ -0,0 +1,32 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoA { + int intA(); + byte byteA(); + char charA(); + double doubleA(); + boolean booleanA(); + long longA(); + float floatA(); + short shortA(); + int[] intAA(); + byte[] byteAA(); + char[] charAA(); + double[] doubleAA(); + boolean[] booleanAA(); + long[] longAA(); + float[] floatAA(); + short[] shortAA(); + String stringA(); + String[] stringAA(); + Class classA(); + Class[] classAA(); + Thread.State stateA(); + Thread.State[] stateAA(); + AnnoB annoBA(); + AnnoB[] annoBAA(); +} diff --git a/test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnoB.java b/test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnoB.java new file mode 100755 index 0000000000..70a77a033f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnoB.java @@ -0,0 +1,9 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoB { + int intB() default 999; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnotationTypeUseSetTest.java b/test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnotationTypeUseSetTest.java new file mode 100755 index 0000000000..6c39fe980f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0201-rt-compact-AnnotationTypeUseSetTest/AnnotationTypeUseSetTest.java @@ -0,0 +1,76 @@ +/* + *- @TestCaseID: Maple_Annotation_invoke_AnnotationSetTest + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:AnnotationTypeUseSetTest.java + *- @TestCaseName: AnnotationTypeUseSetTest + *- @TestCaseType: Function Testing + *- @RequirementID: AR000D0OR6 + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation with @Target(ElementType.TYPE_USE) + *- @Condition: no + *- @Brief:no: + * -#step1. User-defined Annotation with @Target(ElementType.TYPE_USE) has field with primitive type, String, ENUM, annotation, class and their array + * -#step2. verify able to set and get value + *- @Expect:0\n + *- @Priority: Level 1 + *- @Remark: + *- @Source: AnnotationTypeUseSetTest.java AnnoA.java AnnoB.java + *- @ExecuteClass: AnnotationTypeUseSetTest + *- @ExecuteArgs: + */ + +import java.util.Arrays; + +public class AnnotationTypeUseSetTest { + static int[] passCnt; + public static void main(String[] args) { + System.out.println(Test.class.getAnnotations().length); +/* AnnoA anno = Test.class.getTypeParameters()[0].getAnnotation(AnnoA.class); + passCnt = new int[24]; + // 基本数据类型 + int i = 0; + passCnt[i++] = anno.intA() == Integer.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.byteA() == Byte.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.charA() == Character.MAX_VALUE ? 1: 0; + passCnt[i++] += Double.isNaN(anno.doubleA()) ? 1: 0; + passCnt[i++] += anno.booleanA() ? 1: 0; + passCnt[i++] += anno.longA() == Long.MAX_VALUE ? 1: 0; + passCnt[i++] += Float.isNaN(anno.floatA())? 1: 0; + passCnt[i++] += anno.shortA() == Short.MAX_VALUE ? 1: 0; + + //enum, string, annotation, class + passCnt[i++] += anno.stateA() == Thread.State.BLOCKED ? 1: 0; + passCnt[i++] += anno.stringA().compareTo("") == 0 ? 1: 0; + passCnt[i++] += anno.classA() == Thread.class ? 1: 0; + passCnt[i++] += Arrays.toString(anno.intAA()).compareTo("[1, 2]") == 0 ? 1: 0; + + //基本类型数组 + passCnt[i++] += (anno.byteAA().length == 1 && anno.byteAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.charAA().length == 1 && anno.charAA()[0] == ' ') ? 1: 0; + passCnt[i++] += (anno.doubleAA().length == 3 && Double.isNaN(anno.doubleAA()[0]) && Double.isInfinite(anno.doubleAA()[1]) && Double.isInfinite(anno.doubleAA()[2]))? 1: 0; + passCnt[i++] += (anno.booleanAA().length == 1 && anno.booleanAA()[0]) ? 1: 0; + passCnt[i++] += (anno.longAA().length == 1 && anno.longAA()[0] == Long.MAX_VALUE) ? 1: 0; + passCnt[i++] += (anno.floatAA().length == 3 && Float.isNaN(anno.floatAA()[0]) && Float.isInfinite(anno.floatAA()[1]) && Float.isInfinite(anno.floatAA()[2])) ? 1: 0; + passCnt[i++] += (anno.shortAA().length == 1 && anno.shortAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.stringAA().length == 1 && anno.stringAA()[0].compareTo("")==0) ? 1: 0; + passCnt[i++] += (anno.classAA().length == 1 && anno.classAA()[0] == Thread.class)? 1: 0; + passCnt[i++] += (anno.stateAA().length == 1 && anno.stateAA()[0] == Thread.State.NEW) ? 1: 0; + passCnt[i++] += anno.annoBA().toString().compareTo("@AnnoB(intB=999)")==0 ? 1: 0; + passCnt[i++] += Arrays.toString(anno.annoBAA()).compareTo("[@AnnoB(intB=999), @AnnoB(intB=999)]") == 0 ? 1: 0; + System.out.println(Arrays.toString(passCnt).compareTo("[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]"));*/ + } +} + +class Test<@AnnoA(intA = Integer.MAX_VALUE, byteA = Byte.MAX_VALUE, charA = Character.MAX_VALUE, doubleA = Double.NaN, + booleanA = true, longA = Long.MAX_VALUE, floatA = Float.NaN, shortA = Short.MAX_VALUE, + intAA = {1,2}, byteAA = {0}, charAA = {' '}, doubleAA = {Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, + booleanAA = {true}, longAA = {Long.MAX_VALUE}, floatAA = {Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY}, shortAA = {0}, + stringA = "", stringAA = "", classA = Thread.class, classAA = Thread.class, stateA = Thread.State.BLOCKED, + stateAA = Thread.State.NEW, annoBA = @AnnoB, annoBAA = {@AnnoB, @AnnoB}) T> { + +} +// DEPENDENCE: AnnoA.java AnnoB.java +// EXEC:%maple %f AnnoA.java AnnoB.java %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoA.java b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoA.java new file mode 100755 index 0000000000..c46a1ae181 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoA.java @@ -0,0 +1,17 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoA { + int intA() default Integer.MAX_VALUE; + + double doubleA() default Double.MIN_VALUE; + + String stringA() default ""; + + AnnoB annoBA(); + + ENUMA enumA() default ENUMA.A; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoB.java b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoB.java new file mode 100755 index 0000000000..70a77a033f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoB.java @@ -0,0 +1,9 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoB { + int intB() default 999; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoC.java b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoC.java new file mode 100755 index 0000000000..e86c63e3d1 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoC.java @@ -0,0 +1,17 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoC { + int[] intA() default Integer.MAX_VALUE; + + double[] doubleA() default Double.MIN_VALUE; + + String[] stringA() default ""; + + AnnoB[] annoBA() default @AnnoB; + + ENUMA[] enumA() default ENUMA.A; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoD.java b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoD.java new file mode 100755 index 0000000000..eb15087f77 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnoD.java @@ -0,0 +1,17 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoD { + int intA() default Integer.MAX_VALUE; + + double doubleA() default Double.MIN_VALUE; + + String stringA() default ""; + + AnnoB annoBA(); + + ENUMA enumA() default ENUMA.A; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnotationMultiThread.java b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnotationMultiThread.java new file mode 100755 index 0000000000..531fc94fdd --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/AnnotationMultiThread.java @@ -0,0 +1,185 @@ +/* + *- @TestCaseID: Maple_MethodHandle_invoke_AnnotationMultiThread + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:AnnotationMultiThread.java + *- @TestCaseName: AnnotationMultiThread + *- @TestCaseType: Function Testing + *- @RequirementID: AR000D0OR6 + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation, verify when multiple thread try to use annotations, working fine + *- @Condition: no + *- @Brief:no: + * -#step1. User-defined Annotation has field with primitive type, String, ENUM, annotation, class and their array + * -#step2. verify able to set and get value under multithread + *- @Expect:0\n + *- @Priority: Level 1 + *- @Remark: + *- @Source: AnnotationMultiThread.java AnnoA.java AnnoB.java AnnoC.java AnnoD.java ENUMA.java + *- @ExecuteClass: AnnotationMultiThread + *- @ExecuteArgs: + *- @Author:linxiaojun/l00473412 + */ + +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicInteger; + +public class AnnotationMultiThread { + static AtomicInteger passCnt = new AtomicInteger(); + public static void main(String[] args) throws ClassNotFoundException { + ThreadGroup threadGroup = new ThreadGroup("myGroup"); + + String[][] expectedGF = new String[][]{ + {"@AnnoA", "enumA=A", "intA=2147483647", "stringA=", "doubleA=4.9E-324", "annoBA=@AnnoB(intB=999)"}, + {"@AnnoB(intB=999)"}, + {"@AnnoC", "annoBA=[@AnnoB(intB=999)]", "intA=[2147483647]", "enumA=[A]", "stringA=[]", "doubleA=[4.9E-324]"} + }; + + String[][] expectedF = new String[][]{ + {"@AnnoA", "enumA=A", "intA=2147483647", "stringA=", "doubleA=4.9E-324", "annoBA=@AnnoB(intB=999)"}, + {"@AnnoB(intB=999)"}, + {"@AnnoC", "annoBA=[@AnnoB(intB=999)]", "intA=[2147483647]", "enumA=[A]", "stringA=[]", "doubleA=[4.9E-324]"}, + {"@AnnoD", "enumA=A", "intA=2147483647", "stringA=", "doubleA=4.9E-324", "annoBA=@AnnoB(intB=999)"}, + }; + + new AnnotationGetter("GrandFather", expectedGF, expectedGF, threadGroup, "threadGF").start(); + new AnnotationGetter("Father", expectedF, expectedF, threadGroup, "threadF").start(); + new AnnotationGetter("Interface", expectedF, expectedF, threadGroup, "threadI").start(); + new AnnotationGetter("Son", expectedF, new String[][]{}, threadGroup, "threadS").start(); + new AnnotationGetter("Son2", expectedF, new String[][]{}, threadGroup, "threadS2").start(); + new AnnotationGetter("GrandFather", expectedGF, expectedGF, threadGroup, "threadGF").start(); + new AnnotationGetter("Father", expectedF, expectedF, threadGroup, "threadF").start(); + new AnnotationGetter("Interface", expectedF, expectedF, threadGroup, "threadI").start(); + new AnnotationGetter("Son", expectedF, new String[][]{}, threadGroup, "threadI").start(); + new AnnotationGetter("Son2", expectedF, new String[][]{}, threadGroup, "threadI").start(); + + int i = 0; + while (threadGroup.activeCount() > 0){ + i++; + try { + Thread.sleep(100); + }catch (InterruptedException e){ + System.out.println(e); + } + if(i > 1000){ + break; + } + } + + System.out.println(passCnt.get() - 200); + } + + + public static boolean checkAllAnnotations(Annotation[] annotations, String[][] expected){ + String[] actual = new String[annotations.length]; + + for (int i = 0; i < annotations.length; i++){ + actual[i] = annotations[i].toString(); + } + Arrays.sort(actual); + if (actual.length != expected.length){ + return false; + } +// System.out.println(Arrays.toString(actual)); + for (int i = 0; i < annotations.length; i++){ + if (expected[i].length == 1){ + if (actual[i].compareTo(expected[i][0])!=0){ + System.out.println(actual[i]); + System.out.println(expected[i][0]); + return false; + } + }else { + for (int j = 0; j < expected[i].length; j++){ + if (!actual[i].contains(expected[i][j])){ + System.out.println(actual[i]); + System.out.println(expected[i][j]); + return false; + } + } + } + } + return true; + } + +} + +class AnnotationGetter extends Thread{ + String name; + String[][] expected; + String[][] expectedD; + + AnnotationGetter(String nameI, String[][] expectedI, String[][] expectedDI, ThreadGroup threadGroup, String thread_name){ + super(threadGroup, thread_name); + name = nameI; + expected = expectedI; + expectedD = expectedDI; + } + + @Override + public void run() { + try { + for (int i = 0; i < 10; i++) { + if (AnnotationMultiThread.checkAllAnnotations(Class.forName(this.name).getAnnotations(), this.expected)){ + AnnotationMultiThread.passCnt.incrementAndGet(); + } + if (AnnotationMultiThread.checkAllAnnotations(Class.forName(this.name).getDeclaredAnnotations(), this.expectedD)){ + AnnotationMultiThread.passCnt.incrementAndGet(); + } + } + }catch (Exception e){ + e.printStackTrace(); + } + + } +} + +@AnnoB +@AnnoA(annoBA = @AnnoB) +@AnnoC() +class GrandFather{ + public void method1(int a, double b, Object... objects){ + } +} + +@SuppressWarnings("all") +@AnnoB +@AnnoA(annoBA = @AnnoB) +@AnnoC() +@AnnoD(annoBA = @AnnoB) +class Father extends GrandFather implements Interface{ + @Override + public void method1(int a, double b, Object... objects) { + } + + @Deprecated + public void method2(){ + } +} + +class Son extends Father{ + @Override + @Deprecated + public void method2(){ + } +} + +class Son2 extends Father{ + @Override + @Deprecated + public void method2(){ + } +} + +@SuppressWarnings("all") +@AnnoB +@AnnoA(annoBA = @AnnoB) +@AnnoC() +@AnnoD(annoBA = @AnnoB) +interface Interface{ + +} +// DEPENDENCE: AnnoA.java AnnoB.java AnnoC.java AnnoD.java ENUMA.java +// EXEC:%maple %f AnnoA.java AnnoB.java AnnoC.java AnnoD.java ENUMA.java %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/ENUMA.java b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/ENUMA.java new file mode 100755 index 0000000000..4b216d8166 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0202-rt-compact-AnnotationMultiThread/ENUMA.java @@ -0,0 +1,5 @@ +public enum ENUMA { + A, + B, + C +} diff --git a/test/testsuite/ouroboros/compact_test/RT0203-rt-compact-ReflectSpecialClassNameTest/ReflectClassNameTest.java b/test/testsuite/ouroboros/compact_test/RT0203-rt-compact-ReflectSpecialClassNameTest/ReflectClassNameTest.java new file mode 100755 index 0000000000..8161e00393 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0203-rt-compact-ReflectSpecialClassNameTest/ReflectClassNameTest.java @@ -0,0 +1,70 @@ +/* + *- @TestCaseID: Maple_Annotation_invoke_AnnotationSetTest + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:ReflectClassNameTest.java + *- @TestCaseName: ReflectClassNameTest + *- @TestCaseType: Function Testing + *- @RequirementID: AR000D0OR6 + *- @RequirementName: annotation + *- @Title/Destination: positive test for reflection, able to get class, method, field with non-english + *- @Condition: no + *- @Brief:no: + * -#step1. class, method, field with non-english name + * -#step2. able to be get by reflection + *- @Expect:0\n + *- @Priority: Level 1 + *- @Remark: + *- @Source: ReflectClassNameTest.java + *- @ExecuteClass: ReflectClassNameTest + *- @ExecuteArgs: + */ +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Arrays; + +public class ReflectClassNameTest { + static int[] passCnt = new int[6]; + public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { + int i = 0; + Class clazz = Class.forName("一"); + passCnt[i++] = clazz.getName().compareTo("一") == 0 ? 1 : 0; + Method method = clazz.getDeclaredMethod("дракон"); + passCnt[i++] = method.getName().compareTo("дракон") == 0 ? 1 : 0; + Field field = clazz.getDeclaredField("Rồng"); + passCnt[i++] = field.getName().compareTo("Rồng") == 0 ? 1 : 0; + + Class clazz2 = Class.forName("二"); + passCnt[i++] = clazz2.getName().compareTo("二") == 0 ? 1 : 0; + + class 三{ + + } + Class clazz3 = Class.forName("ReflectClassNameTest$1三"); + passCnt[i++] = clazz3.getName().compareTo("ReflectClassNameTest$1三") == 0 ? 1 : 0; + + Class clazz4 = Class.forName("ReflectClassNameTest$二"); + passCnt[i++] = clazz4.getName().compareTo("ReflectClassNameTest$二") == 0 ? 1 : 0; + + System.out.println(Arrays.toString(passCnt).compareTo("[1, 1, 1, 1, 1, 1]")); + } + + class 二{ + + } +} + +class 一{ + int Rồng; + + public void дракон(){ + + } +} + +interface 二{ + +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnoA.java b/test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnoA.java new file mode 100755 index 0000000000..fecde3f71b --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnoA.java @@ -0,0 +1,32 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoA { + int 整型(); + byte 字节(); + char 字符(); + double 双精度浮点(); + boolean 布尔(); + long 长整(); + float 浮点(); + short 短整型(); + int[] あ(); + byte[] い(); + char[] う(); + double[] え(); + boolean[] お(); + long[] か(); + float[] き(); + short[] く(); + String 长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长(); + String[] 神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马(); + Class 类(); + Class[] 类类(); + Thread.State 类类类(); + Thread.State[] 类类类类(); + AnnoB 类类类类类(); + AnnoB[] 类类类类类类(); +} diff --git a/test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnoB.java b/test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnoB.java new file mode 100755 index 0000000000..70a77a033f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnoB.java @@ -0,0 +1,9 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoB { + int intB() default 999; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnotationNotAscii.java b/test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnotationNotAscii.java new file mode 100755 index 0000000000..09e5395c85 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0204-rt-compact-AnnotationSpecialCharacter/AnnotationNotAscii.java @@ -0,0 +1,75 @@ +/* + *- @TestCaseID: Maple_Annotation_invoke_AnnotationSetTest + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:AnnotationNotAscii.java + *- @TestCaseName: AnnotationNotAscii + *- @TestCaseType: Function Testing + *- @RequirementID: AR000D0OR6 + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation with @Target(ElementType.TYPE) + *- @Condition: no + *- @Brief:no: + * -#step1. User-defined Annotation with @Target(ElementType.TYPE) has field with primitive type, String, ENUM, annotation, class and their array + * -#step2. verify able to set and get value on class + *- @Expect:0\n + *- @Priority: Level 1 + *- @Remark: + *- @Source: AnnotationNotAscii.java AnnoA.java AnnoB.java + *- @ExecuteClass: AnnotationNotAscii + *- @ExecuteArgs: + */ + +import java.util.Arrays; + +public class AnnotationNotAscii { + static int[] passCnt = new int[24]; + public static void main(String[] args) { + AnnoA anno = Test.class.getAnnotation(AnnoA.class); + // primitive type + int i = 0; + passCnt[i++] = anno.整型() == Integer.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.字节() == Byte.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.字符() == Character.MAX_VALUE ? 1: 0; + passCnt[i++] += Double.isNaN(anno.双精度浮点()) ? 1: 0; + passCnt[i++] += anno.布尔() ? 1: 0; + passCnt[i++] += anno.长整() == Long.MAX_VALUE ? 1: 0; + passCnt[i++] += Float.isNaN(anno.浮点())? 1: 0; + passCnt[i++] += anno.短整型() == Short.MAX_VALUE ? 1: 0; + + // enum, string, annotation, class + passCnt[i++] += anno.类类类() == Thread.State.BLOCKED ? 1: 0; + passCnt[i++] += anno.长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长().compareTo("") == 0 ? 1: 0; + passCnt[i++] += anno.类() == Thread.class ? 1: 0; + passCnt[i++] += Arrays.toString(anno.あ()).compareTo("[1, 2]") == 0 ? 1: 0; + + // array + passCnt[i++] += (anno.い().length == 1 && anno.い()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.う().length == 1 && anno.う()[0] == ' ') ? 1: 0; + passCnt[i++] += (anno.え().length == 3 && Double.isNaN(anno.え()[0]) && Double.isInfinite(anno.え()[1]) && Double.isInfinite(anno.え()[2]))? 1: 0; + passCnt[i++] += (anno.お().length == 1 && anno.お()[0]) ? 1: 0; + passCnt[i++] += (anno.か().length == 1 && anno.か()[0] == Long.MAX_VALUE) ? 1: 0; + passCnt[i++] += (anno.き().length == 3 && Float.isNaN(anno.き()[0]) && Float.isInfinite(anno.き()[1]) && Float.isInfinite(anno.き()[2])) ? 1: 0; + passCnt[i++] += (anno.く().length == 1 && anno.く()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马().length == 1 && anno.神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马()[0].compareTo("")==0) ? 1: 0; + passCnt[i++] += (anno.类类().length == 1 && anno.类类()[0] == Thread.class)? 1: 0; + passCnt[i++] += (anno.类类类类().length == 1 && anno.类类类类()[0] == Thread.State.NEW) ? 1: 0; + passCnt[i++] += anno.类类类类类().toString().compareTo("@AnnoB(intB=999)")==0 ? 1: 0; + passCnt[i++] += Arrays.toString(anno.类类类类类类()).compareTo("[@AnnoB(intB=999), @AnnoB(intB=999)]") == 0 ? 1: 0; + System.out.println(Arrays.toString(passCnt).compareTo("[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]")); + } +} + +@AnnoA(整型 = Integer.MAX_VALUE, 字节 = Byte.MAX_VALUE, 字符 = Character.MAX_VALUE, 双精度浮点 = Double.NaN, + 布尔 = true, 长整 = Long.MAX_VALUE, 浮点 = Float.NaN, 短整型 = Short.MAX_VALUE, + あ = {1,2}, い = {0}, う = {' '}, え = {Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, + お = {true}, か = {Long.MAX_VALUE}, き = {Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY}, く = {0}, + 长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长 = "", 神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马神马 = "", 类 = Thread.class, 类类 = Thread.class, 类类类 = Thread.State.BLOCKED, + 类类类类 = Thread.State.NEW, 类类类类类 = @AnnoB, 类类类类类类 = {@AnnoB, @AnnoB}) +class Test{ + +} +// DEPENDENCE: AnnoA.java AnnoB.java +// EXEC:%maple %f AnnoA.java AnnoB.java %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnoA.java b/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnoA.java new file mode 100755 index 0000000000..c3c78b6b3e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnoA.java @@ -0,0 +1,53 @@ +import java.lang.annotation.*; + + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@Repeatable(Test.class) +@AnnoB(intB = 1) +@AnnoB(intB = 2) +@AnnoB(intB = 3) +@AnnoB(intB = 4) +@AnnoB(intB = 5) +@AnnoB(intB = 6) +@AnnoB(intB = 7) +@AnnoB(intB = 8) +@AnnoB(intB = 9) +@AnnoB(intB = 10) +@AnnoB(intB = 11) +@AnnoB(intB = 12) +@AnnoB(intB = 13) +@AnnoB(intB = 14) +@AnnoB(intB = 15) +@AnnoB(intB = 16) +@AnnoB(intB = 17) +@AnnoB(intB = 18) +public @interface AnnoA { + int intA() default 0; + byte byteA() default 0; + char charA() default 0; + double doubleA() default 0; + boolean booleanA() default true; + long longA() default 0; + float floatA() default 0; + short shortA() default 0; + int[] intAA() default 0; + byte[] byteAA() default 0; + char[] charAA() default 0; + double[] doubleAA() default 0; + boolean[] booleanAA() default true; + long[] longAA() default 0; + float[] floatAA() default 0; + short[] shortAA() default 0; + String stringA() default ""; + String[] stringAA() default ""; + Class classA() default Thread.class; + Class[] classAA() default Thread.class; + Thread.State stateA() default Thread.State.BLOCKED; + Thread.State[] stateAA() default Thread.State.BLOCKED; + AnnoB annoBA() default @AnnoB; + AnnoB[] annoBAA() default @AnnoB; + AnnoB[] value(); +} diff --git a/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnoB.java b/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnoB.java new file mode 100755 index 0000000000..08e0bcc447 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnoB.java @@ -0,0 +1,10 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@Repeatable(AnnoA.class) +public @interface AnnoB { + int intB() default 999; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnotationRepeatable.java b/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnotationRepeatable.java new file mode 100755 index 0000000000..12f2bbaa24 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/AnnotationRepeatable.java @@ -0,0 +1,87 @@ +/* + *- @TestCaseID: Maple_Annotation_invoke_AnnotationSetTest + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:AnnotationRepeatable.java + *- @TestCaseName: AnnotationRepeatable + *- @TestCaseType: Function Testing + *- @RequirementID: AR000D0OR6 + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation with @Repeatable + *- @Condition: no + *- @Brief:no: + * -#step1. User-defined Annotation with @Repeatable can be used more than one time on annotation type + * -#step2. verify able to set and get value on class + *- @Expect:0\n + *- @Priority: Level 1 + *- @Remark: + *- @Source: AnnotationRepeatable.java AnnoA.java AnnoB.java Test.java + *- @ExecuteClass: AnnotationRepeatable + *- @ExecuteArgs: + */ + +import java.util.Arrays; + +public class AnnotationRepeatable { + static int[] passCnt = new int[25]; + public static void main(String[] args) { + checkAnnoA(Test.class.getAnnotation(Test.class).value()[0], "[@AnnoB(intB=-1)]"); + checkAnnoA(Test.class.getAnnotation(Test.class).value()[1], "[@AnnoB(intB=-2), @AnnoB(intB=1)]"); + checkAnnoA(Test.class.getAnnotation(Test.class).value()[2], "[@AnnoB(intB=-3), @AnnoB(intB=1), @AnnoB(intB=1)]"); + checkAnnoA(Test.class.getAnnotation(Test.class).value()[3], "[@AnnoB(intB=-4), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1)]"); + checkAnnoA(Test.class.getAnnotation(Test.class).value()[4], "[@AnnoB(intB=-5), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1)]"); + checkAnnoA(Test.class.getAnnotation(Test.class).value()[5], "[@AnnoB(intB=-6), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1)]"); + checkAnnoA(Test.class.getAnnotation(Test.class).value()[6], "[@AnnoB(intB=-7), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1)]"); + checkAnnoA(Test.class.getAnnotation(Test.class).value()[7], "[@AnnoB(intB=-8), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1)]"); + checkAnnoA(Test.class.getAnnotation(Test.class).value()[8], "[@AnnoB(intB=-9), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1)]"); + checkAnnoA(Test.class.getAnnotation(Test.class).value()[9], "[@AnnoB(intB=-10), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1), @AnnoB(intB=1)]"); + + boolean checkAnnoA = Arrays.toString(passCnt).compareTo("[1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]") == 0; + boolean checkAnnoB = Arrays.toString(AnnoA.class.getAnnotation(AnnoA.class).value()).compareTo("[@AnnoB(intB=1), @AnnoB(intB=2), @AnnoB(intB=3), @AnnoB(intB=4), @AnnoB(intB=5), @AnnoB(intB=6), @AnnoB(intB=7), @AnnoB(intB=8), @AnnoB(intB=9), @AnnoB(intB=10), @AnnoB(intB=11), @AnnoB(intB=12), @AnnoB(intB=13), @AnnoB(intB=14), @AnnoB(intB=15), @AnnoB(intB=16), @AnnoB(intB=17), @AnnoB(intB=18)]") == 0; + + if (checkAnnoA && checkAnnoB){ + System.out.println(0); + } else { + System.out.println(2); + } + } + + private static void checkAnnoA(AnnoA anno, String value){ + int i = 0; + passCnt[i++] = anno.intA() == 0 ? 1: 0; + passCnt[i++] += anno.byteA() == 0 ? 1: 0; + passCnt[i++] += anno.charA() == 0 ? 1: 0; + passCnt[i++] += anno.doubleA() == 0 ? 1: 0; + passCnt[i++] += anno.booleanA() ? 1: 0; + passCnt[i++] += anno.longA() == 0 ? 1: 0; + passCnt[i++] += anno.floatA() == 0? 1: 0; + passCnt[i++] += anno.shortA() == 0 ? 1: 0; + + // enum, string, annotation, class + passCnt[i++] += anno.stateA() == Thread.State.BLOCKED ? 1: 0; + passCnt[i++] += anno.stringA().compareTo("") == 0 ? 1: 0; + passCnt[i++] += anno.classA() == Thread.class ? 1: 0; + passCnt[i++] += anno.annoBA().toString().compareTo("@AnnoB(intB=999)")==0 ? 1: 0; + + // array + passCnt[i++] += Arrays.toString(anno.intAA()).compareTo("[0]") == 0 ? 1: 0; + passCnt[i++] += (anno.byteAA().length == 1 && anno.byteAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.charAA().length == 1 && anno.charAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.doubleAA().length == 1 && anno.doubleAA()[0] == 0)? 1: 0; + passCnt[i++] += (anno.booleanAA().length == 1 && anno.booleanAA()[0]) ? 1: 0; + passCnt[i++] += (anno.longAA().length == 1 && anno.longAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.floatAA().length == 1 && anno.floatAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.shortAA().length == 1 && anno.shortAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.stringAA().length == 1 && anno.stringAA()[0].compareTo("")==0) ? 1: 0; + passCnt[i++] += (anno.classAA().length == 1 && anno.classAA()[0] == Thread.class)? 1: 0; + passCnt[i++] += (anno.stateAA().length == 1 && anno.stateAA()[0] == Thread.State.BLOCKED) ? 1: 0; + passCnt[i++] += Arrays.toString(anno.annoBAA()).compareTo("[@AnnoB(intB=999)]") == 0 ? 1: 0; + + // value + passCnt[i++] += Arrays.toString(anno.value()).compareTo(value) == 0 ? 1: 0; + } +} +// DEPENDENCE: AnnoA.java AnnoB.java Test.java +// EXEC:%maple %f AnnoA.java AnnoB.java Test.java %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/Test.java b/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/Test.java new file mode 100755 index 0000000000..6294012ade --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0205-rt-compact-AnnotationRepeatable/Test.java @@ -0,0 +1,19 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@AnnoA( value = @AnnoB(intB = -1)) +@AnnoA( value = {@AnnoB(intB = -2), @AnnoB(intB = 1)}) +@AnnoA( value = {@AnnoB(intB = -3), @AnnoB(intB = 1), @AnnoB(intB = 1)}) +@AnnoA( value = {@AnnoB(intB = -4), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1)}) +@AnnoA( value = {@AnnoB(intB = -5), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1)}) +@AnnoA( value = {@AnnoB(intB = -6), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1)}) +@AnnoA( value = {@AnnoB(intB = -7), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1)}) +@AnnoA( value = {@AnnoB(intB = -8), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1)}) +@AnnoA( value = {@AnnoB(intB = -9), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1)}) +@AnnoA( value = {@AnnoB(intB = -10), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1), @AnnoB(intB = 1)}) +public @interface Test{ + AnnoA[] value(); +} diff --git a/test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnoA.java b/test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnoA.java new file mode 100755 index 0000000000..38b433b809 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnoA.java @@ -0,0 +1,32 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoA { + int intA(); + byte byteA(); + char charA(); + double doubleA(); + boolean booleanA(); + long longA(); + float floatA(); + short shortA(); + int[] intAA(); + byte[] byteAA(); + char[] charAA(); + double[] doubleAA(); + boolean[] booleanAA(); + long[] longAA(); + float[] floatAA(); + short[] shortAA(); + String stringA(); + String[] stringAA(); + Class classA(); + Class[] classAA(); + Thread.State stateA(); + Thread.State[] stateAA(); + AnnoB annoBA(); + AnnoB[] annoBAA(); +} diff --git a/test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnoB.java b/test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnoB.java new file mode 100755 index 0000000000..70a77a033f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnoB.java @@ -0,0 +1,9 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoB { + int intB() default 999; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnotationTypeInnerClassSet.java b/test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnotationTypeInnerClassSet.java new file mode 100755 index 0000000000..a2f27d5ead --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0206-rt-compact-AnnotationTypeInnerClassSet/AnnotationTypeInnerClassSet.java @@ -0,0 +1,79 @@ +/* + *- @TestCaseID: Maple_Annotation_invoke_AnnotationSetTest + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:AnnotationTypeInnerClassSet.java + *- @TestCaseName: AnnotationTypeInnerClassSet + *- @TestCaseType: Function Testing + *- @RequirementID: AR000D0OR6 + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation with @Target(ElementType.TYPE) + *- @Condition: no + *- @Brief:no: + * -#step1. User-defined Annotation with @Target(ElementType.TYPE) has field with primitive type, String, ENUM, annotation, class and their array + * -#step2. verify able to set and get value on inner class + *- @Expect:0\n + *- @Priority: Level 1 + *- @Remark: + *- @Source: AnnotationTypeInnerClassSet.java AnnoA.java AnnoB.java + *- @ExecuteClass: AnnotationTypeInnerClassSet + *- @ExecuteArgs: + */ + +import java.util.Arrays; + +public class AnnotationTypeInnerClassSet { + static int[] passCnt = new int[24]; + public static void main(String[] args) throws ClassNotFoundException { + AnnoA anno = Class.forName("AnnotationTypeInnerClassSet$Test").getAnnotation(AnnoA.class); + // primitive type + int i = 0; + passCnt[i++] = anno.intA() == Integer.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.byteA() == Byte.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.charA() == Character.MAX_VALUE ? 1: 0; + passCnt[i++] += Double.isNaN(anno.doubleA()) ? 1: 0; + passCnt[i++] += anno.booleanA() ? 1: 0; + passCnt[i++] += anno.longA() == Long.MAX_VALUE ? 1: 0; + passCnt[i++] += Float.isNaN(anno.floatA())? 1: 0; + passCnt[i++] += anno.shortA() == Short.MAX_VALUE ? 1: 0; + + // enum, string, annotation, class + passCnt[i++] += anno.stateA() == Thread.State.BLOCKED ? 1: 0; + passCnt[i++] += anno.stringA().compareTo("") == 0 ? 1: 0; + passCnt[i++] += anno.classA() == Thread.class ? 1: 0; + passCnt[i++] += Arrays.toString(anno.intAA()).compareTo("[1, 2]") == 0 ? 1: 0; + + // array + passCnt[i++] += (anno.byteAA().length == 1 && anno.byteAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.charAA().length == 1 && anno.charAA()[0] == ' ') ? 1: 0; + passCnt[i++] += (anno.doubleAA().length == 3 && Double.isNaN(anno.doubleAA()[0]) && + Double.isInfinite(anno.doubleAA()[1]) && Double.isInfinite(anno.doubleAA()[2]))? 1: 0; + passCnt[i++] += (anno.booleanAA().length == 1 && anno.booleanAA()[0]) ? 1: 0; + passCnt[i++] += (anno.longAA().length == 1 && anno.longAA()[0] == Long.MAX_VALUE) ? 1: 0; + passCnt[i++] += (anno.floatAA().length == 3 && Float.isNaN(anno.floatAA()[0]) && + Float.isInfinite(anno.floatAA()[1]) && Float.isInfinite(anno.floatAA()[2])) ? 1: 0; + passCnt[i++] += (anno.shortAA().length == 1 && anno.shortAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.stringAA().length == 1 && anno.stringAA()[0].compareTo("")==0) ? 1: 0; + passCnt[i++] += (anno.classAA().length == 1 && anno.classAA()[0] == Thread.class)? 1: 0; + passCnt[i++] += (anno.stateAA().length == 1 && anno.stateAA()[0] == Thread.State.NEW) ? 1: 0; + passCnt[i++] += anno.annoBA().toString().compareTo("@AnnoB(intB=999)")==0 ? 1: 0; + passCnt[i++] += Arrays.toString(anno.annoBAA()).compareTo("[@AnnoB(intB=999), @AnnoB(intB=999)]") == 0 ? 1: 0; + System.out.println(Arrays.toString(passCnt) + .compareTo("[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]")); + } + + @AnnoA(intA = Integer.MAX_VALUE, byteA = Byte.MAX_VALUE, charA = Character.MAX_VALUE, doubleA = Double.NaN, + booleanA = true, longA = Long.MAX_VALUE, floatA = Float.NaN, shortA = Short.MAX_VALUE, + intAA = {1,2}, byteAA = {0}, charAA = {' '}, doubleAA = {Double.NaN, Double.NEGATIVE_INFINITY, + Double.POSITIVE_INFINITY}, booleanAA = {true}, longAA = {Long.MAX_VALUE}, floatAA = {Float.NaN, + Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY}, shortAA = {0}, + stringA = "", stringAA = "", classA = Thread.class, classAA = Thread.class, stateA = Thread.State.BLOCKED, + stateAA = Thread.State.NEW, annoBA = @AnnoB, annoBAA = {@AnnoB, @AnnoB}) + class Test{ + + } +} +// DEPENDENCE: AnnoA.java AnnoB.java +// EXEC:%maple %f AnnoA.java AnnoB.java %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnoA.java b/test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnoA.java new file mode 100755 index 0000000000..38b433b809 --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnoA.java @@ -0,0 +1,32 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoA { + int intA(); + byte byteA(); + char charA(); + double doubleA(); + boolean booleanA(); + long longA(); + float floatA(); + short shortA(); + int[] intAA(); + byte[] byteAA(); + char[] charAA(); + double[] doubleAA(); + boolean[] booleanAA(); + long[] longAA(); + float[] floatAA(); + short[] shortAA(); + String stringA(); + String[] stringAA(); + Class classA(); + Class[] classAA(); + Thread.State stateA(); + Thread.State[] stateAA(); + AnnoB annoBA(); + AnnoB[] annoBAA(); +} diff --git a/test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnoB.java b/test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnoB.java new file mode 100755 index 0000000000..70a77a033f --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnoB.java @@ -0,0 +1,9 @@ +import java.lang.annotation.*; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface AnnoB { + int intB() default 999; +} diff --git a/test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnotationTypeLocalClassSet.java b/test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnotationTypeLocalClassSet.java new file mode 100755 index 0000000000..a9e468b97e --- /dev/null +++ b/test/testsuite/ouroboros/compact_test/RT0207-rt-compact-AnnotationTypeLocalClassSet/AnnotationTypeLocalClassSet.java @@ -0,0 +1,77 @@ +/* + *- @TestCaseID: Maple_Annotation_invoke_AnnotationSetTest + *- @RequirementName: Java Reflection + *- @RequirementID: SR000B7N9H + *- @TestCaseName:AnnotationTypeLocalClassSet.java + *- @TestCaseName: AnnotationTypeLocalClassSet + *- @TestCaseType: Function Testing + *- @RequirementID: AR000D0OR6 + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation with @Target(ElementType.TYPE) + *- @Condition: no + *- @Brief:no: + * -#step1. User-defined Annotation with @Target(ElementType.TYPE) has field with primitive type, String, ENUM, annotation, class and their array + * -#step2. verify able to set and get value on inner class + *- @Expect:0\n + *- @Priority: Level 1 + *- @Remark: + *- @Source: AnnotationTypeLocalClassSet.java AnnoA.java AnnoB.java + *- @ExecuteClass: AnnotationTypeLocalClassSet + *- @ExecuteArgs: + */ + +import java.util.Arrays; + +public class AnnotationTypeLocalClassSet { + static int[] passCnt = new int[24]; + public static void main(String[] args) throws ClassNotFoundException { + @AnnoA(intA = Integer.MAX_VALUE, byteA = Byte.MAX_VALUE, charA = Character.MAX_VALUE, doubleA = Double.NaN, + booleanA = true, longA = Long.MAX_VALUE, floatA = Float.NaN, shortA = Short.MAX_VALUE, + intAA = {1,2}, byteAA = {0}, charAA = {' '}, doubleAA = {Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, + booleanAA = {true}, longAA = {Long.MAX_VALUE}, floatAA = {Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY}, shortAA = {0}, + stringA = "", stringAA = "", classA = Thread.class, classAA = Thread.class, stateA = Thread.State.BLOCKED, + stateAA = Thread.State.NEW, annoBA = @AnnoB, annoBAA = {@AnnoB, @AnnoB}) + class Test{ + + } + + AnnoA anno = Class.forName("AnnotationTypeLocalClassSet$1Test").getAnnotation(AnnoA.class); + // primitive type + int i = 0; + passCnt[i++] = anno.intA() == Integer.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.byteA() == Byte.MAX_VALUE ? 1: 0; + passCnt[i++] += anno.charA() == Character.MAX_VALUE ? 1: 0; + passCnt[i++] += Double.isNaN(anno.doubleA()) ? 1: 0; + passCnt[i++] += anno.booleanA() ? 1: 0; + passCnt[i++] += anno.longA() == Long.MAX_VALUE ? 1: 0; + passCnt[i++] += Float.isNaN(anno.floatA())? 1: 0; + passCnt[i++] += anno.shortA() == Short.MAX_VALUE ? 1: 0; + + // enum, string, annotation, class + passCnt[i++] += anno.stateA() == Thread.State.BLOCKED ? 1: 0; + passCnt[i++] += anno.stringA().compareTo("") == 0 ? 1: 0; + passCnt[i++] += anno.classA() == Thread.class ? 1: 0; + passCnt[i++] += Arrays.toString(anno.intAA()).compareTo("[1, 2]") == 0 ? 1: 0; + + // array + passCnt[i++] += (anno.byteAA().length == 1 && anno.byteAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.charAA().length == 1 && anno.charAA()[0] == ' ') ? 1: 0; + passCnt[i++] += (anno.doubleAA().length == 3 && Double.isNaN(anno.doubleAA()[0]) && Double.isInfinite(anno.doubleAA()[1]) && Double.isInfinite(anno.doubleAA()[2]))? 1: 0; + passCnt[i++] += (anno.booleanAA().length == 1 && anno.booleanAA()[0]) ? 1: 0; + passCnt[i++] += (anno.longAA().length == 1 && anno.longAA()[0] == Long.MAX_VALUE) ? 1: 0; + passCnt[i++] += (anno.floatAA().length == 3 && Float.isNaN(anno.floatAA()[0]) && Float.isInfinite(anno.floatAA()[1]) && Float.isInfinite(anno.floatAA()[2])) ? 1: 0; + passCnt[i++] += (anno.shortAA().length == 1 && anno.shortAA()[0] == 0) ? 1: 0; + passCnt[i++] += (anno.stringAA().length == 1 && anno.stringAA()[0].compareTo("")==0) ? 1: 0; + passCnt[i++] += (anno.classAA().length == 1 && anno.classAA()[0] == Thread.class)? 1: 0; + passCnt[i++] += (anno.stateAA().length == 1 && anno.stateAA()[0] == Thread.State.NEW) ? 1: 0; + passCnt[i++] += anno.annoBA().toString().compareTo("@AnnoB(intB=999)")==0 ? 1: 0; + passCnt[i++] += Arrays.toString(anno.annoBAA()).compareTo("[@AnnoB(intB=999), @AnnoB(intB=999)]") == 0 ? 1: 0; + System.out.println(Arrays.toString(passCnt).compareTo("[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]")); + } + + +} +// DEPENDENCE: AnnoA.java AnnoB.java +// EXEC:%maple %f AnnoA.java AnnoB.java %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan-full 0\n diff --git a/test/testsuite/ouroboros/testlist b/test/testsuite/ouroboros/testlist index 4bd5ad809b..0d0464236b 100644 --- a/test/testsuite/ouroboros/testlist +++ b/test/testsuite/ouroboros/testlist @@ -1,6 +1,7 @@ [ALL-TEST-CASE] arrayboundary_test clinit_test + compact_test eh_test fuzzapi_test other_test -- Gitee From 51fef0751bbf4d82956dff99a3b5c6a76379a908 Mon Sep 17 00:00:00 2001 From: binaryfz Date: Sat, 12 Dec 2020 10:49:33 +0800 Subject: [PATCH 2/2] add exclude case of compact_test --- test/testsuite/ouroboros/testlist | 1 + 1 file changed, 1 insertion(+) diff --git a/test/testsuite/ouroboros/testlist b/test/testsuite/ouroboros/testlist index 0d0464236b..7bc631a5da 100644 --- a/test/testsuite/ouroboros/testlist +++ b/test/testsuite/ouroboros/testlist @@ -20,3 +20,4 @@ reflection_test/issue-0000-rt-Reflection-ReflectionforName2 memory_management/MemoryTest/RC0410-rc-Memory-stressTestCase29 thread_test/RT0180-rt-thread-MonitorTestCase8 + compact_test/RT0199-rt-compact-AnnotationPackageSetTest -- Gitee