diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 28ced05760cc6c930c7f7056b98ffb517dab1e45..6ba9c094211183da74f8a61a66d4e0e87937f0e8 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 50a27fd5f3e098b292bff19f6199b201cfe691b3..4608e9f7de0a3bf181aa189c7d1e177186df2091 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index a307177ad0dd8480a46e8c1aa479be93674a5654..e5f0124d6995c74958e8190f9ec29c6b19e805d8 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index 2a5a60baa505530e6ab65582bb7e90914bc9b888..feeb781a66908a038e31351ceb2c59ed10abf6ab 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -199,6 +199,9 @@ class MIRFunction { void SetAttr(FuncAttrKind attrKind) { funcAttrs.SetAttr(attrKind); } + void UnSetAttr(FuncAttrKind attrKind) { + funcAttrs.SetAttr(attrKind, true); + } bool IsVarargs() const { return funcAttrs.GetAttr(FUNCATTR_varargs); diff --git a/src/mpl2mpl/include/native_stub_func.h b/src/mpl2mpl/include/native_stub_func.h index 7f53b9545340305cd9535ea13f1c1a668cda63ac..76e659cba8c2a58d3d2e3e8399022f13cb0b8116 100644 --- a/src/mpl2mpl/include/native_stub_func.h +++ b/src/mpl2mpl/include/native_stub_func.h @@ -25,7 +25,7 @@ constexpr int kSlownativeFuncnum = 9; #endif constexpr int kJniTypeNormal = 0; constexpr int kJniTypeMapleCriticalNative = 1; -constexpr int kJnitTypeCriticalNative = 2; +constexpr int kJniTypeCriticalNative = 2; constexpr int kInvalidCode = 0x01; class NativeFuncProperty { diff --git a/src/mpl2mpl/src/native_stub_func.cpp b/src/mpl2mpl/src/native_stub_func.cpp index 1ff672192c61924050fb7d253bb233cf8e513ddf..9009e31f7e0a64d33379c13d3a4283877a230882 100644 --- a/src/mpl2mpl/src/native_stub_func.cpp +++ b/src/mpl2mpl/src/native_stub_func.cpp @@ -114,16 +114,15 @@ void NativeStubFuncGeneration::ProcessFunc(MIRFunction *func) { return; } SetCurrentFunction(*func); - if (trace) { - LogInfo::MapleLogger(kLlErr) << "Create stub func: " << func->GetName() << "\n"; + // Has been processed by previous phases, such as simplify. + if (func->GetBody()->GetFirst()) { + GenerateRegTabEntry(*func); + GenerateRegFuncTabEntry(); + return; } func->GetBody()->ResetBlock(); NativeFuncProperty funcProperty; bool needNativeCall = (!func->GetAttr(FUNCATTR_critical_native)) && (funcProperty.jniType == kJniTypeNormal); - if (funcProperty.jniType == kJnitTypeCriticalNative) { - // Can't reach here now. - func->SetAttr(FUNCATTR_critical_native); - } GStrIdx classObjSymStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(CLASSINFO_PREFIX_STR + func->GetBaseClassName()); MIRSymbol *classObjSymbol = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(classObjSymStrIdx); @@ -313,7 +312,6 @@ void NativeStubFuncGeneration::GenerateRegTabEntry(const MIRFunction &func) { void NativeStubFuncGeneration::GenerateRegisteredNativeFuncCall(MIRFunction &func, const MIRFunction &nativeFunc, MapleVector &args, const MIRSymbol *ret) { - // Generate registration table entry. GenerateRegTabEntry(func); GenerateRegFuncTabEntry(); CallReturnVector nrets(func.GetCodeMempoolAllocator().Adapter()); @@ -373,7 +371,7 @@ void NativeStubFuncGeneration::GenerateRegisteredNativeFuncCall(MIRFunction &fun // Define wrapper function call StmtNode *wrapperCall = CreateNativeWrapperCallNode(func, readFuncPtr, args, ret); func.GetBody()->AddStatement(wrapperCall); - } else if (!Options::regNativeDynamicOnly) { + } else if (!Options::regNativeDynamicOnly) { // Qemu func.GetBody()->AddStatement(funcptrAssign); func.GetBody()->AddStatement(funcPtrAndOpAssign); // Get find_native_func function @@ -427,7 +425,7 @@ void NativeStubFuncGeneration::GenerateRegisteredNativeFuncCall(MIRFunction &fun elseBlock->AddStatement(wrapperCall); func.GetBody()->AddStatement(ifStmt); } - } else { + } else { // EMUI func.GetBody()->AddStatement(funcptrAssign); func.GetBody()->AddStatement(funcPtrAndOpAssign); MIRFunction *findNativeFunc = builder->GetOrCreateFunction(NameMangler::kFindNativeFunc, diff --git a/src/mplfe/common/include/fe_java_string_manager.h b/src/mplfe/common/include/fe_java_string_manager.h index fba82b13e3c069a69ba47a0740cf11d053efe774..aa527c7ce449abc3161a690baaa31d3c1548f20a 100644 --- a/src/mplfe/common/include/fe_java_string_manager.h +++ b/src/mplfe/common/include/fe_java_string_manager.h @@ -24,7 +24,7 @@ namespace maple { class FEJavaStringManager { public: explicit FEJavaStringManager(MIRModule &argModule); - ~FEJavaStringManager() = default; + ~FEJavaStringManager(); // profiling void LoadProfilingData(const std::string &profileFileName); MIRSymbol *GetLiteralPtrVar(const MIRSymbol *var) const; diff --git a/src/mplfe/common/include/fe_struct_elem_info.h b/src/mplfe/common/include/fe_struct_elem_info.h index 6c33000a0fd5ca180cca1cbf767cb6e402ccd514..88a04a5cc15494794ad7ab99b239a30804ee6ac4 100644 --- a/src/mplfe/common/include/fe_struct_elem_info.h +++ b/src/mplfe/common/include/fe_struct_elem_info.h @@ -134,7 +134,7 @@ class FEStructFieldInfo : public FEStructElemInfo { class FEStructMethodInfo : public FEStructElemInfo { public: FEStructMethodInfo(const GStrIdx &argFullNameIdx, MIRSrcLang argSrcLang, bool argIsStatic); - ~FEStructMethodInfo() = default; + ~FEStructMethodInfo(); PUIdx GetPuIdx() const; bool IsConstructor() const { return isConstructor; diff --git a/src/mplfe/common/src/fe_java_string_manager.cpp b/src/mplfe/common/src/fe_java_string_manager.cpp index 14e83c8e5cb06d368bd16643d0726fd6636a91f5..4ecf6d229acc47ce016531158c02c0b8b88e815a 100644 --- a/src/mplfe/common/src/fe_java_string_manager.cpp +++ b/src/mplfe/common/src/fe_java_string_manager.cpp @@ -25,6 +25,10 @@ namespace maple { FEJavaStringManager::FEJavaStringManager(MIRModule &argModule) : module(argModule) {} +FEJavaStringManager::~FEJavaStringManager() { + typeString = nullptr; +} + void FEJavaStringManager::LoadProfilingData(const std::string &profileFileName) { std::ifstream inFile(profileFileName); if (!inFile.is_open()) { diff --git a/src/mplfe/common/src/fe_struct_elem_info.cpp b/src/mplfe/common/src/fe_struct_elem_info.cpp index f1b6d3f8d5c13bbf4964cda8734042221f5174d0..f52bd6ddd38622890d400622f3f34b2c571163bd 100644 --- a/src/mplfe/common/src/fe_struct_elem_info.cpp +++ b/src/mplfe/common/src/fe_struct_elem_info.cpp @@ -80,7 +80,7 @@ void FEStructFieldInfo::PrepareImpl(MIRBuilder &mirBuilder, bool argIsStatic) { const std::string &structName = GetStructName(); std::string rawName = structName + NameMangler::kNameSplitterStr + GetElemName(); fieldNameIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(rawName); - fieldID = UINT32_MAX; + fieldID = static_cast(UINT32_MAX); MIRStructType *structType = FEManager::GetTypeManager().GetStructTypeFromName(structName); if (structType == nullptr) { isDefined = false; @@ -130,7 +130,7 @@ void FEStructFieldInfo::PrepareNonStaticField(MIRStructType &structType, MIRBuil uint32 idx = 0; uint32 idx1 = 0; mirBuilder.TraverseToNamedFieldWithType(structType, elemNameIdx, fieldMIRType->GetTypeIndex(), idx1, idx); - fieldID = idx; + fieldID = static_cast(idx); isPrepared = true; isStatic = false; } @@ -227,6 +227,10 @@ FEStructMethodInfo::FEStructMethodInfo(const GStrIdx &argFullNameIdx, MIRSrcLang LoadMethodType(); } +FEStructMethodInfo::~FEStructMethodInfo() { + mirFunc = nullptr; +} + void FEStructMethodInfo::InitJavaPolymorphicWhiteList() { MPLFE_PARALLEL_FORBIDDEN(); std::map> &ans = javaPolymorphicWhiteList; diff --git a/src/mplfe/common/src/fe_type_manager.cpp b/src/mplfe/common/src/fe_type_manager.cpp index 2f1e447d0d7417438b2914c4e93ac8c449ec854d..a7a68152ad102bc3cdff987ff7b464ec1efd4537 100644 --- a/src/mplfe/common/src/fe_type_manager.cpp +++ b/src/mplfe/common/src/fe_type_manager.cpp @@ -53,6 +53,7 @@ FETypeManager::FETypeManager(MIRModule &moduleIn) FETypeManager::~FETypeManager() { mp = nullptr; + funcMCCGetOrInsertLiteral = nullptr; } void FETypeManager::ReleaseMemPool() { diff --git a/src/mplfe/jbc_input/include/jbc_opcode.h b/src/mplfe/jbc_input/include/jbc_opcode.h index 2a022159de8987e78fae2565ffd75c5b408e96bc..c975589abee770aebb733994fc2ad1f06c8dc195 100644 --- a/src/mplfe/jbc_input/include/jbc_opcode.h +++ b/src/mplfe/jbc_input/include/jbc_opcode.h @@ -533,7 +533,7 @@ class JBCOpJsr : public JBCOp { } void SetSlotIdx(uint32 argSlotIdx) { - slotIdx = argSlotIdx; + slotIdx = static_cast(argSlotIdx); } int32 GetJsrID() const { diff --git a/src/mplfe/jbc_input/src/jbc_class_const.cpp b/src/mplfe/jbc_input/src/jbc_class_const.cpp index 505e476f20332861a39b46476615419cab40b3e5..c75b3bbeac4402d70c9c83c966ed2088a69e3c6a 100644 --- a/src/mplfe/jbc_input/src/jbc_class_const.cpp +++ b/src/mplfe/jbc_input/src/jbc_class_const.cpp @@ -201,6 +201,7 @@ JBCConstClass::JBCConstClass(MapleAllocator &alloc, JBCConstTag t, JBCConstPoolI JBCConstClass::~JBCConstClass() { constUTF8 = nullptr; + feType = nullptr; } bool JBCConstClass::ParseFileImpl(BasicIORead &io) { @@ -456,6 +457,7 @@ JBCConstInvokeDynamic::JBCConstInvokeDynamic(MapleAllocator &alloc, JBCConstTag JBCConstInvokeDynamic::~JBCConstInvokeDynamic() { constNameAndType = nullptr; + feStructElemInfo = nullptr; } bool JBCConstInvokeDynamic::PrepareFEStructElemInfo(const std::string &ownerClassName) { diff --git a/src/mplfe/jbc_input/src/jbc_stmt.cpp b/src/mplfe/jbc_input/src/jbc_stmt.cpp index 3d847f02a5cf38502a13fefad3ccdf5df7da044c..4cb3ea1ff9a27441b9321fc2789a6cc2c6313604 100644 --- a/src/mplfe/jbc_input/src/jbc_stmt.cpp +++ b/src/mplfe/jbc_input/src/jbc_stmt.cpp @@ -722,7 +722,7 @@ void JBCStmtInst::PrepareInvokeParametersAndReturn(JBCStack2FEHelper &stack2feHe FEIRStmtCallAssign &callStmt, bool isStatic) const { const std::vector &argTypes = info.GetArgTypes(); - for (int i = argTypes.size() - 1; i >= 0; --i) { + for (size_t i = argTypes.size(); i > 0; --i) { const UniqueFEIRType &argType = argTypes[static_cast(i)]; PrimType pty = argType->GetPrimType(); UniqueFEIRVar var = stack2feHelper.PopItem(JBCStack2FEHelper::SimplifyPrimType(pty)); diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0001-rt-arrayboundary-ABCOcatchArrayIndexOutOfBoundsException/ABCOcatchArrayIndexOutOfBoundsException.java b/test/testsuite/ouroboros/arrayboundary_test/RT0001-rt-arrayboundary-ABCOcatchArrayIndexOutOfBoundsException/ABCOcatchArrayIndexOutOfBoundsException.java new file mode 100755 index 0000000000000000000000000000000000000000..cb72135ec1fc7afe1789ddd47bc7faa59a06b064 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0001-rt-arrayboundary-ABCOcatchArrayIndexOutOfBoundsException/ABCOcatchArrayIndexOutOfBoundsException.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOcatchArrayIndexOutOfBoundsException.java + * -@TestCaseName: ArrayIndexOutOfBoundsException is throw + * -@TestCaseType: Function Test + * -@RequirementName: 编译优化,Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[1024], c = a[1024] + * -#step2: ArrayIndexOutOfBoundsException is throw + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOcatchArrayIndexOutOfBoundsException.java + * -@ExecuteClass: ABCOcatchArrayIndexOutOfBoundsException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOcatchArrayIndexOutOfBoundsException { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 2 /*STATUS_FAILED*/; + try { + func(); + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } catch (Exception e) { + res = res + 2; + } + return res; + } + + public static void func() throws Exception { + int[] a = new int[1024]; + int c = a[1024]; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0002-rt-arrayboundary-ABCOcatchIndexOutOfBoundsException/ABCOcatchIndexOutOfBoundsException.java b/test/testsuite/ouroboros/arrayboundary_test/RT0002-rt-arrayboundary-ABCOcatchIndexOutOfBoundsException/ABCOcatchIndexOutOfBoundsException.java new file mode 100755 index 0000000000000000000000000000000000000000..e39519de703bc2938efed3d2c4eebb2b26c4d271 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0002-rt-arrayboundary-ABCOcatchIndexOutOfBoundsException/ABCOcatchIndexOutOfBoundsException.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOcatchIndexOutOfBoundsException.java + * -@TestCaseName: IndexOutOfBoundsException is throw + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[1024], c = a[1024] + * -#step2: IndexOutOfBoundsException is throw + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOcatchIndexOutOfBoundsException.java + * -@ExecuteClass: ABCOcatchIndexOutOfBoundsException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOcatchIndexOutOfBoundsException { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 2 /*STATUS_FAILED*/; + try { + func(); + } catch (IndexOutOfBoundsException e) { + res--; + } catch (Exception e) { + res = res + 2; + } + return res; + } + + public static void func() throws Exception { + int[] a = new int[1024]; + int c = a[1024]; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0003-rt-arrayboundary-ABCOcatchStringIndexOutOfBoundsException/ABCOcatchStringIndexOutOfBoundsException.java b/test/testsuite/ouroboros/arrayboundary_test/RT0003-rt-arrayboundary-ABCOcatchStringIndexOutOfBoundsException/ABCOcatchStringIndexOutOfBoundsException.java new file mode 100755 index 0000000000000000000000000000000000000000..6d546cf3ceb7c3af57633360407a6f47a9897560 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0003-rt-arrayboundary-ABCOcatchStringIndexOutOfBoundsException/ABCOcatchStringIndexOutOfBoundsException.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOcatchStringIndexOutOfBoundsException.java + * -@TestCaseName: StringIndexOutOfBoundsException is throw + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new char[1024], change char[] to String. + * -#step2: call String.charAt(1024), StringIndexOutOfBoundsException is throw + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOcatchStringIndexOutOfBoundsException.java + * -@ExecuteClass: ABCOcatchStringIndexOutOfBoundsException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOcatchStringIndexOutOfBoundsException { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 2 /*STATUS_FAILED*/; + try { + func(); + } catch (StringIndexOutOfBoundsException e) { + res--; + } catch (Exception e) { + res = res + 2; + } + return res; + } + + public static void func() throws Exception { + char[] a = new char[1024]; + int index = 0; + for (int i = 0; i < a.length; i++) { + a[i] = 'a'; + index++; + } + String joinLine = a.toString(); + char c = joinLine.charAt(index); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0004-rt-arrayboundary-ABCOconstOperation/ABCOconstOperation.java b/test/testsuite/ouroboros/arrayboundary_test/RT0004-rt-arrayboundary-ABCOconstOperation/ABCOconstOperation.java new file mode 100755 index 0000000000000000000000000000000000000000..e7d29052fce7f7e678ec3b368e030470060d47d0 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0004-rt-arrayboundary-ABCOconstOperation/ABCOconstOperation.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOconstOperation.java + * -@TestCaseName: index is X, X = Y +/-/X///&/|/ Const + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: visit index is X, X = Y +/-/X///&/|/ Const, X is large than arr.length + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOconstOperation.java + * -@ExecuteClass: ABCOconstOperation + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOconstOperation { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 10 /*STATUS_FAILED*/; + int[] arr1 = new int[15]; + for (int i = 0; i < arr1.length; i++) { + arr1[i] = i; + } + int index = 1; + + int y = 6; + try { + index = index + y + 9; + int c = arr1[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + index = y - 16 - index; + int c = arr1[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + index = y * y * index; + int c = arr1[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + index = index + 937; + index = (y / index) * y; + int c = arr1[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + index = (y + 9) & 15; + int c = arr1[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + index = y | index; + int c = arr1[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + index = ~index; + int c = arr1[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + index = 15; + index = index ^ 16; + int c = arr1[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + index = index % 16; + int c = arr1[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0005-rt-arrayboundary-ABCOcustomClass/ABCOcustomClass.java b/test/testsuite/ouroboros/arrayboundary_test/RT0005-rt-arrayboundary-ABCOcustomClass/ABCOcustomClass.java new file mode 100755 index 0000000000000000000000000000000000000000..3a0c66edc049034ec8c03e7b1c05b158ea83e835 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0005-rt-arrayboundary-ABCOcustomClass/ABCOcustomClass.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOcustomClass.java + * -@TestCaseName: index and array is in same customClass, and another class call array[index]. + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: create customClass include index and arrays + * -#step2: get customClass.arrays[index], index is arrays.length + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOcustomClass.java + * -@ExecuteClass: ABCOcustomClass + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOcustomClass { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + People p = new People(3); + int x = p.n; + try { + Student a = p.s[x]; + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + return res; + } +} + +class People { + int n; + Student s[] = new Student[n]; + + public People(int n) { + this.n = n; + } +} + +class Student { + int number; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0006-rt-arrayboundary-ABCOdoWhile/ABCOdoWhile.java b/test/testsuite/ouroboros/arrayboundary_test/RT0006-rt-arrayboundary-ABCOdoWhile/ABCOdoWhile.java new file mode 100755 index 0000000000000000000000000000000000000000..aafb14c866dadd5b780f98b77196f4c7c39cb5cd --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0006-rt-arrayboundary-ABCOdoWhile/ABCOdoWhile.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOdoWhile.java + * -@TestCaseName: do while visit Array element + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: do while visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOdoWhile.java + * -@ExecuteClass: ABCOdoWhile + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOdoWhile { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + int[] c = new int[a.length]; + int x = 0; + int y = a.length; + try { + do { + c[x] = a[x]; + x++; + } while (x <= y); + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0007-rt-arrayboundary-ABCOemptyArray/ABCOemptyArray.java b/test/testsuite/ouroboros/arrayboundary_test/RT0007-rt-arrayboundary-ABCOemptyArray/ABCOemptyArray.java new file mode 100755 index 0000000000000000000000000000000000000000..c077d15572cfef35f8116f3071662d10405e3a6b --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0007-rt-arrayboundary-ABCOemptyArray/ABCOemptyArray.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOemptyArray.java + * -@TestCaseName: new Array[0] + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[0] + * -#step2: visit index of const, index is 0 and -1 + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOemptyArray.java + * -@ExecuteClass: ABCOemptyArray + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOemptyArray { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + int result2 = 4; + try { + result = test1(); + result2 = test2(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && result2 == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + Object[] a = new Object[0]; + try { + a[0] = new Object[0]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + Object c = a[-1]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } + + public static int test2() { + int res = 2 /*STATUS_FAILED*/; + String[] data; + try { + data = new String[] {}; // 初始化 + data[0] = "lisi"; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0008-rt-arrayboundary-ABCOemptyString/ABCOemptyString.java b/test/testsuite/ouroboros/arrayboundary_test/RT0008-rt-arrayboundary-ABCOemptyString/ABCOemptyString.java new file mode 100755 index 0000000000000000000000000000000000000000..514a83f7d40f13f1642d639ab38f4697a1239fa5 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0008-rt-arrayboundary-ABCOemptyString/ABCOemptyString.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOemptyString.java + * -@TestCaseName: String is "", index is 0 + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: String is "" or new String("") + * -#step2: index is 0, call charAt and codePointAt + * -#step3: catch Exception StringIndexOutOfBoundsException + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOemptyString.java + * -@ExecuteClass: ABCOemptyString + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOemptyString { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + + try { + String string = ""; + char c = string.charAt(0); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + String string = new String(""); + int c = string.codePointAt(0); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0009-rt-arrayboundary-ABCOfor/ABCOfor.java b/test/testsuite/ouroboros/arrayboundary_test/RT0009-rt-arrayboundary-ABCOfor/ABCOfor.java new file mode 100755 index 0000000000000000000000000000000000000000..03567bed69738fa3239fd7539467e37039453797 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0009-rt-arrayboundary-ABCOfor/ABCOfor.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOfor.java + * -@TestCaseName: for visit Array[index], index visit 0 to Array.length. + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: for visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOfor.java + * -@ExecuteClass: ABCOfor + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOfor { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[1024]; + int[] c = a; + for (int i = 0; i < a.length; i++) { + c[i] = i; + } + + int[] b = new int[a.length]; + try { + for (int i = 0; i <= a.length; i++) { + b[i] = a[i]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0010-rt-arrayboundary-ABCOglobalArray/ABCOglobalArray.java b/test/testsuite/ouroboros/arrayboundary_test/RT0010-rt-arrayboundary-ABCOglobalArray/ABCOglobalArray.java new file mode 100755 index 0000000000000000000000000000000000000000..cc8e7b1c50838bec2a9bcf685d2cf826a746e0a6 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0010-rt-arrayboundary-ABCOglobalArray/ABCOglobalArray.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOglobalArray.java + * -@TestCaseName: new Array[5] in global + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] in global + * -#step2: while visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOglobalArray.java + * -@ExecuteClass: ABCOglobalArray + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; + +public class ABCOglobalArray { + static int RES_PROCESS = 99; + static int[] a = new int[5]; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] b = new int[6]; + Arrays.fill(a, 9); + for (int i = 0; i <= a.length; i++) { + b[i] = i; + } + int[] c = new int[6]; + try { + for (int j = 0; j <= a.length; j++) { + int x = b[j]; + c[x] = a[x]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0011-rt-arrayboundary-ABCOglobalIndex/ABCOglobalIndex.java b/test/testsuite/ouroboros/arrayboundary_test/RT0011-rt-arrayboundary-ABCOglobalIndex/ABCOglobalIndex.java new file mode 100755 index 0000000000000000000000000000000000000000..fcf77b8a717a88b76de35ce719d02173a5fdc4cb --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0011-rt-arrayboundary-ABCOglobalIndex/ABCOglobalIndex.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOglobalIndex.java + * -@TestCaseName: Index in global + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5], Index in global + * -#step2: while visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOglobalIndex.java + * -@ExecuteClass: ABCOglobalIndex + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOglobalIndex { + static int RES_PROCESS = 99; + static int x = 0; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + + int[] a = new int[1024]; + int[] c = a; + for (int i = 0; i < a.length; i++) { + c[i] = i; + } + + int y = a.length; + try { + while (x < y) { + x = a[x + 1]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0012-rt-arrayboundary-ABCOglobalString/ABCOglobalString.java b/test/testsuite/ouroboros/arrayboundary_test/RT0012-rt-arrayboundary-ABCOglobalString/ABCOglobalString.java new file mode 100755 index 0000000000000000000000000000000000000000..4f2437838d1f093aaed13a9c016455cdda1283c8 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0012-rt-arrayboundary-ABCOglobalString/ABCOglobalString.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOglobalString.java + * -@TestCaseName: new Array[5] in global + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] in global + * -#step2: while visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOglobalString.java + * -@ExecuteClass: ABCOglobalString + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOglobalString { + static int RES_PROCESS = 99; + static String joinLine = new String(); + static int index = 0; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + char[] a = new char[1024]; + for (int i = 0; i < a.length; i++) { + a[i] = 'h'; + } + joinLine = a.toString(); + + char[] b = new char[joinLine.length()]; + try { + for (int j = 0; j <= joinLine.length(); j++) { + index = j; + b[index] = joinLine.charAt(index); + } + } catch (StringIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0013-rt-arrayboundary-ABCOif/ABCOif.java b/test/testsuite/ouroboros/arrayboundary_test/RT0013-rt-arrayboundary-ABCOif/ABCOif.java new file mode 100755 index 0000000000000000000000000000000000000000..439daa428b17dd63e9e88553f9b8d7b0f9d5f113 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0013-rt-arrayboundary-ABCOif/ABCOif.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOif.java + * -@TestCaseName: if visit Array + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: if visit Array + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOif.java + * -@ExecuteClass: ABCOif + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOif { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] arr = new int[5]; + int[] arrCp = arr; + for (int i = 0; i < arr.length; i++) { + arrCp[i] = i; + } + + int y = arr.length; + try { + if (y >= 0) { + int c = arr[y]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0014-rt-arrayboundary-ABCOincreaseArray/ABCOincreaseArray.java b/test/testsuite/ouroboros/arrayboundary_test/RT0014-rt-arrayboundary-ABCOincreaseArray/ABCOincreaseArray.java new file mode 100755 index 0000000000000000000000000000000000000000..befaa9268cf87035aa9ac88671a2634e3c46572f --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0014-rt-arrayboundary-ABCOincreaseArray/ABCOincreaseArray.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOincreaseArray.java + * -@TestCaseName: Array is increase length + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[10] a, use System.arraycopy to create new Array[20] newArray + * -#step2: visit a[9], no exception throw + * -#step3: visit newArray[20], catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOincreaseArray.java + * -@ExecuteClass: ABCOincreaseArray + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Array; +import java.util.Arrays; + +public class ABCOincreaseArray { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 2 /*STATUS_FAILED*/; + int[] a = new int[10]; + Arrays.fill(a, 20); + int[] newArray = (int[]) func(a); + int index = newArray[0]; + + try { + int c = a[index - 11]; + } catch (ArrayIndexOutOfBoundsException e) { + res = 5; + } + + try { + int c = newArray[index]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + return res; + } + + public static Object func(Object array) { + Class clazz = array.getClass(); + if (clazz.isArray()) { + Class componentType = clazz.getComponentType(); + int length = Array.getLength(array); + Object newArray = Array.newInstance(componentType, length + 10); + System.arraycopy(array, 0, newArray, 0, length); + return newArray; + } + return null; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0015-rt-arrayboundary-ABCOindexAssociation/ABCOindexAssociation.java b/test/testsuite/ouroboros/arrayboundary_test/RT0015-rt-arrayboundary-ABCOindexAssociation/ABCOindexAssociation.java new file mode 100755 index 0000000000000000000000000000000000000000..723ffaa07d6efa30c5bc33ffab68ca58115a6f23 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0015-rt-arrayboundary-ABCOindexAssociation/ABCOindexAssociation.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOindexAssociation.java + * -@TestCaseName: for visit Array[index], index visit 0 to Array.length. + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] a, make c = a + * -#step2: for visit Array element, give index (0~length) to a + * -#step3: catch Exception + * -#step4: new Array[5] a, make c = a + * -#step5: for visit Array element, give index (0~length-1) to a + * -#step6: for visit Array element, give a[index] to index + * -#step7: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOindexAssociation.java + * -@ExecuteClass: ABCOindexAssociation + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOindexAssociation { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + int result2 = 4; + try { + result = test1(); + result2 = test2(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && result2 == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + int[] c = a; + + try { + for (int i = 0; i <= a.length; i++) { + c[i] = i; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int test2() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + int[] c = a; + for (int i = 0; i < a.length; i++) { + c[i] = i; + } + + try { + for (int j = 1; j <= a.length; j++) { + if (a[j] > a[j - 1]) { + j = a[j]; + } + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0016-rt-arrayboundary-ABCOindexDoWhile/ABCOindexDoWhile.java b/test/testsuite/ouroboros/arrayboundary_test/RT0016-rt-arrayboundary-ABCOindexDoWhile/ABCOindexDoWhile.java new file mode 100755 index 0000000000000000000000000000000000000000..c75fd1e99c5a2247486cad4043043f6f8fc48278 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0016-rt-arrayboundary-ABCOindexDoWhile/ABCOindexDoWhile.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOindexDoWhile.java + * -@TestCaseName: do while visit Array index + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: do while visit Array index + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOindexDoWhile.java + * -@ExecuteClass: ABCOindexDoWhile + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOindexDoWhile { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + // catch ArrayIndexOutOfBoundsException + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[1000]; + int[] c = a; + for (int i = 0; i < a.length; i++) { + c[i] = i; + } + + int[] b = new int[a.length]; + int x = funx(100); + int y = funx(1000); + try { + do { + b[x] = a[x]; + x++; + } while (x <= y); + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int funx(int maxFlag) { + int endIndex = maxFlag + 5; + int index = 0; + do { + index = funy(index); + } while (index < endIndex); + return index; + } + + public static int funy(int forIdx) { + int idx = forIdx + 100; + return idx; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0017-rt-arrayboundary-ABCOindexFor/ABCOindexFor.java b/test/testsuite/ouroboros/arrayboundary_test/RT0017-rt-arrayboundary-ABCOindexFor/ABCOindexFor.java new file mode 100755 index 0000000000000000000000000000000000000000..e32482827965f5f263fad1ebe9149a0fa1576983 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0017-rt-arrayboundary-ABCOindexFor/ABCOindexFor.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOindexFor.java + * -@TestCaseName: for visit Array[index], index visit 0 to Array.length. + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: for visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOindexFor.java + * -@ExecuteClass: ABCOindexFor + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOindexFor { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[1000]; + int[] c = a; + for (int ii = 0; ii < a.length; ii++) { + c[ii] = ii; + } + + int[] b = new int[a.length]; + try { + for (int i = funx(100); i <= funx(1000); i++) { + if (i >= 1000) { + for (int j = i; j > 0; j--) { + int index = funx(1000); + b[index] = a[index]; + } + } + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int funx(int maxFlag) { + int endIndex = maxFlag + 5; + int index; + + for (index = 0; index <= endIndex; index++) { + index = funy(index); + } + + return index; + } + + public static int funy(int forIdx) { + int idx = forIdx + 100; + return idx; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0018-rt-arrayboundary-ABCOindexFromArrayFromParam/ABCOindexFromArrayFromParam.java b/test/testsuite/ouroboros/arrayboundary_test/RT0018-rt-arrayboundary-ABCOindexFromArrayFromParam/ABCOindexFromArrayFromParam.java new file mode 100755 index 0000000000000000000000000000000000000000..2ef4eede936afdd955b6b74c4621374e94f73a86 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0018-rt-arrayboundary-ABCOindexFromArrayFromParam/ABCOindexFromArrayFromParam.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOindexFromArrayFromParam.java + * -@TestCaseName: index From Array element, element From Param + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: while visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOindexFromArrayFromParam.java + * -@ExecuteClass: ABCOindexFromArrayFromParam + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOindexFromArrayFromParam { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + int num = 5; + result = test1(num); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1(int num) { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + a[4] = num; + int[] c = a.clone(); + int x = c[4]; + try { + int b = a[x]; + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0019-rt-arrayboundary-ABCOindexIf/ABCOindexIf.java b/test/testsuite/ouroboros/arrayboundary_test/RT0019-rt-arrayboundary-ABCOindexIf/ABCOindexIf.java new file mode 100755 index 0000000000000000000000000000000000000000..32624028ce0cd50d7ae5643ff6500fae2d461cee --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0019-rt-arrayboundary-ABCOindexIf/ABCOindexIf.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOindexIf.java + * -@TestCaseName: if visit Array + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: if visit Array + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOindexIf.java + * -@ExecuteClass: ABCOindexIf + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Random; + +public class ABCOindexIf { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] arr = new int[5]; + int[] arrCp = arr; + for (int i = 0; i < arr.length; i++) { + arrCp[i] = i; + } + + int y = func(); + try { + if (y >= 0) { + int c = arr[y]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int func() { + Random r = new Random(); + int get = r.nextInt(6); + if (get >= 5) { + return get; + } else { + get = func(); + return get; + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0020-rt-arrayboundary-ABCOindexMutiLoop/ABCOindexMutiLoop.java b/test/testsuite/ouroboros/arrayboundary_test/RT0020-rt-arrayboundary-ABCOindexMutiLoop/ABCOindexMutiLoop.java new file mode 100755 index 0000000000000000000000000000000000000000..a6c4f6902a860dcb2e0b995307839994b8e8c3d7 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0020-rt-arrayboundary-ABCOindexMutiLoop/ABCOindexMutiLoop.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOindexMutiLoop.java + * -@TestCaseName: index from multi-layer loop + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: visit index of multi-layer loop + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOindexMutiLoop.java + * -@ExecuteClass: ABCOindexMutiLoop + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; + +public class ABCOindexMutiLoop { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 2 /*STATUS_FAILED*/; + int[] a = new int[5]; + Arrays.fill(a, 8000); + + int x; + try { + x = func(); + int c = a[x]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + return res; + } + + public static int func() { + int index = 0; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + for (int k = 0; k < 5; k++) { + for (int ii = 0; ii < 5; ii++) { + for (int jj = 0; jj < 5; jj++) { + for (int kk = 0; kk < 5; kk++) { + for (int iii = 0; iii < 5; iii++) { + for (int jjj = 0; jjj < 5; jjj++) { + for (int kkk = 0; kkk < 5; kkk++) { + for (int n = 0; n < 5; n++) { + index = index + n; + } + } + } + } + } + } + } + } + } + } + return index; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0021-rt-arrayboundary-ABCOindexNesting/ABCOindexNesting.java b/test/testsuite/ouroboros/arrayboundary_test/RT0021-rt-arrayboundary-ABCOindexNesting/ABCOindexNesting.java new file mode 100755 index 0000000000000000000000000000000000000000..e825e6be2201495725c61a303f7767fe23273393 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0021-rt-arrayboundary-ABCOindexNesting/ABCOindexNesting.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOindexNesting.java + * -@TestCaseName: give nesting fun to index + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[1023] a, make c = a, visit Array element, give index (0~length) to c + * -#step2: for visit Array index j, nestint func, funx, funy,funw to give value to index + * -#step3: let j = a[index], when j > a.length, will catch ArrayIndexOutOfBoundsException + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOindexNesting.java + * -@ExecuteClass: ABCOindexNesting + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOindexNesting { + static int RES_PROCESS = 99; + static int arrNum = 1023; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[arrNum]; + int[] c = a; + for (int i = 0; i < a.length; i++) { + c[i] = i; + } + + int index = 0; + try { + for (int j = 1; j <= a.length; j++) { + if (j == a.length) { + index = func(j, index); + j = a[index]; + } + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + return res; + } + + public static int func(int index, int getIndex) { + getIndex = funx(getIndex, index); + getIndex = getIndex + 10; + if (getIndex < index) { + getIndex = func(index, getIndex); + } + return getIndex; + } + + public static int funx(int getIndex, int index) { + getIndex = getIndex + index; + getIndex = funy(getIndex, index); + return getIndex; + } + + public static int funy(int getIndex, int index) { + getIndex = getIndex * index; + getIndex = funz(getIndex, index); + return getIndex; + } + + public static int funz(int getIndex, int index) { + getIndex = getIndex / index; + getIndex = funw(getIndex, index); + return getIndex; + } + + public static int funw(int getIndex, int index) { + getIndex = getIndex - index; + return getIndex; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0022-rt-arrayboundary-ABCOindexSwitch/ABCOindexSwitch.java b/test/testsuite/ouroboros/arrayboundary_test/RT0022-rt-arrayboundary-ABCOindexSwitch/ABCOindexSwitch.java new file mode 100755 index 0000000000000000000000000000000000000000..84ac19aacaecde0a66f4447b397bee5cad46996c --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0022-rt-arrayboundary-ABCOindexSwitch/ABCOindexSwitch.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOindexSwitch.java + * -@TestCaseName: switch visit index + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: switch visit Array index + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOindexSwitch.java + * -@ExecuteClass: ABCOindexSwitch + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Random; + +public class ABCOindexSwitch { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + int[] arrCp = a; + for (int i = 0; i < a.length; i++) { + arrCp[i] = i; + } + + int c; + int x = func(); + try { + c = a[x]; + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int func() { + Random r = new Random(); + int getI = r.nextInt(3); + int y = getI % 3; + getI = getI + 5; + switch (y) { + case 0: + getI = getI + 0; + break; + case 1: + getI = getI + 1; + break; + default: + getI = getI + 2; + } + return getI; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0023-rt-arrayboundary-ABCOlength/ABCOlength.java b/test/testsuite/ouroboros/arrayboundary_test/RT0023-rt-arrayboundary-ABCOlength/ABCOlength.java new file mode 100755 index 0000000000000000000000000000000000000000..2519926c2fe701d73285e4aeffae0549b4fee6be --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0023-rt-arrayboundary-ABCOlength/ABCOlength.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOlength.java + * -@TestCaseName: index is X, X is arrays.length + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: visit index of arrays.length + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOlength.java + * -@ExecuteClass: ABCOlength + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOlength { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 2 /*STATUS_FAILED*/; + int[] a = new int[5]; + try { + int b = a.length; + int c = a[b]; + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0024-rt-arrayboundary-ABCOlistToArray/ABCOlistToArray.java b/test/testsuite/ouroboros/arrayboundary_test/RT0024-rt-arrayboundary-ABCOlistToArray/ABCOlistToArray.java new file mode 100755 index 0000000000000000000000000000000000000000..e1a11c027a1a107348007b27429d16fda977ee37 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0024-rt-arrayboundary-ABCOlistToArray/ABCOlistToArray.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOlistToArray.java + * -@TestCaseName: index from Integer.parseInt, Array from list.toArray + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array, Array from list.toArray + * -#step2: index from Integer.parseInt + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOlistToArray.java + * -@ExecuteClass: ABCOlistToArray + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.List; + +public class ABCOlistToArray { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + String[] a = func(); + int x = -1; + try { + String c = a[x]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + x = Integer.parseInt(a[a.length - 1]); + try { + String c = a[x]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } + + public static String[] func() { + List list = new ArrayList<>(); + list.add("1"); + list.add("2"); + list.add("3"); + list.add("4"); + list.add("5"); + String[] arr = new String[list.size()]; + try { + list.toArray(arr); + } catch (Exception e) { + e.printStackTrace(); + } + + return arr; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0025-rt-arrayboundary-ABCOlocalArray/ABCOlocalArray.java b/test/testsuite/ouroboros/arrayboundary_test/RT0025-rt-arrayboundary-ABCOlocalArray/ABCOlocalArray.java new file mode 100755 index 0000000000000000000000000000000000000000..574ad0d486b756c58eca5634be0756abe21e76f2 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0025-rt-arrayboundary-ABCOlocalArray/ABCOlocalArray.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOlocalArray.java + * -@TestCaseName: new Array[5] in local variable + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] in local variable + * -#step2: while visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOlocalArray.java + * -@ExecuteClass: ABCOlocalArray + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOlocalArray { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[][] arr = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}, {0}}; + + int y = arr.length - 1; + try { + int c = arr[-1][y]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + int c = arr[y][1]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0026-rt-arrayboundary-ABCOlocalIndex/ABCOlocalIndex.java b/test/testsuite/ouroboros/arrayboundary_test/RT0026-rt-arrayboundary-ABCOlocalIndex/ABCOlocalIndex.java new file mode 100755 index 0000000000000000000000000000000000000000..2c459babe4c6eeb2c83a66e35e959091deb9166c --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0026-rt-arrayboundary-ABCOlocalIndex/ABCOlocalIndex.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOlocalIndex.java + * -@TestCaseName: Index in local variable + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] and index in local variable + * -#step2: while visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOlocalIndex.java + * -@ExecuteClass: ABCOlocalIndex + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOlocalIndex { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[][] arr = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}, {0}}; + + int y = func(); + try { + int c = arr[0][y]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + int c = arr[y][0]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } + + public static int func() { + int getRand = 0; + for (int i = 0; i < 100; i++) { + getRand = getRand + i; + if (getRand > 100) { + break; + } + } + getRand = getRand + 4; + return getRand; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0027-rt-arrayboundary-ABCOnewArraySize/ABCOnewArraySize.java b/test/testsuite/ouroboros/arrayboundary_test/RT0027-rt-arrayboundary-ABCOnewArraySize/ABCOnewArraySize.java new file mode 100755 index 0000000000000000000000000000000000000000..4eb81d5ad9c45d5586cc7debe1c71d490dd3bcab --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0027-rt-arrayboundary-ABCOnewArraySize/ABCOnewArraySize.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOnewArraySize.java + * -@TestCaseName: index is X, X is Array[size] + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: visit index of new Array[size] + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOnewArraySize.java + * -@ExecuteClass: ABCOnewArraySize + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOnewArraySize { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + int[] d = {0, 1, -1, 5}; + try { + int b = d[2]; + int c = a[b]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + try { + int b = d[3]; + int c = a[b]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0028-rt-arrayboundary-ABCOnormal/ABCOnormal.java b/test/testsuite/ouroboros/arrayboundary_test/RT0028-rt-arrayboundary-ABCOnormal/ABCOnormal.java new file mode 100755 index 0000000000000000000000000000000000000000..10cf911652de8c0cadddfb80c1342d9e2f2af2c1 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0028-rt-arrayboundary-ABCOnormal/ABCOnormal.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOnormal.java + * -@TestCaseName: index is constant + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: visit index of const + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOnormal.java + * -@ExecuteClass: ABCOnormal + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOnormal { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + try { + int c = a[-1]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + try { + int c = a[6]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0029-rt-arrayboundary-ABCOparamIndex/ABCOparamIndex.java b/test/testsuite/ouroboros/arrayboundary_test/RT0029-rt-arrayboundary-ABCOparamIndex/ABCOparamIndex.java new file mode 100755 index 0000000000000000000000000000000000000000..1723269622e638c293c7506427e1e1cd5fe2db99 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0029-rt-arrayboundary-ABCOparamIndex/ABCOparamIndex.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOparamIndex.java + * -@TestCaseName: Array is get by function param + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5], Array is get by function param + * -#step2: if visit Array + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOparamIndex.java + * -@ExecuteClass: ABCOparamIndex + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOparamIndex { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + int[] a = new int[5]; + int[] c = a; + for (int i = 0; i < a.length; i++) { + c[i] = i + 1; + } + int y = c[4]; + result = test1(a, y); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1(int[] arr, int index) { + int res = 3 /*STATUS_FAILED*/; + + try { + if (index >= 0) { + int c = arr[index]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0030-rt-arrayboundary-ABCOparam/ABCOparam.java b/test/testsuite/ouroboros/arrayboundary_test/RT0030-rt-arrayboundary-ABCOparam/ABCOparam.java new file mode 100755 index 0000000000000000000000000000000000000000..9fe7e9c41ab2fa1cc18c4bef9556e57490d61825 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0030-rt-arrayboundary-ABCOparam/ABCOparam.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOparam.java + * -@TestCaseName: Array is get by function param + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5], Array is get by function param + * -#step2: if visit Array + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOparam.java + * -@ExecuteClass: ABCOparam + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOparam { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + int[] arr = new int[5]; + result = test1(arr); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1(int[] arr) { + int res = 3 /*STATUS_FAILED*/; + + int y = arr.length; + try { + if (y >= 0) { + int c = arr[y]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0031-rt-arrayboundary-ABCOreflectArray/ABCOreflectArray.java b/test/testsuite/ouroboros/arrayboundary_test/RT0031-rt-arrayboundary-ABCOreflectArray/ABCOreflectArray.java new file mode 100755 index 0000000000000000000000000000000000000000..904786a71cec2c8bfa0fd8ba3c1e7250fa6d44b7 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0031-rt-arrayboundary-ABCOreflectArray/ABCOreflectArray.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOreflectArray.java + * -@TestCaseName: index is from Array.get + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: index is from Array.get, call Array.get and Array.set + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOreflectArray.java + * -@ExecuteClass: ABCOreflectArray + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Array; + +public class ABCOreflectArray { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + Array.setInt(a, 4, 5); + int x = (int) Array.get(a, 4); + try { + int c = (int) Array.get(a, x); + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + + try { + Array.setInt(a, x, 5); + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0032-rt-arrayboundary-ABCOreturnArray/ABCOreturnArray.java b/test/testsuite/ouroboros/arrayboundary_test/RT0032-rt-arrayboundary-ABCOreturnArray/ABCOreturnArray.java new file mode 100755 index 0000000000000000000000000000000000000000..d5ef0357f363ae1e16696932f0e5273eadae9dfd --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0032-rt-arrayboundary-ABCOreturnArray/ABCOreturnArray.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOreturnArray.java + * -@TestCaseName: Array is get by function return + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5], Array is get by function return + * -#step2: if visit Array + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOreturnArray.java + * -@ExecuteClass: ABCOreturnArray + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOreturnArray { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int[] func() { + int[] arr = new int[5]; + return arr; + } + + public static int test1() { + int[] arr = func(); + int res = 3 /*STATUS_FAILED*/; + + int y = arr.length; + try { + if (y >= 0) { + int c = arr[y]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0033-rt-arrayboundary-ABCOreturnIndex/ABCOreturnIndex.java b/test/testsuite/ouroboros/arrayboundary_test/RT0033-rt-arrayboundary-ABCOreturnIndex/ABCOreturnIndex.java new file mode 100755 index 0000000000000000000000000000000000000000..a6a1d1500e172960c190c72bdfcac5464d80b41c --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0033-rt-arrayboundary-ABCOreturnIndex/ABCOreturnIndex.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOreturnIndex.java + * -@TestCaseName: Array is get by function return, Index is get by function return + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5], Array is get by function return, Index is get by function return + * -#step2: if visit Array + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOreturnIndex.java + * -@ExecuteClass: ABCOreturnIndex + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOreturnIndex { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int func() { + int getRand = 0; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 10; k++) { + getRand = getRand + k; + if (getRand > 200) { + break; + } + } + } + } + return getRand; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + + int[] arr = new int[100]; + int[] arrCopy = arr; + for (int i = 0; i < arr.length; i++) { + arrCopy[i] = i; + } + + int y = func(); + try { + if (y >= 0) { + int c = arr[y]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0034-rt-arrayboundary-ABCOreturnString/ABCOreturnString.java b/test/testsuite/ouroboros/arrayboundary_test/RT0034-rt-arrayboundary-ABCOreturnString/ABCOreturnString.java new file mode 100755 index 0000000000000000000000000000000000000000..a558ff063667b0758412fc7763795c00e864f250 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0034-rt-arrayboundary-ABCOreturnString/ABCOreturnString.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOreturnString.java + * -@TestCaseName: Array is get by function return, Index is get by function return + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new String, String and index is get by function return value + * -#step2: if visit String, index >= length + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOreturnString.java + * -@ExecuteClass: ABCOreturnString + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; + +public class ABCOreturnString { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + + String joinLine = funx(); + int y = func(); + try { + if (y >= 0) { + char c = joinLine.charAt(y); + } + } catch (StringIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int func() { + int getRand = 0; + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 10; k++) { + getRand = getRand + k; + if (getRand > 300) { + break; + } + } + } + } + return getRand; + } + + public static String funx() { + char[] a = new char[100]; + for (int i = 0; i < a.length; i++) { + a[i] = 'h'; + } + String joinLine = Arrays.toString(a); + return joinLine; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0035-rt-arrayboundary-ABCOStringBuilderCatchEx/ABCOStringBuilderCatchEx.java b/test/testsuite/ouroboros/arrayboundary_test/RT0035-rt-arrayboundary-ABCOStringBuilderCatchEx/ABCOStringBuilderCatchEx.java new file mode 100755 index 0000000000000000000000000000000000000000..01e68711ab190ad6b00e6aebeaa31f1031b87ad1 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0035-rt-arrayboundary-ABCOStringBuilderCatchEx/ABCOStringBuilderCatchEx.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOStringBuilderCatchEx.java + * -@TestCaseName: StringIndexOutOfBoundsException is throw by StringBuilder toString + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new StringBuilder(). + * -#step2: call StringBuilder.toString().substring(), StringIndexOutOfBoundsException is throw + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOStringBuilderCatchEx.java + * -@ExecuteClass: ABCOStringBuilderCatchEx + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.List; + +public class ABCOStringBuilderCatchEx { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 2 /*STATUS_FAILED*/; + try { + func(); + } catch (StringIndexOutOfBoundsException e) { + res--; + } catch (Exception e) { + res = res + 2; + } + return res; + } + + public static void func() throws Exception { + StringBuilder sbu = new StringBuilder(); + List lii = new ArrayList<>(); + lii.add("welcome"); + lii.add("to"); + lii.add("hang"); + lii.add("zhou"); + lii.add("huawei"); + lii.add("company"); + for (String str : lii) { + sbu.append(str).append(","); + } + int endIndex = (sbu.toString()).length() + 1; + String getStr = sbu.toString().substring(0, endIndex); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0036-rt-arrayboundary-ABCOStringConstOperation/ABCOStringConstOperation.java b/test/testsuite/ouroboros/arrayboundary_test/RT0036-rt-arrayboundary-ABCOStringConstOperation/ABCOStringConstOperation.java new file mode 100755 index 0000000000000000000000000000000000000000..3929ebf2eef7b4411affe57c3b8647d118a503ba --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0036-rt-arrayboundary-ABCOStringConstOperation/ABCOStringConstOperation.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOStringConstOperation.java + * -@TestCaseName: index is X, X = Y +/-/X///&/|/ Const + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new char[1024], change char[] to String. + * -#step2: visit index is X, X = Y +/-/X///&/|/ Const, X is large than length + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOStringConstOperation.java + * -@ExecuteClass: ABCOStringConstOperation + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; + +public class ABCOStringConstOperation { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 10 /*STATUS_FAILED*/; + byte[] a = new byte[1024]; + for (int i = 0; i < a.length; i++) { + a[i] = '1'; + } + String joinLine = Arrays.toString(a); + + int index = 1; + int y = joinLine.length(); + try { + index = index + y + 9; + String c = joinLine.substring(index); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + index = y - joinLine.length() - index; + String c = joinLine.substring(index); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + index = y * y * index; + String c = joinLine.substring(index); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + index = index + 167772161; + index = (y / index) * y; + String c = joinLine.substring(index); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + index = index & index; + String c = joinLine.substring(index); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + index = y | index; + String c = joinLine.substring(index); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + index = ~index; + String c = joinLine.substring(index); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + index = y + y; + index = index ^ y; + String c = joinLine.substring(index); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + index = index + index; + y = 8195; + index = index % y; + String c = joinLine.substring(index); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0037-rt-arrayboundary-ABCOstringDoWhile/ABCOstringDoWhile.java b/test/testsuite/ouroboros/arrayboundary_test/RT0037-rt-arrayboundary-ABCOstringDoWhile/ABCOstringDoWhile.java new file mode 100755 index 0000000000000000000000000000000000000000..dc0e6eb6c61fc44bda6126371182053e7bc38c95 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0037-rt-arrayboundary-ABCOstringDoWhile/ABCOstringDoWhile.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOstringDoWhile.java + * -@TestCaseName: do while visit String element and index from do while + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: String a is copy of String b + * -#step2: do while visit String element and index from do while + * -#step3: when index is large than length, catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOstringDoWhile.java + * -@ExecuteClass: ABCOstringDoWhile + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOstringDoWhile { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + String aCp = new String(); + int x = 0; + do { + aCp = aCp + "hashl@^&@&2894684"; + x++; + } while (x <= 9999); + String a = aCp; + + x = funx(1000); + int y = funx(170000); + try { + do { + char c = a.charAt(x); + x++; + } while (x <= y); + } catch (StringIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int funx(int maxFlag) { + int endIndex = maxFlag + 5; + int index = 0; + do { + index = funy(index); + } while (index < endIndex); + return index; + } + + public static int funy(int forIdx) { + int idx = forIdx + 100; + return idx; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0038-rt-arrayboundary-ABCOstringFor/ABCOstringFor.java b/test/testsuite/ouroboros/arrayboundary_test/RT0038-rt-arrayboundary-ABCOstringFor/ABCOstringFor.java new file mode 100755 index 0000000000000000000000000000000000000000..7eec206beebffec49bb45c6a3aaa620a64536343 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0038-rt-arrayboundary-ABCOstringFor/ABCOstringFor.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOstringFor.java + * -@TestCaseName: for visit String.charAt[index], index visit 0 to length. + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: for visit String element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOstringFor.java + * -@ExecuteClass: ABCOstringFor + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; + +public class ABCOstringFor { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + char[] a = new char[1024]; + for (int i = 0; i < a.length; i++) { + a[i] = 'h'; + } + String joinLine = Arrays.toString(a); + + char[] b = new char[joinLine.length()]; + try { + for (int i = 0; i <= joinLine.length(); i++) { + int index = funx(i); + b[index] = joinLine.charAt(index); + } + } catch (StringIndexOutOfBoundsException e) { + res = 1; + } + return res; + } + + public static int funx(int maxFlag) { + int endIndex = maxFlag + 5; + int index; + + for (index = 0; index <= endIndex; index++) { + index = funy(index); + } + + return index; + } + + public static int funy(int forIdx) { + int idx = forIdx + 100; + return idx; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0039-rt-arrayboundary-ABCOstringIf/ABCOstringIf.java b/test/testsuite/ouroboros/arrayboundary_test/RT0039-rt-arrayboundary-ABCOstringIf/ABCOstringIf.java new file mode 100755 index 0000000000000000000000000000000000000000..0b8d807564044682230b25e43c29cc422a5e5abb --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0039-rt-arrayboundary-ABCOstringIf/ABCOstringIf.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOstringIf.java + * -@TestCaseName: if visit String + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new String + * -#step2: if visit String, index = String.length() + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOstringIf.java + * -@ExecuteClass: ABCOstringIf + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Random; + +public class ABCOstringIf { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + int result2 = 4; + try { + result = test1(); + result2 = test2(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && result2 == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + char[] a = new char[1024]; + for (int i = 0; i < a.length; i++) { + a[i] = 'h'; + } + String joinLine = Arrays.toString(a); + + int y = func(); + try { + if (y >= 0) { + char c = joinLine.charAt(y); + ; + } + } catch (StringIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int test2() { + int res = 3 /*STATUS_FAILED*/; + char[] a = new char[1024]; + for (int i = 0; i < a.length; i++) { + a[i] = 'h'; + } + String joinLine = Arrays.toString(a); + + try { + for (int i = 0; i < joinLine.length(); i++) { + if (joinLine.charAt(i) == joinLine.charAt(i + 1)) { + char c = joinLine.charAt(i); + } + } + } catch (StringIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int func() { + Random r = new Random(); + int get = r.nextInt(6); + if (get >= 5) { + return get + 3072; + } else { + return get + 3072; + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0040-rt-arrayboundary-ABCOstringIndexNesting/ABCOstringIndexNesting.java b/test/testsuite/ouroboros/arrayboundary_test/RT0040-rt-arrayboundary-ABCOstringIndexNesting/ABCOstringIndexNesting.java new file mode 100755 index 0000000000000000000000000000000000000000..a29e808bd1e5a56aeae7fa4fd36cf864b7ac039f --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0040-rt-arrayboundary-ABCOstringIndexNesting/ABCOstringIndexNesting.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOstringIndexNesting.java + * -@TestCaseName: give nesting fun to String index + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new char[1024], change char[] to String + * -#step2: for visit index, nestint func, funx, funy,funw to give value to index + * -#step3: let char c = joinLine.charAt(index), when index > a.length, will catch ArrayIndexOutOfBoundsException + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOstringIndexNesting.java + * -@ExecuteClass: ABCOstringIndexNesting + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; + +public class ABCOstringIndexNesting { + static int RES_PROCESS = 99; + static int arrNum = 1023; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + char[] a = new char[1024]; + for (int i = 0; i < a.length; i++) { + a[i] = 'w'; + } + String joinLine = Arrays.toString(a); + + int index = 0; + try { + for (int j = 1; j <= joinLine.length(); j++) { + if (j == joinLine.length()) { + index = func(j, index); + char c = joinLine.charAt(index); + } + } + } catch (StringIndexOutOfBoundsException e) { + res = 1; + } + return res; + } + + public static int func(int index, int getIndex) { + getIndex = funx(getIndex, index); + getIndex = getIndex + 10; + if (getIndex < index) { + getIndex = func(index, getIndex); + } + return getIndex; + } + + public static int funx(int getIndex, int index) { + getIndex = getIndex + index; + getIndex = funy(getIndex, index); + return getIndex; + } + + public static int funy(int getIndex, int index) { + getIndex = getIndex * index; + getIndex = funz(getIndex, index); + return getIndex; + } + + public static int funz(int getIndex, int index) { + getIndex = getIndex / index; + getIndex = funw(getIndex, index); + return getIndex; + } + + public static int funw(int getIndex, int index) { + getIndex = getIndex - index; + return getIndex; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0041-rt-arrayboundary-ABCOStringMaxValue/ABCOStringMaxValue.java b/test/testsuite/ouroboros/arrayboundary_test/RT0041-rt-arrayboundary-ABCOStringMaxValue/ABCOStringMaxValue.java new file mode 100755 index 0000000000000000000000000000000000000000..0e512fe977e643acd6ea49444298179d377cf91a --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0041-rt-arrayboundary-ABCOStringMaxValue/ABCOStringMaxValue.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOStringMaxValue.java + * -@TestCaseName: index is MAX_VALUE or MIN_VALUE + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new char[1024], change char[] to String. + * -#step2: visit index of MAX_VALUE or MIN_VALUE const, use codePointCount + * -#step3: catch Exception IndexOutOfBoundsException + * -#step4: visit index of MAX_VALUE or MIN_VALUE const, use charAt + * -#step5: catch Exception StringIndexOutOfBoundsException + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOStringMaxValue.java + * -@ExecuteClass: ABCOStringMaxValue + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; + +public class ABCOStringMaxValue { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 5 /*STATUS_FAILED*/; + + char[] a = new char[1024]; + for (int i = 0; i < a.length; i++) { + a[i] = 'h'; + } + String joinLine = Arrays.toString(a); + + int max = Integer.MAX_VALUE; + int min = Integer.MIN_VALUE; + try { + int c = joinLine.codePointCount(min, 2); + } catch (IndexOutOfBoundsException e) { + res--; + } + + try { + char c = joinLine.charAt(min); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + try { + int c = joinLine.codePointCount(0, max); + } catch (IndexOutOfBoundsException e) { + res--; + } + + try { + char c = joinLine.charAt(max); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0042-rt-arrayboundary-ABCOstringMutiLoop/ABCOstringMutiLoop.java b/test/testsuite/ouroboros/arrayboundary_test/RT0042-rt-arrayboundary-ABCOstringMutiLoop/ABCOstringMutiLoop.java new file mode 100755 index 0000000000000000000000000000000000000000..ea4487a42cd1dabeb2d40358438667f693929f97 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0042-rt-arrayboundary-ABCOstringMutiLoop/ABCOstringMutiLoop.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOstringMutiLoop.java + * -@TestCaseName: index from multi-layer loop + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new String[8000] + * -#step2: visit index of multi-layer loop + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOstringMutiLoop.java + * -@ExecuteClass: ABCOstringMutiLoop + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; + +public class ABCOstringMutiLoop { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 2 /*STATUS_FAILED*/; + + char[] a = new char[8000]; + for (int i = 0; i < a.length; i++) { + a[i] = 'h'; + } + String joinLine = Arrays.toString(a); + + int x; + try { + x = func(); + char c = joinLine.charAt(x); + } catch (StringIndexOutOfBoundsException e) { + res--; + } + + return res; + } + + public static int func() { + int index = 0; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + for (int k = 0; k < 5; k++) { + for (int ii = 0; ii < 5; ii++) { + for (int jj = 0; jj < 5; jj++) { + for (int kk = 0; kk < 5; kk++) { + for (int iii = 0; iii < 5; iii++) { + for (int jjj = 0; jjj < 5; jjj++) { + for (int kkk = 0; kkk < 5; kkk++) { + for (int n = 0; n < 5; n++) { + index = index + n; + } + } + } + } + } + } + } + } + } + } + return index; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0043-rt-arrayboundary-ABCOstringSwitch/ABCOstringSwitch.java b/test/testsuite/ouroboros/arrayboundary_test/RT0043-rt-arrayboundary-ABCOstringSwitch/ABCOstringSwitch.java new file mode 100755 index 0000000000000000000000000000000000000000..d74d40467f0b166109ca1dcee02abd258f3d7a22 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0043-rt-arrayboundary-ABCOstringSwitch/ABCOstringSwitch.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOstringSwitch.java + * -@TestCaseName: switch visit Array element + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: switch visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOstringSwitch.java + * -@ExecuteClass: ABCOstringSwitch + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Random; + +public class ABCOstringSwitch { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + char[] a = new char[3000]; + for (int i = 0; i < a.length; i++) { + a[i] = 'h'; + } + String joinLine = Arrays.toString(a); + + char c; + int x = func(); + int y = x % 2; + try { + switch (y) { + case 0: + c = joinLine.charAt(x); + break; + default: + c = joinLine.charAt(x); + } + } catch (StringIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int func() { + Random r = new Random(); + int getI = r.nextInt(3); + int y = getI % 3; + getI = getI + 9000; + switch (y) { + case 0: + getI = getI + 0; + break; + case 1: + getI = getI + 1; + break; + default: + getI = getI + 2; + } + return getI; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0044-rt-arrayboundary-ABCOswitch/ABCOswitch.java b/test/testsuite/ouroboros/arrayboundary_test/RT0044-rt-arrayboundary-ABCOswitch/ABCOswitch.java new file mode 100755 index 0000000000000000000000000000000000000000..67ba91b22752468bedc4cae3e3aaba6dde38a2d6 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0044-rt-arrayboundary-ABCOswitch/ABCOswitch.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOswitch.java + * -@TestCaseName: switch visit Array element + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: switch visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOswitch.java + * -@ExecuteClass: ABCOswitch + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Random; + +public class ABCOswitch { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + int c; + Random r = new Random(); + int x = r.nextInt(2); + int y = x % 2; + x = x + 5; + try { + switch (y) { + case 0: + c = a[x]; + break; + default: + c = a[x]; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0045-rt-arrayboundary-ABCOtryExtEh/ABCOtryExtEh.java b/test/testsuite/ouroboros/arrayboundary_test/RT0045-rt-arrayboundary-ABCOtryExtEh/ABCOtryExtEh.java new file mode 100755 index 0000000000000000000000000000000000000000..2407cde89efeeaec76b2d5bd7173b526a26acaf4 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0045-rt-arrayboundary-ABCOtryExtEh/ABCOtryExtEh.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOtryExtEh.java + * -@TestCaseName: ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: visit index of const, try catch ArrayIndexOutOfBoundsException and IndexOutOfBoundsException + * -#step3: catch ArrayIndexOutOfBoundsException + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOtryExtEh.java + * -@ExecuteClass: ABCOtryExtEh + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOtryExtEh { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + try { + int c = a[-1]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } catch (IndexOutOfBoundsException e) { + res++; + } + + try { + int c = a[6]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } catch (IndexOutOfBoundsException e) { + res++; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0046-rt-arrayboundary-ABCOmaxValue/ABCOmaxValue.java b/test/testsuite/ouroboros/arrayboundary_test/RT0046-rt-arrayboundary-ABCOmaxValue/ABCOmaxValue.java new file mode 100755 index 0000000000000000000000000000000000000000..4c84577e7e7d7c2530cd4ff2af2349acd8750e88 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0046-rt-arrayboundary-ABCOmaxValue/ABCOmaxValue.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOmaxValue.java + * -@TestCaseName: index is MAX_VALUE or MIN_VALUE + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: visit index of MAX_VALUE or MIN_VALUE const + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOmaxValue.java + * -@ExecuteClass: ABCOmaxValue + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOmaxValue { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + int max = Integer.MAX_VALUE; + int min = Integer.MIN_VALUE; + try { + int c = a[min]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + try { + int c = a[max]; + } catch (ArrayIndexOutOfBoundsException e) { + res--; + } + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0047-rt-arrayboundary-ABCOwhile/ABCOwhile.java b/test/testsuite/ouroboros/arrayboundary_test/RT0047-rt-arrayboundary-ABCOwhile/ABCOwhile.java new file mode 100755 index 0000000000000000000000000000000000000000..0822b2287539368ee8716852a0b3dac89c27b00f --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0047-rt-arrayboundary-ABCOwhile/ABCOwhile.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOwhile.java + * -@TestCaseName: while visit Array element + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: while visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOwhile.java + * -@ExecuteClass: ABCOwhile + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ABCOwhile { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); // + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + int[] a = new int[5]; + int[] c = new int[a.length]; + int x = 0; + int y = a.length; + try { + while (x <= y) { + c[x] = a[x]; + x++; + } + } catch (ArrayIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/arrayboundary_test/RT0048-rt-arrayboundary-ABCOwhileString/ABCOwhileString.java b/test/testsuite/ouroboros/arrayboundary_test/RT0048-rt-arrayboundary-ABCOwhileString/ABCOwhileString.java new file mode 100755 index 0000000000000000000000000000000000000000..17f3b937275493c4892a122ecc5179de1281f4b6 --- /dev/null +++ b/test/testsuite/ouroboros/arrayboundary_test/RT0048-rt-arrayboundary-ABCOwhileString/ABCOwhileString.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_ArrayBoundary_ABCOwhileString.java + * -@TestCaseName: while visit Array element + * -@TestCaseType: Function Test + * -@RequirementName: Array Bounds Check优化 + * -@Brief: + * -#step1: new Array[5] + * -#step2: while visit Array element + * -#step3: catch Exception + * -@Expect: 0\n + * -@Priority: High + * -@Source: ABCOwhileString.java + * -@ExecuteClass: ABCOwhileString + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Arrays; + +public class ABCOwhileString { + static int RES_PROCESS = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 4 /*STATUS_FAILED*/; + try { + result = test1(); + } catch (Exception e) { + RES_PROCESS -= 10; + } + + if (result == 1 && RES_PROCESS == 99) { + result = 0; + } + return result; + } + + public static int test1() { + int res = 3 /*STATUS_FAILED*/; + + char[] a = new char[100]; + for (int i = 0; i < a.length; i++) { + a[i] = 'h'; + } + String joinLine = Arrays.toString(a); + + char[] c = new char[joinLine.length()]; + int x = funx(1000); + int y = funx(170000); + try { + while (x <= y) { + c[x] = joinLine.charAt(y); + ; + x++; + } + } catch (StringIndexOutOfBoundsException e) { + res = 1; + } + + return res; + } + + public static int funx(int maxFlag) { + int endIndex = maxFlag + 5; + int index = 0; + while (index < endIndex) { + index = funy(index); + } + return index; + } + + public static int funy(int forIdx) { + int idx = forIdx + 100; + return idx; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0032-rt-eh-TryFinallyExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0032-rt-eh-TryFinallyExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..bbc1445ae95d764c543a46588e9e7498796a5fce --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0032-rt-eh-TryFinallyExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryFinallyExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0032-rt-eh-TryFinallyExceptionTest/TryFinallyExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0032-rt-eh-TryFinallyExceptionTest/TryFinallyExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..568da20ff3aee17f6366973667d90caa4c9dfdb9 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0032-rt-eh-TryFinallyExceptionTest/TryFinallyExceptionTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryFinallyExceptionTest.java + * -@TestCaseName: Test try-finally mode: try{exception}-finally-->caller. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-finally test static int parseInt(String s). + * -#step3: Check finally is test and NumberFormatException is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryFinallyExceptionTest.java + * -@ExecuteClass: TryFinallyExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryFinallyExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; + + try { + tryFinallyExceptionTest(); + } catch (NumberFormatException e) { + processResult -= 3; + } + if (result == 2 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try-finally mode: try{exception}-finally-->caller. + */ + public static void tryFinallyExceptionTest() { + String str = "123#456"; + try { + Integer.parseInt(str); + System.out.println("=====See:ERROR!!!"); + } finally { + processResult--; + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0033-rt-eh-TryCatchExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0033-rt-eh-TryCatchExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..02287bb722a7c361f7e400708fd9eaa4a324515b --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0033-rt-eh-TryCatchExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryCatchExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0033-rt-eh-TryCatchExceptionTest/TryCatchExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0033-rt-eh-TryCatchExceptionTest/TryCatchExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7d1beea6e700c852f82d969e123e7149fc453e68 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0033-rt-eh-TryCatchExceptionTest/TryCatchExceptionTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryCatchExceptionTest.java + * -@TestCaseName: Test try-catch mode. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#case1 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch test static int parseInt(String s). + * -#step3: Check NumberFormatException is thrown. + * -#case2 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch test static int parseInt(String s). + * -#step3: Check IllegalArgumentException is thrown. + * -#case3 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch test static int parseInt(String s). + * -#step3: Check RuntimeException is thrown. + * -#case4 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch test static int parseInt(String s). + * -#step3: Check Exception is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryCatchExceptionTest.java + * -@ExecuteClass: TryCatchExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryCatchExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; + try { + tryCatchExceptionTest1(); + tryCatchExceptionTest2(); + tryCatchExceptionTest3(); + tryCatchExceptionTest4(); + } catch (Exception e) { + processResult -= 10; + result = 3; + } + if (result == 2 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Check NumberFormatException + */ + public static void tryCatchExceptionTest1() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (NumberFormatException e) { + processResult--; + } + } + + /** + * Check IllegalArgumentException + */ + public static void tryCatchExceptionTest2() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (IllegalArgumentException e) { + processResult--; + } + } + + /** + * Check RuntimeException + */ + public static void tryCatchExceptionTest3() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (RuntimeException e) { + processResult--; + } + } + + /** + * Check Exception + */ + public static void tryCatchExceptionTest4() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (Exception e) { + processResult--; + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0034-rt-eh-TryMultiCatchExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0034-rt-eh-TryMultiCatchExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..411253a927ce104d506a705a8ce1b7b5c29beabc --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0034-rt-eh-TryMultiCatchExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryMultiCatchExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0034-rt-eh-TryMultiCatchExceptionTest/TryMultiCatchExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0034-rt-eh-TryMultiCatchExceptionTest/TryMultiCatchExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..1c37a07148c858263a58b6de5207f27b09fae397 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0034-rt-eh-TryMultiCatchExceptionTest/TryMultiCatchExceptionTest.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryMultiCatchExceptionTest.java + * -@TestCaseName: Test try-catch/catch/...(multi-catch) mode. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#case1 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in first + * catch. + * -#step3: Check NumberFormatException is thrown. + * -#case2 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in second + * catch. + * -#step3: Check NumberFormatException is thrown. + * -#case3 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in third + * catch. + * -#step3: Check NumberFormatException is thrown. + * -#case4 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in fourth + * catch. + * -#step3: Check NumberFormatException is thrown. + * -#case5 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in fifth + * catch. + * -#step3: Check NumberFormatException is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryMultiCatchExceptionTest.java + * -@ExecuteClass: TryMultiCatchExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.nio.file.InvalidPathException; + +public class TryMultiCatchExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; + try { + tryMultiCatchExceptionTest1(); + tryMultiCatchExceptionTest2(); + tryMultiCatchExceptionTest3(); + tryMultiCatchExceptionTest4(); + tryMultiCatchExceptionTest5(); + } catch (Exception e) { + processResult -= 10; + result = 3; + } + + if (result == 2 && processResult == 94) { + result = 0; + } + return result; + } + + /** + * Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in first catch. + */ + public static void tryMultiCatchExceptionTest1() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (NumberFormatException e) { + processResult--; + } catch (ClassCastException e) { + processResult -= 10; + } catch (InvalidPathException e) { + processResult -= 10; + } catch (IllegalStateException e) { + processResult -= 10; + } catch (IllegalArgumentException e) { + processResult -= 10; + } + } + + /** + * Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in second catch. + */ + public static void tryMultiCatchExceptionTest2() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (ClassCastException e) { + processResult -= 10; + } catch (NumberFormatException e) { + processResult--; + } catch (InvalidPathException e) { + processResult -= 10; + } catch (IllegalStateException e) { + processResult -= 10; + } catch (IllegalArgumentException e) { + processResult -= 10; + } + } + + /** + * Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in third catch. + */ + public static void tryMultiCatchExceptionTest3() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (ClassCastException e) { + processResult -= 10; + } catch (InvalidPathException e) { + processResult -= 10; + } catch (NumberFormatException e) { + processResult--; + } catch (IllegalStateException e) { + processResult -= 10; + } catch (IllegalArgumentException e) { + processResult -= 10; + } + } + + /** + * Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in forth catch. + */ + public static void tryMultiCatchExceptionTest4() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (ClassCastException e) { + processResult -= 10; + } catch (InvalidPathException e) { + processResult -= 10; + } catch (IllegalStateException e) { + processResult -= 10; + } catch (NumberFormatException e) { + processResult--; + } catch (IllegalArgumentException e) { + processResult -= 10; + } + } + + /** + * Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in fifth catch. + */ + public static void tryMultiCatchExceptionTest5() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (ClassCastException e) { + processResult -= 10; + } catch (InvalidPathException e) { + processResult -= 10; + } catch (IllegalStateException e) { + processResult -= 10; + } catch (IndexOutOfBoundsException e) { + processResult -= 10; + } catch (NumberFormatException e) { + processResult--; + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0035-rt-eh-TryMultiCatchMatchFirstExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0035-rt-eh-TryMultiCatchMatchFirstExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..36249b5cc0c2ddcf73940b31736d91bd5dae5e86 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0035-rt-eh-TryMultiCatchMatchFirstExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryMultiCatchMatchFirstExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0035-rt-eh-TryMultiCatchMatchFirstExceptionTest/TryMultiCatchMatchFirstExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0035-rt-eh-TryMultiCatchMatchFirstExceptionTest/TryMultiCatchMatchFirstExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8e99c8ed12ee6ce19038a4af6eca1bd3c78fb9a0 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0035-rt-eh-TryMultiCatchMatchFirstExceptionTest/TryMultiCatchMatchFirstExceptionTest.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryMultiCatchMatchFirstExceptionTest.java + * -@TestCaseName: Test try-catch/catch/...(multi-catch) mode. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch/catch/...(multi-catch) test static int parseInt(String s), NumberFormatException is in first + * catch, IllegalArgumentException is in second catch, RuntimeException is in third match, Exception is in + * fourth catch. + * -#step3: Check NumberFormatException is caught. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryMultiCatchMatchFirstExceptionTest.java + * -@ExecuteClass: TryMultiCatchMatchFirstExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryMultiCatchMatchFirstExceptionTest { + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + result = tryMultiCatchMatchFirstExceptionTest1(); + if (result != 0) { + return 2; + } + return result; + } + + /** + * Test try-catch/catch/...(multi-catch) mode. + * + * @return status code + */ + public static int tryMultiCatchMatchFirstExceptionTest1() { + int result1 = 2; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + } catch (NumberFormatException e) { + result1 = 0; + } catch (IllegalArgumentException e) { + result1 = 2; + } catch (RuntimeException e) { + result1 = 2; + } catch (Exception e) { + result1 = 2; + } + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0036-rt-eh-TryCatchPipelineExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0036-rt-eh-TryCatchPipelineExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..60642207118d34402338b95397fbba362721a454 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0036-rt-eh-TryCatchPipelineExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryCatchPipelineExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0036-rt-eh-TryCatchPipelineExceptionTest/TryCatchPipelineExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0036-rt-eh-TryCatchPipelineExceptionTest/TryCatchPipelineExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5236f104964f098e7e021064acb1a291c231f4ec --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0036-rt-eh-TryCatchPipelineExceptionTest/TryCatchPipelineExceptionTest.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryCatchPipelineExceptionTest.java + * -@TestCaseName: Test try-catch(type1 | type 2 | ...). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in first + * type. + * -#step3: Check NumberFormatException is thrown. + * -#case2 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in + * second type. + * -#step3: Check NumberFormatException is thrown. + * -#case3 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in third + * type. + * -#step3: Check NumberFormatException is thrown. + * -#case4 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in + * fourth type. + * -#step3: Check NumberFormatException is thrown. + * -#case5 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in fifth + * type. + * -#step3: Check NumberFormatException is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryCatchPipelineExceptionTest.java + * -@ExecuteClass: TryCatchPipelineExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.nio.file.InvalidPathException; + +public class TryCatchPipelineExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; + try { + tryCatchPipelineExceptionTest1(); + tryCatchPipelineExceptionTest2(); + tryCatchPipelineExceptionTest3(); + tryCatchPipelineExceptionTest4(); + tryCatchPipelineExceptionTest5(); + } catch (Exception e) { + processResult -= 10; + result = 3; + } + + if (result == 2 && processResult == 94) { + result = 0; + } + return result; + } + + /** + * Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in first type. + */ + public static void tryCatchPipelineExceptionTest1() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (NumberFormatException + | ClassCastException + | InvalidPathException + | IllegalStateException + | IndexOutOfBoundsException e) { + processResult--; + } + } + + /** + * Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in second type. + */ + public static void tryCatchPipelineExceptionTest2() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (ClassCastException + | NumberFormatException + | InvalidPathException + | IllegalStateException + | IndexOutOfBoundsException e) { + processResult--; + } + } + + /** + * Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in third type. + */ + public static void tryCatchPipelineExceptionTest3() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (ClassCastException + | InvalidPathException + | NumberFormatException + | IllegalStateException + | IndexOutOfBoundsException e) { + processResult--; + } + } + + /** + * Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in fourth type. + */ + public static void tryCatchPipelineExceptionTest4() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (ClassCastException + | InvalidPathException + | IllegalStateException + | NumberFormatException + | IndexOutOfBoundsException e) { + processResult--; + } + } + + /** + * Use try-catch(type1 | type 2 | ...) to test static int parseInt(String s), NumberFormatException is in fifth+ type. + */ + public static void tryCatchPipelineExceptionTest5() { + String str = "123#456"; + try { + Integer.parseInt(str); + processResult -= 10; + } catch (ClassCastException + | InvalidPathException + | IllegalStateException + | IndexOutOfBoundsException + | NumberFormatException e) { + processResult--; + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0037-rt-eh-TryMultiCatchFinallyExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0037-rt-eh-TryMultiCatchFinallyExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..97c86220b7dfead7a867887676adc01b32ebef4b --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0037-rt-eh-TryMultiCatchFinallyExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryMultiCatchFinallyExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0037-rt-eh-TryMultiCatchFinallyExceptionTest/TryMultiCatchFinallyExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0037-rt-eh-TryMultiCatchFinallyExceptionTest/TryMultiCatchFinallyExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..93d43a47966edb2580f7b18cec12654dcab58687 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0037-rt-eh-TryMultiCatchFinallyExceptionTest/TryMultiCatchFinallyExceptionTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryMultiCatchFinallyExceptionTest.java + * -@TestCaseName: Test try-catch/catch…-finally mode. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#case1 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch/catch…-finally to test static int parseInt(String s), NumberFormatException is in catch. + * -#step3: Check NumberFormatException is caught, finally is traversed. + * -#case1 + * -#step1: Create a String s include number and special symbol. + * -#step2: Use try-catch/catch…-finally to test static int parseInt(String s), NumberFormatException is not in catch. + * -#step3: Check NumberFormatException is thrown, finally is traversed. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryMultiCatchFinallyExceptionTest.java + * -@ExecuteClass: TryMultiCatchFinallyExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryMultiCatchFinallyExceptionTest { + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; + + result = tryMultiCatchFinallyExceptionTest(); + if (result != 0) { + return 2; + } + + try { + result = tryMultiCatchFinallyExceptionTest2(); + } catch (NumberFormatException e) { + if (result != 0) { + return 2; + } + } + return result; + } + + /** + * Use try-catch/catch…-finally to test static int parseInt(String s), NumberFormatException is in catch. + * + * @return status code + */ + public static int tryMultiCatchFinallyExceptionTest() { + int result1 = 2; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + } catch (NumberFormatException e) { + result1--; + } catch (IllegalArgumentException e) { + result1 = 2; + } catch (RuntimeException e) { + result1 = 2; + } catch (Exception e) { + result1 = 2; + } finally { + result1--; + } + return result1; + } + + /** + * Use try-catch/catch…-finally to test static int parseInt(String s), NumberFormatException is not in catch. + * + * @return status code + * @throws NumberFormatException + */ + public static int tryMultiCatchFinallyExceptionTest2() throws NumberFormatException { + int result2 = 2; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + } catch (IndexOutOfBoundsException e) { + result2 = 2; + } finally { + result2 = 0; + } + return result2; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0038-rt-eh-TryCatchResourceExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0038-rt-eh-TryCatchResourceExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..f58de1da5f50880da3edd3be5e84b58c6975743d --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0038-rt-eh-TryCatchResourceExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryCatchResourceExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0038-rt-eh-TryCatchResourceExceptionTest/TryCatchResourceExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0038-rt-eh-TryCatchResourceExceptionTest/TryCatchResourceExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c5c7b9ecdca17d05d0e27b24195fa3dc61e9218a --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0038-rt-eh-TryCatchResourceExceptionTest/TryCatchResourceExceptionTest.java @@ -0,0 +1,174 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryCatchResourceExceptionTest.java + * -@TestCaseName: Test try with resource. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Test no Exception occur: conn.start->conn.close->finally. + * -#step2: Test Exception in try: conn.start->conn.close->catch(catch e in try, ignore e in close)->finally. + * -#step3: Test Exception in try: conn.start->conn.close->catch(catch e in start, ignore e in try & close)->finally. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryCatchResourceExceptionTest.java + * -@ExecuteClass: TryCatchResourceExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryCatchResourceExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 4; /* STATUS_FAILED */ + + try { + // No Exception occur: conn.start->conn.close->finally. + result = result - tryCatchResourceExceptionTest1(); + // Exception in try: conn.start->conn.close->catch(catch e in try,ignore e in close)->finally. + result = result - tryCatchResourceExceptionTest2(); + // Exception in try: conn.start->conn.close->catch(catch e in start,ignore e in try & close)->finally. + result = result - tryCatchResourceExceptionTest3(); + } catch (Exception e) { + processResult += 10; + } + if (result == 1 && processResult == 90) { + result = 0; + } + return result; + } + + /** + * No Exception occur: conn.start->conn.close->finally. + * + * @return status code + */ + public static int tryCatchResourceExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + try (MyResourceA conn = new MyResourceA()) { + conn.start(); + result1 = 1; + processResult--; + } catch (Exception e) { + System.out.println("catch ......"); + processResult -= 10; + result1++; + } finally { + processResult--; + } + processResult--; + return result1; + } + + /** + * Exception in try: conn.start->conn.close->catch(catch e in try,ignore e in close)->finally. + * + * @return status code + */ + public static int tryCatchResourceExceptionTest2() { + int result1 = 4; /* STATUS_FAILED */ + try (MyResourceB conn = new MyResourceB()) { + conn.start(); + int num = 1 / (result1 - 4); + processResult -= 10; + } catch (Exception e) { + processResult--; + result1 = 1; + } finally { + processResult--; + } + processResult--; + return result1; + } + + /** + * Exception in try: conn.start->conn.close->catch(catch e in start,ignore e in try & close)->finally. + * + * @return status code + */ + public static int tryCatchResourceExceptionTest3() { + int result1 = 4; /* STATUS_FAILED */ + try (MyResourceC conn = new MyResourceC()) { + conn.start(); + int num = 1 / (result1 - 4); + processResult -= 10; + } catch (Exception e) { + processResult--; + result1 = 1; + } finally { + processResult--; + } + processResult--; + return result1; + } + + public static class MyResourceA implements AutoCloseable { + /** + * start fun + */ + public void start() { + processResult = processResult * 2; + } + + @Override + public void close() { + processResult = processResult / 2; + } + } + + public static class MyResourceB implements AutoCloseable { + /** + * start fun + */ + public void start() { + processResult = processResult * 2; + } + + @Override + public void close() throws Exception { + processResult = processResult / 2; + throw new NoSuchFieldException("ee"); + } + } + + public static class MyResourceC implements AutoCloseable { + /** + * start fun + */ + public void start() throws Exception { + processResult = processResult * 2; + throw new NoSuchMethodException("mm"); + } + + @Override + public void close() throws Exception { + processResult = processResult / 2; + throw new NoSuchFieldException("ee"); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0039-rt-eh-TryCatchThrowExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0039-rt-eh-TryCatchThrowExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..82dd463b4f6048800c0c345f329c86f944a82415 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0039-rt-eh-TryCatchThrowExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryCatchThrowExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0039-rt-eh-TryCatchThrowExceptionTest/TryCatchThrowExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0039-rt-eh-TryCatchThrowExceptionTest/TryCatchThrowExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..21b1960c68f141b0ae8fc468734f0b06c803e988 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0039-rt-eh-TryCatchThrowExceptionTest/TryCatchThrowExceptionTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryCatchThrowExceptionTest.java + * -@TestCaseName: Test throws and throw in try-catch. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#case1 + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s). + * -#step3: NumberFormatException is caught by catch, throw NumberFormatException correctly in catch. + * -#case2 + * -#step1: Create a new Exception extends from Exception. + * -#step2: Throw the new Exception in method correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryCatchThrowExceptionTest.java + * -@ExecuteClass: TryCatchThrowExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryCatchThrowExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryCatchThrowExceptionTest1(); + } catch (NumberFormatException e) { + processResult--; + } + + if (processResult == 97) { + result--; + } + + try { + tryCatchThrowExceptionTest3(); + } catch (Exception3 e) { + processResult--; + } + if (processResult == 95) { + result--; + } + return result; + } + + /** + * Test static int parseInt(String s), NumberFormatException is caught by catch + * + * @return status code + * @throws NumberFormatException + */ + public static int tryCatchThrowExceptionTest1() throws NumberFormatException { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + } catch (NumberFormatException e) { + processResult--; + throw e; + } + processResult -= 10; // Compiled successfully, but cannot execute. + return result1; + } + + /** + * Create a new Exception extends from Exception. + * + * @return status code + * @throws Exception3 + */ + public static int tryCatchThrowExceptionTest3() throws Exception3 { + int result3 = 3; /* STATUS_FAILED */ + if (result3 != 4) { + processResult--; + throw new Exception3(); + } + processResult -= 10; // Compiled successfully, but cannot execute. + return result3; + } + + static class Exception3 extends Exception { + Exception3() { + super("yes"); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0040-rt-eh-TryExceptionFinallyExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0040-rt-eh-TryExceptionFinallyExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..0bebfc85469438608ffce55232f7b628c0641575 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0040-rt-eh-TryExceptionFinallyExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryExceptionFinallyExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0040-rt-eh-TryExceptionFinallyExceptionTest/TryExceptionFinallyExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0040-rt-eh-TryExceptionFinallyExceptionTest/TryExceptionFinallyExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..825920ce23bd01caffb2d382bfc85f7be8cb3207 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0040-rt-eh-TryExceptionFinallyExceptionTest/TryExceptionFinallyExceptionTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryExceptionFinallyExceptionTest.java + * -@TestCaseName: Test try{exception}-finally:handler is caller. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-finally. + * -#step3: Check NumberFormatException is thrown in outside try-finally, finally is walked. + * -#step4: Check NumberFormatException is thrown, outside finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryExceptionFinallyExceptionTest.java + * -@ExecuteClass: TryExceptionFinallyExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryExceptionFinallyExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryExceptionFinallyExceptionTest1(); + } catch (NumberFormatException e) { + processResult -= 2; + } + + if (result == 2 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try{exception}-finally:handler is caller. + * + * @return status code + */ + public static int tryExceptionFinallyExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + try { + Integer.parseInt(str); + } finally { + processResult--; + } + processResult -= 10; + } finally { + processResult--; + } + processResult -= 10; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0041-rt-eh-TryTryThrowExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0041-rt-eh-TryTryThrowExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..86a0a1389ad9d8fbecff82e6105e8f7156864448 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0041-rt-eh-TryTryThrowExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryTryThrowExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0041-rt-eh-TryTryThrowExceptionTest/TryTryThrowExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0041-rt-eh-TryTryThrowExceptionTest/TryTryThrowExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ab73dad0127230e1b6fc299553e19ecf46ca4a4b --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0041-rt-eh-TryTryThrowExceptionTest/TryTryThrowExceptionTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryTryThrowExceptionTest.java + * -@TestCaseName: Test try{exception}-catch(x)-finally:handler is caller. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-finally. + * -#step3: Check NumberFormatException is thrown in outside try-Multi catch-finally, finally is walked. + * -#step4: Check NumberFormatException is thrown, outside finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryTryThrowExceptionTest.java + * -@ExecuteClass: TryTryThrowExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryTryThrowExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryTryThrowExceptionTest1(); + } catch (NumberFormatException e) { + processResult -= 2; + } + if (result == 2 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try{exception}-catch(x)-finally:handler is caller. + * + * @return status code + */ + public static int tryTryThrowExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + try { + Integer.parseInt(str); + } finally { + processResult--; + } + processResult -= 10; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (IndexOutOfBoundsException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (IllegalStateException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult--; + } + processResult -= 10; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0042-rt-eh-TryTryCatchExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0042-rt-eh-TryTryCatchExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..ad2b4d98921ba3d37b6ade7371f33d0841481f61 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0042-rt-eh-TryTryCatchExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryTryCatchExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0042-rt-eh-TryTryCatchExceptionTest/TryTryCatchExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0042-rt-eh-TryTryCatchExceptionTest/TryTryCatchExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3edbeef104abc04bb5c6e8ec0dc61bb7fb3f0929 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0042-rt-eh-TryTryCatchExceptionTest/TryTryCatchExceptionTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryTryCatchExceptionTest.java + * -@TestCaseName: Test try{exception}-catch(e)-finally. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-finally. + * -#step3: Check NumberFormatException is thrown in outside try-Multi catch-finally, finally is walked. + * -#step4: Check NumberFormatException is caught by outside catch, outside finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryTryCatchExceptionTest.java + * -@ExecuteClass: TryTryCatchExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryTryCatchExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryTryCatchExceptionTest1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 1 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try{exception}-catch(e)-finally. + * + * @return status code + */ + public static int tryTryCatchExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + try { + Integer.parseInt(str); + } finally { + processResult--; + } + processResult -= 10; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (IndexOutOfBoundsException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (IllegalArgumentException e) { + processResult--; + result1 = 1; + } finally { + processResult--; + } + processResult--; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0043-rt-eh-TryCatchTryExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0043-rt-eh-TryCatchTryExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..99d97b9b7161c9b09f1806da68fc4ed748866a0c --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0043-rt-eh-TryCatchTryExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryCatchTryExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0043-rt-eh-TryCatchTryExceptionTest/TryCatchTryExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0043-rt-eh-TryCatchTryExceptionTest/TryCatchTryExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fab693068d301c3612b8df7693742377e12011a2 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0043-rt-eh-TryCatchTryExceptionTest/TryCatchTryExceptionTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryCatchTryExceptionTest.java + * -@TestCaseName: Test try{try{exception} catch(e)}-catch-finally. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-finally. + * -#step3: Check NumberFormatException is caught by inside catch. + * -#step4: Check outside catch is not used, outside finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryCatchTryExceptionTest.java + * -@ExecuteClass: TryCatchTryExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryCatchTryExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryCatchTryExceptionTest1(); + } catch (StringIndexOutOfBoundsException e) { + processResult -= 10; + } + + if (result == 1 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try{try{exception} catch(e)}-catch-finally. + * + * @return status code + */ + public static int tryCatchTryExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + try { + Integer.parseInt(str); + } catch (NumberFormatException e) { + result1 = 1; + processResult--; + } + processResult--; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + System.out.println("=====See:ERROR!!!"); + processResult -= 10; + } catch (IllegalArgumentException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult--; + } + processResult--; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0044-rt-eh-DoubleTryCatchFinallyExceptionTest/DoubleTryCatchFinallyExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0044-rt-eh-DoubleTryCatchFinallyExceptionTest/DoubleTryCatchFinallyExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f79d881b4ffbac621f29450411348b7540503918 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0044-rt-eh-DoubleTryCatchFinallyExceptionTest/DoubleTryCatchFinallyExceptionTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: DoubleTryCatchFinallyExceptionTest.java + * -@TestCaseName: Test try{try{exception} catch(x)}-finally -->caller. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-finally. + * -#step3: Check NumberFormatException is thrown in outside try-Multi catch-finally, finally is walked. + * -#step4: Check NumberFormatException is thrown, outside finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: DoubleTryCatchFinallyExceptionTest.java + * -@ExecuteClass: DoubleTryCatchFinallyExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class DoubleTryCatchFinallyExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = doubleTryCatchFinallyExceptionTest1(); + } catch (IllegalArgumentException e) { + processResult -= 2; + } + + if (result == 2 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try{try{exception} catch(x)}-finally -->caller. + * + * @return status code + */ + public static int doubleTryCatchFinallyExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + try { + Integer.parseInt(str); + } catch (ClassCastException e) { + result1 = 3; + processResult -= 10; + } finally { + processResult--; + } + processResult -= 10; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (IndexOutOfBoundsException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (IllegalStateException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult--; + } + processResult -= 10; + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0044-rt-eh-DoubleTryCatchFinallyExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0044-rt-eh-DoubleTryCatchFinallyExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..287617a681d904cdddad639c4cfcd38dfe91800a --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0044-rt-eh-DoubleTryCatchFinallyExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=DoubleTryCatchFinallyExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0045-rt-eh-TryCatchTryCatchFinallyExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0045-rt-eh-TryCatchTryCatchFinallyExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..7e9a7629f95f28b7cd0f281a1ed288ae9ebc7f22 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0045-rt-eh-TryCatchTryCatchFinallyExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryCatchTryCatchFinallyExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0045-rt-eh-TryCatchTryCatchFinallyExceptionTest/TryCatchTryCatchFinallyExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0045-rt-eh-TryCatchTryCatchFinallyExceptionTest/TryCatchTryCatchFinallyExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8a88d3b58fa53d8fbdd3245dcccefbc4584d7d0b --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0045-rt-eh-TryCatchTryCatchFinallyExceptionTest/TryCatchTryCatchFinallyExceptionTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryCatchTryCatchFinallyExceptionTest.java + * -@TestCaseName: Test try{try{exception} catch(x)}-catch()-finally --> caller. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-catch. + * -#step3: Check NumberFormatException is thrown in outside try-Multi catch-finally. + * -#step4: Check NumberFormatException is thrown, outside finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryCatchTryCatchFinallyExceptionTest.java + * -@ExecuteClass: TryCatchTryCatchFinallyExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.FormatterClosedException; + +public class TryCatchTryCatchFinallyExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryCatchTryCatchFinallyExceptionTest1(); + } catch (NumberFormatException e) { + processResult--; + } + + if (result == 2 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try{try{exception} catch(x)}-catch()-finally --> caller. + * + * @return status code + */ + public static int tryCatchTryCatchFinallyExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + try { + Integer.parseInt(str); + } catch (IllegalStateException e113) { + System.out.println("=====See:ERROR!!!"); + processResult -= 10; + } + processResult -= 10; + } catch (FormatterClosedException e1132) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (IndexOutOfBoundsException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult -= 3; + } + processResult -= 10; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0046-rt-eh-TryCatchTryCatchExceptionFinallyTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0046-rt-eh-TryCatchTryCatchExceptionFinallyTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..ee99bde64aa880601fe9ff1904b47d88bff752f5 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0046-rt-eh-TryCatchTryCatchExceptionFinallyTest/Makefile @@ -0,0 +1,3 @@ +APP=TryCatchTryCatchExceptionFinallyTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0046-rt-eh-TryCatchTryCatchExceptionFinallyTest/TryCatchTryCatchExceptionFinallyTest.java b/test/testsuite/ouroboros/eh_test/RT0046-rt-eh-TryCatchTryCatchExceptionFinallyTest/TryCatchTryCatchExceptionFinallyTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b264ba4441dee19612cd5a0886c713bf446df533 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0046-rt-eh-TryCatchTryCatchExceptionFinallyTest/TryCatchTryCatchExceptionFinallyTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryCatchTryCatchExceptionFinallyTest.java + * -@TestCaseName: Test try{try{exception} catch(x)}-catch(e)-finally. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-catch. + * -#step3: Check NumberFormatException is thrown in outside try-Multi catch-finally. + * -#step4: Check NumberFormatException is caught by catch, outside finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryCatchTryCatchExceptionFinallyTest.java + * -@ExecuteClass: TryCatchTryCatchExceptionFinallyTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.FormatterClosedException; + +public class TryCatchTryCatchExceptionFinallyTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryCatchTryCatchExceptionFinallyTest1(); + } catch (NumberFormatException e) { + processResult -= 10; + } + + if (result == 1 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try{try{exception} catch(x)}-catch(e)-finally. + * + * @return status code + */ + public static int tryCatchTryCatchExceptionFinallyTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + try { + Integer.parseInt(str); + } catch (IllegalStateException e113) { + System.out.println("=====See:ERROR!!!"); + processResult -= 10; + } + processResult -= 10; + } catch (FormatterClosedException e1132) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (IllegalArgumentException e111) { + result1 = 1; + } catch (IndexOutOfBoundsException e112) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult -= 1; + } + processResult -= 3; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0047-rt-eh-CatchThrowNewExceptionTest/CatchThrowNewExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0047-rt-eh-CatchThrowNewExceptionTest/CatchThrowNewExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5cf7eb2712aab8350e5df4f8e876a0ba9d546a94 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0047-rt-eh-CatchThrowNewExceptionTest/CatchThrowNewExceptionTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CatchThrowNewExceptionTest.java + * -@TestCaseName: Test catch(){exception}, handler is caller. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-catch. + * -#step3: Check NumberFormatException is caught by catch. + * -#step4: Create parameter beginIndex < 0, test method String substring(int beginIndex) in catch. + * -#step5: Check StringIndexOutOfBoundsException is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: CatchThrowNewExceptionTest.java + * -@ExecuteClass: CatchThrowNewExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class CatchThrowNewExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = catchThrowNewExceptionTest1(); + } catch (StringIndexOutOfBoundsException e) { + if (result == 2 && processResult == 95) { + return 0; + } + } + + return result; + } + + /** + * Test catch(){exception}, handler is caller. + * + * @return status code + */ + public static int catchThrowNewExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + System.out.println("=====See:ERROR!!!"); + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + processResult -= 2; + System.out.println(str.substring(-5)); + System.out.println("=====See:ERROR!!!"); + processResult -= 10; + } catch (IllegalArgumentException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult -= 2; + } + processResult -= 10; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0047-rt-eh-CatchThrowNewExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0047-rt-eh-CatchThrowNewExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..7be907bc8548238d845e2e72343c4e25c3309eea --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0047-rt-eh-CatchThrowNewExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=CatchThrowNewExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0048-rt-eh-CatchTryCatchNewExceptionTest/CatchTryCatchNewExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0048-rt-eh-CatchTryCatchNewExceptionTest/CatchTryCatchNewExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5a9d671bca542d5c482eece2754c63f1b4eabf45 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0048-rt-eh-CatchTryCatchNewExceptionTest/CatchTryCatchNewExceptionTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CatchTryCatchNewExceptionTest.java + * -@TestCaseName: Test try-catch(){try{exception},catch(e)}-finally. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-catch. + * -#step3: Check NumberFormatException is caught by catch. + * -#step4: Create parameter beginIndex < 0, test method String substring(int beginIndex) in new try-catch in old catch. + * -#step5: Check StringIndexOutOfBoundsException is caught by new catch. + * -@Expect: 0\n + * -@Priority: High + * -@Source: CatchTryCatchNewExceptionTest.java + * -@ExecuteClass: CatchTryCatchNewExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class CatchTryCatchNewExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = catchTryCatchNewExceptionTest1(); + } catch (StringIndexOutOfBoundsException e) { + processResult -= 10; + } + + if (result == 1 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try-catch(){try{exception},catch(e)}-finally. + * + * @return status code + */ + public static int catchTryCatchNewExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + System.out.println("=====See:ERROR!!!"); + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + try { + System.out.println(str.substring(-5)); + } catch (StringIndexOutOfBoundsException e2) { + processResult--; + } + result1 = 1; + } catch (IllegalArgumentException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult--; + } + processResult -= 2; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0048-rt-eh-CatchTryCatchNewExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0048-rt-eh-CatchTryCatchNewExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..6b35a01c30408e7a6f683764872125b8f7d9da45 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0048-rt-eh-CatchTryCatchNewExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=CatchTryCatchNewExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0049-rt-eh-CatchTryThrowNewExceptionTest/CatchTryThrowNewExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0049-rt-eh-CatchTryThrowNewExceptionTest/CatchTryThrowNewExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..86df3526f4c529f926e38dd37f3323b5ed0ba6c1 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0049-rt-eh-CatchTryThrowNewExceptionTest/CatchTryThrowNewExceptionTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CatchTryThrowNewExceptionTest.java + * -@TestCaseName: Test try-catch(){try{exception},catch(x)}-finally --> caller. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-catch. + * -#step3: Check NumberFormatException is caught by catch. + * -#step4: Create parameter beginIndex < 0, test method String substring(int beginIndex) in new try-catch in old catch. + * -#step5: Check StringIndexOutOfBoundsException is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: CatchTryThrowNewExceptionTest.java + * -@ExecuteClass: CatchTryThrowNewExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class CatchTryThrowNewExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = catchTryThrowNewExceptionTest1(); + } catch (StringIndexOutOfBoundsException e) { + processResult--; + } + + if (result == 2 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try-catch(){try{exception},catch(x)}-finally --> caller. + * + * @return status code + */ + public static int catchTryThrowNewExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + System.out.println("=====See:ERROR!!!"); + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + result1 = 1; + try { + System.out.println(str.substring(-5)); + } catch (NumberFormatException e2) { + processResult -= 10; + } + processResult -= 10; + } catch (StringIndexOutOfBoundsException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult -= 3; + } + processResult -= 10; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0049-rt-eh-CatchTryThrowNewExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0049-rt-eh-CatchTryThrowNewExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..a09e7a1307e51650dbd0b4a18b6377ea571c81af --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0049-rt-eh-CatchTryThrowNewExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=CatchTryThrowNewExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0050-rt-eh-FinallyThrowExceptionTest/FinallyThrowExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0050-rt-eh-FinallyThrowExceptionTest/FinallyThrowExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a330b3dcccd931f25ec0e05c3af56cab7ed599f3 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0050-rt-eh-FinallyThrowExceptionTest/FinallyThrowExceptionTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FinallyThrowExceptionTest.java + * -@TestCaseName: Test finally{exception}, handler is caller. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-catch. + * -#step3: Check NumberFormatException is caught by catch. + * -#step4: Create parameter beginIndex < 0, test method String substring(int beginIndex) in finally. + * -#step5: Check StringIndexOutOfBoundsException is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FinallyThrowExceptionTest.java + * -@ExecuteClass: FinallyThrowExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class FinallyThrowExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = finallyThrowExceptionTest1(); + } catch (StringIndexOutOfBoundsException e) { + if (result == 2 && processResult == 95) { + return 0; + } + } + return result; + } + + /** + * Test finally{exception}, handler is caller. + * + * @return status code + */ + public static int finallyThrowExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + System.out.println("=====See:ERROR!!!"); + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + result1 = 1; + } catch (IllegalArgumentException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult -= 4; + System.out.println(str.substring(-5)); + System.out.println("=====See:ERROR!!!"); + processResult -= 10; + } + System.out.println("=====See:ERROR!!!"); + processResult -= 10; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0050-rt-eh-FinallyThrowExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0050-rt-eh-FinallyThrowExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..6d14a037d656b44cea08cc36067ed6c9cc54ddbb --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0050-rt-eh-FinallyThrowExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=FinallyThrowExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0051-rt-eh-FinallyTryCatchExceptionTest/FinallyTryCatchExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0051-rt-eh-FinallyTryCatchExceptionTest/FinallyTryCatchExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..4ed0d16f8ad7958c41b9176ee6a5c1c788d83f5d --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0051-rt-eh-FinallyTryCatchExceptionTest/FinallyTryCatchExceptionTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FinallyTryCatchExceptionTest.java + * -@TestCaseName: Test try-catch-finally{try{exception},catch(e)}. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-catch. + * -#step3: Check NumberFormatException is caught by catch. + * -#step4: Create parameter beginIndex < 0, test method String substring(int beginIndex) in finally. + * -#step5: Check StringIndexOutOfBoundsException is caught by inside try-catch. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FinallyTryCatchExceptionTest.java + * -@ExecuteClass: FinallyTryCatchExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class FinallyTryCatchExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = finallyTryCatchExceptionTest1(); + } catch (StringIndexOutOfBoundsException e) { + processResult -= 10; + } + + if (result == 1 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try-catch-finally{try{exception},catch(e)}. + * + * @return status code + */ + public static int finallyTryCatchExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + System.out.println("=====See:ERROR!!!"); + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + result1 = 1; + } catch (IllegalArgumentException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult--; + try { + System.out.println(str.substring(-5)); + } catch (StringIndexOutOfBoundsException e) { + processResult--; + } + } + processResult -= 2; + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0051-rt-eh-FinallyTryCatchExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0051-rt-eh-FinallyTryCatchExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..19f19b01803f32387ada9696a6e2c25653086b76 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0051-rt-eh-FinallyTryCatchExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=FinallyTryCatchExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0052-rt-eh-FinallyTryThrowExceptionTest/FinallyTryThrowExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0052-rt-eh-FinallyTryThrowExceptionTest/FinallyTryThrowExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..502880d12b025053b490954e3d82bde9aab39270 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0052-rt-eh-FinallyTryThrowExceptionTest/FinallyTryThrowExceptionTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FinallyTryThrowExceptionTest.java + * -@TestCaseName: Test try-catch-finally{try{exception},catch(x)}--> caller. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s) in try-catch. + * -#step3: Check NumberFormatException is caught by catch. + * -#step4: Create parameter beginIndex < 0, test method String substring(int beginIndex) in finally. + * -#step5: Check StringIndexOutOfBoundsException is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FinallyTryThrowExceptionTest.java + * -@ExecuteClass: FinallyTryThrowExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class FinallyTryThrowExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = finallyTryThrowExceptionTest1(); + } catch (StringIndexOutOfBoundsException e) { + processResult -= 3; + } + + if (result == 2 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try-catch-finally{try{exception},catch(x)}--> caller. + * + * @return status code + */ + public static int finallyTryThrowExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + System.out.println("=====See:ERROR!!!"); + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + result1 = 1; + } catch (IllegalArgumentException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult--; + try { + System.out.println(str.substring(-5)); + } catch (NumberFormatException e) { + processResult -= 10; + } + } + processResult -= 10; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0052-rt-eh-FinallyTryThrowExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0052-rt-eh-FinallyTryThrowExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..c42fb183f5341fc6e0a717e9714d74e41778f09d --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0052-rt-eh-FinallyTryThrowExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=FinallyTryThrowExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0053-rt-eh-TryResourceStartThrowExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0053-rt-eh-TryResourceStartThrowExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..4bc70773d04f1c74670b931b86f5d090c12cc336 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0053-rt-eh-TryResourceStartThrowExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryResourceStartThrowExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0053-rt-eh-TryResourceStartThrowExceptionTest/TryResourceStartThrowExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0053-rt-eh-TryResourceStartThrowExceptionTest/TryResourceStartThrowExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..698754956faff30e63d4d86421740baaa2a87052 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0053-rt-eh-TryResourceStartThrowExceptionTest/TryResourceStartThrowExceptionTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryResourceStartThrowExceptionTest.java + * -@TestCaseName: Test try(exception){}-catch(e){}-close()-finally. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create self class by implements AutoCloseable. + * -#step2: Create resource instance by new self class. + * -#step3: Test start() method. + * -#step4: Check NumberFormatException is thrown and finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryResourceStartThrowExceptionTest.java + * -@ExecuteClass: TryResourceStartThrowExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryResourceStartThrowExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryResourceStartThrowExceptionTest1(); + } catch (NumberFormatException e) { + processResult -= 10; + } + + if (result == 1 && processResult == 94) { + result = 0; + } + return result; + } + + public static class MyResource implements AutoCloseable { + /** + * start fun + * + * @throws NumberFormatException + */ + public void start() throws NumberFormatException { + processResult--; + throw new NumberFormatException("start:exception!!!"); + } + + @Override + public void close() throws StringIndexOutOfBoundsException { + processResult--; + } + } + + /** + * Test try(exception){}-catch(e){}-close()-finally. + * + * @return status code + */ + public static int tryResourceStartThrowExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + try (MyResource conn = new MyResource()) { + conn.start(); + } catch (NumberFormatException e) { + processResult--; + result1 = 1; + } catch (StringIndexOutOfBoundsException e) { + processResult -= 10; + result1 = 3; + } finally { + processResult--; + } + processResult--; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0054-rt-eh-TryResourceCloseThrowExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0054-rt-eh-TryResourceCloseThrowExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..b86fc1e9468d477f3ab62098fb352d1531fe879d --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0054-rt-eh-TryResourceCloseThrowExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryResourceCloseThrowExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0054-rt-eh-TryResourceCloseThrowExceptionTest/TryResourceCloseThrowExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0054-rt-eh-TryResourceCloseThrowExceptionTest/TryResourceCloseThrowExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0854e4ecd761440f2bb029dad1ba80374e544a09 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0054-rt-eh-TryResourceCloseThrowExceptionTest/TryResourceCloseThrowExceptionTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryResourceCloseThrowExceptionTest.java + * -@TestCaseName: Test try(){}-catch(e){}-close(exception)-finally. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create self class by implements AutoCloseable. + * -#step2: Create resource instance by new self class. + * -#step3: Test start() method and close() method. + * -#step4: Check StringIndexOutOfBoundsException is thrown and finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryResourceCloseThrowExceptionTest.java + * -@ExecuteClass: TryResourceCloseThrowExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryResourceCloseThrowExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryResourceCloseThrowExceptionTest1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 1 && processResult == 94) { + result = 0; + } + return result; + } + + public static class MyResource implements AutoCloseable { + /** + * start fun + * + * @throws NumberFormatException + */ + public void start() throws NumberFormatException { + processResult--; + } + + @Override + public void close() throws StringIndexOutOfBoundsException { + processResult--; + throw new StringIndexOutOfBoundsException("end:exception!!!"); + } + } + + /** + * Test try(){}-catch(e){}-close(exception)-finally. + * + * @return status code + */ + public static int tryResourceCloseThrowExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + try (MyResource conn = new MyResource()) { + conn.start(); + } catch (NumberFormatException e) { + processResult -= 10; + e.printStackTrace(); + result1 = 3; + } catch (StringIndexOutOfBoundsException e) { + processResult--; + result1 = 1; + } finally { + processResult--; + } + processResult--; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0055-rt-eh-TryResourceStartAndCloseExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0055-rt-eh-TryResourceStartAndCloseExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..a88ae007b87565d618f1a747791329192195fc6b --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0055-rt-eh-TryResourceStartAndCloseExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryResourceStartAndCloseExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0055-rt-eh-TryResourceStartAndCloseExceptionTest/TryResourceStartAndCloseExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0055-rt-eh-TryResourceStartAndCloseExceptionTest/TryResourceStartAndCloseExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..caa51d68f22fb1ec2ba8c1dfac198e0bfc1b02f4 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0055-rt-eh-TryResourceStartAndCloseExceptionTest/TryResourceStartAndCloseExceptionTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryResourceStartAndCloseExceptionTest.java + * -@TestCaseName: Test try(exception1){}-catch(e1){}-close(exception2)-finally. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create self class by implements AutoCloseable. + * -#step2: Create resource instance by new self class. + * -#step3: Test start() method and close() method. + * -#step4: Check NumberFormatException is thrown and finally is walked. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryResourceStartAndCloseExceptionTest.java + * -@ExecuteClass: TryResourceStartAndCloseExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryResourceStartAndCloseExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryResourceStartAndCloseExceptionTest1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 1 && processResult == 94) { + result = 0; + } + return result; + } + + public static class MyResource implements AutoCloseable { + /** + * start fun + * + * @throws NumberFormatException + */ + public void start() throws NumberFormatException { + processResult--; + throw new NumberFormatException("start:exception!!!"); + } + + @Override + public void close() throws StringIndexOutOfBoundsException { + processResult--; + throw new StringIndexOutOfBoundsException("end:exception!!!"); + } + } + + /** + * Test try(exception1){}-catch(e1){}-close(exception2)-finally. + * + * @return status code + */ + public static int tryResourceStartAndCloseExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + try (MyResource conn = new MyResource()) { + conn.start(); + } catch (NumberFormatException e) { + processResult--; + result1 = 1; + } catch (StringIndexOutOfBoundsException e) { + processResult -= 10; + result1 = 3; + } finally { + processResult--; + } + processResult--; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0066-rt-eh-JvmArrayIndexOutOfBoundsExceptionTest/JvmArrayIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0066-rt-eh-JvmArrayIndexOutOfBoundsExceptionTest/JvmArrayIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c7b9bc50a2b19ba2b03bfd848b0ca9c6d8bebd65 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0066-rt-eh-JvmArrayIndexOutOfBoundsExceptionTest/JvmArrayIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: JvmArrayIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test jvm instr: Invoke Initialization thrown ArrayIndexOutOfBoundsException. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a object array instance objs. + * -#step2: Get a object instance by the num element of objs, num is objs.length. + * -#step3: Check ArrayIndexOutOfBoundsException is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: JvmArrayIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: JvmArrayIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class JvmArrayIndexOutOfBoundsExceptionTest { + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + static final int len = 10; + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + Object[] objs = new Object[len]; + try { + Object obj1 = objs[len]; + } catch (ArrayIndexOutOfBoundsException e) { + return 0; // STATUS_PASSED + } + return 2; // STATUS_FAILED + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0066-rt-eh-JvmArrayIndexOutOfBoundsExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0066-rt-eh-JvmArrayIndexOutOfBoundsExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..fec4f7efc1f3b0bd44c6edb8808c5c18f8e4705d --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0066-rt-eh-JvmArrayIndexOutOfBoundsExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=JvmArrayIndexOutOfBoundsExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0067-rt-eh-JvmStaticExceptionInInitializerErrorTest/JvmStaticExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0067-rt-eh-JvmStaticExceptionInInitializerErrorTest/JvmStaticExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f5ebab51e497dafc434f5addc387300b9ba18e7f --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0067-rt-eh-JvmStaticExceptionInInitializerErrorTest/JvmStaticExceptionInInitializerErrorTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: JvmStaticExceptionInInitializerErrorTest.java + * -@TestCaseName: Test jvm instr: invoke static thrown ExceptionInInitializerError. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a static variable that initialize will be fault of a class. + * -#step2: Test static method of the class. + * -#step3: Check ExceptionInInitializerError is caught by catch. + * -#step4: Try test static method of the class. + * -#step5: Check NoClassDefFoundError is caught by catch. + * -@Expect: 0\n + * -@Priority: High + * -@Source: JvmStaticExceptionInInitializerErrorTest.java + * -@ExecuteClass: JvmStaticExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +class JvmStaticExceptionInInitializerErrorTesta { + static int other_class_test_field = 21; + static int local_field = 5 / 0; + + static int testFail() { + int aNum = 1; + return aNum; + } +} + +public class JvmStaticExceptionInInitializerErrorTest { + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + try { + int tmp = JvmStaticExceptionInInitializerErrorTesta.testFail(); + } catch (ExceptionInInitializerError e1) { + try { + int tmp = JvmStaticExceptionInInitializerErrorTesta.testFail(); + } catch (NoClassDefFoundError e2) { + return 0; // STATUS_PASSED + } + } + return 2; // STATUS_FAILED + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0067-rt-eh-JvmStaticExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0067-rt-eh-JvmStaticExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..36ed09bfc64ae963c10b0ecc26cfce3f2a97a47c --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0067-rt-eh-JvmStaticExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=JvmStaticExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0073-rt-eh-MultiTryNoExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0073-rt-eh-MultiTryNoExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..c4c05eb6aae4cf0ad30e626e87a462916980902c --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0073-rt-eh-MultiTryNoExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=MultiTryNoExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0073-rt-eh-MultiTryNoExceptionTest/MultiTryNoExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0073-rt-eh-MultiTryNoExceptionTest/MultiTryNoExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..1cfc2b20fdab25e77cb17bd6a41ddccd24664f03 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0073-rt-eh-MultiTryNoExceptionTest/MultiTryNoExceptionTest.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MultiTryNoExceptionTest.java + * -@TestCaseName: Test no Exception in try-multi catch-finally. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number in double try-multi catch-finally. + * -#step2: Test static int parseInt(String s) in double try-multi catch-finally. + * -#step3: Check method is invoke correctly, no Exception is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: MultiTryNoExceptionTest.java + * -@ExecuteClass: MultiTryNoExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class MultiTryNoExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = multiTryNoExceptionTest1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 1 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test no Exception in try-multi catch-finally. + * + * @return status code + */ + public static int multiTryNoExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123456"; + try { + try { + Integer.parseInt(str); + } catch (ClassCastException e) { + result1 = 3; + } catch (IllegalStateException e) { + result1 = 3; + } catch (IndexOutOfBoundsException e) { + result1 = 3; + } finally { + processResult--; + } + processResult--; + } catch (ClassCastException e) { + result1 = 3; + } catch (IllegalStateException e) { + result1 = 3; + } catch (IndexOutOfBoundsException e) { + result1 = 3; + } finally { + processResult--; + result1 = 1; + } + processResult--; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0074-rt-eh-TryCatchReturnExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0074-rt-eh-TryCatchReturnExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..bbb6a233d1d594485b7b18d05d6aa4a6e1182f00 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0074-rt-eh-TryCatchReturnExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryCatchReturnExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0074-rt-eh-TryCatchReturnExceptionTest/TryCatchReturnExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0074-rt-eh-TryCatchReturnExceptionTest/TryCatchReturnExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5008ee0705f42acfad84653d032129c786b939d9 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0074-rt-eh-TryCatchReturnExceptionTest/TryCatchReturnExceptionTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryCatchReturnExceptionTest.java + * -@TestCaseName: Test try{exception return_x}-catch(e){return_x}-finally{return_v}. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s). + * -#step3: Check NumberFormatException is caught by catch. + * -#step4: Return value in the catch. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryCatchReturnExceptionTest.java + * -@ExecuteClass: TryCatchReturnExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryCatchReturnExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryCatchReturnExceptionTest1(); + } catch (NumberFormatException e) { + processResult -= 10; + } + + if (result == 2 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Test try{exception return_x}-catch(e){return_x}-finally{return_v}. + * + * @return status code + */ + public static int tryCatchReturnExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + return processResult; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + processResult -= 1; + result1 = 1; + return result1; + } catch (IllegalStateException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult -= 3; + result1++; + return result1; // Execute return 2 + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0075-rt-eh-TryReturnValueExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0075-rt-eh-TryReturnValueExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..8561302de6676f47587f9ab0cb13f608fd4ea435 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0075-rt-eh-TryReturnValueExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryReturnValueExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0075-rt-eh-TryReturnValueExceptionTest/TryReturnValueExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0075-rt-eh-TryReturnValueExceptionTest/TryReturnValueExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..bdeb212af0a7dd582ee29044b8c37eb3997f9394 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0075-rt-eh-TryReturnValueExceptionTest/TryReturnValueExceptionTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryReturnValueExceptionTest.java + * -@TestCaseName: try{return_v}-catch(x){return_x}-finally{return_x} + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number. + * -#step2: Test static int parseInt(String s). + * -#step3: Return value in try, no exception is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryReturnValueExceptionTest.java + * -@ExecuteClass: TryReturnValueExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryReturnValueExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryReturnValueExceptionTest1(); + } catch (NumberFormatException e) { + processResult -= 10; + } + + if (result == 5 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * try{return_v}-catch(x){return_x}-finally{return_x} + * + * @return status code + */ + public static int tryReturnValueExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123456"; + try { + Integer.parseInt(str); + return result1; // Execute return result1++. + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + return 3; + } catch (NumberFormatException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + return 3; + } catch (IllegalStateException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + return 3; + } finally { + processResult -= 4; + result1++; + return result1; + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0076-rt-eh-TryCatchReturnValueExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0076-rt-eh-TryCatchReturnValueExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..8742b51a7bf67e005fba4af73579f5bf9601ffe6 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0076-rt-eh-TryCatchReturnValueExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=TryCatchReturnValueExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0076-rt-eh-TryCatchReturnValueExceptionTest/TryCatchReturnValueExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0076-rt-eh-TryCatchReturnValueExceptionTest/TryCatchReturnValueExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..aeb76ca8cabde4ab411f50dd8e603f4591b9adf5 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0076-rt-eh-TryCatchReturnValueExceptionTest/TryCatchReturnValueExceptionTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TryCatchReturnValueExceptionTest.java + * -@TestCaseName: Try{exception return_x}-catch(e){return_v}-finally{}. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a String s include number and special symbol. + * -#step2: Test static int parseInt(String s). + * -#step3: NumberFormatException is caught by catch, return value in catch. + * -@Expect: 0\n + * -@Priority: High + * -@Source: TryCatchReturnValueExceptionTest.java + * -@ExecuteClass: TryCatchReturnValueExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class TryCatchReturnValueExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = tryCatchReturnValueExceptionTest1(); + } catch (NumberFormatException e) { + processResult -= 10; + } + + if (result == 1 && processResult == 95) { + result = 0; + } + return result; + } + + /** + * Try{exception return_x}-catch(e){return_v}-finally{}. + * + * @return status code + */ + public static int tryCatchReturnValueExceptionTest1() { + int result1 = 4; /* STATUS_FAILED */ + String str = "123#456"; + try { + Integer.parseInt(str); + return processResult; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + processResult--; + result1 = 1; + return result1; // Execute return 1. + } catch (IllegalStateException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult -= 3; + result1++; + } + processResult -= 10; + return processResult; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0077-rt-eh-ExcpReturn04140/ExcpReturn04140.java b/test/testsuite/ouroboros/eh_test/RT0077-rt-eh-ExcpReturn04140/ExcpReturn04140.java new file mode 100755 index 0000000000000000000000000000000000000000..cdf4889ab1312cb5cbb46b2787a825fdc0d9d134 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0077-rt-eh-ExcpReturn04140/ExcpReturn04140.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ExcpReturn04140.java + * -@TestCaseName: try{exception return_x}-catch(e){}-finally{},return_v + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:occur exception in try{} + * -#step2:catch by catch{} + * -#step3:excute finally{} + * -#step4:excute return{} + * -@Expect:0\n + * -@Priority: High + * -@Source: ExcpReturn04140.java + * -@ExecuteClass: ExcpReturn04140 + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ExcpReturn04140 { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = excpReturn041401(); + } catch (NumberFormatException e) { + processResult -= 10; + } + + if (result == 2 && processResult == 95) { + result = 0; + } + + return result; + } + + /** + * try{exception return_x}-catch(e){}-finally{},return_v + * + * @return status code + */ + public static int excpReturn041401() { + int result1 = 4; /*STATUS_FAILED*/ + + String str = "123#456"; + try { + Integer.parseInt(str); + return processResult; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (NumberFormatException e) { + processResult--; + result1 = 1; + } catch (IllegalStateException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } finally { + processResult--; + result1++; + } + processResult -= 2; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0077-rt-eh-ExcpReturn04140/Makefile b/test/testsuite/ouroboros/eh_test/RT0077-rt-eh-ExcpReturn04140/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..b9b4e683a67e8a655e5f9eb9fcad24cb04fe8c15 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0077-rt-eh-ExcpReturn04140/Makefile @@ -0,0 +1,3 @@ +APP=ExcpReturn04140 +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0078-rt-eh-ExcpReturn04150/ExcpReturn04150.java b/test/testsuite/ouroboros/eh_test/RT0078-rt-eh-ExcpReturn04150/ExcpReturn04150.java new file mode 100755 index 0000000000000000000000000000000000000000..841403302f71cc8d91a07b5f101ad05cb5663a5d --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0078-rt-eh-ExcpReturn04150/ExcpReturn04150.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ExcpReturn04150.java + * -@TestCaseName: try{exception return_x}-catch(x){}-finally{return_v},-->caller(x) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:occur EH it try{} when return + * -#step2:no catch in catch{} + * -#step3:excute finally{} + * -#step4:catch by caller + * -@Expect:0\n + * -@Priority: High + * -@Source: ExcpReturn04150.java + * -@ExecuteClass: ExcpReturn04150 + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ExcpReturn04150 { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = excpReturn04150(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 5 && processResult == 95) { + result = 0; + } + + return result; + } + + /** + * try{exception return_x}-catch(x){}-finally{return_v},-->caller(x) + * + * @return status code + */ + public static int excpReturn04150() { + int result1 = 4; /*STATUS_FAILED*/ + + String str = "123#456"; + try { + Integer.parseInt(str); + return processResult; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + return result1; + } catch (StringIndexOutOfBoundsException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + return result1; + } catch (IllegalStateException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + return result1; + } finally { + processResult -= 4; + result1++; + return result1; // execute return 5 + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0078-rt-eh-ExcpReturn04150/Makefile b/test/testsuite/ouroboros/eh_test/RT0078-rt-eh-ExcpReturn04150/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..b896dcd7f196b5e133dedb098feebcbebf3f02ff --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0078-rt-eh-ExcpReturn04150/Makefile @@ -0,0 +1,3 @@ +APP=ExcpReturn04150 +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0079-rt-eh-ExcpReturn04160/ExcpReturn04160.java b/test/testsuite/ouroboros/eh_test/RT0079-rt-eh-ExcpReturn04160/ExcpReturn04160.java new file mode 100755 index 0000000000000000000000000000000000000000..6cca0904e76d6ff3c4aa902c539cb8dc2ff4edec --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0079-rt-eh-ExcpReturn04160/ExcpReturn04160.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ExcpReturn04160.java + * -@TestCaseName: try{exception return_x}-catch(x){}-finally{},return_x-->caller(v) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:occur exception in try{} when retrun + * -#step2:cannot catch by catch{} + * -#step3:excute finally{} + * -#step4:cannot excute return{} + * -#step5:catch by caller + * -@Expect:0\n + * -@Priority: High + * -@Source: ExcpReturn04160.java + * -@ExecuteClass: ExcpReturn04160 + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ExcpReturn04160 { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = excpReturn04160(); + } catch (Exception e) { + processResult -= 2; + } + + if (result == 2 && processResult == 95) { + result = 0; + } + + return result; + } + + /** + * try{exception return_x}-catch(x){}-finally{},return_x-->caller(v) + * + * @return status code + */ + public static int excpReturn04160() { + int result1 = 4; /*STATUS_FAILED*/ + + String str = "123#456"; + try { + Integer.parseInt(str); + return processResult; + } catch (ClassCastException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + } catch (StringIndexOutOfBoundsException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + return result1; + } catch (IllegalStateException e) { + System.out.println("=====See:ERROR!!!"); + result1 = 3; + return result1; + } finally { + processResult -= 2; + result1++; + } + processResult -= 10; + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0079-rt-eh-ExcpReturn04160/Makefile b/test/testsuite/ouroboros/eh_test/RT0079-rt-eh-ExcpReturn04160/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..81d0f96a55fff8e7ea0458377b415894561b8454 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0079-rt-eh-ExcpReturn04160/Makefile @@ -0,0 +1,3 @@ +APP=ExcpReturn04160 +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0516-rt-eh-AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest/AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0516-rt-eh-AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest/AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b17652d6562dabca10dfb150f195d82800469b00 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0516-rt-eh-AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest/AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest.java + * -@TestCaseName: Exception in addSuppressed:public T[] getAnnotationsByType(Class annotationClass). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Get AccessibleObject object by getMethod(String name,Class... parameterTypes). + * -#step2: Test method getAnnotationsByType(), parameter annotationClass is null. + * -#step3: Check that if NullPointerException occurs. + * -@Expect: 0\n + * -@Priority: High + * -@Source: AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest.java + * -@ExecuteClass: AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.AccessibleObject; + +public class AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = accessibleObjectgAnnotationsByTypeNullPointerException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in addSuppressed:public T[] getAnnotationsByType(Class annotationClass). + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int accessibleObjectgAnnotationsByTypeNullPointerException() + throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + AccessibleObject accessibleObject = Test013.class.getMethod("getName", new Class[]{}); + try { + Object file1 = accessibleObject.getAnnotationsByType(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + return result1; + } +} + +class Test013 { + private String name = "default"; + + public String getName() { + return name; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0516-rt-eh-AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0516-rt-eh-AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..0d18d38e773feab835f3cc1b2760f9f25dfc55e7 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0516-rt-eh-AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=AccessibleObjectGetAnnotationsByTypeNullPointerExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0517-rt-eh-AccessibleObjectGetDeclaredAnnotationExceptionTest/AccessibleObjectGetDeclaredAnnotationExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0517-rt-eh-AccessibleObjectGetDeclaredAnnotationExceptionTest/AccessibleObjectGetDeclaredAnnotationExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ce027fe4ebe1f91c524c2e42d484864ae00ca830 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0517-rt-eh-AccessibleObjectGetDeclaredAnnotationExceptionTest/AccessibleObjectGetDeclaredAnnotationExceptionTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectGetDeclaredAnnotationExceptionTest.java + * -@TestCaseName: Exception in AccessibleObject: T getDeclaredAnnotation(Class annotationClass). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Get AccessibleObject by getMethod(String name,Class... parameterTypes). + * -#step2: Test method getDeclaredAnnotation(Class annotationClass), Create parameter annotationClass is null. + * -#step3: Check that if NullPointerException occurs. + * -@Expect: 0\n + * -@Priority: High + * -@Source: AccessibleObjectGetDeclaredAnnotationExceptionTest.java + * -@ExecuteClass: AccessibleObjectGetDeclaredAnnotationExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.AccessibleObject; + +public class AccessibleObjectGetDeclaredAnnotationExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + try { + result = accessibleObjectgDeclaredAnnotationNullPointerException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in AccessibleObject: T getDeclaredAnnotation(Class annotationClass). + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int accessibleObjectgDeclaredAnnotationNullPointerException() + throws NoSuchMethodException, SecurityException { + int result1 = 4; /* STATUS_FAILED */ + AccessibleObject accessibleObject = Test02aa.class.getMethod("getName", new Class[]{}); + try { + Object file1 = accessibleObject.getDeclaredAnnotation(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + return result1; + } +} + +class Test02aa { + private String name = "default"; + + public String getName() { + return name; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0517-rt-eh-AccessibleObjectGetDeclaredAnnotationExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0517-rt-eh-AccessibleObjectGetDeclaredAnnotationExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..74c6069c32017bbb29ca77516c156cdfc9d2ab3b --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0517-rt-eh-AccessibleObjectGetDeclaredAnnotationExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=AccessibleObjectGetDeclaredAnnotationExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0518-rt-eh-AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest/AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0518-rt-eh-AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest/AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0c3fd5e7f93f1013b61dc6b6afbd48b0c7a78db9 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0518-rt-eh-AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest/AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest.java + * -@TestCaseName: Exception in AccessibleObject:public T[] getAnnotationsByType(Class annotationClass). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Get AccessibleObject object by getMethod(String name,Class... parameterTypes). + * -#step2: Test method getAnnotationsByType(Class annotationClass), create parameter annotationClass is null. + * -#step3: Check that NullPointerException thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest.java + * -@ExecuteClass: AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.AccessibleObject; + +public class AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = accessibleObjectgDeclaredAnnotationsByTypeNullPointerException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in AccessibleObject:public T[] getAnnotationsByType(Class annotationClass). + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int accessibleObjectgDeclaredAnnotationsByTypeNullPointerException() + throws NoSuchMethodException, SecurityException { + int result1 = 4; /* STATUS_FAILED */ + + AccessibleObject mt = Test01a.class.getMethod("getName", new Class[]{}); + + try { + Object file1 = mt.getDeclaredAnnotationsByType(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult -= 1; + } + return result1; + } +} + +class Test01a { + private String name = "default"; + + public String getName() { + return name; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0518-rt-eh-AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0518-rt-eh-AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..64bee33a2e476ddffc93514c7180ad9e7dbc31f2 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0518-rt-eh-AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=AccessibleObjectGetDeclaredAnnotationsByTypeExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0519-rt-eh-CharacterCodePointCountIndexOutOfBoundsExceptionTest/CharacterCodePointCountIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0519-rt-eh-CharacterCodePointCountIndexOutOfBoundsExceptionTest/CharacterCodePointCountIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..097ba5feed83a73fb72f3422e5622948cb3d057a --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0519-rt-eh-CharacterCodePointCountIndexOutOfBoundsExceptionTest/CharacterCodePointCountIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterCodePointCountIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Exception in Character: public static int codePointCount(char[] seq, int offset, int count), + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * case1: + * -#step1: Create char[] seq, create offset >=0, count > seq.length. + * -#step2: Test method codePointCount(char[] seq, int offset, int count). + * -#step3: Check that IndexOutOfBoundsException thrown correctly. + * case2: + * -#step1: Define CharSequence seq, create offset >=0, count > seq.length. + * -#step2: Test method codePointCount(CharSequence seq, int beginIndex, int endIndex). + * -#step3: Check that IndexOutOfBoundsException thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: CharacterCodePointCountIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: CharacterCodePointCountIndexOutOfBoundsExceptionTest + */ + +import java.io.PrintStream; + +public class CharacterCodePointCountIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = charactercodePointCountIndexOutOfBoundsException1(); + } catch (Exception e) { + processResult -= 20; + } + + try { + result = charactercodePointCountIndexOutOfBoundsException2(); + } catch (Exception e) { + processResult -= 40; + } + + if (result == 4 && processResult == 97) { + result = 0; + } + + return result; + } + + /** + * Test method codePointCount(char[] seq, int offset, int count). + * + * @return status code + */ + public static int charactercodePointCountIndexOutOfBoundsException1() { + int result1 = 4; /*STATUS_FAILED*/ + + char[] chars = new char[]{'a', 'b', 'c', 'd', 'e'}; + int offset = 1; + int count = 10; + try { + int obj = Character.codePointCount(chars, offset, count); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult -= 1; + } + + return result1; + } + + /** + * Test method codePointCount(CharSequence seq, int beginIndex, int endIndex). + * + * @return status code + */ + public static int charactercodePointCountIndexOutOfBoundsException2() { + int result1 = 4; /*STATUS_FAILED*/ + + CharSequence seq = "a b c d e"; + int offset = 1; + int count = 10; + try { + int obj = Character.codePointCount(seq, offset, count); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0519-rt-eh-CharacterCodePointCountIndexOutOfBoundsExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0519-rt-eh-CharacterCodePointCountIndexOutOfBoundsExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..e348668215c9bba8d297c8ed3c9b008e3f0f92f4 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0519-rt-eh-CharacterCodePointCountIndexOutOfBoundsExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=CharacterCodePointCountIndexOutOfBoundsExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0520-rt-eh-CharactercodePointCountNullPointerException/CharactercodePointCountNullPointerException.java b/test/testsuite/ouroboros/eh_test/RT0520-rt-eh-CharactercodePointCountNullPointerException/CharactercodePointCountNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..592cf83dbd2a3367f9124c02b7f91403f99cfad0 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0520-rt-eh-CharactercodePointCountNullPointerException/CharactercodePointCountNullPointerException.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharactercodePointCountNullPointerException.java + * -@TestCaseName: Exception in Character:public static int codePointCount + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:codePointCount(CharSequence seq, int beginIndex, int endIndex),seq is null + * -#step2:catch Exception + * -@Expect:0\n + * -@Priority: High + * -@Source: CharactercodePointCountNullPointerException.java + * -@ExecuteClass: CharactercodePointCountNullPointerException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class CharactercodePointCountNullPointerException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = charactercodePointCountNullPointerException(); + } catch (Exception e) { + processResult -= 20; + } + + try { + result = charactercodePointCountNullPointerException2(); + } catch (Exception e) { + processResult -= 40; + } + + if (result == 4 && processResult == 97) { + result = 0; + } + + return result; + } + + /** + * codePointCount(char[] a, int offset, int count),a is null,catch NullPointerException + * + * @return status code + */ + public static int charactercodePointCountNullPointerException() { + int result1 = 4; /*STATUS_FAILED*/ + + // NullPointerException - if seq is null. + // + // public static int codePointCount(char[] a, int offset, int count) + int offset = 1; + int count = 4; + char[] chars = null; + try { + int obj = Character.codePointCount(chars, offset, count); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + + return result1; + } + + /** + * codePointCount(CharSequence seq, int beginIndex, int endIndex), seq is null,catch NullPointerException + * + * @return status code + */ + public static int charactercodePointCountNullPointerException2() { + int result1 = 4; /*STATUS_FAILED*/ + + // NullPointerException - if seq is null. + // + // public static int codePointCount(CharSequence seq, int beginIndex, int endIndex) + int offset = 1; + int count = 4; + CharSequence seq = null; + try { + int obj = Character.codePointCount(seq, offset, count); + processResult -= 30; + } catch (NullPointerException e1) { + processResult--; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0520-rt-eh-CharactercodePointCountNullPointerException/Makefile b/test/testsuite/ouroboros/eh_test/RT0520-rt-eh-CharactercodePointCountNullPointerException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..67175ee35a0c09165df455832864a127c1874769 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0520-rt-eh-CharactercodePointCountNullPointerException/Makefile @@ -0,0 +1,3 @@ +APP=CharactercodePointCountNullPointerException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0521-rt-eh-CharacteroffsetByCodePointsIndexOutOfBoundsException/CharacteroffsetByCodePointsIndexOutOfBoundsException.java b/test/testsuite/ouroboros/eh_test/RT0521-rt-eh-CharacteroffsetByCodePointsIndexOutOfBoundsException/CharacteroffsetByCodePointsIndexOutOfBoundsException.java new file mode 100755 index 0000000000000000000000000000000000000000..bee656337f767a73188eabf2cad512227a056b9e --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0521-rt-eh-CharacteroffsetByCodePointsIndexOutOfBoundsException/CharacteroffsetByCodePointsIndexOutOfBoundsException.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacteroffsetByCodePointsIndexOutOfBoundsException.java + * -@TestCaseName: Exception in Character:public static int offsetByCodePoints + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:prepare index out of bounds + * -#step2:invoke offsetByCodePoints with Parameters of step1 + * -#step3:catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacteroffsetByCodePointsIndexOutOfBoundsException.java + * -@ExecuteClass: CharacteroffsetByCodePointsIndexOutOfBoundsException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class CharacteroffsetByCodePointsIndexOutOfBoundsException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = characteroffsetByCodePointsIndexOutOfBoundsException1(); + } catch (Exception e) { + processResult -= 20; + } + + try { + result = characteroffsetByCodePointsIndexOutOfBoundsException2(); + } catch (Exception e) { + processResult -= 40; + } + + if (result == 4 && processResult == 97) { + result = 0; + } + + return result; + } + + /** + * offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset), check IndexOutOfBoundsException + * + * @return status code + */ + public static int characteroffsetByCodePointsIndexOutOfBoundsException1() { + int result1 = 4; /*STATUS_FAILED*/ + + // IndexOutOfBoundsException -if start or count is negative, or if start + count is larger than the length + // of the given array, or if index is less than start or larger then start + count, or if codePointOffset + // is positive and the text range starting with index and ending with start + count - 1 has fewer than + // codePointOffset code points, or if codePointOffset is negative and the text range starting with start and + // ending with index - 1 has fewer than the absolute value of codePointOffset code points. + // + // public static int offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset) + int offset = 0; + int count = 10; + char[] chars = new char[]{'a', 'b', 'c', 'd', 'e'}; + try { + int obj = Character.offsetByCodePoints(chars, offset, count, 0, 0); + System.out.println(obj); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + return result1; + } + + /** + * offsetByCodePoints(CharSequence seq, int index, int codePointOffset), catch IndexOutOfBoundsException + * + * @return status code + */ + public static int characteroffsetByCodePointsIndexOutOfBoundsException2() { + int result1 = 4; /*STATUS_FAILED*/ + + // IndexOutOfBoundsException -if start or count is negative, or if start + count is larger than the length + // of the given array, or if index is less than start or larger then start + count, or if codePointOffset + // is positive and the text range starting with index and ending with start + count - 1 has fewer than + // codePointOffset code points, or if codePointOffset is negative and the text range starting with start and + // ending with index - 1 has fewer than the absolute value of codePointOffset code points. + // + // public static int offsetByCodePoints(CharSequence seq, int index, int codePointOffset) + + int offset = 0; + int count = 10; + CharSequence seq = "a b c d e"; + try { + int obj = Character.offsetByCodePoints(seq, offset, count); + System.out.println(obj); + processResult -= 30; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0521-rt-eh-CharacteroffsetByCodePointsIndexOutOfBoundsException/Makefile b/test/testsuite/ouroboros/eh_test/RT0521-rt-eh-CharacteroffsetByCodePointsIndexOutOfBoundsException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..69ed48a4fc240d0eccd0291cb05e0cec79021017 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0521-rt-eh-CharacteroffsetByCodePointsIndexOutOfBoundsException/Makefile @@ -0,0 +1,3 @@ +APP=CharacteroffsetByCodePointsIndexOutOfBoundsException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0522-rt-eh-CharacteroffsetByCodePointsNullPointerException/CharacteroffsetByCodePointsNullPointerException.java b/test/testsuite/ouroboros/eh_test/RT0522-rt-eh-CharacteroffsetByCodePointsNullPointerException/CharacteroffsetByCodePointsNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..6591d219fdfaafef9f806a43ea4ddb292e28c708 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0522-rt-eh-CharacteroffsetByCodePointsNullPointerException/CharacteroffsetByCodePointsNullPointerException.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacteroffsetByCodePointsNullPointerException.java + * -@TestCaseName: Exception in Character:public static int offsetByCodePoints + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief:offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset),a is null,occur NPE + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacteroffsetByCodePointsNullPointerException.java + * -@ExecuteClass: CharacteroffsetByCodePointsNullPointerException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class CharacteroffsetByCodePointsNullPointerException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + ; + try { + result = characteroffsetByCodePointsNullPointerException1(); + } catch (Exception e) { + processResult -= 20; + } + + try { + result = characteroffsetByCodePointsNullPointerException2(); + } catch (Exception e) { + processResult -= 40; + } + + if (result == 4 && processResult == 97) { + result = 0; + } + + return result; + } + + /** + * offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset), catch NullPointerException + * + * @return status code + */ + public static int characteroffsetByCodePointsNullPointerException1() { + int result1 = 4; /*STATUS_FAILED*/ + + // NullPointerException - if seq is null. + // + // public static int offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset) + int offset = 1; + int count = 4; + char[] chars = null; + try { + int obj = Character.offsetByCodePoints(chars, offset, count, 0, 2); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + + return result1; + } + + /** + * offsetByCodePoints(CharSequence seq, int index, int codePointOffset), catch NullPointerException + * + * @return status code + */ + public static int characteroffsetByCodePointsNullPointerException2() { + int result1 = 4; /*STATUS_FAILED*/ + + // NullPointerException - if seq is null. + // + // public static int offsetByCodePoints(CharSequence seq, int index, int codePointOffset) + + int offset = 1; + int count = 4; + CharSequence seq = null; + try { + int obj = Character.offsetByCodePoints(seq, offset, count); + processResult -= 30; + } catch (NullPointerException e1) { + processResult--; + } + + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0522-rt-eh-CharacteroffsetByCodePointsNullPointerException/Makefile b/test/testsuite/ouroboros/eh_test/RT0522-rt-eh-CharacteroffsetByCodePointsNullPointerException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..7206fab20cd84bb951ec050add0df11becacbf44 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0522-rt-eh-CharacteroffsetByCodePointsNullPointerException/Makefile @@ -0,0 +1,3 @@ +APP=CharacteroffsetByCodePointsNullPointerException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0523-rt-eh-ClassasSubclassClassCastException/ClassasSubclassClassCastException.java b/test/testsuite/ouroboros/eh_test/RT0523-rt-eh-ClassasSubclassClassCastException/ClassasSubclassClassCastException.java new file mode 100755 index 0000000000000000000000000000000000000000..37f90f3bdceb312deb4f8cf8aa42e3e39570b1d0 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0523-rt-eh-ClassasSubclassClassCastException/ClassasSubclassClassCastException.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassasSubclassClassCastException.java + * -@TestCaseName: Exception in Class:public Class asSubclass(Class clazz) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:create "subclass" includes the class itself + * -#step2:this Class object does not represent a subclass of the specified class + * -#step3:catch exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassasSubclassClassCastException.java + * -@ExecuteClass: ClassasSubclassClassCastException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.List; + +public class ClassasSubclassClassCastException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = classAsSubclassClassCastException(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * asSubclass(Class clazz), check ClassCastException + * + * @return status code + */ + public static int classAsSubclassClassCastException() { + int result1 = 4; /*STATUS_FAILED*/ + + // ClassCastException - if this Class object does not represent a subclass of the specified class + // (here "subclass" includes the class itself). + // + // public Class asSubclass(Class clazz) + La1 la1 = new La1(); + try { + Class strListCast = la1.getClass().asSubclass(List.class); + processResult -= 10; + } catch (ClassCastException e1) { + processResult -= 1; + } + + return result1; + } +} + +class La1 { + /** + * just for test + */ + public int field1 = 1; + /** + * just for test + */ + public static int[] field2 = {1, 2, 3, 4}; + /** + * just for test + */ + public static int field3 = field2[3]; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0523-rt-eh-ClassasSubclassClassCastException/Makefile b/test/testsuite/ouroboros/eh_test/RT0523-rt-eh-ClassasSubclassClassCastException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..8e2f739fa9a737d34e5d149ba6142176bc49f791 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0523-rt-eh-ClassasSubclassClassCastException/Makefile @@ -0,0 +1,3 @@ +APP=ClassasSubclassClassCastException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0524-rt-eh-ClasscastClassCastException/ClasscastClassCastException.java b/test/testsuite/ouroboros/eh_test/RT0524-rt-eh-ClasscastClassCastException/ClasscastClassCastException.java new file mode 100755 index 0000000000000000000000000000000000000000..d0860e8af42c103042ff7cad8d58e8c7afcfa995 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0524-rt-eh-ClasscastClassCastException/ClasscastClassCastException.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClasscastClassCastException.java + * -@TestCaseName: Exception in Class:public T cast(Object obj) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: this Class object does not represent a subclass of the specified class + * -#step2: catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: ClasscastClassCastException.java + * -@ExecuteClass: ClasscastClassCastException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ClasscastClassCastException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = classCastClassCastException(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in Class:public T cast(Object obj) + * + * @return status code + */ + public static int classCastClassCastException() { + int result1 = 4; /*STATUS_FAILED*/ + + // ClassCastException - if this Class object does not represent a subclass of the specified class + // (here "subclass" includes the class itself). + // + // public T cast(Object obj) + Object obj1 = new Cast1(); + Cast2 cast22 = new Cast2(); + try { + Object type1 = Cast1.class.cast(cast22); + System.out.println(type1.getClass()); + processResult -= 10; + } catch (ClassCastException e1) { + processResult -= 1; + } + + return result1; + } +} + +class Cast1 { + String str1 = "str1"; + + /** + * set String method1 + */ + public static void setStr() { + String method1 = "1"; + } +} + +class Cast2 { + String str2 = "str2"; + + /** + * set String method2 + */ + public static void setInt() { + int method2 = 2; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0524-rt-eh-ClasscastClassCastException/Makefile b/test/testsuite/ouroboros/eh_test/RT0524-rt-eh-ClasscastClassCastException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..2eb20ed8f2d54f9afb8f4b4909438178e3eb8b4a --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0524-rt-eh-ClasscastClassCastException/Makefile @@ -0,0 +1,3 @@ +APP=ClasscastClassCastException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0525-rt-eh-ClassforName1ParExceptionInInitializerError/ClassforName1ParExceptionInInitializerError.java b/test/testsuite/ouroboros/eh_test/RT0525-rt-eh-ClassforName1ParExceptionInInitializerError/ClassforName1ParExceptionInInitializerError.java new file mode 100755 index 0000000000000000000000000000000000000000..db6a1650f5a3c46ca933133858db38050c5993b4 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0525-rt-eh-ClassforName1ParExceptionInInitializerError/ClassforName1ParExceptionInInitializerError.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassforName1ParExceptionInInitializerError.java + * -@TestCaseName: Exception in Class :public static Class forName(String name, boolean initialize, ClassLoader loader) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:prepare a Class contain RuntimeEH in its static block + * -#step2:catch InInitializerError + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassforName1ParExceptionInInitializerError.java + * -@ExecuteClass: ClassforName1ParExceptionInInitializerError + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ClassforName1ParExceptionInInitializerError { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = classForName1ParExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in Class :public static Class forName(String name, boolean initialize, ClassLoader loader) + * + * @return status code + * @throws ClassNotFoundException + */ + public static int classForName1ParExceptionInInitializerError() throws ClassNotFoundException { + int result1 = 4; /*STATUS_FAILED*/ + + // ExceptionInInitializerError - if the initialization provoked by this method fails + // + // public static Class forName(String className) + Class cls = Class.forName("ClassforName1ParExceptionInInitializerError"); + ClassLoader cLoader = cls.getClassLoader(); + + try { + Class cls2 = Class.forName("Cast6"); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class Cast6 { + String str1 = "str1"; + + /** + * set String method1 + */ + public static void setStr() { + String method1 = "1"; + } + + static { + int num = 1 / 0; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0525-rt-eh-ClassforName1ParExceptionInInitializerError/Makefile b/test/testsuite/ouroboros/eh_test/RT0525-rt-eh-ClassforName1ParExceptionInInitializerError/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..6f9221ce147dae2aceeea0fa496d52f24749d2a7 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0525-rt-eh-ClassforName1ParExceptionInInitializerError/Makefile @@ -0,0 +1,3 @@ +APP=ClassforName1ParExceptionInInitializerError +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0526-rt-eh-ClassforNameExceptionInInitializerError/ClassforNameExceptionInInitializerError.java b/test/testsuite/ouroboros/eh_test/RT0526-rt-eh-ClassforNameExceptionInInitializerError/ClassforNameExceptionInInitializerError.java new file mode 100755 index 0000000000000000000000000000000000000000..3d2a70ea161921f2a923ef748ad83b68b0583cbf --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0526-rt-eh-ClassforNameExceptionInInitializerError/ClassforNameExceptionInInitializerError.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassforNameExceptionInInitializerError.java + * -@TestCaseName: Exception in Class :public static Class forName(String name, boolean initialize, ClassLoader loader) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:Class contain RuntimeEH in its static block + * -#step2:Init by Class.forName,occur InitializerError + * -#step3:catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassforNameExceptionInInitializerError.java + * -@ExecuteClass: ClassforNameExceptionInInitializerError + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ClassforNameExceptionInInitializerError { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = classForNameExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in Class :public static Class forName(String name, boolean initialize, ClassLoader loader) + * + * @return status code + * @throws ClassNotFoundException + */ + public static int classForNameExceptionInInitializerError() throws ClassNotFoundException { + int result1 = 4; /*STATUS_FAILED*/ + + // ExceptionInInitializerError - if the initialization provoked by this method fails + // + // public static Class forName(String name, boolean initialize, ClassLoader loader) + Class cls = Class.forName("ClassforNameExceptionInInitializerError"); + ClassLoader cLoader = cls.getClassLoader(); + + try { + Class cls2 = Class.forName("Cast5", true, cLoader); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class Cast5 { + String str1 = "str1"; + + /** + * set String method1 + */ + public static void setStr() { + String method1 = "1"; + } + + static { + int num = 1 / 0; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0526-rt-eh-ClassforNameExceptionInInitializerError/Makefile b/test/testsuite/ouroboros/eh_test/RT0526-rt-eh-ClassforNameExceptionInInitializerError/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..cee6ea8f06fbf06fee2144d44eb0786e2c6bf3ec --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0526-rt-eh-ClassforNameExceptionInInitializerError/Makefile @@ -0,0 +1,3 @@ +APP=ClassforNameExceptionInInitializerError +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0527-rt-eh-ClassgAnnotationsByTypeNullPointerException/ClassgAnnotationsByTypeNullPointerException.java b/test/testsuite/ouroboros/eh_test/RT0527-rt-eh-ClassgAnnotationsByTypeNullPointerException/ClassgAnnotationsByTypeNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..f9d136ff812871f81923a6f435f50ff9e4c03bd6 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0527-rt-eh-ClassgAnnotationsByTypeNullPointerException/ClassgAnnotationsByTypeNullPointerException.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassgAnnotationsByTypeNullPointerException.java + * -@TestCaseName:Exception in AccessibleObject:public A[] getAnnotationsByType(Class annotationClass) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:annotaitonClass is null,invoke getAnnotationsByType(Class annotationClass) + * -#step2:catch NPE + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassgAnnotationsByTypeNullPointerException.java + * -@ExecuteClass: ClassgAnnotationsByTypeNullPointerException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ClassgAnnotationsByTypeNullPointerException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = classGAnnotationsByTypeNullPointerException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in AccessibleObject:public A[] getAnnotationsByType(Class annotationClass) + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int classGAnnotationsByTypeNullPointerException() throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + + // NullPointerException- Null pointer exception + // public A[] getAnnotationsByType(Class annotationClass) + + Class class1 = Class.class; + + try { + Object file1 = class1.getAnnotationsByType(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + return result1; + } +} + +class Test01c { + private String name = "default"; + + public String getName() { + return name; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0527-rt-eh-ClassgAnnotationsByTypeNullPointerException/Makefile b/test/testsuite/ouroboros/eh_test/RT0527-rt-eh-ClassgAnnotationsByTypeNullPointerException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..a9261e8cf54cd78e08e0de7d1bf2592c62fb77fd --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0527-rt-eh-ClassgAnnotationsByTypeNullPointerException/Makefile @@ -0,0 +1,3 @@ +APP=ClassgAnnotationsByTypeNullPointerException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0528-rt-eh-ClassgetDeclaredAnnotationNullPointerException/ClassgetDeclaredAnnotationNullPointerException.java b/test/testsuite/ouroboros/eh_test/RT0528-rt-eh-ClassgetDeclaredAnnotationNullPointerException/ClassgetDeclaredAnnotationNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..e9a517e049fca17ebd80950f4f564e25fce84967 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0528-rt-eh-ClassgetDeclaredAnnotationNullPointerException/ClassgetDeclaredAnnotationNullPointerException.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassgetDeclaredAnnotationNullPointerException.java + * -@TestCaseName: Exception in AccessibleObject:public A getDeclaredAnnotation + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:getDeclaredAnnotation(Class annotationClass),annotationClass is null + * -#step2:catch Exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassgetDeclaredAnnotationNullPointerException.java + * -@ExecuteClass: ClassgetDeclaredAnnotationNullPointerException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.annotation.Annotation; + +public class ClassgetDeclaredAnnotationNullPointerException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = classGetDeclaredAnnotationNullPointerException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in AccessibleObject:public A getDeclaredAnnotation + * + * @return status code + */ + public static int classGetDeclaredAnnotationNullPointerException() { + int result1 = 4; /*STATUS_FAILED*/ + // NullPointerException- Null pointer exception + // public A getDeclaredAnnotation(Class annotationClass) + + Class class1 = Class.class; + + try { + // Object file1 = m. getAnnotationsByType(null); + // getDeclaredAnnotation + Annotation file1 = class1.getDeclaredAnnotation(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult -= 1; + } + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0528-rt-eh-ClassgetDeclaredAnnotationNullPointerException/Makefile b/test/testsuite/ouroboros/eh_test/RT0528-rt-eh-ClassgetDeclaredAnnotationNullPointerException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..4871c63bc57448e296b83026d054e97128e2982b --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0528-rt-eh-ClassgetDeclaredAnnotationNullPointerException/Makefile @@ -0,0 +1,3 @@ +APP=ClassgetDeclaredAnnotationNullPointerException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0529-rt-eh-ClassgetDeclaredFieldNoSuchFieldException/ClassgetDeclaredFieldNoSuchFieldException.java b/test/testsuite/ouroboros/eh_test/RT0529-rt-eh-ClassgetDeclaredFieldNoSuchFieldException/ClassgetDeclaredFieldNoSuchFieldException.java new file mode 100755 index 0000000000000000000000000000000000000000..881549c9c14c7ace4eba26e2f71e68a5dddf466c --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0529-rt-eh-ClassgetDeclaredFieldNoSuchFieldException/ClassgetDeclaredFieldNoSuchFieldException.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassgetDeclaredFieldNoSuchFieldException.java + * -@TestCaseName: Exception in Class constructor:public Field getDeclaredField(String name) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief:invoke getDeclaredField(String name) without this field name + * -#step1:invoke getDeclaredField(String name) without this field name + * -#step2:catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassgetDeclaredFieldNoSuchFieldException.java + * -@ExecuteClass: ClassgetDeclaredFieldNoSuchFieldException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class ClassgetDeclaredFieldNoSuchFieldException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = classGetDeclaredFieldNoSuchFieldException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in Class constructor:public Field getDeclaredField(String name) + * + * @return status code + */ + public static int classGetDeclaredFieldNoSuchFieldException() { + int result1 = 4; /*STATUS_FAILED*/ + + // NoSuchFieldException - if a field with the specified name is not found. + // + // public Field getDeclaredField(String name) + Class class1 = Class.class; + try { + Field file1 = class1.getDeclaredField("abc123"); + processResult -= 10; + } catch (NoSuchFieldException e1) { + processResult--; + } + + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0529-rt-eh-ClassgetDeclaredFieldNoSuchFieldException/Makefile b/test/testsuite/ouroboros/eh_test/RT0529-rt-eh-ClassgetDeclaredFieldNoSuchFieldException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..b48a8cc12429e5e058e221177b9db6664ca82528 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0529-rt-eh-ClassgetDeclaredFieldNoSuchFieldException/Makefile @@ -0,0 +1,3 @@ +APP=ClassgetDeclaredFieldNoSuchFieldException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0530-rt-eh-ClassgetDeclaredFieldNullPointerException/ClassgetDeclaredFieldNullPointerException.java b/test/testsuite/ouroboros/eh_test/RT0530-rt-eh-ClassgetDeclaredFieldNullPointerException/ClassgetDeclaredFieldNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..c6db949745bad6533700748132c421877ee8aa59 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0530-rt-eh-ClassgetDeclaredFieldNullPointerException/ClassgetDeclaredFieldNullPointerException.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassgetDeclaredFieldNullPointerException.java + * -@TestCaseName: Exception in Class constructor:public Field getDeclaredField(String name) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:getDeclaredField(String name),name is null + * -#step2:catch Exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassgetDeclaredFieldNullPointerException.java + * -@ExecuteClass: ClassgetDeclaredFieldNullPointerException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class ClassgetDeclaredFieldNullPointerException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = classGetDeclaredFieldNullPointerException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in Class constructor:public Field getDeclaredField(String name) + * + * @return status code + * @throws NoSuchFieldException + */ + public static int classGetDeclaredFieldNullPointerException() throws NoSuchFieldException { + int result1 = 4; /*STATUS_FAILED*/ + + // NullPointerException - if name is null. + // + // public Field getDeclaredField(String name) + + String string = null; + Class class1 = Class.class; + try { + Field file1 = class1.getDeclaredField(string); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0530-rt-eh-ClassgetDeclaredFieldNullPointerException/Makefile b/test/testsuite/ouroboros/eh_test/RT0530-rt-eh-ClassgetDeclaredFieldNullPointerException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..a6a8ab399e78328c93ec2d7cd3db0ebf212110e9 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0530-rt-eh-ClassgetDeclaredFieldNullPointerException/Makefile @@ -0,0 +1,3 @@ +APP=ClassgetDeclaredFieldNullPointerException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0531-rt-eh-ConstructorgAnnotationNullPointerException/ConstructorgAnnotationNullPointerException.java b/test/testsuite/ouroboros/eh_test/RT0531-rt-eh-ConstructorgAnnotationNullPointerException/ConstructorgAnnotationNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..1d3fa700ee1b59ce2e78ef71e32fa4df6ba8de32 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0531-rt-eh-ConstructorgAnnotationNullPointerException/ConstructorgAnnotationNullPointerException.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorgAnnotationNullPointerException.java + * -@TestCaseName:Exception in Constructor:public T getAnnotation + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: getAnnotation(Class annotationClass),annotationClass is null + * -#step2: catch NPE + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorgAnnotationNullPointerException.java + * -@ExecuteClass: ConstructorgAnnotationNullPointerException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Constructor; + +public class ConstructorgAnnotationNullPointerException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = constructorGAnnotationNullPointerException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in Constructor:public T getAnnotation + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int constructorGAnnotationNullPointerException() throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + + // NullPointerException - Null pointer exception + // public T getAnnotation(Class annotationClass) + Class class1 = Test01b.class; + Constructor c1 = class1.getConstructor(new Class[]{String.class}); + // Constructor m = Class.class.getMethod("getName", new Class[] {}); + + try { + Object file1 = c1.getAnnotation(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult -= 1; + } + return result1; + } +} + +class Test01b { + /** + * just for test + */ + public String name = "default"; + + public String getName() { + return name; + } + + public Test01b(String hh) { + this.name = hh; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0531-rt-eh-ConstructorgAnnotationNullPointerException/Makefile b/test/testsuite/ouroboros/eh_test/RT0531-rt-eh-ConstructorgAnnotationNullPointerException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..bedfba78e7e9a31f93f1a5485b476be8309c26bb --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0531-rt-eh-ConstructorgAnnotationNullPointerException/Makefile @@ -0,0 +1,3 @@ +APP=ConstructorgAnnotationNullPointerException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0532-rt-eh-ConstructornewInstanceExceptionInInitializerError/ConstructornewInstanceExceptionInInitializerError.java b/test/testsuite/ouroboros/eh_test/RT0532-rt-eh-ConstructornewInstanceExceptionInInitializerError/ConstructornewInstanceExceptionInInitializerError.java new file mode 100755 index 0000000000000000000000000000000000000000..bda12c9c0c9347bbbe2f69ac0270524c204b1ad5 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0532-rt-eh-ConstructornewInstanceExceptionInInitializerError/ConstructornewInstanceExceptionInInitializerError.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructornewInstanceExceptionInInitializerError.java + * -@TestCaseName: In a static variable initialization exception occurs + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief:In a static variable initialization exception occurs + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructornewInstanceExceptionInInitializerError.java + * -@ExecuteClass: ConstructornewInstanceExceptionInInitializerError + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +public class ConstructornewInstanceExceptionInInitializerError { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = constructorNewInstanceExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + // System.out.println("result: " + result); + // System.out.println("ConstructornewInstanceExceptionInInitializerError.res: " + + // ConstructornewInstanceExceptionInInitializerError.res); + return result; + } + + /** + * In a static variable initialization exception occurs + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + * @throws InstantiationException + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws InvocationTargetException + */ + public static int constructorNewInstanceExceptionInInitializerError() + throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException { + int result1 = 4; /*STATUS_FAILED*/ + + // ExceptionInInitializerError - In a static variable initialization exception occurs + // public T newInstance(Object... initargs) + Class class1 = Test01n.class; + Constructor c1 = class1.getConstructor(new Class[]{}); + + try { + Object file1 = c1.newInstance(); + // System.out.println(file1); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult -= 1; + } + return result1; + } +} + +class Test01n { + /** + * test a String val + */ + public String name = "default"; + + public String getName() { + return name; + } + + public Test01n() { + this.name = "init"; + } + + static { + int num = 1 / 0; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0532-rt-eh-ConstructornewInstanceExceptionInInitializerError/Makefile b/test/testsuite/ouroboros/eh_test/RT0532-rt-eh-ConstructornewInstanceExceptionInInitializerError/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..6f8ae2e2a8a9540ed745a753899b809fca91b84f --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0532-rt-eh-ConstructornewInstanceExceptionInInitializerError/Makefile @@ -0,0 +1,3 @@ +APP=ConstructornewInstanceExceptionInInitializerError +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0533-rt-eh-FieldgetAnnotationNullPointerException/FieldgetAnnotationNullPointerException.java b/test/testsuite/ouroboros/eh_test/RT0533-rt-eh-FieldgetAnnotationNullPointerException/FieldgetAnnotationNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..cbfa82e15b520b6fe38599a2108b0bff92e738eb --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0533-rt-eh-FieldgetAnnotationNullPointerException/FieldgetAnnotationNullPointerException.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldgetAnnotationNullPointerException.java + * -@TestCaseName: Exception in Class reflect Field:public T getAnnotation(Class annotationClass) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:getAnnotation(Class annotationClass),annotationClass is null + * -#step:catch Exception + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldgetAnnotationNullPointerException.java + * -@ExecuteClass: FieldgetAnnotationNullPointerException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldgetAnnotationNullPointerException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldGetAnnotationNullPointerException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in Class reflect Field:public T getAnnotation(Class annotationClass) + * + * @return status code + * @throws NoSuchFieldException + * @throws SecurityException + */ + public static int fieldGetAnnotationNullPointerException() throws NoSuchFieldException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + + // NullPointerException - if the specified object is null and the field is an instance field. + // public T getAnnotation(Class annotationClass) + + Field field = Test01a.class.getDeclaredField("field1"); + try { + Object value = field.getAnnotation(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + + return result1; + } + + class Test01a { + /** + * a field for test + */ + public int field1 = 1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0533-rt-eh-FieldgetAnnotationNullPointerException/Makefile b/test/testsuite/ouroboros/eh_test/RT0533-rt-eh-FieldgetAnnotationNullPointerException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..e5026f80df53b339f5c95f6a334a0fc34460ff57 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0533-rt-eh-FieldgetAnnotationNullPointerException/Makefile @@ -0,0 +1,3 @@ +APP=FieldgetAnnotationNullPointerException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0534-rt-eh-FieldgetAnnotationsByTypeNullPointerException/FieldgetAnnotationsByTypeNullPointerException.java b/test/testsuite/ouroboros/eh_test/RT0534-rt-eh-FieldgetAnnotationsByTypeNullPointerException/FieldgetAnnotationsByTypeNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..bfaf97e6589092b93c986c362f75e360438b89e2 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0534-rt-eh-FieldgetAnnotationsByTypeNullPointerException/FieldgetAnnotationsByTypeNullPointerException.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldgetAnnotationsByTypeNullPointerException.java + * -@TestCaseName: Exception in reflect Field:public T[] getAnnotationsByType(Class annotationClass) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:invoke getAnnotationsByType(Class annotationClass) with null(annotationClass) + * -#step2:catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldgetAnnotationsByTypeNullPointerException.java + * -@ExecuteClass: FieldgetAnnotationsByTypeNullPointerException + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldgetAnnotationsByTypeNullPointerException { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldGetAnnotationsByTypeNullPointerException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in reflect Field:public T[] getAnnotationsByType(Class annotationClass) + * + * @return status code + * @throws IllegalArgumentException + * @throws IllegalAccessException + * @throws NoSuchFieldException + * @throws SecurityException + */ + public static int fieldGetAnnotationsByTypeNullPointerException() + throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + + // NullPointerException - if the specified object is null and the field is an instance field. + // public T[] getAnnotationsByType(Class annotationClass) + + Field field = Test01a.class.getDeclaredField("field1"); + try { + Object value = field.getAnnotationsByType(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult -= 1; + } + + return result1; + } + + class Test01a { + /** + * a field for test + */ + public int field1 = 1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0534-rt-eh-FieldgetAnnotationsByTypeNullPointerException/Makefile b/test/testsuite/ouroboros/eh_test/RT0534-rt-eh-FieldgetAnnotationsByTypeNullPointerException/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..b465b887b9be49251a6c2b27e57c3e98c979dfb7 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0534-rt-eh-FieldgetAnnotationsByTypeNullPointerException/Makefile @@ -0,0 +1,3 @@ +APP=FieldgetAnnotationsByTypeNullPointerException +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0535-rt-eh-FieldgetByteExceptionInInitializerError/FieldgetByteExceptionInInitializerError.java b/test/testsuite/ouroboros/eh_test/RT0535-rt-eh-FieldgetByteExceptionInInitializerError/FieldgetByteExceptionInInitializerError.java new file mode 100755 index 0000000000000000000000000000000000000000..6a5a5af6fb086034a302f195cf9d199c08650790 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0535-rt-eh-FieldgetByteExceptionInInitializerError/FieldgetByteExceptionInInitializerError.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldgetByteExceptionInInitializerError.java + * -@TestCaseName: Exception in reflect filed:public byte getByte(Object obj) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:prepare Class with wrong init order + * -#step2:trigger class init by Field.getByte + * -#step3:catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldgetByteExceptionInInitializerError.java + * -@ExecuteClass: FieldgetByteExceptionInInitializerError + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldgetByteExceptionInInitializerError { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldGetByteExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in reflect filed:public byte getByte(Object obj) + * + * @return status code + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldGetByteExceptionInInitializerError() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + int result1 = 4; /*STATUS_FAILED*/ + + // ExceptionInInitializerError -if the initialization provoked by this method fails. + // + // public byte getByte(Object obj) + Field field = Test03aa.class.getDeclaredField("field6"); + try { + byte obj = field.getByte(new Test03aa()); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class Test03aa { + /** + * define a byte for test + */ + public static byte field6 = selfByte(); + /** + * define a int[] filed for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set bValue and return + * + * @return bValue + */ + public static byte selfByte() { + int self1 = field2[2]; + byte bValue = 11; + return bValue; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0535-rt-eh-FieldgetByteExceptionInInitializerError/Makefile b/test/testsuite/ouroboros/eh_test/RT0535-rt-eh-FieldgetByteExceptionInInitializerError/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..83dc97502fcce0d3988b4f1511ed55dd10537793 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0535-rt-eh-FieldgetByteExceptionInInitializerError/Makefile @@ -0,0 +1,3 @@ +APP=FieldgetByteExceptionInInitializerError +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0536-rt-eh-FieldgetCharExceptionInInitializerError/FieldgetCharExceptionInInitializerError.java b/test/testsuite/ouroboros/eh_test/RT0536-rt-eh-FieldgetCharExceptionInInitializerError/FieldgetCharExceptionInInitializerError.java new file mode 100755 index 0000000000000000000000000000000000000000..3e4e4d8d795caab2a98a01d3c8dd16dab6176661 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0536-rt-eh-FieldgetCharExceptionInInitializerError/FieldgetCharExceptionInInitializerError.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldgetCharExceptionInInitializerError.java + * -@TestCaseName: Exception in reflect filed:public byte getByte(Object obj) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:Class contain RuntimeEH in static block + * -#step2:init by getChar,occur InitializerError + * -#step3:catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldgetCharExceptionInInitializerError.java + * -@ExecuteClass: FieldgetCharExceptionInInitializerError + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldgetCharExceptionInInitializerError { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldGetCharExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in reflect filed:public byte getByte(Object obj) + * + * @return status code + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldGetCharExceptionInInitializerError() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + int result1 = 4; /*STATUS_FAILED*/ + + // ExceptionInInitializerError -if the initialization provoked by this method fails. + // + // public char getChar(Object obj) + Field field = TestChar.class.getDeclaredField("field6"); + try { + char obj = field.getChar(new TestChar()); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class TestChar { + /** + * a char field for test + */ + public static char field6 = selfChar(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set cValue and return + */ + public static char selfChar() { + int self1 = field2[2]; + char cValue = 11; + return cValue; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0536-rt-eh-FieldgetCharExceptionInInitializerError/Makefile b/test/testsuite/ouroboros/eh_test/RT0536-rt-eh-FieldgetCharExceptionInInitializerError/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..40102c635a7a843f1bdfbfdd4a1a936ab3fe349d --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0536-rt-eh-FieldgetCharExceptionInInitializerError/Makefile @@ -0,0 +1,3 @@ +APP=FieldgetCharExceptionInInitializerError +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0537-rt-eh-FieldgetDoubleExceptionInInitializerError/FieldgetDoubleExceptionInInitializerError.java b/test/testsuite/ouroboros/eh_test/RT0537-rt-eh-FieldgetDoubleExceptionInInitializerError/FieldgetDoubleExceptionInInitializerError.java new file mode 100755 index 0000000000000000000000000000000000000000..f66498fbf263c5f1ada0567269f48e3456a50b7c --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0537-rt-eh-FieldgetDoubleExceptionInInitializerError/FieldgetDoubleExceptionInInitializerError.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldgetDoubleExceptionInInitializerError.java + * -@TestCaseName: Exception in reflect filed:public double getDouble(Object obj) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:prepare Class with wrong init order + * -#step2:invoke this Class's Field,use Field.getDouble to trigger class init + * -#step3:catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldgetDoubleExceptionInInitializerError.java + * -@ExecuteClass: FieldgetDoubleExceptionInInitializerError + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldgetDoubleExceptionInInitializerError { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldGetDoubleExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in reflect filed:public double getDouble(Object obj) + * + * @return status code + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldGetDoubleExceptionInInitializerError() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + int result1 = 4; /*STATUS_FAILED*/ + // ExceptionInInitializerError -if the initialization provoked by this method fails. + // + // public double getDouble(Object obj) + Field field = TestDouble.class.getDeclaredField("field6"); + try { + double obj = field.getDouble(new TestDouble()); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class TestDouble { + /** + * a double field for test + */ + public static double field6 = selfDouble(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set dValue and return + */ + public static double selfDouble() { + int self1 = field2[2]; + double dValue = 11; + return dValue; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0537-rt-eh-FieldgetDoubleExceptionInInitializerError/Makefile b/test/testsuite/ouroboros/eh_test/RT0537-rt-eh-FieldgetDoubleExceptionInInitializerError/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..098e12ee811b507b7820594b8172111a21eb0b67 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0537-rt-eh-FieldgetDoubleExceptionInInitializerError/Makefile @@ -0,0 +1,3 @@ +APP=FieldgetDoubleExceptionInInitializerError +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0538-rt-eh-FieldgetExceptionInInitializerError/FieldgetExceptionInInitializerError.java b/test/testsuite/ouroboros/eh_test/RT0538-rt-eh-FieldgetExceptionInInitializerError/FieldgetExceptionInInitializerError.java new file mode 100755 index 0000000000000000000000000000000000000000..0a7e3bc0ad5a27d8ee1424462c7625da77277873 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0538-rt-eh-FieldgetExceptionInInitializerError/FieldgetExceptionInInitializerError.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldgetExceptionInInitializerError.java + * -@TestCaseName: Exception in reflect field:public Object get(Object obj) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:prepare Class with RuntimeEH + * -#step2:trigger class init by invoke Field + * -#step3:catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldgetExceptionInInitializerError.java + * -@ExecuteClass: FieldgetExceptionInInitializerError + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldgetExceptionInInitializerError { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldGetExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in reflect field:public Object get(Object obj) + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldGetExceptionInInitializerError() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /*STATUS_FAILED*/ + + // ExceptionInInitializerError -if the initialization provoked by this method fails. + // + // public Object get(Object obj) + // Test01aa class1 = new Test01aa(); + Field field = Test01aa.class.getDeclaredField("field1"); + try { + Object obj = field.get(new Test01aa()); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class Test01aa { + /** + * a int field for test + */ + public int field1 = 1; + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + /** + * a int field for test + */ + public static int field3 = field2[3]; + + static { + int field4 = 1 / 0; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0538-rt-eh-FieldgetExceptionInInitializerError/Makefile b/test/testsuite/ouroboros/eh_test/RT0538-rt-eh-FieldgetExceptionInInitializerError/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..b0fbaea30a85765913aac7f82f97e924e92da5bf --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0538-rt-eh-FieldgetExceptionInInitializerError/Makefile @@ -0,0 +1,3 @@ +APP=FieldgetExceptionInInitializerError +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0539-rt-eh-FieldgetFloatExceptionInInitializerError/FieldgetFloatExceptionInInitializerError.java b/test/testsuite/ouroboros/eh_test/RT0539-rt-eh-FieldgetFloatExceptionInInitializerError/FieldgetFloatExceptionInInitializerError.java new file mode 100755 index 0000000000000000000000000000000000000000..7faef9e084cb8328c81f84e87a8c5711d480b24d --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0539-rt-eh-FieldgetFloatExceptionInInitializerError/FieldgetFloatExceptionInInitializerError.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldgetFloatExceptionInInitializerError.java + * -@TestCaseName: Exception in reflect filed:public float getFloat(Object obj) + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:prepare Class have wrong init order + * -#step2:trigger class init by Field.getFloat + * -#step3:catch EH + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldgetFloatExceptionInInitializerError.java + * -@ExecuteClass: FieldgetFloatExceptionInInitializerError + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldgetFloatExceptionInInitializerError { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldGetFloatExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in reflect filed:public float getFloat(Object obj) + * + * @return status code + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldGetFloatExceptionInInitializerError() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + int result1 = 4; /*STATUS_FAILED*/ + // ExceptionInInitializerError -if the initialization provoked by this method fails. + // + // public float getFloat(Object obj) + Field field = TestFloat.class.getDeclaredField("field6"); + try { + float obj = field.getFloat(new TestFloat()); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class TestFloat { + /** + * a float field for test + */ + public static float field6 = selfDouble(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set fValue and return + * + * @return fValue + */ + public static float selfDouble() { + int self1 = field2[2]; + float fValue = 11; + return fValue; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0539-rt-eh-FieldgetFloatExceptionInInitializerError/Makefile b/test/testsuite/ouroboros/eh_test/RT0539-rt-eh-FieldgetFloatExceptionInInitializerError/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..953c65dfeb03237832dd8e8f7a8bd2f9062d533d --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0539-rt-eh-FieldgetFloatExceptionInInitializerError/Makefile @@ -0,0 +1,3 @@ +APP=FieldgetFloatExceptionInInitializerError +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0541-rt-eh-FieldGetIntExceptionInInitializerErrorTest/FieldGetIntExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0541-rt-eh-FieldGetIntExceptionInInitializerErrorTest/FieldGetIntExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5736cdea30f49ce3bb9b14eb1525252a739e9204 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0541-rt-eh-FieldGetIntExceptionInInitializerErrorTest/FieldGetIntExceptionInInitializerErrorTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldGetIntExceptionInInitializerErrorTest.java + * -@TestCaseName: Exception in reflect filed: public int getInt(Object obj). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a TestInt class, and create a public static selfDouble method and static area has expression + * error. + * -#step2: Create a Field instance f by calling the getDeclareFiled method on the TestInt object. + * -#step3: Test method getInt(Object obj). + * -#step4:Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldGetIntExceptionInInitializerErrorTest.java + * -@ExecuteClass: FieldGetIntExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldGetIntExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = fieldGetIntExceptionInInitializerErrorTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed: public int getInt(Object obj). + * + * @return status code + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldGetIntExceptionInInitializerErrorTest() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + int result1 = 4; /* STATUS_FAILED */ + + Field field = TestInt.class.getDeclaredField("field6"); + try { + int obj = field.getInt(new TestInt()); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestInt { + /** + * a int field for test + */ + public static int field6 = selfDouble(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set iValue and return + * + * @return iValue + */ + public static int selfDouble() { + int self1 = field2[2]; + int iValue = 11; + return iValue; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0541-rt-eh-FieldGetIntExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0541-rt-eh-FieldGetIntExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..80b5e39598ff4f7dd0d396a88e8167ff9799a93b --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0541-rt-eh-FieldGetIntExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldGetIntExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0542-rt-eh-FieldGetLongExceptionInInitializerErrorTest/FieldGetLongExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0542-rt-eh-FieldGetLongExceptionInInitializerErrorTest/FieldGetLongExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ee6df3b895cfa9974431c5c06ede553a1db1181e --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0542-rt-eh-FieldGetLongExceptionInInitializerErrorTest/FieldGetLongExceptionInInitializerErrorTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldGetLongExceptionInInitializerErrorTest.java + * -@TestCaseName: Exception in reflect filed: public double getLong(Object obj). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a TestGetLong class, and create a public static selfDouble method and static area has expression + * error. + * -#step2: Create a Field instance f by calling the getDeclareFiled method on the TestGetLong object. + * -#step3: Test method getLong(Object obj). + * -#step4:Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldGetLongExceptionInInitializerErrorTest.java + * -@ExecuteClass: FieldGetLongExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldGetLongExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = fieldGetLongExceptionInInitializerErrorTes1(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed: public double getLong(Object obj). + * + * @return status code + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldGetLongExceptionInInitializerErrorTes1() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + int result1 = 4; /* STATUS_FAILED */ + + Field fe = TestLong.class.getDeclaredField("field6"); + try { + long obj = fe.getLong(new TestLong()); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestLong { + /** + * a long field for test + */ + public static long field6 = selfDouble(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set lValue and return + * + * @return lValue + */ + public static long selfDouble() { + int self1 = field2[2]; + long lValue = 11; + return lValue; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0542-rt-eh-FieldGetLongExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0542-rt-eh-FieldGetLongExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..5d1da03ed7bed1907281b3ad49b045445bd80bcf --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0542-rt-eh-FieldGetLongExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldGetLongExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0543-rt-eh-FieldGetShortExceptionInInitializerErrorTest/FieldGetShortExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0543-rt-eh-FieldGetShortExceptionInInitializerErrorTest/FieldGetShortExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..6b5f86a69161657672dcded35580ae8c02219fa9 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0543-rt-eh-FieldGetShortExceptionInInitializerErrorTest/FieldGetShortExceptionInInitializerErrorTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldGetShortExceptionInInitializerErrorTest.java + * -@TestCaseName: Exception in reflect filed: public short getShort(Object obj). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a TestGetShort class, and create a public static selfShort method and static area has expression + * error. + * -#step2: Create a Field instance f by calling the getDeclareFiled method on the TestGetShort object. + * -#step3: Test method getShort(Object obj). + * -#step4:Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldGetShortExceptionInInitializerErrorTest.java + * -@ExecuteClass: FieldGetShortExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldGetShortExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = fieldGetShortExceptionInInitializerErrorTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed: public short getShort(Object obj). + * + * @return status code + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldGetShortExceptionInInitializerErrorTest() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + int result1 = 4; /* STATUS_FAILED */ + + Field field = TestShort.class.getDeclaredField("field6"); + try { + short obj = field.getShort(new TestShort()); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestShort { + /** + * a short field for test + */ + public static short field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static short selfShort() { + int self1 = field2[2]; + short value = 11; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0543-rt-eh-FieldGetShortExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0543-rt-eh-FieldGetShortExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..9e8453f9704b169d934ae8c06963e3aaf1753216 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0543-rt-eh-FieldGetShortExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldGetShortExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0544-rt-eh-FieldSetBooleanExceptionInInitializerErrorTest/FieldSetBooleanExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0544-rt-eh-FieldSetBooleanExceptionInInitializerErrorTest/FieldSetBooleanExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..cdc084f5170c4216762d68fc9ba6e9487daf9ebe --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0544-rt-eh-FieldSetBooleanExceptionInInitializerErrorTest/FieldSetBooleanExceptionInInitializerErrorTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldSetBooleanExceptionInInitializerErrorTest.java + * -@TestCaseName: Exception in reflect filed: public void setBoolean(Object obj, boolean z). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a TestSetBoolean class, and create a public static selfShort method and static area has expression + * error. + * -#step2: Create a Field instance f by calling the getDeclareFiled method on the TestSetBoolean object. + * -#step3: Test method setBoolean(Object obj, boolean z). + * -#step4:Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldSetBooleanExceptionInInitializerErrorTest.java + * -@ExecuteClass: FieldSetBooleanExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldSetBooleanExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = fieldSetBooleanExceptionInInitializerErrorTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed: public void setBoolean(Object obj, boolean z). + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldSetBooleanExceptionInInitializerErrorTest() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /* STATUS_FAILED */ + + Field field = TestSetBoolean.class.getDeclaredField("field6"); + try { + field.setBoolean(new TestSetBoolean(), false); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestSetBoolean { + /** + * a boolean field for test + */ + public static boolean field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static boolean selfShort() { + int self1 = field2[2]; + boolean value = true; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0544-rt-eh-FieldSetBooleanExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0544-rt-eh-FieldSetBooleanExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..c9dac9d7c616f6f709237d2c030165bb36c5f838 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0544-rt-eh-FieldSetBooleanExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldSetBooleanExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0545-rt-eh-FieldSetByteExceptionInInitializerErrorTest/FieldSetByteExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0545-rt-eh-FieldSetByteExceptionInInitializerErrorTest/FieldSetByteExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..df18da574534571ff5d69f74855d11ca9a1c725e --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0545-rt-eh-FieldSetByteExceptionInInitializerErrorTest/FieldSetByteExceptionInInitializerErrorTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldSetByteExceptionInInitializerErrorTest.java + * -@TestCaseName: Exception in reflect filed: public void setByte(Object obj, byte b). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a TestSetByte class, and create a public static selfShort method and static area has expression + * error. + * -#step2: Create a Field instance f by calling the getDeclareFiled method on the TestSetByte object. + * -#step3: Test method setByte(Object obj, byte b). + * -#step4:Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldSetByteExceptionInInitializerErrorTest.java + * -@ExecuteClass: FieldSetByteExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldSetByteExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = fieldSetByteExceptionInInitializerErrorTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed: public void setByte(Object obj, byte b). + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldSetByteExceptionInInitializerErrorTest() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /* STATUS_FAILED */ + + Field field = TestSetByte.class.getDeclaredField("field6"); + try { + field.setByte(new TestSetByte(), (byte) 1); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestSetByte { + /** + * a byte field for test + */ + public static byte field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static byte selfShort() { + int self1 = field2[2]; + byte value = (byte) 2; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0545-rt-eh-FieldSetByteExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0545-rt-eh-FieldSetByteExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..41f5b4e23008aae1a29b1c0149cad85356fe9f9e --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0545-rt-eh-FieldSetByteExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldSetByteExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0546-rt-eh-FieldSetCharExceptionInInitializerErrorTest/FieldSetCharExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0546-rt-eh-FieldSetCharExceptionInInitializerErrorTest/FieldSetCharExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..95f8b7d6b65d544e3ee88c232347c8bcfd73d923 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0546-rt-eh-FieldSetCharExceptionInInitializerErrorTest/FieldSetCharExceptionInInitializerErrorTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldSetCharExceptionInInitializerErrorTest.java + * -@TestCaseName: Exception in reflect filed:public void setChar(Object obj, char c). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a TestSetChar class, and create a public static selfShort method and static area has expression + * error. + * -#step2: Create a Field instance f by calling the getDeclareFiled method on the TestSetChar object. + * -#step3: Test method setChar(Object obj, char c). + * -#step4:Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldSetCharExceptionInInitializerErrorTest.java + * -@ExecuteClass: FieldSetCharExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldSetCharExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = fieldSetCharExceptionInInitializerErrorTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed:public void setChar(Object obj, char c). + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldSetCharExceptionInInitializerErrorTest() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /* STATUS_FAILED */ + + Field field = TestSetChar.class.getDeclaredField("field6"); + try { + field.setChar(new TestSetChar(), 'c'); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestSetChar { + /** + * a char field for test + */ + public static char field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static char selfShort() { + int self1 = field2[2]; + char value = 'a'; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0546-rt-eh-FieldSetCharExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0546-rt-eh-FieldSetCharExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..27c966fa77a7fc68308e73a096f7ed65fa5d03b8 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0546-rt-eh-FieldSetCharExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldSetCharExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0547-rt-eh-FieldSetDoubleExceptionInInitializerErrorTest/FieldSetDoubleExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0547-rt-eh-FieldSetDoubleExceptionInInitializerErrorTest/FieldSetDoubleExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..432d76abc74098ca271454830cc925e2a0141815 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0547-rt-eh-FieldSetDoubleExceptionInInitializerErrorTest/FieldSetDoubleExceptionInInitializerErrorTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldSetDoubleExceptionInInitializerErrorTest.java + * -@TestCaseName: Exception in reflect filed:public void setDouble(Object obj, double d). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a TestSetDouble class, and create a public static selfShort method and static area has expression + * error. + * -#step2: Create a Field instance f by calling the getDeclareFiled method on the TestSetDouble object. + * -#step3: Test method setDouble(Object obj, double d). + * -#step4:Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldSetDoubleExceptionInInitializerErrorTest.java + * -@ExecuteClass: FieldSetDoubleExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldSetDoubleExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = fieldSetDoubleExceptionInInitializerErrorTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed:public void setDouble(Object obj, double d). + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldSetDoubleExceptionInInitializerErrorTest() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /* STATUS_FAILED */ + + Field field = TestSetDouble.class.getDeclaredField("field6"); + try { + field.setDouble(new TestSetDouble(), 23); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestSetDouble { + /** + * a double field for test + */ + public static double field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static double selfShort() { + int self1 = field2[2]; + double value = 12; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0547-rt-eh-FieldSetDoubleExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0547-rt-eh-FieldSetDoubleExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..57a70fd66bd0030d95cec99ea59aabc03a2358ed --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0547-rt-eh-FieldSetDoubleExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldSetDoubleExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0548-rt-eh-FieldsetExceptionInInitializerErrorTest/FieldSetExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0548-rt-eh-FieldsetExceptionInInitializerErrorTest/FieldSetExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d33bd00c0faa825205ba2ce257a610ec6f87949e --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0548-rt-eh-FieldsetExceptionInInitializerErrorTest/FieldSetExceptionInInitializerErrorTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldSetExceptionInInitializerErrorTest.java + * -@TestCaseName: Exception in reflect filed: public void set(Object obj, Object value). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a TestSet class, and create a public static selfShort method and static area has expression error. + * -#step2: Create a Field instance f by calling the getDeclareFiled method on the TestSet object. + * -#step3: Test method set(Object obj, Object value). + * -#step4:Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldSetExceptionInInitializerErrorTest.java + * -@ExecuteClass: FieldSetExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldSetExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + try { + result = fieldSetExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed: public void set(Object obj, Object value). + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldSetExceptionInInitializerError() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /* STATUS_FAILED */ + + Field field = TestSet.class.getDeclaredField("field6"); + try { + field.set(new TestSet(), 123); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestSet { + /** + * a int field for test + */ + public static int field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static int selfShort() { + int self1 = field2[2]; + int value = 11; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0548-rt-eh-FieldsetExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0548-rt-eh-FieldsetExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..ed781e5e30f80fed0fb710522863047094b18a7b --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0548-rt-eh-FieldsetExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldSetExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0549-rt-eh-FieldSetFloatExceptionInInitializerErrorTest/FieldSetFloatExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0549-rt-eh-FieldSetFloatExceptionInInitializerErrorTest/FieldSetFloatExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..19a41502c69c0f0afcee6e9c91966a0a28f5bf67 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0549-rt-eh-FieldSetFloatExceptionInInitializerErrorTest/FieldSetFloatExceptionInInitializerErrorTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldSetFloatExceptionInInitializerError.java + * -@TestCaseName: Exception in reflect filed: public void setFloat(Object obj, float f). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a TestFloat class, and create a public static selfFloat method and static area has expression error. + * -#step2: Create a Field instance f by calling the getDeclareFiled method on the TestSetFloat object. + * -#step3: Test method setFloat(Object obj, float f). + * -#step4:Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldSetFloatExceptionInInitializerErrorTest.java + * -@ExecuteClass: FieldSetFloatExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldSetFloatExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = fieldSetFloatExceptionInInitializerErrorTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed: public void setFloat(Object obj, float f). + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldSetFloatExceptionInInitializerErrorTest() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /* STATUS_FAILED */ + + Field field = TestSetFloat.class.getDeclaredField("field6"); + try { + field.setFloat(new TestSetFloat(), (float) 0.12); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestSetFloat { + /** + * a float field for test + */ + public static float field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static float selfShort() { + int self1 = field2[2]; + float value = (float) 12.54; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0549-rt-eh-FieldSetFloatExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0549-rt-eh-FieldSetFloatExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..193877cdfb32d04cf9efe28ee9285ed6d9fe0ec3 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0549-rt-eh-FieldSetFloatExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldSetFloatExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0550-rt-eh-FieldSetIntExceptionTest/FieldSetIntExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0550-rt-eh-FieldSetIntExceptionTest/FieldSetIntExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a4e33535dd7e534e3772c4c143f7898f4537b247 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0550-rt-eh-FieldSetIntExceptionTest/FieldSetIntExceptionTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldSetIntExceptionTest.java + * -@TestCaseName: Exception in reflect filed: public void setInt(Object obj, int i). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Get Field object by getDeclaredField(String name). + * -#step2: Test method setInt(Object obj, int i) to change the field object's value to int type. + * -#step3: Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldSetIntExceptionTest.java + * -@ExecuteClass: FieldSetIntExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldSetIntExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldSetIntExceptionTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed: public void setInt(Object obj, int i). + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldSetIntExceptionTest() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /*STATUS_FAILED*/ + + Field field = TestSetInt.class.getDeclaredField("field6"); + try { + field.setInt(new TestSetInt(), 123); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + return result1; + } +} + +class TestSetInt { + /** + * a int field for test + */ + public static int field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static int selfShort() { + int self1 = field2[2]; + int value = 11; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0550-rt-eh-FieldSetIntExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0550-rt-eh-FieldSetIntExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..80f6da403b074b68de073209c92c2e4b338a8444 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0550-rt-eh-FieldSetIntExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldSetIntExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0551-rt-eh-FieldSetLongExceptionTest/FieldSetLongExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0551-rt-eh-FieldSetLongExceptionTest/FieldSetLongExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f03b29bc32946d777fadd749fd711fc85bc89eb8 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0551-rt-eh-FieldSetLongExceptionTest/FieldSetLongExceptionTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldSetLongExceptionTest.java + * -@TestCaseName: Exception in reflect filed: public void setLong(Object obj, long l). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Get Field object by getDeclaredField(String name). + * -#step2: Test method setLong(Object obj, long l) to change the field object's value to long type. + * -#step3: Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldSetLongExceptionTest.java + * -@ExecuteClass: FieldSetLongExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldSetLongExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldSetLongExceptionTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in reflect filed: public void setLong(Object obj, long l). + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldSetLongExceptionTest() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /*STATUS_FAILED*/ + + Field field = TestSetLong.class.getDeclaredField("field6"); + try { + field.setLong(new TestSetLong(), 123); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class TestSetLong { + /** + * a long field for test + */ + public static long field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static long selfShort() { + int self1 = field2[2]; + long value = 11; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0551-rt-eh-FieldSetLongExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0551-rt-eh-FieldSetLongExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..0e6b397199751ab7525892d2ee9bce7aeaa8e841 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0551-rt-eh-FieldSetLongExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldSetLongExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0552-rt-eh-FieldSetShortExceptionTest/FieldSetShortExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0552-rt-eh-FieldSetShortExceptionTest/FieldSetShortExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a40a7af977599b4ea58526e2530a6b235edb2265 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0552-rt-eh-FieldSetShortExceptionTest/FieldSetShortExceptionTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldSetShortExceptionTest.java + * -@TestCaseName: Exception in reflect filed: public void setShort(Object obj, short s). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Get Field object by getDeclaredField(String name). + * -#step2: Test method setShort(Object obj, short s) change the field object's value to short type. + * -#step3: Check ExceptionInInitializerError is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: FieldSetShortExceptionTest.java + * -@ExecuteClass: FieldSetShortExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class FieldSetShortExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = fieldSetShortExceptionTest(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect filed: public void setShort(Object obj, short s). + * + * @return status code + * @throws ClassNotFoundException + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static int fieldSetShortExceptionTest() + throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, + IllegalAccessException { + int result1 = 4; /*STATUS_FAILED*/ + + Field field = TestSetShort.class.getDeclaredField("field6"); + try { + field.setShort(new TestSetShort(), (short) 12); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class TestSetShort { + /** + * a short field for test + */ + public static short field6 = selfShort(); + /** + * a int[] field for test + */ + public static int[] field2 = {1, 2, 3, 4}; + + /** + * set value and return + * + * @return value + */ + public static short selfShort() { + int self1 = field2[2]; + short value = 11; + return value; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0552-rt-eh-FieldSetShortExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0552-rt-eh-FieldSetShortExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..75c50cdf7922f46ca9751818e2c4a653763c2613 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0552-rt-eh-FieldSetShortExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=FieldSetShortExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0553-rt-eh-MethodGetAnnotationExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0553-rt-eh-MethodGetAnnotationExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..aa2bea66ff431f48901d9d49ff9ebd60a1053adf --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0553-rt-eh-MethodGetAnnotationExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=MethodGetAnnotationExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0553-rt-eh-MethodGetAnnotationExceptionTest/MethodGetAnnotationExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0553-rt-eh-MethodGetAnnotationExceptionTest/MethodGetAnnotationExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..59800c2a2c44f04d0810178ae5928c046c6d0ac7 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0553-rt-eh-MethodGetAnnotationExceptionTest/MethodGetAnnotationExceptionTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodGetAnnotationExceptionTest.java + * -@TestCaseName: Exception in reflect Method: public T getAnnotation(Class annotationClass). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create self class. + * -#step2: Get class method instance from self class. + * -#step3: Test method getAnnotation(Class annotationClass), parameter annotationClass is null. + * -#step4: Check NullPointerException exception is thrown correctly. + * -@Expect: 0\n + * -@Priority: High + * -@Source: MethodGetAnnotationExceptionTest.java + * -@ExecuteClass: MethodGetAnnotationExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Method; + +public class MethodGetAnnotationExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = methodGetAnnotationExceptionTest(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect Method: public T getAnnotation(Class annotationClass). + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int methodGetAnnotationExceptionTest() throws NoSuchMethodException, SecurityException { + int result1 = 4; /* STATUS_FAILED */ + + Method method = Test02a.class.getMethod("getName", new Class[]{}); + try { + Object value = method.getAnnotation(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + return result1; + } +} + +class Test02a { + private String name = "default"; + + public String getName() { + return name; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0555-rt-eh-MethodInvokeExceptionInInitializerErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0555-rt-eh-MethodInvokeExceptionInInitializerErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..637c4a37780deaf872ffcc76cb095950246f0885 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0555-rt-eh-MethodInvokeExceptionInInitializerErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=MethodInvokeExceptionInInitializerErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0555-rt-eh-MethodInvokeExceptionInInitializerErrorTest/MethodInvokeExceptionInInitializerErrorTest.java b/test/testsuite/ouroboros/eh_test/RT0555-rt-eh-MethodInvokeExceptionInInitializerErrorTest/MethodInvokeExceptionInInitializerErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..48a3c80fa2335f671c5da7a66f2e85d883ba556e --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0555-rt-eh-MethodInvokeExceptionInInitializerErrorTest/MethodInvokeExceptionInInitializerErrorTest.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodInvokeExceptionInInitializerErrorTest.java + * -@TestCaseName: Exception in reflect method : public Object invoke(Object obj, Object... args). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create self class has fault static, create class instance by self class construct. + * -#step2: Get class method from self class. + * -#step3: Test invoke(Object obj, Object... args), args is a new object Array. + * -#step4: Check that if ExceptionInInitializerError exception occurs. + * -@Expect: 0\n + * -@Priority: High + * -@Source: MethodInvokeExceptionInInitializerErrorTest.java + * -@ExecuteClass: MethodInvokeExceptionInInitializerErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class MethodInvokeExceptionInInitializerErrorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = methodInvokeExceptionInInitializerError(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + + return result; + } + + /** + * Exception in reflect method : public Object invoke(Object obj, Object... args). + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws InvocationTargetException + */ + public static int methodInvokeExceptionInInitializerError() + throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException { + int result1 = 4; /*STATUS_FAILED*/ + Class class1 = TestExceptionInInitializerError.class; + Method method = class1.getMethod("setInt", new Class[]{int.class}); + try { + method.invoke(new TestExceptionInInitializerError(10), new Object[]{20}); + processResult -= 10; + } catch (ExceptionInInitializerError e1) { + processResult--; + } + + return result1; + } +} + +class TestExceptionInInitializerError { + int nu; + + /** + * set num + * + * @param num for test + */ + public static void setInt(int num) { + int num1 = num; + } + + public TestExceptionInInitializerError(int num) { + this.nu = num; + } + + static { + int num = 1 / 0; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0556-rt-eh-ParameterGetAnnotationNullPointerExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0556-rt-eh-ParameterGetAnnotationNullPointerExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..acd112e2ac104ba6222ce7fcae7a74afefbfbc9a --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0556-rt-eh-ParameterGetAnnotationNullPointerExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=ParameterGetAnnotationNullPointerExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0556-rt-eh-ParameterGetAnnotationNullPointerExceptionTest/ParameterGetAnnotationNullPointerExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0556-rt-eh-ParameterGetAnnotationNullPointerExceptionTest/ParameterGetAnnotationNullPointerExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..aa645d389a3e6296745f0995fb736af362ec3e64 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0556-rt-eh-ParameterGetAnnotationNullPointerExceptionTest/ParameterGetAnnotationNullPointerExceptionTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ParameterGetAnnotationNullPointerExceptionTest.java + * -@TestCaseName: Exception in reflect.Parameter: public T getAnnotation(Class annotationClass). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create method instance by self class. + * -#step2: Get method parameters by getParameters() from method instance. + * -#step3: Test method getAnnotation(Class annotationClass), parameter annotationClass is null. + * -#step3: Check that if NullPointerException occurs. + * -@Expect: 0\n + * -@Priority: High + * -@Source: ParameterGetAnnotationNullPointerExceptionTest.java + * -@ExecuteClass: ParameterGetAnnotationNullPointerExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterGetAnnotationNullPointerExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + try { + result = parameterGetAnnotationNullPointerException(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect.Parameter: public T getAnnotation(Class annotationClass). + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int parameterGetAnnotationNullPointerException() throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + + Method method = Test03a.class.getMethod("getName", new Class[]{String.class}); + Parameter[] parameters = method.getParameters(); + try { + Object value = parameters[0].getAnnotation(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + return result1; + } +} + +class Test03a { + private String name = "default"; + + public String getName(String str1) { + return str1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0557-rt-eh-ParameterGetAnnotationsByTypeNullPointerExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0557-rt-eh-ParameterGetAnnotationsByTypeNullPointerExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..3065f4fdd436821fa5ab4999201235e53dea7a00 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0557-rt-eh-ParameterGetAnnotationsByTypeNullPointerExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=ParameterGetAnnotationsByTypeNullPointerExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0557-rt-eh-ParameterGetAnnotationsByTypeNullPointerExceptionTest/ParameterGetAnnotationsByTypeNullPointerExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0557-rt-eh-ParameterGetAnnotationsByTypeNullPointerExceptionTest/ParameterGetAnnotationsByTypeNullPointerExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ff7e00c8edd6591741b1eb3d3de6df6dd4873157 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0557-rt-eh-ParameterGetAnnotationsByTypeNullPointerExceptionTest/ParameterGetAnnotationsByTypeNullPointerExceptionTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ParameterGetAnnotationsByTypeNullPointerExceptionTest.java + * -@TestCaseName: Exception in reflect.Parameter: public T[] getAnnotationsByType(Class annotationClass). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create method instance by self class. + * -#step2: Get method parameters by getParameters() from method instance. + * -#step3: Test method getAnnotationsByType(Class annotationClass), parameter annotationClass is null. + * -#step4: Check that if NullPointerException exception occurs. + * -@Expect: 0\n + * -@Priority: High + * -@Source: ParameterGetAnnotationsByTypeNullPointerExceptionTest.java + * -@ExecuteClass: ParameterGetAnnotationsByTypeNullPointerExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterGetAnnotationsByTypeNullPointerExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = parameterGetAnnotationsByTypeNullPointerException(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect.Parameter: public T[] getAnnotationsByType(Class annotationClass). + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int parameterGetAnnotationsByTypeNullPointerException() + throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + + Method method = Test04a.class.getMethod("getName", new Class[]{String.class}); + Parameter[] parameters = method.getParameters(); + try { + Object value = parameters[0].getAnnotationsByType(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + + return result1; + } +} + +class Test04a { + private String name = "default"; + + public String getName(String str1) { + return str1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0558-rt-eh-ParameterGetDeclaredAnnotationNullPointerExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0558-rt-eh-ParameterGetDeclaredAnnotationNullPointerExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..f4064f2b6ebb1d75c750c151dbd8f61e0e46cce7 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0558-rt-eh-ParameterGetDeclaredAnnotationNullPointerExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=ParameterGetDeclaredAnnotationNullPointerExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0558-rt-eh-ParameterGetDeclaredAnnotationNullPointerExceptionTest/ParameterGetDeclaredAnnotationNullPointerExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0558-rt-eh-ParameterGetDeclaredAnnotationNullPointerExceptionTest/ParameterGetDeclaredAnnotationNullPointerExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c04d80be166dd324e0a2b9d4c482c292dc3e82d6 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0558-rt-eh-ParameterGetDeclaredAnnotationNullPointerExceptionTest/ParameterGetDeclaredAnnotationNullPointerExceptionTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ParameterGetDeclaredAnnotationNullPointerExceptionTest.java + * -@TestCaseName: Exception in reflect.Parameter: public T getDeclaredAnnotation(Class annotationClass). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create method instance by self class. + * -#step2: Get method parameters by getParameters() from method instance. + * -#step3: Test method getDeclaredAnnotation(Class annotationClass), parameter annotationClass is null. + * -#step4: Check that if NullPointerException exception occurs. + * -@Expect: 0\n + * -@Priority: High + * -@Source: ParameterGetDeclaredAnnotationNullPointerExceptionTest.java + * -@ExecuteClass: ParameterGetDeclaredAnnotationNullPointerExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterGetDeclaredAnnotationNullPointerExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + try { + result = parameterGetDeclaredAnnotationNullPointerException1(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in reflect.Parameter: public T getDeclaredAnnotation(Class annotationClass). + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int parameterGetDeclaredAnnotationNullPointerException1() + throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + + Method method = Test05a.class.getMethod("getName", new Class[]{String.class}); + Parameter[] parameters = method.getParameters(); + try { + Object value = parameters[0].getDeclaredAnnotation(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + return result1; + } +} + +class Test05a { + private String name = "default"; + + public String getName(String str1) { + return str1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0559-rt-eh-ParameterGetDeclaredAnnotationsByTypeExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0559-rt-eh-ParameterGetDeclaredAnnotationsByTypeExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..fb236eeb2c84e9fd073456690283b3bc41c69120 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0559-rt-eh-ParameterGetDeclaredAnnotationsByTypeExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=ParameterGetDeclaredAnnotationsByTypeExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0559-rt-eh-ParameterGetDeclaredAnnotationsByTypeExceptionTest/ParameterGetDeclaredAnnotationsByTypeExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0559-rt-eh-ParameterGetDeclaredAnnotationsByTypeExceptionTest/ParameterGetDeclaredAnnotationsByTypeExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7ecfecc46073f54e707623b87e203a975bbdc186 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0559-rt-eh-ParameterGetDeclaredAnnotationsByTypeExceptionTest/ParameterGetDeclaredAnnotationsByTypeExceptionTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ParameterGetDeclaredAnnotationsByTypeExceptionTest.java + * -@TestCaseName: Exception in Parameter: public T[] getDeclaredAnnotationsByType(Class annotationClass). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create method instance by self class. + * -#step2: Get method parameters by getParameters() from method instance. + * -#step3: Test method getDeclaredAnnotationsByType(Class annotationClass), parameter annotationClass is null. + * -#step4: Check that if NullPointerException exception occurs. + * -@Expect: 0\n + * -@Priority: High + * -@Source: ParameterGetDeclaredAnnotationsByTypeExceptionTest.java + * -@ExecuteClass: ParameterGetDeclaredAnnotationsByTypeExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterGetDeclaredAnnotationsByTypeExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = parameterGetDeclaredAnnotationsByTypeException(); + } catch (Exception e) { + processResult -= 20; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in Parameter: public T[] getDeclaredAnnotationsByType(Class annotationClass). + * + * @return status code + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static int parameterGetDeclaredAnnotationsByTypeException() + throws NoSuchMethodException, SecurityException { + int result1 = 4; /* STATUS_FAILED */ + + Method method = Test06a.class.getMethod("getName", new Class[]{String.class}); + Parameter[] parameters = method.getParameters(); + try { + Object value = parameters[0].getDeclaredAnnotationsByType(null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + return result1; + } +} + +class Test06a { + private String name = "default"; + + public String getName(String str1) { + return str1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0560-rt-eh-ThrowableAddSuppressedExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0560-rt-eh-ThrowableAddSuppressedExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..00baa35ee6d79ddf1c8f6422dcbec43149196067 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0560-rt-eh-ThrowableAddSuppressedExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=ThrowableAddSuppressedExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0560-rt-eh-ThrowableAddSuppressedExceptionTest/ThrowableAddSuppressedExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0560-rt-eh-ThrowableAddSuppressedExceptionTest/ThrowableAddSuppressedExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ef9d5e8418b28d93c96f7c9801c08c16dc62d698 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0560-rt-eh-ThrowableAddSuppressedExceptionTest/ThrowableAddSuppressedExceptionTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThrowableAddSuppressedExceptionTest.java + * -@TestCaseName: Exception in Throwable: public final void addSuppressed(Throwable exception). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create throwable instance and parameter throwable instance exception. + * -#step2: Test method addSuppressed(Throwable exception). + * -#step3: Check that if IllegalArgumentException occurs. + * -@Expect: 0\n + * -@Priority: High + * -@Source: ThrowableAddSuppressedExceptionTest.java + * -@ExecuteClass: ThrowableAddSuppressedExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ThrowableAddSuppressedExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + result = throwableAddSuppressedException(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in Throwable: public final void addSuppressed(Throwable exception). + * + * @return status code + */ + public static int throwableAddSuppressedException() { + int result1 = 4; /* STATUS_FAILED */ + Throwable cause = new Throwable(); + + try { + cause.addSuppressed(cause); + processResult -= 10; + } catch (IllegalArgumentException e1) { + processResult--; + } + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0561-rt-eh-ThrowableAddSuppressedNullPointerExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0561-rt-eh-ThrowableAddSuppressedNullPointerExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..c86bf4af7b63ed54af9eab2b0a09b60cf0918601 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0561-rt-eh-ThrowableAddSuppressedNullPointerExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=ThrowableAddSuppressedNullPointerExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0561-rt-eh-ThrowableAddSuppressedNullPointerExceptionTest/ThrowableAddSuppressedNullPointerExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0561-rt-eh-ThrowableAddSuppressedNullPointerExceptionTest/ThrowableAddSuppressedNullPointerExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0dad4eb1532c2caec46b960e025a17b6b2c8d322 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0561-rt-eh-ThrowableAddSuppressedNullPointerExceptionTest/ThrowableAddSuppressedNullPointerExceptionTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThrowableAddSuppressedNullPointerExceptionTest.java + * -@TestCaseName: Exception in Throwable: public final void addSuppressed(Throwable exception). + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create Throwable instance. + * -#step2: Test method addSuppressed(Throwable exception), exception is null. + * -#step3: Check that if NullPointerException occurs. + * -@Expect: 0\n + * -@Priority: High + * -@Source: ThrowableAddSuppressedNullPointerExceptionTest.java + * -@ExecuteClass: ThrowableAddSuppressedNullPointerExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ThrowableAddSuppressedNullPointerExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = throwableAddSuppressedNullPointerException1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 98) { + result = 0; + } + return result; + } + + /** + * Exception in Throwable: public final void addSuppressed(Throwable exception). + * + * @return status code + */ + public static int throwableAddSuppressedNullPointerException1() { + int result1 = 4; /*STATUS_FAILED*/ + Throwable cause = new Throwable(); + try { + cause.addSuppressed((Throwable) null); + processResult -= 10; + } catch (NullPointerException e1) { + processResult--; + } + return result1; + } +} + +class Test02ga { + private String name = "default"; + + public String getName() { + return name; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0817-rt-mrtUT-MethodInvokeExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0817-rt-mrtUT-MethodInvokeExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..13cb8d7742de0a810e349a62a9fcf45c11a430e1 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0817-rt-mrtUT-MethodInvokeExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=MethodInvokeExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0817-rt-mrtUT-MethodInvokeExceptionTest/MethodInvokeExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT0817-rt-mrtUT-MethodInvokeExceptionTest/MethodInvokeExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3450d075813ca3bbccd2829f28cfd81678092dee --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0817-rt-mrtUT-MethodInvokeExceptionTest/MethodInvokeExceptionTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodInvokeExceptionTest.java + * -@TestCaseName: Test Exception in invoke of method. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#case1 + * -#step1: Create a method from getConstructor of java.lang.Class. + * -#step2: Generate an instance from java.security.CodeSigner. Assign parameters is Class[]. + * -#step3: Test Object invoke(Object obj, Object... args), check exception is thrown correctly. + * -#case2 + * -#step1: Create a method from CharConversionException of java.lang.Character. + * -#step2: Generate an instance by class java.security.CodeSigner. Assign parameters is Class[]. + * -#step3: Test Object invoke(Object obj, Object... args), check exception is thrown correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: MethodInvokeExceptionTest.java + * -@ExecuteClass: MethodInvokeExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.lang.reflect.Method; + +public class MethodInvokeExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + private static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_FAILED */ + + try { + invokeMethod(); + } catch (Exception e) { + processResult--; + System.out.println(3); + } + + try { + invokeMethodTest(); + } catch (Exception e) { + processResult--; + System.out.println(6); + } + + if (result == 2 && processResult == 97) { + result = 0; + } + return result; + } + + static void invokeMethod() throws Exception { + Method method = Class.forName("java.lang.Class").getDeclaredMethod("getConstructor", Class[].class); + Object instance = Class.forName("java.security.CodeSigner"); + Object[] parameters = new Object[1]; + parameters[0] = + new Class[]{ + java.security.CodeSigner.class, + java.util.concurrent.locks.AbstractOwnableSynchronizer.class, + java.util.concurrent.locks.AbstractOwnableSynchronizer.class, + java.util.LinkedHashMap.class, + java.nio.channels.AsynchronousFileChannel.class, + java.sql.Time.class, + java.util.EnumMap.class, + java.nio.channels.FileLock.class, + java.util.WeakHashMap.class + }; + System.out.println(1); + method.invoke(instance, parameters); + System.out.println(2); + } + + static void invokeMethodTest() throws Exception { + Method method = + Class.forName("java.lang.Character").getDeclaredMethod("CharConversionException", Class[].class); + Object instance = Class.forName("java.security.CodeSigner"); + Object[] parameters = new Object[1]; + + parameters[0] = + new Class[]{ + java.security.CodeSigner.class, + java.util.concurrent.locks.AbstractOwnableSynchronizer.class, + java.util.concurrent.locks.AbstractOwnableSynchronizer.class, + java.util.LinkedHashMap.class, + java.nio.channels.AsynchronousFileChannel.class, + java.sql.Time.class, + java.util.EnumMap.class, + java.nio.channels.FileLock.class, + java.util.WeakHashMap.class + }; + System.out.println(4); + method.invoke(instance, parameters); + System.out.println(5); + } +} + +// DEPENDENCE: old_result_figo.log +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 1\s*3\s*6\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT0817-rt-mrtUT-MethodInvokeExceptionTest/old_result_figo.log b/test/testsuite/ouroboros/eh_test/RT0817-rt-mrtUT-MethodInvokeExceptionTest/old_result_figo.log new file mode 100755 index 0000000000000000000000000000000000000000..2bdf79d1340d622634a928845f9dd9084ce5e1f9 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0817-rt-mrtUT-MethodInvokeExceptionTest/old_result_figo.log @@ -0,0 +1,2 @@ +/home/chenliliu/emui/maple/cll/important/RT0817-runtime-mrtUT-MethodInvokeExceptionTest/ +MethodInvokeException.java Failed 0 run check unexpected output diff --git a/test/testsuite/ouroboros/eh_test/RT0904-rt-fuzzapi-MethodInvokeObjectObjectsTest/Makefile b/test/testsuite/ouroboros/eh_test/RT0904-rt-fuzzapi-MethodInvokeObjectObjectsTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..e1160bfdc6096db3a460d09955c33951eec1bd41 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0904-rt-fuzzapi-MethodInvokeObjectObjectsTest/Makefile @@ -0,0 +1,3 @@ +APP=MethodInvokeObjectObjectsTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT0904-rt-fuzzapi-MethodInvokeObjectObjectsTest/MethodInvokeObjectObjectsTest.java b/test/testsuite/ouroboros/eh_test/RT0904-rt-fuzzapi-MethodInvokeObjectObjectsTest/MethodInvokeObjectObjectsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..935ce81e4400b348bfe290542d3efc0cd76b491f --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT0904-rt-fuzzapi-MethodInvokeObjectObjectsTest/MethodInvokeObjectObjectsTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodInvokeObjectObjectsTest.java + * -@TestCaseName: Test Object invoke(Object obj, Object... args) of Method, check Exception order. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1:Create an instance of a method from class java.util.concurrent.ConcurrentHashMap. + * -#step2: Create Parameter param1 as a StringBuffer, Create Parameter param2 as a Object[]. + * -#step3: Test the method invoke(Object obj, Object... args), and check the Exception is thrown correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: MethodInvokeObjectObjectsTest.java + * -@ExecuteClass: MethodInvokeObjectObjectsTest + * -@ExecuteArgs: + */ + +import java.lang.reflect.*; +import java.nio.charset.Charset; +import java.util.*; + +public class MethodInvokeObjectObjectsTest { + /** + * test class + */ + public static Class clazz; + + public static void main(String[] args) { + try { + System.out.println(run()); + } catch (Exception e) { + System.out.println(e); + } + } + + /** + * main test fun + * + * @return status code + */ + public static int run() { + try { + clazz = Class.forName("java.lang.reflect.Method"); + Method method = clazz.getMethod("invoke", Object.class, Object[].class); + String fcn2 = "java.util.concurrent.ConcurrentHashMap"; + int mIndex6 = 1; + Method[] methods2 = Class.forName(fcn2).getDeclaredMethods(); + Arrays.sort(methods2, new ConstructorComparator()); + Object instance = methods2[mIndex6]; + Constructor con = java.lang.StringBuffer.class.getDeclaredConstructor(); + Object param1 = con.newInstance(); + Object[] param2 = new Object[4]; + Constructor con0 = java.lang.StringBuffer.class.getDeclaredConstructor(); + param2[0] = con0.newInstance(); + Constructor con1 = + java.security.spec.MGF1ParameterSpec.class.getDeclaredConstructor(java.lang.String.class); + param2[1] = con1.newInstance("abcdefghijklmnopqrstuvwxxzABCDEFGHIJKLMNOPQRSTUVWXYZ-9223372036854775551"); + Constructor con2 = java.util.Stack.class.getDeclaredConstructor(); + param2[2] = con2.newInstance(); + Constructor con3 = + java.security.spec.ECGenParameterSpec.class.getDeclaredConstructor(java.lang.String.class); + param2[3] = con3.newInstance("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); + Object result = method.invoke(instance, param1, param2); + System.out.println(result); + } catch (Exception e) { + if (e.toString().equals("java.lang.reflect.InvocationTargetException") + && e.getCause().getClass().getName().toString().equals("java.lang.IllegalArgumentException")) { + return 0; + } + } + return -1; + } +} + +class ConstructorComparator implements Comparator { + @Override + public int compare(Object c1, Object c2) { + byte[] b1 = c1.toString().getBytes(Charset.defaultCharset()); + byte[] b2 = c2.toString().getBytes(Charset.defaultCharset()); + int len = (b1.length < b2.length ? b1.length : b2.length); + for (int i = 0; i < len; i++) { + if (b1[i] < b2[i]) { + return 1; + } else if (b1[i] > b2[i]) { + return -1; + } + } + if (b1.length > b2.length) { + return -1; + } else if (b1.length < b2.length) { + return 1; + } + return 1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/RT1075-rt-EH-MethodInvokeInvocationTargetExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/RT1075-rt-EH-MethodInvokeInvocationTargetExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..7d8afa9e893572e79b9892cc8b7650054e9056e7 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT1075-rt-EH-MethodInvokeInvocationTargetExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=MethodInvokeInvocationTargetExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/RT1075-rt-EH-MethodInvokeInvocationTargetExceptionTest/MethodInvokeInvocationTargetExceptionTest.java b/test/testsuite/ouroboros/eh_test/RT1075-rt-EH-MethodInvokeInvocationTargetExceptionTest/MethodInvokeInvocationTargetExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b54a3729dbe8c045b8e8a5485d44c56bd75e01ca --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/RT1075-rt-EH-MethodInvokeInvocationTargetExceptionTest/MethodInvokeInvocationTargetExceptionTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodInvokeInvocationTargetExceptionTest + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Create a Method method. + * -#step2: Generate an instance object of the method and assign parameters. + * -#step3: Call the method's invoke method. + * -#step4: Check the InvocationTargetException thrown by invoke Method. + * -@Expect: 0\n + * -@Priority: High + * -@Source: MethodInvokeInvocationTargetExceptionTest.java + * -@ExecuteClass: MethodInvokeInvocationTargetExceptionTest + * -@ExecuteArgs: + */ + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class MethodInvokeInvocationTargetExceptionTest { + public static void main(String[] args) { + try { + invokeMethod(); + } catch (InvocationTargetException e) { + System.out.println(0); + } catch (Exception e) { + System.out.println(3); + } + } + + static void invokeMethod() + throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException { + Method method = Class.forName("java.lang.Class").getDeclaredMethod("getConstructor", Class[].class); + Object instance = Class.forName("java.security.CodeSigner"); + Object[] parameters = new Object[1]; + + parameters[0] = + new Class[]{ + java.security.CodeSigner.class, + java.util.concurrent.locks.AbstractOwnableSynchronizer.class, + java.util.concurrent.locks.AbstractOwnableSynchronizer.class, + java.util.LinkedHashMap.class, + java.nio.channels.AsynchronousFileChannel.class, + java.sql.Time.class, + java.util.EnumMap.class, + java.nio.channels.FileLock.class, + java.util.WeakHashMap.class + }; + + method.invoke(instance, parameters); + System.out.println(2); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n diff --git a/test/testsuite/ouroboros/eh_test/issue-RT0065-rt-eh-UninitializedExNullPointerExceptionTest/Makefile b/test/testsuite/ouroboros/eh_test/issue-RT0065-rt-eh-UninitializedExNullPointerExceptionTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..b0170801966668ad0b9176f5d76799ae4c0861e2 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/issue-RT0065-rt-eh-UninitializedExNullPointerExceptionTest/Makefile @@ -0,0 +1,3 @@ +APP=UninitializedExNullPointerExceptionTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/eh_test/issue-RT0065-rt-eh-UninitializedExNullPointerExceptionTest/UninitializedExNullPointerExceptionTest.java b/test/testsuite/ouroboros/eh_test/issue-RT0065-rt-eh-UninitializedExNullPointerExceptionTest/UninitializedExNullPointerExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..319c123bd783abf0f47792624356bfd31b7b797f --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/issue-RT0065-rt-eh-UninitializedExNullPointerExceptionTest/UninitializedExNullPointerExceptionTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UninitializedExNullPointerExceptionTest.java + * -@TestCaseName: Test Jvm instr: invoke special throw NullPointException. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Declare a static class. + * -#step2: Invoke a method of static class. + * -#step3: Check NullPointException is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: UninitializedExNullPointerExceptionTest.java + * -@ExecuteClass: UninitializedExNullPointerExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class UninitializedExNullPointerExceptionTest { + static int processResult = 2; + static UninitializedExNullPointerExceptionTest iv; + + private void proc2() { + } + + /** + * Test Jvm instr: invoke special throw NullPointException. + */ + public static void proc1() { + try { + iv.proc2(); // the invoke special instruction is used here + } catch (NullPointerException e) { + processResult = 0; // STATUS_PASSED + } + } + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + proc1(); + return processResult; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/issue-RT0068-rt-eh-JvmInitializeOutOfMemoryErrorTest/JvmInitializeOutOfMemoryErrorTest.java b/test/testsuite/ouroboros/eh_test/issue-RT0068-rt-eh-JvmInitializeOutOfMemoryErrorTest/JvmInitializeOutOfMemoryErrorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..6e81f97b0d0397b2421cb938d6f8949d21e00cda --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/issue-RT0068-rt-eh-JvmInitializeOutOfMemoryErrorTest/JvmInitializeOutOfMemoryErrorTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: JvmInitializeOutOfMemoryErrorTest.java + * -@TestCaseName: Test jvm instr: invoke virtual thrown Exception InInitializerError. + * -@TestCaseType: Function Test + * -@RequirementName: [运行时需求]支持Java异常处理 + * -@Brief: + * -#step1: Initialize a big int param, beyond 512M. + * -#step2: Check OutOfMemoryError is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: JvmInitializeOutOfMemoryErrorTest.java + * -@ExecuteClass: JvmInitializeOutOfMemoryErrorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class JvmInitializeOutOfMemoryErrorTest { + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + /** + * main test fun + * + * @return status code + */ + public static int run(String[] argv, PrintStream out) { + JvmInitializeOutOfMemoryErrorTest tTest = new JvmInitializeOutOfMemoryErrorTest(); + return tTest.test(); + } + + /** + * Test jvm instr: invoke virtual thrown Exception InInitializerError. + * + * @return status code + */ + public static int test() { + try { + int[] num; + num = new int[1024 * 1024 * 1280]; // 1024*1024*4B = 4M, *128=512M + num[0] = 1; // If no this, y = new int[] will be optimizated and deleted. + } catch (OutOfMemoryError e2) { + return 0; + } + return 2; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/eh_test/issue-RT0068-rt-eh-JvmInitializeOutOfMemoryErrorTest/Makefile b/test/testsuite/ouroboros/eh_test/issue-RT0068-rt-eh-JvmInitializeOutOfMemoryErrorTest/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..8164fada0f4bfef161e5ecb958f2b1fabfdd1a83 --- /dev/null +++ b/test/testsuite/ouroboros/eh_test/issue-RT0068-rt-eh-JvmInitializeOutOfMemoryErrorTest/Makefile @@ -0,0 +1,3 @@ +APP=JvmInitializeOutOfMemoryErrorTest +include $(MAPLE_BUILD_CORE)/config/common_test.mk +include $(MAPLE_BUILD_CORE)/Maple.common_test.mk diff --git a/test/testsuite/ouroboros/fuzzapi_test/RT0001-rt-fuzzapi-PipedReaderEH/Message125004.java b/test/testsuite/ouroboros/fuzzapi_test/RT0001-rt-fuzzapi-PipedReaderEH/Message125004.java new file mode 100755 index 0000000000000000000000000000000000000000..97abbf0ecccbb80768311e6aae2658caa37246d1 --- /dev/null +++ b/test/testsuite/ouroboros/fuzzapi_test/RT0001-rt-fuzzapi-PipedReaderEH/Message125004.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Message125004.java + *- @Title/Destination: PipedReader.getField() should get correct unstack when EH + *- @Brief: + *- @Expect:expected.txt + *- @Priority: High + *- @Source: Message125004.java + *- @ExecuteClass: Message125004 + *- @ExecuteArgs: + */ + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class Message125004 { + private static int RES = 99; + private static Class clazz; + + public static void main(String[] args) { + int result; + try { + result = message125004(); + if (result == 4 && Message125004.RES == 89) { + result = 0; + } + System.out.println(result); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + /**测试实例:[{NeedRandomClass=java.io.PipedReader}] 测试入参:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ257 测试api信息:java.lang.Class + * 测试api信息:getField + 测试api信息:String + */ + public static int message125004() { + try { + clazz = Class.forName("java.lang.Class"); + Method method = clazz.getMethod("getField",java.lang.String.class); + String parameters1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ257"; + Class instance = Class.forName("java.io.PipedReader") ; + Object result1 = method.invoke(instance, parameters1); + Message125004.RES -= 10; + return 4; + } catch (InvocationTargetException e) { + // 只打印类型 由Agent端接受进行对比 + // 打印全错误信息 +// e.printStackTrace(); + Message125004.RES -= 10; + return 4; + } catch (Exception e) { + // 只打印类型 由Agent端接受进行对比 + // 打印全错误信息 +// e.printStackTrace(); + Message125004.RES -= 10; + return 4; + } + } + + +} + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 diff --git a/test/testsuite/ouroboros/fuzzapi_test/RT0002-rt-fuzzapi-EHOrder/Message011706.java b/test/testsuite/ouroboros/fuzzapi_test/RT0002-rt-fuzzapi-EHOrder/Message011706.java new file mode 100755 index 0000000000000000000000000000000000000000..3717d429d50e83d13732243dce96832c64d1719d --- /dev/null +++ b/test/testsuite/ouroboros/fuzzapi_test/RT0002-rt-fuzzapi-EHOrder/Message011706.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Message011706.java + *- @Title/Destination: java.lang.reflect.Method/invoke/ObjectAndObject[],check EH order + *- @Brief: + *- @Expect:expected.txt + *- @Priority: High + *- @Source: Message011706.java + *- @ExecuteClass: Message011706 + *- @ExecuteArgs: + */ + +import java.lang.reflect.*; +import java.util.*; + +public class Message011706 { + public static Class clazz; + private static List resultlist = new LinkedList<>(); + + public static void main(String[] args) { + try { + System.out.println(messageCommonUse()); + } catch (Exception e) { + System.out.println(e); + } + } + + + public static int messageCommonUse() { + try { + clazz = Class.forName("java.lang.reflect.Method"); + Method method = clazz.getMethod("invoke",Object.class,Object[].class); + String fcn2 = "java.util.concurrent.ConcurrentHashMap"; + int mIndex6 = 1; + Method[] methods2 = Class.forName(fcn2).getDeclaredMethods(); + Arrays.sort(methods2, new ConstructorComparator()); + Object instance = methods2[mIndex6]; + Constructor con = java.lang.StringBuffer.class.getDeclaredConstructor(); + Object param1 = con.newInstance(); + Object param2[] = new Object[4]; + Constructor con0 = java.lang.StringBuffer.class.getDeclaredConstructor(); + param2[0] = con0.newInstance(); + Constructor con1 = java.security.spec.MGF1ParameterSpec.class.getDeclaredConstructor(java.lang.String.class); + param2[1] = con1.newInstance("abcdefghijklmnopqrstuvwxxzABCDEFGHIJKLMNOPQRSTUVWXYZ-9223372036854775551"); + Constructor con2 = java.util.Stack.class.getDeclaredConstructor(); + param2[2] = con2.newInstance(); + Constructor con3 = java.security.spec.ECGenParameterSpec.class.getDeclaredConstructor(java.lang.String.class); + param2[3] = con3.newInstance("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); + Object Result = method.invoke(instance,param1,param2); + System.out.println(Result); + } catch (Exception e) { + if (e.toString().equals("java.lang.reflect.InvocationTargetException") && + e.getCause().getClass().getName().toString().equals("java.lang.IllegalArgumentException")) { + return 0; + } + } + return -1; + } +} + +class ConstructorComparator implements Comparator{ + @Override + public int compare(Object c1, Object c2) { + byte[] b1 = c1.toString().getBytes(); + byte[] b2 = c2.toString().getBytes(); + int len = (b1.lengthb2[i]) { + return -1; + } + } + if (b1.length > b2.length) { + return -1; + } else if (b1.length < b2.length) { + return 1; + } + return 1; + } + +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/fuzzapi_test/RT0003-rt-fuzzapi-noStartThreadInfo/ThreadcountStackFramesTest.java b/test/testsuite/ouroboros/fuzzapi_test/RT0003-rt-fuzzapi-noStartThreadInfo/ThreadcountStackFramesTest.java new file mode 100755 index 0000000000000000000000000000000000000000..e75832197b087feb0ddf31b2d80fb4966267cf3f --- /dev/null +++ b/test/testsuite/ouroboros/fuzzapi_test/RT0003-rt-fuzzapi-noStartThreadInfo/ThreadcountStackFramesTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadcountStackFramesTest.java + *- @Title/Destination: Thread api: countStackFrames() + *- @Brief: + *- @Expect:expected.txt + *- @Priority: High + *- @Source: ThreadcountStackFramesTest.java + *- @ExecuteClass: ThreadcountStackFramesTest + *- @ExecuteArgs: + */ + +public class ThreadcountStackFramesTest { + static int RES = 99; + public static void main(String[] args) { + System.out.println(run()); + } + + private static int run() { + int result; + result = countStackFramesTest(); + if (result == 4 && ThreadcountStackFramesTest.RES == 89) { + result = 0; + } + return result; + } + + private static int countStackFramesTest() { + Runnable ra = new MyThread1(); + String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ4294967295"; + Thread t = new Thread(ra, str); + @SuppressWarnings("deprecation") + int i = t.countStackFrames(); + if (i == 0) { + ThreadcountStackFramesTest.RES -= 10; + } + return 4; + } +} + +class MyThread1 implements Runnable { + private int ticket = 10; + @SuppressWarnings("unused") + private String name; + + public void run() { + for (int i = 0; i < 500; i++) { + if (this.ticket > 0) { + System.out.println(Thread.currentThread().getName() + "---->" + (this.ticket--)); + } + } + } + + public Object handler() { + Thread thread = new Thread(new MyThread1()); + thread.setUncaughtExceptionHandler(new MyExceptionHandler()); + thread.start(); + return thread.getUncaughtExceptionHandler(); + } + + class MyExceptionHandler implements Thread.UncaughtExceptionHandler { + + public void uncaughtException(Thread t, Throwable e) { + System.out.printf("An exception has been captured\n"); + System.out.printf("Thread:%s\n", t.getName()); + System.out.printf("Exception: %s: %s:\n", e.getClass().getName(), e.getMessage()); + System.out.printf("Stack Trace:\n"); + e.printStackTrace(); + System.out.printf("Thread status:%s\n", t.getState()); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/fuzzapi_test/RT0004-rt-fuzzapi-stackframeless/Message021404.java b/test/testsuite/ouroboros/fuzzapi_test/RT0004-rt-fuzzapi-stackframeless/Message021404.java new file mode 100755 index 0000000000000000000000000000000000000000..603834850fade1aaa05b18ec5b61dbc44c533129 --- /dev/null +++ b/test/testsuite/ouroboros/fuzzapi_test/RT0004-rt-fuzzapi-stackframeless/Message021404.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Message021404.java + *- @Title/Destination: Unsafe api: getUnsafe().when invoke use reflect,stack frame will miss one + *- @Brief: + *- @Expect:expected.txt + *- @Priority: High + *- @Source: Message021404.java + *- @ExecuteClass: Message021404 + *- @ExecuteArgs: + */ + + +import sun.misc.Unsafe; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class Message021404 { + private static int res = 99; + public static void main(String[] args) { + try { + System.out.println(run()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static int run() throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { + int result; + result = message021404(); + if (result == 4 && Message021404.res == 89) { + result = 0; + } + return result; + } + + private static int message021404() throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { + Field f = Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + Unsafe s = (Unsafe)f.get(null); + Method m = Unsafe.class.getDeclaredMethod("getUnsafe"); + m.invoke(s); + Message021404.res -= 10; + return 4; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/fuzzapi_test/issue-RT0901-rt-fuzzapi-Message61004-subStringOOM/Message61004.java b/test/testsuite/ouroboros/fuzzapi_test/issue-RT0901-rt-fuzzapi-Message61004-subStringOOM/Message61004.java new file mode 100755 index 0000000000000000000000000000000000000000..87eee23543b335ee87f355876719c7661cad8cda --- /dev/null +++ b/test/testsuite/ouroboros/fuzzapi_test/issue-RT0901-rt-fuzzapi-Message61004-subStringOOM/Message61004.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Message61004.java + *- @Title/Destination: String api: subString(),OOM + *- @Brief: + *- @Expect:expected.txt + *- @Priority: High + *- @Source: Message61004.java + *- @ExecuteClass: Message61004 + *- @ExecuteArgs: + */ + + +public class Message61004 { + + private static int RES = 99; + private static Class clazz; + + public static void main(String[] args) { +//message61104(); + int result = 2; + try { + result = message61004(); + if (result == 4 && Message61004.RES == 89) { + result = 0; + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println(result); + } + + /* 测试实例:测试入参:1389308892测试入参:-1727641912测试api信息:java.lang.String测试api信息:substring测试api信息:int测试api信息:int + */ + private static int message61004() { + String str = null; + try { + clazz = Class.forName("java.lang.String"); +// Method[] met = clazz.getMethods(); +// Method method = clazz.getMethod("substring", int.class, int.class); + int parameters1 = 1389308892; + int parameters2 = -1727641912; + String instance = new String(); + instance.substring(parameters1, parameters2); +// Object result1 = method.invoke(instance, parameters1, parameters2); + } catch (Error e) { + str = e.getClass().toString(); + //System.out.println(str); + //e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + if (str != null && str.equals("class java.lang.OutOfMemoryError")) { + Message61004.RES -= 10; + } + return 4; + } + +} + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/other_test/RT0001-rt-other-CharacterNativeUncover/CharacterNativeUncover.java b/test/testsuite/ouroboros/other_test/RT0001-rt-other-CharacterNativeUncover/CharacterNativeUncover.java new file mode 100755 index 0000000000000000000000000000000000000000..46990760bcba1c05bf4e8498dc8567b7c7c81d07 --- /dev/null +++ b/test/testsuite/ouroboros/other_test/RT0001-rt-other-CharacterNativeUncover/CharacterNativeUncover.java @@ -0,0 +1,586 @@ +/** + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: natives/CharacterNativeUncover.java + * -@Title/Destination: Character Methods + * -@Brief: + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterNativeUncover.java + * -@ExecuteClass: CharacterNativeUncover + * -@ExecuteArgs: + */ + +public class CharacterNativeUncover { + private static int res = 99; + + public static void main(String[] args) { + int result = 2; + CharacterDemo1(); + if (result == 2 && res == 53) { + res = 0; + } + System.out.println(res); + } + + + public static void CharacterDemo1() { + Character character = new Character('a'); + test1(character); + test2(character); + test3(character); + test4(character); + test5(character); + test6(character); + test7(character); + test8(character); + test9(character); + test10(character); + test11(character); + test12(character); + test13(character); + test14(character); + test15(character); + test16(character); + test17(character); + test18(character); + test19(character); + test20(character); + test21(character); + test22(character); + test23(character); + } + + + /** + * static native boolean isLowerCaseImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test1(Character character) { + try { + boolean flag = Character.isLowerCase(97);//isLowerCaseImpl() called by isLowerCase(); + // System.out.println(flag); + if (flag) { + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isUpperCaseImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test2(Character character) { + try { + boolean flag = Character.isUpperCase(65);//isUpperCaseImpl() called by isUpperCase(); + //System.out.println(flag); + if (flag) { + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isTitleCaseImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test3(Character character) { + try { + boolean flag = Character.isTitleCase(0x01c8);//isTitleCaseImpl() called by isTitleCase(); + //System.out.println(flag); + if (flag) { + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isDigitImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test4(Character character) { + try { + boolean flag = Character.isDigit(0x06f8);//isDigitImpl() called by isDigit();judge if it`s number; + //System.out.println(flag); + if (flag) { + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isDefinedImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test5(Character character) { + try { + boolean flag = Character.isDefined(0x012345);//isDefinedImpl() called by isDefined(); + //System.out.println(flag); + if (flag) { + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + /** + * static native boolean isLetterImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test6(Character character) { + try { + boolean flag = Character.isLetter(0x0065);//isLetterImpl() called by isLetter();tell if it`s char type; + //System.out.println(flag); + if (flag) { + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isLetterOrDigitImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test7(Character character) { + try { + boolean flag = Character.isLetterOrDigit(0x0033);//isLetterOrDigitImpl() called by isLetterOrDigit();tell if it`s char type; + //System.out.println(flag); + if (flag) { + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isAlphabeticImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test8(Character character) { + try { + boolean flag = Character.isAlphabetic(0x0065);//isAlphabeticImpl() called by isAlphabetic(); tell if it`s char type; + //System.out.println(flag); + if (flag) { + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isIdeographicImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test9(Character character) { + try { + boolean flag = Character.isIdeographic(0x0065);//isIdeographicImpl() called by isIdeographic(); + + if (!flag) { + //System.out.println(flag); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isUnicodeIdentifierStartImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test10(Character character) { + try { + boolean flag = Character.isUnicodeIdentifierStart(0x0065);//isUnicodeIdentifierStartImpl() called by isUnicodeIdentifierStart(); + + if (flag) { + //System.out.println(flag); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isUnicodeIdentifierPartImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test11(Character character) { + try { + boolean flag = Character.isUnicodeIdentifierPart(0x053e);//isUnicodeIdentifierPartImpl() called by isUnicodeIdentifierPart(); + + if (flag) { + //System.out.println(flag); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * ensure the char should be a ignoreable char in java or unicode identifier + * static native boolean isIdentifierIgnorableImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test12(Character character) { + try { + boolean flag = Character.isIdentifierIgnorable(0x053e);//isIdentifierIgnorableImpl() called by isIdentifierIgnorable(); + + if (!flag) { + //System.out.println(flag); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native int toLowerCaseImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test13(Character character) { + try { + int num = Character.toLowerCase(0x053e);//toLowerCaseImpl() called by toLowerCase(); + + if (num == 1390) { + //System.out.println(num); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + /** + * static native int toUpperCaseImpl(int codePoint) + * + * @param character + * @return + */ + public static boolean test14(Character character) { + try { + int num = Character.toUpperCase(0x053e);//toUpperCaseImpl() called by toUpperCase(); + + if (num == 1342) { + //System.out.println(num); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native int toTitleCaseImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test15(Character character) { + try { + int num = Character.toTitleCase(0x053e);//toTitleCaseImpl() called by toTitleCase(); + + if (num == 1342) { + //System.out.println(num); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + /** + * native static int digitImpl(int codePoint, int radix); + * + * @param character + * @return + */ + public static boolean test16(Character character) { + try { + int num = Character.digit(9, 2);//digitImpl() called by digit(); + + if (num == -1) { + //System.out.println(num); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * native static int getNumericValueImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test17(Character character) { + try { + int num = Character.getNumericValue(9);//getNumericValueImpl() called by getNumericValue(); + + if (num == -1) { + //System.out.println(num); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native boolean isSpaceCharImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test18(Character character) { + try { + boolean flag = Character.isSpaceChar(9);//isSpaceCharImpl() called by isSpaceChar(); + + if (!flag) { + //System.out.println(flag); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * native static boolean isWhitespaceImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test19(Character character) { + try { + boolean flag = Character.isWhitespace(9);//isWhitespaceImpl() called by isWhitespace(); + + if (flag) { + //System.out.println(flag); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * static native int getTypeImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test20(Character character) { + try { + int num = Character.getType(9);//getTypeImpl() called by getType(); + + if (num == 15) { + //System.out.println(num); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + /** + * native static byte getDirectionalityImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test21(Character character) { + try { + int num = Character.getDirectionality(9);//getDirectionalityImpl() called by getDirectionality(); + + if (num == 11) { + //System.out.println(num); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * native static boolean isMirroredImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test22(Character character) { + try { + boolean flag = Character.isMirrored(9);//isMirroredImpl() called by isMirrored(); + + if (!flag) { + //System.out.println(flag); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + + /** + * private static native String getNameImpl(int codePoint); + * + * @param character + * @return + */ + public static boolean test23(Character character) { + try { + String string = Character.getName(9);//getNameImpl() called by getName(); + + //if (string.equals("CHARACTER TABULATION")) { + if (string.equals("")) { + //System.out.println(string); + CharacterNativeUncover.res = CharacterNativeUncover.res - 2; + } else { + return false; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/other_test/RT0002-rt-other-ClassNativeUncover/ClassNativeUncover.java b/test/testsuite/ouroboros/other_test/RT0002-rt-other-ClassNativeUncover/ClassNativeUncover.java new file mode 100755 index 0000000000000000000000000000000000000000..849c5b24b1a9a410e2d46f9dd0eeca26614817bc --- /dev/null +++ b/test/testsuite/ouroboros/other_test/RT0002-rt-other-ClassNativeUncover/ClassNativeUncover.java @@ -0,0 +1,381 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: natives/ClassNativeUncover.java + * -@Title/Destination: ClassNativeUncover Methods + * -@Brief: + * -@Expect: 0\n + * -@Priority: High + * -@Source: ClassNativeUncover.java + * -@ExecuteClass: ClassNativeUncover + * -@ExecuteArgs: + */ + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; + +public class ClassNativeUncover { + private static int res = 99; + public String name; + + public ClassNativeUncover() { + super(); + + } + + public ClassNativeUncover(String name) { + super(); + this.name = name; + } + + public static void main(String[] args) { + int result = 2; + ClassDemo1(); + + if (result == 2 && res == 65) { + res = 0; + } + System.out.println(res); + } + + + public static void ClassDemo1() { + Class class1 = ClassNativeUncover.class; + test1(class1); + test2(class1); + test3(class1); + test4(class1); + test5(class1); + test6(class1); + test7(class1); + test8(class1); + test9(class1); + test10(class1); + test11(class1); + test12(class1); + test13(class1); + test14(class1); + test15(class1); + test16(class1); + test17(class1); + } + + /** + * public native Class getDeclaringClass(); + * + * @param class1 + */ + public static void test1(Class class1) { + try { + boolean flag = class1.isMemberClass();//getDeclaringClass() called by isMemberClass(); + if (!flag) { + //System.out.println(flag); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } + + + /** + * public native Class getEnclosingClass(); + * + * @param class1 + */ + public static void test2(Class class1) { + try { + String string = class1.getCanonicalName();//getEnclosingClass() called by getCanonicalName(); + if (string.equals("ClassNativeUncover")) { + //System.out.println(string); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * public native boolean isAnonymousClass(); + * + * @param class1 + */ + public static void test3(Class class1) { + try { + boolean flag = class1.isAnonymousClass(); + if (!flag) { + //System.out.println(flag); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * private native Field getPublicFieldRecursive(String name); + * + * @param class1 + */ + public static void test4(Class class1) { + try { + Field field = class1.getField("name");//get the whole attributes which named "public" and inherited from parent class;getPublicFieldRecursive() called by getField(); + if (field.toString().equals("public java.lang.String ClassNativeUncover.name")) { + //System.out.println(field.toString()); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + /** + * public native Field[] getDeclaredFields(); + * + * @param class1 + */ + public static void test5(Class class1) { + try { + Field[] fields = class1.getDeclaredFields();//get all declarative attributes; + if (fields != null && fields.length > 0) { +// for(Field field:fields ) { +// System.out.println(field); +// } + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + /** + * public native Method[] MethodsUnchecked(boolean publicOnly); + * + * @param class1 + */ + public static void test6(Class class1) { + try { + Method[] methods = class1.getDeclaredMethods();//get declarative methods;getDeclaredMethodsUnchecked() called by getDeclaredMethods(); + if (methods != null && methods.length > 0) { +// for(Method method:methods ) { +// System.out.println(method); +// } + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + /** + * private native Constructor[] getDeclaredConstructorsInternal(boolean publicOnly); + * + * @param class1 + */ + public static void test7(Class class1) { + try { + Constructor[] constructors = class1.getConstructors();//get public constructions and inherited from parent class;getDeclaredConstructorsInternal()called bygetConstructors(); + if (constructors != null && constructors.length > 0) { +// for(Constructor constructor:constructors ) { +// System.out.println(constructor); +// } + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * dcons + * private native Constructor[] getDeclaredConstructorsInternal(boolean publicOnly); + * + * @param class1 + */ + public static void test8(Class class1) { + try { + Constructor[] constructors = class1.getDeclaredConstructors();//get all of declarative construcors;getDeclaredConstructorsInternal() called by getDeclaredConstructors; + if (constructors != null && constructors.length > 0) { +// for(Constructor constructor:constructors ) { +// System.out.println(constructor); +// } + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + /** + * public native Field getDeclaredField(String name) throws NoSuchFieldException; + * + * @param class1 + */ + public static void test9(Class class1) { + try { + Field field = class1.getDeclaredField("res"); + if (field.toString().equals("private static int ClassNativeUncover.res")) { + //System.out.println(field); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + } + + + /** + * private native Constructor getDeclaredConstructorInternal(Class[] args); + * + * @param class1 + */ + public static void test10(Class class1) { + try { + Constructor constructor = class1.getConstructor(new Class[]{String.class});//getDeclaredConstructorInternal() called by getConstructor; + if (constructor.toString().equals("public ClassNativeUncover(java.lang.String)")) { + //System.out.println(constructor); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + + /** + * private native Constructor getDeclaredConstructorInternal(Class[] args); + * + * @param class1 + */ + public static void test11(Class class1) { + try { + Constructor constructor = class1.getDeclaredConstructor(new Class[]{String.class});//getDeclaredConstructorInternal() called by getDeclaredConstructor(); + if (constructor.toString().equals("public ClassNativeUncover(java.lang.String)")) { + //System.out.println(constructor); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + + + /** + * private native String getInnerClassName(); + * + * @param class1 + */ + public static void test12(Class class1) { + try { + String string = class1.getSimpleName();//getInnerClassName() called by getSimpleName(); + if (string.equals("ClassNativeUncover")) { + ClassNativeUncover.res = ClassNativeUncover.res - 2; + //System.out.println(string); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * private native String[] getSignatureAnnotation(); + * + * @param class1 + */ + public static void test13(Class class1) { + try { + TypeVariable[] typeVariables = class1.getTypeParameters();//return a array length 0;getSignatureAnnotation() called by getTypeParameters(); + if (typeVariables.getClass().toString().equals("class [Ljava.lang.reflect.TypeVariable;") && typeVariables.length == 0) { + //System.out.println(typeVariables.length); + //System.out.println(typeVariables.getClass().toString()); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * private native String[] getSignatureAnnotation(); + * + * @param class1 + */ + public static void test14(Class class1) { + try { + Type type = class1.getGenericSuperclass();//getSignatureAnnotation()called by getGenericSuperclass; + if (type.toString().equals("class java.lang.Object")) { + //System.out.println(type); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * private native String[] getSignatureAnnotation(); + * + * @param class1 + */ + public static void test15(Class class1) { + + Type[] type = class1.getGenericInterfaces();//getSignatureAnnotation() called by getGenericInterfaces; + if (type.length == 0 && type.getClass().toString().equals("class [Ljava.lang.Class;")) { + //System.out.println(type.length); + //System.out.println(type.getClass().toString()); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } + + /** + * private native Method getDeclaredMethodInternal(String name, Class[] args); + * + * @param class1 + */ + public static void test16(Class class1) { + try { + Method method = class1.getMethod("ClassDemo1");//getDeclaredMethodInternal() called by getMethod() + if (method.toString().equals("public static void ClassNativeUncover.ClassDemo1()")) { + //System.out.println(method); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + + public static void test17(Class class1) { + try { + Annotation[] a = class1.getAnnotations(); //getDeclaredAnnotations() called by getAnnotations() + if (a.length == 0 && a.getClass().toString().equals("class [Ljava.lang.annotation.Annotation;")) { + //System.out.println(a.length); + //System.out.println(a.getClass().toString()); + ClassNativeUncover.res = ClassNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/other_test/RT0003-rt-other-ConstructorNativeUncover/ConstructorNativeUncover.java b/test/testsuite/ouroboros/other_test/RT0003-rt-other-ConstructorNativeUncover/ConstructorNativeUncover.java new file mode 100755 index 0000000000000000000000000000000000000000..c386a45bf7070d0545f98711cef56c42f6b3c850 --- /dev/null +++ b/test/testsuite/ouroboros/other_test/RT0003-rt-other-ConstructorNativeUncover/ConstructorNativeUncover.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: reflect.natives/ConstructorNativeUncover.java + * -@Title/Destination: ConstructorNativeUncover Methods + * -@Brief: + * -@Expect: 0\n + * -@Priority: High + * -@Source: ConstructorNativeUncover.java + * -@ExecuteClass: ConstructorNativeUncover + * -@ExecuteArgs: + */ + +import java.lang.reflect.Constructor; +import java.util.Arrays; + +public class ConstructorNativeUncover { + + private static int res = 99; + + public ConstructorNativeUncover() { + super(); + // TODO Auto-generated constructor stub + } + + public static void main(String[] args) { + int result = 2; + ConstructorDemo1(); + if (result == 2 && res == 97) { + res = 0; + } + System.out.println(res); + } + + + public static void ConstructorDemo1() { + ConstructorNativeUncover constructorNativeUncover = new ConstructorNativeUncover(); + test(constructorNativeUncover); + } + + + /** + * public native Class[] getExceptionTypes(); + * @param constructorNativeUncover + * @return + */ + public static boolean test(ConstructorNativeUncover constructorNativeUncover) { + try { + Class class1 = constructorNativeUncover.getClass(); + Constructor constructor = class1.getConstructor(new Class[] {}); + Class[] classes = constructor.getExceptionTypes(); + if (classes.length == 0 && classes.getClass().toString().equals("class [Ljava.lang.Class;")) { +// System.out.println(classes.getClass().toString()); +// System.out.println(classes.length); + ConstructorNativeUncover.res = ConstructorNativeUncover.res - 2; + } + } catch(NoSuchMethodException e) { + e.printStackTrace(); + return false; + } + return true; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/other_test/RT0005-rt-other-MethodNativeUncover/MethodNativeUncover.java b/test/testsuite/ouroboros/other_test/RT0005-rt-other-MethodNativeUncover/MethodNativeUncover.java new file mode 100755 index 0000000000000000000000000000000000000000..d41619803a01e62c116fa161d0bf778a8c5be0de --- /dev/null +++ b/test/testsuite/ouroboros/other_test/RT0005-rt-other-MethodNativeUncover/MethodNativeUncover.java @@ -0,0 +1,104 @@ + + +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: reflect.natives/MethodNativeUncover.java + * -@Title/Destination: MethodNativeUncover Methods + * -@Brief: + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodNativeUncover.java + * -@ExecuteClass: MethodNativeUncover + * -@ExecuteArgs: + */ + +import java.lang.reflect.Method; + +public class MethodNativeUncover { + +private static int res = 99; + + public static void sayHello() { + String hello = "halo"; + } + + + public static void main(String[] args) { + int result = 2; + MethodDemo1(); + if (result == 2 && res == 95) { + res = 0; + } + System.out.println(res); + } + + + public static void MethodDemo1(){ + MethodNativeUncover methodNativeUncover = new MethodNativeUncover(); + test(methodNativeUncover); + test1(methodNativeUncover); + + } + + /** + * public native Class[] getExceptionTypes(); + * @param methodNativeUncover + */ + public static void test(MethodNativeUncover methodNativeUncover) { + Class class1 = methodNativeUncover.getClass(); + try { + Method method = class1.getMethod("sayHello"); + Class[] newClass = method.getExceptionTypes(); + if (newClass.length == 0 && newClass.getClass().toString().equals("class [Ljava.lang.Class;")) { + //System.out.println(newClass.length); + //System.out.println(newClass.getClass()); + MethodNativeUncover.res = MethodNativeUncover.res - 2; + } + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } + + } + + + /** + * public native Object getDefaultValue(); + * @param methodNativeUncover + */ + public static void test1(MethodNativeUncover methodNativeUncover) { + Class class1 = methodNativeUncover.getClass(); + try { + Method method = class1.getMethod("sayHello"); + Object object = method.getDefaultValue(); + if (object == null) { + //System.out.println(object); + MethodNativeUncover.res = MethodNativeUncover.res - 2; + } + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } + + } + + + +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/other_test/RT0006-rt-other-ThreadNativeUncover/ThreadNativeUncover.java b/test/testsuite/ouroboros/other_test/RT0006-rt-other-ThreadNativeUncover/ThreadNativeUncover.java new file mode 100755 index 0000000000000000000000000000000000000000..8c27d02eab6373f7f6d0cd5f52cb148a46fc2a89 --- /dev/null +++ b/test/testsuite/ouroboros/other_test/RT0006-rt-other-ThreadNativeUncover/ThreadNativeUncover.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Ouroboros/rt_test/ThreadNativeUncover.java + * - @Title/Destination: ThreadNativeUncover Methods getState() + * - @Brief: + * - @Expect:expected.txt + * - @Priority: High + * - @Source: ThreadNativeUncover.java + * - @ExecuteClass: ThreadNativeUncover + * - @ExecuteArgs: + */ + +import java.lang.Thread.State; + +public class ThreadNativeUncover { + private static int res = 99; + + public static void main(String[] args) { + int result = 2; + ThreadDemo1(); + if (result == 2 && res == 97) { + res = 0; + } + System.out.println(res); + } + + public static void ThreadDemo1() { + Thread thread = new Thread(); + test(thread); + } + + /** + * private native int nativeGetStatus(boolean hasBeenStarted); + * @param thread + */ + public static void test(Thread thread) { + try { + State state = thread.getState();//nativeGetStatus() called by getState(); + if (state.toString().equals("NEW")) { + ThreadNativeUncover.res = ThreadNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/other_test/RT0007-rt-other-ThrowableNativeUncover/ThrowableNativeUncover.java b/test/testsuite/ouroboros/other_test/RT0007-rt-other-ThrowableNativeUncover/ThrowableNativeUncover.java new file mode 100755 index 0000000000000000000000000000000000000000..348cdd746346b61568adc3144a4b8b1202bc4671 --- /dev/null +++ b/test/testsuite/ouroboros/other_test/RT0007-rt-other-ThrowableNativeUncover/ThrowableNativeUncover.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: natives/ThrowableNativeUncover.java + * -@Title/Destination: ThrowableNativeUncover Methods + * -@Brief: + * -@Expect: 0\n + * -@Priority: High + * -@Source: ThrowableNativeUncover.java + * -@ExecuteClass: ThrowableNativeUncover + * -@ExecuteArgs: + */ + +public class ThrowableNativeUncover { + private static int res = 99; + + public static void main(String[] args) { + ThrowableDemo1(); + } + + + + public static void ThrowableDemo1() { + int result = 2; + Throwable throwable = new Throwable(); + test(throwable); + test1(throwable); + if (result == 2 && res == 95) { + res = 0; + } + System.out.println(res); + } + + /** + * private static native Object nativeFillInStackTrace(); + * @param throwable + * @return + */ + public static boolean test(Throwable throwable) { + + try { + Throwable throwable2 = throwable.fillInStackTrace();//nativeFillInStackTrace() called by fillInStackTrace(); + if (throwable2.toString().equals("java.lang.Throwable")) { + //System.out.println(throwable2.toString()); + ThrowableNativeUncover.res = ThrowableNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + + } + return true; + } + + + /** + * private static native StackTraceElement[] nativeGetStackTrace(Object stackState); + * @param throwable + * @return + */ + public static boolean test1(Throwable throwable) { + try { + StackTraceElement[] stackTraceElements = throwable.getStackTrace();//nativeGetStackTrace() called by getStackTrace(); + if (stackTraceElements.length == 3 && stackTraceElements.getClass().toString().equals("class [Ljava.lang.StackTraceElement;")) { + //System.out.println(stackTraceElements.length); + //System.out.println(stackTraceElements.getClass().toString()); + ThrowableNativeUncover.res = ThrowableNativeUncover.res - 2; + } + } catch (Exception e) { + e.printStackTrace(); + } + + return true; + + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/other_test/issue-RT0630-rt-other-ArrayNativeUncover/ArrayNativeUncover.java b/test/testsuite/ouroboros/other_test/issue-RT0630-rt-other-ArrayNativeUncover/ArrayNativeUncover.java new file mode 100755 index 0000000000000000000000000000000000000000..caebba5bb96c495fd03f4a8c606e0ced6ea0de94 --- /dev/null +++ b/test/testsuite/ouroboros/other_test/issue-RT0630-rt-other-ArrayNativeUncover/ArrayNativeUncover.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: reflect.natives/ArrayNativeUncover.java + * -@Title/Destination: ArrayNativeUncover Methods + * -@Brief: + * -@Expect: 0\n + * -@Priority: High + * -@Source: ArrayNativeUncover.java + * -@ExecuteClass: ArrayNativeUncover + * -@ExecuteArgs: + */ +import java.lang.reflect.Array; + +public class ArrayNativeUncover { + private static int res = 99; + + public static void main(String[] args) { + int result = 2; + ArrayDemo1(); + if (result == 2 && ArrayNativeUncover.res == 97) { + result = 0; + System.out.println(result); + } + } + + public static void ArrayDemo1() { + test1(); + } + + + /** + * private static native Object createObjectArray(Class componentType, int length) throws NegativeArraySizeException; + * + * @return + */ + public static boolean test1() { + try { + Object object = Array.newInstance(String.class, 5);//createObjectArray() called by newInstance(); + if (object.getClass().toString().equals("class [Ljava.lang.String;")) { + ArrayNativeUncover.res = ArrayNativeUncover.res - 2; + return true; + } + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0001-rt-parent-AccessibleObjectExObjectequals/AccessibleObjectExObjectequals.java b/test/testsuite/ouroboros/parent_test/RT0001-rt-parent-AccessibleObjectExObjectequals/AccessibleObjectExObjectequals.java new file mode 100755 index 0000000000000000000000000000000000000000..101c925cef4a7921608b77ee0d5d41af78389add --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0001-rt-parent-AccessibleObjectExObjectequals/AccessibleObjectExObjectequals.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectExObjectequals.java + * -@TestCaseName: Exception in reflect/AccessibleObject: boolean equals(Object obj) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create Class AccessibleClass1 Field with sampleField + * -#step2: Create Object1 Get the Field of the sampleField of AccessibleClass1 through the getDeclaredField method + * -#step3: Create Object2 Get the Field of sampleField of AccessibleClass1 by getDeclaredField method + * -#step4: Call equals to compare object 1 and object 2 and confirm that they are equal + * -@Expect:0\n + * -@Priority: High + * -@Source: AccessibleObjectExObjectequals.java + * -@ExecuteClass: AccessibleObjectExObjectequals + * -@ExecuteArgs: + */ + + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.*; + +public class AccessibleObjectExObjectequals { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new AccessibleObjectExObjectequals().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = accessibleObjectExObjectequals1(); + } catch (Exception e) { + AccessibleObjectExObjectequals.res = AccessibleObjectExObjectequals.res - 20; + } + if (result == 4 && AccessibleObjectExObjectequals.res == 89) { + result = 0; + } + return result; + } + + + private int accessibleObjectExObjectequals1() throws NoSuchFieldException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + // boolean equals(Object obj) + AccessibleObject sampleField2 = AccessibleClass1.class.getDeclaredField("sampleField"); + AccessibleObject sampleField1 = AccessibleClass1.class.getDeclaredField("sampleField"); + if (sampleField2.equals(sampleField1)) { + AccessibleObjectExObjectequals.res = AccessibleObjectExObjectequals.res - 10; + } else { + AccessibleObjectExObjectequals.res = AccessibleObjectExObjectequals.res - 1; + } + return result1; + } +} + +@AccessibleAnnotation1(name = "SampleClass", value = "Sample Class Annotation") +class AccessibleClass1 { + private String sampleField; + + @AccessibleAnnotation1(name = "sampleMethod", value = "Sample Method Annotation") + public String sampleMethod() { + return "sample"; + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@interface AccessibleAnnotation1 { + String name(); + + String value(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0002-rt-parent-AccessibleObjectExObjecthashCode/AccessibleObjectExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0002-rt-parent-AccessibleObjectExObjecthashCode/AccessibleObjectExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..7d344295846865f63298e8f197ceb5a032d912fe --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0002-rt-parent-AccessibleObjectExObjecthashCode/AccessibleObjectExObjecthashCode.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectExObjecthashCode.java + * -@TestCaseName: Exception in reflect/AccessibleObject: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create Class SampleClass Field with sampleField0, sampleField1 + * -#step2: Create Object1 Get the Field of the sampleField0 of SampleClass through the getDeclaredField method + * -#step3: Create Object2 Get the Field of sampleField0 of SampleClass by getDeclaredField method + * -#step4: Create Object3 Get the Field of sampleField1 of SampleClass by getDeclaredField method + * -#step5: Call hashCode to compare, object1 and object2 confirm that they are equal, object2 and object3 confirm that + * they are not equal + * -@Expect:0\n + * -@Priority: High + * -@Source: AccessibleObjectExObjecthashCode.java + * -@ExecuteClass: AccessibleObjectExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.AccessibleObject; + +public class AccessibleObjectExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new AccessibleObjectExObjecthashCode().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = accessibleObjectExObjecthashCode1(); + } catch (Exception e) { + AccessibleObjectExObjecthashCode.res = AccessibleObjectExObjecthashCode.res - 20; + } + + if (result == 4 && AccessibleObjectExObjecthashCode.res == 89) { + result = 0; + } + return result; + } + + private int accessibleObjectExObjecthashCode1() throws NoSuchFieldException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + AccessibleObject sampleField0 = SampleClass.class.getDeclaredField("sampleField0"); + AccessibleObject sampleField1 = SampleClass.class.getDeclaredField("sampleField0"); + AccessibleObject sampleField2 = SampleClass.class.getDeclaredField("sampleField1"); + int px0 = sampleField0.hashCode(); + int px1 = sampleField1.hashCode(); + int px2 = sampleField2.hashCode(); + if (px0 == px1 && px0 != px2) { + AccessibleObjectExObjecthashCode.res = AccessibleObjectExObjecthashCode.res - 10; + } + return result1; + } +} + + +@CustomAnnotation(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass { + private String sampleField0; + + private String sampleField1; + + @CustomAnnotation(name = "sampleMethod", value = "Sample Method Annotation") + public String sampleMethod() { + return "sample"; + } + + /** + * get sampleField0 + * @return sampleField0 + */ + public String getSampleField() { + return sampleField0; + } + + /** + * set sampleField0 + * @param sampleField just for test + */ + public void setSampleField(String sampleField) { + this.sampleField0 = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@interface CustomAnnotation { + String name(); + + String value(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0003-rt-parent-AccessibleObjectExObjectnotifyAllIllegalMonitorStateException/AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0003-rt-parent-AccessibleObjectExObjectnotifyAllIllegalMonitorStateException/AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..bc34d2f413585ff8a0f49274a18dd02ae06e5097 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0003-rt-parent-AccessibleObjectExObjectnotifyAllIllegalMonitorStateException/AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect/AccessibleObject: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll() inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: AccessibleObjectExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.AccessibleObject; + +public class AccessibleObjectExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private static AccessibleObject sampleField1 = null; + + public static void main(String argv[]) throws NoSuchFieldException, SecurityException { + sampleField1 = AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.class.getDeclaredField("res"); + System.out.println(new AccessibleObjectExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = accessibleObjectExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new AccessibleObjectExObjectnotifyAllIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int accessibleObjectExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + sampleField1.notifyAll(); + AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + return result1; + } + + private class AccessibleObjectExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + try { + sampleField1.notifyAll(); + AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0004-rt-parent-AccessibleObjectExObjectnotifyIllegalMonitorStateException/AccessibleObjectExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0004-rt-parent-AccessibleObjectExObjectnotifyIllegalMonitorStateException/AccessibleObjectExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..02dc2f16beefe8e237c6570afda8622fcf12dda9 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0004-rt-parent-AccessibleObjectExObjectnotifyIllegalMonitorStateException/AccessibleObjectExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect/AccessibleObject: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: AccessibleObjectExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: AccessibleObjectExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.AccessibleObject; + +public class AccessibleObjectExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private static AccessibleObject sampleField1 = null; + + public static void main(String argv[]) throws NoSuchFieldException, SecurityException { + sampleField1 = AccessibleObjectExObjectnotifyIllegalMonitorStateException.class.getDeclaredField("res"); + System.out.println(new AccessibleObjectExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = acessibleObjectExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + AccessibleObjectExObjectnotifyIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new AccessibleObjectExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && AccessibleObjectExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int acessibleObjectExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + sampleField1.notify(); + AccessibleObjectExObjectnotifyIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectnotifyIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyIllegalMonitorStateException.res - 1; + } + return result1; + } + + private class AccessibleObjectExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + try { + sampleField1.notify(); + AccessibleObjectExObjectnotifyIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectnotifyIllegalMonitorStateException.res = AccessibleObjectExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0005-rt-parent-AccessibleObjectExObjecttoString/AccessibleObjectExObjecttoString.java b/test/testsuite/ouroboros/parent_test/RT0005-rt-parent-AccessibleObjectExObjecttoString/AccessibleObjectExObjecttoString.java new file mode 100755 index 0000000000000000000000000000000000000000..f1339279a460abe164d3a3803f82fcb6b481471d --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0005-rt-parent-AccessibleObjectExObjecttoString/AccessibleObjectExObjecttoString.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectExObjecttoString.java + * -@TestCaseName: Exception in reflect/AccessibleObject: String toString() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Call getDeclaredField to get the res of AccessibleObjectExObjecttoString as the new object of + * AccessibleObject sampleField1 + * -#step2: Call toString () on sampleField1 + * -#step3: Confirm that toString () returns correctly + * -@Expect:0\n + * -@Priority: High + * -@Source: AccessibleObjectExObjecttoString.java + * -@ExecuteClass: AccessibleObjectExObjecttoString + * -@ExecuteArgs: + */ + + +import java.lang.reflect.AccessibleObject; + +public class AccessibleObjectExObjecttoString { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new AccessibleObjectExObjecttoString().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = accessibleObjectExObjecttoString1(); + } catch (Exception e) { + AccessibleObjectExObjecttoString.res = AccessibleObjectExObjecttoString.res - 20; + } + if (result == 4 && AccessibleObjectExObjecttoString.res == 89) { + result = 0; + } + + return result; + } + + + private int accessibleObjectExObjecttoString1() throws NoSuchFieldException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ +// String toString() + AccessibleObject sampleField1 = AccessibleObjectExObjecttoString.class.getDeclaredField("res"); + String px1 = sampleField1.toString(); +// System.out.println(px1); + if (px1.equals("static int AccessibleObjectExObjecttoString.res")) { + AccessibleObjectExObjecttoString.res = AccessibleObjectExObjecttoString.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0006-rt-parent-AccessibleObjectExObjectwaitIllegalMonitorStateException/AccessibleObjectExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0006-rt-parent-AccessibleObjectExObjectwaitIllegalMonitorStateException/AccessibleObjectExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..5e3f3e3928467d1ecf37f8b42fc338e15024415d --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0006-rt-parent-AccessibleObjectExObjectwaitIllegalMonitorStateException/AccessibleObjectExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect/AccessibleObject: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: AccessibleObjectExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: AccessibleObjectExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.AccessibleObject; + +public class AccessibleObjectExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static AccessibleObject sampleField1 = null; + + public static void main(String argv[]) throws NoSuchFieldException, SecurityException { + sampleField1 = AccessibleObjectExObjectwaitIllegalMonitorStateException.class.getDeclaredField("res"); + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = accessibleObjectExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = accessibleObjectExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = accessibleObjectExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 20; + } + if (result == 4 && AccessibleObjectExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int accessibleObjectExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + sampleField1.wait(); + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int accessibleObjectExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // + // final void wait(long millis) + long millis = 123; + try { + sampleField1.wait(millis); + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } + + private static int accessibleObjectExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + sampleField1.wait(millis, nanos); + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectwaitIllegalMonitorStateException.res = AccessibleObjectExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0007-rt-parent-ArrayExObjecthashCode/ArrayExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0007-rt-parent-ArrayExObjecthashCode/ArrayExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..9bc2457b489851860ec4bf0234b41cf96855e446 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0007-rt-parent-ArrayExObjecthashCode/ArrayExObjecthashCode.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ArrayExObjecthashCode.java + * -@TestCaseName: Exception in reflect/Array: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Call Array.newInstance to create Object + * -#step2: Create Object 2 from the direct assignment of Object 1 + * -#step3: Call Array.newInstance to create Object 3 + * -#step4: Call hashCode () to compare the hashcode values of three objects. Object 1 and object 2 are equal, and + * object 1 and object 3 are not equal. + * -@Expect:0\n + * -@Priority: High + * -@Source: ArrayExObjecthashCode.java + * -@ExecuteClass: ArrayExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.reflect.Array; + +public class ArrayExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ArrayExObjecthashCode().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = arrayExObjecthashCode1(); + } catch (Exception e) { + ArrayExObjecthashCode.res = ArrayExObjecthashCode.res - 20; + } + if (result == 4 && ArrayExObjecthashCode.res == 89) { + result = 0; + } + + return result; + } + + private int arrayExObjecthashCode1() throws NoSuchFieldException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + Object ary0 = Array.newInstance(int.class, 10); + Object ary1 = ary0; + Object ary2 = Array.newInstance(int.class, 11); + int px0 = ary0.hashCode(); + int px1 = ary1.hashCode(); + int px2 = ary2.hashCode(); + + if (px0 == px1 && px0 != px2) { + ArrayExObjecthashCode.res = ArrayExObjecthashCode.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0008-rt-parent-ArrayExObjectnotifyAllIllegalMonitorStateException/ArrayExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0008-rt-parent-ArrayExObjectnotifyAllIllegalMonitorStateException/ArrayExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..1f66e9141f91ec132385970a7ff3f0304ab1775f --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0008-rt-parent-ArrayExObjectnotifyAllIllegalMonitorStateException/ArrayExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ArrayExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect/Array: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ArrayExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ArrayExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Array; + +public class ArrayExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private static Object ary1 = Array.newInstance(int.class, 10); + + public static void main(String argv[]) { + System.out.println(new ArrayExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = arrayExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ArrayExObjectnotifyAllIllegalMonitorStateException.res = ArrayExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new ArrayExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && ArrayExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int arrayExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + ary1.notifyAll(); + ArrayExObjectnotifyAllIllegalMonitorStateException.res = ArrayExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectnotifyAllIllegalMonitorStateException.res = ArrayExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ArrayExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ArrayExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (ary1) { + try { + ary1.notifyAll(); + ArrayExObjectnotifyAllIllegalMonitorStateException.res = ArrayExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectnotifyAllIllegalMonitorStateException.res = ArrayExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0009-rt-parent-ArrayExObjectnotifyIllegalMonitorStateException/ArrayExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0009-rt-parent-ArrayExObjectnotifyIllegalMonitorStateException/ArrayExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..8a7abdbd7b8f0e01b51b93378731972ad3898541 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0009-rt-parent-ArrayExObjectnotifyIllegalMonitorStateException/ArrayExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ArrayExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect/Array: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ArrayExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ArrayExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Array; + +public class ArrayExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private static Object ary1 = Array.newInstance(int.class, 10); + + public static void main(String argv[]) { + System.out.println(new ArrayExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = arrayExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ArrayExObjectnotifyIllegalMonitorStateException.res = ArrayExObjectnotifyIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new ArrayExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && ArrayExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int arrayExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + ary1.notify(); + ArrayExObjectnotifyIllegalMonitorStateException.res = ArrayExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectnotifyIllegalMonitorStateException.res = ArrayExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ArrayExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ArrayExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (ary1) { + try { + ary1.notify(); + ArrayExObjectnotifyIllegalMonitorStateException.res = ArrayExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectnotifyIllegalMonitorStateException.res = ArrayExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0010-rt-parent-ArrayExObjectwaitIllegalMonitorStateException/ArrayExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0010-rt-parent-ArrayExObjectwaitIllegalMonitorStateException/ArrayExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..a304fb6358ff1453d86550a5687aadbe424343a6 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0010-rt-parent-ArrayExObjectwaitIllegalMonitorStateException/ArrayExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ArrayExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect/Array: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ArrayExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ArrayExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Array; + +public class ArrayExObjectwaitIllegalMonitorStateException { + static int res = 99; + static Object ary1 = Array.newInstance(int.class, 10); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = arrayExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = arrayExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = arrayExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 20; + } + if (result == 4 && ArrayExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + return result; + } + + private static int arrayExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + ary1.wait(); + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int arrayExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + ary1.wait(millis); + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int arrayExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + ary1.wait(millis, nanos); + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectwaitIllegalMonitorStateException.res = ArrayExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0011-rt-parent-ArrayExObjectwaitInterruptedException/ArrayExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0011-rt-parent-ArrayExObjectwaitInterruptedException/ArrayExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..8337d0d965a303efdc4ec5eb8e8730dc2024c235 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0011-rt-parent-ArrayExObjectwaitInterruptedException/ArrayExObjectwaitInterruptedException.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ArrayExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in reflect/Array: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: ArrayExObjectwaitInterruptedException.java + * -@ExecuteClass: ArrayExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Array; + +public class ArrayExObjectwaitInterruptedException { + static int res = 99; + private static Object ary1 = Array.newInstance(int.class, 10); + + public static void main(String argv[]) { + System.out.println(new ArrayExObjectwaitInterruptedException().run()); + } + + private class ArrayExObjectwaitInterruptedException11 implements Runnable { + /** + * Thread run fun + */ + public void run() { + synchronized (ary1) { + ary1.notifyAll(); + try { + ary1.wait(); + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class ArrayExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + long millis = 10000; + + /** + * Thread run fun + */ + public void run() { + synchronized (ary1) { + ary1.notifyAll(); + try { + ary1.wait(millis); + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class ArrayExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10000; + int nanos = 100; + + /** + * Thread run fun + */ + public void run() { + synchronized (ary1) { + ary1.notifyAll(); + try { + ary1.wait(millis, nanos); + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ArrayExObjectwaitInterruptedException.res = ArrayExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * @param slpNum wait time + */ + public void sleep(int slpNum) { + try { + Thread.sleep(slpNum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ArrayExObjectwaitInterruptedException11()); + // final void wait(long millis) + Thread t3 = new Thread(new ArrayExObjectwaitInterruptedException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ArrayExObjectwaitInterruptedException31()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t1.interrupt(); + sleep(100); + t3.start(); + sleep(100); + t3.interrupt(); + sleep(100); + t5.start(); + sleep(100); + t5.interrupt(); + sleep(100); + if (result == 2 && ArrayExObjectwaitInterruptedException.res == 96) { + result = 0; + } + + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0012-rt-parent-ArrayExObjectwait/ArrayExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0012-rt-parent-ArrayExObjectwait/ArrayExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..37f67d0bc66279de548aed250bc939435e3175f3 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0012-rt-parent-ArrayExObjectwait/ArrayExObjectwait.java @@ -0,0 +1,187 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ArrayExObjectwait.java + * -@TestCaseName: Exception in reflect/Array: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: ArrayExObjectwait.java + * -@ExecuteClass: ArrayExObjectwait + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Array; + +public class ArrayExObjectwait { + static int res = 99; + private static Object ary1 = Array.newInstance(int.class, 10); + + public static void main(String argv[]) { + System.out.println(new ArrayExObjectwait().run()); + } + + private class ArrayExObjectwait11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (ary1) { + ary1.notifyAll(); + try { + ary1.wait(); + ArrayExObjectwait.res = ArrayExObjectwait.res - 10; + } catch (InterruptedException e1) { + ArrayExObjectwait.res = ArrayExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectwait.res = ArrayExObjectwait.res - 30; + } + } + } + } + + private class ArrayExObjectwait12 implements Runnable { + // final void wait(long millis) + + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (ary1) { + ary1.notifyAll(); + try { + ary1.wait(millis); + ArrayExObjectwait.res = ArrayExObjectwait.res - 10; + } catch (InterruptedException e1) { + ArrayExObjectwait.res = ArrayExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectwait.res = ArrayExObjectwait.res - 30; + } + } + } + } + + private class ArrayExObjectwait13 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (ary1) { + ary1.notifyAll(); + try { + ary1.wait(millis, nanos); + ArrayExObjectwait.res = ArrayExObjectwait.res - 10; + } catch (InterruptedException e1) { + ArrayExObjectwait.res = ArrayExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ArrayExObjectwait.res = ArrayExObjectwait.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new ArrayExObjectwait11()); + Thread t2 = new Thread(new ArrayExObjectwait11()); + // final void wait(long millis) + Thread t3 = new Thread(new ArrayExObjectwait12()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ArrayExObjectwait13()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + sleep(1000); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.start(); + sleep(1000); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && ArrayExObjectwait.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0013-rt-parent-CharacterExObjectgetClass/CharacterExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0013-rt-parent-CharacterExObjectgetClass/CharacterExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..151020cd0fcb331c09771991dbe31a8f68942b5d --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0013-rt-parent-CharacterExObjectgetClass/CharacterExObjectgetClass.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterExObjectgetClass.java + * -@TestCaseName: Exception in Character: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Construct object char1 by new Character (char name) + * -#step2: Call getClass () on char1 + * -#step3: Confirm that the returned object is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterExObjectgetClass.java + * -@ExecuteClass: CharacterExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterExObjectgetClass { + static int res = 99; + + + public static void main(String argv[]) { + System.out.println(new CharacterExObjectgetClass().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = characterExObjectgetClass1(); + } catch (Exception e) { + CharacterExObjectgetClass.res = CharacterExObjectgetClass.res - 20; + } + if (result == 4 && CharacterExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + + private int characterExObjectgetClass1() { + // final Class getClass() + int result1 = 4; /*STATUS_FAILED*/ + char name = 'A'; + Character char1 = new Character(name); + + Class px1 = char1.getClass(); + + if (px1.toString().equals("class java.lang.Character")) { + CharacterExObjectgetClass.res = CharacterExObjectgetClass.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0014-rt-parent-CharacterExObjectnotifyIllegalMonitorStateException/CharacterExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0014-rt-parent-CharacterExObjectnotifyIllegalMonitorStateException/CharacterExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..c53a38e493b3f2b592665962895f9f573bcff954 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0014-rt-parent-CharacterExObjectnotifyIllegalMonitorStateException/CharacterExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in Character: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: CharacterExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.Character; + +public class CharacterExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private char name = 'A'; + private Character rp = name; + + public static void main(String argv[]) { + System.out.println(new CharacterExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = characterExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + CharacterExObjectnotifyIllegalMonitorStateException.res = CharacterExObjectnotifyIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new CharacterExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && CharacterExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int characterExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + rp.notify(); + CharacterExObjectnotifyIllegalMonitorStateException.res = CharacterExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectnotifyIllegalMonitorStateException.res = CharacterExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class CharacterExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notify(); + CharacterExObjectnotifyIllegalMonitorStateException.res = CharacterExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectnotifyIllegalMonitorStateException.res = CharacterExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0015-rt-parent-CharacterExObjectwaitIllegalMonitorStateException/CharacterExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0015-rt-parent-CharacterExObjectwaitIllegalMonitorStateException/CharacterExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..434b54519fe34b3fe9473d36eeca51f5faf62eba --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0015-rt-parent-CharacterExObjectwaitIllegalMonitorStateException/CharacterExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in Character: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: CharacterExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterExObjectwaitIllegalMonitorStateException { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = characterExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = characterExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = characterExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 20; + } + if (result == 4 && CharacterExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + return result; + } + + private static int characterExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + char name = 'A'; + Character rp = new Character(name); + try { + rp.wait(); + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int characterExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + char name = 'A'; + long millis = 123; + Character rp = new Character(name); + try { + rp.wait(millis); + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } + + private static int characterExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + char name = 'A'; + long millis = 123; + int nanos = 10; + Character rp = new Character(name); + try { + rp.wait(millis, nanos); + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectwaitIllegalMonitorStateException.res = CharacterExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0016-rt-parent-CharacterExObjectwaitInterruptedException/CharacterExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0016-rt-parent-CharacterExObjectwaitInterruptedException/CharacterExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..4461fb7dcb7c253444f9507a69f4d7a980198ab1 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0016-rt-parent-CharacterExObjectwaitInterruptedException/CharacterExObjectwaitInterruptedException.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in Character: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterExObjectwaitInterruptedException.java + * -@ExecuteClass: CharacterExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterExObjectwaitInterruptedException { + static int res = 99; + static char name = 'A'; + static Character sampleField1 = new Character(name); + + public static void main(String argv[]) throws NoSuchFieldException, SecurityException { + System.out.println(new CharacterExObjectwaitInterruptedException().run()); + } + + private class CharacterExObjectwaitInterruptedException11 implements Runnable { + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(); + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class CharacterExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + long millis = 10000; + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(millis); + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class CharacterExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10000; + int nanos = 100; + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(millis, nanos); + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + CharacterExObjectwaitInterruptedException.res = CharacterExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * @param slpNum wait time + */ + public void sleep(int slpNum) { + try { + Thread.sleep(slpNum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new CharacterExObjectwaitInterruptedException11()); + // final void wait(long millis) + Thread t3 = new Thread(new CharacterExObjectwaitInterruptedException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new CharacterExObjectwaitInterruptedException31()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t1.interrupt(); + sleep(100); + t3.start(); + sleep(100); + t3.interrupt(); + sleep(100); + t5.start(); + sleep(100); + t5.interrupt(); + sleep(100); + if (result == 2 && CharacterExObjectwaitInterruptedException.res == 96) { + result = 0; + } + + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0017-rt-parent-CharacterExObjectwait/CharacterExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0017-rt-parent-CharacterExObjectwait/CharacterExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..fc13624890d05e8ca5ea0c49331d14c9881bc814 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0017-rt-parent-CharacterExObjectwait/CharacterExObjectwait.java @@ -0,0 +1,207 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterExObjectwait.java + * -@TestCaseName: Exception in Charactor: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterExObjectwait.java + * -@ExecuteClass: CharacterExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterExObjectwait { + static int res = 99; + private char name = 'A'; + private String actions = null; + private Character rp = new Character(name); + private Character rp2 = new Character(name); + private Character rp3 = new Character(name); + + public static void main(String argv[]) { + System.out.println(new CharacterExObjectwait().run()); + } + + private class CharacterExObjectwait11 implements Runnable { + // final void wait() + + private int remainder; + + private CharacterExObjectwait11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + rp.notifyAll(); + try { + rp.wait(); + CharacterExObjectwait.res = CharacterExObjectwait.res - 10; + } catch (InterruptedException e1) { + CharacterExObjectwait.res = CharacterExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectwait.res = CharacterExObjectwait.res - 30; + } + } + } + } + + private class CharacterExObjectwait12 implements Runnable { + // final void wait(long millis) + + private int remainder; + long millis = 10; + + private CharacterExObjectwait12(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (rp2) { + rp2.notifyAll(); + try { + rp2.wait(millis); + CharacterExObjectwait.res = CharacterExObjectwait.res - 10; + } catch (InterruptedException e1) { + CharacterExObjectwait.res = CharacterExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectwait.res = CharacterExObjectwait.res - 30; + } + } + } + } + + private class CharacterExObjectwait13 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10; + int nanos = 10; + + private CharacterExObjectwait13(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (rp3) { + rp3.notifyAll(); + try { + rp3.wait(millis, nanos); + CharacterExObjectwait.res = CharacterExObjectwait.res - 10; + } catch (InterruptedException e1) { + CharacterExObjectwait.res = CharacterExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectwait.res = CharacterExObjectwait.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new CharacterExObjectwait11(1)); + Thread t2 = new Thread(new CharacterExObjectwait11(2)); + // final void wait(long millis) + Thread t3 = new Thread(new CharacterExObjectwait12(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new CharacterExObjectwait13(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t3.start(); + sleep(100); + t5.start(); + sleep(100); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && CharacterExObjectwait.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0018-rt-parent-CharacterSubsetExObjectgetClass/CharacterSubsetExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0018-rt-parent-CharacterSubsetExObjectgetClass/CharacterSubsetExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..a39b49355d349bd333db15245b7773057a512bb8 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0018-rt-parent-CharacterSubsetExObjectgetClass/CharacterSubsetExObjectgetClass.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterSubsetExObjectgetClass.java + * -@TestCaseName: Exception in Character/Subset: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Construct MySubset s by new MySubset (char name) + * -#step2: Call getClass() on s + * -#step3: Confirm that the returned object is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterSubsetExObjectgetClass.java + * -@ExecuteClass: CharacterSubsetExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterSubsetExObjectgetClass { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new CharacterSubsetExObjectgetClass().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = characterSubsetExObjectgetClass1(); + } catch (Exception e) { + CharacterSubsetExObjectgetClass.res = CharacterSubsetExObjectgetClass.res - 20; + } + if (result == 4 && CharacterSubsetExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + + private int characterSubsetExObjectgetClass1() { +// final Class getClass() + int result1 = 4; /*STATUS_FAILED*/ + MySubset subset = new MySubset("some subset"); + Class px1 = subset.getClass(); + if (px1.toString().equals("class MySubset")) { + CharacterSubsetExObjectgetClass.res = CharacterSubsetExObjectgetClass.res - 10; + } + return result1; + } +} + +class MySubset extends Character.Subset { + MySubset(String name) { + super(name); + } +} + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0019-rt-parent-CharacterSubsetExObjectnotifyAllIllegalMonitorStateException/CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0019-rt-parent-CharacterSubsetExObjectnotifyAllIllegalMonitorStateException/CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..150a3c502d008552ab0beb8cd134fb5db4d480b3 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0019-rt-parent-CharacterSubsetExObjectnotifyAllIllegalMonitorStateException/CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in Character/Subset: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: CharacterSubsetExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterSubsetExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + MySubset1 mf2 = new MySubset1("some subset"); + + public static void main(String argv[]) { + System.out.println(new CharacterSubsetExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = characterSubsetExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new CharacterSubsetExObjectnotifyAllIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int characterSubsetExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + mf2.notifyAll(); + CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class CharacterSubsetExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + try { + mf2.notifyAll(); + CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} + +class MySubset1 extends Character.Subset { + MySubset1(String name) { + super(name); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0020-rt-parent-CharacterSubsetExObjectnotifyIllegalMonitorStateException/CharacterSubsetExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0020-rt-parent-CharacterSubsetExObjectnotifyIllegalMonitorStateException/CharacterSubsetExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..fe8d1228856539b0df39e9475ac98f0d0b0feb97 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0020-rt-parent-CharacterSubsetExObjectnotifyIllegalMonitorStateException/CharacterSubsetExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterSubsetExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in Character/Subset: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterSubsetExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: CharacterSubsetExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterSubsetExObjectnotifyIllegalMonitorStateException { + static int res = 99; + MySubset2 mf2 = new MySubset2("some subset"); + + public static void main(String argv[]) { + System.out.println(new CharacterSubsetExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = characterSubsetExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + CharacterSubsetExObjectnotifyIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new CharacterSubsetExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && CharacterSubsetExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int characterSubsetExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // + // final void notify() + try { + mf2.notify(); + CharacterSubsetExObjectnotifyIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectnotifyIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class CharacterSubsetExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + try { + mf2.notify(); + CharacterSubsetExObjectnotifyIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectnotifyIllegalMonitorStateException.res = CharacterSubsetExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} + +class MySubset2 extends Character.Subset { + MySubset2(String name) { + super(name); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0021-rt-parent-CharacterSubsetExObjectwaitIllegalArgumentException/CharacterSubsetExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0021-rt-parent-CharacterSubsetExObjectwaitIllegalArgumentException/CharacterSubsetExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..cf40aca5fe6d7c7b10c07d133d98adfe42fb0463 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0021-rt-parent-CharacterSubsetExObjectwaitIllegalArgumentException/CharacterSubsetExObjectwaitIllegalArgumentException.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterSubsetExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in Character/Subset: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterSubsetExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: CharacterSubsetExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterSubsetExObjectwaitIllegalArgumentException { + static int res = 99; + MySubset4 csb1 = new MySubset4("some subset"); + + public static void main(String argv[]) { + System.out.println(new CharacterSubsetExObjectwaitIllegalArgumentException().run()); + } + + private class CharacterSubsetExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + long millis = -1; + + /** + * Thread run fun + */ + public void run() { + synchronized (csb1) { + csb1.notifyAll(); + try { + csb1.wait(millis); + CharacterSubsetExObjectwaitIllegalArgumentException.res = CharacterSubsetExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + CharacterSubsetExObjectwaitIllegalArgumentException.res = CharacterSubsetExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectwaitIllegalArgumentException.res = CharacterSubsetExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + CharacterSubsetExObjectwaitIllegalArgumentException.res = CharacterSubsetExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class CharacterSubsetExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // final void wait(long millis, int nanos) + long millis = -2; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (csb1) { + csb1.notifyAll(); + try { + csb1.wait(millis, nanos); + CharacterSubsetExObjectwaitIllegalArgumentException.res = CharacterSubsetExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + CharacterSubsetExObjectwaitIllegalArgumentException.res = CharacterSubsetExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectwaitIllegalArgumentException.res = CharacterSubsetExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + CharacterSubsetExObjectwaitIllegalArgumentException.res = CharacterSubsetExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * @param sleepNum wait time + */ + public void sleep(int sleepNum) { + try { + Thread.sleep(sleepNum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new CharacterSubsetExObjectwaitIllegalArgumentException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new CharacterSubsetExObjectwaitIllegalArgumentException31()); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && CharacterSubsetExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + return result; + } +} + +class MySubset4 extends Character.Subset { + MySubset4(String name) { + super(name); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0022-rt-parent-CharacterSubsetExObjectwaitIllegalMonitorStateException/CharacterSubsetExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0022-rt-parent-CharacterSubsetExObjectwaitIllegalMonitorStateException/CharacterSubsetExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..2a5ec48604f63a91505c725744d4ebc84fe36a74 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0022-rt-parent-CharacterSubsetExObjectwaitIllegalMonitorStateException/CharacterSubsetExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterSubsetExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in Character/Subset: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterSubsetExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: CharacterSubsetExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterSubsetExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static MySubset5 csb1 = new MySubset5("some subset"); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = characterSubsetExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = characterSubsetExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = characterSubsetExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 20; + } + if (result == 4 && CharacterSubsetExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } +// System.out.println("result: " + result); +// System.out.println("CharacterSubsetExObjectwaitIllegalMonitorStateException.res: " + CharacterSubsetExObjectwaitIllegalMonitorStateException.res); + return result; + } + + private static int characterSubsetExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor + // final void wait() + try { + csb1.wait(); + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } + + private static int characterSubsetExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + csb1.wait(millis); + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int characterSubsetExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + csb1.wait(millis, nanos); + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectwaitIllegalMonitorStateException.res = CharacterSubsetExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} + +class MySubset5 extends Character.Subset { + MySubset5(String name) { + super(name); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0023-rt-parent-CharacterSubsetExObjectwaitInterruptedException/CharacterSubsetExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0023-rt-parent-CharacterSubsetExObjectwaitInterruptedException/CharacterSubsetExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..ee0312d4000a56fb08db2b207ed815b01462fa7c --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0023-rt-parent-CharacterSubsetExObjectwaitInterruptedException/CharacterSubsetExObjectwaitInterruptedException.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterSubsetExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in Character/Subset: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterSubsetExObjectwaitInterruptedException.java + * -@ExecuteClass: CharacterSubsetExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterSubsetExObjectwaitInterruptedException { + static int res = 99; + private static MySubset6 csb1 = new MySubset6("some subset"); + + public static void main(String argv[]) { + System.out.println(new CharacterSubsetExObjectwaitInterruptedException().run()); + } + + private class CharacterSubsetExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (csb1) { + csb1.notifyAll(); + try { + csb1.wait(); + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class CharacterSubsetExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + long millis = 10000; + + /** + * Thread run fun + */ + public void run() { + synchronized (csb1) { + csb1.notifyAll(); + try { + csb1.wait(millis); + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class CharacterSubsetExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10000; + int nanos = 100; + + /** + * Thread run fun + */ + public void run() { + synchronized (csb1) { + csb1.notifyAll(); + try { + csb1.wait(millis, nanos); + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + CharacterSubsetExObjectwaitInterruptedException.res = CharacterSubsetExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * @param sleepNum wait time + */ + public void sleep(int sleepNum) { + try { + Thread.sleep(sleepNum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new CharacterSubsetExObjectwaitInterruptedException11()); + // final void wait(long millis) + Thread t3 = new Thread(new CharacterSubsetExObjectwaitInterruptedException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new CharacterSubsetExObjectwaitInterruptedException31()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t1.interrupt(); + sleep(100); + t3.start(); + sleep(100); + t3.interrupt(); + sleep(100); + t5.start(); + sleep(100); + t5.interrupt(); + sleep(100); + if (result == 2 && CharacterSubsetExObjectwaitInterruptedException.res == 96) { + result = 0; + } + return result; + } +} + +class MySubset6 extends Character.Subset { + MySubset6(String name) { + super(name); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0024-rt-parent-ClassExObjectHashcode/ClassExObjectHashcode.java b/test/testsuite/ouroboros/parent_test/RT0024-rt-parent-ClassExObjectHashcode/ClassExObjectHashcode.java new file mode 100755 index 0000000000000000000000000000000000000000..df6745bb4006fa1effd858de5c4694a364bc5f9b --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0024-rt-parent-ClassExObjectHashcode/ClassExObjectHashcode.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassExObjectHashcode.java + * -@TestCaseName: Exception in Class: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create Class ClassExObjectHashcode + * -#step2: Create Object1 from ClassExObjectHashcode.class.getClass(). + * -#step3: Call hashCode of Object1, check no exception is thrown. + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassExObjectHashcode.java + * -@ExecuteClass: ClassExObjectHashcode + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ClassExObjectHashcode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = classExObjectHashcode(); + } catch (Exception e) { + ClassExObjectHashcode.res = ClassExObjectHashcode.res - 10; + } + if (result == 4 && ClassExObjectHashcode.res == 89) { + result = 0; + } + + return result; + } + + private static int classExObjectHashcode() { + // int hashCode() + int result1 = 4; /*STATUS_FAILED*/ + Class cal = ClassExObjectHashcode.class.getClass(); + try { + int hashcode = cal.hashCode(); + ClassExObjectHashcode.res = ClassExObjectHashcode.res - 10; + } catch (IllegalArgumentException e1) { + ClassExObjectHashcode.res = ClassExObjectHashcode.res - 1; + } + return result1; + } +} + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0025-rt-parent-ClassExObjectnotifyAllIllegalMonitorStateException/ClassExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0025-rt-parent-ClassExObjectnotifyAllIllegalMonitorStateException/ClassExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..53162af8f5ed5b96bdf4786ca059996d4f5eca42 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0025-rt-parent-ClassExObjectnotifyAllIllegalMonitorStateException/ClassExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in Class: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ClassExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private Class[] rp = ClassExObjectnotifyAllIllegalMonitorStateException.class.getClasses(); + + public static void main(String argv[]) { + System.out.println(new ClassExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = classExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ClassExObjectnotifyAllIllegalMonitorStateException.res = ClassExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new ClassExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && ClassExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int classExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + rp.notifyAll(); + ClassExObjectnotifyAllIllegalMonitorStateException.res = ClassExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ClassExObjectnotifyAllIllegalMonitorStateException.res = ClassExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ClassExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ClassExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notifyAll(); + ClassExObjectnotifyAllIllegalMonitorStateException.res = ClassExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ClassExObjectnotifyAllIllegalMonitorStateException.res = ClassExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0026-rt-parent-ClassExObjectnotifyIllegalMonitorStateException/ClassExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0026-rt-parent-ClassExObjectnotifyIllegalMonitorStateException/ClassExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..46c58cb87f72937b150fa75c862c980289d29cde --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0026-rt-parent-ClassExObjectnotifyIllegalMonitorStateException/ClassExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Class: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ClassExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private Class[] rp = ClassExObjectnotifyIllegalMonitorStateException.class.getClasses(); + + public static void main(String argv[]) { + System.out.println(new ClassExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = classExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ClassExObjectnotifyIllegalMonitorStateException.res = ClassExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ClassExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ClassExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int classExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + rp.notifyAll(); + ClassExObjectnotifyIllegalMonitorStateException.res = ClassExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ClassExObjectnotifyIllegalMonitorStateException.res = ClassExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ClassExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ClassExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notify(); + ClassExObjectnotifyIllegalMonitorStateException.res = ClassExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ClassExObjectnotifyIllegalMonitorStateException.res = ClassExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} + + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0027-rt-parent-ClassExObjectwaitIllegalArgumentException/ClassExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0027-rt-parent-ClassExObjectwaitIllegalArgumentException/ClassExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..42684d0b24f03847b8a3269337df532eb821dcd7 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0027-rt-parent-ClassExObjectwaitIllegalArgumentException/ClassExObjectwaitIllegalArgumentException.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in Class: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: ClassExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassExObjectwaitIllegalArgumentException { + static int res = 99; + private Class[] clazz = ClassExObjectwaitIllegalArgumentException.class.getClasses(); + + public static void main(String argv[]) { + System.out.println(new ClassExObjectwaitIllegalArgumentException().run()); + } + + private class ClassExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + long millis = -1; + + /** + * Thread run fun + */ + public void run() { + synchronized (clazz) { + clazz.notifyAll(); + try { + clazz.wait(millis); + ClassExObjectwaitIllegalArgumentException.res = ClassExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ClassExObjectwaitIllegalArgumentException.res = ClassExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ClassExObjectwaitIllegalArgumentException.res = ClassExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ClassExObjectwaitIllegalArgumentException.res = ClassExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class ClassExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // final void wait(long millis, int nanos) + long millis = -2; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (clazz) { + clazz.notifyAll(); + try { + clazz.wait(millis, nanos); + ClassExObjectwaitIllegalArgumentException.res = ClassExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ClassExObjectwaitIllegalArgumentException.res = ClassExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ClassExObjectwaitIllegalArgumentException.res = ClassExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ClassExObjectwaitIllegalArgumentException.res = ClassExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new ClassExObjectwaitIllegalArgumentException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ClassExObjectwaitIllegalArgumentException31()); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && ClassExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0028-rt-parent-ClassExObjectwaitInterruptedException/ClassExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0028-rt-parent-ClassExObjectwaitInterruptedException/ClassExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..6ed02b1723ecaa44951aa67f71194e7bca8c9ddf --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0028-rt-parent-ClassExObjectwaitInterruptedException/ClassExObjectwaitInterruptedException.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: runtime/Class/ClassExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in Class: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassExObjectwaitInterruptedException.java + * -@ExecuteClass: ClassExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassExObjectwaitInterruptedException { + static int res = 99; + private static Class[] sampleField1 = null; + + public static void main(String argv[]) throws NoSuchFieldException, SecurityException { + sampleField1 = ClassExObjectwaitInterruptedException.class.getClasses(); + System.out.println(new ClassExObjectwaitInterruptedException().run()); + } + + private class ClassExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(); + ClassExObjectwaitInterruptedException.res = ClassExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + ClassExObjectwaitInterruptedException.res = ClassExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassExObjectwaitInterruptedException.res = ClassExObjectwaitInterruptedException.res - 30; + } + } + } + } + + private class ClassExObjectwaitInterruptedException12 implements Runnable { + // final void wait(long millis) + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(millis); + ClassExObjectwaitInterruptedException.res = ClassExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + ClassExObjectwaitInterruptedException.res = ClassExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassExObjectwaitInterruptedException.res = ClassExObjectwaitInterruptedException.res - 30; + } + } + } + } + + private class ClassExObjectwaitInterruptedException13 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(millis, nanos); + ClassExObjectwaitInterruptedException.res = ClassExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + ClassExObjectwaitInterruptedException.res = ClassExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassExObjectwaitInterruptedException.res = ClassExObjectwaitInterruptedException.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new ClassExObjectwaitInterruptedException11()); + Thread t2 = new Thread(new ClassExObjectwaitInterruptedException11()); + // final void wait(long millis) + Thread t3 = new Thread(new ClassExObjectwaitInterruptedException12()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ClassExObjectwaitInterruptedException13()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t3.start(); + sleep(100); + t5.start(); + sleep(100); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && ClassExObjectwaitInterruptedException.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0029-rt-parent-ClassExObjectwait/ClassExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0029-rt-parent-ClassExObjectwait/ClassExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..9e7329e78e0af7ef281fb7d56dc2ee478646ba2a --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0029-rt-parent-ClassExObjectwait/ClassExObjectwait.java @@ -0,0 +1,204 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: runtime/Class/ClassExObjectwait.java + * -@TestCaseName: Exception in Class: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassExObjectwait.java + * -@ExecuteClass: ClassExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassExObjectwait { + static int res = 99; + private Class[] cal = ClassExObjectwait.class.getClasses(); + private Class[] cal2 = ClassExObjectwait.class.getClasses(); + private Class[] cal3 = ClassExObjectwait.class.getClasses(); + + public static void main(String argv[]) { + System.out.println(new ClassExObjectwait().run()); + } + + private class ClassExObjectwait11 implements Runnable { + // final void wait() + private int remainder; + + private ClassExObjectwait11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cal) { + cal.notifyAll(); + try { + cal.wait(); + ClassExObjectwait.res = ClassExObjectwait.res - 10; + } catch (InterruptedException e1) { + ClassExObjectwait.res = ClassExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassExObjectwait.res = ClassExObjectwait.res - 30; + } + } + } + } + + private class ClassExObjectwait12 implements Runnable { + // final void wait(long millis) + + private int remainder; + long millis = 10; + + private ClassExObjectwait12(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cal2) { + cal2.notifyAll(); + try { + cal2.wait(millis); + ClassExObjectwait.res = ClassExObjectwait.res - 10; + } catch (InterruptedException e1) { + ClassExObjectwait.res = ClassExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassExObjectwait.res = ClassExObjectwait.res - 30; + } + } + } + } + + private class ClassExObjectwait13 implements Runnable { + // final void wait(long millis, int nanos) + private int remainder; + long millis = 10; + int nanos = 10; + + private ClassExObjectwait13(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cal3) { + cal3.notifyAll(); + try { + cal3.wait(millis, nanos); + ClassExObjectwait.res = ClassExObjectwait.res - 10; + } catch (InterruptedException e1) { + ClassExObjectwait.res = ClassExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassExObjectwait.res = ClassExObjectwait.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new ClassExObjectwait11(1)); + Thread t2 = new Thread(new ClassExObjectwait11(2)); + // final void wait(long millis) + Thread t3 = new Thread(new ClassExObjectwait12(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ClassExObjectwait13(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t3.start(); + sleep(100); + t5.start(); + sleep(100); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && ClassExObjectwait.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0030-rt-parent-ClassLoaderExObjectnotifyAllIllegalMonitorStateException/ClassLoaderExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0030-rt-parent-ClassLoaderExObjectnotifyAllIllegalMonitorStateException/ClassLoaderExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..4b2dbf18edd95effce98ebd8d64b87a8f5d5fd92 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0030-rt-parent-ClassLoaderExObjectnotifyAllIllegalMonitorStateException/ClassLoaderExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassLoaderExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in ClassLoader: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassLoaderExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ClassLoaderExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassLoaderExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private ClassLoader rp = ClassLoaderExObjectnotifyAllIllegalMonitorStateException.class.getClassLoader(); + + public static void main(String argv[]) { + System.out.println(new ClassLoaderExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = methodExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res = ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new MethodExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int methodExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // + // final void notifyAll() + try { + rp.notifyAll(); + ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res = ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res = ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class MethodExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notifyAll(); + ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res = ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res = ClassLoaderExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} + + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0031-rt-parent-ClassLoaderExObjectnotifyIllegalMonitorStateException/ClassLoaderExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0031-rt-parent-ClassLoaderExObjectnotifyIllegalMonitorStateException/ClassLoaderExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..029cad606019278a9440cb1a8de3701651d888f5 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0031-rt-parent-ClassLoaderExObjectnotifyIllegalMonitorStateException/ClassLoaderExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassLoaderExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in ClassLoader: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassLoaderExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ClassLoaderExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassLoaderExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private ClassLoader rp = ClassLoaderExObjectnotifyIllegalMonitorStateException.class.getClassLoader(); + + public static void main(String argv[]) { + System.out.println(new ClassLoaderExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = classLoaderExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ClassLoaderExObjectnotifyIllegalMonitorStateException.res = ClassLoaderExObjectnotifyIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new ClassLoaderExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && ClassLoaderExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int classLoaderExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + rp.notify(); + ClassLoaderExObjectnotifyIllegalMonitorStateException.res = ClassLoaderExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectnotifyIllegalMonitorStateException.res = ClassLoaderExObjectnotifyIllegalMonitorStateException.res - 1; + } + return result1; + } + + private class ClassLoaderExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notify(); + ClassLoaderExObjectnotifyIllegalMonitorStateException.res = ClassLoaderExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectnotifyIllegalMonitorStateException.res = ClassLoaderExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} + + + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0032-rt-parent-ClassLoaderExObjectwaitIllegalArgumentException/ClassLoaderExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0032-rt-parent-ClassLoaderExObjectwaitIllegalArgumentException/ClassLoaderExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..26cc549076243c573b4ed3530c52aa22eaddcc49 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0032-rt-parent-ClassLoaderExObjectwaitIllegalArgumentException/ClassLoaderExObjectwaitIllegalArgumentException.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassLoaderExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in ClassLoader: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassLoaderExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: ClassLoaderExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassLoaderExObjectwaitIllegalArgumentException { + static int res = 99; + private ClassLoader cl = ClassLoaderExObjectwaitIllegalArgumentException.class.getClassLoader(); + + public static void main(String argv[]) { + System.out.println(new ClassLoaderExObjectwaitIllegalArgumentException().run()); + } + + private class ClassLoaderExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + long millis = -1; + + /** + * Thread run fun + */ + public void run() { + synchronized (cl) { + cl.notifyAll(); + try { + cl.wait(millis); + ClassLoaderExObjectwaitIllegalArgumentException.res = ClassLoaderExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ClassLoaderExObjectwaitIllegalArgumentException.res = ClassLoaderExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwaitIllegalArgumentException.res = ClassLoaderExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ClassLoaderExObjectwaitIllegalArgumentException.res = ClassLoaderExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class ClassLoaderExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // final void wait(long millis, int nanos) + long millis = -2; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (cl) { + cl.notifyAll(); + try { + cl.wait(millis, nanos); + ClassLoaderExObjectwaitIllegalArgumentException.res = ClassLoaderExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ClassLoaderExObjectwaitIllegalArgumentException.res = ClassLoaderExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwaitIllegalArgumentException.res = ClassLoaderExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ClassLoaderExObjectwaitIllegalArgumentException.res = ClassLoaderExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new ClassLoaderExObjectwaitIllegalArgumentException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ClassLoaderExObjectwaitIllegalArgumentException31()); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && ClassLoaderExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0033-rt-parent-ClassLoaderExObjectwaitIllegalMonitorStateException/ClassLoaderExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0033-rt-parent-ClassLoaderExObjectwaitIllegalMonitorStateException/ClassLoaderExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..f440cbebf194233d1692b88557f44bd12eeb0d4d --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0033-rt-parent-ClassLoaderExObjectwaitIllegalMonitorStateException/ClassLoaderExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassLoaderExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in ClassLoader: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassLoaderExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ClassLoaderExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassLoaderExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static ClassLoader cl = ClassLoaderExObjectwaitIllegalMonitorStateException.class.getClassLoader(); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = classLoaderExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = classLoaderExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = classLoaderExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 20; + } + if (result == 4 && ClassLoaderExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + return result; + } + + private static int classLoaderExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + cl.wait(); + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } + + private static int classLoaderExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + cl.wait(millis); + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } + + private static int classLoaderExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + cl.wait(millis, nanos); + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwaitIllegalMonitorStateException.res = ClassLoaderExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } + +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0034-rt-parent-ClassLoaderExObjectwaitInterruptedException/ClassLoaderExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0034-rt-parent-ClassLoaderExObjectwaitInterruptedException/ClassLoaderExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..bdcd10bd4276bb4e70ddcf20de8b462b2c4578b2 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0034-rt-parent-ClassLoaderExObjectwaitInterruptedException/ClassLoaderExObjectwaitInterruptedException.java @@ -0,0 +1,184 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassLoaderExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in ClassLoader: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassLoaderExObjectwaitInterruptedException.java + * -@ExecuteClass: ClassLoaderExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassLoaderExObjectwaitInterruptedException { + static int res = 99; + private static ClassLoader sampleField1 = ClassLoaderExObjectwaitInterruptedException.class.getClassLoader(); + + public static void main(String argv[]) throws NoSuchFieldException, SecurityException { + System.out.println(new ClassLoaderExObjectwaitInterruptedException().run()); + } + + private class ClassLoaderExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(); + ClassLoaderExObjectwaitInterruptedException.res = ClassLoaderExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + ClassLoaderExObjectwaitInterruptedException.res = ClassLoaderExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwaitInterruptedException.res = ClassLoaderExObjectwaitInterruptedException.res - 30; + } + } + } + } + + private class ClassLoaderExObjectwaitInterruptedException12 implements Runnable { + // final void wait(long millis) + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(millis); + ClassLoaderExObjectwaitInterruptedException.res = ClassLoaderExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + ClassLoaderExObjectwaitInterruptedException.res = ClassLoaderExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwaitInterruptedException.res = ClassLoaderExObjectwaitInterruptedException.res - 30; + } + } + } + } + + private class ClassLoaderExObjectwaitInterruptedException13 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(millis, nanos); + ClassLoaderExObjectwaitInterruptedException.res = ClassLoaderExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + ClassLoaderExObjectwaitInterruptedException.res = ClassLoaderExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwaitInterruptedException.res = ClassLoaderExObjectwaitInterruptedException.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new ClassLoaderExObjectwaitInterruptedException11()); + Thread t2 = new Thread(new ClassLoaderExObjectwaitInterruptedException11()); + // final void wait(long millis) + Thread t3 = new Thread(new ClassLoaderExObjectwaitInterruptedException12()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ClassLoaderExObjectwaitInterruptedException13()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 2 && ClassLoaderExObjectwaitInterruptedException.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0035-rt-parent-ClassLoaderExObjectwait/ClassLoaderExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0035-rt-parent-ClassLoaderExObjectwait/ClassLoaderExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..37b15511d6618bde58d354d9ae4a272220b2151c --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0035-rt-parent-ClassLoaderExObjectwait/ClassLoaderExObjectwait.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassLoaderExObjectwait.java + * -@TestCaseName: Exception in ClassLoader: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: ClassLoaderExObjectwait.java + * -@ExecuteClass: ClassLoaderExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ClassLoaderExObjectwait { + static int res = 99; + private ClassLoader cal = ClassLoaderExObjectwait.class.getClassLoader(); + private ClassLoader cal2 = ClassLoaderExObjectwait.class.getClassLoader(); + private ClassLoader cal3 = ClassLoaderExObjectwait.class.getClassLoader(); + + public static void main(String argv[]) { + System.out.println(new ClassLoaderExObjectwait().run()); + } + + private class ClassLoaderExObjectwait11 implements Runnable { + /** + * Thread run fun + */ + public void run() { + synchronized (cal) { + cal.notifyAll(); + try { + cal.wait(); + ClassLoaderExObjectwait.res = ClassLoaderExObjectwait.res - 10; + } catch (InterruptedException e1) { + ClassLoaderExObjectwait.res = ClassLoaderExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwait.res = ClassLoaderExObjectwait.res - 30; + } + } + } + } + + private class ClassLoaderExObjectwait12 implements Runnable { + // final void wait(long millis) + + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (cal2) { + cal2.notifyAll(); + try { + cal2.wait(millis); + ClassLoaderExObjectwait.res = ClassLoaderExObjectwait.res - 10; + } catch (InterruptedException e1) { + ClassLoaderExObjectwait.res = ClassLoaderExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwait.res = ClassLoaderExObjectwait.res - 30; + } + } + } + } + + private class ClassLoaderExObjectwait13 implements Runnable { + // final void wait(long millis, int nanos) + + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (cal3) { + cal3.notifyAll(); + try { + cal3.wait(millis, nanos); + ClassLoaderExObjectwait.res = ClassLoaderExObjectwait.res - 10; + } catch (InterruptedException e1) { + ClassLoaderExObjectwait.res = ClassLoaderExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ClassLoaderExObjectwait.res = ClassLoaderExObjectwait.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new ClassLoaderExObjectwait11()); + Thread t2 = new Thread(new ClassLoaderExObjectwait11()); + // final void wait(long millis) + Thread t3 = new Thread(new ClassLoaderExObjectwait12()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ClassLoaderExObjectwait13()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && ClassLoaderExObjectwait.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0042-rt-parent-ConstructorExAccessibleObjectisAccessible/ConstructorExAccessibleObjectisAccessible.java b/test/testsuite/ouroboros/parent_test/RT0042-rt-parent-ConstructorExAccessibleObjectisAccessible/ConstructorExAccessibleObjectisAccessible.java new file mode 100755 index 0000000000000000000000000000000000000000..f778f2febaa6d892d40a55554272c1b70248eca6 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0042-rt-parent-ConstructorExAccessibleObjectisAccessible/ConstructorExAccessibleObjectisAccessible.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExAccessibleObjectisAccessible.java + * -@TestCaseName: Exception in reflect /Constructor: boolean isAccessible() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class SampleClass6, which has a single String parameter constructor, and annotate the class with + * CustomAnnotations + * -#step2: Call the run of the use case, and execute method1. In the method, get the constructor by calling getConstructor + * -#step3: Call isAccessible() on object 1 to confirm that the returned is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExAccessibleObjectisAccessible.java + * -@ExecuteClass: ConstructorExAccessibleObjectisAccessible + * -@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.AccessibleObject; + +public class ConstructorExAccessibleObjectisAccessible { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + static int run() { + int result = 2; + try { + result = constructorExAccessibleObjectisAccessibleTest(); + } catch (Exception e) { + e.printStackTrace(); + } + if (result == 4 && ConstructorExAccessibleObjectisAccessible.res == 97) { + result = 0; + } + return result; + } + + private static int constructorExAccessibleObjectisAccessibleTest() { + int result = 4; + try { + // boolean isAccessible() + AccessibleObject sampleconstructor = SampleClass6.class.getConstructor(String.class); + boolean value = sampleconstructor.isAccessible(); + // System.out.println(a); + if (!value) { + ConstructorExAccessibleObjectisAccessible.res = ConstructorExAccessibleObjectisAccessible.res - 2; + } + } catch (NoSuchMethodException | SecurityException | NullPointerException e) { + String eMsg = e.toString(); + } + return result; + } +} + +@CustomAnnotations6(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass6 { + private String sampleField; + + @CustomAnnotations6(name = "sampleConstructor", value = "Sample Constructor Annotation") + public SampleClass6(String str) { + this.sampleField = str; + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@interface CustomAnnotations6 { + String name(); + + String value(); +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0044-rt-parent-ConstructorExAccessibleObjectsetAccessibleSecurityException/ConstructorExAccessibleObjectsetAccessibleSecurityException.java b/test/testsuite/ouroboros/parent_test/RT0044-rt-parent-ConstructorExAccessibleObjectsetAccessibleSecurityException/ConstructorExAccessibleObjectsetAccessibleSecurityException.java new file mode 100755 index 0000000000000000000000000000000000000000..c343b2229192bd813a6eb04f9458bd94032401fa --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0044-rt-parent-ConstructorExAccessibleObjectsetAccessibleSecurityException/ConstructorExAccessibleObjectsetAccessibleSecurityException.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExAccessibleObjectsetAccessibleSecurityException.java + * -@TestCaseName: Exception in reflect /Constructor: void setAccessible(boolean flag)/ static void setAccessible(AccessibleObject[] array, boolean flag) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class SampleClass8, which has a single String parameter constructor, and annotate the class + * -#step2: Call the run of the use case, and execute method1. In the method, get the constructor by calling getConstructor + * -#step3: Call setAccessible(boolean flag) on object 1 to confirm isAccessible() that the returned is correct + * -#step4: Call the run of the use case, and execute method2. In the method, get the constructor by calling getConstructors + * -#step5: Call setAccessible(boolean flag) on object2[0], confirm to isAccessible() that the returned is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExAccessibleObjectsetAccessibleSecurityException.java + * -@ExecuteClass: ConstructorExAccessibleObjectsetAccessibleSecurityException + * -@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.AccessibleObject; + +public class ConstructorExAccessibleObjectsetAccessibleSecurityException { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + static int run() { + int result = 2; + result = constructorExAccessibleObjectsetAccessibleSecurityExceptionTest(); + constructorExAccessibleObjectsetAccessibleSecurityExceptionTest2(); + if (result == 4 && ConstructorExAccessibleObjectsetAccessibleSecurityException.res == 95) { + result = 0; + } + return result; + } + + private static int constructorExAccessibleObjectsetAccessibleSecurityExceptionTest() { + int result1 = 4; + + try { + // void setAccessible(boolean flag) + AccessibleObject sampleconstructor = SampleClass8.class.getConstructor(String.class); + sampleconstructor.setAccessible(true); + boolean value = sampleconstructor.isAccessible(); + if (value) { + // System.out.println(b); + ConstructorExAccessibleObjectsetAccessibleSecurityException.res = ConstructorExAccessibleObjectsetAccessibleSecurityException.res - 2; + } + } catch (NoSuchMethodException | SecurityException e) { + String eMsg = e.toString(); + } + return result1; + } + + + private static void constructorExAccessibleObjectsetAccessibleSecurityExceptionTest2() { + try { + // static void setAccessible(AccessibleObject[] array, boolean flag) + AccessibleObject[] sampleconstructorlist = SampleClass8.class.getConstructors(); + AccessibleObject.setAccessible(sampleconstructorlist, true); + boolean value = sampleconstructorlist[0].isAccessible(); + if (value) { + ConstructorExAccessibleObjectsetAccessibleSecurityException.res = ConstructorExAccessibleObjectsetAccessibleSecurityException.res - 2; + } + } catch (SecurityException e) { + String eMsg = e.toString(); + } + } +} + +@CustomAnnotations8(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass8 { + private String sampleField; + + @CustomAnnotations8(name = "sampleConstructor", value = "Sample Constructor Annotation") + public SampleClass8(String str) { + + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@interface CustomAnnotations8 { + String name(); + + String value(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0048-rt-parent-ConstructorExExecutablegetExceptionTypes/ConstructorExExecutablegetExceptionTypes.java b/test/testsuite/ouroboros/parent_test/RT0048-rt-parent-ConstructorExExecutablegetExceptionTypes/ConstructorExExecutablegetExceptionTypes.java new file mode 100755 index 0000000000000000000000000000000000000000..69704d81125c8131eba9c12f0abe004c6e860afb --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0048-rt-parent-ConstructorExExecutablegetExceptionTypes/ConstructorExExecutablegetExceptionTypes.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExExecutablegetExceptionTypes.java + * -@TestCaseName: abstract Class[] getExceptionTypes() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class SampleClass12, which has a single String parameter constructor, and annotate the class with + * CustomAnnotations12 + * -#step2: Call the run of the use case, and execute method 1. In the method, get the constructor by calling + * getConstructor as object1 + * -#step3: Call getExceptionTypes() on object1 to confirm that the returned are correct + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExExecutablegetExceptionTypes.java + * -@ExecuteClass: ConstructorExExecutablegetExceptionTypes + * -@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.Executable; + +public class ConstructorExExecutablegetExceptionTypes { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + static int run() { + int result = 2; + try { + result = constructorExExecutablegetExceptionTypes1(); + } catch (Exception e) { + e.printStackTrace(); + } + if (result == 4 && ConstructorExExecutablegetExceptionTypes.res == 97) { + result = 0; + } + return result; + } + + private static int constructorExExecutablegetExceptionTypes1() { + int result1 = 4; + try { + // abstract Class[] getExceptionTypes() + Executable sampleExecutable = SampleClass12.class.getConstructor(String.class); + Class[] vlClass = sampleExecutable.getExceptionTypes(); + if (vlClass.length == 0 && vlClass.getClass().toString().equals("class [Ljava.lang.Class;")) { + ConstructorExExecutablegetExceptionTypes.res = ConstructorExExecutablegetExceptionTypes.res - 2; + } + } catch (NoSuchMethodException | SecurityException e1) { + String eMsg = e1.toString(); + } + return result1; + } +} + +@CustomAnnotations12(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass12 { + private String sampleField; + + @CustomAnnotations12(name = "sampleConstructor", value = "Sample Constructor Annotation") + public SampleClass12(String str) { + this.sampleField = str; + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@interface CustomAnnotations12 { + String name(); + + String value(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0049-rt-parent-ConstructorExExecutablegetGenericParameterTypes/ConstructorExExecutablegetGenericParameterTypes.java b/test/testsuite/ouroboros/parent_test/RT0049-rt-parent-ConstructorExExecutablegetGenericParameterTypes/ConstructorExExecutablegetGenericParameterTypes.java new file mode 100755 index 0000000000000000000000000000000000000000..21ae3dc6d4c82998384a4497258f47ae1c48786b --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0049-rt-parent-ConstructorExExecutablegetGenericParameterTypes/ConstructorExExecutablegetGenericParameterTypes.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExExecutablegetGenericParameterTypes.java + * -@TestCaseName: Type[] getGenericParameterTypes() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class SampleClass13, which has a single String parameter constructor, and annotate the class with + * CustomAnnotations13 + * -#step2: Call the run of the use case, and execute method 1. In the method, get the constructor by calling + * getConstructor as object1 + * -#step3: Call getParameterTypes() on object1 to confirm that the returned are correct + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExExecutablegetGenericParameterTypes.java + * -@ExecuteClass: ConstructorExExecutablegetGenericParameterTypes + * -@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.Executable; + +public class ConstructorExExecutablegetGenericParameterTypes { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + static int run() { + int result = 2; + try { + result = constructorExExecutablegetGenericParameterTypes1(); + } catch (Exception e) { + e.printStackTrace(); + } + if (result == 4 && ConstructorExExecutablegetGenericParameterTypes.res == 97) { + result = 0; + } + return result; + } + + private static int constructorExExecutablegetGenericParameterTypes1() { + int result1 = 4; + try { + // Type[] getGenericParameterTypes() + Executable sampleExecutable = SampleClass13.class.getConstructor(String.class); + Class[] classes = sampleExecutable.getParameterTypes(); + if (classes.length == 1 && classes.getClass().toString().equals("class [Ljava.lang.Class;")) { + ConstructorExExecutablegetGenericParameterTypes.res = ConstructorExExecutablegetGenericParameterTypes.res - 2; + } + } catch (NoSuchMethodException | SecurityException e1) { + String eMsg = e1.toString(); + } + return result1; + } +} + +@CustomAnnotations13(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass13 { + private String sampleField; + + @CustomAnnotations13(name = "sampleConstructor", value = "Sample Constructor Annotation") + public SampleClass13(String str) { + + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@interface CustomAnnotations13 { + String name(); + + String value(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0050-rt-parent-ConstructorExObjectnotifyAllIllegalMonitorStateException/ConstructorExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0050-rt-parent-ConstructorExObjectnotifyAllIllegalMonitorStateException/ConstructorExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..702e4432f281714e14ef52943a83558e3a8a1abb --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0050-rt-parent-ConstructorExObjectnotifyAllIllegalMonitorStateException/ConstructorExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect /Constructor: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ConstructorExObjectnotifyAllIllegalMonitorStateException + * -@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.Constructor; + + +public class ConstructorExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private static Constructor con = null; + + public static void main(String argv[]) throws NoSuchMethodException, SecurityException { + con = SampleClass14.class.getConstructor(String.class); + System.out.println(new ConstructorExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; + try { + result = constructorExObjectnotifyAllIllegalMonitorStateExceptionTest1(); + } catch (Exception e) { + ConstructorExObjectnotifyAllIllegalMonitorStateException.res = ConstructorExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new ConstructorExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && ConstructorExObjectnotifyAllIllegalMonitorStateException.res == 57) { + result = 0; + } + return result; + } + + private int constructorExObjectnotifyAllIllegalMonitorStateExceptionTest1() { + int result1 = 4; + try { + con.notifyAll(); + ConstructorExObjectnotifyAllIllegalMonitorStateException.res = ConstructorExObjectnotifyAllIllegalMonitorStateException.res - 50; + + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectnotifyAllIllegalMonitorStateException.res = ConstructorExObjectnotifyAllIllegalMonitorStateException.res - 2; + } + return result1; + } + + + private class ConstructorExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + private int remainder; + + // final void notifyAll() + private ConstructorExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (con) { + try { + con.notifyAll(); + ConstructorExObjectnotifyAllIllegalMonitorStateException.res = ConstructorExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectnotifyAllIllegalMonitorStateException.res = ConstructorExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } + +} + +@CustomAnnotations14(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass14 { + private String sampleField; + + @CustomAnnotations14(name = "sampleConstructor", value = "Sample Constructor Annotation") + public SampleClass14(String str) { + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@interface CustomAnnotations14 { + String name(); + + String value(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0051-rt-parent-ConstructorExObjectnotifyIllegalMonitorStateException/ConstructorExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0051-rt-parent-ConstructorExObjectnotifyIllegalMonitorStateException/ConstructorExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..85f1f1ed3bfe223ac2d8b45b56a4e339ddb5b027 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0051-rt-parent-ConstructorExObjectnotifyIllegalMonitorStateException/ConstructorExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect /Constructor: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ConstructorExObjectnotifyIllegalMonitorStateException + * -@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.Constructor; + +public class ConstructorExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private static Constructor con = null; + + public static void main(String argv[]) throws NoSuchMethodException, SecurityException { + con = SampleClass15.class.getConstructor(String.class); + System.out.println(new ConstructorExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; + try { + result = constructorExObjectnotifyIllegalMonitorStateExceptionTest1(); + } catch (Exception e) { + ConstructorExObjectnotifyIllegalMonitorStateException.res = ConstructorExObjectnotifyIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new ConstructorExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && ConstructorExObjectnotifyIllegalMonitorStateException.res == 57) { + result = 0; + } + return result; + } + + private int constructorExObjectnotifyIllegalMonitorStateExceptionTest1() { + int result1 = 4; + try { + con.notify(); + ConstructorExObjectnotifyIllegalMonitorStateException.res = ConstructorExObjectnotifyIllegalMonitorStateException.res - 50; + + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectnotifyIllegalMonitorStateException.res = ConstructorExObjectnotifyIllegalMonitorStateException.res - 2; + } + return result1; + } + + private class ConstructorExObjectnotifyIllegalMonitorStateException11 implements Runnable { + private int remainder; + + // final void notify() + private ConstructorExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (con) { + try { + con.notify(); + ConstructorExObjectnotifyIllegalMonitorStateException.res = ConstructorExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectnotifyIllegalMonitorStateException.res = ConstructorExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } + +} + +@CustomAnnotations15(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass15 { + private String sampleField; + + @CustomAnnotations15(name = "sampleConstructor", value = "Sample Constructor Annotation") + public SampleClass15(String s) { + + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@interface CustomAnnotations15 { + String name(); + + String value(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0052-rt-parent-ConstructorExObjectwaitIllegalArgumentException/ConstructorExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0052-rt-parent-ConstructorExObjectwaitIllegalArgumentException/ConstructorExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..fd4608da5888899d7523d24c1b5076f73f85fdb9 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0052-rt-parent-ConstructorExObjectwaitIllegalArgumentException/ConstructorExObjectwaitIllegalArgumentException.java @@ -0,0 +1,207 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExObjectwaitIllegalArgumentException.java + * -@TestCaseName: final void wait(long millis, int nanos)/ final void wait(long millis)/ final void wait() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: ConstructorExObjectwaitIllegalArgumentException + * -@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.Constructor; + +public class ConstructorExObjectwaitIllegalArgumentException { + static int res = 99; + private static Constructor con = null; + + public static void main(String argv[]) throws SecurityException, NoSuchMethodException { + con = SampleClass16.class.getConstructor(String.class); + System.out.println(new ConstructorExObjectwaitIllegalArgumentException().run()); + } + + private class ConstructorExObjectwaitIllegalArgumentException11 implements Runnable { + /** + * Thread run fun + */ + public void run() { + synchronized (con) { + con.notifyAll(); + try { + con.wait(); + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 1; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 10; + } + } + } + } + + private class ConstructorExObjectwaitIllegalArgumentException21 implements Runnable { + // final void wait(long millis) + long millis = 10000; + + /** + * Thread run fun + */ + public void run() { + synchronized (con) { + con.notifyAll(); + try { + con.wait(millis); + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 1; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class ConstructorExObjectwaitIllegalArgumentException31 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10000; + int nanos = 100; + + /** + * Thread run fun + */ + public void run() { + synchronized (con) { + con.notifyAll(); + try { + con.wait(millis, nanos); + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 1; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ConstructorExObjectwaitIllegalArgumentException.res = ConstructorExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ConstructorExObjectwaitIllegalArgumentException11()); + // final void wait(long millis) + Thread t3 = new Thread(new ConstructorExObjectwaitIllegalArgumentException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ConstructorExObjectwaitIllegalArgumentException31()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t1.interrupt(); + sleep(1000); + t3.start(); + sleep(1000); + t3.interrupt(); + sleep(1000); + t5.start(); + sleep(1000); + t5.interrupt(); + sleep(1000); + + if (result == 2 && ConstructorExObjectwaitIllegalArgumentException.res == 96) { + result = 0; + } + return result; + } +} + +@CustomAnnotations16(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass16 { + private String sampleField; + + @CustomAnnotations16(name = "sampleConstructor", value = "Sample Constructor Annotation") + public SampleClass16(String str) { + + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@interface CustomAnnotations16 { + String name(); + + String value(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0053-rt-parent-ConstructorExObjectwaitIllegalMonitorStateException/ConstructorExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0053-rt-parent-ConstructorExObjectwaitIllegalMonitorStateException/ConstructorExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..9980ea771bb84c863158c55dd5dda682487caf37 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0053-rt-parent-ConstructorExObjectwaitIllegalMonitorStateException/ConstructorExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExObjectwaitIllegalArgumentException.java + * -@TestCaseName: final void wait(long millis, int nanos)/ final void wait(long millis)/ final void wait() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ConstructorExObjectwaitIllegalMonitorStateException + * -@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.Constructor; + +public class ConstructorExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static Constructor con = null; + + public static void main(String argv[]) throws SecurityException, NoSuchMethodException { + con = SampleClass17.class.getConstructor(String.class); + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = constructorExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = constructorExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = constructorExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && ConstructorExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int constructorExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + con.wait(); + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int constructorExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + con.wait(millis); + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int constructorExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + con.wait(millis, nanos); + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwaitIllegalMonitorStateException.res = ConstructorExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } +} + +@CustomAnnotations17(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass17 { + private String sampleField; + + @CustomAnnotations17(name = "sampleConstructor", value = "Sample Constructor Annotation") + public SampleClass17(String str) { + + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@interface CustomAnnotations17 { + String name(); + + String value(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0054-rt-parent-ConstructorExObjectwaitInterruptedException/ConstructorExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0054-rt-parent-ConstructorExObjectwaitInterruptedException/ConstructorExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..b2375d68ce812e55e03f2dff00daf8e137eb77fb --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0054-rt-parent-ConstructorExObjectwaitInterruptedException/ConstructorExObjectwaitInterruptedException.java @@ -0,0 +1,209 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExObjectwaitIllegalArgumentException.java + * -@TestCaseName: final void wait(long millis, int nanos)/ final void wait(long millis)/ final void wait() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExObjectwaitInterruptedException.java + * -@ExecuteClass: ConstructorExObjectwaitInterruptedException + * -@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.Constructor; + +public class ConstructorExObjectwaitInterruptedException { + static int res = 99; + private static Constructor con = null; + + public static void main(String argv[]) throws NoSuchMethodException, SecurityException { + con = SampleClass18.class.getConstructor(String.class); + System.out.println(new ConstructorExObjectwaitInterruptedException().run()); + } + + private class ConstructorExObjectwaitInterruptedException11 implements Runnable { + /** + * Thread run fun + */ + public void run() { + synchronized (con) { + con.notifyAll(); + try { + con.wait(); + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class ConstructorExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + long millis = 10000; + + /** + * Thread run fun + */ + public void run() { + synchronized (con) { + con.notifyAll(); + try { + con.wait(millis); + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class ConstructorExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10000; + int nanos = 100; + + /** + * Thread run fun + */ + public void run() { + synchronized (con) { + con.notifyAll(); + try { + con.wait(millis, nanos); + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ConstructorExObjectwaitInterruptedException.res = ConstructorExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ConstructorExObjectwaitInterruptedException11()); + // final void wait(long millis) + Thread t3 = new Thread(new ConstructorExObjectwaitInterruptedException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ConstructorExObjectwaitInterruptedException31()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t1.interrupt(); + sleep(1000); + t3.start(); + sleep(1000); + t3.interrupt(); + sleep(1000); + t5.start(); + sleep(1000); + t5.interrupt(); + sleep(1000); + + if (result == 2 && ConstructorExObjectwaitInterruptedException.res == 96) { + result = 0; + } + return result; + } +} + +@CustomAnnotations18(name = "SampleClass", value = "Sample Class Annotation") +class SampleClass18 { + private String sampleField; + + @CustomAnnotations18(name = "sampleConstructor", value = "Sample Constructor Annotation") + public SampleClass18(String str) { + + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) +@interface CustomAnnotations18 { + String name(); + + String value(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0055-rt-parent-ConstructorExObjectwait/ConstructorExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0055-rt-parent-ConstructorExObjectwait/ConstructorExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..41d59be4d9643017ad3e503ae21ea35ae1d9f533 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0055-rt-parent-ConstructorExObjectwait/ConstructorExObjectwait.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorExObjectwait.java + * -@TestCaseName: Exception in reflect Method: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: ConstructorExObjectwait.java + * -@ExecuteClass: ConstructorExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.reflect.Constructor; + +public class ConstructorExObjectwait { + static int res = 99; + private Constructor[] con1 = ConstructorExObjectwait.class.getConstructors(); + private Constructor[] con2 = ConstructorExObjectwait.class.getConstructors(); + private Constructor[] con3 = ConstructorExObjectwait.class.getConstructors(); + + public static void main(String argv[]) { + System.out.println(new ConstructorExObjectwait().run()); + } + + private class ConstructorExObjectwait11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (con1) { + con1.notifyAll(); + try { + con1.wait(); + ConstructorExObjectwait.res = ConstructorExObjectwait.res - 10; + } catch (InterruptedException e1) { + ConstructorExObjectwait.res = ConstructorExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwait.res = ConstructorExObjectwait.res - 30; + } + } + } + } + + private class ConstructorExObjectwait12 implements Runnable { + // final void wait(long millis) + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (con2) { + con2.notifyAll(); + try { + con2.wait(millis); + ConstructorExObjectwait.res = ConstructorExObjectwait.res - 10; + } catch (InterruptedException e1) { + ConstructorExObjectwait.res = ConstructorExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwait.res = ConstructorExObjectwait.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private class ConstructorExObjectwait13 implements Runnable { + // final void wait(long millis, int nanos) + + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (con3) { + con3.notifyAll(); + try { + con3.wait(millis, nanos); + ConstructorExObjectwait.res = ConstructorExObjectwait.res - 10; + } catch (InterruptedException e1) { + ConstructorExObjectwait.res = ConstructorExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ConstructorExObjectwait.res = ConstructorExObjectwait.res - 30; + } + } + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new ConstructorExObjectwait11()); + Thread t2 = new Thread(new ConstructorExObjectwait11()); + // final void wait(long millis) + Thread t3 = new Thread(new ConstructorExObjectwait12()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ConstructorExObjectwait13()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + t2.interrupt(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && ConstructorExObjectwait.res == 69) { + result = 0; + } + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0061-rt-parent-FieldExAccessibleObjectisAccessible/FieldExAccessibleObjectisAccessible.java b/test/testsuite/ouroboros/parent_test/RT0061-rt-parent-FieldExAccessibleObjectisAccessible/FieldExAccessibleObjectisAccessible.java new file mode 100755 index 0000000000000000000000000000000000000000..f56c8696699f3d13b94e8b70c4f07fc024deadf8 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0061-rt-parent-FieldExAccessibleObjectisAccessible/FieldExAccessibleObjectisAccessible.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldExAccessibleObjectisAccessible.java + * -@TestCaseName: Exception in reflect/Field: boolean isAccessible() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class SampleClassField_h2, which has a field id, and annotate the class with CustomAnnotations_h2 + * -#step2: Call the run of the use case, and execute method 1. In the method, get the filed "id" by calling + * getDeclaredField as Object1 + * -#step3: Call isAccessible() on object 1 to confirm that the returned are correct + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldExAccessibleObjectisAccessible.java + * -@ExecuteClass: FieldExAccessibleObjectisAccessible + * -@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 FieldExAccessibleObjectisAccessible { + static int res = 99; + + public static void main(String[] argv) { + System.out.println(new FieldExAccessibleObjectisAccessible().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = fieldExAccessibleObjectisAccessible1(); + } catch (Exception e) { + FieldExAccessibleObjectisAccessible.res = FieldExAccessibleObjectisAccessible.res - 20; + } + + if (result == 4 && FieldExAccessibleObjectisAccessible.res == 89) { + result = 0; + } + + return result; + } + + private int fieldExAccessibleObjectisAccessible1() throws NoSuchFieldException { + // boolean isAccessible() + int result1 = 4; + Field f1 = SampleClassFieldH2.class.getDeclaredField("id"); + try { + if (!f1.isAccessible()) { + FieldExAccessibleObjectisAccessible.res = FieldExAccessibleObjectisAccessible.res - 10; + } else { + FieldExAccessibleObjectisAccessible.res = FieldExAccessibleObjectisAccessible.res - 15; + } + } catch (Exception e) { + FieldExAccessibleObjectisAccessible.res = FieldExAccessibleObjectisAccessible.res - 15; + } + + return result1; + } +} + +class SampleClassFieldH2 { + @CustomAnnotationsH2(name = "id") + String id; +} + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@interface CustomAnnotationsH2 { + String name(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0063-rt-parent-FieldExAccessibleObjectsetAccessibleSecurityException/FieldExAccessibleObjectsetAccessibleSecurityException.java b/test/testsuite/ouroboros/parent_test/RT0063-rt-parent-FieldExAccessibleObjectsetAccessibleSecurityException/FieldExAccessibleObjectsetAccessibleSecurityException.java new file mode 100755 index 0000000000000000000000000000000000000000..b34f363f5262204d0653040dcdc0edc2cc1fe84a --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0063-rt-parent-FieldExAccessibleObjectsetAccessibleSecurityException/FieldExAccessibleObjectsetAccessibleSecurityException.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldExAccessibleObjectsetAccessibleSecurityException.java + * -@TestCaseName: Exception in reflect/Field: void setAccessible(boolean flag) \ static void setAccessible(AccessibleObject[] array, boolean flag) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class SampleClassField_h4, which has a field id, and annotate the class with CustomAnnotations_h4 + * -#step2: Call the run of the use case, and execute method 1. In the method, get the filed "id" by calling + * getDeclaredField as Object1 + * -#step3: Call setAccessible(boolean flag) on object 1, flag test true and false, confirm set success + * -#step4: Call the run of the use case, and execute method 1. In the method, get the filed "id" by calling + * getDeclaredField as Object2 + * -#step5: Call setAccessible(AccessibleObject[] array, boolean flag) on object 2, flag test true and false, confirm + * set success + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldExAccessibleObjectsetAccessibleSecurityException.java + * -@ExecuteClass: FieldExAccessibleObjectsetAccessibleSecurityException + * -@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.AccessibleObject; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; + +public class FieldExAccessibleObjectsetAccessibleSecurityException { + static int res = 99; + + public static void main(String[] args) { + System.out.println(new FieldExAccessibleObjectsetAccessibleSecurityException().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = fieldExAccessibleObjectsetAccessibleSecurityException1(); + } catch (Exception e) { + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 20; + } + + try { + result = fieldExAccessibleObjectsetAccessibleSecurityException2(); + } catch (Exception e) { + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 20; + } + + if (result == 4 && FieldExAccessibleObjectsetAccessibleSecurityException.res == 59) { + result = 0; + } + + return result; + } + + private int fieldExAccessibleObjectsetAccessibleSecurityException1() throws NoSuchFieldException { + // void setAccessible(boolean flag) + int result1 = 4; + Field f1 = SampleClassFieldH4.class.getDeclaredField("id"); + try { + f1.setAccessible(false); + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 10; + } catch (SecurityException e) { + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 15; + } + + try { + f1.setAccessible(true); + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 10; + } catch (SecurityException e) { + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 15; + } + + return result1; + } + + private int fieldExAccessibleObjectsetAccessibleSecurityException2() throws NoSuchFieldException { + // static void setAccessible(AccessibleObject[] array, boolean flag) + int result2 = 4; + Constructor[] test = AccessibleObject.class.getDeclaredConstructors(); + try { + AccessibleObject.setAccessible(test, false); + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 10; + } catch (SecurityException e) { + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 15; + } + + try { + AccessibleObject.setAccessible(test, true); + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 10; + } catch (SecurityException e) { + FieldExAccessibleObjectsetAccessibleSecurityException.res = FieldExAccessibleObjectsetAccessibleSecurityException.res - 15; + } + return result2; + } +} + +class SampleClassFieldH4 { + @CustomAnnotationsH4(name = "id") + String id; +} + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@interface CustomAnnotationsH4 { + String name(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0064-rt-parent-FieldExObjectgetClass/FieldExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0064-rt-parent-FieldExObjectgetClass/FieldExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..a3d707e1f1d410b7b66fde0a359161839886eac2 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0064-rt-parent-FieldExObjectgetClass/FieldExObjectgetClass.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID:FieldExObjectgetClass.java + * -@TestCaseName: Exception in reflect/Field: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create class FieldExObjectgetClass, call getDeclaredFields() of class of FieldExObjectgetClass as object1 + * -#step2: Call getClass() on object1[0] + * -#step3: Confirm that the returned Class is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldExObjectgetClass.java + * -@ExecuteClass: FieldExObjectgetClass + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Field; + +public class FieldExObjectgetClass { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new FieldExObjectgetClass().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = fieldExObjectgetClass1(); + } catch (Exception e) { + FieldExObjectgetClass.res = FieldExObjectgetClass.res - 20; + } + + if (result == 4 && FieldExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + + private int fieldExObjectgetClass1() { + // final Class getClass() + int result1 = 4; /*STATUS_FAILED*/ + Field[] f1 = FieldExObjectgetClass.class.getDeclaredFields(); + + Class px1 = f1[0].getClass(); + + if (px1.toString().equals("class java.lang.reflect.Field")) { + FieldExObjectgetClass.res = FieldExObjectgetClass.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0065-rt-parent-FieldExObjectnotifyAllIllegalMonitorStateException/FieldExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0065-rt-parent-FieldExObjectnotifyAllIllegalMonitorStateException/FieldExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..35f533564a18c2c29e88c0ea9d2ca071cd597d1b --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0065-rt-parent-FieldExObjectnotifyAllIllegalMonitorStateException/FieldExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Field: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: FieldExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Field; + +public class FieldExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private Field[] rp = FieldExObjectnotifyAllIllegalMonitorStateException.class.getDeclaredFields(); + + public static void main(String argv[]) { + System.out.println(new FieldExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = methodExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + FieldExObjectnotifyAllIllegalMonitorStateException.res = FieldExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new MethodExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && FieldExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int methodExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + rp.notifyAll(); + FieldExObjectnotifyAllIllegalMonitorStateException.res = FieldExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + FieldExObjectnotifyAllIllegalMonitorStateException.res = FieldExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class MethodExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notifyAll(); + FieldExObjectnotifyAllIllegalMonitorStateException.res = FieldExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + FieldExObjectnotifyAllIllegalMonitorStateException.res = FieldExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0066-rt-parent-FieldExObjectnotifyIllegalMonitorStateException/FieldExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0066-rt-parent-FieldExObjectnotifyIllegalMonitorStateException/FieldExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..5ccda649159b7edb5707f0c9634b3a3d12f9671d --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0066-rt-parent-FieldExObjectnotifyIllegalMonitorStateException/FieldExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Field: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: FieldExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Field; + +public class FieldExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private Field[] rp = FieldExObjectnotifyIllegalMonitorStateException.class.getDeclaredFields(); + + public static void main(String argv[]) { + System.out.println(new FieldExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = methodExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + FieldExObjectnotifyIllegalMonitorStateException.res = FieldExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new MethodExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && FieldExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int methodExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + rp.notify(); + FieldExObjectnotifyIllegalMonitorStateException.res = FieldExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + FieldExObjectnotifyIllegalMonitorStateException.res = FieldExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class MethodExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notify(); + FieldExObjectnotifyIllegalMonitorStateException.res = FieldExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + FieldExObjectnotifyIllegalMonitorStateException.res = FieldExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0067-rt-parent-FieldExObjectwaitIllegalArgumentException/FieldExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0067-rt-parent-FieldExObjectwaitIllegalArgumentException/FieldExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..9bd4478948e5bfe89d9883d94e9914786cb3b867 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0067-rt-parent-FieldExObjectwaitIllegalArgumentException/FieldExObjectwaitIllegalArgumentException.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in reflect/Field: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: FieldExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class FieldExObjectwaitIllegalArgumentException { + static int res = 99; + private Field[] fields = FieldExObjectwaitIllegalArgumentException.class.getDeclaredFields(); + + public static void main(String argv[]) { + System.out.println(new FieldExObjectwaitIllegalArgumentException().run()); + } + + private class FieldExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + long millis = -1; + + /** + * Thread run fun + */ + public void run() { + synchronized (fields[0]) { + fields[0].notifyAll(); + try { + fields[0].wait(millis); + FieldExObjectwaitIllegalArgumentException.res = FieldExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + FieldExObjectwaitIllegalArgumentException.res = FieldExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwaitIllegalArgumentException.res = FieldExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + FieldExObjectwaitIllegalArgumentException.res = FieldExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class FieldExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // final void wait(long millis, int nanos) + + long millis = -2; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (fields[0]) { + fields[0].notifyAll(); + try { + fields[0].wait(millis, nanos); + FieldExObjectwaitIllegalArgumentException.res = FieldExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + FieldExObjectwaitIllegalArgumentException.res = FieldExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwaitIllegalArgumentException.res = FieldExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + FieldExObjectwaitIllegalArgumentException.res = FieldExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new FieldExObjectwaitIllegalArgumentException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new FieldExObjectwaitIllegalArgumentException31()); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && FieldExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0068-rt-parent-FieldExObjectwaitIllegalMonitorStateException/FieldExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0068-rt-parent-FieldExObjectwaitIllegalMonitorStateException/FieldExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..290a3e8664b920108544d4821b89a2cd89712399 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0068-rt-parent-FieldExObjectwaitIllegalMonitorStateException/FieldExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect/Field: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: FieldExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class FieldExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static Field[] fields = FieldExObjectwaitIllegalMonitorStateException.class.getDeclaredFields(); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = fieldExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = fieldExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = fieldExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && FieldExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int fieldExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + fields[0].wait(); + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int fieldExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + fields[0].wait(millis); + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } + + private static int fieldExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + fields[0].wait(millis, nanos); + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwaitIllegalMonitorStateException.res = FieldExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0069-rt-parent-FieldExObjectwaitInterruptedException/FieldExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0069-rt-parent-FieldExObjectwaitInterruptedException/FieldExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..c7dec55776f761d6492092e67abe579f467fc783 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0069-rt-parent-FieldExObjectwaitInterruptedException/FieldExObjectwaitInterruptedException.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in reflect/Field: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldExObjectwaitInterruptedException.java + * -@ExecuteClass: FieldExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Field; + +public class FieldExObjectwaitInterruptedException { + static int res = 99; + private static Field[] fields = FieldExObjectwaitInterruptedException.class.getDeclaredFields(); + + public static void main(String argv[]) throws NoSuchFieldException, SecurityException { + System.out.println(new FieldExObjectwaitInterruptedException().run()); + } + + private class FieldExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (fields[0]) { + fields[0].notifyAll(); + try { + fields[0].wait(); + FieldExObjectwaitInterruptedException.res = FieldExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + FieldExObjectwaitInterruptedException.res = FieldExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwaitInterruptedException.res = FieldExObjectwaitInterruptedException.res - 30; + } + } + } + } + + private class FieldExObjectwaitInterruptedException12 implements Runnable { + // final void wait(long millis) + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (fields[0]) { + fields[0].notifyAll(); + try { + fields[0].wait(millis); + FieldExObjectwaitInterruptedException.res = FieldExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + FieldExObjectwaitInterruptedException.res = FieldExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwaitInterruptedException.res = FieldExObjectwaitInterruptedException.res - 30; + } + } + } + } + + private class FieldExObjectwaitInterruptedException13 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (fields[0]) { + fields[0].notifyAll(); + try { + fields[0].wait(millis, nanos); + FieldExObjectwaitInterruptedException.res = FieldExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + FieldExObjectwaitInterruptedException.res = FieldExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwaitInterruptedException.res = FieldExObjectwaitInterruptedException.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new FieldExObjectwaitInterruptedException11()); + Thread t2 = new Thread(new FieldExObjectwaitInterruptedException11()); + // final void wait(long millis) + Thread t3 = new Thread(new FieldExObjectwaitInterruptedException12()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new FieldExObjectwaitInterruptedException13()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && FieldExObjectwaitInterruptedException.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0070-rt-parent-FieldExObjectwait/FieldExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0070-rt-parent-FieldExObjectwait/FieldExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..8d6b9d4d37595360f209fb8ebeaece4592ff1f28 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0070-rt-parent-FieldExObjectwait/FieldExObjectwait.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Field/FieldExObjectwait.java + * -@TestCaseName: Exception in reflect Field: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: FieldExObjectwait.java + * -@ExecuteClass: FieldExObjectwait + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Field; + +public class FieldExObjectwait { + static int res = 99; + private Field[] cal = FieldExObjectwait.class.getDeclaredFields(); + private Field[] cal2 = FieldExObjectwait.class.getDeclaredFields(); + private Field[] cal3 = FieldExObjectwait.class.getDeclaredFields(); + + public static void main(String argv[]) { + System.out.println(new FieldExObjectwait().run()); + } + + private class FieldExObjectwait11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (cal) { + cal.notifyAll(); + try { + cal.wait(); + FieldExObjectwait.res = FieldExObjectwait.res - 10; + } catch (InterruptedException e1) { + FieldExObjectwait.res = FieldExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwait.res = FieldExObjectwait.res - 30; + } + } + } + } + + private class FieldExObjectwait12 implements Runnable { + // final void wait(long millis) + + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (cal2) { + cal2.notifyAll(); + try { + cal2.wait(millis); + FieldExObjectwait.res = FieldExObjectwait.res - 10; + } catch (InterruptedException e1) { + FieldExObjectwait.res = FieldExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwait.res = FieldExObjectwait.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private class FieldExObjectwait13 implements Runnable { + // final void wait(long millis, int nanos) + + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (cal3) { + cal3.notifyAll(); + try { + cal3.wait(millis, nanos); + FieldExObjectwait.res = FieldExObjectwait.res - 10; + } catch (InterruptedException e1) { + FieldExObjectwait.res = FieldExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + FieldExObjectwait.res = FieldExObjectwait.res - 30; + } + } + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new FieldExObjectwait11()); + Thread t2 = new Thread(new FieldExObjectwait11()); + // final void wait(long millis) + Thread t3 = new Thread(new FieldExObjectwait12()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new FieldExObjectwait13()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && FieldExObjectwait.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0075-rt-parent-MethodExAccessibleObjectisAccessible/MethodExAccessibleObjectisAccessible.java b/test/testsuite/ouroboros/parent_test/RT0075-rt-parent-MethodExAccessibleObjectisAccessible/MethodExAccessibleObjectisAccessible.java new file mode 100755 index 0000000000000000000000000000000000000000..56a263c38526a9f8570b22495ea35fbf660f21cb --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0075-rt-parent-MethodExAccessibleObjectisAccessible/MethodExAccessibleObjectisAccessible.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExAccessibleObjectisAccessible.java + * -@TestCaseName: Exception in reflect Method:public boolean isAccessible() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class MethodClass11, which has sampleMethod method, and annotate the method + * -#step2: Call the run of the use case, and execute method 1. In the method, get the method of MethodClass11 by + * calling getMethod as Object 1 + * -#step3: Call isAccessible() on object 1 to confirm that the returned are correct + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExAccessibleObjectisAccessible.java + * -@ExecuteClass: MethodExAccessibleObjectisAccessible + * -@ExecuteArgs: + */ + +import java.lang.reflect.Method; + + +public class MethodExAccessibleObjectisAccessible { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + + try { + result = methodExAccessibleObjectisAccessible1(); + } catch (Exception e) { + MethodExAccessibleObjectisAccessible.res = MethodExAccessibleObjectisAccessible.res - 10; + } + + + if (result == 4 && MethodExAccessibleObjectisAccessible.res == 98) { + result = 0; + } + + return result; + } + + private static int methodExAccessibleObjectisAccessible1() throws NoSuchMethodException, SecurityException, NoSuchFieldException { + int result1 = 4; /*STATUS_FAILED*/ + // boolean isAccessible() + Method sampleMethod = MethodClass11.class.getMethod("sampleMethod"); + + if (sampleMethod.isAccessible()) { + MethodExAccessibleObjectisAccessible.res = MethodExAccessibleObjectisAccessible.res - 10; + } else { + MethodExAccessibleObjectisAccessible.res = MethodExAccessibleObjectisAccessible.res - 1; + } + + return result1; + } + +} + +@CustomAnnotationn(name = "SampleClass", value = "Sample Class Annotation") +class MethodClass11 { + private String sampleField; + + @CustomAnnotationn(name = "sampleMethod", value = "Sample Class Annotation") + public String sampleMethod() { + return "sample"; + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@interface CustomAnnotationn { + String name(); + + String value(); +} + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0076-rt-parent-MethodExAccessibleObjectisAnnotationPresentNullPointerException/MethodExAccessibleObjectisAnnotationPresentNullPointerException.java b/test/testsuite/ouroboros/parent_test/RT0076-rt-parent-MethodExAccessibleObjectisAnnotationPresentNullPointerException/MethodExAccessibleObjectisAnnotationPresentNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..e857cc32c8b737a48d92d9bb2b01fe3a81ddb1bf --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0076-rt-parent-MethodExAccessibleObjectisAnnotationPresentNullPointerException/MethodExAccessibleObjectisAnnotationPresentNullPointerException.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExAccessibleObjectisAnnotationPresentNullPointerException.java + * -@TestCaseName: Exception in reflect Method:public boolean isAnnotationPresent(Class annotationClass) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class MethodClass8, which has sampleMethod method, and annotate the method + * -#step2: Call the run of the use case, and execute method 1. In the method, get the method of MethodClass8 by + * calling getMethod as Object 1 + * -#step3: Call isAnnotationPresent(Class annotationClass) on object 1 to confirm that the returned are correct + * -#step4: execute method 2. In the method, get the method of SampleClass_h6 by calling getMethod as Object 2 + * -#step5: Call isAnnotationPresent(null) on object 2 with null parameter, confirm to throw NullPointerException + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExAccessibleObjectisAnnotationPresentNullPointerException.java + * -@ExecuteClass: MethodExAccessibleObjectisAnnotationPresentNullPointerException + * -@ExecuteArgs: + */ + + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.reflect.Method; + + +public class MethodExAccessibleObjectisAnnotationPresentNullPointerException { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + + try { + result = methodExAccessibleObjectisAnnotationPresentNullPointerException1(); + } catch (Exception e) { + MethodExAccessibleObjectisAnnotationPresentNullPointerException.res = MethodExAccessibleObjectisAnnotationPresentNullPointerException.res - 20; + } + + try { + result = methodExAccessibleObjectisAnnotationPresentNullPointerException2(); + } catch (Exception e) { + MethodExAccessibleObjectisAnnotationPresentNullPointerException.res = MethodExAccessibleObjectisAnnotationPresentNullPointerException.res - 20; + } + + + if (result == 4 && MethodExAccessibleObjectisAnnotationPresentNullPointerException.res == 68) { + result = 0; + } + return result; + } + + private static int methodExAccessibleObjectisAnnotationPresentNullPointerException1() throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + // NullPointerException - If the specified object is empty. + Method sampleMethod = MethodClass8.class.getMethod("sampleMethod"); + try { + sampleMethod.isAnnotationPresent(null); + MethodExAccessibleObjectisAnnotationPresentNullPointerException.res = MethodExAccessibleObjectisAnnotationPresentNullPointerException.res - 10; + } catch (NullPointerException e1) { + MethodExAccessibleObjectisAnnotationPresentNullPointerException.res = MethodExAccessibleObjectisAnnotationPresentNullPointerException.res - 1; + } + return result1; + } + + private static int methodExAccessibleObjectisAnnotationPresentNullPointerException2() throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + // NullPointerException - If the specified object is empty. + // boolean isAnnotationPresent(Class annotationClass) + Method sampleMethod = MethodClass8.class.getMethod("sampleMethod"); + try { + sampleMethod.isAnnotationPresent(CustomAnnotationH100.class); + MethodExAccessibleObjectisAnnotationPresentNullPointerException.res = MethodExAccessibleObjectisAnnotationPresentNullPointerException.res - 30; + } catch (NullPointerException e1) { + MethodExAccessibleObjectisAnnotationPresentNullPointerException.res = MethodExAccessibleObjectisAnnotationPresentNullPointerException.res - 5; + } + return result1; + } + +} + +@CustomAnnotationH100(name = "SampleClass", value = "Sample Class Annotation") +class MethodClass8 { + private String sampleField; + + @CustomAnnotationH100(name = "sampleMethod", value = "Sample Method Annotation") + public String sampleMethod() { + return "sample"; + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@Retention(RetentionPolicy.RUNTIME) +@interface CustomAnnotationH100 { + String name(); + + String value(); +} + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0077-rt-parent-MethodExAccessibleObjectSetAccessible/MethodExAccessibleObjectSetAccessible.java b/test/testsuite/ouroboros/parent_test/RT0077-rt-parent-MethodExAccessibleObjectSetAccessible/MethodExAccessibleObjectSetAccessible.java new file mode 100755 index 0000000000000000000000000000000000000000..66d021dd87a3bcb536c99ee1f1de017f9b69b9c8 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0077-rt-parent-MethodExAccessibleObjectSetAccessible/MethodExAccessibleObjectSetAccessible.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExAccessibleObjectSetAccessible.java + * -@TestCaseName: Exception in reflect Method: static void setAccessible(AccessibleObject[] array, boolean flag) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class MethodClass14, which has sampleMethod method, and annotate the method + * -#step2: Call the run of the use case, and execute method 1. In the method, get the method of MethodClass14 by + * calling getMethod as Object 1 + * -#step3: Call setAccessible(AccessibleObject[] array, boolean flag) on object 1 to confirm that the returned are correct + * -#step4: Call the run of the use case, and execute method 2. In the method, get the method of MethodClass14 by + * calling getMethod as Object 2 + * -#step5: Call setAccessible(boolean flag) on object 2 to confirm that the returned are correct + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExAccessibleObjectSetAccessible.java + * -@ExecuteClass: MethodExAccessibleObjectSetAccessible + * -@ExecuteArgs: + */ + + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Method; + + +public class MethodExAccessibleObjectSetAccessible { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = methodExAccessibleObjectSetAccessible1(); + } catch (Exception e) { + MethodExAccessibleObjectSetAccessible.res = MethodExAccessibleObjectSetAccessible.res - 10; + } + + try { + result = methodExAccessibleObjectSetAccessible2(); + } catch (Exception e) { + MethodExAccessibleObjectSetAccessible.res = MethodExAccessibleObjectSetAccessible.res - 10; + } + + + if (result == 4 && MethodExAccessibleObjectSetAccessible.res == 79) { + result = 0; + } + return result; + } + + private static int methodExAccessibleObjectSetAccessible1() throws NoSuchFieldException { + int result1 = 4; /*STATUS_FAILED*/ + // SecurityException - Exception safety + // static void setAccessible(AccessibleObject[] array, boolean flag) + Method[] sampleMethod = MethodClass14.class.getMethods(); + + try { + AccessibleObject.setAccessible(sampleMethod, false); + MethodExAccessibleObjectSetAccessible.res = MethodExAccessibleObjectSetAccessible.res - 10; + } catch (SecurityException e1) { + MethodExAccessibleObjectSetAccessible.res = MethodExAccessibleObjectSetAccessible.res - 1; + } + return result1; + } + + private static int methodExAccessibleObjectSetAccessible2() throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + // SecurityException - Exception safety + // void setAccessible(boolean flag) + + Method sampleMethod = MethodClass14.class.getMethod("sampleMethod"); + try { + sampleMethod.setAccessible(false); + MethodExAccessibleObjectSetAccessible.res = MethodExAccessibleObjectSetAccessible.res - 10; + } catch (SecurityException e1) { + MethodExAccessibleObjectSetAccessible.res = MethodExAccessibleObjectSetAccessible.res - 1; + } + return result1; + } +} + +@CustomAnnotationwe(name = "SampleClass", value = "Sample Class Annotation") +class MethodClass14 { + private String sampleField; + + @CustomAnnotationwe(name = "sampleMethod", value = "Sample Method Annotation") + public String sampleMethod() { + return "sample"; + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@interface CustomAnnotationwe { + String name(); + + String value(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0079-rt-parent-MethodExExecutablegetAnnotationsByTypeNullPointerException/MethodExExecutablegetAnnotationsByTypeNullPointerException.java b/test/testsuite/ouroboros/parent_test/RT0079-rt-parent-MethodExExecutablegetAnnotationsByTypeNullPointerException/MethodExExecutablegetAnnotationsByTypeNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..7b00ca4fe248b95e6f2d4053e2a58554a549d69f --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0079-rt-parent-MethodExExecutablegetAnnotationsByTypeNullPointerException/MethodExExecutablegetAnnotationsByTypeNullPointerException.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExExecutablegetAnnotationsByTypeNullPointerException.java + *- @TestCaseName: Exception in reflect/Method: T[] getAnnotationsByType(Class annotationClass) + *- @TestCaseType: Function Test + *- @RequirementName: 补充重写类的父类方法 + *- @Brief: + * -#step1: Create a class SampleClass_h1, which has sampleMethod method, and annotate the method + * -#step2: Call the run of the use case, and execute method 1. In the method, get the method of SampleClass_h1 by + * calling getMethod as Object 1 + * -#step3: Call getAnnotationsByType(Class annotationClass) on object 1 to confirm that the returned are correct + * -#step4: execute method 2. In the method, get the method of SampleClass_h6 by calling getMethod as Object 2 + * -#step5: Call getAnnotationsByType(null) on object 2 with null parameter, confirm to throw NullPointerException + *- @Expect:0\n + *- @Priority: High + *- @Source: MethodExExecutablegetAnnotationsByTypeNullPointerException.java + *- @ExecuteClass: MethodExExecutablegetAnnotationsByTypeNullPointerException + *- @ExecuteArgs: + */ + +import java.lang.reflect.Method; + +public class MethodExExecutablegetAnnotationsByTypeNullPointerException { + static int res = 99; + + public static void main(String[] argv) { + System.out.println(new MethodExExecutablegetAnnotationsByTypeNullPointerException().run()); + } + + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = MethodExExecutablegetAnnotationsByTypeNullPointerException_1(); + } catch (Exception e) { + MethodExExecutablegetAnnotationsByTypeNullPointerException.res = MethodExExecutablegetAnnotationsByTypeNullPointerException.res - 20; + } + + try { + result = MethodExExecutablegetAnnotationsByTypeNullPointerException_2(); + } catch (Exception e) { + MethodExExecutablegetAnnotationsByTypeNullPointerException.res = MethodExExecutablegetAnnotationsByTypeNullPointerException.res - 20; + } + + if (result == 4 && MethodExExecutablegetAnnotationsByTypeNullPointerException.res == 74) { + result = 0; + } + + return result; + } + + private int MethodExExecutablegetAnnotationsByTypeNullPointerException_1() throws NoSuchMethodException { + // T[] getAnnotationsByType(Class annotationClass) + int result1 = 4; + Method m1 = SampleClass_h1.class.getDeclaredMethod("sampleMethod"); + try { + CustomAnnotations_h5[] tp = m1.getAnnotationsByType(CustomAnnotations_h5.class); + if (tp.getClass().toString().equals("class [LCustomAnnotations_h5;")) { + MethodExExecutablegetAnnotationsByTypeNullPointerException.res = MethodExExecutablegetAnnotationsByTypeNullPointerException.res - 10; + } + } catch (Exception e) { + MethodExExecutablegetAnnotationsByTypeNullPointerException.res = MethodExExecutablegetAnnotationsByTypeNullPointerException.res - 15; + } + + return result1; + } + + private int MethodExExecutablegetAnnotationsByTypeNullPointerException_2() throws NoSuchMethodException { + // NullPointerException - if the given annotation class is null + // T[] getAnnotationsByType(Class annotationClass) + int result1 = 4; + Method m1 = SampleClass_h1.class.getDeclaredMethod("sampleMethod"); + try { + CustomAnnotations_h5[] tp = m1.getAnnotationsByType(null); + MethodExExecutablegetAnnotationsByTypeNullPointerException.res = MethodExExecutablegetAnnotationsByTypeNullPointerException.res - 10; + } catch (NullPointerException e) { + MethodExExecutablegetAnnotationsByTypeNullPointerException.res = MethodExExecutablegetAnnotationsByTypeNullPointerException.res - 15; + } + + return result1; + } +} + +@CustomAnnotations_h5(name="SampleClass", value = "Sample Class Annotation") +class SampleClass_h1 { + private String sampleField; + + @CustomAnnotations_h5(name="sampleMethod", value = "Sample Method Annotation") + public String sampleMethod() { + return "sample"; + } + + public String getSampleField() { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@interface CustomAnnotations_h5 { + String name(); + String value(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0081-rt-parent-MethodExExecutablegetGenericParameterTypesExceptions/MethodExExecutablegetGenericParameterTypesExceptions.java b/test/testsuite/ouroboros/parent_test/RT0081-rt-parent-MethodExExecutablegetGenericParameterTypesExceptions/MethodExExecutablegetGenericParameterTypesExceptions.java new file mode 100755 index 0000000000000000000000000000000000000000..adf97b16c7c586ff756d6780a5429ee152ea7c80 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0081-rt-parent-MethodExExecutablegetGenericParameterTypesExceptions/MethodExExecutablegetGenericParameterTypesExceptions.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExExecutablegetGenericParameterTypesExceptions.java + * -@TestCaseName: Exception in reflect/Method:Type[] getGenericParameterTypes() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a class SampleClass_h3, which has getSampleField method, and annotate the method + * -#step2: Call the run of the use case, and execute method 1. In the method, get the method of SampleClass_h3 by + * calling getMethod as Object 1 + * -#step3: Call getGenericParameterTypes() on object 1 to confirm that the returned are correct + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExExecutablegetGenericParameterTypesExceptions.java + * -@ExecuteClass: MethodExExecutablegetGenericParameterTypesExceptions + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.Arrays; + + +public class MethodExExecutablegetGenericParameterTypesExceptions { + static int res = 99; + + public static void main(String[] argv) { + System.out.println(new MethodExExecutablegetGenericParameterTypesExceptions().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = methodExExecutablegetGenericParameterTypesExceptions1(); + } catch (Exception e) { + MethodExExecutablegetGenericParameterTypesExceptions.res = MethodExExecutablegetGenericParameterTypesExceptions.res - 20; + } + + if (result == 4 && MethodExExecutablegetGenericParameterTypesExceptions.res == 89) { + result = 0; + } + + return result; + } + + private int methodExExecutablegetGenericParameterTypesExceptions1() throws NoSuchMethodException { + // Type[] getGenericParameterTypes() + int result1 = 4; + Method m1 = SampleClassH3.class.getDeclaredMethod("getSampleField"); + try { + Type[] tp = m1.getGenericParameterTypes(); + + if (Arrays.toString(tp).equals("[]")) { + MethodExExecutablegetGenericParameterTypesExceptions.res = MethodExExecutablegetGenericParameterTypesExceptions.res - 10; + } + } catch (Exception e) { + MethodExExecutablegetGenericParameterTypesExceptions.res = MethodExExecutablegetGenericParameterTypesExceptions.res - 15; + } + + return result1; + } +} + +@CustomAnnotationsH8(name = "SampleClass", value = "Sample Class Annotation") +class SampleClassH3 { + private String sampleField; + + public String getSampleField() throws ArrayIndexOutOfBoundsException { + return sampleField; + } + + public void setSampleField(String sampleField) { + this.sampleField = sampleField; + } +} + +@interface CustomAnnotationsH8 { + String name(); + + String value(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0082-rt-parent-MethodExObjectnotifyAllIllegalMonitorStateException/MethodExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0082-rt-parent-MethodExObjectnotifyAllIllegalMonitorStateException/MethodExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..d34675f53ab7aaa0095bf1b78ff5f3f48723d5a3 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0082-rt-parent-MethodExObjectnotifyAllIllegalMonitorStateException/MethodExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Method: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: MethodExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Method; + +public class MethodExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private Method[] rp = MethodExObjectnotifyAllIllegalMonitorStateException.class.getMethods(); + + public static void main(String argv[]) { + System.out.println(new MethodExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = methodExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + MethodExObjectnotifyAllIllegalMonitorStateException.res = MethodExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new MethodExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && MethodExObjectnotifyAllIllegalMonitorStateException.res == 68) { + result = 0; + } + + return result; + } + + private int methodExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + rp[0].notifyAll(); + MethodExObjectnotifyAllIllegalMonitorStateException.res = MethodExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + MethodExObjectnotifyAllIllegalMonitorStateException.res = MethodExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class MethodExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp[0].notifyAll(); + MethodExObjectnotifyAllIllegalMonitorStateException.res = MethodExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + MethodExObjectnotifyAllIllegalMonitorStateException.res = MethodExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0083-rt-parent-MethodExObjectnotifyIllegalMonitorStateException/MethodExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0083-rt-parent-MethodExObjectnotifyIllegalMonitorStateException/MethodExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..387367252354a9407f84809a628f38e6f6bbdd19 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0083-rt-parent-MethodExObjectnotifyIllegalMonitorStateException/MethodExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Method: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: MethodExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Method; + +public class MethodExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private Method[] rp = MethodExObjectnotifyIllegalMonitorStateException.class.getMethods(); + + public static void main(String argv[]) { + System.out.println(new MethodExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = methodExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + MethodExObjectnotifyIllegalMonitorStateException.res = MethodExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new MethodExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && MethodExObjectnotifyIllegalMonitorStateException.res == 68) { + result = 0; + } + + return result; + } + + private int methodExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + rp[0].notify(); + MethodExObjectnotifyIllegalMonitorStateException.res = MethodExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + MethodExObjectnotifyIllegalMonitorStateException.res = MethodExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class MethodExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp[0].notify(); + MethodExObjectnotifyIllegalMonitorStateException.res = MethodExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + MethodExObjectnotifyIllegalMonitorStateException.res = MethodExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0084-rt-parent-MethodExObjectwaitIllegalArgumentException/MethodExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0084-rt-parent-MethodExObjectwaitIllegalArgumentException/MethodExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..4efc418be442be678a52b2dbfb696358bad2ae37 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0084-rt-parent-MethodExObjectwaitIllegalArgumentException/MethodExObjectwaitIllegalArgumentException.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in reflect/Method: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: MethodExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Method; + +public class MethodExObjectwaitIllegalArgumentException { + static int res = 99; + static Method[] methods = MethodExObjectwaitIllegalArgumentException.class.getMethods(); + + public static void main(String argv[]) { + System.out.println(new MethodExObjectwaitIllegalArgumentException().run()); + } + + private class MethodExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + long millis = -1; + + /** + * Thread run fun + */ + public void run() { + synchronized (methods[0]) { + methods[0].notifyAll(); + try { + methods[0].wait(millis); + MethodExObjectwaitIllegalArgumentException.res = MethodExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + MethodExObjectwaitIllegalArgumentException.res = MethodExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwaitIllegalArgumentException.res = MethodExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + MethodExObjectwaitIllegalArgumentException.res = MethodExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class MethodExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // + // final void wait(long millis, int nanos) + + long millis = -2; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (methods[0]) { + methods[0].notifyAll(); + try { + methods[0].wait(millis, nanos); + MethodExObjectwaitIllegalArgumentException.res = MethodExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + MethodExObjectwaitIllegalArgumentException.res = MethodExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwaitIllegalArgumentException.res = MethodExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + MethodExObjectwaitIllegalArgumentException.res = MethodExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new MethodExObjectwaitIllegalArgumentException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new MethodExObjectwaitIllegalArgumentException31()); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && MethodExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n diff --git a/test/testsuite/ouroboros/parent_test/RT0085-rt-parent-MethodExObjectwaitIllegalMonitorStateException/MethodExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0085-rt-parent-MethodExObjectwaitIllegalMonitorStateException/MethodExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..be9ec406d0347f1745a23e224dd5ab890b869834 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0085-rt-parent-MethodExObjectwaitIllegalMonitorStateException/MethodExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect/Method: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: MethodExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Method; + +public class MethodExObjectwaitIllegalMonitorStateException { + static int res = 99; + static Method[] methods = MethodExObjectwaitIllegalMonitorStateException.class.getMethods(); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = methodExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = methodExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = methodExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && MethodExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int methodExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + methods[0].wait(); + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int methodExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + methods[0].wait(millis); + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int methodExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + methods[0].wait(millis, nanos); + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwaitIllegalMonitorStateException.res = MethodExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0086-rt-parent-MethodExObjectwaitInterruptedException/MethodExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0086-rt-parent-MethodExObjectwaitInterruptedException/MethodExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..96690da58185b8f72fb0fcf36b8f21162829e1f1 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0086-rt-parent-MethodExObjectwaitInterruptedException/MethodExObjectwaitInterruptedException.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in reflect/Field: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExObjectwaitInterruptedException.java + * -@ExecuteClass: MethodExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.Method; + +public class MethodExObjectwaitInterruptedException { + static int res = 99; + static Method[] methods = MethodExObjectwaitInterruptedException.class.getMethods(); + + public static void main(String argv[]) throws NoSuchFieldException, SecurityException { + System.out.println(new MethodExObjectwaitInterruptedException().run()); + } + + private class MethodExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (methods[0]) { + methods[0].notifyAll(); + try { + methods[0].wait(); + MethodExObjectwaitInterruptedException.res = MethodExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + MethodExObjectwaitInterruptedException.res = MethodExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwaitInterruptedException.res = MethodExObjectwaitInterruptedException.res - 30; + } + } + } + } + + private class MethodExObjectwaitInterruptedException12 implements Runnable { + // final void wait(long millis) + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (methods[0]) { + methods[0].notifyAll(); + try { + methods[0].wait(millis); + MethodExObjectwaitInterruptedException.res = MethodExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + MethodExObjectwaitInterruptedException.res = MethodExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwaitInterruptedException.res = MethodExObjectwaitInterruptedException.res - 30; + } + } + } + } + + private class MethodExObjectwaitInterruptedException13 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (methods[0]) { + methods[0].notifyAll(); + try { + methods[0].wait(millis, nanos); + MethodExObjectwaitInterruptedException.res = MethodExObjectwaitInterruptedException.res - 10; + } catch (InterruptedException e1) { + MethodExObjectwaitInterruptedException.res = MethodExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwaitInterruptedException.res = MethodExObjectwaitInterruptedException.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new MethodExObjectwaitInterruptedException11()); + Thread t2 = new Thread(new MethodExObjectwaitInterruptedException11()); + // final void wait(long millis) + Thread t3 = new Thread(new MethodExObjectwaitInterruptedException12()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new MethodExObjectwaitInterruptedException13()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && MethodExObjectwaitInterruptedException.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0087-rt-parent-MethodExObjectwait/MethodExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0087-rt-parent-MethodExObjectwait/MethodExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..1401ecd142d1239fd562ee02182dcdc9ed49203c --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0087-rt-parent-MethodExObjectwait/MethodExObjectwait.java @@ -0,0 +1,187 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Method/MethodExObjectwait.java + * -@TestCaseName: Exception in reflect Method: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: MethodExObjectwait.java + * -@ExecuteClass: MethodExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.reflect.Method; + +public class MethodExObjectwait { + static int res = 99; + private Method[] cal = MethodExObjectwait.class.getMethods(); + private Method[] cal2 = MethodExObjectwait.class.getMethods(); + private Method[] cal3 = MethodExObjectwait.class.getMethods(); + + public static void main(String argv[]) { + System.out.println(new MethodExObjectwait().run()); + } + + private class MethodExObjectwait11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (cal) { + cal.notifyAll(); + try { + cal.wait(); + MethodExObjectwait.res = MethodExObjectwait.res - 10; + } catch (InterruptedException e1) { + MethodExObjectwait.res = MethodExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwait.res = MethodExObjectwait.res - 30; + } + } + } + } + + private class MethodExObjectwait12 implements Runnable { + // final void wait(long millis) + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (cal2) { + cal2.notifyAll(); + try { + cal2.wait(millis); + MethodExObjectwait.res = MethodExObjectwait.res - 10; + } catch (InterruptedException e1) { + MethodExObjectwait.res = MethodExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwait.res = MethodExObjectwait.res - 30; + } + } + } + } + + private class MethodExObjectwait13 implements Runnable { + // final void wait(long millis, int nanos) + + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (cal3) { + cal3.notifyAll(); + try { + cal3.wait(millis, nanos); + MethodExObjectwait.res = MethodExObjectwait.res - 10; + } catch (InterruptedException e1) { + MethodExObjectwait.res = MethodExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + MethodExObjectwait.res = MethodExObjectwait.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new MethodExObjectwait11()); + Thread t2 = new Thread(new MethodExObjectwait11()); + // final void wait(long millis) + Thread t3 = new Thread(new MethodExObjectwait12()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new MethodExObjectwait13()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && MethodExObjectwait.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0088-rt-parent-ModifierExObjectgetClass/ModifierExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0088-rt-parent-ModifierExObjectgetClass/ModifierExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..240069fc32938c86e38deb1ba5dd602fb296004e --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0088-rt-parent-ModifierExObjectgetClass/ModifierExObjectgetClass.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ModifierExObjectgetClass.java + * -@TestCaseName: Exception in reflect Modifier: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create Object1 by new Modifier() + * -#step2: Call getClass() on Object1 + * -#step3: Confirm that the returned Class is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: ModifierExObjectgetClass.java + * -@ExecuteClass: ModifierExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.reflect.Modifier; + +public class ModifierExObjectgetClass { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ModifierExObjectgetClass().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = modifierExObjectgetClass1(); + } catch (Exception e) { + ModifierExObjectgetClass.res = ModifierExObjectgetClass.res - 20; + } + + if (result == 4 && ModifierExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + + private int modifierExObjectgetClass1() { + int result1 = 4; /*STATUS_FAILED*/ + // final Class getClass() + + Modifier mf2 = new Modifier(); + Class px1 = mf2.getClass(); + if (px1.toString().equals("class java.lang.reflect.Modifier")) { + ModifierExObjectgetClass.res = ModifierExObjectgetClass.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0089-rt-parent-ModifierExObjecthashCode/ModifierExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0089-rt-parent-ModifierExObjecthashCode/ModifierExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..4b6280df58eaf6546269104f2ec8642d27c78527 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0089-rt-parent-ModifierExObjecthashCode/ModifierExObjecthashCode.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ModifierExObjecthashCode.java + * -@TestCaseName: Exception in reflect Modifier: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create Object1 by new Modifier(), Object2 is given by Object1 + * -#step2: Create Object3 by new Modifier(). + * -#step3: Check hashCode of the Object1 and Object2 is equal, check hashCode of the Object1 and Object3 is not equal. + * -@Expect:0\n + * -@Priority: High + * -@Source: ModifierExObjecthashCode.java + * -@ExecuteClass: ModifierExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.reflect.Modifier; + +public class ModifierExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ModifierExObjecthashCode().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = modifierExObjecthashCode1(); + } catch (Exception e) { + ModifierExObjecthashCode.res = ModifierExObjecthashCode.res - 20; + } + + + if (result == 4 && ModifierExObjecthashCode.res == 89) { + result = 0; + } + + return result; + } + + + private int modifierExObjecthashCode1() { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + + Modifier mf0 = new Modifier(); + Modifier mf1 = mf0; + Modifier mf2 = new Modifier(); + + int px0 = mf0.hashCode(); + int px1 = mf1.hashCode(); + int px2 = mf2.hashCode(); + + if (px0 == px1 && px0 != px2) { + ModifierExObjecthashCode.res = ModifierExObjecthashCode.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0090-rt-parent-ModifierExObjectnotifyAllIllegalMonitorStateException/ModifierExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0090-rt-parent-ModifierExObjectnotifyAllIllegalMonitorStateException/ModifierExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..ab8286effdc6cd47287b550c59f1502e7d08260a --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0090-rt-parent-ModifierExObjectnotifyAllIllegalMonitorStateException/ModifierExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ModifierExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Modifier: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll() inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ModifierExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ModifierExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Modifier; + +public class ModifierExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + Modifier mf2 = new Modifier(); + + public static void main(String argv[]) { + System.out.println(new ModifierExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = modifierExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ModifierExObjectnotifyAllIllegalMonitorStateException.res = ModifierExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ModifierExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ModifierExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int modifierExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + mf2.notifyAll(); + ModifierExObjectnotifyAllIllegalMonitorStateException.res = ModifierExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectnotifyAllIllegalMonitorStateException.res = ModifierExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ModifierExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ModifierExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + try { + mf2.notifyAll(); + ModifierExObjectnotifyAllIllegalMonitorStateException.res = ModifierExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectnotifyAllIllegalMonitorStateException.res = ModifierExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0091-rt-parent-ModifierExObjectnotifyIllegalMonitorStateException/ModifierExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0091-rt-parent-ModifierExObjectnotifyIllegalMonitorStateException/ModifierExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..1d9cb27641c6f21ce4378dcf500f21e9c8426931 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0091-rt-parent-ModifierExObjectnotifyIllegalMonitorStateException/ModifierExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ModifierExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Modifier: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ModifierExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ModifierExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Modifier; + +public class ModifierExObjectnotifyIllegalMonitorStateException { + static int res = 99; + Modifier mf2 = new Modifier(); + + public static void main(String argv[]) { + System.out.println(new ModifierExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = modifierExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ModifierExObjectnotifyIllegalMonitorStateException.res = ModifierExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ModifierExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ModifierExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int modifierExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + mf2.notify(); + ModifierExObjectnotifyIllegalMonitorStateException.res = ModifierExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectnotifyIllegalMonitorStateException.res = ModifierExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ModifierExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ModifierExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + try { + mf2.notify(); + ModifierExObjectnotifyIllegalMonitorStateException.res = ModifierExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectnotifyIllegalMonitorStateException.res = ModifierExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0092-rt-parent-ModifierExObjectwaitInterruptedException/ModifierExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0092-rt-parent-ModifierExObjectwaitInterruptedException/ModifierExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..272e36bfa5531a187df70e304d10b2aaa6ca634c --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0092-rt-parent-ModifierExObjectwaitInterruptedException/ModifierExObjectwaitInterruptedException.java @@ -0,0 +1,196 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ModifierExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in reflect Modifier: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: ModifierExObjectwaitInterruptedException.java + * -@ExecuteClass: ModifierExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Modifier; + +public class ModifierExObjectwaitInterruptedException { + static int res = 99; + private static Modifier mf2 = new Modifier(); + + public static void main(String argv[]) { + System.out.println(new ModifierExObjectwaitInterruptedException().run()); + } + + private class ModifierExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + + private int remainder; + + private ModifierExObjectwaitInterruptedException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(); + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class ModifierExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10000; + + private ModifierExObjectwaitInterruptedException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis); + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class ModifierExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10000; + int nanos = 100; + + private ModifierExObjectwaitInterruptedException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis, nanos); + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ModifierExObjectwaitInterruptedException.res = ModifierExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ModifierExObjectwaitInterruptedException11(1)); + // final void wait(long millis) + Thread t3 = new Thread(new ModifierExObjectwaitInterruptedException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ModifierExObjectwaitInterruptedException31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t1.interrupt(); + sleep(1000); + t3.start(); + sleep(1000); + t3.interrupt(); + sleep(1000); + t5.start(); + sleep(1000); + t5.interrupt(); + sleep(1000); + + if (result == 2 && ModifierExObjectwaitInterruptedException.res == 96) { + result = 0; + } + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0093-rt-parent-ModifierExObjectwait/ModifierExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0093-rt-parent-ModifierExObjectwait/ModifierExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..c50a76ded6a90d9c1a68abde1df94023c1c83008 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0093-rt-parent-ModifierExObjectwait/ModifierExObjectwait.java @@ -0,0 +1,217 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ModifierExObjectwait.java + * -@TestCaseName: Exception in reflect Modifier: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: ModifierExObjectwait.java + * -@ExecuteClass: ModifierExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.reflect.Modifier; + +public class ModifierExObjectwait { + static int res = 99; + private Modifier mf2 = new Modifier(); + + public static void main(String argv[]) { + System.out.println(new ModifierExObjectwait().run()); + } + + private class ModifierExObjectwait11 implements Runnable { + // final void wait() + private int remainder; + + private ModifierExObjectwait11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(); + ModifierExObjectwait.res = ModifierExObjectwait.res - 15; + } catch (InterruptedException e1) { + ModifierExObjectwait.res = ModifierExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwait.res = ModifierExObjectwait.res - 10; + } + } + } + } + + private class ModifierExObjectwait21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10; + + private ModifierExObjectwait21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notify(); + try { + mf2.wait(millis); + ModifierExObjectwait.res = ModifierExObjectwait.res - 15; + } catch (InterruptedException e1) { + ModifierExObjectwait.res = ModifierExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwait.res = ModifierExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ModifierExObjectwait.res = ModifierExObjectwait.res - 5; + } + } + } + } + + private class ModifierExObjectwait31 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10; + int nanos = 10; + + private ModifierExObjectwait31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis, nanos); + ModifierExObjectwait.res = ModifierExObjectwait.res - 15; + } catch (InterruptedException e1) { + ModifierExObjectwait.res = ModifierExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwait.res = ModifierExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ModifierExObjectwait.res = ModifierExObjectwait.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * join fun + * + * @param thread want join thread + */ + private void waitFinish(Thread thread) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ModifierExObjectwait11(1)); + Thread t2 = new Thread(new ModifierExObjectwait11(2)); + // final void wait(long millis) + Thread t3 = new Thread(new ModifierExObjectwait21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ModifierExObjectwait31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + t1.interrupt(); + t2.interrupt(); + + waitFinish(t1); + waitFinish(t3); + waitFinish(t5); + + if (result == 2 && ModifierExObjectwait.res == 54) { + result = 0; + } + + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0094-rt-parent-ParameterExObjectgetClass/ParameterExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0094-rt-parent-ParameterExObjectgetClass/ParameterExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..e6f9c6234584b5fffc7635725146bcda3b3dc35a --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0094-rt-parent-ParameterExObjectgetClass/ParameterExObjectgetClass.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ParameterExObjectgetClass.java + * -@TestCaseName: Exception in reflect Parameter: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -@Expect:0\n + * -@Priority: High + * -@Source: ParameterExObjectgetClass.java + * -@ExecuteClass: ParameterExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; + +public class ParameterExObjectgetClass { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ParameterExObjectgetClass().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = parameterExObjectgetClass1(); + } catch (Exception e) { + System.out.println(e); + ParameterExObjectgetClass.res = ParameterExObjectgetClass.res - 20; + } + + if (result == 4 && ParameterExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + private int parameterExObjectgetClass1() throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + // final Class getClass() + // System.out.println("-0-"); + Method method = Parameter01a.class.getMethod("getName", new Class[]{String.class}); + // System.out.println("-1-"); + Parameter[] parameters = method.getParameters(); + // System.out.println("-2-"); + Class px1 = parameters[0].getClass(); + // System.out.println(px1); + if (px1.toString().equals("class java.lang.reflect.Parameter")) { + ParameterExObjectgetClass.res = ParameterExObjectgetClass.res - 10; + } + return result1; + } + +} + +class Parameter01a { + String name = "default"; + + public String getName(String str1) { + return this.name; + } + +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0095-rt-parent-ParameterExObjectnotifyAllIllegalMonitorStateException/ParameterExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0095-rt-parent-ParameterExObjectnotifyAllIllegalMonitorStateException/ParameterExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..82a542d9f10206d7850817fe9b9ec6afc2f0b458 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0095-rt-parent-ParameterExObjectnotifyAllIllegalMonitorStateException/ParameterExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ParameterExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Parameter: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ParameterExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ParameterExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Parameter; +import java.lang.reflect.Method; + +public class ParameterExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ParameterExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = parameterExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ParameterExObjectnotifyAllIllegalMonitorStateException.res = ParameterExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ParameterExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ParameterExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int parameterExObjectnotifyAllIllegalMonitorStateException1() throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + Method method = Parameter03a.class.getMethod("getName", new Class[]{String.class}); + Parameter[] parameters = method.getParameters(); + + try { + parameters[0].notifyAll(); + ParameterExObjectnotifyAllIllegalMonitorStateException.res = ParameterExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ParameterExObjectnotifyAllIllegalMonitorStateException.res = ParameterExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ParameterExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ParameterExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + Method me = null; + try { + me = Parameter03a.class.getMethod("getName", new Class[]{String.class}); + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + Parameter[] parameters = me.getParameters(); + synchronized (parameters[0]) { + try { + parameters[0].notifyAll(); + ParameterExObjectnotifyAllIllegalMonitorStateException.res = ParameterExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ParameterExObjectnotifyAllIllegalMonitorStateException.res = ParameterExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} + +class Parameter03a { + private String name = "default"; + + public String getName(String str1) { + return str1; + } + +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0096-rt-parent-ParameterExObjectnotifyIllegalMonitorStateException/ParameterExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0096-rt-parent-ParameterExObjectnotifyIllegalMonitorStateException/ParameterExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..705cde6190eaa91d97da34e57b7bb48a8cf58843 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0096-rt-parent-ParameterExObjectnotifyIllegalMonitorStateException/ParameterExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ParameterExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Parameter: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ParameterExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ParameterExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Parameter; +import java.lang.reflect.Method; + +public class ParameterExObjectnotifyIllegalMonitorStateException { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ParameterExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = parameterExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ParameterExObjectnotifyIllegalMonitorStateException.res = ParameterExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ParameterExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ParameterExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int parameterExObjectnotifyIllegalMonitorStateException1() throws NoSuchMethodException, SecurityException { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + Method method = Parameter02a.class.getMethod("getName", new Class[]{String.class}); + Parameter[] parameters = method.getParameters(); + + try { + parameters[0].notify(); + ParameterExObjectnotifyIllegalMonitorStateException.res = ParameterExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ParameterExObjectnotifyIllegalMonitorStateException.res = ParameterExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ParameterExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ParameterExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + Method me = null; + try { + me = Parameter02a.class.getMethod("getName", new Class[]{String.class}); + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + Parameter[] parameters = me.getParameters(); + synchronized (parameters[0]) { + try { + parameters[0].notify(); + ParameterExObjectnotifyIllegalMonitorStateException.res = ParameterExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ParameterExObjectnotifyIllegalMonitorStateException.res = ParameterExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} + +class Parameter02a { + private String name = "default"; + + public String getName(String str1) { + return str1; + } + +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0097-rt-parent-ParameterExObjectwait/ParameterExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0097-rt-parent-ParameterExObjectwait/ParameterExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..5530fc03cf8b65bd6d92a7d653a35eee11cfd498 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0097-rt-parent-ParameterExObjectwait/ParameterExObjectwait.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ParameterExObjectwait.java + *- @TestCaseName: Exception in reflect Parameter: final void wait(*) + *- @TestCaseType: Function Test + *- @RequirementName: 补充重写类的父类方法 + *- @Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + *- @Expect:0\n + *- @Priority: High + *- @Source: ParameterExObjectwait.java + *- @ExecuteClass: ParameterExObjectwait + *- @ExecuteArgs: + */ + +import java.lang.reflect.Parameter; + +public class ParameterExObjectwait { + static int res = 99; + private static Parameter[] param = null; + + public static void main(String argv[]) { + try { + param = ParameterExObjectwait.class.getMethod("sleep", new Class[]{int.class}).getParameters(); + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + System.out.println(new ParameterExObjectwait().run()); + } + + private class ParameterExObjectwait_11 implements Runnable { + // final void wait() + private int remainder; + + private ParameterExObjectwait_11(int remainder) { + this.remainder = remainder; + } + + public void run() { + synchronized (param[0]) { + param[0].notifyAll(); + try { + param[0].wait(); + ParameterExObjectwait.res = ParameterExObjectwait.res - 15; + } catch (InterruptedException e1) { + //System.out.println("111"); + ParameterExObjectwait.res = ParameterExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + //System.out.println("222"); + ParameterExObjectwait.res = ParameterExObjectwait.res - 10; + } + } + } + } + + private class ParameterExObjectwait_21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10; + + private ParameterExObjectwait_21(int remainder) { + this.remainder = remainder; + } + + public void run() { + synchronized (param[0]) { + param[0].notify(); + try { + param[0].wait(millis); + ParameterExObjectwait.res = ParameterExObjectwait.res - 15; + } catch (InterruptedException e1) { + ParameterExObjectwait.res = ParameterExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ParameterExObjectwait.res = ParameterExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ParameterExObjectwait.res = ParameterExObjectwait.res - 5; + } + } + } + } + + private class ParameterExObjectwait_31 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10; + int nanos = 10; + + private ParameterExObjectwait_31(int remainder) { + this.remainder = remainder; + } + + public void run() { + synchronized (param[0]) { + param[0].notifyAll(); + try { + param[0].wait(millis, nanos); + ParameterExObjectwait.res = ParameterExObjectwait.res - 15; + } catch (InterruptedException e1) { + ParameterExObjectwait.res = ParameterExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ParameterExObjectwait.res = ParameterExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ParameterExObjectwait.res = ParameterExObjectwait.res - 5; + } + } + } + } + + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private void waitFinish(Thread thread) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public int run() { + int result = 2; /*STATUS_FAILED*/ + //check api normal + // final void wait() + Thread t1 = new Thread(new ParameterExObjectwait_11(1)); + Thread t2 = new Thread(new ParameterExObjectwait_11(2)); + //final void wait(long millis) + Thread t3 = new Thread(new ParameterExObjectwait_21(3)); + //final void wait(long millis, int nanos) + Thread t5 = new Thread(new ParameterExObjectwait_31(5)); + t1.start(); + sleep(100); + t3.start(); + sleep(100); + t5.start(); + sleep(100); + t2.start(); + t1.interrupt(); + t2.interrupt(); + + waitFinish(t1); + waitFinish(t3); + waitFinish(t5); + + + if (result == 2 && ParameterExObjectwait.res == 54) { + result = 0; + } + +// System.out.println("result: " + result); +// System.out.println("ParameterExObjectwait.res: " + ParameterExObjectwait.res); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0098-rt-parent-ProxyExObjecthashCode/ProxyExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0098-rt-parent-ProxyExObjecthashCode/ProxyExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..fc57c899e026465c8e27d203813e9f962907653c --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0098-rt-parent-ProxyExObjecthashCode/ProxyExObjecthashCode.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ProxyExObjecthashCode.java + * -@TestCaseName: Exception in reflect Proxy: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create MyProxy1 extend by Proxy + * -#step2: Create Object1 by new MyProxy1, Object2 is given by Object2, Object3 by new MyProxy1. + * -#step3: Check hashCode of the Object1 and Object2 is equal, check hashCode of the Object1 and Object3 is not equal. + * -@Expect:0\n + * -@Priority: High + * -@Source: ProxyExObjecthashCode.java + * -@ExecuteClass: ProxyExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +public class ProxyExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = proxyExObjecthashCode1(); + } catch (Exception e) { + ProxyExObjecthashCode.res = ProxyExObjecthashCode.res - 20; + } + + if (result == 4 && ProxyExObjecthashCode.res == 89) { + result = 0; + } + + return result; + } + + private static int proxyExObjecthashCode1() { + // int hashCode() + int result1 = 4; /*STATUS_FAILED*/ + MyProxy1 px0 = new MyProxy1(new MyInvocationHandler()); + MyProxy1 px1 = px0; + MyProxy1 px2 = new MyProxy1(new MyInvocationHandler()); + + try { + int int0 = px0.hashCode(); + int int1 = px1.hashCode(); + int int2 = px2.hashCode(); + + if (px0 == px1 && px0 != px2) { + ProxyExObjecthashCode.res = ProxyExObjecthashCode.res - 10; + } + } catch (IllegalMonitorStateException e) { + ProxyExObjecthashCode.res = ProxyExObjecthashCode.res - 1; + } + + return result1; + } + +} + + +class MyProxy1 extends Proxy { + MyProxy1(InvocationHandler h) { + super(h); + } + + InvocationHandler getInvocationHandlerField() { + return h; + } +} + +class MyInvocationHandler implements InvocationHandler { + /** + * invoke test + * @param proxy proxy test + * @param method method for test + * @param args object[] for test + * @return any implementation + * @throws Throwable exception + */ + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return new Object(); // any implementation + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0099-rt-parent-ProxyExObjectnotifyAllIllegalMonitorStateException/ProxyExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0099-rt-parent-ProxyExObjectnotifyAllIllegalMonitorStateException/ProxyExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..1f4d68ace9540d0369572e15b6ed96428f1f6fbf --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0099-rt-parent-ProxyExObjectnotifyAllIllegalMonitorStateException/ProxyExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ProxyExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Proxy: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ProxyExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ProxyExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Proxy; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class ProxyExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private MyProxy3 proxy = new MyProxy3(new MyInvocationHandler2()); + + public static void main(String argv[]) { + System.out.println(new ProxyExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = proxyExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ProxyExObjectnotifyAllIllegalMonitorStateException.res = ProxyExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ProxyExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && ProxyExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int proxyExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + proxy.notifyAll(); + ProxyExObjectnotifyAllIllegalMonitorStateException.res = ProxyExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectnotifyAllIllegalMonitorStateException.res = ProxyExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ProxyExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ProxyExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + try { + proxy.notifyAll(); + ProxyExObjectnotifyAllIllegalMonitorStateException.res = ProxyExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectnotifyAllIllegalMonitorStateException.res = ProxyExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} + +class MyProxy3 extends Proxy { + MyProxy3(InvocationHandler h) { + super(h); + } + + InvocationHandler getInvocationHandlerField() { + return h; + } +} + +class MyInvocationHandler2 implements InvocationHandler { + /** + * invoke test + * + * @param proxy proxy test + * @param method method for test + * @param args object[] for test + * @return any implementation + * @throws Throwable exception + */ + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return new Object(); // any implementation + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0100-rt-parent-ProxyExObjectnotifyIllegalMonitorStateException/ProxyExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0100-rt-parent-ProxyExObjectnotifyIllegalMonitorStateException/ProxyExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..9c4104c1db723b1be51317251657a14b630b59e6 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0100-rt-parent-ProxyExObjectnotifyIllegalMonitorStateException/ProxyExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ProxyExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Proxy: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ProxyExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ProxyExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Proxy; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class ProxyExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private MyProxy2 proxy = new MyProxy2(new MyInvocationHandler1()); + + public static void main(String argv[]) { + System.out.println(new ProxyExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = proxyExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ProxyExObjectnotifyIllegalMonitorStateException.res = ProxyExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ProxyExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ProxyExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int proxyExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + proxy.notify(); + ProxyExObjectnotifyIllegalMonitorStateException.res = ProxyExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectnotifyIllegalMonitorStateException.res = ProxyExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ProxyExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ProxyExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + try { + proxy.notify(); + ProxyExObjectnotifyIllegalMonitorStateException.res = ProxyExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectnotifyIllegalMonitorStateException.res = ProxyExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} + +class MyProxy2 extends Proxy { + MyProxy2(InvocationHandler h) { + super(h); + } + + InvocationHandler getInvocationHandlerField() { + return h; + } +} + +class MyInvocationHandler1 implements InvocationHandler { + /** + * invoke test + * + * @param proxy proxy test + * @param method method for test + * @param args object[] for test + * @return any implementation + * @throws Throwable exception + */ + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return new Object(); // any implementation + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0101-rt-parent-ProxyExObjectwaitIllegalArgumentException/ProxyExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0101-rt-parent-ProxyExObjectwaitIllegalArgumentException/ProxyExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..14dcc6ba89d00c4038207f79f147d9609807d057 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0101-rt-parent-ProxyExObjectwaitIllegalArgumentException/ProxyExObjectwaitIllegalArgumentException.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ProxyExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in reflect Proxy: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: ProxyExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: ProxyExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Proxy; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class ProxyExObjectwaitIllegalArgumentException { + static int res = 99; + private MyProxy5 proxy = new MyProxy5(new MyInvocationHandler5()); + + public static void main(String argv[]) { + System.out.println(new ProxyExObjectwaitIllegalArgumentException().run()); + } + + private class ProxyExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + private int remainder; + long millis = -1; + + private ProxyExObjectwaitIllegalArgumentException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + proxy.notifyAll(); + try { + proxy.wait(millis); + ProxyExObjectwaitIllegalArgumentException.res = ProxyExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ProxyExObjectwaitIllegalArgumentException.res = ProxyExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwaitIllegalArgumentException.res = ProxyExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ProxyExObjectwaitIllegalArgumentException.res = ProxyExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class ProxyExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // + // final void wait(long millis, int nanos) + + private int remainder; + long millis = -2; + int nanos = 10; + + private ProxyExObjectwaitIllegalArgumentException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + proxy.notifyAll(); + try { + proxy.wait(millis, nanos); + ProxyExObjectwaitIllegalArgumentException.res = ProxyExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ProxyExObjectwaitIllegalArgumentException.res = ProxyExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwaitIllegalArgumentException.res = ProxyExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ProxyExObjectwaitIllegalArgumentException.res = ProxyExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new ProxyExObjectwaitIllegalArgumentException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ProxyExObjectwaitIllegalArgumentException31(5)); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && ProxyExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + + return result; + } +} + +class MyProxy5 extends Proxy { + MyProxy5(InvocationHandler h) { + super(h); + } + + InvocationHandler getInvocationHandlerField() { + return h; + } +} + +class MyInvocationHandler5 implements InvocationHandler { + /** + * invoke test + * + * @param proxy proxy test + * @param method method for test + * @param args object[] for test + * @return any implementation + * @throws Throwable exception + */ + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return new Object(); // any implementation + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0102-rt-parent-ProxyExObjectwaitIllegalMonitorStateException/ProxyExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0102-rt-parent-ProxyExObjectwaitIllegalMonitorStateException/ProxyExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..c5889ff352202e5231f470ae2b60eaaebd67cebf --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0102-rt-parent-ProxyExObjectwaitIllegalMonitorStateException/ProxyExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ProxyExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Proxy: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ProxyExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ProxyExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Proxy; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class ProxyExObjectwaitIllegalMonitorStateException { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = proxyExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = proxyExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = proxyExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && ProxyExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int proxyExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + MyProxy7 proxy = new MyProxy7(new MyInvocationHandler6()); + try { + proxy.wait(); + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int proxyExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + MyProxy7 proxy = new MyProxy7(new MyInvocationHandler6()); + long millis = 123; + try { + proxy.wait(millis); + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int proxyExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + MyProxy7 proxy = new MyProxy7(new MyInvocationHandler6()); + long millis = 123; + int nanos = 10; + try { + proxy.wait(millis, nanos); + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwaitIllegalMonitorStateException.res = ProxyExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } +} + +class MyProxy7 extends Proxy { + MyProxy7(InvocationHandler h) { + super(h); + } + + InvocationHandler getInvocationHandlerField() { + return h; + } +} + +class MyInvocationHandler6 implements InvocationHandler { + /** + * invoke test + * + * @param proxy proxy test + * @param method method for test + * @param args object[] for test + * @return any implementation + * @throws Throwable exception + */ + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return new Object(); // any implementation + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0103-rt-parent-ProxyExObjectwaitInterruptedException/ProxyExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0103-rt-parent-ProxyExObjectwaitInterruptedException/ProxyExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..74b2a44476bb9f9742b100cdcbf14bfbea2a3b28 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0103-rt-parent-ProxyExObjectwaitInterruptedException/ProxyExObjectwaitInterruptedException.java @@ -0,0 +1,223 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ProxyExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in reflect Proxy: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: ProxyExObjectwaitInterruptedException.java + * -@ExecuteClass: ProxyExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Proxy; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationHandler; + +public class ProxyExObjectwaitInterruptedException { + static int res = 99; + private MyProxy8 proxy = new MyProxy8(new MyInvocationHandler7()); + + public static void main(String argv[]) { + System.out.println(new ProxyExObjectwaitInterruptedException().run()); + } + + private class ProxyExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + private int remainder; + + private ProxyExObjectwaitInterruptedException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + proxy.notifyAll(); + try { + proxy.wait(); + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class ProxyExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10000; + + private ProxyExObjectwaitInterruptedException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + proxy.notifyAll(); + try { + proxy.wait(millis); + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class ProxyExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10000; + int nanos = 100; + + private ProxyExObjectwaitInterruptedException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + proxy.notifyAll(); + try { + proxy.wait(millis, nanos); + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ProxyExObjectwaitInterruptedException.res = ProxyExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ProxyExObjectwaitInterruptedException11(1)); + // final void wait(long millis) + Thread t3 = new Thread(new ProxyExObjectwaitInterruptedException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ProxyExObjectwaitInterruptedException31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t1.interrupt(); + sleep(1000); + t3.start(); + sleep(1000); + t3.interrupt(); + sleep(1000); + t5.start(); + sleep(1000); + t5.interrupt(); + sleep(1000); + + if (result == 2 && ProxyExObjectwaitInterruptedException.res == 96) { + result = 0; + } + + return result; + } +} + +class MyProxy8 extends Proxy { + MyProxy8(InvocationHandler h) { + super(h); + } + + InvocationHandler getInvocationHandlerField() { + return h; + } +} + +class MyInvocationHandler7 implements InvocationHandler { + /** + * invoke test + * + * @param proxy proxy test + * @param method method for test + * @param args object[] for test + * @return any implementation + * @throws Throwable exception + */ + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return new Object(); // any implementation + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0104-rt-parent-ProxyExObjectwait/ProxyExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0104-rt-parent-ProxyExObjectwait/ProxyExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..1b5ef603dc20d97026850f093d5ef2d3a1273e16 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0104-rt-parent-ProxyExObjectwait/ProxyExObjectwait.java @@ -0,0 +1,242 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ProxyExObjectwait.java + * -@TestCaseName: Exception in reflect Proxy: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: ProxyExObjectwait.java + * -@ExecuteClass: ProxyExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +public class ProxyExObjectwait { + static int res = 99; + private MyProxy4 proxy = new MyProxy4(new MyInvocationHandler3()); + + public static void main(String argv[]) { + System.out.println(new ProxyExObjectwait().run()); + } + + private class ProxyExObjectwait11 implements Runnable { + // final void wait() + private int remainder; + + private ProxyExObjectwait11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + proxy.notifyAll(); + try { + proxy.wait(); + ProxyExObjectwait.res = ProxyExObjectwait.res - 15; + } catch (InterruptedException e1) { + ProxyExObjectwait.res = ProxyExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwait.res = ProxyExObjectwait.res - 10; + } + } + } + } + + private class ProxyExObjectwait21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10; + + private ProxyExObjectwait21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + proxy.notifyAll(); + try { + proxy.wait(millis); + ProxyExObjectwait.res = ProxyExObjectwait.res - 15; + } catch (InterruptedException e1) { + ProxyExObjectwait.res = ProxyExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwait.res = ProxyExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ProxyExObjectwait.res = ProxyExObjectwait.res - 5; + } + } + } + } + + private class ProxyExObjectwait31 implements Runnable { + // final void wait(long millis, int nanos) + private int remainder; + long millis = 10; + int nanos = 10; + + private ProxyExObjectwait31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (proxy) { + proxy.notifyAll(); + try { + proxy.wait(millis, nanos); + ProxyExObjectwait.res = ProxyExObjectwait.res - 15; + } catch (InterruptedException e1) { + ProxyExObjectwait.res = ProxyExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ProxyExObjectwait.res = ProxyExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ProxyExObjectwait.res = ProxyExObjectwait.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * join fun + * + * @param thread wait join thread + */ + private void waitFinish(Thread thread) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ProxyExObjectwait11(1)); + Thread t2 = new Thread(new ProxyExObjectwait11(2)); + // final void wait(long millis) + Thread t3 = new Thread(new ProxyExObjectwait21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ProxyExObjectwait31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t3.start(); + sleep(100); + t5.start(); + sleep(100); + t2.start(); + waitFinish(t1); + waitFinish(t3); + waitFinish(t5); + t2.interrupt(); + + + if (result == 2 && ProxyExObjectwait.res == 54) { + result = 0; + } + + return result; + } +} + +class MyProxy4 extends Proxy { + MyProxy4(InvocationHandler h) { + super(h); + } + + InvocationHandler getInvocationHandlerField() { + return h; + } +} + +class MyInvocationHandler3 implements InvocationHandler { + /** + * invoke test + * + * @param proxy proxy test + * @param method method for test + * @param args object[] for test + * @return any implementation + * @throws Throwable exception + */ + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return new Object(); // any implementation + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0105-rt-parent-ReflectPermissionExBasicPermissionimplies/ReflectPermissionExBasicPermissionimplies.java b/test/testsuite/ouroboros/parent_test/RT0105-rt-parent-ReflectPermissionExBasicPermissionimplies/ReflectPermissionExBasicPermissionimplies.java new file mode 100755 index 0000000000000000000000000000000000000000..0df9d58bcd3d3c5bba72322cd0e234b9f251f027 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0105-rt-parent-ReflectPermissionExBasicPermissionimplies/ReflectPermissionExBasicPermissionimplies.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectPermissionExBasicPermissionimplies.java + * -@TestCaseName: Exception in reflect ReflectPermission: boolean implies(Permission p) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a ReflectPermission object + * -#step2: call method implies(Permission p) of new Object + * -#step3: Confirm that the return value is true + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectPermissionExBasicPermissionimplies.java + * -@ExecuteClass: ReflectPermissionExBasicPermissionimplies + * -@ExecuteArgs: + */ + +import java.lang.reflect.ReflectPermission; + +public class ReflectPermissionExBasicPermissionimplies { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = reflectPermissionExBasicPermissionimplies1(); + } catch (Exception e) { + ReflectPermissionExBasicPermissionimplies.res = ReflectPermissionExBasicPermissionimplies.res - 20; + } + + if (result == 4 && ReflectPermissionExBasicPermissionimplies.res == 89) { + result = 0; + } + + return result; + } + + private static int reflectPermissionExBasicPermissionimplies1() { + // boolean implies(Permission p) + int result1 = 4; /*STATUS_FAILED*/ + String name = "name"; + String actions = null; + ReflectPermission rp = new ReflectPermission(name, actions); + if (rp.implies(rp)) { + ReflectPermissionExBasicPermissionimplies.res = ReflectPermissionExBasicPermissionimplies.res - 10; + } else { + ReflectPermissionExBasicPermissionimplies.res = ReflectPermissionExBasicPermissionimplies.res - 5; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0106-rt-parent-ReflectPermissionExObjectgetClass/ReflectPermissionExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0106-rt-parent-ReflectPermissionExObjectgetClass/ReflectPermissionExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..579324b53e01f67fecc20f4637ebedb6de9dd87c --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0106-rt-parent-ReflectPermissionExObjectgetClass/ReflectPermissionExObjectgetClass.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectPermissionExObjectgetClass.java + * -@TestCaseName: Exception in reflect ReflectPermission: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a ReflectPermission object1 + * -#step2: Call getClass() on Object1 + * -#step3: Confirm that the returned Class is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectPermissionExObjectgetClass.java + * -@ExecuteClass: ReflectPermissionExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.reflect.ReflectPermission; + +public class ReflectPermissionExObjectgetClass { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = reflectPermissionExObjectgetClass1(); + } catch (Exception e) { + ReflectPermissionExObjectgetClass.res = ReflectPermissionExObjectgetClass.res - 20; + } + + if (result == 4 && ReflectPermissionExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + private static int reflectPermissionExObjectgetClass1() throws ClassNotFoundException { + // final Class getClass() + int result1 = 4; /*STATUS_FAILED*/ + String name = "name"; + String actions = null; + ReflectPermission rp = new ReflectPermission(name, actions); + try { + Class cls1 = rp.getClass(); + if (cls1.toString().equals("class java.lang.reflect.ReflectPermission")) { + ReflectPermissionExObjectgetClass.res = ReflectPermissionExObjectgetClass.res - 10; + } + } catch (IllegalMonitorStateException e) { + ReflectPermissionExObjectgetClass.res = ReflectPermissionExObjectgetClass.res - 1; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0107-rt-parent-ReflectPermissionExObjectnotifyAllIllegalMonitorStateException/ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0107-rt-parent-ReflectPermissionExObjectnotifyAllIllegalMonitorStateException/ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..87bc337034c21b304bee3822348bf6a341cbc646 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0107-rt-parent-ReflectPermissionExObjectnotifyAllIllegalMonitorStateException/ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect ReflectPermission: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ReflectPermissionExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.ReflectPermission; + +public class ReflectPermissionExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private String name = "name"; + private String actions = null; + private ReflectPermission rp = new ReflectPermission(name, actions); + + public static void main(String argv[]) { + System.out.println(new ReflectPermissionExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = reflectPermissionExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ReflectPermissionExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int reflectPermissionExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + rp.notifyAll(); + ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ReflectPermissionExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ReflectPermissionExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notifyAll(); + ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0108-rt-parent-ReflectPermissionExObjectnotifyIllegalMonitorStateException/ReflectPermissionExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0108-rt-parent-ReflectPermissionExObjectnotifyIllegalMonitorStateException/ReflectPermissionExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..486bc407af086854f591cd56f4a0fefba4053d63 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0108-rt-parent-ReflectPermissionExObjectnotifyIllegalMonitorStateException/ReflectPermissionExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectPermissionExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect ReflectPermission: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectPermissionExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ReflectPermissionExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.ReflectPermission; + +public class ReflectPermissionExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private String name = "name"; + private String actions = null; + private ReflectPermission rp = new ReflectPermission(name, actions); + + public static void main(String argv[]) { + System.out.println(new ReflectPermissionExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = reflectPermissionExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ReflectPermissionExObjectnotifyIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ReflectPermissionExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ReflectPermissionExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int reflectPermissionExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + rp.notify(); + ReflectPermissionExObjectnotifyIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectnotifyIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ReflectPermissionExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ReflectPermissionExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notify(); + ReflectPermissionExObjectnotifyIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectnotifyIllegalMonitorStateException.res = ReflectPermissionExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0109-rt-parent-ReflectPermissionExObjecttoString/ReflectPermissionExObjecttoString.java b/test/testsuite/ouroboros/parent_test/RT0109-rt-parent-ReflectPermissionExObjecttoString/ReflectPermissionExObjecttoString.java new file mode 100755 index 0000000000000000000000000000000000000000..02c198632a615bb5f41d5813136736dda69fc7c9 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0109-rt-parent-ReflectPermissionExObjecttoString/ReflectPermissionExObjecttoString.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectPermissionExObjecttoString.java + * -@TestCaseName: Exception in reflect ReflectPermission: String toString() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a ReflectPermission object + * -#step2: call method toString() of new Object + * -#step3: Confirm that the return value is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectPermissionExObjecttoString.java + * -@ExecuteClass: ReflectPermissionExObjecttoString + * -@ExecuteArgs: + */ + +import java.lang.reflect.ReflectPermission; + +public class ReflectPermissionExObjecttoString { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = reflectPermissionExObjecttoString1(); + } catch (Exception e) { + ReflectPermissionExObjecttoString.res = ReflectPermissionExObjecttoString.res - 20; + } + + if (result == 4 && ReflectPermissionExObjecttoString.res == 89) { + result = 0; + } + + return result; + } + + private static int reflectPermissionExObjecttoString1() { + int result1 = 4; /*STATUS_FAILED*/ + // String toString() + String name = "name"; + String actions = null; + ReflectPermission rp = new ReflectPermission(name, actions); + try { + String str1 = rp.toString(); + + if (str1.contains("java.lang.reflect.ReflectPermission")) { + ReflectPermissionExObjecttoString.res = ReflectPermissionExObjecttoString.res - 10; + } + } catch (IllegalMonitorStateException e) { + ReflectPermissionExObjecttoString.res = ReflectPermissionExObjecttoString.res - 1; + } + + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0110-rt-parent-ReflectPermissionExObjectwaitIllegalMonitorStateException/ReflectPermissionExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0110-rt-parent-ReflectPermissionExObjectwaitIllegalMonitorStateException/ReflectPermissionExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..ca4d7d8e9a060a06cb6f9ef803f7a65736035991 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0110-rt-parent-ReflectPermissionExObjectwaitIllegalMonitorStateException/ReflectPermissionExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectPermissionExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect ReflectPermission: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectPermissionExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ReflectPermissionExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.ReflectPermission; + +public class ReflectPermissionExObjectwaitIllegalMonitorStateException { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = reflectPermissionExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = reflectPermissionExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = reflectPermissionExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && ReflectPermissionExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int reflectPermissionExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + String name = "name"; + String actions = null; + ReflectPermission rp = new ReflectPermission(name, actions); + try { + rp.wait(); + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int reflectPermissionExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + String name = "name"; + String actions = null; + long millis = 123; + ReflectPermission rp = new ReflectPermission(name, actions); + try { + rp.wait(millis); + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int reflectPermissionExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + String name = "name"; + String actions = null; + long millis = 123; + int nanos = 10; + ReflectPermission rp = new ReflectPermission(name, actions); + try { + rp.wait(millis, nanos); + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectwaitIllegalMonitorStateException.res = ReflectPermissionExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0111-rt-parent-ReflectPermissionExObjectwaitInterruptedException/ReflectPermissionExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0111-rt-parent-ReflectPermissionExObjectwaitInterruptedException/ReflectPermissionExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..20c5db51ae83218d237e6a4f0518092e30b0e0c3 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0111-rt-parent-ReflectPermissionExObjectwaitInterruptedException/ReflectPermissionExObjectwaitInterruptedException.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectPermission/ReflectPermissionExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in reflect ReflectPermission: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectPermissionExObjectwaitInterruptedException.java + * -@ExecuteClass: ReflectPermissionExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.reflect.ReflectPermission; + +public class ReflectPermissionExObjectwaitInterruptedException { + static int res = 99; + private static String name = "name"; + private static String action = null; + private static ReflectPermission RP = new ReflectPermission(name, action); + + public static void main(String argv[]) { + System.out.println(new ReflectPermissionExObjectwaitInterruptedException().run()); + } + + private class ReflectPermissionExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + + private int remainder; + + private ReflectPermissionExObjectwaitInterruptedException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (RP) { + RP.notifyAll(); + try { + RP.wait(); + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class ReflectPermissionExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10000; + + private ReflectPermissionExObjectwaitInterruptedException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (RP) { + RP.notifyAll(); + try { + RP.wait(millis); + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class ReflectPermissionExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10000; + int nanos = 100; + + private ReflectPermissionExObjectwaitInterruptedException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (RP) { + RP.notifyAll(); + try { + RP.wait(millis, nanos); + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ReflectPermissionExObjectwaitInterruptedException.res = ReflectPermissionExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ReflectPermissionExObjectwaitInterruptedException.ReflectPermissionExObjectwaitInterruptedException11(1)); + // final void wait(long millis) + Thread t3 = new Thread(new ReflectPermissionExObjectwaitInterruptedException.ReflectPermissionExObjectwaitInterruptedException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ReflectPermissionExObjectwaitInterruptedException.ReflectPermissionExObjectwaitInterruptedException31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t1.interrupt(); + sleep(100); + t3.start(); + sleep(100); + t3.interrupt(); + sleep(100); + t5.start(); + sleep(100); + t5.interrupt(); + sleep(100); + + if (result == 2 && ReflectPermissionExObjectwaitInterruptedException.res == 96) { + result = 0; + } + + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0112-rt-parent-ReflectPermissionExObjectwait/ReflectPermissionExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0112-rt-parent-ReflectPermissionExObjectwait/ReflectPermissionExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..41fe2da5d7ec54722e7b81c2bac1311b575fc779 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0112-rt-parent-ReflectPermissionExObjectwait/ReflectPermissionExObjectwait.java @@ -0,0 +1,205 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectPermissionExObjectwait.java + * -@TestCaseName: Exception in reflect ReflectPermission: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectPermissionExObjectwait.java + * -@ExecuteClass: ReflectPermissionExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.reflect.ReflectPermission; + +public class ReflectPermissionExObjectwait { + static int res = 99; + private String name = "name"; + private String action = null; + private ReflectPermission RP = new ReflectPermission(name, action); + private ReflectPermission RP2 = new ReflectPermission(name, action); + private ReflectPermission RP3 = new ReflectPermission(name, action); + + public static void main(String argv[]) { + System.out.println(new ReflectPermissionExObjectwait().run()); + } + + private class ReflectPermissionExObjectwait11 implements Runnable { + // final void wait() + + private int remainder; + + private ReflectPermissionExObjectwait11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (RP) { + RP.notifyAll(); + try { + RP.wait(); + ReflectPermissionExObjectwait.res = ReflectPermissionExObjectwait.res - 10; + } catch (InterruptedException e1) { + ReflectPermissionExObjectwait.res = ReflectPermissionExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectwait.res = ReflectPermissionExObjectwait.res - 30; + } + } + } + } + + private class ReflectPermissionExObjectwait12 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10; + + private ReflectPermissionExObjectwait12(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (RP2) { + RP2.notifyAll(); + try { + RP2.wait(millis); + ReflectPermissionExObjectwait.res = ReflectPermissionExObjectwait.res - 10; + } catch (InterruptedException e1) { + ReflectPermissionExObjectwait.res = ReflectPermissionExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectwait.res = ReflectPermissionExObjectwait.res - 30; + } + } + } + } + + private class ReflectPermissionExObjectwait13 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10; + int nanos = 10; + + private ReflectPermissionExObjectwait13(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (RP3) { + RP3.notifyAll(); + try { + RP3.wait(millis, nanos); + ReflectPermissionExObjectwait.res = ReflectPermissionExObjectwait.res - 10; + } catch (InterruptedException e1) { + ReflectPermissionExObjectwait.res = ReflectPermissionExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ReflectPermissionExObjectwait.res = ReflectPermissionExObjectwait.res - 30; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + Thread t1 = new Thread(new ReflectPermissionExObjectwait11(1)); + Thread t2 = new Thread(new ReflectPermissionExObjectwait11(2)); + // final void wait(long millis) + Thread t3 = new Thread(new ReflectPermissionExObjectwait12(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ReflectPermissionExObjectwait13(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + try { + t1.join(); + t3.join(); + t5.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 2 && ReflectPermissionExObjectwait.res == 69) { + result = 0; + } + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0113-rt-parent-ReflectPermissionExPermissioncheckGuard/ReflectPermissionExPermissioncheckGuard.java b/test/testsuite/ouroboros/parent_test/RT0113-rt-parent-ReflectPermissionExPermissioncheckGuard/ReflectPermissionExPermissioncheckGuard.java new file mode 100755 index 0000000000000000000000000000000000000000..200a4309bf6aa9fb5c36b59c359bdff1c0d180f5 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0113-rt-parent-ReflectPermissionExPermissioncheckGuard/ReflectPermissionExPermissioncheckGuard.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectPermissionExPermissioncheckGuard.java + * -@TestCaseName: Exception in reflect ReflectPermission: void checkGuard(Object object) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a ReflectPermission object + * -#step2: call method checkGuard(Object object) of new Object + * -#step3: Confirm that execute is correct, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectPermissionExPermissioncheckGuard.java + * -@ExecuteClass: ReflectPermissionExPermissioncheckGuard + * -@ExecuteArgs: + */ + +import java.lang.reflect.ReflectPermission; + +public class ReflectPermissionExPermissioncheckGuard { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = reflectPermissionExPermissioncheckGuard1(); + } catch (Exception e) { + ReflectPermissionExPermissioncheckGuard.res = ReflectPermissionExPermissioncheckGuard.res - 20; + } + + if (result == 4 && ReflectPermissionExPermissioncheckGuard.res == 89) { + result = 0; + } + + return result; + } + + private static int reflectPermissionExPermissioncheckGuard1() { + int result1 = 4; /*STATUS_FAILED*/ + // void checkGuard(Object object) + String name = "name"; + String actions = null; + final Object obj = new Object(); + ReflectPermission rp = new ReflectPermission(name, actions); + try { + rp.checkGuard(obj); + ReflectPermissionExPermissioncheckGuard.res = ReflectPermissionExPermissioncheckGuard.res - 10; + } catch (IllegalMonitorStateException e) { + ReflectPermissionExPermissioncheckGuard.res = ReflectPermissionExPermissioncheckGuard.res - 1; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0114-rt-parent-StringBufferExObjectgetClass/StringBufferExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0114-rt-parent-StringBufferExObjectgetClass/StringBufferExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..5f48c75d862b0803eb64ca79338e86dbf50b1b61 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0114-rt-parent-StringBufferExObjectgetClass/StringBufferExObjectgetClass.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferExObjectgetClass.java + * -@TestCaseName: Exception in String: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a StringBuffer object1 + * -#step2: Call getClass() on Object1 + * -#step3: Confirm that the returned Class is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBufferExObjectgetClass.java + * -@ExecuteClass: StringBufferExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.Class; + +public class StringBufferExObjectgetClass { + static int res = 99; + private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + + public static void main(String argv[]) { + System.out.println(new StringBufferExObjectgetClass().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringBufferExObjectgetClass1(); + } catch (Exception e) { + StringBufferExObjectgetClass.res = StringBufferExObjectgetClass.res - 20; + } + + if (result == 4 && StringBufferExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + + private int stringBufferExObjectgetClass1() { + int result1 = 4; /*STATUS_FAILED*/ + // final Class getClass() + + StringBuffer sb = null; + for (int i = 0; i < stringArray.length; i++) { + sb = new StringBuffer(stringArray[i]); + } + Class px1 = sb.getClass(); + if (px1.toString().equals("class java.lang.StringBuffer")) { + StringBufferExObjectgetClass.res = StringBufferExObjectgetClass.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0115-rt-parent-StringBufferExObjecthashCode/StringBufferExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0115-rt-parent-StringBufferExObjecthashCode/StringBufferExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..19cd0709d408b6df0370955ad2ccd064fafeea54 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0115-rt-parent-StringBufferExObjecthashCode/StringBufferExObjecthashCode.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferExObjecthashCode.java + * -@TestCaseName: Exception in StringBuffer: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create Object1 by new StringBuffer(String name) + * -#step2: Create Object2 is given by Object2, Object3 by new StringBuffer(String name) + * -#step3: Check hashCode of the Object1 and Object2 is equal, check hashCode of the Object1 and Object3 is not equal. + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBufferExObjecthashCode.java + * -@ExecuteClass: StringBufferExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.StringBuffer; + +public class StringBufferExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new StringBufferExObjecthashCode().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringBufferExObjecthashCode1(); + } catch (Exception e) { + StringBufferExObjecthashCode.res = StringBufferExObjecthashCode.res - 20; + } + + if (result == 4 && StringBufferExObjecthashCode.res == 89) { + result = 0; + } + return result; + } + + + private int stringBufferExObjecthashCode1() { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + StringBuffer sb1 = new StringBuffer("aa"); + StringBuffer sb2 = sb1; + StringBuffer sb3 = new StringBuffer("╬の〆"); + + if (sb1.hashCode() == sb2.hashCode() && sb1.hashCode() != sb3.hashCode()) { + StringBufferExObjecthashCode.res = StringBufferExObjecthashCode.res - 10; + } else { + StringBufferExObjecthashCode.res = StringBufferExObjecthashCode.res - 5; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0116-rt-parent-StringBufferExObjectnotifyAllIllegalMonitorStateException/StringBufferExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0116-rt-parent-StringBufferExObjectnotifyAllIllegalMonitorStateException/StringBufferExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..859b107933af43974e759738b9ca0c85e734a447 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0116-rt-parent-StringBufferExObjectnotifyAllIllegalMonitorStateException/StringBufferExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in StringBuffer: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBufferExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: StringBufferExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.StringBuffer; + +public class StringBufferExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuffer sb = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + sb = new StringBuffer(stringArray[i]); + } + System.out.println(new StringBufferExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringBufferExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + StringBufferExObjectnotifyAllIllegalMonitorStateException.res = StringBufferExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new StringBufferExObjectnotifyAllIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && StringBufferExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int stringBufferExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + sb.notifyAll(); + StringBufferExObjectnotifyAllIllegalMonitorStateException.res = StringBufferExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectnotifyAllIllegalMonitorStateException.res = StringBufferExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class StringBufferExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + try { + sb.notifyAll(); + StringBufferExObjectnotifyAllIllegalMonitorStateException.res = StringBufferExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectnotifyAllIllegalMonitorStateException.res = StringBufferExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0117-rt-parent-StringBufferExObjectnotifyIllegalMonitorStateException/StringBufferExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0117-rt-parent-StringBufferExObjectnotifyIllegalMonitorStateException/StringBufferExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..236d0a7ddb2d9fe1cb8d28b8beede5190446bcdb --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0117-rt-parent-StringBufferExObjectnotifyIllegalMonitorStateException/StringBufferExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in StringBuffer: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBufferExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: StringBufferExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.StringBuffer; + +public class StringBufferExObjectnotifyIllegalMonitorStateException { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuffer sb = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + sb = new StringBuffer(stringArray[i]); + } + System.out.println(new StringBufferExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringBufferExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + StringBufferExObjectnotifyIllegalMonitorStateException.res = StringBufferExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new StringBufferExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && StringBufferExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int stringBufferExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + sb.notify(); + StringBufferExObjectnotifyIllegalMonitorStateException.res = StringBufferExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectnotifyIllegalMonitorStateException.res = StringBufferExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class StringBufferExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + try { + sb.notify(); + StringBufferExObjectnotifyIllegalMonitorStateException.res = StringBufferExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectnotifyIllegalMonitorStateException.res = StringBufferExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0118-rt-parent-StringBufferExObjectwaitIllegalArgumentException/StringBufferExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0118-rt-parent-StringBufferExObjectwaitIllegalArgumentException/StringBufferExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..eb3c40c2c58e7ae93a093627791a1215ca588a30 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0118-rt-parent-StringBufferExObjectwaitIllegalArgumentException/StringBufferExObjectwaitIllegalArgumentException.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in StringBuffer: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBufferExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: StringBufferExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.StringBuffer; + +public class StringBufferExObjectwaitIllegalArgumentException { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuffer mf2 = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + mf2 = new StringBuffer(stringArray[i]); + } + System.out.println(new StringBufferExObjectwaitIllegalArgumentException().run()); + } + + private class StringBufferExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + long millis = -1; + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis); + StringBufferExObjectwaitIllegalArgumentException.res = StringBufferExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + StringBufferExObjectwaitIllegalArgumentException.res = StringBufferExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectwaitIllegalArgumentException.res = StringBufferExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + StringBufferExObjectwaitIllegalArgumentException.res = StringBufferExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class StringBufferExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // final void wait(long millis, int nanos) + long millis = -2; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis, nanos); + StringBufferExObjectwaitIllegalArgumentException.res = StringBufferExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + StringBufferExObjectwaitIllegalArgumentException.res = StringBufferExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectwaitIllegalArgumentException.res = StringBufferExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + StringBufferExObjectwaitIllegalArgumentException.res = StringBufferExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new StringBufferExObjectwaitIllegalArgumentException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new StringBufferExObjectwaitIllegalArgumentException31()); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && StringBufferExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0119-rt-parent-StringBufferExObjectwaitIllegalMonitorStateException/StringBufferExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0119-rt-parent-StringBufferExObjectwaitIllegalMonitorStateException/StringBufferExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..fc92b720a00f3ec20dad00f11d037b0d11cbd221 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0119-rt-parent-StringBufferExObjectwaitIllegalMonitorStateException/StringBufferExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in StringBuffer: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBufferExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: StringBufferExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.StringBuffer; + +public class StringBufferExObjectwaitIllegalMonitorStateException { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuffer mf2 = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + mf2 = new StringBuffer(stringArray[i]); + } + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = stringBufferExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = stringBufferExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = stringBufferExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && StringBufferExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int stringBufferExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + mf2.wait(); + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int stringBufferExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + mf2.wait(millis); + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int stringBufferExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + mf2.wait(millis, nanos); + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectwaitIllegalMonitorStateException.res = StringBufferExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0120-rt-parent-StringBufferExObjectwait/StringBufferExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0120-rt-parent-StringBufferExObjectwait/StringBufferExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..fc5df2b345072b0b19e7c76228904ec83a509864 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0120-rt-parent-StringBufferExObjectwait/StringBufferExObjectwait.java @@ -0,0 +1,209 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferExObjectwait.java + * -@TestCaseName: Exception in StringBuffer: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBufferExObjectwait.java + * -@ExecuteClass: StringBufferExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.StringBuffer; + +public class StringBufferExObjectwait { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuffer sb = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + sb = new StringBuffer(stringArray[i]); + } + System.out.println(new StringBufferExObjectwait().run()); + } + + private class StringBufferExObjectwait11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + sb.notifyAll(); + try { + sb.wait(); + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 15; + } catch (InterruptedException e1) { + // System.out.println("111"); + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + System.out.println("222"); + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 10; + } + } + } + } + + private class StringBufferExObjectwait21 implements Runnable { + // final void wait(long millis) + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + sb.notify(); + try { + sb.wait(millis); + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 15; + } catch (InterruptedException e1) { + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 5; + } + } + } + } + + private class StringBufferExObjectwait31 implements Runnable { + // final void wait(long millis, int nanos) + + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + sb.notifyAll(); + try { + sb.wait(millis, nanos); + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 15; + } catch (InterruptedException e1) { + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + StringBufferExObjectwait.res = StringBufferExObjectwait.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * join fun + * @param thread wait join thread + */ + private void waitFinish(Thread thread) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new StringBufferExObjectwait11()); + Thread t2 = new Thread(new StringBufferExObjectwait11()); + // final void wait(long millis) + Thread t3 = new Thread(new StringBufferExObjectwait21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new StringBufferExObjectwait31()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + t1.interrupt(); + + waitFinish(t1); + waitFinish(t3); + waitFinish(t5); + + if (result == 2 && StringBufferExObjectwait.res == 54) { + result = 0; + } + + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0121-rt-parent-StringBuilderExObjectgetClass/StringBuilderExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0121-rt-parent-StringBuilderExObjectgetClass/StringBuilderExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..a8ce960eb23a5dc78c02a64a2c819541481358aa --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0121-rt-parent-StringBuilderExObjectgetClass/StringBuilderExObjectgetClass.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderExObjectgetClass.java + * -@TestCaseName: Exception in StringBuilder: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a StringBuilder object1 + * -#step2: Call getClass() on Object1 + * -#step3: Confirm that the returned Class is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBuilderExObjectgetClass.java + * -@ExecuteClass: StringBuilderExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.String; + +public class StringBuilderExObjectgetClass { + static int res = 99; + private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + + public static void main(String argv[]) { + System.out.println(new StringBuilderExObjectgetClass().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringBuilderExObjectgetClass1(); + } catch (Exception e) { + StringBuilderExObjectgetClass.res = StringBuilderExObjectgetClass.res - 20; + } + + if (result == 4 && StringBuilderExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + + private int stringBuilderExObjectgetClass1() { + int result1 = 4; /*STATUS_FAILED*/ + // final Class getClass() + + StringBuilder sb = null; + for (int i = 0; i < stringArray.length; i++) { + sb = new StringBuilder(stringArray[i]); + } + Class px1 = sb.getClass(); + + if (px1.toString().equals("class java.lang.StringBuilder")) { + StringBuilderExObjectgetClass.res = StringBuilderExObjectgetClass.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0122-rt-parent-StringBuilderExObjecthashCode/StringBuilderExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0122-rt-parent-StringBuilderExObjecthashCode/StringBuilderExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..62b78365a1e31722ab3ad2f9fc0bdf16609d0cce --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0122-rt-parent-StringBuilderExObjecthashCode/StringBuilderExObjecthashCode.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderExObjecthashCode.java + * -@TestCaseName: Exception in StringBuilder: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create Object1 by new StringBuilder(String name) + * -#step2: Create Object2 is given by Object2, Object3 by new StringBuilder(String name) + * -#step3: Check hashCode of the Object1 and Object2 is equal, check hashCode of the Object1 and Object3 is not equal. + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBuilderExObjecthashCode.java + * -@ExecuteClass: StringBuilderExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.StringBuilder; + +public class StringBuilderExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new StringBuilderExObjecthashCode().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringBuilderExObjecthashCode1(); + } catch (Exception e) { + StringBuilderExObjecthashCode.res = StringBuilderExObjecthashCode.res - 20; + } + + if (result == 4 && StringBuilderExObjecthashCode.res == 89) { + result = 0; + } + + return result; + } + + + private int stringBuilderExObjecthashCode1() { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + + StringBuilder sb1 = new StringBuilder("aa"); + StringBuilder sb2 = sb1; + StringBuilder sb3 = new StringBuilder("╬の〆"); + + if (sb1.hashCode() == sb2.hashCode() && sb1.hashCode() != sb3.hashCode()) { + StringBuilderExObjecthashCode.res = StringBuilderExObjecthashCode.res - 10; + } else { + StringBuilderExObjecthashCode.res = StringBuilderExObjecthashCode.res - 5; + } + return result1; + } +} + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0123-rt-parent-StringBuilderExObjectnotifyAllIllegalMonitorStateException/StringBuilderExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0123-rt-parent-StringBuilderExObjectnotifyAllIllegalMonitorStateException/StringBuilderExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..d558e0679e6b5712be86a4f2cce10630bd352ef2 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0123-rt-parent-StringBuilderExObjectnotifyAllIllegalMonitorStateException/StringBuilderExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in StringBuilder: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBuilderExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: StringBuilderExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.StringBuilder; + +public class StringBuilderExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuilder sb = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + sb = new StringBuilder(stringArray[i]); + } + System.out.println(new StringBuilderExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringBuilderExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + StringBuilderExObjectnotifyAllIllegalMonitorStateException.res = StringBuilderExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new StringBuilderExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && StringBuilderExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int stringBuilderExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + sb.notifyAll(); + StringBuilderExObjectnotifyAllIllegalMonitorStateException.res = StringBuilderExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectnotifyAllIllegalMonitorStateException.res = StringBuilderExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class StringBuilderExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private StringBuilderExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + try { + sb.notifyAll(); + StringBuilderExObjectnotifyAllIllegalMonitorStateException.res = StringBuilderExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectnotifyAllIllegalMonitorStateException.res = StringBuilderExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0124-rt-parent-StringBuilderExObjectnotifyIllegalMonitorStateException/StringBuilderExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0124-rt-parent-StringBuilderExObjectnotifyIllegalMonitorStateException/StringBuilderExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..85dc9be5f05cd3614d2f1132ee45b09a8d81122b --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0124-rt-parent-StringBuilderExObjectnotifyIllegalMonitorStateException/StringBuilderExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in StringBuilder: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBuilderExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: StringBuilderExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.StringBuilder; + +public class StringBuilderExObjectnotifyIllegalMonitorStateException { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuilder sb = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + sb = new StringBuilder(stringArray[i]); + } + System.out.println(new StringBuilderExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringBuilderExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + StringBuilderExObjectnotifyIllegalMonitorStateException.res = StringBuilderExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new StringBuilderExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && StringBuilderExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int stringBuilderExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + sb.notify(); + StringBuilderExObjectnotifyIllegalMonitorStateException.res = StringBuilderExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectnotifyIllegalMonitorStateException.res = StringBuilderExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class StringBuilderExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private StringBuilderExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + try { + sb.notify(); + StringBuilderExObjectnotifyIllegalMonitorStateException.res = StringBuilderExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectnotifyIllegalMonitorStateException.res = StringBuilderExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0125-rt-parent-StringBuilderExObjectwaitIllegalArgumentException/StringBuilderExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0125-rt-parent-StringBuilderExObjectwaitIllegalArgumentException/StringBuilderExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..440c297d22a50213717c02f4c7523dd31a8aafe8 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0125-rt-parent-StringBuilderExObjectwaitIllegalArgumentException/StringBuilderExObjectwaitIllegalArgumentException.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in StringBuilder: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBuilderExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: StringBuilderExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.StringBuilder; + +public class StringBuilderExObjectwaitIllegalArgumentException { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuilder mf2 = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + mf2 = new StringBuilder(stringArray[i]); + } + System.out.println(new StringBuilderExObjectwaitIllegalArgumentException().run()); + } + + private class StringBuilderExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + private int remainder; + long millis = -1; + + private StringBuilderExObjectwaitIllegalArgumentException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis); + StringBuilderExObjectwaitIllegalArgumentException.res = StringBuilderExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + StringBuilderExObjectwaitIllegalArgumentException.res = StringBuilderExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectwaitIllegalArgumentException.res = StringBuilderExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + StringBuilderExObjectwaitIllegalArgumentException.res = StringBuilderExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class StringBuilderExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // final void wait(long millis, int nanos) + + private int remainder; + long millis = -2; + int nanos = 10; + + private StringBuilderExObjectwaitIllegalArgumentException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis, nanos); + StringBuilderExObjectwaitIllegalArgumentException.res = StringBuilderExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + StringBuilderExObjectwaitIllegalArgumentException.res = StringBuilderExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectwaitIllegalArgumentException.res = StringBuilderExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + StringBuilderExObjectwaitIllegalArgumentException.res = StringBuilderExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new StringBuilderExObjectwaitIllegalArgumentException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new StringBuilderExObjectwaitIllegalArgumentException31(5)); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && StringBuilderExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0126-rt-parent-StringBuilderExObjectwaitIllegalMonitorStateException/StringBuilderExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0126-rt-parent-StringBuilderExObjectwaitIllegalMonitorStateException/StringBuilderExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..29372bbc3cb3092688e68c680faf7fdf3061651b --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0126-rt-parent-StringBuilderExObjectwaitIllegalMonitorStateException/StringBuilderExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in StringBuilder: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBuilderExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: StringBuilderExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.StringBuilder; + +public class StringBuilderExObjectwaitIllegalMonitorStateException { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuilder mf2 = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + mf2 = new StringBuilder(stringArray[i]); + } + System.out.println(run()); + } + + /** + * main test fun + * + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = stringBuilderExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = stringBuilderExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = stringBuilderExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && StringBuilderExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int stringBuilderExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + mf2.wait(); + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int stringBuilderExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + mf2.wait(millis); + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int stringBuilderExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + mf2.wait(millis, nanos); + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectwaitIllegalMonitorStateException.res = StringBuilderExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0127-rt-parent-StringBuilderExObjectwait/StringBuilderExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0127-rt-parent-StringBuilderExObjectwait/StringBuilderExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..b195b3b61a11dde604fa0736131d8b13ca228d27 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0127-rt-parent-StringBuilderExObjectwait/StringBuilderExObjectwait.java @@ -0,0 +1,225 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderExObjectwait.java + * -@TestCaseName: Exception in StringBuilder: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: StringBuilderExObjectwait.java + * -@ExecuteClass: StringBuilderExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.StringBuilder; + +public class StringBuilderExObjectwait { + static int res = 99; + static private String[] stringArray = { + "", "a", "b", "c", "ab", "ac", "abc", "aaaabbbccc" + }; + static private StringBuilder sb = null; + + public static void main(String argv[]) { + for (int i = 0; i < stringArray.length; i++) { + sb = new StringBuilder(stringArray[i]); + } + System.out.println(new StringBuilderExObjectwait().run()); + } + + private class StringBuilderExObjectwait11 implements Runnable { + // final void wait() + private int remainder; + + private StringBuilderExObjectwait11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + sb.notifyAll(); + try { + sb.wait(); + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 15; + } catch (InterruptedException e1) { + // System.out.println("111"); + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + // System.out.println("222"); + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 10; + } + } + } + } + + private class StringBuilderExObjectwait21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10; + + private StringBuilderExObjectwait21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + sb.notify(); + try { + sb.wait(millis); + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 15; + } catch (InterruptedException e1) { + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 5; + } + } + } + } + + private class StringBuilderExObjectwait31 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10; + int nanos = 10; + + private StringBuilderExObjectwait31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + sb.notifyAll(); + try { + sb.wait(millis, nanos); + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 15; + } catch (InterruptedException e1) { + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + StringBuilderExObjectwait.res = StringBuilderExObjectwait.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * join fun + * @param thread wait join thread + */ + private void waitFinish(Thread thread) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new StringBuilderExObjectwait11(1)); + Thread t2 = new Thread(new StringBuilderExObjectwait11(2)); + // final void wait(long millis) + Thread t3 = new Thread(new StringBuilderExObjectwait21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new StringBuilderExObjectwait31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t3.start(); + sleep(100); + t5.start(); + sleep(100); + t2.start(); + t1.interrupt(); + + waitFinish(t1); + waitFinish(t3); + waitFinish(t5); + + + if (result == 2 && StringBuilderExObjectwait.res == 54) { + result = 0; + } + + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0128-rt-parent-StringExObjectgetClass/StringExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0128-rt-parent-StringExObjectgetClass/StringExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..40dbf38a3265da60536bb99229b82067b07df094 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0128-rt-parent-StringExObjectgetClass/StringExObjectgetClass.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringExObjectgetClass.java + * -@TestCaseName: Exception in String: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a String object1 + * -#step2: Call getClass() on Object1 + * -#step3: Confirm that the returned Class is correct + * -@Expect:0\n + * -@Priority: High + * -@Source: StringExObjectgetClass.java + * -@ExecuteClass: StringExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.Class; + +public class StringExObjectgetClass { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new StringExObjectgetClass().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringExObjectgetClass1(); + } catch (Exception e) { + StringExObjectgetClass.res = StringExObjectgetClass.res - 20; + } + + if (result == 4 && StringExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + + private int stringExObjectgetClass1() { + // final Class getClass() + int result1 = 4; /*STATUS_FAILED*/ + String tr2 = "this is a test"; + Class cls1 = tr2.getClass(); + + if (cls1.toString().equals("class java.lang.String")) { + StringExObjectgetClass.res = StringExObjectgetClass.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0129-rt-parent-StringExObjectnotifyAllIllegalMonitorStateException/StringExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0129-rt-parent-StringExObjectnotifyAllIllegalMonitorStateException/StringExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..6aef0f3f4192f018bf493fd53c36aedf159caff8 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0129-rt-parent-StringExObjectnotifyAllIllegalMonitorStateException/StringExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in String: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: StringExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: StringExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class StringExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + String mf2 = "this is a test"; + + public static void main(String argv[]) { + System.out.println(new StringExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + StringExObjectnotifyAllIllegalMonitorStateException.res = StringExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new StringExObjectnotifyAllIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && StringExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int stringExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + mf2.notifyAll(); + StringExObjectnotifyAllIllegalMonitorStateException.res = StringExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + StringExObjectnotifyAllIllegalMonitorStateException.res = StringExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class StringExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + try { + mf2.notifyAll(); + StringExObjectnotifyAllIllegalMonitorStateException.res = StringExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + StringExObjectnotifyAllIllegalMonitorStateException.res = StringExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0130-rt-parent-StringExObjectnotifyIllegalMonitorStateException/StringExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0130-rt-parent-StringExObjectnotifyIllegalMonitorStateException/StringExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..01ac55ff2a1de35d97ad4ed2803528fec157c071 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0130-rt-parent-StringExObjectnotifyIllegalMonitorStateException/StringExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in String: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: StringExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: StringExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class StringExObjectnotifyIllegalMonitorStateException { + static int res = 99; + String mf2 = "this is a test"; + + public static void main(String argv[]) { + System.out.println(new StringExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = stringExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + StringExObjectnotifyIllegalMonitorStateException.res = StringExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new StringExObjectnotifyIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && StringExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int stringExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + mf2.notify(); + StringExObjectnotifyIllegalMonitorStateException.res = StringExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + StringExObjectnotifyIllegalMonitorStateException.res = StringExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class StringExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + try { + mf2.notify(); + StringExObjectnotifyIllegalMonitorStateException.res = StringExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + StringExObjectnotifyIllegalMonitorStateException.res = StringExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0131-rt-parent-StringExObjectwaitIllegalArgumentException/StringExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0131-rt-parent-StringExObjectwaitIllegalArgumentException/StringExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..579c35d1913a37dd972acbeed0764f9f0b7ec3f7 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0131-rt-parent-StringExObjectwaitIllegalArgumentException/StringExObjectwaitIllegalArgumentException.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in String: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: StringExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: StringExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class StringExObjectwaitIllegalArgumentException { + static int res = 99; + private static String mf2 = "this is a test"; + + public static void main(String argv[]) { + System.out.println(new StringExObjectwaitIllegalArgumentException().run()); + } + + private class StringExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + long millis = -1; + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis); + StringExObjectwaitIllegalArgumentException.res = StringExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + StringExObjectwaitIllegalArgumentException.res = StringExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + StringExObjectwaitIllegalArgumentException.res = StringExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + StringExObjectwaitIllegalArgumentException.res = StringExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class StringExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // + // final void wait(long millis, int nanos) + long millis = -2; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis, nanos); + StringExObjectwaitIllegalArgumentException.res = StringExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + StringExObjectwaitIllegalArgumentException.res = StringExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + StringExObjectwaitIllegalArgumentException.res = StringExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + StringExObjectwaitIllegalArgumentException.res = StringExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new StringExObjectwaitIllegalArgumentException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new StringExObjectwaitIllegalArgumentException31()); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && StringExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0132-rt-parent-StringExObjectwaitIllegalMonitorStateException/StringExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0132-rt-parent-StringExObjectwaitIllegalMonitorStateException/StringExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..74886fb0bd5a5fcf436635fde918619df1319a50 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0132-rt-parent-StringExObjectwaitIllegalMonitorStateException/StringExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in String: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: StringExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: StringExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class StringExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static String mf2 = "this is a test"; + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = stringExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = stringExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = stringExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && StringExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int stringExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + mf2.wait(); + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int stringExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + mf2.wait(millis); + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } + + private static int stringExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + mf2.wait(millis, nanos); + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + StringExObjectwaitIllegalMonitorStateException.res = StringExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0133-rt-parent-StringExObjectwait/StringExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0133-rt-parent-StringExObjectwait/StringExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..1f97514cbbbbb347c8af4ec85276a4cd8c965764 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0133-rt-parent-StringExObjectwait/StringExObjectwait.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringExObjectwait.java + * -@TestCaseName: Exception in String: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: StringExObjectwait.java + * -@ExecuteClass: StringExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class StringExObjectwait { + static int res = 99; + private String mf2 = "this is a test"; + static Thread t2; + + public static void main(String argv[]) { + System.out.println(new StringExObjectwait().run()); + t2.interrupt(); + } + + private class StringExObjectwait11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(); + StringExObjectwait.res = StringExObjectwait.res - 15; + } catch (InterruptedException e1) { + StringExObjectwait.res = StringExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + StringExObjectwait.res = StringExObjectwait.res - 10; + } + } + } + } + + private class StringExObjectwait21 implements Runnable { + // final void wait(long millis) + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notify(); + try { + mf2.wait(millis); + StringExObjectwait.res = StringExObjectwait.res - 15; + } catch (InterruptedException e1) { + StringExObjectwait.res = StringExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + StringExObjectwait.res = StringExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + StringExObjectwait.res = StringExObjectwait.res - 5; + } + } + } + } + + private class StringExObjectwait31 implements Runnable { + // final void wait(long millis, int nanos) + + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis, nanos); + StringExObjectwait.res = StringExObjectwait.res - 15; + } catch (InterruptedException e1) { + StringExObjectwait.res = StringExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + StringExObjectwait.res = StringExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + StringExObjectwait.res = StringExObjectwait.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * join fun + * @param thread wait join thread + */ + private void waitFinish(Thread thread) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + + // check api normal + // final void wait() + Thread t1 = new Thread(new StringExObjectwait11()); + t2 = new Thread(new StringExObjectwait11()); + // final void wait(long millis) + Thread t3 = new Thread(new StringExObjectwait21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new StringExObjectwait31()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + t1.interrupt(); + + waitFinish(t1); + waitFinish(t3); + waitFinish(t5); + + if (result == 2 && StringExObjectwait.res == 54) { + result = 0; + } + + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0134-rt-parent-ThreadExObjecthashCode/ThreadExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0134-rt-parent-ThreadExObjecthashCode/ThreadExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..4e6f8d0f51899345c280484c34f6af5251007392 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0134-rt-parent-ThreadExObjecthashCode/ThreadExObjecthashCode.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadExObjecthashCode.java + * -@TestCaseName: Exception in Thread: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create Object1 by new Thread() + * -#step2: Create Object2 is given by Object2, Object3 by new Thread() + * -#step3: Check hashCode of the Object1 and Object2 is equal, check hashCode of the Object1 and Object3 is not equal. + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadExObjecthashCode.java + * -@ExecuteClass: ThreadExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ThreadExObjecthashCode().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadExObjecthashCode1(); + } catch (Exception e) { + ThreadExObjecthashCode.res = ThreadExObjecthashCode.res - 20; + } + if (result == 4 && ThreadExObjecthashCode.res == 89) { + result = 0; + } + + return result; + } + + + private int threadExObjecthashCode1() { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + + Thread thr1 = new Thread(); + Thread thr2 = thr1; + Thread thr3 = new Thread(); + thr1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + thr2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + thr3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + + if (thr1.hashCode() == thr2.hashCode() && thr1.hashCode() != thr3.hashCode()) { + ThreadExObjecthashCode.res = ThreadExObjecthashCode.res - 10; + } else { + ThreadExObjecthashCode.res = ThreadExObjecthashCode.res - 5; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0135-rt-parent-ThreadExObjectnotifyAllIllegalMonitorStateException/ThreadExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0135-rt-parent-ThreadExObjectnotifyAllIllegalMonitorStateException/ThreadExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..eb7eb64f940f44e4afed02ae091ecf8d600ab2a7 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0135-rt-parent-ThreadExObjectnotifyAllIllegalMonitorStateException/ThreadExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in Thread: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ThreadExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + Thread sb = new Thread(); + + public static void main(String argv[]) { + System.out.println(new ThreadExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ThreadExObjectnotifyAllIllegalMonitorStateException.res = ThreadExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ThreadExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + sb.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ThreadExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int threadExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + sb.notifyAll(); + ThreadExObjectnotifyAllIllegalMonitorStateException.res = ThreadExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectnotifyAllIllegalMonitorStateException.res = ThreadExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + return result1; + } + + private class ThreadExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ThreadExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + try { + sb.notifyAll(); + ThreadExObjectnotifyAllIllegalMonitorStateException.res = ThreadExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectnotifyAllIllegalMonitorStateException.res = ThreadExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0136-rt-parent-ThreadExObjectnotifyIllegalMonitorStateException/ThreadExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0136-rt-parent-ThreadExObjectnotifyIllegalMonitorStateException/ThreadExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..0dc2b84a718aa4931d66bafa623e669066ab5b55 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0136-rt-parent-ThreadExObjectnotifyIllegalMonitorStateException/ThreadExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in Thread: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notify() inside run + * -#step2: Call the run of the use case, execute method 1, and call notify() in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ThreadExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadExObjectnotifyIllegalMonitorStateException { + static int res = 99; + Thread sb = new Thread(); + + public static void main(String argv[]) { + System.out.println(new ThreadExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ThreadExObjectnotifyIllegalMonitorStateException.res = ThreadExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ThreadExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + sb.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && ThreadExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int threadExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + sb.notify(); + ThreadExObjectnotifyIllegalMonitorStateException.res = ThreadExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectnotifyIllegalMonitorStateException.res = ThreadExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ThreadExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ThreadExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + try { + sb.notify(); + ThreadExObjectnotifyIllegalMonitorStateException.res = ThreadExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectnotifyIllegalMonitorStateException.res = ThreadExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0137-rt-parent-ThreadExObjectwaitIllegalArgumentException/ThreadExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0137-rt-parent-ThreadExObjectwaitIllegalArgumentException/ThreadExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..3bb0c039489d4c095ab2d51b9de185753c81dbae --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0137-rt-parent-ThreadExObjectwaitIllegalArgumentException/ThreadExObjectwaitIllegalArgumentException.java @@ -0,0 +1,160 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in Thread: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: ThreadExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadExObjectwaitIllegalArgumentException { + static int res = 99; + private Thread mf2 = new Thread(); + + public static void main(String argv[]) { + System.out.println(new ThreadExObjectwaitIllegalArgumentException().run()); + } + + private class ThreadExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + private int remainder; + long millis = -1; + + private ThreadExObjectwaitIllegalArgumentException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis); + ThreadExObjectwaitIllegalArgumentException.res = ThreadExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ThreadExObjectwaitIllegalArgumentException.res = ThreadExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectwaitIllegalArgumentException.res = ThreadExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadExObjectwaitIllegalArgumentException.res = ThreadExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class ThreadExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // + // final void wait(long millis, int nanos) + + private int remainder; + long millis = -2; + int nanos = 10; + + private ThreadExObjectwaitIllegalArgumentException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis, nanos); + ThreadExObjectwaitIllegalArgumentException.res = ThreadExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ThreadExObjectwaitIllegalArgumentException.res = ThreadExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectwaitIllegalArgumentException.res = ThreadExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadExObjectwaitIllegalArgumentException.res = ThreadExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new ThreadExObjectwaitIllegalArgumentException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ThreadExObjectwaitIllegalArgumentException31(5)); + mf2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && ThreadExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0138-rt-parent-ThreadExObjectwaitIllegalMonitorStateException/ThreadExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0138-rt-parent-ThreadExObjectwaitIllegalMonitorStateException/ThreadExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..ceb1da0365c428e42b625ea6cb184b035ff46a1c --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0138-rt-parent-ThreadExObjectwaitIllegalMonitorStateException/ThreadExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in Thread: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ThreadExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadExObjectwaitIllegalMonitorStateException { + static int res = 99; + static Thread mf2 = new Thread(); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + mf2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + // final void wait() + try { + result = threadExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = threadExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = threadExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && ThreadExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int threadExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + mf2.wait(); + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int threadExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + mf2.wait(millis); + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int threadExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + mf2.wait(millis, nanos); + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectwaitIllegalMonitorStateException.res = ThreadExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0139-rt-parent-ThreadExObjectwait/ThreadExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0139-rt-parent-ThreadExObjectwait/ThreadExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..78212812fd2be759ae8c591bf0d29005b25f46ad --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0139-rt-parent-ThreadExObjectwait/ThreadExObjectwait.java @@ -0,0 +1,220 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadExObjectwait.java + * -@TestCaseName: Exception in Thread: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, and call wait (), wait (millis), wait (millis, nanos) + * in run respectively + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: execute the start () method of the private class 2. + * -#step4: execute the start () method of the private class 3. + * -#step5: execute the start () method of the private class 1. + * -#step6: Wait for 2 ~ 4 threads to finish running, confirm that wait ends successfully, no exception is thrown + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadExObjectwait.java + * -@ExecuteClass: ThreadExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadExObjectwait { + static int res = 99; + Thread sb = new Thread(); + + public static void main(String argv[]) { + System.out.println(new ThreadExObjectwait().run()); + } + + private class ThreadExObjectwait11 implements Runnable { + // final void wait() + private int remainder; + + private ThreadExObjectwait11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + sb.notifyAll(); + try { + sb.wait(); + ThreadExObjectwait.res = ThreadExObjectwait.res - 15; + } catch (InterruptedException e1) { + ThreadExObjectwait.res = ThreadExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectwait.res = ThreadExObjectwait.res - 10; + } + } + } + } + + private class ThreadExObjectwait21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10; + + private ThreadExObjectwait21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + sb.notify(); + try { + sb.wait(millis); + ThreadExObjectwait.res = ThreadExObjectwait.res - 15; + } catch (InterruptedException e1) { + ThreadExObjectwait.res = ThreadExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectwait.res = ThreadExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ThreadExObjectwait.res = ThreadExObjectwait.res - 5; + } + } + } + } + + private class ThreadExObjectwait31 implements Runnable { + // final void wait(long millis, int nanos) + private int remainder; + long millis = 10; + int nanos = 10; + + private ThreadExObjectwait31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (sb) { + sb.notifyAll(); + try { + sb.wait(millis, nanos); + ThreadExObjectwait.res = ThreadExObjectwait.res - 15; + } catch (InterruptedException e1) { + ThreadExObjectwait.res = ThreadExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ThreadExObjectwait.res = ThreadExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ThreadExObjectwait.res = ThreadExObjectwait.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private void waitFinish(Thread thread) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private void sbSetUncaught() { + sb.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ThreadExObjectwait11(1)); + Thread t2 = new Thread(new ThreadExObjectwait11(2)); + // final void wait(long millis) + Thread t3 = new Thread(new ThreadExObjectwait21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ThreadExObjectwait31(5)); + sbSetUncaught(); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + t1.interrupt(); + + waitFinish(t1); + waitFinish(t3); + waitFinish(t5); + + if (result == 2 && ThreadExObjectwait.res == 54) { + result = 0; + } + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0140-rt-parent-ThreadGroupExObjectequals/ThreadGroupExObjectequals.java b/test/testsuite/ouroboros/parent_test/RT0140-rt-parent-ThreadGroupExObjectequals/ThreadGroupExObjectequals.java new file mode 100755 index 0000000000000000000000000000000000000000..5496640414af946335952330c76ed2bde83c7ef1 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0140-rt-parent-ThreadGroupExObjectequals/ThreadGroupExObjectequals.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupExObjectequals.java + * -@TestCaseName: Exception in ThreadGroup: boolean equals(Object obj) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Created ThreadGroup Object1 by new ThreadGroup(String name) + * -#step2: Created ThreadGroup Object2 by new ThreadGroup(String name) the same as Object1 + * -#step3: call equals(Object obj), and check the result is correctly. + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadGroupExObjectequals.java + * -@ExecuteClass: ThreadGroupExObjectequals + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadGroupExObjectequals { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ThreadGroupExObjectequals().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadGroupExObjectequals1(); + } catch (Exception e) { + ThreadGroupExObjectequals.res = ThreadGroupExObjectequals.res - 20; + } + + + if (result == 4 && ThreadGroupExObjectequals.res == 89) { + result = 0; + } + + return result; + } + + + private int threadGroupExObjectequals1() { + int result1 = 4; /*STATUS_FAILED*/ + // boolean equals(Object obj) + ThreadGroup gr1 = new ThreadGroup("Thread3251"); + ThreadGroup gr2 = new ThreadGroup("Thread3252"); + boolean ret = gr1.equals(gr2); + if (!ret) { + ThreadGroupExObjectequals.res = ThreadGroupExObjectequals.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0141-rt-parent-ThreadGroupExObjectgetClass/ThreadGroupExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0141-rt-parent-ThreadGroupExObjectgetClass/ThreadGroupExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..fca2c115ba2f515e130a5c81b3d26f4d54807a53 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0141-rt-parent-ThreadGroupExObjectgetClass/ThreadGroupExObjectgetClass.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupExObjectgetClass.java + * -@TestCaseName: Exception in ThreadGroup: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test api getClass extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadGroupExObjectgetClass.java + * -@ExecuteClass: ThreadGroupExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadGroupExObjectgetClass { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ThreadGroupExObjectgetClass().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadGroupExObjectgetClass1(); + } catch (Exception e) { + ThreadGroupExObjectgetClass.res = ThreadGroupExObjectgetClass.res - 20; + } + + if (result == 4 && ThreadGroupExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + + private int threadGroupExObjectgetClass1() { + int result1 = 4; /*STATUS_FAILED*/ + // final Class getClass() + ThreadGroup gr1 = new ThreadGroup("Thread8023"); + Class px1 = gr1.getClass(); + + if (px1.toString().equals("class java.lang.ThreadGroup")) { + ThreadGroupExObjectgetClass.res = ThreadGroupExObjectgetClass.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0142-rt-parent-ThreadGroupExObjecthashCode/ThreadGroupExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0142-rt-parent-ThreadGroupExObjecthashCode/ThreadGroupExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..4e0314e356e118b216cc013d929cfa9573f84628 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0142-rt-parent-ThreadGroupExObjecthashCode/ThreadGroupExObjecthashCode.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupExObjecthashCode.java + * -@TestCaseName: Exception in ThreadGroup: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test api hashCode extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadGroupExObjecthashCode.java + * -@ExecuteClass: ThreadGroupExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.ThreadGroup; + +public class ThreadGroupExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ThreadGroupExObjecthashCode().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadGroupExObjecthashCode1(); + } catch (Exception e) { + ThreadGroupExObjecthashCode.res = ThreadGroupExObjecthashCode.res - 20; + } + + if (result == 4 && ThreadGroupExObjecthashCode.res == 89) { + result = 0; + } + + return result; + } + + private int threadGroupExObjecthashCode1() { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + + ThreadGroup gr1 = new ThreadGroup("Thread8023"); + ThreadGroup gr2 = gr1; + ThreadGroup gr3 = new ThreadGroup("Thread1988"); + + if (gr1.hashCode() == gr2.hashCode() && gr1.hashCode() != gr3.hashCode()) { + ThreadGroupExObjecthashCode.res = ThreadGroupExObjecthashCode.res - 10; + } else { + ThreadGroupExObjecthashCode.res = ThreadGroupExObjecthashCode.res - 5; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0143-rt-parent-ThreadGroupExObjectnotifyAllIllegalMonitorStateException/ThreadGroupExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0143-rt-parent-ThreadGroupExObjectnotifyAllIllegalMonitorStateException/ThreadGroupExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..2146abd966889e189c8b78219ceee6acc856a27e --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0143-rt-parent-ThreadGroupExObjectnotifyAllIllegalMonitorStateException/ThreadGroupExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in ThreadGroup: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test api notifyAll extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadGroupExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ThreadGroupExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadGroupExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + ThreadGroup gr1 = new ThreadGroup("Thread8023"); + + public static void main(String argv[]) { + System.out.println(new ThreadGroupExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadGroupExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res = ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ThreadGroupExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int threadGroupExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + gr1.notifyAll(); + ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res = ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res = ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ThreadGroupExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ThreadGroupExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (gr1) { + try { + gr1.notifyAll(); + ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res = ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res = ThreadGroupExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0144-rt-parent-ThreadGroupExObjectnotifyIllegalMonitorStateException/ThreadGroupExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0144-rt-parent-ThreadGroupExObjectnotifyIllegalMonitorStateException/ThreadGroupExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..e59a30ea741dfec49b700cd68ac55b3eff9b1a99 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0144-rt-parent-ThreadGroupExObjectnotifyIllegalMonitorStateException/ThreadGroupExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in ThreadGroup: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test api notify extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadGroupExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ThreadGroupExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadGroupExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private ThreadGroup gr1 = new ThreadGroup("Thread8023"); + + public static void main(String argv[]) { + System.out.println(new ThreadGroupExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadGroupExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ThreadGroupExObjectnotifyIllegalMonitorStateException.res = ThreadGroupExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ThreadGroupExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ThreadGroupExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int threadGroupExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + gr1.notify(); + ThreadGroupExObjectnotifyIllegalMonitorStateException.res = ThreadGroupExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectnotifyIllegalMonitorStateException.res = ThreadGroupExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ThreadGroupExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ThreadGroupExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (gr1) { + try { + gr1.notify(); + ThreadGroupExObjectnotifyIllegalMonitorStateException.res = ThreadGroupExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectnotifyIllegalMonitorStateException.res = ThreadGroupExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0145-rt-parent-ThreadGroupExObjecttoString/ThreadGroupExObjecttoString.java b/test/testsuite/ouroboros/parent_test/RT0145-rt-parent-ThreadGroupExObjecttoString/ThreadGroupExObjecttoString.java new file mode 100755 index 0000000000000000000000000000000000000000..8680cb4e80df8d9cd8279cce868d99e40c53e750 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0145-rt-parent-ThreadGroupExObjecttoString/ThreadGroupExObjecttoString.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupExObjecttoString.java + * -@TestCaseName: Exception in ThreadGroup: String toString() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test api toString extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadGroupExObjecttoString.java + * -@ExecuteClass: ThreadGroupExObjecttoString + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadGroupExObjecttoString { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ThreadGroupExObjecttoString().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadGroupExObjecttoString1(); + } catch (Exception e) { + ThreadGroupExObjecttoString.res = ThreadGroupExObjecttoString.res - 20; + } + + + if (result == 4 && ThreadGroupExObjecttoString.res == 89) { + result = 0; + } + + return result; + } + + + private int threadGroupExObjecttoString1() { + int result1 = 4; /*STATUS_FAILED*/ + // String toString() + ThreadGroup gr1 = new ThreadGroup("Thread8023"); + String str1 = gr1.toString(); + + if (str1.equals("java.lang.ThreadGroup[name=Thread8023,maxpri=10]")) { + ThreadGroupExObjecttoString.res = ThreadGroupExObjecttoString.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0146-rt-parent-ThreadGroupExObjectwaitIllegalArgumentException/ThreadGroupExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0146-rt-parent-ThreadGroupExObjectwaitIllegalArgumentException/ThreadGroupExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..27336c3e711820cc38bfe578824ae34f30807de8 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0146-rt-parent-ThreadGroupExObjectwaitIllegalArgumentException/ThreadGroupExObjectwaitIllegalArgumentException.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in ThreadGroup: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Test api wait extends from Object + * -#step2:Give the value of timeout is negative or the value of nanos is not in the range 0-999999 + * -#step3:Throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadGroupExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: ThreadGroupExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadGroupExObjectwaitIllegalArgumentException { + static int res = 99; + ThreadGroup gr1 = new ThreadGroup("Thread8023"); + + public static void main(String argv[]) { + System.out.println(new ThreadGroupExObjectwaitIllegalArgumentException().run()); + } + + private class ThreadGroupExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + private int remainder; + long millis = -1; + + private ThreadGroupExObjectwaitIllegalArgumentException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (gr1) { + gr1.notifyAll(); + try { + gr1.wait(millis); + ThreadGroupExObjectwaitIllegalArgumentException.res = ThreadGroupExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ThreadGroupExObjectwaitIllegalArgumentException.res = ThreadGroupExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectwaitIllegalArgumentException.res = ThreadGroupExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadGroupExObjectwaitIllegalArgumentException.res = ThreadGroupExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class ThreadGroupExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // final void wait(long millis, int nanos) + + private int remainder; + long millis = -2; + int nanos = 10; + + private ThreadGroupExObjectwaitIllegalArgumentException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (gr1) { + gr1.notifyAll(); + try { + gr1.wait(millis, nanos); + ThreadGroupExObjectwaitIllegalArgumentException.res = ThreadGroupExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ThreadGroupExObjectwaitIllegalArgumentException.res = ThreadGroupExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectwaitIllegalArgumentException.res = ThreadGroupExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadGroupExObjectwaitIllegalArgumentException.res = ThreadGroupExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new ThreadGroupExObjectwaitIllegalArgumentException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ThreadGroupExObjectwaitIllegalArgumentException31(5)); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && ThreadGroupExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0147-rt-parent-ThreadGroupExObjectwaitIllegalMonitorStateException/ThreadGroupExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0147-rt-parent-ThreadGroupExObjectwaitIllegalMonitorStateException/ThreadGroupExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..c60378817519f73c21e773f9f6fe8329f93d1d13 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0147-rt-parent-ThreadGroupExObjectwaitIllegalMonitorStateException/ThreadGroupExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in ThreadGroup: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare the current thread is not the owner of the object's monitor. + * -#step2:Test api wait extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadGroupExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ThreadGroupExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.ThreadGroup; + +public class ThreadGroupExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static ThreadGroup gr1 = new ThreadGroup("Thread8023"); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = threadGroupExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = threadGroupExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = threadGroupExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && ThreadGroupExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int threadGroupExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + gr1.wait(); + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int threadGroupExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + gr1.wait(millis); + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int threadGroupExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + gr1.wait(millis, nanos); + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectwaitIllegalMonitorStateException.res = ThreadGroupExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0148-rt-parent-ThreadGroupExObjectwaitInterruptedException/ThreadGroupExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0148-rt-parent-ThreadGroupExObjectwaitInterruptedException/ThreadGroupExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..5811cb770dfc927b79cbb7941353b424e73d196a --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0148-rt-parent-ThreadGroupExObjectwaitInterruptedException/ThreadGroupExObjectwaitInterruptedException.java @@ -0,0 +1,191 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in ThreadGroup: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Test api wait extends from Object + * -#step2:Thread is interruptted when wait + * -#step3:Throw InterruptedException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadGroupExObjectwaitInterruptedException.java + * -@ExecuteClass: ThreadGroupExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.ThreadGroup; + +public class ThreadGroupExObjectwaitInterruptedException { + static int res = 99; + private static ThreadGroup gr1 = new ThreadGroup("Thread8023"); + + public static void main(String argv[]) { + System.out.println(new ThreadGroupExObjectwaitInterruptedException().run()); + } + + private class ThreadGroupExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + + private int remainder; + + private ThreadGroupExObjectwaitInterruptedException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (gr1) { + gr1.notifyAll(); + try { + gr1.wait(); + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class ThreadGroupExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10000; + + private ThreadGroupExObjectwaitInterruptedException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (gr1) { + gr1.notifyAll(); + try { + gr1.wait(millis); + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class ThreadGroupExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + private int remainder; + long millis = 10000; + int nanos = 100; + + private ThreadGroupExObjectwaitInterruptedException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (gr1) { + gr1.notifyAll(); + try { + gr1.wait(millis, nanos); + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadGroupExObjectwaitInterruptedException.res = ThreadGroupExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ThreadGroupExObjectwaitInterruptedException11(1)); + // final void wait(long millis) + Thread t3 = new Thread(new ThreadGroupExObjectwaitInterruptedException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ThreadGroupExObjectwaitInterruptedException31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t1.interrupt(); + sleep(1000); + t3.start(); + sleep(1000); + t3.interrupt(); + sleep(1000); + t5.start(); + sleep(1000); + t5.interrupt(); + sleep(1000); + + if (result == 2 && ThreadGroupExObjectwaitInterruptedException.res == 96) { + result = 0; + } + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0149-rt-parent-ThreadLocalExObjectgetClass/ThreadLocalExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0149-rt-parent-ThreadLocalExObjectgetClass/ThreadLocalExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..47e46e797e69d374b5d1fa944279c19d761f4e39 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0149-rt-parent-ThreadLocalExObjectgetClass/ThreadLocalExObjectgetClass.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadLocalExObjectgetClass.java + * -@TestCaseName: Exception in ThreadLocal: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test ThreadLocal api getClass extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadLocalExObjectgetClass.java + * -@ExecuteClass: ThreadLocalExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.ThreadLocal; + +public class ThreadLocalExObjectgetClass { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ThreadLocalExObjectgetClass().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadLocalExObjectgetClass1(); + } catch (Exception e) { + ThreadLocalExObjectgetClass.res = ThreadLocalExObjectgetClass.res - 20; + } + + if (result == 4 && ThreadLocalExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + private int threadLocalExObjectgetClass1() { + int result1 = 4; /*STATUS_FAILED*/ + // final Class getClass() + ThreadLocal threadLocal1 = new ThreadLocal(); + Class px1 = threadLocal1.getClass(); + + if (px1.toString().equals("class java.lang.ThreadLocal")) { + ThreadLocalExObjectgetClass.res = ThreadLocalExObjectgetClass.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0150-rt-parent-ThreadLocalExObjecthashCode/ThreadLocalExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0150-rt-parent-ThreadLocalExObjecthashCode/ThreadLocalExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..ae4178516bcdb58db96793bc1775fcdd7dde0737 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0150-rt-parent-ThreadLocalExObjecthashCode/ThreadLocalExObjecthashCode.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadLocalExObjecthashCode.java + * -@TestCaseName: Exception in ThreadLocal: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test ThreadLocal api hashCode extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadLocalExObjecthashCode.java + * -@ExecuteClass: ThreadLocalExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.ThreadLocal; + +public class ThreadLocalExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ThreadLocalExObjecthashCode().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadLocalExObjecthashCode1(); + } catch (Exception e) { + ThreadLocalExObjecthashCode.res = ThreadLocalExObjecthashCode.res - 20; + } + + if (result == 4 && ThreadLocalExObjecthashCode.res == 89) { + result = 0; + } + + return result; + } + + private int threadLocalExObjecthashCode1() { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + + ThreadLocal threadLocal1 = new ThreadLocal(); + ThreadLocal threadLocal2 = threadLocal1; + ThreadLocal threadLocal3 = new ThreadLocal(); + + if (threadLocal1.hashCode() == threadLocal2.hashCode() && threadLocal1.hashCode() != threadLocal3.hashCode()) { + ThreadLocalExObjecthashCode.res = ThreadLocalExObjecthashCode.res - 10; + } else { + ThreadLocalExObjecthashCode.res = ThreadLocalExObjecthashCode.res - 5; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0151-rt-parent-ThreadLocalExObjectnotifyAllIllegalMonitorStateException/ThreadLocalExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0151-rt-parent-ThreadLocalExObjectnotifyAllIllegalMonitorStateException/ThreadLocalExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..dcdac961cc04600c7cd0a60f22ba6c8cefbcbb69 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0151-rt-parent-ThreadLocalExObjectnotifyAllIllegalMonitorStateException/ThreadLocalExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadLocalExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in ThreadLocal: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test ThreadLocal api notifyAll extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadLocalExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ThreadLocalExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadLocalExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + ThreadLocal tl1 = new ThreadLocal(); + + public static void main(String argv[]) { + System.out.println(new ThreadLocalExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadLocalExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res = ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ThreadLocalExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int threadLocalExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + tl1.notifyAll(); + ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res = ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res = ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ThreadLocalExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ThreadLocalExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (tl1) { + try { + tl1.notifyAll(); + ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res = ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res = ThreadLocalExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0152-rt-parent-ThreadLocalExObjectnotifyIllegalMonitorStateException/ThreadLocalExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0152-rt-parent-ThreadLocalExObjectnotifyIllegalMonitorStateException/ThreadLocalExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..31b83e7bcc1b155e6452154933a509a0d034d579 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0152-rt-parent-ThreadLocalExObjectnotifyIllegalMonitorStateException/ThreadLocalExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadLocalExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in ThreadLocal: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test ThreadLocal api notify extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadLocalExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ThreadLocalExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.ThreadLocal; + +public class ThreadLocalExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private ThreadLocal tl1 = new ThreadLocal(); + + public static void main(String argv[]) { + System.out.println(new ThreadLocalExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadLocalExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ThreadLocalExObjectnotifyIllegalMonitorStateException.res = ThreadLocalExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ThreadLocalExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ThreadLocalExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int threadLocalExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + tl1.notify(); + ThreadLocalExObjectnotifyIllegalMonitorStateException.res = ThreadLocalExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectnotifyIllegalMonitorStateException.res = ThreadLocalExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ThreadLocalExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ThreadLocalExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (tl1) { + try { + tl1.notify(); + ThreadLocalExObjectnotifyIllegalMonitorStateException.res = ThreadLocalExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectnotifyIllegalMonitorStateException.res = ThreadLocalExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0153-rt-parent-ThreadLocalExObjecttoString/ThreadLocalExObjecttoString.java b/test/testsuite/ouroboros/parent_test/RT0153-rt-parent-ThreadLocalExObjecttoString/ThreadLocalExObjecttoString.java new file mode 100755 index 0000000000000000000000000000000000000000..e9d4252a55cafc1e1ece488295c5207e19642ae3 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0153-rt-parent-ThreadLocalExObjecttoString/ThreadLocalExObjecttoString.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadLocalExObjecttoString.java + * -@TestCaseName: Exception in ThreadLocal: String toString() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test ThreadLocal api toString extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadLocalExObjecttoString.java + * -@ExecuteClass: ThreadLocalExObjecttoString + * -@ExecuteArgs: + */ + +import java.lang.ThreadLocal; + +public class ThreadLocalExObjecttoString { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ThreadLocalExObjecttoString().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = threadLocalExObjecttoString1(); + } catch (Exception e) { + ThreadLocalExObjecttoString.res = ThreadLocalExObjecttoString.res - 20; + } + + if (result == 4 && ThreadLocalExObjecttoString.res == 89) { + result = 0; + } + + return result; + } + + + private int threadLocalExObjecttoString1() { + int result1 = 4; /*STATUS_FAILED*/ + // String toString() + + ThreadLocal threadLocal1 = new ThreadLocal(); + String str1 = threadLocal1.toString(); + if (str1.contains("java.lang.ThreadLocal")) { + ThreadLocalExObjecttoString.res = ThreadLocalExObjecttoString.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0154-rt-parent-ThreadLocalExObjectwaitIllegalArgumentException/ThreadLocalExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0154-rt-parent-ThreadLocalExObjectwaitIllegalArgumentException/ThreadLocalExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..eb28ef1f20ad1736873e85471d1bbf09acde1490 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0154-rt-parent-ThreadLocalExObjectwaitIllegalArgumentException/ThreadLocalExObjectwaitIllegalArgumentException.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadLocalExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in ThreadLocal: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Test ThreadLocal api wait extends from Object + * -#step2:Give the value of timeout is negative or the value of nanos is not in the range 0-999999 + * -#step3:Throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadLocalExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: ThreadLocalExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadLocalExObjectwaitIllegalArgumentException { + static int res = 99; + ThreadLocal tl1 = new ThreadLocal(); + + public static void main(String argv[]) { + System.out.println(new ThreadLocalExObjectwaitIllegalArgumentException().run()); + } + + private class ThreadLocalExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + private int remainder; + long millis = -1; + + private ThreadLocalExObjectwaitIllegalArgumentException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (tl1) { + tl1.notifyAll(); + try { + tl1.wait(millis); + ThreadLocalExObjectwaitIllegalArgumentException.res = ThreadLocalExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ThreadLocalExObjectwaitIllegalArgumentException.res = ThreadLocalExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectwaitIllegalArgumentException.res = ThreadLocalExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadLocalExObjectwaitIllegalArgumentException.res = ThreadLocalExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class ThreadLocalExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // + // final void wait(long millis, int nanos) + + private int remainder; + long millis = -2; + int nanos = 10; + + private ThreadLocalExObjectwaitIllegalArgumentException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (tl1) { + tl1.notifyAll(); + try { + tl1.wait(millis, nanos); + ThreadLocalExObjectwaitIllegalArgumentException.res = ThreadLocalExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ThreadLocalExObjectwaitIllegalArgumentException.res = ThreadLocalExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectwaitIllegalArgumentException.res = ThreadLocalExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadLocalExObjectwaitIllegalArgumentException.res = ThreadLocalExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new ThreadLocalExObjectwaitIllegalArgumentException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ThreadLocalExObjectwaitIllegalArgumentException31(5)); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && ThreadLocalExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0155-rt-parent-ThreadLocalExObjectwaitIllegalMonitorStateException/ThreadLocalExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0155-rt-parent-ThreadLocalExObjectwaitIllegalMonitorStateException/ThreadLocalExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..f3759cf1a75165a801f45f59552779177d6162b8 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0155-rt-parent-ThreadLocalExObjectwaitIllegalMonitorStateException/ThreadLocalExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadLocalExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in ThreadLocal: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test ThreadLocal api wait extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadLocalExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ThreadLocalExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadLocalExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static ThreadLocal tl1 = new ThreadLocal<>(); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = threadLocalExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = threadLocalExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = threadLocalExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && ThreadLocalExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + return result; + } + + private static int threadLocalExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + tl1.wait(); + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int threadLocalExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + tl1.wait(millis); + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int threadLocalExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + tl1.wait(millis, nanos); + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectwaitIllegalMonitorStateException.res = ThreadLocalExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0156-rt-parent-ThreadLocalExObjectwaitInterruptedException/ThreadLocalExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0156-rt-parent-ThreadLocalExObjectwaitInterruptedException/ThreadLocalExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..bda41c0e68c79c2ddcb1a16c8b5ac4316bc2001e --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0156-rt-parent-ThreadLocalExObjectwaitInterruptedException/ThreadLocalExObjectwaitInterruptedException.java @@ -0,0 +1,191 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadLocalExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in ThreadLocal: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Test ThreadLocal api wait extends from Object + * -#step2:Thread is interruptted when wait + * -#step3:Throw InterruptedException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThreadLocalExObjectwaitInterruptedException.java + * -@ExecuteClass: ThreadLocalExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThreadLocalExObjectwaitInterruptedException { + static int res = 99; + static ThreadLocal tl1 = new ThreadLocal<>(); + + public static void main(String argv[]) { + System.out.println(new ThreadLocalExObjectwaitInterruptedException().run()); + } + + private class ThreadLocalExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + private int remainder; + + private ThreadLocalExObjectwaitInterruptedException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (tl1) { + tl1.notifyAll(); + try { + tl1.wait(); + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class ThreadLocalExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10000; + + private ThreadLocalExObjectwaitInterruptedException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (tl1) { + tl1.notifyAll(); + try { + tl1.wait(millis); + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class ThreadLocalExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + private int remainder; + long millis = 10000; + int nanos = 100; + + private ThreadLocalExObjectwaitInterruptedException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (tl1) { + tl1.notifyAll(); + try { + tl1.wait(millis, nanos); + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ThreadLocalExObjectwaitInterruptedException.res = ThreadLocalExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ThreadLocalExObjectwaitInterruptedException11(1)); + // final void wait(long millis) + Thread t3 = new Thread(new ThreadLocalExObjectwaitInterruptedException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ThreadLocalExObjectwaitInterruptedException31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t1.interrupt(); + sleep(100); + t3.start(); + sleep(100); + t3.interrupt(); + sleep(100); + t5.start(); + sleep(100); + t5.interrupt(); + sleep(100); + + if (result == 2 && ThreadLocalExObjectwaitInterruptedException.res == 96) { + result = 0; + } + + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0157-rt-parent-ThrowableExObjecthashCode/ThrowableExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0157-rt-parent-ThrowableExObjecthashCode/ThrowableExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..cb063e382d0d6f4becaf50898353fcf93ff8ee09 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0157-rt-parent-ThrowableExObjecthashCode/ThrowableExObjecthashCode.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThrowableExObjecthashCode.java + * -@TestCaseName: Exception in Throwable: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test Throwable api hashCode extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: ThrowableExObjecthashCode.java + * -@ExecuteClass: ThrowableExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.Throwable; + +public class ThrowableExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new ThrowableExObjecthashCode().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = throwableExObjecthashCode1(); + } catch (Exception e) { + ThrowableExObjecthashCode.res = ThrowableExObjecthashCode.res - 20; + } + + if (result == 4 && ThrowableExObjecthashCode.res == 89) { + result = 0; + } + + return result; + } + + private int throwableExObjecthashCode1() { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + + Throwable cause1 = new Throwable("detailed message of cause1"); + Throwable cause2 = cause1; + Throwable cause3 = new Throwable("detailed message of cause3"); + + if (cause1.hashCode() == cause2.hashCode() && cause1.hashCode() != cause3.hashCode()) { + ThrowableExObjecthashCode.res = ThrowableExObjecthashCode.res - 10; + } else { + ThrowableExObjecthashCode.res = ThrowableExObjecthashCode.res - 5; + } + + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0158-rt-parent-ThrowableExObjectnotifyAllIllegalMonitorStateException/ThrowableExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0158-rt-parent-ThrowableExObjectnotifyAllIllegalMonitorStateException/ThrowableExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..57d7ad14783aeaf9cececf0335d37fe2726f6cf4 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0158-rt-parent-ThrowableExObjectnotifyAllIllegalMonitorStateException/ThrowableExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThrowableExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in Throwable: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test Throwable api notifyAll extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThrowableExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: ThrowableExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThrowableExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private Throwable cause = new Throwable("detailed message of cause"); + + public static void main(String argv[]) { + System.out.println(new ThrowableExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = throwableExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + ThrowableExObjectnotifyAllIllegalMonitorStateException.res = ThrowableExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ThrowableExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ThrowableExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int throwableExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // + // final void notifyAll() + try { + cause.notifyAll(); + ThrowableExObjectnotifyAllIllegalMonitorStateException.res = ThrowableExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectnotifyAllIllegalMonitorStateException.res = ThrowableExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ThrowableExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private ThrowableExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + try { + cause.notifyAll(); + ThrowableExObjectnotifyAllIllegalMonitorStateException.res = ThrowableExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectnotifyAllIllegalMonitorStateException.res = ThrowableExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0159-rt-parent-ThrowableExObjectnotifyIllegalMonitorStateException/ThrowableExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0159-rt-parent-ThrowableExObjectnotifyIllegalMonitorStateException/ThrowableExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..86cf444af4f6fb50f8223a4670d572249cc6a402 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0159-rt-parent-ThrowableExObjectnotifyIllegalMonitorStateException/ThrowableExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThrowableExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in Throwable: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test Throwable api notify extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThrowableExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: ThrowableExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThrowableExObjectnotifyIllegalMonitorStateException { + static int res = 99; + private Throwable cause = new Throwable("detailed message of cause"); + + public static void main(String argv[]) { + System.out.println(new ThrowableExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = throwableExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + ThrowableExObjectnotifyIllegalMonitorStateException.res = ThrowableExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new ThrowableExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && ThrowableExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int throwableExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + cause.notify(); + ThrowableExObjectnotifyIllegalMonitorStateException.res = ThrowableExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectnotifyIllegalMonitorStateException.res = ThrowableExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class ThrowableExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private ThrowableExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + try { + cause.notify(); + ThrowableExObjectnotifyIllegalMonitorStateException.res = ThrowableExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectnotifyIllegalMonitorStateException.res = ThrowableExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0160-rt-parent-ThrowableExObjectwaitIllegalArgumentException/ThrowableExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/RT0160-rt-parent-ThrowableExObjectwaitIllegalArgumentException/ThrowableExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..dafd062c005811499618e8cff9a2afb00a3882dc --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0160-rt-parent-ThrowableExObjectwaitIllegalArgumentException/ThrowableExObjectwaitIllegalArgumentException.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThrowableExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in Throwable: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Test Throwable api wait extends from Object + * -#step2:Give the value of timeout is negative or the value of nanos is not in the range 0-999999 + * -#step3:Throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThrowableExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: ThrowableExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class ThrowableExObjectwaitIllegalArgumentException { + static int res = 99; + private Throwable cause = new Throwable("detailed message of cause"); + + public static void main(String argv[]) { + System.out.println(new ThrowableExObjectwaitIllegalArgumentException().run()); + } + + private class ThrowableExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + private int remainder; + long millis = -1; + + private ThrowableExObjectwaitIllegalArgumentException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + cause.notifyAll(); + try { + cause.wait(millis); + ThrowableExObjectwaitIllegalArgumentException.res = ThrowableExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ThrowableExObjectwaitIllegalArgumentException.res = ThrowableExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwaitIllegalArgumentException.res = ThrowableExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ThrowableExObjectwaitIllegalArgumentException.res = ThrowableExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class ThrowableExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // + // final void wait(long millis, int nanos) + + private int remainder; + long millis = -2; + int nanos = 10; + + private ThrowableExObjectwaitIllegalArgumentException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + cause.notifyAll(); + try { + cause.wait(millis, nanos); + ThrowableExObjectwaitIllegalArgumentException.res = ThrowableExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ThrowableExObjectwaitIllegalArgumentException.res = ThrowableExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwaitIllegalArgumentException.res = ThrowableExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ThrowableExObjectwaitIllegalArgumentException.res = ThrowableExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new ThrowableExObjectwaitIllegalArgumentException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ThrowableExObjectwaitIllegalArgumentException31(5)); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && ThrowableExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + + return result; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0161-rt-parent-ThrowableExObjectwaitIllegalMonitorStateException/ThrowableExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0161-rt-parent-ThrowableExObjectwaitIllegalMonitorStateException/ThrowableExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..023cf27c89612a14709bbe9366b3f8a3845e9e0e --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0161-rt-parent-ThrowableExObjectwaitIllegalMonitorStateException/ThrowableExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThrowableExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in Throwable: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test Throwable api notifyAll extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThrowableExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ThrowableExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Throwable; + +public class ThrowableExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static Throwable cause = new Throwable("detailed message of cause"); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = throwableExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = throwableExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = throwableExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && ThrowableExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int throwableExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + cause.wait(); + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int throwableExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + cause.wait(millis); + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int throwableExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + cause.wait(millis, nanos); + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwaitIllegalMonitorStateException.res = ThrowableExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0162-rt-parent-ThrowableExObjectwaitInterruptedException/ThrowableExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0162-rt-parent-ThrowableExObjectwaitInterruptedException/ThrowableExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..98cddee1b92dc325425e941baae205c9fe7e31d7 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0162-rt-parent-ThrowableExObjectwaitInterruptedException/ThrowableExObjectwaitInterruptedException.java @@ -0,0 +1,191 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThrowableExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in Throwable: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Test Throwable api wait extends from Object + * -#step2:Thread is interruptted when wait + * -#step3:Throw InterruptedException + * -@Expect:0\n + * -@Priority: High + * -@Source: ThrowableExObjectwaitInterruptedException.java + * -@ExecuteClass: ThrowableExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.Throwable; + +public class ThrowableExObjectwaitInterruptedException { + static int res = 99; + static Throwable cause = new Throwable("detailed message of cause"); + + public static void main(String argv[]) { + System.out.println(new ThrowableExObjectwaitInterruptedException().run()); + } + + private class ThrowableExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + private int remainder; + + private ThrowableExObjectwaitInterruptedException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + cause.notifyAll(); + try { + cause.wait(); + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class ThrowableExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10000; + + private ThrowableExObjectwaitInterruptedException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + cause.notifyAll(); + try { + cause.wait(millis); + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class ThrowableExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + private int remainder; + long millis = 10000; + int nanos = 100; + + private ThrowableExObjectwaitInterruptedException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + cause.notifyAll(); + try { + cause.wait(millis, nanos); + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + ThrowableExObjectwaitInterruptedException.res = ThrowableExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ThrowableExObjectwaitInterruptedException11(1)); + // final void wait(long millis) + Thread t3 = new Thread(new ThrowableExObjectwaitInterruptedException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ThrowableExObjectwaitInterruptedException31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(100); + t1.interrupt(); + sleep(100); + t3.start(); + sleep(100); + t3.interrupt(); + sleep(100); + t5.start(); + sleep(100); + t5.interrupt(); + sleep(100); + + if (result == 2 && ThrowableExObjectwaitInterruptedException.res == 96) { + result = 0; + } + + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0163-rt-parent-ThrowableExObjectwait/ThrowableExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0163-rt-parent-ThrowableExObjectwait/ThrowableExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..3d34e58f25eb3802ea45ef161d75205fb5c2d525 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0163-rt-parent-ThrowableExObjectwait/ThrowableExObjectwait.java @@ -0,0 +1,210 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThrowableExObjectwait.java + * -@TestCaseName: Exception in Throwable: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test Throwable api wait extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: ThrowableExObjectwait.java + * -@ExecuteClass: ThrowableExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.Throwable; + +public class ThrowableExObjectwait { + static int res = 99; + private Throwable cause = new Throwable("detailed message of cause"); + + public static void main(String argv[]) { + System.out.println(new ThrowableExObjectwait().run()); + } + + private class ThrowableExObjectwait11 implements Runnable { + // final void wait() + private int remainder; + + private ThrowableExObjectwait11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + cause.notifyAll(); + try { + cause.wait(); + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 15; + } catch (InterruptedException e1) { + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 10; + } + } + } + } + + private class ThrowableExObjectwait21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10; + + private ThrowableExObjectwait21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + cause.notify(); + try { + cause.wait(millis); + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 15; + } catch (InterruptedException e1) { + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 5; + } + } + } + } + + private class ThrowableExObjectwait31 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10; + int nanos = 10; + + private ThrowableExObjectwait31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (cause) { + cause.notifyAll(); + try { + cause.wait(millis, nanos); + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 15; + } catch (InterruptedException e1) { + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + ThrowableExObjectwait.res = ThrowableExObjectwait.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * join fun + * @param thread wait join thread + */ + private void waitFinish(Thread thread) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new ThrowableExObjectwait11(1)); + Thread t2 = new Thread(new ThrowableExObjectwait11(2)); + // final void wait(long millis) + Thread t3 = new Thread(new ThrowableExObjectwait21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ThrowableExObjectwait31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + t1.interrupt(); + + waitFinish(t1); + waitFinish(t3); + waitFinish(t5); + + + if (result == 2 && ThrowableExObjectwait.res == 54) { + result = 0; + } + + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0164-rt-parent-UnicodeBlockExObjectgetClass/UnicodeBlockExObjectgetClass.java b/test/testsuite/ouroboros/parent_test/RT0164-rt-parent-UnicodeBlockExObjectgetClass/UnicodeBlockExObjectgetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..c79582ba99eba5a24da6eff0780e3b32095e3d82 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0164-rt-parent-UnicodeBlockExObjectgetClass/UnicodeBlockExObjectgetClass.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnicodeBlockExObjectgetClass.java + * -@TestCaseName: Exception in Character/UnicodeBlock: final Class getClass() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test UnicodeBlock api getClass extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: UnicodeBlockExObjectgetClass.java + * -@ExecuteClass: UnicodeBlockExObjectgetClass + * -@ExecuteArgs: + */ + +import java.lang.Character; + +public class UnicodeBlockExObjectgetClass { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new UnicodeBlockExObjectgetClass().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = unicodeBlockExObjectgetClass1(); + } catch (Exception e) { + UnicodeBlockExObjectgetClass.res = UnicodeBlockExObjectgetClass.res - 20; + } + + if (result == 4 && UnicodeBlockExObjectgetClass.res == 89) { + result = 0; + } + + return result; + } + + + private int unicodeBlockExObjectgetClass1() { + int result1 = 4; /*STATUS_FAILED*/ + // final Class getClass() + Character.UnicodeBlock unB1 = null; + for (int cp = 0; cp <= 10; ++cp) { + unB1 = Character.UnicodeBlock.of(cp); + } + + Class px1 = unB1.getClass(); + + if (px1.toString().equals("class java.lang.Character$UnicodeBlock")) { + UnicodeBlockExObjectgetClass.res = UnicodeBlockExObjectgetClass.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0165-rt-parent-UnicodeBlockExObjecthashCode/UnicodeBlockExObjecthashCode.java b/test/testsuite/ouroboros/parent_test/RT0165-rt-parent-UnicodeBlockExObjecthashCode/UnicodeBlockExObjecthashCode.java new file mode 100755 index 0000000000000000000000000000000000000000..cde85652ca5bfaef94a85f215a5bc2cd21a75864 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0165-rt-parent-UnicodeBlockExObjecthashCode/UnicodeBlockExObjecthashCode.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnicodeBlockExObjecthashCode.java + * -@TestCaseName: Exception in Character/UnicodeBlock: int hashCode() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test UnicodeBlock api hashCode extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: UnicodeBlockExObjecthashCode.java + * -@ExecuteClass: UnicodeBlockExObjecthashCode + * -@ExecuteArgs: + */ + +import java.lang.Character; + +public class UnicodeBlockExObjecthashCode { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new UnicodeBlockExObjecthashCode().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = unicodeBlockExObjecthashCode1(); + } catch (Exception e) { + UnicodeBlockExObjecthashCode.res = UnicodeBlockExObjecthashCode.res - 20; + } + + if (result == 4 && UnicodeBlockExObjecthashCode.res == 89) { + result = 0; + } + + return result; + } + + private int unicodeBlockExObjecthashCode1() { + int result1 = 4; /*STATUS_FAILED*/ + // int hashCode() + Character.UnicodeBlock unB1 = Character.UnicodeBlock.of(10); + Character.UnicodeBlock unB2 = Character.UnicodeBlock.of(10); + Character.UnicodeBlock unB3 = Character.UnicodeBlock.of('〆'); + + if (unB1.hashCode() == unB2.hashCode() && unB1.hashCode() != unB3.hashCode()) { + UnicodeBlockExObjecthashCode.res = UnicodeBlockExObjecthashCode.res - 10; + } else { + UnicodeBlockExObjecthashCode.res = UnicodeBlockExObjecthashCode.res - 5; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0166-rt-parent-UnicodeBlockExObjectnotifyAllIllegalMonitorStateException/UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0166-rt-parent-UnicodeBlockExObjectnotifyAllIllegalMonitorStateException/UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..20a4847c8046b4c9cdec223048fd13cd31392ba9 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0166-rt-parent-UnicodeBlockExObjectnotifyAllIllegalMonitorStateException/UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in Character/UnicodeBlock: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test UnicodeBlock api notifyAll extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: UnicodeBlockExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Character; + +public class UnicodeBlockExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private static Character.UnicodeBlock unb1 = null; + + public static void main(String argv[]) { + for (int cp = 0; cp <= 10; ++cp) { + unb1 = Character.UnicodeBlock.of(cp); + } + System.out.println(new UnicodeBlockExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = unicodeBlockExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new UnicodeBlockExObjectnotifyAllIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int unicodeBlockExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + unb1.notifyAll(); + UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class UnicodeBlockExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + private int remainder; + + private UnicodeBlockExObjectnotifyAllIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (unb1) { + try { + unb1.notifyAll(); + UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0167-rt-parent-UnicodeBlockExObjectnotifyIllegalMonitorStateException/UnicodeBlockExObjectnotifyIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0167-rt-parent-UnicodeBlockExObjectnotifyIllegalMonitorStateException/UnicodeBlockExObjectnotifyIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..f6722f6a245075ecdb2897b30e3b005c6bdb84c9 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0167-rt-parent-UnicodeBlockExObjectnotifyIllegalMonitorStateException/UnicodeBlockExObjectnotifyIllegalMonitorStateException.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnicodeBlockExObjectnotifyIllegalMonitorStateException.java + * -@TestCaseName: Exception in Character/UnicodeBlock: final void notify() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test UnicodeBlock api notifyAll extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: UnicodeBlockExObjectnotifyIllegalMonitorStateException.java + * -@ExecuteClass: UnicodeBlockExObjectnotifyIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Character; + +public class UnicodeBlockExObjectnotifyIllegalMonitorStateException { + static int res = 99; + static Character.UnicodeBlock unb1 = null; + + public static void main(String argv[]) { + for (int cp = 0; cp <= 10; ++cp) { + unb1 = Character.UnicodeBlock.of(cp); + } + System.out.println(new UnicodeBlockExObjectnotifyIllegalMonitorStateException().run()); + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = unicodeBlockExObjectnotifyIllegalMonitorStateException1(); + } catch (Exception e) { + UnicodeBlockExObjectnotifyIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyIllegalMonitorStateException.res - 20; + } + + Thread t1 = new Thread(new UnicodeBlockExObjectnotifyIllegalMonitorStateException11(1)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (result == 4 && UnicodeBlockExObjectnotifyIllegalMonitorStateException.res == 58) { + result = 0; + } + + return result; + } + + private int unicodeBlockExObjectnotifyIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notify() + try { + unb1.notify(); + UnicodeBlockExObjectnotifyIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectnotifyIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private class UnicodeBlockExObjectnotifyIllegalMonitorStateException11 implements Runnable { + // final void notify() + private int remainder; + + private UnicodeBlockExObjectnotifyIllegalMonitorStateException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (unb1) { + try { + unb1.notify(); + UnicodeBlockExObjectnotifyIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectnotifyIllegalMonitorStateException.res = UnicodeBlockExObjectnotifyIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0168-rt-parent-UnicodeBlockExObjecttoString/UnicodeBlockExObjecttoString.java b/test/testsuite/ouroboros/parent_test/RT0168-rt-parent-UnicodeBlockExObjecttoString/UnicodeBlockExObjecttoString.java new file mode 100755 index 0000000000000000000000000000000000000000..cfe2b9e51b701ae80d8a37df78edf5b32092b149 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0168-rt-parent-UnicodeBlockExObjecttoString/UnicodeBlockExObjecttoString.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnicodeBlockExObjecttoString.java + * -@TestCaseName: Exception in Character/UnicodeBlock: final String toString() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test UnicodeBlock api toString extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: UnicodeBlockExObjecttoString.java + * -@ExecuteClass: UnicodeBlockExObjecttoString + * -@ExecuteArgs: + */ + +import java.lang.Character; + +public class UnicodeBlockExObjecttoString { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(new UnicodeBlockExObjecttoString().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = unicodeBlockExObjecttoString1(); + } catch (Exception e) { + UnicodeBlockExObjecttoString.res = UnicodeBlockExObjecttoString.res - 20; + } + + if (result == 4 && UnicodeBlockExObjecttoString.res == 89) { + result = 0; + } + + return result; + } + + private int unicodeBlockExObjecttoString1() { + int result1 = 4; /*STATUS_FAILED*/ + // final String toString() + Character.UnicodeBlock unB1 = null; + for (int cp = 0; cp <= 10; ++cp) { + unB1 = Character.UnicodeBlock.of(cp); + } + + String px1 = unB1.toString(); + if (px1.equals("BASIC_LATIN")) { + UnicodeBlockExObjecttoString.res = UnicodeBlockExObjecttoString.res - 10; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0169-rt-parent-UnicodeBlockExObjectwaitIllegalMonitorStateException/UnicodeBlockExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/RT0169-rt-parent-UnicodeBlockExObjectwaitIllegalMonitorStateException/UnicodeBlockExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..a25bb27830525c22986093841be7b2fab34bab02 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0169-rt-parent-UnicodeBlockExObjectwaitIllegalMonitorStateException/UnicodeBlockExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnicodeBlockExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in Character/UnicodeBlock: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Prepare current thread is not the owner of the object's monitor + * -#step2:Test UnicodeBlock api wait extends from Object + * -#step3:Throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: UnicodeBlockExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: UnicodeBlockExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Character; + +public class UnicodeBlockExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static Character.UnicodeBlock unb1 = null; + + public static void main(String argv[]) { + for (int cp = 0; cp <= 10; ++cp) { + unb1 = Character.UnicodeBlock.of(cp); + } + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = unicodeBlockExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = unicodeBlockExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = unicodeBlockExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && UnicodeBlockExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int unicodeBlockExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait() + try { + unb1.wait(); + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int unicodeBlockExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + unb1.wait(millis); + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int unicodeBlockExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + unb1.wait(millis, nanos); + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectwaitIllegalMonitorStateException.res = UnicodeBlockExObjectwaitIllegalMonitorStateException.res - 1; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0170-rt-parent-UnicodeBlockExObjectwaitInterruptedException/UnicodeBlockExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/RT0170-rt-parent-UnicodeBlockExObjectwaitInterruptedException/UnicodeBlockExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..99aa998fb840856c4a5b2ef28e27e9fdcbb27828 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0170-rt-parent-UnicodeBlockExObjectwaitInterruptedException/UnicodeBlockExObjectwaitInterruptedException.java @@ -0,0 +1,194 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnicodeBlockExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in Character/UnicodeBlock: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1:Test UnicodeBlock api wait extends from Object + * -#step2:Thread is interruptted when wait + * -#step3:Throw InterruptedException + * -@Expect:0\n + * -@Priority: High + * -@Source: UnicodeBlockExObjectwaitInterruptedException.java + * -@ExecuteClass: UnicodeBlockExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + +import java.lang.Character; + +public class UnicodeBlockExObjectwaitInterruptedException { + static int res = 99; + private static Character.UnicodeBlock unb1 = null; + + public static void main(String argv[]) { + for (int cp = 0; cp <= 10; ++cp) { + unb1 = Character.UnicodeBlock.of(cp); + } + System.out.println(new UnicodeBlockExObjectwaitInterruptedException().run()); + } + + private class UnicodeBlockExObjectwaitInterruptedException11 implements Runnable { + // final void wait() + private int remainder; + + private UnicodeBlockExObjectwaitInterruptedException11(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (unb1) { + unb1.notifyAll(); + try { + unb1.wait(); + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class UnicodeBlockExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + private int remainder; + long millis = 10000; + + private UnicodeBlockExObjectwaitInterruptedException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (unb1) { + unb1.notifyAll(); + try { + unb1.wait(millis); + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class UnicodeBlockExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + + private int remainder; + long millis = 10000; + int nanos = 100; + + private UnicodeBlockExObjectwaitInterruptedException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (unb1) { + unb1.notifyAll(); + try { + unb1.wait(millis, nanos); + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + UnicodeBlockExObjectwaitInterruptedException.res = UnicodeBlockExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new UnicodeBlockExObjectwaitInterruptedException11(1)); + // final void wait(long millis) + Thread t3 = new Thread(new UnicodeBlockExObjectwaitInterruptedException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new UnicodeBlockExObjectwaitInterruptedException31(5)); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t1.interrupt(); + sleep(1000); + t3.start(); + sleep(1000); + t3.interrupt(); + sleep(1000); + t5.start(); + sleep(1000); + t5.interrupt(); + sleep(1000); + + if (result == 2 && UnicodeBlockExObjectwaitInterruptedException.res == 96) { + result = 0; + } + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/RT0171-rt-parent-UnicodeBlockExObjectwait/UnicodeBlockExObjectwait.java b/test/testsuite/ouroboros/parent_test/RT0171-rt-parent-UnicodeBlockExObjectwait/UnicodeBlockExObjectwait.java new file mode 100755 index 0000000000000000000000000000000000000000..7e3ed8d373e67d948f56cb22eccb9e67e3d71f7a --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/RT0171-rt-parent-UnicodeBlockExObjectwait/UnicodeBlockExObjectwait.java @@ -0,0 +1,197 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnicodeBlockExObjectwait.java + * -@TestCaseName: Exception in Character/UnicodeBlock: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief:Test UnicodeBlock api wait extends from Object + * -@Expect:0\n + * -@Priority: High + * -@Source: UnicodeBlockExObjectwait.java + * -@ExecuteClass: UnicodeBlockExObjectwait + * -@ExecuteArgs: + */ + +import java.lang.Character; + +public class UnicodeBlockExObjectwait { + static int res = 99; + private static Character.UnicodeBlock unb1 = null; + + public static void main(String argv[]) { + for (int cp = 0; cp <= 10; ++cp) { + unb1 = Character.UnicodeBlock.of(cp); + } + System.out.println(new UnicodeBlockExObjectwait().run()); + } + + private class UnicodeBlockExObjectwait11 implements Runnable { + // final void wait() + + /** + * Thread run fun + */ + public void run() { + synchronized (unb1) { + unb1.notifyAll(); + try { + unb1.wait(); + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 15; + } catch (InterruptedException e1) { + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 10; + } + } + } + } + + private class UnicodeBlockExObjectwait21 implements Runnable { + // final void wait(long millis) + long millis = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (unb1) { + unb1.notify(); + try { + unb1.wait(millis); + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 15; + } catch (InterruptedException e1) { + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 5; + } + } + } + } + + private class UnicodeBlockExObjectwait31 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10; + int nanos = 10; + + /** + * Thread run fun + */ + public void run() { + synchronized (unb1) { + unb1.notifyAll(); + try { + unb1.wait(millis, nanos); + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 15; + } catch (InterruptedException e1) { + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 1; + } catch (IllegalMonitorStateException e2) { + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 10; + } catch (IllegalArgumentException e3) { + UnicodeBlockExObjectwait.res = UnicodeBlockExObjectwait.res - 5; + } + } + } + } + + /** + * sleep fun + * + * @param slpnum wait time + */ + public void sleep(int slpnum) { + try { + Thread.sleep(slpnum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * join fun + * @param thread wait join thread + */ + private void waitFinish(Thread thread) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new UnicodeBlockExObjectwait11()); + Thread t2 = new Thread(new UnicodeBlockExObjectwait11()); + // final void wait(long millis) + Thread t3 = new Thread(new UnicodeBlockExObjectwait21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new UnicodeBlockExObjectwait31()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t2.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + sleep(1000); + t3.start(); + sleep(1000); + t5.start(); + sleep(1000); + t2.start(); + sleep(1000); + t1.interrupt(); + + waitFinish(t1); + waitFinish(t3); + waitFinish(t5); + + if (result == 2 && UnicodeBlockExObjectwait.res == 54) { + result = 0; + } + + t2.interrupt(); + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/issue-RT0646-rt-parent-AccessibleObjectExObjectwaitInterruptedException/AccessibleObjectExObjectwaitInterruptedException.java b/test/testsuite/ouroboros/parent_test/issue-RT0646-rt-parent-AccessibleObjectExObjectwaitInterruptedException/AccessibleObjectExObjectwaitInterruptedException.java new file mode 100755 index 0000000000000000000000000000000000000000..a1529fa296cfa754e3f10357dd1c6809a63a878c --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/issue-RT0646-rt-parent-AccessibleObjectExObjectwaitInterruptedException/AccessibleObjectExObjectwaitInterruptedException.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AccessibleObjectExObjectwaitInterruptedException.java + * -@TestCaseName: Exception in reflect/AccessibleObject: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three private classes to implement Runnable, run sampleField1 as a synchronization lock, Call wait(), + * wait (millis), wait (millis, nanos) respectively + * -#step2: Call the run of the use case, execute the start () method of the private class 1, and wait for 100 + * milliseconds to interrupt + * -#step3: Execute the start () method of private class 2 and wait for 100 milliseconds to interrupt + * -#step4: Execute the start () method of private class 3 and wait for 100 milliseconds to interrupt + * -#step5: Confirm whether all classes are successfully interrupted and InterruptedException is successfully caught + * -@Expect:0\n + * -@Priority: High + * -@Source: AccessibleObjectExObjectwaitInterruptedException.java + * -@ExecuteClass: AccessibleObjectExObjectwaitInterruptedException + * -@ExecuteArgs: + */ + + +import java.lang.reflect.AccessibleObject; + +public class AccessibleObjectExObjectwaitInterruptedException { + static int res = 99; + private static AccessibleObject sampleField1 = null; + + public static void main(String argv[]) throws NoSuchFieldException, SecurityException { + sampleField1 = AccessibleObjectExObjectwaitInterruptedException.class.getDeclaredField("res"); + System.out.println(new AccessibleObjectExObjectwaitInterruptedException().run()); + } + + private class AccessibleObjectExObjectwaitInterruptedException11 implements Runnable { + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(); + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 10; + } + } + } + } + + private class AccessibleObjectExObjectwaitInterruptedException21 implements Runnable { + // final void wait(long millis) + long millis = 10000; + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(millis); + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 5; + } + } + } + } + + private class AccessibleObjectExObjectwaitInterruptedException31 implements Runnable { + // final void wait(long millis, int nanos) + long millis = 10000; + int nanos = 100; + + /** + * Thread run fun + */ + public void run() { + synchronized (sampleField1) { + sampleField1.notifyAll(); + try { + sampleField1.wait(millis, nanos); + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 15; + } catch (InterruptedException e1) { + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 1; + } catch (IllegalMonitorStateException e2) { + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 10; + } catch (IllegalArgumentException e3) { + AccessibleObjectExObjectwaitInterruptedException.res = AccessibleObjectExObjectwaitInterruptedException.res - 5; + } + } + } + } + + /** + * sleep fun + * @param sleepNum wait time + */ + public void sleep(int sleepNum) { + try { + Thread.sleep(sleepNum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // check api normal + // final void wait() + Thread t1 = new Thread(new AccessibleObjectExObjectwaitInterruptedException11()); + // final void wait(long millis) + Thread t3 = new Thread(new AccessibleObjectExObjectwaitInterruptedException21()); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new AccessibleObjectExObjectwaitInterruptedException31()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + + t1.start(); + sleep(100); + t1.interrupt(); + sleep(100); + t3.start(); + sleep(100); + t3.interrupt(); + sleep(100); + t5.start(); + sleep(100); + t5.interrupt(); + sleep(100); + + if (result == 2 && AccessibleObjectExObjectwaitInterruptedException.res == 96) { + result = 0; + } + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/issue-RT0654-rt-parent-CharacterExObjectnotifyAllIllegalMonitorStateException/CharacterExObjectnotifyAllIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/issue-RT0654-rt-parent-CharacterExObjectnotifyAllIllegalMonitorStateException/CharacterExObjectnotifyAllIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..11cc808d40b62c6b52462d04abf002911f363e91 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/issue-RT0654-rt-parent-CharacterExObjectnotifyAllIllegalMonitorStateException/CharacterExObjectnotifyAllIllegalMonitorStateException.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: CharacterExObjectnotifyAllIllegalMonitorStateException.java + * -@TestCaseName: Exception in Character: final void notifyAll() + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create a private class to implement Runnable, call notifyAll () inside run + * -#step2: Call the run of the use case, execute method 1, and call notifyAll () in the method + * -#step3: Execute the start () method of the private class and wait 100 milliseconds + * -#step4: Confirm method 1 throws an exception IllegalMonitorStateException, the class does not throw an exception + * -@Expect:0\n + * -@Priority: High + * -@Source: CharacterExObjectnotifyAllIllegalMonitorStateException.java + * -@ExecuteClass: CharacterExObjectnotifyAllIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.Thread; + +public class CharacterExObjectnotifyAllIllegalMonitorStateException { + static int res = 99; + private char name = 'A'; + private Character rp = new Character(name); + + public static void main(String argv[]) { + System.out.println(new CharacterExObjectnotifyAllIllegalMonitorStateException().run()); + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + try { + result = characterExObjectnotifyAllIllegalMonitorStateException1(); + } catch (Exception e) { + CharacterExObjectnotifyAllIllegalMonitorStateException.res = CharacterExObjectnotifyAllIllegalMonitorStateException.res - 20; + } + Thread t1 = new Thread(new CharacterExObjectnotifyAllIllegalMonitorStateException11()); + t1.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t1.start(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (result == 4 && CharacterExObjectnotifyAllIllegalMonitorStateException.res == 58) { + result = 0; + } + return result; + } + + private int characterExObjectnotifyAllIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void notifyAll() + try { + rp.notifyAll(); + CharacterExObjectnotifyAllIllegalMonitorStateException.res = CharacterExObjectnotifyAllIllegalMonitorStateException.res - 10; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectnotifyAllIllegalMonitorStateException.res = CharacterExObjectnotifyAllIllegalMonitorStateException.res - 1; + } + return result1; + } + + private class CharacterExObjectnotifyAllIllegalMonitorStateException11 implements Runnable { + // final void notifyAll() + + /** + * Thread run fun + */ + public void run() { + synchronized (rp) { + try { + rp.notifyAll(); + CharacterExObjectnotifyAllIllegalMonitorStateException.res = CharacterExObjectnotifyAllIllegalMonitorStateException.res - 40; + } catch (IllegalMonitorStateException e2) { + CharacterExObjectnotifyAllIllegalMonitorStateException.res = CharacterExObjectnotifyAllIllegalMonitorStateException.res - 30; + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/issue-RT0733-rt-parent-ModifierExObjectwaitIllegalArgumentException/ModifierExObjectwaitIllegalArgumentException.java b/test/testsuite/ouroboros/parent_test/issue-RT0733-rt-parent-ModifierExObjectwaitIllegalArgumentException/ModifierExObjectwaitIllegalArgumentException.java new file mode 100755 index 0000000000000000000000000000000000000000..a3a3af1ab371e97870c87cf3d6caad34377c7051 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/issue-RT0733-rt-parent-ModifierExObjectwaitIllegalArgumentException/ModifierExObjectwaitIllegalArgumentException.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ModifierExObjectwaitIllegalArgumentException.java + * -@TestCaseName: Exception in reflect Modifier: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create 2 private classes to implement Runnable, and call wait (millis), wait (millis, nanos) respectively in run + * -#step2: Call the run of the use case and execute the start () method of the private class 1. + * -#step3: Execute the start () method of private class 2 + * -#step4: Wait 1000 ms + * -#step5: Confirm that all classes throw IllegalArgumentException + * -@Expect:0\n + * -@Priority: High + * -@Source: ModifierExObjectwaitIllegalArgumentException.java + * -@ExecuteClass: ModifierExObjectwaitIllegalArgumentException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Modifier; + +public class ModifierExObjectwaitIllegalArgumentException { + static int res = 99; + static Modifier mf2 = new Modifier(); + + public static void main(String argv[]) { + System.out.println(new ModifierExObjectwaitIllegalArgumentException().run()); + } + + private class ModifierExObjectwaitIllegalArgumentException21 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative. + // final void wait(long millis) + private int remainder; + long millis = -1; + + private ModifierExObjectwaitIllegalArgumentException21(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis); + ModifierExObjectwaitIllegalArgumentException.res = ModifierExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ModifierExObjectwaitIllegalArgumentException.res = ModifierExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwaitIllegalArgumentException.res = ModifierExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ModifierExObjectwaitIllegalArgumentException.res = ModifierExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + private class ModifierExObjectwaitIllegalArgumentException31 implements Runnable { + // IllegalArgumentException - if the value of timeout is negative or the value of nanos is not in the range 0-999999. + // final void wait(long millis, int nanos) + + private int remainder; + long millis = -2; + int nanos = 10; + + private ModifierExObjectwaitIllegalArgumentException31(int remainder) { + this.remainder = remainder; + } + + /** + * Thread run fun + */ + public void run() { + synchronized (mf2) { + mf2.notifyAll(); + try { + mf2.wait(millis, nanos); + ModifierExObjectwaitIllegalArgumentException.res = ModifierExObjectwaitIllegalArgumentException.res - 15; + } catch (InterruptedException e1) { + ModifierExObjectwaitIllegalArgumentException.res = ModifierExObjectwaitIllegalArgumentException.res - 20; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwaitIllegalArgumentException.res = ModifierExObjectwaitIllegalArgumentException.res - 10; + } catch (IllegalArgumentException e3) { + ModifierExObjectwaitIllegalArgumentException.res = ModifierExObjectwaitIllegalArgumentException.res - 5; + } + } + } + } + + /** + * sleep fun + * @param slpNum wait time + */ + public void sleep(int slpNum) { + try { + Thread.sleep(slpNum); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * main test fun + * @return status code + */ + public int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait(long millis) + Thread t3 = new Thread(new ModifierExObjectwaitIllegalArgumentException21(3)); + // final void wait(long millis, int nanos) + Thread t5 = new Thread(new ModifierExObjectwaitIllegalArgumentException31(5)); + t3.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t5.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + System.out.println(t.getName() + " : " + e.getMessage()); + } + }); + t3.start(); + t5.start(); + sleep(1000); + if (result == 2 && ModifierExObjectwaitIllegalArgumentException.res == 89) { + result = 0; + } + + return result; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/parent_test/issue-RT0734-rt-parent-ModifierExObjectwaitIllegalMonitorStateException/ModifierExObjectwaitIllegalMonitorStateException.java b/test/testsuite/ouroboros/parent_test/issue-RT0734-rt-parent-ModifierExObjectwaitIllegalMonitorStateException/ModifierExObjectwaitIllegalMonitorStateException.java new file mode 100755 index 0000000000000000000000000000000000000000..6af58f89c83606aa18b1c9b0e108c41901002ee1 --- /dev/null +++ b/test/testsuite/ouroboros/parent_test/issue-RT0734-rt-parent-ModifierExObjectwaitIllegalMonitorStateException/ModifierExObjectwaitIllegalMonitorStateException.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ModifierExObjectwaitIllegalMonitorStateException.java + * -@TestCaseName: Exception in reflect Modifier: final void wait(*) + * -@TestCaseType: Function Test + * -@RequirementName: 补充重写类的父类方法 + * -@Brief: + * -#step1: Create three methods, which call wait (), wait (millis), wait (millis, nanos) + * -#step2: Call the run of the use case, and execute these three methods respectively + * -#step3: Confirm that all methods throw IllegalMonitorStateException + * -@Expect:0\n + * -@Priority: High + * -@Source: ModifierExObjectwaitIllegalMonitorStateException.java + * -@ExecuteClass: ModifierExObjectwaitIllegalMonitorStateException + * -@ExecuteArgs: + */ + +import java.lang.reflect.Modifier; + +public class ModifierExObjectwaitIllegalMonitorStateException { + static int res = 99; + private static Modifier mf2 = new Modifier(); + + public static void main(String argv[]) { + System.out.println(run()); + } + + /** + * main test fun + * @return status code + */ + public static int run() { + int result = 2; /*STATUS_FAILED*/ + // final void wait() + try { + result = modifierExObjectwaitIllegalMonitorStateException1(); + } catch (Exception e) { + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis) + try { + result = modifierExObjectwaitIllegalMonitorStateException2(); + } catch (Exception e) { + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 20; + } + // final void wait(long millis, int nanos) + try { + result = modifierExObjectwaitIllegalMonitorStateException3(); + } catch (Exception e) { + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 20; + } + + if (result == 4 && ModifierExObjectwaitIllegalMonitorStateException.res == 96) { + result = 0; + } + + return result; + } + + private static int modifierExObjectwaitIllegalMonitorStateException1() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // + // final void wait() + try { + mf2.wait(); + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int modifierExObjectwaitIllegalMonitorStateException2() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis) + long millis = 123; + try { + mf2.wait(millis); + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + + private static int modifierExObjectwaitIllegalMonitorStateException3() { + int result1 = 4; /*STATUS_FAILED*/ + // IllegalMonitorStateException - if the current thread is not the owner of the object's monitor. + // final void wait(long millis, int nanos) + long millis = 123; + int nanos = 10; + try { + mf2.wait(millis, nanos); + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 10; + } catch (InterruptedException e1) { + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 30; + } catch (IllegalMonitorStateException e2) { + ModifierExObjectwaitIllegalMonitorStateException.res = ModifierExObjectwaitIllegalMonitorStateException.res - 1; + } + + return result1; + } + +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0001-rt-reflection-ReflectingetConstructor1/ReflectingGetConstructor1.java b/test/testsuite/ouroboros/reflection_test/RT0001-rt-reflection-ReflectingetConstructor1/ReflectingGetConstructor1.java new file mode 100755 index 0000000000000000000000000000000000000000..25800e0edcc3de66d1a7e937ca0b8cfa3f9cb73d --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0001-rt-reflection-ReflectingetConstructor1/ReflectingGetConstructor1.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectingGetConstructor1 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectingGetConstructor1.java + *- @Title/Destination: Getting public constructors of different arguments from reflection by calling + * Class.getConstructor() + *- @Brief:no: + * -#step1: 通过Class.forName获得GetConstructor1类的一个实例对象getConstructor1; + * -#step2: 分别调用GetConstructor1类的三个构造方法,从而实现从反射中获取不同参数的公共构造函数constructor1、constructor2、 + * constructor3; + * -#step3: 判断三个构造方法获取成功; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0002-rt-reflection-ReflectingetConstructor2/ReflectingGetConstructor2.java b/test/testsuite/ouroboros/reflection_test/RT0002-rt-reflection-ReflectingetConstructor2/ReflectingGetConstructor2.java new file mode 100755 index 0000000000000000000000000000000000000000..7d1d7e5296e122f33e70a3dc6146216452e16a77 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0002-rt-reflection-ReflectingetConstructor2/ReflectingGetConstructor2.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectingGetConstructor2 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectingGetConstructor2.java + *- @Title/Destination: When the specified constructor could not be found by reflection, NoSuchMethodException is thrown + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0003-rt-reflection-ReflectingetConstructors/ReflectingGetConstructors.java b/test/testsuite/ouroboros/reflection_test/RT0003-rt-reflection-ReflectingetConstructors/ReflectingGetConstructors.java new file mode 100755 index 0000000000000000000000000000000000000000..0ddea7f4001fa361d53e9150f5eb423ba1c6faaf --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0003-rt-reflection-ReflectingetConstructors/ReflectingGetConstructors.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectingGetConstructors + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectingGetConstructors.java + *- @Title/Destination: Call Class.GetConstructors() to get all the public constructors in a class by reflection + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0004-rt-reflection-ReflectingetDeclaredConstructor1/ReflectingGetDeclaredConstructor1.java b/test/testsuite/ouroboros/reflection_test/RT0004-rt-reflection-ReflectingetDeclaredConstructor1/ReflectingGetDeclaredConstructor1.java new file mode 100755 index 0000000000000000000000000000000000000000..905d5cc28e7487b8728c20e604fa6a39d1dc7df0 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0004-rt-reflection-ReflectingetDeclaredConstructor1/ReflectingGetDeclaredConstructor1.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectingGetDeclaredConstructor1 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectingGetDeclaredConstructor1.java + *- @Title/Destination: Call Class.getDeclaredConstructor() to get the local constructor of a class by reflection + *- @Brief:no: + * -#step1: 通过反射的方法获得GetDeclaredConstructor1类的一个实例对象getDeclaredConstructor1; + * -#step2: 通过step1中获得的getDeclaredConstructor1分别调用GetDeclaredConstructor1类的三个构造方法,从而实现从反射中获 + * 取不同参数的本地构造函数constructor1、constructor2、constructor3; + * -#step3: step2中所获取到的三个公共构造函数constructor1、constructor2、constructor3分别对应于 + * GetDeclaredConstructor1类的三个构造函数,表明本地构造函数获取成功; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0005-rt-reflection-ReflectingetDeclaredConstructor2/ReflectingGetDeclaredConstructor2.java b/test/testsuite/ouroboros/reflection_test/RT0005-rt-reflection-ReflectingetDeclaredConstructor2/ReflectingGetDeclaredConstructor2.java new file mode 100755 index 0000000000000000000000000000000000000000..acc2f210a00acc0d311a3d4e7c06ed7fe1c41bf2 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0005-rt-reflection-ReflectingetDeclaredConstructor2/ReflectingGetDeclaredConstructor2.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectingGetDeclaredConstructor2 + *- @RequirementName: Java Reflection + *- @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 + *- @Brief:no: + * -#step1: 通过反射的方法获得GetDeclaredConstructor2类的一个实例对象getDeclaredConstructor2; + * -#step2: 尝试通过step1中的getDeclaredConstructor2对象调用GetDeclaredConstructor2类的不存在的本地构造函数; + * -#step3: step2中获取getDeclaredConstructor2对象的不存在的本地构造函数不成功,会抛出NoSuchMethodException; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0006-rt-reflection-ReflectingetDeclaredConstructors/ReflectingGetDeclaredConstructors.java b/test/testsuite/ouroboros/reflection_test/RT0006-rt-reflection-ReflectingetDeclaredConstructors/ReflectingGetDeclaredConstructors.java new file mode 100755 index 0000000000000000000000000000000000000000..08201691188e7502a49a8498e9506b25d0a03d15 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0006-rt-reflection-ReflectingetDeclaredConstructors/ReflectingGetDeclaredConstructors.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectingGetDeclaredConstructors + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectingGetDeclaredConstructors.java + *- @Title/Destination: Call Class.getDeclaredConstructors() to get all the local constructors of a class by reflection + *- @Brief:no: + * -#step1: 通过反射的方法获得GetDeclaredConstructors类的一个实例对象getDeclaredConstructors; + * -#step2: 通过调用getDeclaredConstructors的GetDeclaredConstructors()方法,获取到它的所有本地构造函数并记为constructors; + * -#step3: 确定step2中获取getDeclaredConstructors对象的所有本地构造函数constructors成功,并且其长度为4; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0007-rt-reflection-ReflectionasSubclass1/ReflectionAsSubclass1.java b/test/testsuite/ouroboros/reflection_test/RT0007-rt-reflection-ReflectionasSubclass1/ReflectionAsSubclass1.java new file mode 100755 index 0000000000000000000000000000000000000000..5b3f8b30a4160c67f5217caf276a986e3fff894b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0007-rt-reflection-ReflectionasSubclass1/ReflectionAsSubclass1.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionAsSubclass1 + *- @RequirementName: Java Reflection + *- @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 + *- @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 + *- @Source: ReflectionAsSubclass1.java + *- @ExecuteClass: ReflectionAsSubclass1 + *- @ExecuteArgs: + */ + +interface A { +} + +class A_1 implements A { +} + +class A_2 extends A_1 { +} + +public class ReflectionAsSubclass1 { + public static void main(String[] args) { + try { + Class a_2 = Class.forName("A_1").asSubclass(A.class); + Class a_1 = Class.forName("A_2").asSubclass(A.class); + if (a_2.newInstance() instanceof A) { + if (a_1.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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0008-rt-reflection-ReflectionasSubclass2/ReflectionAsSubclass2.java b/test/testsuite/ouroboros/reflection_test/RT0008-rt-reflection-ReflectionasSubclass2/ReflectionAsSubclass2.java new file mode 100755 index 0000000000000000000000000000000000000000..59d4f31b6f2dbe42a610fce1214a72168bc36fd1 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0008-rt-reflection-ReflectionasSubclass2/ReflectionAsSubclass2.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionAsSubclass2 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionAsSubclass2.java + *- @Title/Destination: To cast a subclass of another class by reflection get a class + *- @Brief:no: + * -#step1: 通过Class.forName("B_1"),再对其返回值调用asSubclass()方法可以获得B类的子类B_1类; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0009-rt-reflection-ReflectionasSubclass3/ReflectionAsSubclass3.java b/test/testsuite/ouroboros/reflection_test/RT0009-rt-reflection-ReflectionasSubclass3/ReflectionAsSubclass3.java new file mode 100755 index 0000000000000000000000000000000000000000..60889d78f316067a2dbfda66da8958d60e43fdba --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0009-rt-reflection-ReflectionasSubclass3/ReflectionAsSubclass3.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionAsSubclass3 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionAsSubclass3.java + *- @Title/Destination: class A calls Class.asSubclass on class B, if A is not a subclass of B, throws ClassCastException + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0010-rt-reflection-Reflectioncast1/ReflectionCast1.java b/test/testsuite/ouroboros/reflection_test/RT0010-rt-reflection-Reflectioncast1/ReflectionCast1.java new file mode 100755 index 0000000000000000000000000000000000000000..49f5484042cf83d1da578b1b6433ae5a7d9ab031 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0010-rt-reflection-Reflectioncast1/ReflectionCast1.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionCast1 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionCast1.java + *- @Title/Destination: Casts an object to the class or interface represented by this Class object + *- @Brief:no: + * -#step1: 创建一个Cast1_a类的实例对象cast1_a,创建一个Cast1类的实例对象cast1; + * -#step2: 将step1中的Cast1类的实例对象cast1强制转换为Cast1_a类型; + * -#step3: 经转换后的cast1对象和Cast1_a类是同一类型; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0011-rt-reflection-Reflectioncast2/ReflectionCast2.java b/test/testsuite/ouroboros/reflection_test/RT0011-rt-reflection-Reflectioncast2/ReflectionCast2.java new file mode 100755 index 0000000000000000000000000000000000000000..13c3b25ca6e765f324ee7953f9bdbef3a2a816ff --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0011-rt-reflection-Reflectioncast2/ReflectionCast2.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionCast2 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionCast2.java + *- @Title/Destination: An exception is reported when the parent object cannot be cast to the class represented by this + * class object + *- @Brief:no: + * -#step1: 创建一个Cast2类的实例对象cast2,创建一个Cast2类的子类Cast2_a类的实例对象cast2_a; + * -#step2: 将Cast2_a类的对象cast2_a强制转换为父类Cast2类型; + * -#step3: step2中的转换不能转换成功,会发生ClassCastException; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0012-rt-reflection-Reflectioncast3/ReflectionCast3.java b/test/testsuite/ouroboros/reflection_test/RT0012-rt-reflection-Reflectioncast3/ReflectionCast3.java new file mode 100755 index 0000000000000000000000000000000000000000..63a5bb1e70fa9f2487debb138ddfb1818965f52b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0012-rt-reflection-Reflectioncast3/ReflectionCast3.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionCast3 + *- @RequirementName: Java Reflection + *- @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 + *- @Brief:no: + * -#step1: 创建一个Cast3_a类的实例对象cast3_a,创建一个Cast3类的实例对象cast3; + * -#step2: 将Cast3_a类的对象cast3_a强制转换为Cast3类型; + * -#step3: step2中的转换不能转换成功,会发生ClassCastException; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0013-rt-reflection-Reflectioncast4/ReflectionCast4.java b/test/testsuite/ouroboros/reflection_test/RT0013-rt-reflection-Reflectioncast4/ReflectionCast4.java new file mode 100755 index 0000000000000000000000000000000000000000..e53f55cfbec952ea4634b7ed2ade135292585628 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0013-rt-reflection-Reflectioncast4/ReflectionCast4.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionCast4 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionCast4.java + *- @Title/Destination: Object cast to NULL + *- @Brief:no: + * -#step1: 创建一个Cast4类的实例对象cast4,创建一个Object类的变量object,并赋初值为null; + * -#step2: 将Cast4类的实例对象cast4强制转换为null; + * -#step3: step2中成功将cast4对象转换为null; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0014-rt-reflection-ReflectiondesiredAssertionStatus/ReflectionDesiredAssertionStatus.java b/test/testsuite/ouroboros/reflection_test/RT0014-rt-reflection-ReflectiondesiredAssertionStatus/ReflectionDesiredAssertionStatus.java new file mode 100755 index 0000000000000000000000000000000000000000..d7c9fbd5aff33097015d87211c88f917c2f6d606 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0014-rt-reflection-ReflectiondesiredAssertionStatus/ReflectionDesiredAssertionStatus.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionDesiredAssertionStatus + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionDesiredAssertionStatus.java + *- @Title/Destination: When a class's assertionStatus is not set, desiredAssertionStatus() return false + *- @Brief:no: + * -#step1: 创建一个ReflectionDesiredAssertionStatus类的实例对象reflectionDesiredAssertionStatus; + * -#step2: 通过reflectionDesiredAssertionStatus的getClass()方法获取其所属的类型并记为clazz; + * -#step3: 调用clazz的desiredAssertionStatus()方法得到的返回值为false; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0015-rt-reflection-ReflectionforName1/ReflectionForName1.java b/test/testsuite/ouroboros/reflection_test/RT0015-rt-reflection-ReflectionforName1/ReflectionForName1.java new file mode 100755 index 0000000000000000000000000000000000000000..18653bbfe877eb539db0e720e9f7dae7bebb4e05 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0015-rt-reflection-ReflectionforName1/ReflectionForName1.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionForName1 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionForName1.java + *- @Title/Destination: Use Class.forName() To find a class by class name + *- @Brief:no: + * -#step1: 通过Class.forName的方法获取ForName1类的类型clazz; + * -#step2: 确定step1中的clazz与ForName1类是同一类型; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0016-rt-reflection-ReflectionforName4/ReflectionForName4.java b/test/testsuite/ouroboros/reflection_test/RT0016-rt-reflection-ReflectionforName4/ReflectionForName4.java new file mode 100755 index 0000000000000000000000000000000000000000..83d2300128dadfe50b8134066200c11254133b33 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0016-rt-reflection-ReflectionforName4/ReflectionForName4.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionForName4 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionForName4.java + *- @Title/Destination: An exception is reported when a class is not found with reflection through a class name + *- @Brief:no: + * -#step1: 以“for*”、true、ForName4_a.class.getClassLoader()为参数,通过Class.forName()获取相关类的运行时类时会 + * 抛出ClassNotFoundException; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0017-rt-reflection-ReflectionforName5/ReflectionForName5.java b/test/testsuite/ouroboros/reflection_test/RT0017-rt-reflection-ReflectionforName5/ReflectionForName5.java new file mode 100755 index 0000000000000000000000000000000000000000..bb076d4bc2715c2a3a71a348e20d0603aac2e579 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0017-rt-reflection-ReflectionforName5/ReflectionForName5.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionForName5 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionForName5.java + *- @Title/Destination: Use Class.forName() to get a multilevel inherited class by reflection + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取ForName5类的类型clazz,且clazz和ForName5类是同一类型; + * -#step2: 通过Class.forName()方法获取ForName55类的类型clazz2,且clazz2和ForName55类是同一类型; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0020-rt-reflection-ReflectiongetAnnotation3/ReflectionGetAnnotation3.java b/test/testsuite/ouroboros/reflection_test/RT0020-rt-reflection-ReflectiongetAnnotation3/ReflectionGetAnnotation3.java new file mode 100755 index 0000000000000000000000000000000000000000..35e45af460a65bd909236b43b45134a48cd4c1c7 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0020-rt-reflection-ReflectiongetAnnotation3/ReflectionGetAnnotation3.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetAnnotation3 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0021-rt-reflection-ReflectiongetAnnotation4/ReflectionGetAnnotation4.java b/test/testsuite/ouroboros/reflection_test/RT0021-rt-reflection-ReflectiongetAnnotation4/ReflectionGetAnnotation4.java new file mode 100755 index 0000000000000000000000000000000000000000..0b805e62c75af0a41c6e66cc6e705946dc64b558 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0021-rt-reflection-ReflectiongetAnnotation4/ReflectionGetAnnotation4.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetAnnotation4 + *- @RequirementName: Java Reflection + *- @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. + *- @Brief:no: + * -#step1: 定义含注解的内部类GetAnnotation4_a。 + * -#step2:通过调用getMethod()从内部类GetAnnotation4_a中获取成员方法。 + * -#step3:调用getAnnotation(Class annotationClass)获取GetAnnotation4_a成员方法的注解并抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0026-rt-reflection-ReflectiongetAnnotationsByType2/ReflectionGetAnnotationsByType2.java b/test/testsuite/ouroboros/reflection_test/RT0026-rt-reflection-ReflectiongetAnnotationsByType2/ReflectionGetAnnotationsByType2.java new file mode 100755 index 0000000000000000000000000000000000000000..d61da41997c4142ccc5bab420a02b3b7857aec01 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0026-rt-reflection-ReflectiongetAnnotationsByType2/ReflectionGetAnnotationsByType2.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetAnnotationsByType2 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0028-rt-reflection-ReflectiongetCanonicalName/ReflectionGetCanonicalName.java b/test/testsuite/ouroboros/reflection_test/RT0028-rt-reflection-ReflectiongetCanonicalName/ReflectionGetCanonicalName.java new file mode 100755 index 0000000000000000000000000000000000000000..0e9af78ff996d40f35b03b2204569c9febeae0c7 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0028-rt-reflection-ReflectiongetCanonicalName/ReflectionGetCanonicalName.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetCanonicalName + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetCanonicalName.java + *- @Title/Destination: Class.getCanonicalName() returns class name by reflection. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0029-rt-reflection-ReflectiongetComponentType/ReflectionGetComponentType.java b/test/testsuite/ouroboros/reflection_test/RT0029-rt-reflection-ReflectiongetComponentType/ReflectionGetComponentType.java new file mode 100755 index 0000000000000000000000000000000000000000..fdfaf8bc64797a05936598633db2479026598477 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0029-rt-reflection-ReflectiongetComponentType/ReflectionGetComponentType.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetComponentType + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0030-rt-reflection-ReflectiongetDeclaredAnnotations1/ReflectionGetDeclaredAnnotations1.java b/test/testsuite/ouroboros/reflection_test/RT0030-rt-reflection-ReflectiongetDeclaredAnnotations1/ReflectionGetDeclaredAnnotations1.java new file mode 100755 index 0000000000000000000000000000000000000000..f2acf5786fb31649b7e830f55123c7a83a73e0e2 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0030-rt-reflection-ReflectiongetDeclaredAnnotations1/ReflectionGetDeclaredAnnotations1.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredAnnotations1 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetDeclaredAnnotations1.java + *- @Title/Destination: Class.GetDeclaredAnnotations() retrieve all annotations from the target class by reflection, + * and result an array of annotations. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0031-rt-reflection-ReflectiongetDeclaredAnnotations2/ReflectionGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/reflection_test/RT0031-rt-reflection-ReflectiongetDeclaredAnnotations2/ReflectionGetDeclaredAnnotations2.java new file mode 100755 index 0000000000000000000000000000000000000000..9b929dd0f8c04e939aa1001a03b80d15217be0ef --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0031-rt-reflection-ReflectiongetDeclaredAnnotations2/ReflectionGetDeclaredAnnotations2.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetDeclaredAnnotations2.java + *- @Title/Destination: Class.GetDeclaredAnnotations() does not result annotations that inherited from parent class. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0033-rt-reflection-ReflectionGetDeclaredAnnotationsByTypeNullPointerException/ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java b/test/testsuite/ouroboros/reflection_test/RT0033-rt-reflection-ReflectionGetDeclaredAnnotationsByTypeNullPointerException/ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..231efffe6958ec08b527e9dadc66a4ad8eaf2615 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0033-rt-reflection-ReflectionGetDeclaredAnnotationsByTypeNullPointerException/ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredAnnotationsByTypeNullPointerException + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetDeclaredAnnotationsByTypeNullPointerException.java + *- @Title/Destination: Class.GetDeclaredAnnotationsByType(null) throws NullPointerException. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0034-rt-reflection-ReflectiongetDeclaredClasses/ReflectionGetDeclaredClasses.java b/test/testsuite/ouroboros/reflection_test/RT0034-rt-reflection-ReflectiongetDeclaredClasses/ReflectionGetDeclaredClasses.java new file mode 100755 index 0000000000000000000000000000000000000000..317dbad6397ed27ce9a8d63fa6fe0c4e091fe668 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0034-rt-reflection-ReflectiongetDeclaredClasses/ReflectionGetDeclaredClasses.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredClasses + *- @RequirementName: Java Reflection + *- @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 + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0035-rt-reflection-ReflectiongetDeclaredField1/ReflectionGetDeclaredField1.java b/test/testsuite/ouroboros/reflection_test/RT0035-rt-reflection-ReflectiongetDeclaredField1/ReflectionGetDeclaredField1.java new file mode 100755 index 0000000000000000000000000000000000000000..c7f309af0d4144686cb732bff2c9462ca4199450 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0035-rt-reflection-ReflectiongetDeclaredField1/ReflectionGetDeclaredField1.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredField1 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0036-rt-reflection-ReflectionGetDeclaredFieldNullPointerException/ReflectionGetDeclaredFieldNullPointerException.java b/test/testsuite/ouroboros/reflection_test/RT0036-rt-reflection-ReflectionGetDeclaredFieldNullPointerException/ReflectionGetDeclaredFieldNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..5b2b791340e6c3ed3831bea48cc94c3cc07dce64 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0036-rt-reflection-ReflectionGetDeclaredFieldNullPointerException/ReflectionGetDeclaredFieldNullPointerException.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredFieldNullPointerException. + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetDeclaredFieldNullPointerException.java + *- @Title/Destination: Class.GetDeclaredField(null) throws NullPointerException. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0037-rt-reflection-ReflectiongetDeclaredFields1/ReflectionGetDeclaredFields1.java b/test/testsuite/ouroboros/reflection_test/RT0037-rt-reflection-ReflectiongetDeclaredFields1/ReflectionGetDeclaredFields1.java new file mode 100755 index 0000000000000000000000000000000000000000..d5678af1f457eda7fa1df1afc3172236200f1e28 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0037-rt-reflection-ReflectiongetDeclaredFields1/ReflectionGetDeclaredFields1.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredFields1 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0038-rt-reflection-ReflectiongetDeclaredFields2/ReflectionGetDeclaredFields.java b/test/testsuite/ouroboros/reflection_test/RT0038-rt-reflection-ReflectiongetDeclaredFields2/ReflectionGetDeclaredFields.java new file mode 100755 index 0000000000000000000000000000000000000000..3d4cdfaef8182c5bbe6184d3cb3238c02b1cd5fb --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0038-rt-reflection-ReflectiongetDeclaredFields2/ReflectionGetDeclaredFields.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredFields + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0039-rt-reflection-ReflectiongetDeclaredMethod1/ReflectionGetDeclaredMethod1.java b/test/testsuite/ouroboros/reflection_test/RT0039-rt-reflection-ReflectiongetDeclaredMethod1/ReflectionGetDeclaredMethod1.java new file mode 100755 index 0000000000000000000000000000000000000000..61666aa9d333530318680c81246b9b318c0b4720 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0039-rt-reflection-ReflectiongetDeclaredMethod1/ReflectionGetDeclaredMethod1.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredMethod1 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0040-rt-reflection-ReflectiongetDeclaredMethod2/ReflectionGetDeclaredMethod2.java b/test/testsuite/ouroboros/reflection_test/RT0040-rt-reflection-ReflectiongetDeclaredMethod2/ReflectionGetDeclaredMethod2.java new file mode 100755 index 0000000000000000000000000000000000000000..4c34db27b952e43171ca10d44712d271368cbb88 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0040-rt-reflection-ReflectiongetDeclaredMethod2/ReflectionGetDeclaredMethod2.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredMethod2 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetDeclaredMethod2.java + *- @Title/Destination: Class.getDeclaredMethod() throws NoSuchMethodException when expected method not found in class; + * Class.getDeclaredMethod(null) throws NullPointerException. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0041-rt-reflection-ReflectiongetDeclaredMethod3/ReflectionGetDeclaredMethod3.java b/test/testsuite/ouroboros/reflection_test/RT0041-rt-reflection-ReflectiongetDeclaredMethod3/ReflectionGetDeclaredMethod3.java new file mode 100755 index 0000000000000000000000000000000000000000..8b4eb446aff3585d9705930f2517cfd38b5bb0ce --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0041-rt-reflection-ReflectiongetDeclaredMethod3/ReflectionGetDeclaredMethod3.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredMethod3 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetDeclaredMethod3.java + *- @Title/Destination: Class.getDeclaredMethod() can return abstract methods of target class + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0042-rt-reflection-ReflectiongetDeclaredMethods1/ReflectionGetDeclaredMethods1.java b/test/testsuite/ouroboros/reflection_test/RT0042-rt-reflection-ReflectiongetDeclaredMethods1/ReflectionGetDeclaredMethods1.java new file mode 100755 index 0000000000000000000000000000000000000000..f2a031904d6b93fb5880afd53f1f486d85dfddbc --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0042-rt-reflection-ReflectiongetDeclaredMethods1/ReflectionGetDeclaredMethods1.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredMethods1 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0043-rt-reflection-ReflectiongetDeclaredMethods2/ReflectionGetDeclaredMethods2.java b/test/testsuite/ouroboros/reflection_test/RT0043-rt-reflection-ReflectiongetDeclaredMethods2/ReflectionGetDeclaredMethods2.java new file mode 100755 index 0000000000000000000000000000000000000000..ebe40343fd1b4e3b83da3d6e9125e3aaab6a3583 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0043-rt-reflection-ReflectiongetDeclaredMethods2/ReflectionGetDeclaredMethods2.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaredMethods2 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetDeclaredMethods2.java + *- @Title/Destination: Class.getDeclaredMethods() does not return inherited methods. + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetDeclaredMethods2类的运行时类clazz; + * -#step2: 通过getDeclaredMethods()方法获取clazz的所有的方法对象,返回值为一个数组,并记为method; + * -#step3: 确定method的长度为0,即返回的数组为空,证明通过getDeclaredMethods()方法不返回继承的方法。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0044-rt-reflection-ReflectiongetDeclaringClass/ReflectionGetDeclaringClass.java b/test/testsuite/ouroboros/reflection_test/RT0044-rt-reflection-ReflectiongetDeclaringClass/ReflectionGetDeclaringClass.java new file mode 100755 index 0000000000000000000000000000000000000000..3a632bf313a31a5bebc84f2feacda26a108bcca6 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0044-rt-reflection-ReflectiongetDeclaringClass/ReflectionGetDeclaringClass.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetDeclaringClass + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0047-rt-reflection-ReflectiongetEnumConstants/ReflectionGetEnumConstants.java b/test/testsuite/ouroboros/reflection_test/RT0047-rt-reflection-ReflectiongetEnumConstants/ReflectionGetEnumConstants.java new file mode 100755 index 0000000000000000000000000000000000000000..b7e8083df8ab1ba217a4b48327d21c956dd80272 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0047-rt-reflection-ReflectiongetEnumConstants/ReflectionGetEnumConstants.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetEnumConstants + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0048-rt-reflection-ReflectiongetField1/ReflectionGetField1.java b/test/testsuite/ouroboros/reflection_test/RT0048-rt-reflection-ReflectiongetField1/ReflectionGetField1.java new file mode 100755 index 0000000000000000000000000000000000000000..4d81a84032a26f26d9a7ff41fb283571bf24592b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0048-rt-reflection-ReflectiongetField1/ReflectionGetField1.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetField1 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetField1.java + *- @Title/Destination: Class.getField() returns a Field object that reflects the specified public member field, + * including the inherited public fields. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0049-rt-reflection-ReflectiongetField2/ReflectionGetField2.java b/test/testsuite/ouroboros/reflection_test/RT0049-rt-reflection-ReflectiongetField2/ReflectionGetField2.java new file mode 100755 index 0000000000000000000000000000000000000000..b4e0cf037339decf6f0a3e8b264ae4f5aec4cb5a --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0049-rt-reflection-ReflectiongetField2/ReflectionGetField2.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetField2 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetField2.java + *- @Title/Destination: If expected Field not found, throws NoSuchFieldException; Class.getField(null) throws + * NullPointerException. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0050-rt-reflection-ReflectiongetFields/ReflectionGetFields.java b/test/testsuite/ouroboros/reflection_test/RT0050-rt-reflection-ReflectiongetFields/ReflectionGetFields.java new file mode 100755 index 0000000000000000000000000000000000000000..5ac1a656b190a61549386c80ea6e934656cb18bb --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0050-rt-reflection-ReflectiongetFields/ReflectionGetFields.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetFields + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0051-rt-reflection-ReflectiongetMethod1/ReflectionGetMethod1.java b/test/testsuite/ouroboros/reflection_test/RT0051-rt-reflection-ReflectiongetMethod1/ReflectionGetMethod1.java new file mode 100755 index 0000000000000000000000000000000000000000..a9aa1fbce2796512d085a80ac702c8257d6ba666 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0051-rt-reflection-ReflectiongetMethod1/ReflectionGetMethod1.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetMethod1 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0052-rt-reflection-ReflectiongetMethod2/ReflectionGetMethod2.java b/test/testsuite/ouroboros/reflection_test/RT0052-rt-reflection-ReflectiongetMethod2/ReflectionGetMethod2.java new file mode 100755 index 0000000000000000000000000000000000000000..7a3f9685e3c31b9280c8c8709633a91d25c736ed --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0052-rt-reflection-ReflectiongetMethod2/ReflectionGetMethod2.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetMethod2 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetMethod2.java + *- @Title/Destination: If expected method is not found, getMethod throws NoSuchMethodException; Class.getMethod(NULL) + * throws NullPointerException. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0053-rt-reflection-ReflectiongetSigners/ReflectionGetSigners.java b/test/testsuite/ouroboros/reflection_test/RT0053-rt-reflection-ReflectiongetSigners/ReflectionGetSigners.java new file mode 100755 index 0000000000000000000000000000000000000000..0341a1be871ee386d81425efaba5dfe1a92b855c --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0053-rt-reflection-ReflectiongetSigners/ReflectionGetSigners.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetSigners + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetSigners.java + *- @Title/Destination: Gets the signers of this class. + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetSigners类的运行时类clazz; + * -#step2: 通过getSigners()方法获取clazz的所有的标签并记为objects; + * -#step3: 确定step2中成功获取到objects,并且objects等于null; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0054-rt-reflection-ReflectiongetSimpleName/ReflectionGetSimpleName.java b/test/testsuite/ouroboros/reflection_test/RT0054-rt-reflection-ReflectiongetSimpleName/ReflectionGetSimpleName.java new file mode 100755 index 0000000000000000000000000000000000000000..a586301f132ad3972c750cf32a5e4df5a3d2abbb --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0054-rt-reflection-ReflectiongetSimpleName/ReflectionGetSimpleName.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionGetSimpleName + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionGetSimpleName.java + *- @Title/Destination: Returns the simple name of the underlying class as given in the source code. + *- @Brief:no: + * -#step1: 通过Class.forName()方法获取GetSimpleName类的运行时类clazz; + * -#step2: 通过getSimpleName()方法获取clazz的类名并记为string; + * -#step3: 确定step2中成功获取到string并且其类型与GetSimpleName类是同一类型; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0056-rt-reflection-ReflectionisArray/ReflectionIsArray.java b/test/testsuite/ouroboros/reflection_test/RT0056-rt-reflection-ReflectionisArray/ReflectionIsArray.java new file mode 100755 index 0000000000000000000000000000000000000000..bb498e479351afeb7990e2be2c70185d0dc9ad60 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0056-rt-reflection-ReflectionisArray/ReflectionIsArray.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionIsArray + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionIsArray.java + *- @Title/Destination: Determines if this Class object represents an array class. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0057-rt-reflection-ReflectionisAssignableFrom1/ReflectionIsAssignableFrom1.java b/test/testsuite/ouroboros/reflection_test/RT0057-rt-reflection-ReflectionisAssignableFrom1/ReflectionIsAssignableFrom1.java new file mode 100755 index 0000000000000000000000000000000000000000..620e20a1029afa3a1a5df1b59cb8c2d83267e715 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0057-rt-reflection-ReflectionisAssignableFrom1/ReflectionIsAssignableFrom1.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionIsAssignableFrom1 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionIsAssignableFrom1.java + *- @Title/Destination: Class.isAssignableFrom(cls) return true when Class is superclass of cls. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0058-rt-reflection-ReflectionisAssignableFrom2/ReflectionIsAssignableFromNullPointerException.java b/test/testsuite/ouroboros/reflection_test/RT0058-rt-reflection-ReflectionisAssignableFrom2/ReflectionIsAssignableFromNullPointerException.java new file mode 100755 index 0000000000000000000000000000000000000000..2734b44b83dec77b0828b28d2c0c6fec34ce561c --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0058-rt-reflection-ReflectionisAssignableFrom2/ReflectionIsAssignableFromNullPointerException.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionIsAssignableFromNullPointerException + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionIsAssignableFromNullPointerException.java + *- @Title/Destination: Class.isAssignableFrom(null) throws NullPointerException. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0059-rt-reflection-ReflectionisLocalClass/ReflectionIsLocalClass.java b/test/testsuite/ouroboros/reflection_test/RT0059-rt-reflection-ReflectionisLocalClass/ReflectionIsLocalClass.java new file mode 100755 index 0000000000000000000000000000000000000000..1a3c53fd7563892867e86d5fa5fc73adc3eba48d --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0059-rt-reflection-ReflectionisLocalClass/ReflectionIsLocalClass.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionIsLocalClass + *- @RequirementName: Java Reflection + *- @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) + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0060-rt-reflection-ReflectionisMemberClass/ReflectionIsMemberClass.java b/test/testsuite/ouroboros/reflection_test/RT0060-rt-reflection-ReflectionisMemberClass/ReflectionIsMemberClass.java new file mode 100755 index 0000000000000000000000000000000000000000..4e08722c3f69063c03436cd7d8e6cdf262d6a1be --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0060-rt-reflection-ReflectionisMemberClass/ReflectionIsMemberClass.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionIsMemberClass + *- @RequirementName: Java Reflection + *- @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). + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0061-rt-reflection-ReflectionisPrimitive/ReflectionIsPrimitive.java b/test/testsuite/ouroboros/reflection_test/RT0061-rt-reflection-ReflectionisPrimitive/ReflectionIsPrimitive.java new file mode 100755 index 0000000000000000000000000000000000000000..81627680f92fbd8f710d12a23e85dec8c6aa76c4 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0061-rt-reflection-ReflectionisPrimitive/ReflectionIsPrimitive.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionIsPrimitive + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionIsPrimitive.java + *- @Title/Destination: Determines if the specified Class object represents a primitive type. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0062-rt-reflection-ReflectionisSynthetic/ReflectionIsSynthetic.java b/test/testsuite/ouroboros/reflection_test/RT0062-rt-reflection-ReflectionisSynthetic/ReflectionIsSynthetic.java new file mode 100755 index 0000000000000000000000000000000000000000..6283e7e7664e3d0783e7eab6ac6fa4239e239c3b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0062-rt-reflection-ReflectionisSynthetic/ReflectionIsSynthetic.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionIsSynthetic + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionIsSynthetic.java + *- @Title/Destination: Returns true if this class is a synthetic class + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0063-rt-reflection-ReflectionnewInstance1/ReflectionNewInstance1.java b/test/testsuite/ouroboros/reflection_test/RT0063-rt-reflection-ReflectionnewInstance1/ReflectionNewInstance1.java new file mode 100755 index 0000000000000000000000000000000000000000..0100ae31b892dc118b70952415d6e5d3f3c78a59 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0063-rt-reflection-ReflectionnewInstance1/ReflectionNewInstance1.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionNewInstance1 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0064-rt-reflection-ReflectionnewInstance2/ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java b/test/testsuite/ouroboros/reflection_test/RT0064-rt-reflection-ReflectionnewInstance2/ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java new file mode 100755 index 0000000000000000000000000000000000000000..9e6381031b7c2d0f82b5b04bf3290af5ce14f05d --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0064-rt-reflection-ReflectionnewInstance2/ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionNewInstanceInstantiationExceptionIllegalAccessException + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionNewInstanceInstantiationExceptionIllegalAccessException.java + *- @Title/Destination: call newInstance() on an interface object throws InstantiationException; if the class's + * constructor is not accessible, throws IllegalAccessException. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0065-rt-reflection-ReflectiontoGenericString/ReflectionToGenericString.java b/test/testsuite/ouroboros/reflection_test/RT0065-rt-reflection-ReflectiontoGenericString/ReflectionToGenericString.java new file mode 100755 index 0000000000000000000000000000000000000000..0992dd1ea70db148ddf151cd4957a6cd40bd2fc9 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0065-rt-reflection-ReflectiontoGenericString/ReflectionToGenericString.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionToGenericString + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionToGenericString.java + *- @Title/Destination: getGenericString() returns a string description of this class, including information about + * modifiers and type parameters. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0066-rt-reflection-ReflectiontoString/ReflectionToString.java b/test/testsuite/ouroboros/reflection_test/RT0066-rt-reflection-ReflectiontoString/ReflectionToString.java new file mode 100755 index 0000000000000000000000000000000000000000..abc9b44d25101e355df81ec0fae571fd0c967f20 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0066-rt-reflection-ReflectiontoString/ReflectionToString.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionToString + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionToString.java + *- @Title/Destination: To obtain a class for string output by reflection. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0068-rt-reflection-RTConstructorgetAnnotation2/RTConstructorGetAnnotation2.java b/test/testsuite/ouroboros/reflection_test/RT0068-rt-reflection-RTConstructorgetAnnotation2/RTConstructorGetAnnotation2.java new file mode 100755 index 0000000000000000000000000000000000000000..6ab61fc2726b578636d5495df5de34e7ee64660f --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0068-rt-reflection-RTConstructorgetAnnotation2/RTConstructorGetAnnotation2.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTConstructorGetAnnotation2 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0070-rt-reflection-RTConstructorgetDeclaredAnnotations2/RTConstructorGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/reflection_test/RT0070-rt-reflection-RTConstructorgetDeclaredAnnotations2/RTConstructorGetDeclaredAnnotations2.java new file mode 100755 index 0000000000000000000000000000000000000000..6d2600db5b37ee2bed7d4ab8f0f2f451589f044c --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0070-rt-reflection-RTConstructorgetDeclaredAnnotations2/RTConstructorGetDeclaredAnnotations2.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTConstructorGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTConstructorGetDeclaredAnnotations2.java + *- @Title/Destination: Constructor.getDeclaredAnnotations() does not return annotations inherited from parent class. + *- @Brief:no: + * -#step1: 定义两个类,有父子关系,父类含有注解的构造方法,子类的构造方法没有注解。 + * -#step2:调用getConstructor(Class... parameterTypes)从子类中获取构造方法1。 + * -#step3:调用getDeclaredAnnotations()获取注解数组,判断数组长度为0。 + * -#step4:调用getConstructor(Class... parameterTypes)从子类中获取构造方法2。 + * -#step5:调用getDeclaredAnnotations()获取注解数组,判断数组长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0074-rt-reflection-RTFieldget1/RTFieldGet1.java b/test/testsuite/ouroboros/reflection_test/RT0074-rt-reflection-RTFieldget1/RTFieldGet1.java new file mode 100755 index 0000000000000000000000000000000000000000..f3fe746766fee15c03b8cfb98000c9cfce7cedcf --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0074-rt-reflection-RTFieldget1/RTFieldGet1.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldGet1 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldGet1.java + *- @Title/Destination: Field.get() returns the value of the field represented by this field on the target object. + *- @Brief:no: + * -#step1: 创建类FieldGet1_a和它的子类FieldGet1。 + * -#step2:通过forName()方法加载FieldGet1并调用newInstance()生成实例对象。 + * -#step3:通过getField()方法获取实例对象中的成员变量,并确认值正确。 + * -#step4:通过forName()方法加载FieldGet1_a并生成实例对象,通过getField()方法获取对应的成员变量并核对值正确。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0075-rt-reflection-RTFieldget2/RTFieldGet2.java b/test/testsuite/ouroboros/reflection_test/RT0075-rt-reflection-RTFieldget2/RTFieldGet2.java new file mode 100755 index 0000000000000000000000000000000000000000..1b3bb231516d32e58b77a9d226b309eebdca884d --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0075-rt-reflection-RTFieldget2/RTFieldGet2.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldGet2 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0076-rt-reflection-RTFieldget3/RTFieldGet3.java b/test/testsuite/ouroboros/reflection_test/RT0076-rt-reflection-RTFieldget3/RTFieldGet3.java new file mode 100755 index 0000000000000000000000000000000000000000..3b7315d2d384a7ea890c30c71a943c111d545f3a --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0076-rt-reflection-RTFieldget3/RTFieldGet3.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldGet3 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldGet3.java + *- @Title/Destination: If the filed is not given a value, the default value is returned by reflection。 + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0077-rt-reflection-RTFieldgetAnnotation/RTFieldGetAnnotation1.java b/test/testsuite/ouroboros/reflection_test/RT0077-rt-reflection-RTFieldgetAnnotation/RTFieldGetAnnotation1.java new file mode 100755 index 0000000000000000000000000000000000000000..35d92d7d7e24d2fac03ef457abb0308c86e9b053 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0077-rt-reflection-RTFieldgetAnnotation/RTFieldGetAnnotation1.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldGetAnnotation1 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldGetAnnotation1.java + *- @Title/Destination: Field.GetAnnotation() returns null when the expected annotation is not present. + *- @Brief:no: + * -#step1: 定义含注解类FieldGetAnnotation1。 + * -#step2: 通过调用forName()方法加载类FieldGetAnnotation1。 + * -#step3: 通过调用getField()获取对应名称的成员变量。 + * -#step4: 调用getAnnotation(Class annotationClass),annotationClass为不匹配的类型,确认返回null。 + * -#step5: 调用返回空注解类型进行.number()的调用,确认抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0079-rt-reflection-RTFieldgetDeclaredAnnotations2/RTFieldGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/reflection_test/RT0079-rt-reflection-RTFieldgetDeclaredAnnotations2/RTFieldGetDeclaredAnnotations2.java new file mode 100755 index 0000000000000000000000000000000000000000..3bec5336fa97930987c9639235db48b6dbccd953 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0079-rt-reflection-RTFieldgetDeclaredAnnotations2/RTFieldGetDeclaredAnnotations2.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldGetDeclaredAnnotations2.java + *- @Title/Destination: Field.GetDeclaredAnnotations() ignores inherited annotations. + *- @Brief:no: + * -#step1: 定义含注解类FieldGetDeclaredAnnotations2,定义含注解的类FieldGetDeclaredAnnotations2的子类 + * FieldGetDeclaredAnnotations2_a。 + * -#step2: 通过调用forName()方法加载类FieldGetDeclaredAnnotations2_a。 + * -#step3: 通过调用 getField()获取对应名称的成员变量。 + * -#step4: 通过调用getAnnotation(Class annotationClass)获取注解,调用equals()方法进行判断获取正确。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0080-rt-reflection-RTFieldgetDeclaringClass/RTFieldGetDeclaringClass.java b/test/testsuite/ouroboros/reflection_test/RT0080-rt-reflection-RTFieldgetDeclaringClass/RTFieldGetDeclaringClass.java new file mode 100755 index 0000000000000000000000000000000000000000..d9fffc527c2a9ed58937e53a00c4a654bf170a55 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0080-rt-reflection-RTFieldgetDeclaringClass/RTFieldGetDeclaringClass.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldGetDeclaringClass + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldGetDeclaringClass.java + *- @Title/Destination: Field.GetDeclaringClass() returns the class object of the class declaring the field represented + * by this Field object. + *- @Brief:no: + * -#step1: 定义类FieldGetDeclaringClass。 + * -#step2: 通过调用forName()方法加载类FieldGetDeclaringClass。 + * -#step3: 通过调用 getField()、getDeclaredField()获取对应名称的成员变量。 + * -#step4: 通过调用FieldGetDeclaringClass()获取类对象,调用equals()方法进行判断获取正确。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0081-rt-reflection-RTFieldgetModifiers/RTFieldGetModifiers.java b/test/testsuite/ouroboros/reflection_test/RT0081-rt-reflection-RTFieldgetModifiers/RTFieldGetModifiers.java new file mode 100755 index 0000000000000000000000000000000000000000..671a1df19bbb42f01a384499e94abf864fb37894 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0081-rt-reflection-RTFieldgetModifiers/RTFieldGetModifiers.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldGetModifiers + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldGetModifiers.java + *- @Title/Destination: Field.GetModifiers() Returns the Java language modifiers for the field represented by this Field + * object, as an integer. + *- @Brief:no: + * -#step1: 定义含受保护的今天成员变量的类FieldGetModifiers。 + * -#step2: 通过调用forName()方法加载类FieldGetModifiers。 + * -#step3: 通过调用getField()、getDeclaredField()获取对应名称的成员变量。 + * -#step4: 通过调用getModifiers()获取对应字段的Java语言修饰符,调用equals()方法进行判断描述正确。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0082-rt-reflection-RTFieldgetName/RTFieldGetName.java b/test/testsuite/ouroboros/reflection_test/RT0082-rt-reflection-RTFieldgetName/RTFieldGetName.java new file mode 100755 index 0000000000000000000000000000000000000000..f2743b4661839866f7aa56eb26e7df887c244ec3 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0082-rt-reflection-RTFieldgetName/RTFieldGetName.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldGetName + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldGetName.java + *- @Title/Destination: Field.GetName() Returns the name of the field represented by this Field object. + *- @Brief:no: + * -#step1: 定义类FieldGetName。 + * -#step2: 通过调用forName()方法加载类FieldGetModifiers。 + * -#step3: 通过调用getField()、getDeclaredField()获取对应名称的成员变量。 + * -#step4: 通过调用getName()方法获取对应字段,调用equals()方法进行判断字段值正确。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0083-rt-reflection-RTFieldgetType/RTFieldGetType.java b/test/testsuite/ouroboros/reflection_test/RT0083-rt-reflection-RTFieldgetType/RTFieldGetType.java new file mode 100755 index 0000000000000000000000000000000000000000..31747d0b461336a4f0cbc71874e8ff3c0f54c744 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0083-rt-reflection-RTFieldgetType/RTFieldGetType.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldGetType + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldGetType.java + *- @Title/Destination: Field.GetType() Returns a Class object that identifies the declared type for the field + * represented by this Field object. + *- @Brief:no: + * -#step1: 定义类FieldGetType。 + * -#step2: 调用forName()方法加载类FieldGetType。 + * -#step3: 调用getField()、getDeclaredField()方法获取对应的成员变量。 + * -#step4: 调用getType().getName()获取相应的类型,调用equals()方法与相应的类型比较,判断通过字段值正确。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0084-rt-reflection-RTFieldset1/RTFieldSet1.java b/test/testsuite/ouroboros/reflection_test/RT0084-rt-reflection-RTFieldset1/RTFieldSet1.java new file mode 100755 index 0000000000000000000000000000000000000000..0030aad970a05744658144f3a12f449b9d601043 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0084-rt-reflection-RTFieldset1/RTFieldSet1.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldSet1 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldSet1.java + *- @Title/Destination: Field.set() sets the field on the specified object argument to the new value. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0085-rt-reflection-RTFieldset2/RTFieldSet2.java b/test/testsuite/ouroboros/reflection_test/RT0085-rt-reflection-RTFieldset2/RTFieldSet2.java new file mode 100755 index 0000000000000000000000000000000000000000..1faec4e7e314dfcb142ced14dc05cb4a935d9664 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0085-rt-reflection-RTFieldset2/RTFieldSet2.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldSet2 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0086-rt-reflection-RTFieldset3/RTFieldSet3.java b/test/testsuite/ouroboros/reflection_test/RT0086-rt-reflection-RTFieldset3/RTFieldSet3.java new file mode 100755 index 0000000000000000000000000000000000000000..307f6d0b72af5da72f82e855e64a5d24b54c637b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0086-rt-reflection-RTFieldset3/RTFieldSet3.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldSet3 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldSet3.java + *- @Title/Destination: Setting on a final field throws IllegalAccessException. + *- @Brief:no: + * -#step1: 定义类FieldSet3_a,包含final修饰的变量。定义类FieldSet3_a的子类FieldSet3,包含final修饰的变量。 + * -#step2: 通过调用forName()方法加载类FieldSet3,调用newInstance()方法生成实例对象。 + * -#step3: 通过调用 getField()获取对应名称的成员变量,调用set()方法设置变量的值,抛出IllegalAccessException。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0087-rt-reflection-RTFieldset4/RTFieldSet4.java b/test/testsuite/ouroboros/reflection_test/RT0087-rt-reflection-RTFieldset4/RTFieldSet4.java new file mode 100755 index 0000000000000000000000000000000000000000..1d1638e2bbb8fa0d38a78de2220fd46da4a3ae75 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0087-rt-reflection-RTFieldset4/RTFieldSet4.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldSet4 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldSet4.java + *- @Title/Destination: To set a value with no corresponding object on a static field by reflection. + *- @Brief:no: + * -#step1: 定义含私有变量的类FieldSet4。 + * -#step2: 通过调用forName()方法加载类FieldSet4,调用newInstance()方法生成实例对象。 + * -#step3: 通过调用getDeclaredField()获取对应名称的成员变量,调用set()方法设置变量的值。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0089-rt-reflection-RTFieldtoString/RTFieldToString.java b/test/testsuite/ouroboros/reflection_test/RT0089-rt-reflection-RTFieldtoString/RTFieldToString.java new file mode 100755 index 0000000000000000000000000000000000000000..3ee2dfc3f7132dff5642ea193979eb5e20b12c00 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0089-rt-reflection-RTFieldtoString/RTFieldToString.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTFieldToString + *- @RequirementName: Java Reflection + *- @TestCaseName:RTFieldToString.java + *- @Title/Destination: Field.ToString() returns a string describing this Field. + *- @Brief:no: + * -#step1: 定义含私有变量的类FieldToGenericString。 + * -#step2: 通过调用forName()方法加载类FieldToGenericString,调用getField()、getDeclaredField()分别获取相应的成员。 + * -#step3: 通过调用toString()()返回对象的string,确认字符串描述正确。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0091-rt-reflection-RTMethodgetAnnotation2/RTMethodGetAnnotation2.java b/test/testsuite/ouroboros/reflection_test/RT0091-rt-reflection-RTMethodgetAnnotation2/RTMethodGetAnnotation2.java new file mode 100755 index 0000000000000000000000000000000000000000..352348e88ace2785de440b12cf0407901588b44c --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0091-rt-reflection-RTMethodgetAnnotation2/RTMethodGetAnnotation2.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTMethodGetAnnotation2 + *- @RequirementName: Java Reflection + *- @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 + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0093-rt-reflection-RTMethodgetDeclaredAnnotations2/RTMethodGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/reflection_test/RT0093-rt-reflection-RTMethodgetDeclaredAnnotations2/RTMethodGetDeclaredAnnotations2.java new file mode 100755 index 0000000000000000000000000000000000000000..d6365e03bd41be7e83b8f0c99a9f20b542b364d4 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0093-rt-reflection-RTMethodgetDeclaredAnnotations2/RTMethodGetDeclaredAnnotations2.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTMethodGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @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 + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0095-rt-reflection-RTMethodgetParameterCount/RTMethodGetParameterCount.java b/test/testsuite/ouroboros/reflection_test/RT0095-rt-reflection-RTMethodgetParameterCount/RTMethodGetParameterCount.java new file mode 100755 index 0000000000000000000000000000000000000000..89397bf8ecf79e25ed7cb5280e09ac4274a94ded --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0095-rt-reflection-RTMethodgetParameterCount/RTMethodGetParameterCount.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTMethodGetParameterCount + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0097-rt-reflection-RTMethonisDefault/RTMethodIsDefault.java b/test/testsuite/ouroboros/reflection_test/RT0097-rt-reflection-RTMethonisDefault/RTMethodIsDefault.java new file mode 100755 index 0000000000000000000000000000000000000000..90826765599408e0942a64b917696d0dc2548cca --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0097-rt-reflection-RTMethonisDefault/RTMethodIsDefault.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTMethodIsDefault + *- @RequirementName: Java Reflection + *- @TestCaseName:RTMethodIsDefault.java + *- @Title/Destination: Verify through reflection whether the default method in the interface. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0099-rt-reflection-RTModifierparameterModifiers/RTModifierParameterModifiers.java b/test/testsuite/ouroboros/reflection_test/RT0099-rt-reflection-RTModifierparameterModifiers/RTModifierParameterModifiers.java new file mode 100755 index 0000000000000000000000000000000000000000..1a45cc1d018a45ba437259b1041bfe44367157af --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0099-rt-reflection-RTModifierparameterModifiers/RTModifierParameterModifiers.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTModifierParameterModifiers + *- @RequirementName: Java Reflection + *- @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. + *- @Brief:no: + * -#step1: 经判断得知Modifier.parameterModifiers()的返回值为16,即修饰符类的参数修饰符的整数值为16; + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0101-rt-reflection-RTParametergetAnnotation2/RTParameterGetAnnotation2.java b/test/testsuite/ouroboros/reflection_test/RT0101-rt-reflection-RTParametergetAnnotation2/RTParameterGetAnnotation2.java new file mode 100755 index 0000000000000000000000000000000000000000..63365e6f29511ea990999615fae7fffc37405414 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0101-rt-reflection-RTParametergetAnnotation2/RTParameterGetAnnotation2.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTParameterGetAnnotation2 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTParameterGetAnnotation2.java + *- @Title/Destination: If expected annotation not exist, getAnnotation() return null; if the given annotation class is + * null, getAnnotation() throws NullPointerException; + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0104-rt-reflection-RTParametergetAnnotationsByType2/RTParameterGetAnnotationsByType2.java b/test/testsuite/ouroboros/reflection_test/RT0104-rt-reflection-RTParametergetAnnotationsByType2/RTParameterGetAnnotationsByType2.java new file mode 100755 index 0000000000000000000000000000000000000000..352a4c5fe321fb7e7bf12ec1532a001bc183351d --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0104-rt-reflection-RTParametergetAnnotationsByType2/RTParameterGetAnnotationsByType2.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTParameterGetAnnotationsByType2 + *- @RequirementName: Java Reflection + *- @TestCaseName:RTParameterGetAnnotationsByType2.java + *- @Title/Destination:Parameter.getAnnotationsByType() return an array of length zero if no expected annotation found; + * getAnnotationsByType(null) throws NullPointerException. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0107-rt-reflection-RTParametergetDeclaredAnnotations2/RTParameterGetDeclaredAnnotations2.java b/test/testsuite/ouroboros/reflection_test/RT0107-rt-reflection-RTParametergetDeclaredAnnotations2/RTParameterGetDeclaredAnnotations2.java new file mode 100755 index 0000000000000000000000000000000000000000..f055e7950a2156b36f9723d09f8ef0a89eab4fde --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0107-rt-reflection-RTParametergetDeclaredAnnotations2/RTParameterGetDeclaredAnnotations2.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTParameterGetDeclaredAnnotations2 + *- @RequirementName: Java Reflection + *- @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. + *- @Brief:no: + * -#step1:创建一个类1,含有注解和无注解的构造方法和有注解方法。创建一个子类2继承类1,含有注解和无注解的构造方法和有注 + * 解方法。创建子类3继承类2,重写构造方法和方法,均为无注解。 + * -#step2:通过调用getDeclaredConstructor获取自定义类3的构造方法,通过调用getParameters()获取参数数组,调用 + * getDeclaredAnnotations()获取注解数组,检查数组长度为0。 + * -#step3:通过调用getMethod获取自定义类的方法,通过调用getParameters()获取参数数组,调用getDeclaredAnnotations()获取注 + * 解数组,检查数组长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0109-rt-reflection-RTProxygetProxyClass1/RTProxyGetProxyClass1.java b/test/testsuite/ouroboros/reflection_test/RT0109-rt-reflection-RTProxygetProxyClass1/RTProxyGetProxyClass1.java new file mode 100755 index 0000000000000000000000000000000000000000..c7fb99231da218a9cf9d0213c81754fec3b4da4b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0109-rt-reflection-RTProxygetProxyClass1/RTProxyGetProxyClass1.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: RTProxyGetProxyClass1 + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0110-rt-reflection-ClassgetDeclaredAnnotationNPE/ClassGetDeclaredAnnotationNPE.java b/test/testsuite/ouroboros/reflection_test/RT0110-rt-reflection-ClassgetDeclaredAnnotationNPE/ClassGetDeclaredAnnotationNPE.java new file mode 100755 index 0000000000000000000000000000000000000000..ada7c6ed1845c7228644c46f6c3102a623ee4284 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0110-rt-reflection-ClassgetDeclaredAnnotationNPE/ClassGetDeclaredAnnotationNPE.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassGetDeclaredAnnotationNPE + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassGetDeclaredAnnotationNPE.java + *- @Title/Destination: Class.getDeclaredAnnotation(null) throws NullPointerException + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0111-rt-reflection-reflectClasssetisAssignableFrom/ClassIsAssignableFromNPE.java b/test/testsuite/ouroboros/reflection_test/RT0111-rt-reflection-reflectClasssetisAssignableFrom/ClassIsAssignableFromNPE.java new file mode 100755 index 0000000000000000000000000000000000000000..452adedbffb9b1524c338eed3ad4fb42d680d614 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0111-rt-reflection-reflectClasssetisAssignableFrom/ClassIsAssignableFromNPE.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassIsAssignableFromNPE + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassIsAssignableFromNPE.java + *- @Title/Destination: Test isAssignableFrom( null ) throws NullPointerException of class. + *- @Brief:no: + * -#step1: 定义一个int数组intArray,获取intArray的class。 + * -#step2:调用isAssignableFrom(Class cls), cls为null。 + * -#step3:确认抛出NullPointerException。 + *- @Expect: 0\n + *- @Priority: High + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0112-rt-reflection-ClassGetAnnotationsByType/ClassGetAnnotationsByType.java b/test/testsuite/ouroboros/reflection_test/RT0112-rt-reflection-ClassGetAnnotationsByType/ClassGetAnnotationsByType.java new file mode 100755 index 0000000000000000000000000000000000000000..f3f43ce9cee8d218b70a5a540ac1428bed4cd2b1 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0112-rt-reflection-ClassGetAnnotationsByType/ClassGetAnnotationsByType.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassGetAnnotationsByType + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassGetAnnotationsByType.java + * - @Title/Destination: Class have no Annotation and method have annotation, Class.getAnnotationsByType() return an + * array of length 0. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest0。 + * -#step2:获取class MyTargetTest0。 + * -#step3:调用getAnnotationsByType(Class annotationClass)获取类型为MyTarget的注解数组。 + * -#step4:确认获取的注解数组个数大于0。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0115-rt-reflection-ClassGetEnumConstants/ClassGetEnumConstants.java b/test/testsuite/ouroboros/reflection_test/RT0115-rt-reflection-ClassGetEnumConstants/ClassGetEnumConstants.java new file mode 100755 index 0000000000000000000000000000000000000000..76bba4215768b969d76a07d2be4e40414e26bf5c --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0115-rt-reflection-ClassGetEnumConstants/ClassGetEnumConstants.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassGetEnumConstants + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassGetEnumConstants.java + * - @Title/Destination: Class getEnumConstants() return null when there is no enum in the class。 + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest3。 + * -#step2:获取class MyTargetTest3。 + * -#step3:调用getEnumConstants()获取枚举类的元素。 + * -#step4:确认返回为空。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0117-rt-reflection-ClassGetTypeParameters/ClassGetTypeParameters.java b/test/testsuite/ouroboros/reflection_test/RT0117-rt-reflection-ClassGetTypeParameters/ClassGetTypeParameters.java new file mode 100755 index 0000000000000000000000000000000000000000..625b73249bf7388a7b4328cdab846ef8254a2f7a --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0117-rt-reflection-ClassGetTypeParameters/ClassGetTypeParameters.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassGetTypeParameters + *- @RequirementName: Java Reflection + *- @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. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest5。 + * -#step2:获取class MyTargetTest5。 + * -#step3:调用getTypeParameters()获取TypeVariable对象的一个数组。 + * -#step4:确认返回的数组的长度为0。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0118-rt-reflection-ClassToGenericString/ClassToGenericString.java b/test/testsuite/ouroboros/reflection_test/RT0118-rt-reflection-ClassToGenericString/ClassToGenericString.java new file mode 100755 index 0000000000000000000000000000000000000000..50d7818cf1e69ad566383058d9cf87f5820265ab --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0118-rt-reflection-ClassToGenericString/ClassToGenericString.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassToGenericString + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassToGenericString.java + * - @Title/Destination: Class.toGenericString() returns a string describing this Class, including information about + * modifiers and type parameters. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest5。 + * -#step2:获取class MyTargetTest5。 + * -#step3:调用toGenericString()获取描述此class的字符串。 + * -#step4:确认返回的描述正确。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0121-rt-reflection-ConstructorGetExceptionTypes/ConstructorGetExceptionTypes.java b/test/testsuite/ouroboros/reflection_test/RT0121-rt-reflection-ConstructorGetExceptionTypes/ConstructorGetExceptionTypes.java new file mode 100755 index 0000000000000000000000000000000000000000..ff151d735934f20e502a2e802b1d776fa1dbbadf --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0121-rt-reflection-ConstructorGetExceptionTypes/ConstructorGetExceptionTypes.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorGetExceptionTypes.java + *- @RequirementName: Java Reflection + *- @TestCaseName:ConstructorGetExceptionTypes.java + * - @Title/Destination: Constructor.getExceptionTypes() returns an array of length 0 if the executable declares no + * exceptions in its throws clause. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest02。 + * -#step2:通过调用getConstructor(Class[])从内部类MyTargetTest02中获取对应的构造方法。 + * -#step3:调用getExceptionTypes()获取抛出的异常类型的Class对象的数组。 + * -#step4:确认返回的数组长度是0。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0122-rt-reflection-ConstructorGetTypeParameters/ConstructorGetTypeParameters.java b/test/testsuite/ouroboros/reflection_test/RT0122-rt-reflection-ConstructorGetTypeParameters/ConstructorGetTypeParameters.java new file mode 100755 index 0000000000000000000000000000000000000000..cdd295731b5070303921d72af565ce7c58135b23 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0122-rt-reflection-ConstructorGetTypeParameters/ConstructorGetTypeParameters.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorGetTypeParameters.java + *- @RequirementName: Java Reflection + *- @TestCaseName:ConstructorGetTypeParameters.java + * - @Title/Destination: Constructor.getTypeParameters() returns an array of length 0 if the underlying generic + * declaration declares no type variables. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest03。 + * -#step2:通过调用getConstructor(Class[])从内部类MyTargetTest03中获取对应的构造方法。 + * -#step3:调用getTypeParameters()获取TypeVariable对象的数组。 + * -#step4:确认返回的数组长度是0。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0123-rt-reflection-ConstructorToGenericString/ConstructorToGenericString.java b/test/testsuite/ouroboros/reflection_test/RT0123-rt-reflection-ConstructorToGenericString/ConstructorToGenericString.java new file mode 100755 index 0000000000000000000000000000000000000000..6697fa5fb2585fefd1ea9f5b24de6926a3b97007 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0123-rt-reflection-ConstructorToGenericString/ConstructorToGenericString.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorToGenericString.java + *- @RequirementName: Java Reflection + *- @TestCaseName:ConstructorToGenericString.java + * - @Title/Destination: Constructor.toGenericString() returns a string describing this Constructor, including type + * parameters. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest04。 + * -#step2:通过调用getConstructor(Class[])从内部类MyTargetTest04中获取对应的构造方法。 + * -#step3:调用toGenericString()获取描述此Field的字符串。 + * -#step4:确认返回的描述正确。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0128-rt-reflection-FieldToGenericString/FieldToGenericString.java b/test/testsuite/ouroboros/reflection_test/RT0128-rt-reflection-FieldToGenericString/FieldToGenericString.java new file mode 100755 index 0000000000000000000000000000000000000000..3626fdce8ceb33eb8d438da598137a4e99a1d579 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0128-rt-reflection-FieldToGenericString/FieldToGenericString.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldToGenericString + *- @RequirementName: Java Reflection + *- @TestCaseName:FieldToGenericString.java + * - @Title/Destination: Field.toGenericString() returns a string describing this Field, including its generic type. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest10。 + * -#step2:通过调用getField()从内部类MyTargetTest10中获取home。 + * -#step3:调用toGenericString()获取描述此Field的字符串。 + * -#step4:确认返回的描述正确。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0131-rt-reflection-MethodgetDefaultValue/MethodGetDefaultValue.java b/test/testsuite/ouroboros/reflection_test/RT0131-rt-reflection-MethodgetDefaultValue/MethodGetDefaultValue.java new file mode 100755 index 0000000000000000000000000000000000000000..bd05e1f36f26cac9c9210f690a9af7d57d66867b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0131-rt-reflection-MethodgetDefaultValue/MethodGetDefaultValue.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodGetDefaultValue + *- @RequirementName: Java Reflection + *- @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。 + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest13。 + * -#step2:通过调用getMethod()从内部类MyTargetTest13中获取MyTargetTest_1。 + * -#step3:调用getDefaultValue()获取注解成员的默认值。 + * -#step4:确认获取为null,无异常抛出。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0132-rt-reflection-MethodGetParameterCount/MethodGetParameterCount.java b/test/testsuite/ouroboros/reflection_test/RT0132-rt-reflection-MethodGetParameterCount/MethodGetParameterCount.java new file mode 100755 index 0000000000000000000000000000000000000000..5d2c635045069bda1890223f6931ca422c633d6e --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0132-rt-reflection-MethodGetParameterCount/MethodGetParameterCount.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodGetParameterCount + *- @RequirementName: Java Reflection + *- @TestCaseName:MethodGetParameterCount.java + * - @Title/Destination: Method.getParameterCount() returns the number of formal parameters. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest14。 + * -#step2:通过调用getMethod()从内部类MyTargetTest14中获取MyTargetTest_1。 + * -#step3:调用getParameterCount()获取参数个数。 + * -#step4:确认返回的参数个数是0。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0133-rt-reflection-MethodGetTypeParameters/MethodGetTypeParameters.java b/test/testsuite/ouroboros/reflection_test/RT0133-rt-reflection-MethodGetTypeParameters/MethodGetTypeParameters.java new file mode 100755 index 0000000000000000000000000000000000000000..59eebfd5cc5ef10a8ead4452c88ad6ef877e1559 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0133-rt-reflection-MethodGetTypeParameters/MethodGetTypeParameters.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodGetTypeParameters + *- @RequirementName: Java Reflection + *- @TestCaseName:MethodGetTypeParameters.java + * - @Title/Destination: Method.getTypeParameters() returns an array of TypeVariable objects. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest15。 + * -#step2:通过调用getMethod()从内部类MyTargetTest15中获取MyTargetTest_1。 + * -#step3:调用getTypeParameters()获取TypeVariable对象的数组。 + * -#step4:确认返回的数组长度是0。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0134-rt-reflection-MethodIsDefault/MethodIsDefault.java b/test/testsuite/ouroboros/reflection_test/RT0134-rt-reflection-MethodIsDefault/MethodIsDefault.java new file mode 100755 index 0000000000000000000000000000000000000000..5e78591e36824b924e905e276c8b6beb45dc5027 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0134-rt-reflection-MethodIsDefault/MethodIsDefault.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodIsDefault + *- @RequirementName: Java Reflection + *- @TestCaseName:MethodIsDefault.java + * - @Title/Destination: Method.isDefault() Returns true if this method is a default method。 + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest16。 + * -#step2:通过调用getMethod()从内部类MyTargetTest16中获取MyTargetTest_1。 + * -#step3:调用isDefault()判断是否是default method。 + * -#step4:确认返回false。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0135-rt-reflection-MethodToGenericString/MethodToGenericString.java b/test/testsuite/ouroboros/reflection_test/RT0135-rt-reflection-MethodToGenericString/MethodToGenericString.java new file mode 100755 index 0000000000000000000000000000000000000000..b6f858327a34c4dc2b02ab89e3afa70396dbb1ff --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0135-rt-reflection-MethodToGenericString/MethodToGenericString.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodToGenericString + *- @RequirementName: Java Reflection + *- @TestCaseName:MethodToGenericString.java + * - @Title/Destination: Method.toGenericString() Returns a string describing this Method, including type parameters. + * - @Brief:no: + * -#step1: 定义含注解的内部类MyTargetTest15。 + * -#step2:通过调用getMethod()从内部类MyTargetTest15中获取MyTargetTest_1。 + * -#step3:调用toGenericString()获取描述此Method的字符串。 + * -#step4:确认返回的描述正确。 + * - @Expect: 0\n + * - @Priority: High + * - @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0142-rt-reflection-ReflectionAnnotationGetClass/ReflectionAnnotationGetClass.java b/test/testsuite/ouroboros/reflection_test/RT0142-rt-reflection-ReflectionAnnotationGetClass/ReflectionAnnotationGetClass.java new file mode 100755 index 0000000000000000000000000000000000000000..d3bf18567e945d9d98e5cdd10e0d328350eb4eb7 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0142-rt-reflection-ReflectionAnnotationGetClass/ReflectionAnnotationGetClass.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + *- @TestCaseID: ReflectionAnnotationGetClass + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionAnnotationGetClass.java + *- @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 + *- @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 diff --git a/test/testsuite/ouroboros/reflection_test/RT0143-rt-reflection-ClinitClassNewInstance/ClassInitClassNewInstance.java b/test/testsuite/ouroboros/reflection_test/RT0143-rt-reflection-ClinitClassNewInstance/ClassInitClassNewInstance.java new file mode 100755 index 0000000000000000000000000000000000000000..74a9c124c5ed36b6396c474432a7f0a1af4561c5 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0143-rt-reflection-ClinitClassNewInstance/ClassInitClassNewInstance.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitClassNewInstance + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitClassNewInstance.java + *- @Title/Destination: When call Class.newInstance, class is initialized; when call other methods of Class, class is + * not initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0144-rt-reflection-ClinitConstructorNewInstance/ClassInitConstructorNewInstance.java b/test/testsuite/ouroboros/reflection_test/RT0144-rt-reflection-ClinitConstructorNewInstance/ClassInitConstructorNewInstance.java new file mode 100755 index 0000000000000000000000000000000000000000..d4b0b61a435ff33792382e98d96a514c3b8c452d --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0144-rt-reflection-ClinitConstructorNewInstance/ClassInitConstructorNewInstance.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitConstructorNewInstance + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitConstructorNewInstance.java + *- @Title/Destination: When call Constructor.newInstance, class is initialized; when call other methods of Constructor, + * class is not initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0145-rt-reflection-ClinitFieldGetBooleanStatic/ClassInitFieldGetBooleanStatic.java b/test/testsuite/ouroboros/reflection_test/RT0145-rt-reflection-ClinitFieldGetBooleanStatic/ClassInitFieldGetBooleanStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..1b0e61f18d431a214e5b7d01eab2dcc797a2654b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0145-rt-reflection-ClinitFieldGetBooleanStatic/ClassInitFieldGetBooleanStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetBooleanStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldGetBooleanStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getBoolean(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0146-rt-reflection-ClinitFieldGetByteStatic/ClassInitFieldGetByteStatic.java b/test/testsuite/ouroboros/reflection_test/RT0146-rt-reflection-ClinitFieldGetByteStatic/ClassInitFieldGetByteStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..69a48757c3c7ba7c7258fc6c1f33c5f2c285ee28 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0146-rt-reflection-ClinitFieldGetByteStatic/ClassInitFieldGetByteStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetByteStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldGetByteStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getByte(), class One is initialized + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0147-rt-reflection-ClinitFieldGetCharStatic/ClassInitFieldGetCharStatic.java b/test/testsuite/ouroboros/reflection_test/RT0147-rt-reflection-ClinitFieldGetCharStatic/ClassInitFieldGetCharStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..05da220c258cb99dcbc225b424bde799f2bd1cde --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0147-rt-reflection-ClinitFieldGetCharStatic/ClassInitFieldGetCharStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetCharStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldGetCharStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getChar(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0148-rt-reflection-ClinitFieldGetDoubleStatic/ClassInitFieldGetDoubleStatic.java b/test/testsuite/ouroboros/reflection_test/RT0148-rt-reflection-ClinitFieldGetDoubleStatic/ClassInitFieldGetDoubleStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..007aa3a5be4bcec373ccfe3a60061607ef4dc3b1 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0148-rt-reflection-ClinitFieldGetDoubleStatic/ClassInitFieldGetDoubleStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetDoubleStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldGetDoubleStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getDouble(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0149-rt-reflection-ClinitFieldGetFloatStatic/ClassInitFieldGetFloatStatic.java b/test/testsuite/ouroboros/reflection_test/RT0149-rt-reflection-ClinitFieldGetFloatStatic/ClassInitFieldGetFloatStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..942673f3385b17a2365a3e4573483a86bf4d7ca7 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0149-rt-reflection-ClinitFieldGetFloatStatic/ClassInitFieldGetFloatStatic.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetFloatStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldGetFloatStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getFloat(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0150-rt-reflection-ClinitFieldGetIntStatic/ClassInitFieldGetIntStatic.java b/test/testsuite/ouroboros/reflection_test/RT0150-rt-reflection-ClinitFieldGetIntStatic/ClassInitFieldGetIntStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..c4ffc17d5a781c17a710fe760a130576515da351 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0150-rt-reflection-ClinitFieldGetIntStatic/ClassInitFieldGetIntStatic.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetIntStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldGetIntStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getInt(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0151-rt-reflection-ClinitFieldGetLongStatic/ClassInitFieldGetLongStatic.java b/test/testsuite/ouroboros/reflection_test/RT0151-rt-reflection-ClinitFieldGetLongStatic/ClassInitFieldGetLongStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..48e3bbc2ba66d833c5bddf94854956c0a6b691f3 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0151-rt-reflection-ClinitFieldGetLongStatic/ClassInitFieldGetLongStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetLongStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldGetLongStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getLong(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0152-rt-reflection-ClinitFieldGetShortStatic/ClassInitFieldGetShortStatic.java b/test/testsuite/ouroboros/reflection_test/RT0152-rt-reflection-ClinitFieldGetShortStatic/ClassInitFieldGetShortStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..5306c4924be0947404b56f4b581f23f08f2f55e1 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0152-rt-reflection-ClinitFieldGetShortStatic/ClassInitFieldGetShortStatic.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetShortStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldGetShortStatic.java + *- @Title/Destination: When f is a static field of class One and call f.getShort(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0153-rt-reflection-ClinitFieldGetStatic/ClassInitFieldGetStatic.java b/test/testsuite/ouroboros/reflection_test/RT0153-rt-reflection-ClinitFieldGetStatic/ClassInitFieldGetStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..5d642295a49f609e5b32ba252ac812992e5317f5 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0153-rt-reflection-ClinitFieldGetStatic/ClassInitFieldGetStatic.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldGetStatic.java + *- @Title/Destination: When f is a static field of class One and call f.get(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0154-rt-reflection-ClinitFieldOtherMethod/ClassInitFieldOtherMethod.java b/test/testsuite/ouroboros/reflection_test/RT0154-rt-reflection-ClinitFieldOtherMethod/ClassInitFieldOtherMethod.java new file mode 100755 index 0000000000000000000000000000000000000000..6afe197010dc8646ca3e434765d552e1d779fad0 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0154-rt-reflection-ClinitFieldOtherMethod/ClassInitFieldOtherMethod.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldOtherMethod + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldOtherMethod.java + *- @Title/Destination: When f is a static field of class One and call method except setXX/getXX, class is not + * initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0155-rt-reflection-ClinitFieldSetBooleanStatic/ClassInitFieldSetBooleanStatic.java b/test/testsuite/ouroboros/reflection_test/RT0155-rt-reflection-ClinitFieldSetBooleanStatic/ClassInitFieldSetBooleanStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..9f85facd838f130bbd23f8514bd3e1bcc20e970e --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0155-rt-reflection-ClinitFieldSetBooleanStatic/ClassInitFieldSetBooleanStatic.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetBooleanStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetBooleanStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setBoolean(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0156-rt-reflection-ClinitFieldSetByteStatic/ClassInitFieldSetByteStatic.java b/test/testsuite/ouroboros/reflection_test/RT0156-rt-reflection-ClinitFieldSetByteStatic/ClassInitFieldSetByteStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..7ce54a5cdb24593fb0c9c6d1b9d1760d84acf278 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0156-rt-reflection-ClinitFieldSetByteStatic/ClassInitFieldSetByteStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetByteStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetByteStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setByte(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0157-rt-reflection-ClinitFieldSetCharStatic/ClassInitFieldSetCharStatic.java b/test/testsuite/ouroboros/reflection_test/RT0157-rt-reflection-ClinitFieldSetCharStatic/ClassInitFieldSetCharStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..eece6d331dfbcd4ac74ab7a48d081501c7a0864a --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0157-rt-reflection-ClinitFieldSetCharStatic/ClassInitFieldSetCharStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetCharStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetCharStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setChar(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0158-rt-reflection-ClinitFieldSetDoubleStatic/ClassInitFieldSetDoubleStatic.java b/test/testsuite/ouroboros/reflection_test/RT0158-rt-reflection-ClinitFieldSetDoubleStatic/ClassInitFieldSetDoubleStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..16c16abf3b88dcf030f4518b47cba19efb9b46d0 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0158-rt-reflection-ClinitFieldSetDoubleStatic/ClassInitFieldSetDoubleStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetDoubleStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetDoubleStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setDouble(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0159-rt-reflection-ClinitFieldSetFloatStatic/ClassInitFieldSetFloatStatic.java b/test/testsuite/ouroboros/reflection_test/RT0159-rt-reflection-ClinitFieldSetFloatStatic/ClassInitFieldSetFloatStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..99523c0ee23ac9ad9b9234b3a8aff8d4886ba854 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0159-rt-reflection-ClinitFieldSetFloatStatic/ClassInitFieldSetFloatStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetFloatStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetFloatStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setFloat(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0160-rt-reflection-ClinitFieldSetIntStatic/ClassInitFieldSetIntStatic.java b/test/testsuite/ouroboros/reflection_test/RT0160-rt-reflection-ClinitFieldSetIntStatic/ClassInitFieldSetIntStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..c9d8db69deab1d7f370d5a7168952876d36b1832 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0160-rt-reflection-ClinitFieldSetIntStatic/ClassInitFieldSetIntStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetIntStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetIntStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setInt(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0161-rt-reflection-ClinitFieldSetLongStatic/ClassInitFieldSetLongStatic.java b/test/testsuite/ouroboros/reflection_test/RT0161-rt-reflection-ClinitFieldSetLongStatic/ClassInitFieldSetLongStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..c7aed800d67fbe8b5da8962d7fdde379dfa46ce2 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0161-rt-reflection-ClinitFieldSetLongStatic/ClassInitFieldSetLongStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetLongStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetLongStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setLong(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0162-rt-reflection-ClinitFieldSetShortStatic/ClassInitFieldSetShortStatic.java b/test/testsuite/ouroboros/reflection_test/RT0162-rt-reflection-ClinitFieldSetShortStatic/ClassInitFieldSetShortStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..3de0ef53fd717e0cc129c3a7cebafb89dc6b5cbd --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0162-rt-reflection-ClinitFieldSetShortStatic/ClassInitFieldSetShortStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetShortStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetShortStatic.java + *- @Title/Destination: When f is a static field of class One and call f.setShort(), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0163-rt-reflection-ClinitFieldSetStatic/ClassInitFieldSetStatic.java b/test/testsuite/ouroboros/reflection_test/RT0163-rt-reflection-ClinitFieldSetStatic/ClassInitFieldSetStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..90e18c78074adad416c8840b6e232e7afee6791c --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0163-rt-reflection-ClinitFieldSetStatic/ClassInitFieldSetStatic.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetStatic.java + *- @Title/Destination: When f is a static field of class One and call f.set(), class One is initialized + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0164-rt-reflection-ClinitMethodInvokeStatic/ClassInitMethodInvokeStatic.java b/test/testsuite/ouroboros/reflection_test/RT0164-rt-reflection-ClinitMethodInvokeStatic/ClassInitMethodInvokeStatic.java new file mode 100755 index 0000000000000000000000000000000000000000..ea11a2971a16f7e0a7e5bebcb20ce1fd699834e0 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0164-rt-reflection-ClinitMethodInvokeStatic/ClassInitMethodInvokeStatic.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitMethodInvokeStatic + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitMethodInvokeStatic.java + *- @Title/Destination: When m is a static method of class One and call m.invoke(null, args), class One is initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0165-rt-reflection-ClinitFieldGetBooleanInterface/ClassInitFieldGetBooleanInterface.java b/test/testsuite/ouroboros/reflection_test/RT0165-rt-reflection-ClinitFieldGetBooleanInterface/ClassInitFieldGetBooleanInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..53a5707339b45b61ac2098e19f91da84b28d5e12 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0165-rt-reflection-ClinitFieldGetBooleanInterface/ClassInitFieldGetBooleanInterface.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetBooleanInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0166-rt-reflection-ClinitFieldGetByteInterface/ClassInitFieldGetByteInterface.java b/test/testsuite/ouroboros/reflection_test/RT0166-rt-reflection-ClinitFieldGetByteInterface/ClassInitFieldGetByteInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..ad8cc58211174ea49e71364e2073a0bb547b1dae --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0166-rt-reflection-ClinitFieldGetByteInterface/ClassInitFieldGetByteInterface.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetByteInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0167-rt-reflection-ClinitFieldGetCharInterface/ClassInitFieldGetCharInterface.java b/test/testsuite/ouroboros/reflection_test/RT0167-rt-reflection-ClinitFieldGetCharInterface/ClassInitFieldGetCharInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..ffb84c35fc67309034173cdc9b43ead26130464c --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0167-rt-reflection-ClinitFieldGetCharInterface/ClassInitFieldGetCharInterface.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetCharInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0168-rt-reflection-ClinitFieldGetDoubleInterface/ClassInitFieldGetDoubleInterface.java b/test/testsuite/ouroboros/reflection_test/RT0168-rt-reflection-ClinitFieldGetDoubleInterface/ClassInitFieldGetDoubleInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..7189c79e26b3483249e03dbf1f9e3e9c3b413fe3 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0168-rt-reflection-ClinitFieldGetDoubleInterface/ClassInitFieldGetDoubleInterface.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetDoubleInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0169-rt-reflection-ClinitFieldGetFloatInterface/ClassInitFieldGetFloatInterface.java b/test/testsuite/ouroboros/reflection_test/RT0169-rt-reflection-ClinitFieldGetFloatInterface/ClassInitFieldGetFloatInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..ab69302a82be5842e446722afdd45e3dfe4a4a1b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0169-rt-reflection-ClinitFieldGetFloatInterface/ClassInitFieldGetFloatInterface.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetFloatInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0170-rt-reflection-ClinitFieldGetInterface/ClassInitFieldGetInterface.java b/test/testsuite/ouroboros/reflection_test/RT0170-rt-reflection-ClinitFieldGetInterface/ClassInitFieldGetInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..5ae54cc2caf754da04a592f7dcb1c554bc2f8de3 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0170-rt-reflection-ClinitFieldGetInterface/ClassInitFieldGetInterface.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0171-rt-reflection-ClinitFieldGetIntInterface/ClassInitFieldGetIntInterface.java b/test/testsuite/ouroboros/reflection_test/RT0171-rt-reflection-ClinitFieldGetIntInterface/ClassInitFieldGetIntInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..a6d14346c92812c915c5b0cbb645d15c0359c649 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0171-rt-reflection-ClinitFieldGetIntInterface/ClassInitFieldGetIntInterface.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetIntInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0172-rt-reflection-ClinitFieldGetLongInterface/ClassInitFieldGetLongInterface.java b/test/testsuite/ouroboros/reflection_test/RT0172-rt-reflection-ClinitFieldGetLongInterface/ClassInitFieldGetLongInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..8d78ce4c60bd00b5f0b75bd154bc7a4c073b12f7 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0172-rt-reflection-ClinitFieldGetLongInterface/ClassInitFieldGetLongInterface.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetLongInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0173-rt-reflection-ClinitFieldGetShortInterface/ClassInitFieldGetShortInterface.java b/test/testsuite/ouroboros/reflection_test/RT0173-rt-reflection-ClinitFieldGetShortInterface/ClassInitFieldGetShortInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..1d63d192135da94a97d71201c373617594dee924 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0173-rt-reflection-ClinitFieldGetShortInterface/ClassInitFieldGetShortInterface.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldGetShortInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0174-rt-reflection-ClinitFieldOtherMethodInterface/ClassInitFieldOtherMethodInterface.java b/test/testsuite/ouroboros/reflection_test/RT0174-rt-reflection-ClinitFieldOtherMethodInterface/ClassInitFieldOtherMethodInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..ec276a32ca57fa45a6f13ff381402fa75445c946 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0174-rt-reflection-ClinitFieldOtherMethodInterface/ClassInitFieldOtherMethodInterface.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldOtherMethodInterface + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldOtherMethodInterface.java + *- @Title/Destination: When f is a field of of interface OneInterface and call method except setXX/getXX, class is not + * initialized. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0175-rt-reflection-ClinitFieldSetBooleanInterface/ClassInitFieldSetBooleanInterface.java b/test/testsuite/ouroboros/reflection_test/RT0175-rt-reflection-ClinitFieldSetBooleanInterface/ClassInitFieldSetBooleanInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..02d5b05f9049309005fc02bf1d90e644ea68eec0 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0175-rt-reflection-ClinitFieldSetBooleanInterface/ClassInitFieldSetBooleanInterface.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetBooleanInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0176-rt-reflection-ClinitFieldSetByteInterface/ClassInitFieldSetByteInterface.java b/test/testsuite/ouroboros/reflection_test/RT0176-rt-reflection-ClinitFieldSetByteInterface/ClassInitFieldSetByteInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..a8230d388cd88483f71d8e47195af89ea06252fe --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0176-rt-reflection-ClinitFieldSetByteInterface/ClassInitFieldSetByteInterface.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetByteInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0177-rt-reflection-ClinitFieldSetFloatInterface/ClassInitFieldSetFloatInterface.java b/test/testsuite/ouroboros/reflection_test/RT0177-rt-reflection-ClinitFieldSetFloatInterface/ClassInitFieldSetFloatInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..1fddfaa357a014aa04bf22a427fcc6278ef1260d --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0177-rt-reflection-ClinitFieldSetFloatInterface/ClassInitFieldSetFloatInterface.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetFloatInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0178-rt-reflection-ClinitFieldSetInterface/ClassInitFieldSetInterface.java b/test/testsuite/ouroboros/reflection_test/RT0178-rt-reflection-ClinitFieldSetInterface/ClassInitFieldSetInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..51c21e2bf3ee5a39c4fa9fc7eaf77df43460e574 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0178-rt-reflection-ClinitFieldSetInterface/ClassInitFieldSetInterface.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0179-rt-reflection-ClinitFieldSetIntInterface/ClassInitFieldSetIntInterface.java b/test/testsuite/ouroboros/reflection_test/RT0179-rt-reflection-ClinitFieldSetIntInterface/ClassInitFieldSetIntInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..608251d78d83b5c22489061761a9d7b3d084273c --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0179-rt-reflection-ClinitFieldSetIntInterface/ClassInitFieldSetIntInterface.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetIntInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0180-rt-reflection-ClinitFieldSetLongInterface/ClassInitFieldSetLongInterface.java b/test/testsuite/ouroboros/reflection_test/RT0180-rt-reflection-ClinitFieldSetLongInterface/ClassInitFieldSetLongInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..b2f09eb63ae529a3ef1ec86bbd370fcd818e9db0 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0180-rt-reflection-ClinitFieldSetLongInterface/ClassInitFieldSetLongInterface.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetLongInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0181-rt-reflection-ClinitFieldSetShortInterface/ClassInitFieldSetShortInterface.java b/test/testsuite/ouroboros/reflection_test/RT0181-rt-reflection-ClinitFieldSetShortInterface/ClassInitFieldSetShortInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..1841166852fa0d633c7a3ab7fb53e19b0bee1c93 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0181-rt-reflection-ClinitFieldSetShortInterface/ClassInitFieldSetShortInterface.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetShortInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0182-rt-reflection-ClinitMethodInvokeInterface/ClassInitMethodInvokeInterface.java b/test/testsuite/ouroboros/reflection_test/RT0182-rt-reflection-ClinitMethodInvokeInterface/ClassInitMethodInvokeInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..73bc2326a4355db291022464a645219fbf72c5bf --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0182-rt-reflection-ClinitMethodInvokeInterface/ClassInitMethodInvokeInterface.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitMethodInvokeInterface + *- @RequirementName: Java Reflection + *- @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. + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0184-rt-reflection-MethodTest/MethodTest.java b/test/testsuite/ouroboros/reflection_test/RT0184-rt-reflection-MethodTest/MethodTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fa0f92d36bf120fc2f62c6cdc1fe7400f178ae93 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0184-rt-reflection-MethodTest/MethodTest.java @@ -0,0 +1,449 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodTest.java + *- @RequirementName: Java Reflection + *- @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 + *- @Brief:no: see steps of separate test cases + *- @Expect:0\n + *- @Priority: High + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0186-rt-reflection-ConstructorTest/ConstructorTest.java b/test/testsuite/ouroboros/reflection_test/RT0186-rt-reflection-ConstructorTest/ConstructorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ca46b6e6c47acd99275d8331a9a68f019019267b --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0186-rt-reflection-ConstructorTest/ConstructorTest.java @@ -0,0 +1,379 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ConstructorTest.java + *- @RequirementName: Java Reflection + *- @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) + *- @Brief:no: see steps of separate test cases + *- @Expect:0\n + *- @Priority: High + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0188-rt-reflection-MethodHandleReflectCombineTest/MethodHandleReflectCombineTest.java b/test/testsuite/ouroboros/reflection_test/RT0188-rt-reflection-MethodHandleReflectCombineTest/MethodHandleReflectCombineTest.java new file mode 100755 index 0000000000000000000000000000000000000000..227fbc18de50e6f5d3310d4f45adb991592fd6f0 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0188-rt-reflection-MethodHandleReflectCombineTest/MethodHandleReflectCombineTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodHandleReflectCombineTest.java + *- @RequirementName: Java Reflection + *- @TestCaseName:MethodHandleReflectCombineTest.java + *- @Title/Destination: Test Field/Method/Constructor object return by MethodHandles.reflectAs(Class expected, MethodHandle target) is heap object + *- @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 + *- @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 < testData.length; i++) { + passCnt += singleMethodCheck(reflectAs((Class) testData[i][0], (MethodHandle) testData[i][1]), reflectAs((Class) testData[i][0], (MethodHandle) testData[i][1])) == 3 ? 1 : 0; + } + + Constructor privC = Class.forName("RATest").getDeclaredConstructor(); + privC.setAccessible(true); + MethodHandle raCon = lookup().unreflectConstructor(privC); + passCnt += singleMethodCheck(privC, reflectAs(Constructor.class, raCon)) == 3 ? 1 : 0; + + return passCnt - 11; + } +} + +class RATest { + public static MethodHandles.Lookup LOOKUP() { + return lookup(); + } + + static public double count = 0; + protected static int svi = 333; + private double vd = 136; + String[] vs = {"hi"}; + + RATest(int i) { + count = i; + } + + public RATest(double[] i) { + count = i.length; + } + + private RATest() { + count = -1; + } + + private int mhVar(Object... a) { + return a.length; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0189-rt-reflection-FieldTest/FieldTest.java b/test/testsuite/ouroboros/reflection_test/RT0189-rt-reflection-FieldTest/FieldTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8b0d6f131e770e21a8e8a00efd972f1eb57027be --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0189-rt-reflection-FieldTest/FieldTest.java @@ -0,0 +1,385 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldTest.java + *- @RequirementName: Java Reflection + *- @TestCaseName:FieldTest.java + *- @Title/Destination: for the same field, different Field object is return when call following API twice: Class.getFields(), Class.getDeclaredFields(), Class.getField(String name), Class.getDeclareedField(String name). tests field with different data type, modifier, annotation and declaring class + *- @Brief:no: see steps of separate test cases + *- @Expect:0\n + *- @Priority: High + *- @Source: FieldTest.java + *- @ExecuteClass: FieldTest + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class FieldTest { + /** + * Verify that for the same field, different Field object is return when call following API twice: + * - Class.getFields() + * - Class.getDeclaredFields() + * - Class.getField(String name) + * - Class.getDeclareedField(String name) + * if any Field failed the check, will print error message including testcase and field name; + * after all check is pass, casePassed will be increased; + */ + private static void classAllFieldTest(Class clazz, String caseName) throws Exception { + // checkpoint 1. Class.getFields() + Field[] fields1 = clazz.getFields(); + Field[] fields2 = clazz.getFields(); + checkFields(fields1, fields2); + for (Field f : fields1) { + // checkpoint 2. Class.getDeclaredFields() + Field f1 = clazz.getField(f.getName()); + Field f2 = clazz.getField(f.getName()); + if (singleFieldCheck(f1, f2) != 3) { + System.out.println(caseName + ": " + f1.getDeclaringClass().toString() + "." + f1.getName() + " failed"); + } + } + + // checkpoint 3. Class.getField(String name) + fields1 = clazz.getDeclaredFields(); + fields2 = clazz.getDeclaredFields(); + checkFields(fields1, fields2); + for (Field f : fields1) { + // checkpoint 4. Class.getDeclareedField(String name) + Field f1 = clazz.getDeclaredField(f.getName()); + Field f2 = clazz.getDeclaredField(f.getName()); + if (singleFieldCheck(f1, f2) != 3) { + System.out.println(caseName + ": " + f1.getDeclaringClass().toString() + "." + f1.getName() + " failed for declared fields"); + } + } + casesPassed++; + } + + private static void checkFields(Field[] fields1, Field[] fields2) { + for (Field f1: fields1) { + for (Field f2: fields2) { + // only when modifers and class and name is same, two Field object is for same field + if(f1.toGenericString().equals(f2.toGenericString())) { + if (singleFieldCheck(f1, f2) != 3) { + System.out.println(f1.getName()+" failed in checkFields"); + } + } + } + } + } + + private static int singleFieldCheck(Field f1, Field f2) { + int passCnt = 0; + passCnt += f1 == f2 ? 0 : 1; + passCnt += f1.equals(f2) ? 1 : 0; + passCnt += f1.hashCode() == f2.hashCode() ? 1 : 0; + return passCnt; + } + + static int casesPassed = 0; + + public static void main(String [] args) { + field01(); + field02(); + field03(); + field04(); + field05(); + field06(); + field07(); + field08(); + field09(); + field10(); + field11(); + field12(); + System.out.println(casesPassed - 12); + } + + /** + *- @TestCaseID: field01 + *- @Title/Destination: for same field in pre-defined class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. all test in classAllFieldTest() passed for pre-defined class java.lang.Thread + */ + private static void field01() { + try { + classAllFieldTest(Class.forName("java.lang.Thread"), "field01"); + } catch (Exception e) { + System.out.println("Case field01 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field02 + *- @Title/Destination: for same field in user-defined class with different type/modifier/annotation, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. classAllFieldTest() passed for fields with different type + * -#step2. classAllFieldTest() passed for fields with different access modifier: public, private, protected + * -#step3. classAllFieldTest() passed for fields with different modifier: transient, final, volatile, static + * -#step4. classAllFieldTest() passed for fields with annotation + */ + private static void field02() { + try { + classAllFieldTest(Class.forName("TestField02"), "field02"); + } catch (Exception e) { + System.out.println("Case field02 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field03 + *- @Title/Destination: for same field in strictfp class, certain APIs return different Field object when called twice + *- @Brief:no: + * -step1. all test in classAllFieldTest() passed for class with modifier strictfp + */ + private static void field03() { + try { + classAllFieldTest(Class.forName("TestField03"), "field03"); + } catch (Exception e) { + System.out.println("Case field03 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field04 + *- @Title/Destination: for same field in interface, certain APIs return different Field object when called twice + *- @Brief:no: + * -step1. check all test in classAllFieldTest passed for fields in interface + */ + private static void field04() { + try { + classAllFieldTest(Class.forName("TestField04"), "field04"); + } catch (Exception e) { + System.out.println("Case field04 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field05 + *- @Title/Destination: for same field in abstract class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in abstract class + */ + private static void field05() { + try { + classAllFieldTest(Class.forName("TestField05"), "field05"); + } catch (Exception e) { + System.out.println("Case field05 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field06 + *- @Title/Destination: for same field in anonymous class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. get the class instance of an anonymous class + * -#step2. check all test in classAllFieldTest passed for fields in anonymous class + */ + private static void field06() { + try { + // step 1 + Class clazz = Class.forName("FieldTest"); + FieldTest mainClass = new FieldTest(); + Field field = clazz.getDeclaredField("testField06"); + + classAllFieldTest(field.get(mainClass).getClass(), "field06"); + } catch (Exception e) { + System.out.println("Case field06 failed with exception" + e); + } + } + + private Runnable testField06 = new Runnable() { + int intAnonymous = 10; + public double doubleAnonymous = 1988.416; + + @Override + public void run() { + for (int i = 0; i < intAnonymous; i++) { + intAnonymous += i; + } + } + }; + + /** + *- @TestCaseID: field07 + *- @Title/Destination: for same field in local class(class in a function), certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in local class + */ + private static void field07() { + class TestField07 { + private final transient int intLocal = 9; + public volatile String stringLocal = "a fake behind the fear"; + } + try { + classAllFieldTest(Class.forName("FieldTest$1TestField07"), "field07"); + } catch (Exception e) { + System.out.println("Case field07 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field08 + *- @Title/Destination: for same field in inner class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in inner class + */ + private static void field08() { + try { + classAllFieldTest(Class.forName("FieldTest$TestField08"), "field08"); + } catch (Exception e) { + System.out.println("Case field08 failed with exception" + e); + } + } + + class TestField08 { + volatile private char charInner = 'l'; + public final static transient double doubleInner = 0.88; + } + + /** + *- @TestCaseID: field09 + *- @Title/Destination: for same field in user-defined enum class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in enum class + */ + private static void field09() { + try { + classAllFieldTest(Class.forName("TestField09"), "field09"); + } catch (Exception e) { + System.out.println("Case field09 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field10 + *- @Title/Destination: for same field in parent class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in parent class + */ + private static void field10() { + try { + classAllFieldTest(Class.forName("TestField10"), "field10"); + } catch (Exception e) { + System.out.println("Case field10 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field11 + *- @Title/Destination: for same field in child class with implemented interface, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in child class with implemented interface + */ + private static void field11() { + try { + classAllFieldTest(Class.forName("TestField11"), "field11"); + } catch (Exception e) { + System.out.println("Case field11 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field12 + *- @Title/Destination: for same field in interface implemented by another class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in interface implemented by another class + */ + private static void field12() { + try { + classAllFieldTest(Class.forName("TestField12"), "field12"); + } catch (Exception e) { + System.out.println("Case field12 failed with exception" + e); + } + } +} + +class TestField02 { + // step1 + boolean booleanField = true; + byte byteField = (byte)2; + short shortField = (short)4; + int intField = 6; + long longField = 8; + char charField = 10; + float floatField = 0.4f; + double doubleField = 0.8; + + String stringField = "The queerest of the queer"; + Runnable r = null; + + boolean[][][][][][][] booleanArray7 = new boolean[][][][][][][] {{{{{{{true, false}}}}}}}; + String[][][] stringArray3 = new String[][][] {{{"the strangest of the strange"}}}; + + // step2 + public int publicInt = 88; + protected double protectedDouble = 99; + private String privateString = "the coldest of the cool"; + + // step3 + transient double[][] transientDoubleArray = new double[][] {{1988, 4.16}}; + final int finalInt = 9876; + volatile String volatileString = "the lamest of the lame"; + static Character staticCharacter = 'd'; + + //step 4 + @Deprecated + String[][] stringsAnnotation = new String[][] {{"the numbest of the dumb"}}; +} + +strictfp class TestField03 { + float floatField = 4.16f; + public double doubleField = 19.88; +} + +interface TestField04 { + String stringInterface = "i know what's good for you"; + char[] charInterface = new char[] {'l', 'e', 't'}; +} + +abstract class TestField05 { + String[] stringsAbstractArray = {"i hate to see you here", "you choke behind a smile"}; + Runnable[] runnableAbstractArray = {new Runnable() { + @Override + public void run() { + } + } + }; +} + +enum TestField09 { + WHISKY, VODKA, BRANDY, GIN, RUM, TEQUILA; + private static short shortEnum = (short)6; + public final String stringEnum = "Dry Martini"; +} + +class TestField10 { + public int int10; + protected boolean boolean10; + char[] chars10 = new char[] {'a', 'b', 'c'}; + private String string10 = "I'm only happy when it rains"; +} + +class TestField11 extends TestField10 implements TestField12 { + boolean boolean10 = true; + public double double11 = 0.416; + +} + +interface TestField12 { + int int10 = 9; + boolean boolean10 = false; + char[] chars10 = new char[] {'a', 'b', 'c'}; + String string10 = "I'm only happy when it rains"; +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0200-rt-reflection-AnnotationTypeParameterSetTest/AnnoA.java b/test/testsuite/ouroboros/reflection_test/RT0200-rt-reflection-AnnotationTypeParameterSetTest/AnnoA.java new file mode 100755 index 0000000000000000000000000000000000000000..8c2ab1b3973a77248c3afcf1b038b6603a3aeb21 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0200-rt-reflection-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/reflection_test/RT0200-rt-reflection-AnnotationTypeParameterSetTest/AnnoB.java b/test/testsuite/ouroboros/reflection_test/RT0200-rt-reflection-AnnotationTypeParameterSetTest/AnnoB.java new file mode 100755 index 0000000000000000000000000000000000000000..70a77a033f61b181a8783b74f2eabec2b75dca3f --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0200-rt-reflection-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/reflection_test/RT0200-rt-reflection-AnnotationTypeParameterSetTest/AnnotationTypeParameterSetTest.java b/test/testsuite/ouroboros/reflection_test/RT0200-rt-reflection-AnnotationTypeParameterSetTest/AnnotationTypeParameterSetTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c540d20397c874a35aab9ed296b7da5543f60d3e --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0200-rt-reflection-AnnotationTypeParameterSetTest/AnnotationTypeParameterSetTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_Annotation_invoke_AnnotationSetTest + *- @RequirementName: Java Reflection + *- @TestCaseName:AnnotationTypeParameterSetTest.java + *- @TestCaseName: AnnotationTypeParameterSetTest + *- @TestCaseType: Function Testing + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation with @Target(ElementType.TYPE_PARAMETER) + *- @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 + *- @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: AnnoB.java AnnoA.java +// EXEC:%maple %f AnnoA.java AnnoB.java %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0201-rt-reflection-AnnotationTypeUseSetTest/AnnoA.java b/test/testsuite/ouroboros/reflection_test/RT0201-rt-reflection-AnnotationTypeUseSetTest/AnnoA.java new file mode 100755 index 0000000000000000000000000000000000000000..063bd569435d45bd8139ac3522fa94efa6dc779f --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0201-rt-reflection-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/reflection_test/RT0201-rt-reflection-AnnotationTypeUseSetTest/AnnoB.java b/test/testsuite/ouroboros/reflection_test/RT0201-rt-reflection-AnnotationTypeUseSetTest/AnnoB.java new file mode 100755 index 0000000000000000000000000000000000000000..70a77a033f61b181a8783b74f2eabec2b75dca3f --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0201-rt-reflection-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/reflection_test/RT0201-rt-reflection-AnnotationTypeUseSetTest/AnnotationTypeUseSetTest.java b/test/testsuite/ouroboros/reflection_test/RT0201-rt-reflection-AnnotationTypeUseSetTest/AnnotationTypeUseSetTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2344a79ed30b8b9355868e2d04c44dae0352fb38 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0201-rt-reflection-AnnotationTypeUseSetTest/AnnotationTypeUseSetTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_Annotation_invoke_AnnotationSetTest + *- @RequirementName: Java Reflection + *- @TestCaseName:AnnotationTypeUseSetTest.java + *- @TestCaseName: AnnotationTypeUseSetTest + *- @TestCaseType: Function Testing + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation with @Target(ElementType.TYPE_USE) + *- @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 + *- @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: AnnoB.java AnnoA.java +// EXEC:%maple %f AnnoA.java AnnoB.java %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnoA.java b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnoA.java new file mode 100755 index 0000000000000000000000000000000000000000..c46a1ae1813abd9c73b5abb163a5f82eca4109e1 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-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/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnoB.java b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnoB.java new file mode 100755 index 0000000000000000000000000000000000000000..70a77a033f61b181a8783b74f2eabec2b75dca3f --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-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/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnoC.java b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnoC.java new file mode 100755 index 0000000000000000000000000000000000000000..e86c63e3d1ae797fc234241ee0cabf8bddf12093 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-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/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnoD.java b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnoD.java new file mode 100755 index 0000000000000000000000000000000000000000..eb15087f77423ad5cb389033d9f5b987f9192d8a --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-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/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnotationMultiThread.java b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnotationMultiThread.java new file mode 100755 index 0000000000000000000000000000000000000000..4fa951ea6a21bef704df1551ee1415f0b76f808a --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/AnnotationMultiThread.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_MethodHandle_invoke_AnnotationMultiThread + *- @RequirementName: Java Reflection + *- @TestCaseName:AnnotationMultiThread.java + *- @TestCaseName: AnnotationMultiThread + *- @TestCaseType: Function Testing + *- @RequirementName: annotation + *- @Title/Destination: positive test for User-defined Annotation, verify when multiple thread try to use annotations, working fine + *- @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 + *- @Source: AnnotationMultiThread.java AnnoA.java AnnoB.java AnnoC.java AnnoD.java ENUMA.java + *- @ExecuteClass: AnnotationMultiThread + *- @ExecuteArgs: + */ + +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: AnnoB.java AnnoC.java AnnoA.java ENUMA.java AnnoD.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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/ENUMA.java b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/ENUMA.java new file mode 100755 index 0000000000000000000000000000000000000000..887e7087584a42143061807f5cc25892bd2f5ae0 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0202-rt-reflection-AnnotationMultiThread/ENUMA.java @@ -0,0 +1,5 @@ +public enum ENUMA { + A, + B, + C +} diff --git a/test/testsuite/ouroboros/reflection_test/RT0208-rt-reflection-MetadataCheck/FieldTest.java b/test/testsuite/ouroboros/reflection_test/RT0208-rt-reflection-MetadataCheck/FieldTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2c6071c0bcd88bf53e23bbcbc08e4904fcdd5fcf --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0208-rt-reflection-MetadataCheck/FieldTest.java @@ -0,0 +1,386 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: FieldTest.java + *- @RequirementName: Java Reflection + *- @TestCaseName:FieldTest.java + *- @Title/Destination: for the same field, different Field object is return when call following API twice: Class.getFields(), Class.getDeclaredFields(), Class.getField(String name), Class.getDeclareedField(String name). tests field with different data type, modifier, annotation and declaring class + *- @Brief:no: see steps of separate test cases + *- @Expect:0\n + *- @Priority: High + *- @Source: FieldTest.java + *- @ExecuteClass: FieldTest + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class FieldTest { + /** + * Verify that for the same field, different Field object is return when call following API twice: + * - Class.getFields() + * - Class.getDeclaredFields() + * - Class.getField(String name) + * - Class.getDeclareedField(String name) + * if any Field failed the check, will print error message including testcase and field name; + * after all check is pass, casePassed will be increased; + */ + private static void classAllFieldTest(Class clazz, String caseName) throws Exception { + // checkpoint 1. Class.getFields() + Field[] fields1 = clazz.getFields(); + Field[] fields2 = clazz.getFields(); + checkFields(fields1, fields2); + for (Field f : fields1) { + // checkpoint 2. Class.getDeclaredFields() + Field f1 = clazz.getField(f.getName()); + Field f2 = clazz.getField(f.getName()); + if (singleFieldCheck(f1, f2) != 3) { + System.out.println(caseName + ": " + f1.getDeclaringClass().toString() + "." + f1.getName() + " failed"); + } + } + + // checkpoint 3. Class.getField(String name) + fields1 = clazz.getDeclaredFields(); + fields2 = clazz.getDeclaredFields(); + checkFields(fields1, fields2); + for (Field f : fields1) { + // checkpoint 4. Class.getDeclareedField(String name) + Field f1 = clazz.getDeclaredField(f.getName()); + Field f2 = clazz.getDeclaredField(f.getName()); + if (singleFieldCheck(f1, f2) != 3) { + System.out.println(caseName + ": " + f1.getDeclaringClass().toString() + "." + f1.getName() + " failed for declared fields"); + } + } + casesPassed++; + } + + private static void checkFields(Field[] fields1, Field[] fields2) { + for (Field f1: fields1) { + for (Field f2: fields2) { + // only when modifers and class and name is same, two Field object is for same field + if(f1.toGenericString().equals(f2.toGenericString())) { + if (singleFieldCheck(f1, f2) != 3) { + System.out.println(f1.getName()+" failed in checkFields"); + } + } + } + } + } + + private static int singleFieldCheck(Field f1, Field f2) { + int passCnt = 0; + passCnt += f1 == f2 ? 0 : 1; + passCnt += f1.equals(f2) ? 1 : 0; + passCnt += f1.hashCode() == f2.hashCode() ? 1 : 0; + return passCnt; + } + + static int casesPassed = 0; + + public static void main(String [] args) { + field01(); + field02(); + field03(); + field04(); + field05(); + field06(); + field07(); + field08(); + field09(); + field10(); + field11(); + field12(); + System.out.println(casesPassed - 12); + } + + /** + *- @TestCaseID: field01 + *- @Title/Destination: for same field in pre-defined class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. all test in classAllFieldTest() passed for pre-defined class java.lang.Thread + */ + private static void field01() { + try { + classAllFieldTest(Class.forName("java.lang.Thread"), "field01"); + } catch (Exception e) { + System.out.println("Case field01 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field02 + *- @Title/Destination: for same field in user-defined class with different type/modifier/annotation, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. classAllFieldTest() passed for fields with different type + * -#step2. classAllFieldTest() passed for fields with different access modifier: public, private, protected + * -#step3. classAllFieldTest() passed for fields with different modifier: transient, final, volatile, static + * -#step4. classAllFieldTest() passed for fields with annotation + */ + private static void field02() { + try { + classAllFieldTest(Class.forName("TestField02"), "field02"); + } catch (Exception e) { + System.out.println("Case field02 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field03 + *- @Title/Destination: for same field in strictfp class, certain APIs return different Field object when called twice + *- @Brief:no: + * -step1. all test in classAllFieldTest() passed for class with modifier strictfp + */ + private static void field03() { + try { + classAllFieldTest(Class.forName("TestField03"), "field03"); + } catch (Exception e) { + System.out.println("Case field03 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field04 + *- @Title/Destination: for same field in interface, certain APIs return different Field object when called twice + *- @Brief:no: + * -step1. check all test in classAllFieldTest passed for fields in interface + */ + private static void field04() { + try { + classAllFieldTest(Class.forName("TestField04"), "field04"); + } catch (Exception e) { + System.out.println("Case field04 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field05 + *- @Title/Destination: for same field in abstract class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in abstract class + */ + private static void field05() { + try { + classAllFieldTest(Class.forName("TestField05"), "field05"); + } catch (Exception e) { + System.out.println("Case field05 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field06 + *- @Title/Destination: for same field in anonymous class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. get the class instance of an anonymous class + * -#step2. check all test in classAllFieldTest passed for fields in anonymous class + */ + private static void field06() { + try { + // step 1 + Class clazz = Class.forName("FieldTest"); + FieldTest mainClass = new FieldTest(); + Field field = clazz.getDeclaredField("testField06"); + + classAllFieldTest(field.get(mainClass).getClass(), "field06"); + } catch (Exception e) { + System.out.println("Case field06 failed with exception" + e); + } + } + + private Runnable testField06 = new Runnable() { + int intAnonymous = 10; + public double doubleAnonymous = 1988.416; + + @Override + public void run() { + for (int i = 0; i < intAnonymous; i++) { + intAnonymous += i; + } + } + }; + + /** + *- @TestCaseID: field07 + *- @Title/Destination: for same field in local class(class in a function), certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in local class + */ + private static void field07() { + class TestField07 { + private final transient int intLocal = 9; + public volatile String stringLocal = "a fake behind the fear"; + } + try { + classAllFieldTest(Class.forName("FieldTest$1TestField07"), "field07"); + } catch (Exception e) { + System.out.println("Case field07 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field08 + *- @Title/Destination: for same field in inner class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in inner class + */ + private static void field08() { + try { + classAllFieldTest(Class.forName("FieldTest$TestField08"), "field08"); + } catch (Exception e) { + System.out.println("Case field08 failed with exception" + e); + } + } + + class TestField08 { + volatile private char charInner = 'l'; + public final static transient double doubleInner = 0.88; + } + + /** + *- @TestCaseID: field09 + *- @Title/Destination: for same field in user-defined enum class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in enum class + */ + private static void field09() { + try { + classAllFieldTest(Class.forName("TestField09"), "field09"); + } catch (Exception e) { + System.out.println("Case field09 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field10 + *- @Title/Destination: for same field in parent class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in parent class + */ + private static void field10() { + try { + classAllFieldTest(Class.forName("TestField10"), "field10"); + } catch (Exception e) { + System.out.println("Case field10 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field11 + *- @Title/Destination: for same field in child class with implemented interface, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in child class with implemented interface + */ + private static void field11() { + try { + classAllFieldTest(Class.forName("TestField11"), "field11"); + } catch (Exception e) { + System.out.println("Case field11 failed with exception" + e); + } + } + + /** + *- @TestCaseID: field12 + *- @Title/Destination: for same field in interface implemented by another class, certain APIs return different Field object when called twice + *- @Brief:no: + * -#step1. check all test in classAllFieldTest passed for fields in interface implemented by another class + */ + private static void field12() { + try { + classAllFieldTest(Class.forName("TestField12"), "field12"); + } catch (Exception e) { + System.out.println("Case field12 failed with exception" + e); + } + } +} + +class TestField02 { + // step1 + boolean booleanField = true; + byte byteField = (byte)2; + short shortField = (short)4; + int intField = 6; + long longField = 8; + char charField = 10; + float floatField = 0.4f; + double doubleField = 0.8; + + String stringField = "The queerest of the queer"; + Runnable r = null; + + boolean[][][][][][][] booleanArray7 = new boolean[][][][][][][] {{{{{{{true, false}}}}}}}; + String[][][] stringArray3 = new String[][][] {{{"the strangest of the strange"}}}; + + // step2 + public int publicInt = 88; + protected double protectedDouble = 99; + private String privateString = "the coldest of the cool"; + + // step3 + transient double[][] transientDoubleArray = new double[][] {{1988, 4.16}}; + final int finalInt = 9876; + volatile String volatileString = "the lamest of the lame"; + static Character staticCharacter = 'd'; + + //step 4 + @Deprecated + String[][] stringsAnnotation = new String[][] {{"the numbest of the dumb"}}; +} + +strictfp class TestField03 { + float floatField = 4.16f; + public double doubleField = 19.88; +} + +interface TestField04 { + String stringInterface = "i know what's good for you"; + char[] charInterface = new char[] {'l', 'e', 't'}; +} + +abstract class TestField05 { + String[] stringsAbstractArray = {"i hate to see you here", "you choke behind a smile"}; + Runnable[] runnableAbstractArray = {new Runnable() { + @Override + public void run() { + } + } + }; +} + +enum TestField09 { + WHISKY, VODKA, BRANDY, GIN, RUM, TEQUILA; + private static short shortEnum = (short)6; + public final String stringEnum = "Dry Martini"; +} + +class TestField10 { + public int int10; + protected boolean boolean10; + char[] chars10 = new char[] {'a', 'b', 'c'}; + private String string10 = "I'm only happy when it rains"; +} + +class TestField11 extends TestField10 implements TestField12 { + boolean boolean10 = true; + public double double11 = 0.416; + +} + +interface TestField12 { + int int10 = 9; + boolean boolean10 = false; + char[] chars10 = new char[] {'a', 'b', 'c'}; + String string10 = "I'm only happy when it rains"; +} +// DEPENDENCE: MethodTest.java check_s.py +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0208-rt-reflection-MetadataCheck/MethodTest.java b/test/testsuite/ouroboros/reflection_test/RT0208-rt-reflection-MetadataCheck/MethodTest.java new file mode 100755 index 0000000000000000000000000000000000000000..06f367db501065bbc8c98ad5f28aacd672846588 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0208-rt-reflection-MetadataCheck/MethodTest.java @@ -0,0 +1,450 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MethodTest.java + *- @RequirementName: Java Reflection + *- @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 + *- @Brief:no: see steps of separate test cases + *- @Expect:0\n + *- @Priority: High + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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 + *- @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(); +} + +// DEPENDENCE: check_s.py FieldTest.java +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/RT0208-rt-reflection-MetadataCheck/check_s.py b/test/testsuite/ouroboros/reflection_test/RT0208-rt-reflection-MetadataCheck/check_s.py new file mode 100755 index 0000000000000000000000000000000000000000..9dab058366fb9d936639495ac169e40e7220a594 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/RT0208-rt-reflection-MetadataCheck/check_s.py @@ -0,0 +1,52 @@ +import sys + +def check_vtableimpl_s(filename): + f = open(filename, 'r') + result = list() + check_cnt = 0 + pass_cnt = 0 + fail_cnt = 0 + for line in f.readlines(): + line = line.strip() + if line.startswith(".type"): + result = list() + result.append(line) + if line.startswith(".size"): + if result[0].find("methods_info") != -1: + check_cnt += 1 + for i in result: + if i.find(".section") != -1: + if i == '.section .rometadata.method,"a",%progbits': + pass_cnt += 1 + else: + fail_cnt += 1 + elif i.find(".data") != -1: + fail_cnt += 1 + elif result[0].find("fields_info") != -1: + check_cnt += 1 + for i in result: + if i.find(".section") != -1: + if i == '.section .rometadata.field,"a",%progbits': + pass_cnt += 1 + else: + fail_cnt += 1 + elif i.find(".data") != -1: + fail_cnt += 1 + elif result[0].find("fieldOffsetData") != -1: + check_cnt += 1 + for i in result: + if i.find(".section") != -1: + fail_cnt += 1 + elif i.find(".data") != -1: + pass_cnt += 1 + else: + continue + if check_cnt == pass_cnt and fail_cnt == 0: + print(0) + else: + print(2) + + +if __name__ == '__main__': + check_vtableimpl_s(sys.argv[1]) + diff --git a/test/testsuite/ouroboros/reflection_test/issue-0000-rt-Reflection-ReflectionforName2/ReflectionForName2.java b/test/testsuite/ouroboros/reflection_test/issue-0000-rt-Reflection-ReflectionforName2/ReflectionForName2.java new file mode 100755 index 0000000000000000000000000000000000000000..9cfb9b178484d799f2658a635820117ebc126358 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/issue-0000-rt-Reflection-ReflectionforName2/ReflectionForName2.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectionForName2 + *- @RequirementName: Java Reflection + *- @TestCaseName:ReflectionForName2.java + *- @Title/Destination: Use Class.forName to get class, Static initialization blocks for target classes are executed + * when initialized set to True. + *- @Brief:no: + * -#step1: 定义一个类1,含有静态块,初始化会新建文件1。 + * -#step2:判断文件1是否存在,如果存在删除该文件。 + * -#step3:调用static Class forName(String name, boolean initialize, ClassLoader loader)获取类1,initialize为true。 + * -#step4:检查类的静态块被初始化,产生新的文件1。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ReflectionForName2.java + *- @ExecuteClass: ReflectionForName2 + *- @ExecuteArgs: + */ + +import java.io.File; +import java.io.IOException; + +class ForName2 { + static { + File cls2 = new File("/data/local/tmp/ReflectionForName2.txt"); + try { + cls2.createNewFile(); + } catch (IOException e) { + System.err.println(e); + } + } +} + +public class ReflectionForName2 { + public static void main(String[] args) throws ClassNotFoundException { + File cls1 = new File("/data/local/tmp/ReflectionForName2.txt"); + if (cls1.exists()) { + cls1.delete(); + } + Class cls = Class.forName("ForName2", true, ForName2.class.getClassLoader()); + if (cls1.exists()) { + 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 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/issue-RT0893-rt-Reflection-ClinitFieldSetCharInterface/ClassInitFieldSetCharInterface.java b/test/testsuite/ouroboros/reflection_test/issue-RT0893-rt-Reflection-ClinitFieldSetCharInterface/ClassInitFieldSetCharInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..25a7a09c6836ee379c33e3415d5d38b0159c0414 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/issue-RT0893-rt-Reflection-ClinitFieldSetCharInterface/ClassInitFieldSetCharInterface.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetCharInterface + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetCharInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.setChar(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.setChar(null, (char)46), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Source: ClassInitFieldSetCharInterface.java + *- @ExecuteClass: ClassInitFieldSetCharInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldSetCharInterface { + 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.setChar(null, (char) 46); + } + } 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 = ClassInitFieldSetCharInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface { + String aOne = ClassInitFieldSetCharInterface.result.append("One").toString(); + char hiChar = (char) 45; +} + +interface TwoInterface extends OneInterface { + String aTwo = ClassInitFieldSetCharInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldSetCharInterface.result.append("Annotation").toString(); +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/reflection_test/issue-RT0894-rt-Reflection-ClinitFieldSetDoubleInterface/ClassInitFieldSetDoubleInterface.java b/test/testsuite/ouroboros/reflection_test/issue-RT0894-rt-Reflection-ClinitFieldSetDoubleInterface/ClassInitFieldSetDoubleInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..8bc2565d92d2ab925157b1b97824e02fbbd8ae58 --- /dev/null +++ b/test/testsuite/ouroboros/reflection_test/issue-RT0894-rt-Reflection-ClinitFieldSetDoubleInterface/ClassInitFieldSetDoubleInterface.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ClassInitFieldSetDoubleInterface + *- @RequirementName: Java Reflection + *- @TestCaseName:ClassInitFieldSetDoubleInterface.java + *- @Title/Destination: When f is a field of interface OneInterface and call f.setDouble(), OneInterface is initialized, + * it's parent interface is not initialized. + *- @Brief:no: + * -#step1: Class.forName("OneInterface", false, OneInterface.class.getClassLoader()) and clazz.getField to get field f + * of OneInterface. + * -#step2: Call method f.setDouble(null), OneInterface is initialized. + *- @Expect: 0\n + *- @Priority: High + *- @Source: ClassInitFieldSetDoubleInterface.java + *- @ExecuteClass: ClassInitFieldSetDoubleInterface + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ClassInitFieldSetDoubleInterface { + 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.setDouble(null, 0.265874); + } + } catch (IllegalAccessException e) { + result.append("IllegalAccessException"); + } catch (Exception e) { + System.out.println(e); + } + + if (result.toString().compareTo("OneIllegalAccessException") == 0) { + System.out.println(0); + return; + } else { + System.out.println(2); + return; + } + } +} + +interface SuperInterface { + String aSuper = ClassInitFieldSetDoubleInterface.result.append("Super").toString(); +} + +@A +interface OneInterface extends SuperInterface { + String aOne = ClassInitFieldSetDoubleInterface.result.append("One").toString(); + double hiDouble = 0.1532; +} + +interface TwoInterface extends OneInterface { + String aTwo = ClassInitFieldSetDoubleInterface.result.append("Two").toString(); +} + +@interface A { + String aA = ClassInitFieldSetDoubleInterface.result.append("Annotation").toString(); +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0001-rt-String-StmtTest01/StmtTest01.java b/test/testsuite/ouroboros/stmtpre_test/RT0001-rt-String-StmtTest01/StmtTest01.java new file mode 100755 index 0000000000000000000000000000000000000000..ac4990fcb1a83d4c39593ee85e984a73e43652ed --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0001-rt-String-StmtTest01/StmtTest01.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest01 + *- @TestCaseName: StmtTest01 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief:在同一个函数统一分支中出现的字符串常量冗余时,只需要为该字符串常量调用一次runtime的MCC_GetOrInsertLiteral函数。 + * -#step1: 创建一个函数,在该函数中反复调用一个特定的字符串常量做相关操作; + * -#step2: 在main行数用if-else创造两个互斥分支。 + * -#step3: 校验中间文件SmtmTest01.VtableImpl.mpl中 callassigned &MCC_GetOrInsertLiteral出现的次数:3次。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: StmtTest01.java + *- @ExecuteClass: StmtTest01 + *- @ExecuteArgs: + */ + +public class StmtTest01 { + public static void main(String[] args) { + if (test()) { + System.out.println("ExpectResult"); // 1 + } else { + String string = "ExpectResult" + "ExpectResult"; // 2 + System.out.println(string); + } + } + + // 基础的测试 + private static boolean test() { + String string = "A"; // 3 + for (int ii = 0; ii < 100; ii++) { + string += "A"; + } + return string.length() == 101; //true; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0002-rt-String-StmtTest02/StmtTest02.java b/test/testsuite/ouroboros/stmtpre_test/RT0002-rt-String-StmtTest02/StmtTest02.java new file mode 100755 index 0000000000000000000000000000000000000000..a7681216ede194cc0f22207e291cf3462a81e416 --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0002-rt-String-StmtTest02/StmtTest02.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest02 + *- @TestCaseName: StmtTest02 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief:在同一个函数同一个分支中出现的字符串常量冗余,只需要为该字符串常量调用一次runtime的MCC_GetOrInsertLiteral函数。涉及到另外函数调用时,不会做该优化 + * -#step1: 创建一个函数,在该函数中反复调用一个特定的字符串常量做相关操作;再起另一个函数调用该函数,在这个函数中也有该常量字符串的操作。 + * -#step2: 在main行数用if-else创造两个互斥分支。 + * -#step3: 校验中间文件SmtmTest02.VtableImpl.mpl中callassigned &MCC_GetOrInsertLiteral出现的次数:4次。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: StmtTest02.java + *- @ExecuteClass: StmtTest02 + *- @ExecuteArgs: + */ + +public class StmtTest02 { + public static void main(String[] args) { + if (test1()) { + System.out.println("ExpectResult"); // 1 + } else { + System.out.println("ExpectResult " + "ExpectResult"); // 2 + } + } + + // 基础的测试 + private static boolean test() { + String string = "A"; // 3 + for (int ii = 0; ii < 100; ii++) { + string += "A"; + } + return string.length() == 101; //true; + } + + // 有函数调用,确认 + private static boolean test1() { + String str1 = "A" + "A"; // 4 + String str2 = "A" + "A"; + if (test() == true) { + str2 = str1; + } + return str1 == str1; //true + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0003-rt-String-StmtTest03/StmtTest03.java b/test/testsuite/ouroboros/stmtpre_test/RT0003-rt-String-StmtTest03/StmtTest03.java new file mode 100755 index 0000000000000000000000000000000000000000..ac72f648aacba61190b31022a25d563ab04264de --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0003-rt-String-StmtTest03/StmtTest03.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest03 + *- @TestCaseName: StmtTest03 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief:涉及接口实现的场景下,在同一个函数同一分支中出现的字符串常量,只需要为该字符串常量调用一次runtime的MCC_GetOrInsertLiteral函数。 + * -#step1: 创建一个实现接口的类,在该类中实现接口中的函数test(),在该函数中反复调用一个特定的字符串常量做相关操作; + * -#step2: 在main行数用if-else创造两个互斥分支。 + * -#step3: 校验中间文件SmtmTest03.VtableImpl.s中callassigned &MCC_GetOrInsertLiteral出现的次数:3次。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: StmtTest03.java + *- @ExecuteClass: StmtTest03 + *- @ExecuteArgs: + */ + +interface Interface { + boolean test(); +} + +public class StmtTest03 implements Interface { + public static void main(String[] args) { + if (new StmtTest03().test()) { + System.out.println("ExpectResult"); // 1 + } else { + System.out.println("ExpectResult " + "ExpectResult"); // 2 + } + } + + // 实现接口 + public boolean test() { + String str1 = "A" + "A"; // 3 + String str2 = "A" + "A"; + return str1 == str2; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0004-rt-String-StmtTest04/StmtTest04.java b/test/testsuite/ouroboros/stmtpre_test/RT0004-rt-String-StmtTest04/StmtTest04.java new file mode 100755 index 0000000000000000000000000000000000000000..48007205e7fcbe0a2d602ca619c3262515e411c7 --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0004-rt-String-StmtTest04/StmtTest04.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest04 + *- @TestCaseName: StmtTest04 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief:在继承的场景下,在同一个函数中出现的字符串常量,只需要调用runtime的MCC_GetOrInsertLiteral函数只会为该字符串常量调用一次。 + * -#step1: 创建一个有父类的类,在该类中父类中的函数test1(),在该函数中调用一个特定的字符串常量做相关操作; + * -#step2: 在main行数用if-else创造两个互斥分支。 + * -#step3: 校验中间文件SmtmTest04.VtableImpl.s中callassigned &MCC_GetOrInsertLiteral出现的次数:4次。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: StmtTest04.java + *- @ExecuteClass: StmtTest04 + *- @ExecuteArgs: + */ + +class Father { + public String name; + + public boolean test1() { + String str1 = "A" + "A"; // 1 + String str2 = "A" + "A"; + return str1 == str2; // false; + } +} + +public class StmtTest04 extends Father { + public String name; + + public static void main(String[] args) { + Father father = new StmtTest04(); + father.name = "ExpectResult"; // 2 + if (father.test1()) { + System.out.println("ExpectResult"); + } else { + System.out.println("ExpectResult" + " " + "ExpectResult"); // 4 + } + } + + // 集成父类 + @Override + public boolean test1() { + String str1 = "A" + "A"; // 3 + String str2 = "A" + "A"; + return str1.equals(str2); // true; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0005-rt-String-StmtTest05/StmtTest05.java b/test/testsuite/ouroboros/stmtpre_test/RT0005-rt-String-StmtTest05/StmtTest05.java new file mode 100755 index 0000000000000000000000000000000000000000..ec84880051cebac210af9a379fd687900cdf8fdc --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0005-rt-String-StmtTest05/StmtTest05.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest05 + *- @TestCaseName: StmtTest05 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief:在同一个函数中,有Switch-多case分支时,在同一个数据流中出现的冗余字符串常量,只需要为该字符串常量调用一次runtime的MCC_GetOrInsertLiteral函数。 + * -#step1: 在main行数用switch - case创造两个互斥分支。 + * -#step2: 校验中间文件StmtTest05.VtableImpl.mpl中 callassigned &MCC_GetOrInsertLiteral出现的次数:6次。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: StmtTest05.java + *- @ExecuteClass: StmtTest05 + *- @ExecuteArgs: + */ + +public class StmtTest05 { + public static void main(String[] args) { + String test = "TestStringForStmt"; // 1 + switch (test) { + case "TestStringForStmt33": // 6 + test = "TestStringForStmt01"; // 2 + break; + case "TestStringForStmt55": // 3 + test += "TestStringForStmt01"; // 4 + break; + default: + test = "TestStringForStmt"; + break; + } + + String output = "ExpectResult"; // 5 + if (test == "TestStringForStmt") { + System.out.println(output); + } else { + System.out.print("ExpectResult"); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0006-rt-String-StmtTest06/StmtTest06.java b/test/testsuite/ouroboros/stmtpre_test/RT0006-rt-String-StmtTest06/StmtTest06.java new file mode 100755 index 0000000000000000000000000000000000000000..e5590640b78be22842a23ef3c1bdd17d75824943 --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0006-rt-String-StmtTest06/StmtTest06.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest06 + *- @TestCaseName: StmtTest06 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief:在同一个函数中,有try-多catch分支时,在同一个数据流中出现的冗余字符串常量,只需要为该字符串常量调用一次runtime的MCC_GetOrInsertLiteral函数。 + * -#step1: 在main行数用stry-多catch创造两个互斥分支 + * -#step2: 校验中间文件StmtTest06.VtableImpl.mpl中 callassigned &MCC_GetOrInsertLiteral出现的次数:3次。 + *- @Expect:123#\n + *- @Priority: High + *- @Source: StmtTest06.java + *- @ExecuteClass: StmtTest06 + *- @ExecuteArgs: + */ + +public class StmtTest06 { + public static void main(String[] argv) { + int result = 2; + boolean check; + String str = "123#"; // 1 + try { + Integer.parseInt(str); + } catch (NumberFormatException e) { + str = "123#456"; // 2 + result--; + } catch (NullPointerException e) { + str = "123456"; // 3 + result = 2; + } catch (OutOfMemoryError e) { + str += "123#456"; // 被外提 + result = 2; + } finally { + check = str == "123#456"; + result--; + } + if (check == true && result == 0) { + System.out.println("123#"); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 123#\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0007-rt-String-StmtTest07/StmtTest07.java b/test/testsuite/ouroboros/stmtpre_test/RT0007-rt-String-StmtTest07/StmtTest07.java new file mode 100755 index 0000000000000000000000000000000000000000..74e166c34aed1d6ead4eb3ef2ac6df60c95970b8 --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0007-rt-String-StmtTest07/StmtTest07.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest07 + *- @TestCaseName: StmtTest07 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief: 在同一个函数统一分支(try{For循环嵌套}catch{})中出现的字符串常量冗余时,只需要为该字符串常量调用一次runtime的MCC_GetOrInsertLiteral函数。 + * -#step1: 在test()函数用for多层嵌套、try-多catch创造for嵌套和互斥分支,并冗余使用字符串常量 + * -#step2: 校验中间文件SmtmTest07.VtableImpl.mpl中 callassigned &MCC_GetOrInsertLiteral出现的次数:4次。 + *- @Expect:AA\nExpectResult\n + *- @Priority: High + *- @Source: StmtTest07.java + *- @ExecuteClass: StmtTest07 + *- @ExecuteArgs: + */ + +public class StmtTest07 { + public static void main(String[] args) { + if (test()) { + System.out.println("ExpectResult"); // 1 + } else { + String string = "ExpectResult" + "ExpectResult"; // 2 + System.out.println(string); + } + } + + // 基础的测试for循环嵌套 + private static boolean test() { + String string = "AA"; // 3 + for (int ii = 0; ii < 10; ii++) { + string = "AA"; + for (int jj = 0; jj < 10; jj++) { + for (int kk = 0; kk < 2; kk++) { + string += "AA"; + } + } + } + try { + string = "AA"; + for (int jj = 0; jj < 10; jj++) { + for (int ii = 0; ii < getInt(); ii++) { + string += "123"; // 4 + } + } + } catch (ArithmeticException a) { + System.out.println(string); + } + return string.length() == 2; //true; + } + + private static int getInt() { + return 1 / 0; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan AA\nExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0008-rt-String-StmtTest08/StmtTest08.java b/test/testsuite/ouroboros/stmtpre_test/RT0008-rt-String-StmtTest08/StmtTest08.java new file mode 100755 index 0000000000000000000000000000000000000000..613f9b30450734d64af518e6e9aef0cfb5c1546f --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0008-rt-String-StmtTest08/StmtTest08.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest08 + *- @TestCaseName: StmtTest08 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief: 在同一个函数统一分支if-else多分支中出现的字符串常量冗余时,同一数据流里的冗余字符串常量只需要为该字符串常量才会调用一次runtime的MCC_GetOrInsertLiteral函数。 + * -#step1: 在test1()函数有多层if-else分支,并冗余使用字符串常量 + * -#step2: 校验中间文件StmtTest08.VtableImpl.mpl中callassigned &MCC_GetOrInsertLiteral出现的次数:7次。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: StmtTest08.java + *- @ExecuteClass: StmtTest08 + *- @ExecuteArgs: + */ + +public class StmtTest08 { + public static void main(String[] args) { + if (test1() == false) { + System.out.println("ExpectResult"); // 1 + } else { + System.out.println("ExpectResult " + "ExpectResult"); // 2 + } + } + + // 基础的测试 + private static boolean test() { + String string = "A"; // 3 + for (int ii = 0; ii < 100; ii++) { + string += "A"; + } + return string.length() == 101; //true; + } + + // 有函数调用,确认 + private static boolean test1() { + String str1 = "AA"; // 4 + String str2; + if (test() == true) { + str2 = str1; + if (str2 == "AA") { + str2 = str2.substring(0, 1); + } else { + str1 = "AAA"; // 5 + } + } else { + str2 = "A"; // 6 + if (str2.equals("AA")) { + str2 = str2.substring(0, 1); + } else { + str1 = "AAA"; // 7 + } + } + return str2 == str1; //true + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0009-rt-String-StmtTest09/StmtTest09.java b/test/testsuite/ouroboros/stmtpre_test/RT0009-rt-String-StmtTest09/StmtTest09.java new file mode 100755 index 0000000000000000000000000000000000000000..d20a858e977786bef2bc38c524998e63c4a1eb62 --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0009-rt-String-StmtTest09/StmtTest09.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest09 + *- @TestCaseName: StmtTest09 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief: 在同一个函数同一个分支(多层switch嵌套)中出现的字符串常量冗余,只需要为该字符串常量调用一次runtime的MCC_GetOrInsertLiteral函数。涉及到函数调用时,不会做该优化 + * -#step1: 在main方法中函数有switch-多case分支,并冗余使用字符串常量 + * -#step2: 校验中间文件StmtTest09.VtableImpl.mpl中callassigned &MCC_GetOrInsertLiteral出现的次数:8次。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: StmtTest09.java + *- @ExecuteClass: StmtTest09 + *- @ExecuteArgs: + */ + +public class StmtTest09 { + public static void main(String[] args) { + String test = "TestStringForStmt"; // 1 + switch (test) { + case "TestStringForStmt33": // 2 + test = "TestStringForStmt01"; // 3 + break; + case "TestStringForStmt55": // 4 + test += "TestStringForStmt01"; // 其他优化导致"TestStringForStmt01"的地址调用外提到22行,所以与33行合用。 + break; + default: + switch (test) { + case "TestStringForStmt34": // 5 + test = "TestStringForStmt01"; // 其他优化导致"TestStringForStmt01"的地址调用外提到22行,所以与33行合用 + break; + case "TestStringForStmt35": // 6 + test += "TestStringForStmt01"; // 7 + break; + default: + test = "TestStringForStmt"; + break; + } + } + String output = "ExpectResult"; // 8、 + if (test == "TestStringForStmt") { + System.out.println(output); + } else { + System.out.print("ExpectResult"); + } + + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0010-rt-String-StmtTest10/StmtTest10.java b/test/testsuite/ouroboros/stmtpre_test/RT0010-rt-String-StmtTest10/StmtTest10.java new file mode 100755 index 0000000000000000000000000000000000000000..87e94738fa6af7d1b13ae7fb3aa9acf3dda62fc1 --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0010-rt-String-StmtTest10/StmtTest10.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest10 + *- @TestCaseName: StmtTest10 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief: 在同一个函数同一个分支(多层try-多cathc嵌套)中出现的字符串常量冗余,只需要为该字符串常量调用一次runtime的MCC_GetOrInsertLiteral函数。涉及到函数调用时,不会做该优化 + * -#step1: 在main方法中函数有两层try-多catch分支,并冗余使用字符串常量 + * -#step2: 校验中间文件StmtTest10.VtableImpl.mpl中 callassigned &MCC_GetOrInsertLiteral出现的次数:4次。 + * 注:"123#456"的函数调用会外提,因此在实际的中间代码里出现的次数是4次。 + *- @Expect:123#\n + *- @Priority: High + *- @Source: StmtTest10.java + *- @ExecuteClass: StmtTest10 + *- @ExecuteArgs: + */ + +public class StmtTest10 { + public static void main(String[] argv) { + int result = 2; + boolean check; + String str = "123#"; // 1 + try { + str = "123456"; // 2 + try { + Integer.parseInt(str); + } catch (NumberFormatException e) { + str = "123#456"; // 3 + result--; + } catch (NullPointerException e) { + str = "123456#"; // 4 + result = 2; + } catch (OutOfMemoryError e) { + str += "123#456"; // 与32行被其他优化了 + result = 2; + } finally { + str = "123#456"; + } + Integer.parseInt(str); + } catch (NumberFormatException e) { + str = "123#456"; + result--; + } catch (NullPointerException e) { + str = "123456"; + result = 2; + } catch (OutOfMemoryError e) { + str += "123#456"; + result = 2; + } finally { + check = str == "123#456"; + result--; + } + if (check == true && result == 0) { + System.out.println("123#"); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 123#\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0011-rt-String-StmtTest11/StmtTest11.java b/test/testsuite/ouroboros/stmtpre_test/RT0011-rt-String-StmtTest11/StmtTest11.java new file mode 100755 index 0000000000000000000000000000000000000000..a2f36952f0ffb798c49fc8f4f412f380ea100584 --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0011-rt-String-StmtTest11/StmtTest11.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest11 + *- @TestCaseName: StmtTest11 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief: 在同一个函数同一数据流分支(For/If-else/try-catch/switch-case)中出现的字符串常量冗余时,只需要为该字符串常量调用一次runtime的MCC_GetOrInsertLiteral函数。 + * -#step1: 在main方法中函数有try-catch/switch-case/if-else嵌套使用,并冗余使用字符串常量 + * -#step2: 校验中间文件StmtTest11.VtableImpl.mpl中 callassigned &MCC_GetOrInsertLiteral出现的次数:6次。 + *- @Expect:AB\nExpectResult\n + *- @Priority: High + *- @Source: StmtTest11.java + *- @ExecuteClass: StmtTest11 + *- @ExecuteArgs: + */ + +public class StmtTest11 { + public static void main(String[] args) { + if (test()) { + System.out.println("ExpectResult"); // 1 + } else { + String string = "ExpectResultExpectResult"; // 2 + System.out.println(string); + } + } + + // 基础的测试for循环嵌套 + private static boolean test() { + String string = "AA"; // 3 + try { + string = "AB"; // 4 + if (string.length() == 2) { + for (int jj = 0; jj < 10; jj++) { + for (int ii = 0; ii < getInt(); ii++) { + string += "123"; // 5,被外提 + } + } + } else { + switch (string) { + case "A": // 6 + string = "123"; //被外提 + break; + case "AA": + string = "A"; + break; + default: + break; + } + } + } catch (ArithmeticException a) { + System.out.println(string); + } + return string.length() == 2; //true; + } + + private static int getInt() { + return 1 / 0; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan AB\nExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0013-rt-String-StmtTest13/StmtTest13.java b/test/testsuite/ouroboros/stmtpre_test/RT0013-rt-String-StmtTest13/StmtTest13.java new file mode 100755 index 0000000000000000000000000000000000000000..92a72641cd117b5b355de2609240a3063bacf036 --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0013-rt-String-StmtTest13/StmtTest13.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest13 + *- @TestCaseName: StmtTest13 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief: 字符串常量在字符串常量池中,引用变量拼接和new出来的在堆上,不会做该优化,实例变量上的字符串常量不参与常量。 + * -#step1: 校验中间文件StmtTest13.VtableImpl.mpl中 callassigned &MCC_GetOrInsertLiteral出现的次数:3次。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: StmtTest13.java + *- @ExecuteClass: StmtTest13 + *- @ExecuteArgs: + */ + +public class StmtTest13 { + private String outOfMethod = "AB"; //3 + + public static void main(String[] args) { + String string = "AB"; // 1 + for (int ii = 0; ii < 10; ii++) { + string += "A" + "B"; + } + if (string.length() == 22) { + string = "AB"; //此处在堆上分配内存,不会用第22行的伪寄存器地址 + } else { + char[] chars = {'A', 'B'}; + string = chars.toString(); + } + if (string.equals(new StmtTest13().outOfMethod)) { + System.out.println("ExpectResult"); // 2 + } else { + System.out.print("ExpectResult"); //优化外提,这边不会再取一次。 + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/stmtpre_test/RT0014-rt-String-StmtTest14/StmtTest14.java b/test/testsuite/ouroboros/stmtpre_test/RT0014-rt-String-StmtTest14/StmtTest14.java new file mode 100755 index 0000000000000000000000000000000000000000..7124309faf1d5af138db243d48485ddd02b8bada --- /dev/null +++ b/test/testsuite/ouroboros/stmtpre_test/RT0014-rt-String-StmtTest14/StmtTest14.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_StmtTest13 + *- @TestCaseName: StmtTest13 + *- @TestCaseType: Function Testing + *- @RequirementName: Store PRE和Stmt PRE使能(store PRE 收益十分有限,先挂起) + *- @Brief: 字符串常量在各种情况下出现冗余时,都应该用优化后的同一个伪寄存器地址。 + * -#step1: 校验中间文件StmtTest14.VtableImpl.mpl中 callassigned &MCC_GetOrInsertLiteral出现的次数:1次。 + *- @Expect:AB\n + *- @Priority: High + *- @Source: StmtTest14.java + *- @ExecuteClass: StmtTest14 + *- @ExecuteArgs: + */ + +import java.nio.charset.StandardCharsets; + +public class StmtTest14 { + public static void main(String[] args) { + String string = "AB"; // 1 + for (int ii = 0; ii < 10; ii++) { + string += "A" + "B"; // +号拼接场景 + } + if (string.length() == 22) { + string = "AB"; // 作为入参 + } else { + char[] chars = "AB".toCharArray(); // 作为函数调用主体 + string = chars.toString(); + } + byte[] bs = string.getBytes(); + string = new String(bs, StandardCharsets.US_ASCII); + System.out.println(string); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan AB\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0001-rt-string-ReflectString/ReflectString.java b/test/testsuite/ouroboros/string_test/RT0001-rt-string-ReflectString/ReflectString.java new file mode 100755 index 0000000000000000000000000000000000000000..a6bc2325252a1c2b8751dafbaa2fa458e301057f --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0001-rt-string-ReflectString/ReflectString.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ReflectString.java + * -@TestCaseName: String.class.newInstance + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1:create String instance by Reflect + * -#step1:check the instance corret + * -@Expect:0\n + * -@Priority: High + * -@Source: ReflectString.java + * -@ExecuteClass: ReflectString + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ReflectString { + static int res = 99; + + public static void main(String argv[]) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 2/*STATUS_FAILED*/; + + try { + ReflectString_1(); + } catch (Exception e) { + res -= 10; + } + if (result == 2 && res == 95) { + result = 0; + } + return result; + + } + + public static void ReflectString_1() { + int result1 = 4; /*STATUS_FAILED*/ + Object test1 = null; + try { + test1 = String.class.newInstance(); + res -= 4; + } catch (InstantiationException e1) { + System.err.println(e1); + } catch (IllegalAccessException e2) { + System.err.println(e2); + } +// System.out.println("test1:"+ test1); + + } + +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0002-rt-String-BufferConstructorsTest/StringBufferConstructorsTest.java b/test/testsuite/ouroboros/string_test/RT0002-rt-String-BufferConstructorsTest/StringBufferConstructorsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..1e5f9dd5e19957973d5be02597d0a0a804436e09 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0002-rt-String-BufferConstructorsTest/StringBufferConstructorsTest.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferConstructorsTest.java + * -@TestCaseName: Test String Buffer Constructors StringBuffer(String str)/StringBuffer()/StringBuffer(int capacity) + * /StringBuffer(CharSequence seq). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#case1 + * -#step1: Create a String instance By new and not new. + * -#step2: Test Constructor StringBuffer(String str). + * -#step3: Check new StringBuffer instance is new correctly. + * -#step4: Change Parameter str Traversing String mix with Letter and special symbols and Number、empty String、null to + * repeat step2~3. + * -#case2 + * -#step1: Test new StringBuffer() and check the capacity() of instance is correctly. + * -#step2: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step1. + * -#case3 + * -#step1: Create capacity > 0 or capacity = 0, test new StringBuffer(int capacity), check the capacity() of instance + * is correctly. + * -#case4 + * -#step1: Create seq Contains numbers, letters, special symbols, test StringBuffer(CharSequence seq), check new + * instance is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferConstructorsTest.java + * -@ExecuteClass: StringBufferConstructorsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferConstructorsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferConstructorsTest_1(); + } catch (Exception e) { + e.printStackTrace(); + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferConstructorsTest_1() { + String str1_1 = new String("abc123abc"); + String str1_2 = new String(" @!.&%()*"); + String str1_3 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "abc123ABC"; + String str2_2 = " @!.&%()*"; + String str2_3 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZX" + + "CVBNM0x96"; + String str2_4 = ""; + + test1_1(str1_1); + test1_1(str1_2); + test1_1(str1_3); + test1_1(str1_4); + test1_1(str1_5); + test1_1(str2_1); + test1_1(str2_2); + test1_1(str2_3); + test1_1(str2_4); + + StringBuffer strBuffer1_1 = new StringBuffer("abc123abc"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=" + + "!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + + test1_2(strBuffer1_1); + test1_2(strBuffer1_2); + test1_2(strBuffer1_3); + test1_2(strBuffer1_4); + test1_2(strBuffer1_5); + + test1_3(); + test1_4(); + test1_5(); + } + + private static void test1_1(String str) { + System.out.println(new StringBuffer(str)); + } + + private static void test1_2(StringBuffer strBuffer) { + System.out.println(strBuffer.toString()); + } + + // Test new StringBuffer(). + private static void test1_3() { + StringBuffer strBuffer1_6 = new StringBuffer(); + System.out.println(strBuffer1_6.capacity()); + } + + // Test new StringBuffer(int capacity). + private static void test1_4() { + int capacity = 20; + StringBuffer strBuffer1_6 = new StringBuffer(capacity); + System.out.println(strBuffer1_6.capacity()); + int capacityMin = 0; + strBuffer1_6 = new StringBuffer(capacityMin); + System.out.println(strBuffer1_6.capacity()); + } + + // Test new StringBuffer(CharSequence seq). + private static void test1_5() { + CharSequence chs1_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTY" + + "UIOPZXCVBNM0x96"; + StringBuffer strBuffer1_7 = new StringBuffer(chs1_1); + test1_2(strBuffer1_7); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123abc\s*\@\!\.\&\%\(\)\*\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*abc123ABC\s*\@\!\.\&\%\(\)\*\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*abc123abc\s*\@\!\.\&\%\(\)\*\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*16\s*20\s*0\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0003-rt-String-BufferAppendAndAppendCodePointTest/StringBufferAppendAndAppendCodePointTest.java b/test/testsuite/ouroboros/string_test/RT0003-rt-String-BufferAppendAndAppendCodePointTest/StringBufferAppendAndAppendCodePointTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ae67155b9bb7c69b7bb7f5b35a794e9d550e7799 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0003-rt-String-BufferAppendAndAppendCodePointTest/StringBufferAppendAndAppendCodePointTest.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferAppendAndAppendCodePointTest.java + * -@TestCaseName: Test method append(boolean b)/append(char c)/append(char[] str)/append(CharSequence s)/ + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * append(CharSequence s, int start, int end)/append(double d)/append(float f)/append(int i)/ + * append(long lng)/append(Object obj)/append(String str)/append(StringBuffer sb)/ + * appendCodePoint(int codePoint) of StringBuffer. + * -@Brief: + * -#step1: Create StringBuffer instance. + * -#step2: Create parameter str is a String instance, test method append(String str). + * -#step3: Create parameter b is true or false, test method append(boolean b). + * -#step4: Create parameter c is a letter, test method append(char c). + * -#step5: Create parameter data.length > 0, data.element is a char, test method append(char[] data). + * -#step6: Create parameter s is a CharSequence, test method append(CharSequence s). + * -#step7: Create parameters: s is a CharSequence, 0 =< start < end, end <= s.length, start and end coverage boundary + * value. test method append(CharSequence s, int start, int end). + * -#step8: Create parameter d > 0 or d = 0, test method append(double d). + * -#step9: Create parameter f > 0 or f = 0, test method append(float f). + * -#step10: Create parameter i > 0 or i = 0, test method append(int i). + * -#step11: Create parameter lng > 0 or lng = 0, test method append(long lng). + * -#step12: Create parameter obj is a Object, test method append(Object obj). + * -#step13: Create parameter sb is a StringBuffer, test method append(StringBuffer sb). + * -#step14: Create parameter codePoint is unicode num, test method appendCodePoint(int codePoint). + * -#step15: Check the append result is correctly and the Src StringBuffer is correctly. + * -#step16: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~15. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferAppendAndAppendCodePointTest.java + * -@ExecuteClass: StringBufferAppendAndAppendCodePointTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferAppendAndAppendCodePointTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferAppendAndAppendCodePointTest_1(); + } catch (Exception e) { + e.printStackTrace(); + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferAppendAndAppendCodePointTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + test1(strBuffer1_4); + test1(strBuffer1_5); + } + + private static void test1(StringBuffer strBuffer) { + char c = 'C'; + char[] data = {'A', 'B', 'C'}; + CharSequence chs1_1 = "xyz"; + double d = 8888.8888; + double dMin = 0; + float f = 99999999; + float fMin = 0; + int i = 77777777; + int iMin = 0; + long lng = 66666666; + long lngMin = 0; + Object obj = new String("object"); + String str = "string"; + StringBuffer sb = new StringBuffer("stringbuffer"); + int codePoint = 74; // unicode 74 is J + + System.out.println(strBuffer.append("-").append(true).append("-").append(false).append("-").append(c) + .append("-").append(data).append("-").append(chs1_1).append("-").append(chs1_1, 1, 2).append("-") + .append(chs1_1, 0, 3).append("-").append(chs1_1, 3, 3).append("-").append(chs1_1, 0, 0).append("-") + .append(d).append("-").append(dMin).append("-").append(f).append("-").append(fMin).append("-").append(i) + .append("-").append(iMin).append("-").append(lng).append("-").append(lngMin).append("-").append(obj) + .append("-").append(str).append("-").append(sb).append("-").appendCodePoint(codePoint)); + System.out.println(strBuffer.subSequence(2, 8)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-stringbuffer\-J\s*ertyui\s*\@\!\.\&\%\(\)\*\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-stringbuffer\-J\s*\!\.\&\%\(\)\s*abc123abc\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-stringbuffer\-J\s*c123ab\s*\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-stringbuffer\-J\s*rue\-fa\s*\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-stringbuffer\-J\s*rue\-fa\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0004-rt-String-BufferInsertTest/StringBufferInsertTest.java b/test/testsuite/ouroboros/string_test/RT0004-rt-String-BufferInsertTest/StringBufferInsertTest.java new file mode 100755 index 0000000000000000000000000000000000000000..87d8186ffa3eda8392f6dabb5413e41db1b1e0bf --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0004-rt-String-BufferInsertTest/StringBufferInsertTest.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferInsertTest.java + * -@TestCaseName: Test Method insert(Various parameters) of StringBuffer include insert(int offset, boolean b)/ + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * insert(int offset, char c)/insert(int offset, char[] str)/insert(int dstOffset, CharSequence s)/ + * insert(int dstOffset, CharSequence s, int start, int end)/insert(int offset, double d)/insert + * (int offset, float f)/insert(int offset, int i)/insert(int offset, long l)/insert(int offset, + * Object obj)/insert(int offset, String str). + * -@Brief: + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: 0 =< offset < instance.length, offset test boundary value, str is a String, test method + * insert(int offset, String str). + * -#step3: Create parameters: 0 =< offset < instance.length, offset test boundary value, b is true/false, test method + * insert(int offset, boolean b). + * -#step4: Create parameters: 0 =< offset < instance.length, offset test boundary value, c is a char, test method + * insert(int offset, char c). + * -#step5: Create parameters: 0 =< offset < instance.length, offset test boundary value, create a char[] data, test + * method insert(int offset, char[] data). + * -#step6: Create parameters: 0 =< offset < instance.length, offset test boundary value, s is a CharSequence, test + * method insert(int offset, CharSequence s). + * -#step7: Create parameters: 0 =< offset < instance.length, s is a CharSequence, 0 =< start < end, end <= s.length, + * offset/start/end test boundary value, test method insert(int offset, CharSequence s, int start, int end). + * -#step8: Create parameters: 0 =< offset < instance.length, offset test boundary value, d > 0 or d = 0, test method + * insert(int offset, double d). + * -#step9: Create parameters: 0 =< offset < instance.length, offset test boundary value, f > 0 or f = 0, test method + * insert(int offset, float f). + * -#step10: Create parameters: 0 =< offset < instance.length, offset test boundary value, i > 0 or i = 0, test method + * insert(int offset, int i). + * -#step11: Create parameters: 0 =< offset < instance.length, offset test boundary value, l > 0 or l = 0, test method + * insert(int offset, long l). + * -#step12: Create parameters: 0 =< offset < instance.length, offset test boundary value, obj is a Object, test method + * insert(int offset, Object obj). + * -#step13: Check the insert result is correctly and the Src instance is correctly. + * -#step14: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~13. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferInsertTest.java + * -@ExecuteClass: StringBufferInsertTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferInsertTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferInsertTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferInsertTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + test1(strBuffer1_4); + test1(strBuffer1_5); + } + + private static void test1(StringBuffer strBuffer) { + boolean b = true; + char c = 'C'; + char[] data = {'A', 'B', 'C'}; + CharSequence chs1_1 = "xyz"; + double d = 8888.8888; + double dMin = 0; + float f = 99999999; + float fMin = 0; + int i = 77777777; + int iMin = 0; + long lng = 66666666; + long lngMin = 0; + Object obj = new String("object"); + String str = "-"; + + System.out.println(strBuffer.insert(0, str).insert(0, b).insert(strBuffer.length(), str) + .insert(strBuffer.length(), b).insert(0, str).insert(0, false).insert(strBuffer.length(), str) + .insert(strBuffer.length(), false).insert(0, str).insert(0, c).insert(strBuffer.length(), str) + .insert(strBuffer.length(), c).insert(0, str).insert(0, data).insert(strBuffer.length(), str) + .insert(strBuffer.length(), data).insert(0, str).insert(0, chs1_1).insert(strBuffer.length(), str) + .insert(strBuffer.length(), chs1_1).insert(0, str).insert(0, chs1_1, 1, 2) + .insert(strBuffer.length(), str).insert(strBuffer.length(), chs1_1, 1, 2).insert(0, str) + .insert(0, chs1_1, 0, 3).insert(strBuffer.length(), str).insert(strBuffer.length(), chs1_1, 0, 3) + .insert(0, str).insert(0, chs1_1, 3, 3).insert(strBuffer.length(), str) + .insert(strBuffer.length(), chs1_1, 3, 3).insert(0, str).insert(0, chs1_1, 0, 0) + .insert(strBuffer.length(), str).insert(strBuffer.length(), chs1_1, 0, 0).insert(0, str).insert(0, d) + .insert(strBuffer.length(), str).insert(strBuffer.length(), d).insert(0, str).insert(0, dMin) + .insert(0, str).insert(0, f).insert(strBuffer.length(), str).insert(strBuffer.length(), f) + .insert(0, str).insert(0, fMin).insert(0, str).insert(0, i).insert(strBuffer.length(), str) + .insert(strBuffer.length(), i).insert(0, str).insert(0, iMin).insert(0, str).insert(0, lng) + .insert(strBuffer.length(), str).insert(strBuffer.length(), lng).insert(0, str) + .insert(0, lngMin).insert(0, str).insert(0, obj).insert(strBuffer.length(), str) + .insert(strBuffer.length(), obj)); + System.out.println(strBuffer.subSequence(2, 8)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-true\-qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-true\-\s*\@\!\.\&\%\(\)\*\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-true\-abc123abc\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-true\-\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-true\-\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0005-rt-String-BufferDeleteAndDeleteCharAtTest/StringBufferDeleteAndDeleteCharAtTest.java b/test/testsuite/ouroboros/string_test/RT0005-rt-String-BufferDeleteAndDeleteCharAtTest/StringBufferDeleteAndDeleteCharAtTest.java new file mode 100755 index 0000000000000000000000000000000000000000..92dfc610bbf27e23903788e7e630e0a98f0624c8 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0005-rt-String-BufferDeleteAndDeleteCharAtTest/StringBufferDeleteAndDeleteCharAtTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferDeleteAndDeleteCharAtTest.java + * -@TestCaseName: Test Method StringBuffer delete(int start, int end) and StringBuffer deleteCharAt(int index) of + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * StringBuffer. + * -@Brief: + * -#case1 + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: 0 =< start =< end, end =< instance.length, start and end coverage boundary value. + * -#step3: Test Method delete(int start, int end) and check result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case2 + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: 0 =< index < instance.length, index coverage boundary value. + * -#step3: Test Method deleteCharAt(int index) and check result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferDeleteAndDeleteCharAtTest.java + * -@ExecuteClass: StringBufferDeleteAndDeleteCharAtTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferDeleteAndDeleteCharAtTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferDeleteAndDeleteCharAtTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferDeleteAndDeleteCharAtTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + + StringBuffer strBuffer2_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer2_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer2_3 = new StringBuffer("abc123abc"); + + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + + test2(strBuffer2_1); + test2(strBuffer2_2); + test2(strBuffer2_3); + } + + // Test method delete(int start, int end). + private static void test1(StringBuffer strBuffer) { + // Test 0 < start < end, end < strBuffer.length(). + System.out.println(strBuffer.delete(3, 5)); + // Test start = 0. + System.out.println(strBuffer.delete(0, 1)); + // Test end = 0. + System.out.println(strBuffer.delete(0, 0)); + // Test start=strBuffer.length(). + System.out.println(strBuffer.delete(strBuffer.length(), strBuffer.length())); + // Test end=strBuffer.length(). + System.out.println(strBuffer.delete(2, strBuffer.length())); + } + + // Test method deleteCharAt(int index). + private static void test2(StringBuffer strBuffer) { + // Test 0 < index < strBuffer.length(). + System.out.println(strBuffer.deleteCharAt(1)); + // Test index = 0. + System.out.println(strBuffer.deleteCharAt(0)); + // Test index = strBuffer.length() - 1. + System.out.println(strBuffer.deleteCharAt(strBuffer.length() - 1)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qweyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*weyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*weyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*weyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*we\s*\@\!\%\(\)\*\s*\@\!\%\(\)\*\s*\@\!\%\(\)\*\s*\@\!\%\(\)\*\s*\@\!\s*abc3abc\s*bc3abc\s*bc3abc\s*bc3abc\s*bc\s*qertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x9\s*\!\.\&\%\(\)\*\s*\!\.\&\%\(\)\*\s*\!\.\&\%\(\)\s*ac123abc\s*c123abc\s*c123ab\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0006-rt-String-BufferCodePointExceptionTest/StringBufferCodePointExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0006-rt-String-BufferCodePointExceptionTest/StringBufferCodePointExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0584187fc1bca5b5648a538b5556f309afc1d2a4 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0006-rt-String-BufferCodePointExceptionTest/StringBufferCodePointExceptionTest.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferCodePointExceptionTest.java + * -@TestCaseName: Test method codePointAt(int index)/codePointBefore(int index)/codePointCount(int beginIndex, int + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * endIndex)/offsetByCodePoints(int index, int codePointOffset) of StringBuffer, test + * StringIndexOutOfBoundsException throw in codePointAt and codePointBefore, test + * IndexOutOfBoundsException throw in codePointCount and offsetByCodePoints. + * -@Brief: + * -#case1 + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: index range from 0 to instance.length. + * -#step3: Test method codePointAt(int index). Check result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case2 + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: index range from 0 to instance.length. + * -#step3: Test method codePointBefore(int index). Check result is correctly, StringIndexOutOfBoundsException is thrown + * when index = 0. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case3 + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: beginIndex range from 0 to instance.length - 2, endIndex = beginIndex + 3. + * -#step3: Test method codePointCount(int beginIndex, int endIndex),Check result is correctly.IndexOutOfBoundsException + * is thrown when endIndex > instance.length - 1. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case4 + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: index range from 0 to instance.length - 2, codePointOffset = index + 3. + * -#step3: Test method int offsetByCodePoints(int index, int codePointOffset),Check result is correctly, + * StringIndexOutOfBoundsException is thrown when index + codePointOffset > instance.length. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferCodePointExceptionTest.java + * -@ExecuteClass: StringBufferCodePointExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferCodePointExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferCodePointExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferCodePointExceptionTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-" + + "=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123"); + + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + + test2(strBuffer1_1); + test2(strBuffer1_2); + test2(strBuffer1_3); + + test3(strBuffer1_1); + test3(strBuffer1_2); + test3(strBuffer1_3); + + test4(strBuffer1_1); + test4(strBuffer1_2); + test4(strBuffer1_3); + } + + // Test method codePointAt(int index). + private static void test1(StringBuffer strBuffer) { + int codePoint = 0; + for (int i = 0; i < 6; i++) { + try { + codePoint = strBuffer.codePointAt(i); + System.out.println("i=" + i + " " + "codePointAt=" + codePoint); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("codePointAt(): " + i + "out of length"); + } finally { + try { + System.out.println(strBuffer.charAt(i) + " Unicode is" + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println(i + " out of length"); + } + } + } + } + + // Test method codePointBefore(int index). + private static void test2(StringBuffer strBuffer) { + int codePoint = 0; + for (int i = 0; i < 6; i++) { + try { + codePoint = strBuffer.codePointBefore(i); + System.out.println("i=" + i + " " + "codePointBefore=" + codePoint); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("codePointBefore(): " + i + "out of length"); + } finally { + try { + System.out.println(strBuffer.charAt(i - 1) + " Unicode is" + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println(i + " out of length"); + } + } + } + } + + // Test method codePointCount(int beginIndex, int endIndex). + private static void test3(StringBuffer strBuffer) { + int codePoint = 0; + for (int i = 0; i < 4; i++) { + try { + codePoint = strBuffer.codePointCount(i, i + 3); + System.out.println("i=" + i + " " + "codePointCount=" + codePoint); + } catch (IndexOutOfBoundsException e1) { + System.out.println("codePointCount(): " + i + " out of length"); + } finally { + try { + System.out.println(strBuffer.charAt(i) + "~" + strBuffer.charAt(i + 3) + + " codePointCount is " + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println(i + " out of length"); + } + } + } + } + + // Test method int offsetByCodePoints(int index, int codePointOffset). + private static void test4(StringBuffer strBuffer) { + int codePoint = 0; + for (int i = 0; i < 4; i++) { + try { + codePoint = strBuffer.offsetByCodePoints(i, i + 3); + System.out.println("i=" + i + " " + "offsetByCodePoints=" + codePoint); + } catch (IndexOutOfBoundsException e1) { + System.out.println("offsetByCodePoints(): " + i + "+3 out of length"); + } finally { + try { + System.out.println(strBuffer.charAt(i) + " offsetByCodePoints +3 is " + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " out of length"); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan i\=0\s*codePointAt\=113\s*q\s*Unicode\s*is\:113\s*i\=1\s*codePointAt\=119\s*w\s*Unicode\s*is\:119\s*i\=2\s*codePointAt\=101\s*e\s*Unicode\s*is\:101\s*i\=3\s*codePointAt\=114\s*r\s*Unicode\s*is\:114\s*i\=4\s*codePointAt\=116\s*t\s*Unicode\s*is\:116\s*i\=5\s*codePointAt\=121\s*y\s*Unicode\s*is\:121\s*i\=0\s*codePointAt\=32\s*Unicode\s*is\:32\s*i\=1\s*codePointAt\=64\s*\@\s*Unicode\s*is\:64\s*i\=2\s*codePointAt\=33\s*\!\s*Unicode\s*is\:33\s*i\=3\s*codePointAt\=46\s*\.\s*Unicode\s*is\:46\s*i\=4\s*codePointAt\=38\s*\&\s*Unicode\s*is\:38\s*i\=5\s*codePointAt\=37\s*\%\s*Unicode\s*is\:37\s*i\=0\s*codePointAt\=97\s*a\s*Unicode\s*is\:97\s*i\=1\s*codePointAt\=98\s*b\s*Unicode\s*is\:98\s*i\=2\s*codePointAt\=99\s*c\s*Unicode\s*is\:99\s*i\=3\s*codePointAt\=49\s*1\s*Unicode\s*is\:49\s*i\=4\s*codePointAt\=50\s*2\s*Unicode\s*is\:50\s*i\=5\s*codePointAt\=51\s*3\s*Unicode\s*is\:51\s*codePointBefore\(\)\:\s*0out\s*of\s*length\s*0\s*out\s*of\s*length\s*i\=1\s*codePointBefore\=113\s*q\s*Unicode\s*is\:113\s*i\=2\s*codePointBefore\=119\s*w\s*Unicode\s*is\:119\s*i\=3\s*codePointBefore\=101\s*e\s*Unicode\s*is\:101\s*i\=4\s*codePointBefore\=114\s*r\s*Unicode\s*is\:114\s*i\=5\s*codePointBefore\=116\s*t\s*Unicode\s*is\:116\s*codePointBefore\(\)\:\s*0out\s*of\s*length\s*0\s*out\s*of\s*length\s*i\=1\s*codePointBefore\=32\s*Unicode\s*is\:32\s*i\=2\s*codePointBefore\=64\s*\@\s*Unicode\s*is\:64\s*i\=3\s*codePointBefore\=33\s*\!\s*Unicode\s*is\:33\s*i\=4\s*codePointBefore\=46\s*\.\s*Unicode\s*is\:46\s*i\=5\s*codePointBefore\=38\s*\&\s*Unicode\s*is\:38\s*codePointBefore\(\)\:\s*0out\s*of\s*length\s*0\s*out\s*of\s*length\s*i\=1\s*codePointBefore\=97\s*a\s*Unicode\s*is\:97\s*i\=2\s*codePointBefore\=98\s*b\s*Unicode\s*is\:98\s*i\=3\s*codePointBefore\=99\s*c\s*Unicode\s*is\:99\s*i\=4\s*codePointBefore\=49\s*1\s*Unicode\s*is\:49\s*i\=5\s*codePointBefore\=50\s*2\s*Unicode\s*is\:50\s*i\=0\s*codePointCount\=3\s*q\~r\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*w\~t\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*e\~y\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*r\~u\s*codePointCount\s*is\s*\:3\s*i\=0\s*codePointCount\=3\s*\~\.\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*\@\~\&\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*\!\~\%\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*3\s*out\s*of\s*length\s*i\=0\s*codePointCount\=3\s*a\~1\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*b\~2\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*c\~3\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*3\s*out\s*of\s*length\s*i\=0\s*offsetByCodePoints\=3\s*q\s*offsetByCodePoints\s*\+3\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*w\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*i\=2\s*offsetByCodePoints\=7\s*e\s*offsetByCodePoints\s*\+3\s*is\s*\:7\s*i\=3\s*offsetByCodePoints\=9\s*r\s*offsetByCodePoints\s*\+3\s*is\s*\:9\s*i\=0\s*offsetByCodePoints\=3\s*offsetByCodePoints\s*\+3\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*\@\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*2\+3\s*out\s*of\s*length\s*\!\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*3\+3\s*out\s*of\s*length\s*\.\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*i\=0\s*offsetByCodePoints\=3\s*a\s*offsetByCodePoints\s*\+3\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*b\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*2\+3\s*out\s*of\s*length\s*c\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*3\+3\s*out\s*of\s*length\s*1\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0007-rt-String-BufferCapacityAndEnsureCapacityTest/StringBufferCapacityAndEnsureCapacityTest.java b/test/testsuite/ouroboros/string_test/RT0007-rt-String-BufferCapacityAndEnsureCapacityTest/StringBufferCapacityAndEnsureCapacityTest.java new file mode 100755 index 0000000000000000000000000000000000000000..e69ec838981daac29c32ec8a8b601cce2da601b4 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0007-rt-String-BufferCapacityAndEnsureCapacityTest/StringBufferCapacityAndEnsureCapacityTest.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferCapacityAndEnsureCapacityTest.java + * -@TestCaseName: Test Method capacity()/ensureCapacity(int minimumCapacity) of StringBuffer. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create StringBuffer instance. + * -#step2: Test method int capacity(), check the result capacity and the length of instance is correctly. + * -#step3: Create str(str.length > 0), Invoke Append(String str), test method capacity(), check the result capacity and + * the length of instance is correctly. + * -#step4: Create minimumCapacity > old capacity(), Test method ensureCapacity(int minimumCapacity), test + * method capacity(), check the result capacity and the length of instance is correctly. + * -#step5: Create newLength > StringBuffer.length, Invoke setLength(int newLength), test method capacity(), check + * the result capacity and the length of instance is correctly. + * -#step6: Invoke trimToSize(), test method capacity(), check the result capacity and the length of instance is + * correctly. + * -#step7: Create minimumCapacity = 0 or minimumCapacity < 0 or 0 < minimumCapacity < old capacity(), Test method + * ensureCapacity(int minimumCapacity), test method capacity(), check the result capacity and the length of + * instance is correctly. + * -#step8: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~7. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferCapacityAndEnsureCapacityTest.java + * -@ExecuteClass: StringBufferCapacityAndEnsureCapacityTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferCapacityAndEnsureCapacityTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferCapacityAndEnsureCapacityTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferCapacityAndEnsureCapacityTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=" + + "!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + test1(strBuffer1_4); + test1(strBuffer1_5); + } + + private static void test1(StringBuffer strBuffer) { + System.out.println("1-capacity: " + strBuffer.capacity()); + System.out.println("1-lent: " + strBuffer.length()); + + strBuffer = strBuffer.append("01234567890123456789"); + System.out.println("2-capacity: " + strBuffer.capacity()); + System.out.println("2-lent: " + strBuffer.length()); + + strBuffer.ensureCapacity(80); + System.out.println("3-capacity: " + strBuffer.capacity()); + System.out.println("3-lent: " + strBuffer.length()); + + strBuffer.setLength(100); + System.out.println("4-capacity: " + strBuffer.capacity()); + System.out.println("4-lent: " + strBuffer.length()); + + strBuffer.trimToSize(); + System.out.println("5-capacity: " + strBuffer.capacity()); + System.out.println("5-lent: " + strBuffer.length()); + + // Test minimumCapacity < 0. + strBuffer.ensureCapacity(-2); + System.out.println("6-capacity: " + strBuffer.capacity()); + System.out.println("6-lent: " + strBuffer.length()); + + // Test minimumCapacity = 0. + strBuffer.ensureCapacity(0); + System.out.println("7-capacity: " + strBuffer.capacity()); + System.out.println("7-lent: " + strBuffer.length()); + + // Test minimumCapacity > 0. + strBuffer.ensureCapacity(2); + System.out.println("8-capacity: " + strBuffer.capacity()); + System.out.println("8-lent: " + strBuffer.length()); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 1\-capacity\:\s*115\s*1\-lent\:\s*99\s*2\-capacity\:\s*232\s*2\-lent\:\s*119\s*3\-capacity\:\s*232\s*3\-lent\:\s*119\s*4\-capacity\:\s*232\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*1\-capacity\:\s*25\s*1\-lent\:\s*9\s*2\-capacity\:\s*52\s*2\-lent\:\s*29\s*3\-capacity\:\s*106\s*3\-lent\:\s*29\s*4\-capacity\:\s*106\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*1\-capacity\:\s*22\s*1\-lent\:\s*6\s*2\-capacity\:\s*46\s*2\-lent\:\s*26\s*3\-capacity\:\s*94\s*3\-lent\:\s*26\s*4\-capacity\:\s*190\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*1\-capacity\:\s*16\s*1\-lent\:\s*0\s*2\-capacity\:\s*34\s*2\-lent\:\s*20\s*3\-capacity\:\s*80\s*3\-lent\:\s*20\s*4\-capacity\:\s*162\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*1\-capacity\:\s*16\s*1\-lent\:\s*0\s*2\-capacity\:\s*34\s*2\-lent\:\s*20\s*3\-capacity\:\s*80\s*3\-lent\:\s*20\s*4\-capacity\:\s*162\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0008-rt-String-BufferCharAtAndSetCharAtExceptionTest/StringBufferCharAtAndSetCharAtExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0008-rt-String-BufferCharAtAndSetCharAtExceptionTest/StringBufferCharAtAndSetCharAtExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..771eec6ae66017e1f71f4316d16fb239cc04413d --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0008-rt-String-BufferCharAtAndSetCharAtExceptionTest/StringBufferCharAtAndSetCharAtExceptionTest.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferCharAtAndSetCharAtExceptionTest.java + * -@TestCaseName: Test Method charAt(int index)/setCharAt(int index, char ch) of StringBuffer and + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * StringIndexOutOfBoundsException occured in charAt/setCharAt. + * -@Brief: + * -#case1 + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: index range from -1 to exceed instance.length. + * -#step3: Test method char charAt(int index) and StringIndexOutOfBoundsException is thrown. + * -#step4: Check the result char is correctly when index is range from 0 to (instance.length -1), + * StringIndexOutOfBoundsException is thrown when index < 0 or index > (instance.length -1). + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/"" to repeat step2~4. + * -#case2 + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: index range from -1 to exceed instance.length. ch is a Letter char. + * -#step3: Test Method void setCharAt(int index, char ch) and StringIndexOutOfBoundsException is thrown. + * -#step4: Check the instance after setCharAt is replaced correctly when index is range from 0 to (instance.length -1), + * or StringIndexOutOfBoundsException is thrown when index < 0 or index > (instance.length -1). + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/"" to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferCharAtAndSetCharAtExceptionTest.java + * -@ExecuteClass: StringBufferCharAtAndSetCharAtExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferCharAtAndSetCharAtExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferCharAtAndSetCharAtExceptionTest_1(); + StringBufferCharAtAndSetCharAtExceptionTest_2(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferCharAtAndSetCharAtExceptionTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=" + + "!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + test1(strBuffer1_4); + } + + public static void StringBufferCharAtAndSetCharAtExceptionTest_2() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + + test2(strBuffer1_1); + test2(strBuffer1_2); + test2(strBuffer1_3); + test2(strBuffer1_4); + } + + // Test method char charAt(int index). + private static void test1(StringBuffer strBuffer) { + int charAt = 0; + for (int i = -1; i < 8; i++) { + try { + charAt = strBuffer.charAt(i); + System.out.println("i=" + i + " " + "charAt=" + charAt); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("index: " + i + " String index out of range"); + } + } + } + + // Test Method void setCharAt(int index, char ch). + private static void test2(StringBuffer strBuffer) { + char ch = 'A'; + for (int i = -1; i < 8; i++) { + try { + strBuffer.setCharAt(i, ch); + System.out.println("i=" + i + " " + "setcharAt=" + strBuffer); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("index: " + i + " String index out of range"); + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*charAt\=113\s*i\=1\s*charAt\=119\s*i\=2\s*charAt\=101\s*i\=3\s*charAt\=114\s*i\=4\s*charAt\=116\s*i\=5\s*charAt\=121\s*i\=6\s*charAt\=117\s*i\=7\s*charAt\=105\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*charAt\=32\s*i\=1\s*charAt\=64\s*i\=2\s*charAt\=33\s*i\=3\s*charAt\=46\s*i\=4\s*charAt\=38\s*i\=5\s*charAt\=37\s*i\=6\s*charAt\=40\s*i\=7\s*charAt\=41\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*charAt\=97\s*i\=1\s*charAt\=98\s*i\=2\s*charAt\=99\s*i\=3\s*charAt\=49\s*i\=4\s*charAt\=50\s*i\=5\s*charAt\=51\s*index\:\s*6\s*String\s*index\s*out\s*of\s*range\s*index\:\s*7\s*String\s*index\s*out\s*of\s*range\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*index\:\s*0\s*String\s*index\s*out\s*of\s*range\s*index\:\s*1\s*String\s*index\s*out\s*of\s*range\s*index\:\s*2\s*String\s*index\s*out\s*of\s*range\s*index\:\s*3\s*String\s*index\s*out\s*of\s*range\s*index\:\s*4\s*String\s*index\s*out\s*of\s*range\s*index\:\s*5\s*String\s*index\s*out\s*of\s*range\s*index\:\s*6\s*String\s*index\s*out\s*of\s*range\s*index\:\s*7\s*String\s*index\s*out\s*of\s*range\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*setcharAt\=Awertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=1\s*setcharAt\=AAertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=2\s*setcharAt\=AAArtyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=3\s*setcharAt\=AAAAtyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=4\s*setcharAt\=AAAAAyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=5\s*setcharAt\=AAAAAAuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=6\s*setcharAt\=AAAAAAAiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=7\s*setcharAt\=AAAAAAAAop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*setcharAt\=A\@\!\.\&\%\(\)\*\s*i\=1\s*setcharAt\=AA\!\.\&\%\(\)\*\s*i\=2\s*setcharAt\=AAA\.\&\%\(\)\*\s*i\=3\s*setcharAt\=AAAA\&\%\(\)\*\s*i\=4\s*setcharAt\=AAAAA\%\(\)\*\s*i\=5\s*setcharAt\=AAAAAA\(\)\*\s*i\=6\s*setcharAt\=AAAAAAA\)\*\s*i\=7\s*setcharAt\=AAAAAAAA\*\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*setcharAt\=Abc123\s*i\=1\s*setcharAt\=AAc123\s*i\=2\s*setcharAt\=AAA123\s*i\=3\s*setcharAt\=AAAA23\s*i\=4\s*setcharAt\=AAAAA3\s*i\=5\s*setcharAt\=AAAAAA\s*index\:\s*6\s*String\s*index\s*out\s*of\s*range\s*index\:\s*7\s*String\s*index\s*out\s*of\s*range\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*index\:\s*0\s*String\s*index\s*out\s*of\s*range\s*index\:\s*1\s*String\s*index\s*out\s*of\s*range\s*index\:\s*2\s*String\s*index\s*out\s*of\s*range\s*index\:\s*3\s*String\s*index\s*out\s*of\s*range\s*index\:\s*4\s*String\s*index\s*out\s*of\s*range\s*index\:\s*5\s*String\s*index\s*out\s*of\s*range\s*index\:\s*6\s*String\s*index\s*out\s*of\s*range\s*index\:\s*7\s*String\s*index\s*out\s*of\s*range\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0009-rt-String-BufferGetCharsTest/StringBufferGetCharsTest.java b/test/testsuite/ouroboros/string_test/RT0009-rt-String-BufferGetCharsTest/StringBufferGetCharsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..44fba0ac30effabd2b8394d5bfa495816a84a617 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0009-rt-String-BufferGetCharsTest/StringBufferGetCharsTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferGetCharsTest.java + * -@TestCaseName: Test Method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) of StringBuffer. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create StringBuffer instance. + * -#step2: Create parameters: srcBegin =< srcEnd < instance.length,, dstBegin < dst(char[]).length, srcBegin/srcEnd + * /dstBegin coverage boundary value. + * -#step3: Test Method void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin). + * -#step4: Check some chars of dst(char[]) is replaced correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferGetCharsTest.java + * -@ExecuteClass: StringBufferGetCharsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferGetCharsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferGetCharsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferGetCharsTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123"); + + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + } + + private static void test1(StringBuffer strBuffer) { + // Test srcBegin < srcEnd < instance.length, dstBegin < dst(char[]).length. + char[] dst = {'A', 'B', 'C', 'D', 'E', 'F'}; + strBuffer.getChars(2, 5, dst, 2); + System.out.println(dst); + + // Test srcBegin = 0. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuffer.getChars(0, 3, dst, 2); + System.out.println(dst); + + // Test srcEnd = 0. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuffer.getChars(0, 0, dst, 2); + System.out.println(dst); + + // Test dstBegin = 0. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuffer.getChars(2, 5, dst, 0); + System.out.println(dst); + + // Test srcBegin = srcEnd. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuffer.getChars(2, 2, dst, 0); + System.out.println(dst); + + // Test srcBegin = strBuffer.length() - 1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + int index = strBuffer.length() - 1; + strBuffer.getChars(index, index, dst, 0); + System.out.println(dst); + + // Test srcEnd = strBuffer.length() - 1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuffer.getChars(index - 2, index, dst, 0); + System.out.println(dst); + + // Test dstBegin = dst.length - 1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuffer.getChars(0, 1, dst, dst.length - 1); + System.out.println(dst); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ABertF\s*ABqweF\s*ABCDEF\s*ertDEF\s*ABCDEF\s*ABCDEF\s*x9CDEF\s*ABCDEq\s*AB\!\.\&F\s*AB\s*\@\!F\s*ABCDEF\s*\!\.\&DEF\s*ABCDEF\s*ABCDEF\s*\(\)CDEF\s*ABCDE\s*ABc12F\s*ABabcF\s*ABCDEF\s*c12DEF\s*ABCDEF\s*ABCDEF\s*12CDEF\s*ABCDEa\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0010-rt-String-BufferIndexOfAndLastIndexOfTest/StringBufferIndexOfAndLastIndexOfTest.java b/test/testsuite/ouroboros/string_test/RT0010-rt-String-BufferIndexOfAndLastIndexOfTest/StringBufferIndexOfAndLastIndexOfTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8749768df6f1bdc7b0be6a9717b0d38bb49837b1 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0010-rt-String-BufferIndexOfAndLastIndexOfTest/StringBufferIndexOfAndLastIndexOfTest.java @@ -0,0 +1,171 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferIndexOfAndLastIndexOfTest.java + * -@TestCaseName: Test Method int indexOf(String str)/int indexOf(String str, int fromIndex)/int lastIndexOf( + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * String str)/int lastIndexOf(String str, int fromIndex) of StringBuffer. + * -@Brief: + * -#case1 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters: str is String with letter or empty String. + * -#step3: Test method indexOf(String str), check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~3. + * -#case2 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters: str is String with letter, instance.length > fromIndex >= 0, fromIndex coverage boundary + * value. + * -#step3: Test method indexOf(String str, int fromIndex), check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~3. + * -#case3 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters: str is String with letter or empty String. + * -#step3: Test method lastIndexOf(String str), check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~3. + * -#case4 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters: str is String with letter, instance.length > fromIndex >= 0, fromIndex coverage boundary + * value. + * -#step3: Test method lastIndexOf(String str, int fromIndex), check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferIndexOfAndLastIndexOfTest.java + * -@ExecuteClass: StringBufferIndexOfAndLastIndexOfTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferIndexOfAndLastIndexOfTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferIndexOfAndLastIndexOfTest_1(); + StringBufferIndexOfAndLastIndexOfTest_2(); + StringBufferIndexOfAndLastIndexOfTest_3(); + StringBufferIndexOfAndLastIndexOfTest_4(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferIndexOfAndLastIndexOfTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + test1(strBuffer1_4); + test1(strBuffer1_5); + } + + public static void StringBufferIndexOfAndLastIndexOfTest_2() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + test2(strBuffer1_1); + test2(strBuffer1_2); + test2(strBuffer1_3); + test2(strBuffer1_4); + test2(strBuffer1_5); + } + + public static void StringBufferIndexOfAndLastIndexOfTest_3() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + + test3(strBuffer1_1); + test3(strBuffer1_2); + test3(strBuffer1_3); + test3(strBuffer1_4); + test3(strBuffer1_5); + } + + + public static void StringBufferIndexOfAndLastIndexOfTest_4() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + + test4(strBuffer1_1); + test4(strBuffer1_2); + test4(strBuffer1_3); + test4(strBuffer1_4); + test4(strBuffer1_5); + } + + // Test method indexOf(String str). + private static void test1(StringBuffer strBuffer) { + System.out.println(strBuffer.indexOf("b")); + // Test empty String. + System.out.println(strBuffer.indexOf("")); + } + + // Test method indexOf(String str, int fromIndex). + private static void test2(StringBuffer strBuffer) { + System.out.println(strBuffer.indexOf("b", 2)); + // Test fromIndex = 0. + System.out.println(strBuffer.indexOf("b", 0)); + // Test fromIndex = strBuffer.length() - 1. + System.out.println(strBuffer.indexOf("6", strBuffer.length() - 1)); + } + + // Test method lastIndexOf(String str). + private static void test3(StringBuffer strBuffer) { + System.out.println(strBuffer.lastIndexOf("b")); + // Test empty String. + System.out.println(strBuffer.lastIndexOf("")); + } + + // Test method lastIndexOf(String str, int fromIndex). + private static void test4(StringBuffer strBuffer) { + System.out.println(strBuffer.lastIndexOf("b", 1)); + // Test fromIndex = 0. + System.out.println(strBuffer.lastIndexOf("b", 0)); + // Test fromIndex = strBuffer.length() - 1. + System.out.println(strBuffer.lastIndexOf("6", strBuffer.length() - 1)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 33\s*0\s*\-1\s*0\s*1\s*0\s*\-1\s*0\s*\-1\s*0\s*33\s*33\s*98\s*\-1\s*\-1\s*\-1\s*7\s*1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*33\s*99\s*\-1\s*9\s*7\s*9\s*\-1\s*0\s*\-1\s*0\s*\-1\s*\-1\s*98\s*\-1\s*\-1\s*\-1\s*1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0011-rt-String-BufferReplaceAndReverseTest/StringBufferReplaceAndReverseTest.java b/test/testsuite/ouroboros/string_test/RT0011-rt-String-BufferReplaceAndReverseTest/StringBufferReplaceAndReverseTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3d894bf319d91d9269dd34571cd2d6fa504e03e8 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0011-rt-String-BufferReplaceAndReverseTest/StringBufferReplaceAndReverseTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferReplaceAndReverseTest.java + * -@TestCaseName: Test Method StringBuffer replace(int start, int end, String str)/StringBuffer reverse() of + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * StringBuffer. + * -@Brief: + * -#case1 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters: start < end < instance.length, start/end coverage boundary value. str is String with some + * letters. + * -#step3: Test method replace(int start, int end, String str), check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case2 + * -#step1: Create StringBuffer instance. + * -#step2: Test method reverse(), check return result is correctly. + * -#step3: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferReplaceAndReverseTest.java + * -@ExecuteClass: StringBufferReplaceAndReverseTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferReplaceAndReverseTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferReplaceAndReverseTest_1(); + StringBufferReplaceAndReverseTest_2(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferReplaceAndReverseTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + } + + public static void StringBufferReplaceAndReverseTest_2() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + + test2(strBuffer1_1); + test2(strBuffer1_2); + test2(strBuffer1_3); + test2(strBuffer1_4); + test2(strBuffer1_5); + } + + // Test method replace(int start, int end, String str). + private static void test1(StringBuffer strBuffer) { + System.out.println(strBuffer.replace(2, 6, "xyz")); + // end = 0 + System.out.println(strBuffer.replace(0, 0, "xyz")); + // start = 0 & end = strBuffer.length() + System.out.println(strBuffer.replace(0, strBuffer.length(), "xyz")); + // start = strBuffer.length() & end = strBuffer.length() + System.out.println(strBuffer.replace(strBuffer.length(), strBuffer.length(), "xyz")); + } + + // Test method reverse(). + private static void test2(StringBuffer strBuffer) { + strBuffer.reverse(); + System.out.println(strBuffer); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwxyzuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*xyzqwxyzuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*xyz\s*xyzxyz\s*\@xyz\s*xyz\s*\@xyz\s*xyz\s*xyzxyz\s*abxyzabc\s*xyzabxyzabc\s*xyz\s*xyzxyz\s*69x0MNBVCXZPOIUYTREWQLKJHGFDSA\s*\+_\)\(\*\&\^\%\$\#\@\!\=\-0987654321\`\~\?\/\>\<\.\,mnbvcxz\"\'\:\;lkjhgfdsa\|\\\]\[\}\{poiuytrewq\s*\%\&\.\!\@\s*cba321cba\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0012-rt-String-BufferSubstringAndToStringTest/StringBufferSubstringAndToStringTest.java b/test/testsuite/ouroboros/string_test/RT0012-rt-String-BufferSubstringAndToStringTest/StringBufferSubstringAndToStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5e422fdaf15242ab8d9dba5eb75c9130239ede66 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0012-rt-String-BufferSubstringAndToStringTest/StringBufferSubstringAndToStringTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferSubstringAndToStringTest.java + * -@TestCaseName: Test Method:String substring(int start)/String substring(int start, int end)/String toString() + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * of StringBuffer. + * -@Brief: + * -#case1 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters: start < instance.length, start < end < instance.length, start and end coverage boundary + * value. + * -#step3: Test method substring(int start, int end). + * -#step4: Check the return result of substring is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -#case2 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters: 0 =< start < instance.length, start coverage boundary value. + * -#step3: Test method substring(int start). + * -#step4: Check the return result of substring is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -#case3 + * -#step1: Create StringBuffer instance. + * -#step2: Test method toString(). + * -#step3: Check the return result of toString is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2-3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBufferSubstringAndToStringTest.java + * -@ExecuteClass: StringBufferSubstringAndToStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferSubstringAndToStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBufferSubstringAndToStringTest_1(); + StringBufferSubstringAndToStringTest_2(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBufferSubstringAndToStringTest_1() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%()*"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + + test1(strBuffer1_1); + test1(strBuffer1_2); + test1(strBuffer1_3); + + test2(strBuffer1_1); + test2(strBuffer1_2); + test2(strBuffer1_3); + } + + public static void StringBufferSubstringAndToStringTest_2() { + StringBuffer strBuffer1_1 = new StringBuffer("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuffer strBuffer1_2 = new StringBuffer(" @!.&%"); + StringBuffer strBuffer1_3 = new StringBuffer("abc123abc"); + StringBuffer strBuffer1_4 = new StringBuffer(""); + StringBuffer strBuffer1_5 = new StringBuffer(); + + test3(strBuffer1_1); + test3(strBuffer1_2); + test3(strBuffer1_3); + test3(strBuffer1_4); + test3(strBuffer1_5); + } + + // Test method substring(int start, int end). + private static void test1(StringBuffer strBuffer) { + System.out.println(strBuffer.substring(2, 7)); + // Test start = 0 & end = strBuffer.length(). + System.out.println(strBuffer.substring(0, strBuffer.length())); + // Test start = strBuffer.length(). + System.out.println(strBuffer.substring(strBuffer.length(), strBuffer.length())); + // Test end = 0. + System.out.println(strBuffer.substring(0, 0)); + } + + // Test method substring(int start). + private static void test2(StringBuffer strBuffer) { + System.out.println(strBuffer.substring(3)); + // Test start = 0. + System.out.println(strBuffer.substring(0)); + // Test start = strBuffer.length(). + System.out.println(strBuffer.substring(strBuffer.length())); + } + + // Test method toString(). + private static void test3(StringBuffer strBuffer) { + System.out.println(strBuffer.toString()); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ertyu\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\!\.\&\%\(\s*\@\!\.\&\%\(\)\*\s*c123a\s*abc123abc\s*rtyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\.\&\%\(\)\*\s*\@\!\.\&\%\(\)\*\s*123abc\s*abc123abc\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*abc123abc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0013-rt-String-BuilderConstructorsTest/StringBuilderConstructorsTest.java b/test/testsuite/ouroboros/string_test/RT0013-rt-String-BuilderConstructorsTest/StringBuilderConstructorsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7a018ecc5ee735a4ca135d36657a6ea277453822 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0013-rt-String-BuilderConstructorsTest/StringBuilderConstructorsTest.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderConstructorsTest.java + * -@TestCaseName: Test StringBuilder Constructors StringBuilder()/StringBuilder(CharSequence seq)/StringBuilder + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * (int capacity)/StringBuilder(String str). + * -@Brief: + * -#case1 + * -#step1: Create a String instance By new String(String str) and not new. + * -#step2: Test Constructor StringBuilder(String instance). + * -#step3: Check new StringBuilder instance is new correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~3. + * -#case2 + * -#step1: Test new StringBuilder() and check the capacity() of instance is correctly. + * -#step2: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step1. + * -#case3 + * -#step1: Create capacity > 0 or capacity = 0, test new StringBuilder(int capacity), check the capacity() of instance + * is correctly. + * -#case4 + * -#step1: Create seq Contains numbers, letters, special symbols, test StringBuilder(CharSequence seq), check new + * instance is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderConstructorsTest.java + * -@ExecuteClass: StringBuilderConstructorsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderConstructorsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderConstructorsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderConstructorsTest_1() { + String str1_1 = new String("abc123abc"); + String str1_2 = new String(" @!.&%()*"); + String str1_3 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "abc123ABC"; + String str2_2 = " @!.&%()*"; + String str2_3 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZX" + + "CVBNM0x96"; + String str2_4 = ""; + + test1_1(str1_1); + test1_1(str1_2); + test1_1(str1_3); + test1_1(str1_4); + test1_1(str1_5); + test1_1(str2_1); + test1_1(str2_2); + test1_1(str2_3); + test1_1(str2_4); + + StringBuilder strBuilder1_1 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%"); + StringBuilder strBuilder1_3 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=" + + "!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test1_2(strBuilder1_1); + test1_2(strBuilder1_2); + test1_2(strBuilder1_3); + test1_2(strBuilder1_4); + test1_2(strBuilder1_5); + + // Test new StringBuilder() + test1_3(); + + // Test new StringBuilder(int capacity) + test1_4(); + + // Test new StringBuilder(CharSequence seq) + test1_5(); + } + + private static void test1_1(String str) { + System.out.println(new StringBuilder(str)); + } + + private static void test1_2(StringBuilder strBuilder) { + System.out.println(strBuilder.toString()); + } + + private static void test1_3() { + StringBuilder strBuilder1_6 = new StringBuilder(); + System.out.println(strBuilder1_6.capacity()); + } + + private static void test1_4() { + int capacity = 20; + StringBuilder strBuilder1_6 = new StringBuilder(capacity); + System.out.println(strBuilder1_6.capacity()); + + int capacityMin = 0; + strBuilder1_6 = new StringBuilder(capacityMin); + System.out.println(strBuilder1_6.capacity()); + } + + private static void test1_5() { + CharSequence chs1_1 = "xyz"; + StringBuilder strBuilder1_7 = new StringBuilder(chs1_1); + test1_2(strBuilder1_7); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123abc\s*\@\!\.\&\%\(\)\*\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*abc123ABC\s*\@\!\.\&\%\(\)\*\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*abc123abc\s*\@\!\.\&\%\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*16\s*20\s*0\s*xyz\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0014-rt-String-BuilderAppendAndAppendCodePointTest/StringBuilderAppendAndAppendCodePointTest.java b/test/testsuite/ouroboros/string_test/RT0014-rt-String-BuilderAppendAndAppendCodePointTest/StringBuilderAppendAndAppendCodePointTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7a6ef966fff933cec92bb2abcdc45521504c98d7 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0014-rt-String-BuilderAppendAndAppendCodePointTest/StringBuilderAppendAndAppendCodePointTest.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderAppendAndAppendCodePointTest.java + * -@TestCaseName: Test method append(boolean b)/append(char c)/append(char[] str)/append(char[] str, int offset, + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * int len)/append(CharSequence s)/append(CharSequence s, int start, int end)/append(double d)/ + * append(float f)/append(int i)/append(long lng)/append(Object obj)/append(String str)/ + * append(StringBuilder sb)/appendCodePoint(int codePoint) of StringBuilder + * -@Brief: + * -#step1: Create StringBuilder instance. + * -#step2: Create parameter str is a String instance, test method append(String str). + * -#step3: Create parameter b is true or false, test method append(boolean b). + * -#step4: Create parameter c is a letter, test method append(char c). + * -#step5: Create parameter data.length > 0, data.element is a char, test method append(char[] data). + * -#step6: Create parameter s is a CharSequence, test method append(CharSequence s). + * -#step7: Create parameters: s is a CharSequence, 0 =< start < end, end <= s.length, start and end coverage boundary + * value. test method append(CharSequence s, int start, int end). + * -#step8: Create parameter d > 0 or d = 0, test method append(double d). + * -#step9: Create parameter f > 0 or f = 0, test method append(float f). + * -#step10: Create parameter i > 0 or i = 0, test method append(int i). + * -#step11: Create parameter lng > 0 or lng = 0, test method append(long lng). + * -#step12: Create parameter obj is a Object, test method append(Object obj). + * -#step13: Create parameter sb is a StringBuffer, test method append(StringBuilder sb). + * -#step14: Create parameter codePoint is unicode num, test method appendCodePoint(int codePoint). + * -#step15: Check the append result is correctly and the Src StringBuilder is correctly. + * -#step16: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~15. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderAppendAndAppendCodePointTest.java + * -@ExecuteClass: StringBuilderAppendAndAppendCodePointTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderAppendAndAppendCodePointTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderAppendAndAppendCodePointTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderAppendAndAppendCodePointTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_2 = new StringBuilder(" "); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + test1(strBuilder1_4); + test1(strBuilder1_5); + } + + private static void test1(StringBuilder strBuilder) { + char c = 'C'; + char[] data = {'A', 'B', 'C'}; + CharSequence chs1_1 = "xyz"; + Object obj = new String("object"); + String str = "string"; + double d = 8888.8888; + double dMin = 0; + float f = 99999999; + float fMin = 0; + int i = 77777777; + int iMin = 0; + long lng = 66666666; + long lngMin = 0; + StringBuilder sb = new StringBuilder("StringBuilder"); + int codePoint = 74; // unicode 74 is J + + System.out.println(strBuilder.append("-").append(true).append("-").append(false).append("-").append(c) + .append("-").append(data).append("-").append(chs1_1).append("-").append(chs1_1, 1, 2).append("-") + .append(chs1_1, 0, 3).append("-").append(chs1_1, 3, 3).append("-").append(chs1_1, 0, 0).append("-") + .append(d).append("-").append(dMin).append("-").append(f).append("-").append(fMin).append("-").append(i) + .append("-").append(iMin).append("-").append(lng).append("-").append(lngMin).append("-").append(obj) + .append("-").append(str).append("-").append(sb).append("-").appendCodePoint(codePoint)); + + System.out.println(strBuilder.subSequence(2, 8)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123abc\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-StringBuilder\-J\s*c123ab\s*\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-StringBuilder\-J\s*\-t\s*abc123abc\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-StringBuilder\-J\s*c123ab\s*\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-StringBuilder\-J\s*rue\-fa\s*\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-0\.0\-1\.0E8\-0\.0\-77777777\-0\-66666666\-0\-object\-string\-StringBuilder\-J\s*rue\-fa\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0015-rt-String-BuilderInsertTest/StringBuilderInsertTest.java b/test/testsuite/ouroboros/string_test/RT0015-rt-String-BuilderInsertTest/StringBuilderInsertTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9897905f6a38883e1af7446d0aba657453dd3175 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0015-rt-String-BuilderInsertTest/StringBuilderInsertTest.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderInsertTest.java + * -@TestCaseName: Test Method insert(Various parameters) of StringBuilder include insert(int offset, boolean b)/ + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * insert(int offset, char c)/insert(int offset, char[] str)/insert(int index, char[] str, + * int offset, int len)insert(int dstOffset, CharSequence s)/insert(int dstOffset, CharSequence s, + * int start, int end)/insert(int offset, double d)/insert(int offset, float f)/insert(int offset, + * int i)/insert(int offset, long l)/insert(int offset,Object obj)/insert(int offset, String str). + * -@Brief: + * -#step1: Create StringBuilder instance. + * -#step2: Create parameters: 0 =< offset < instance.length, offset test boundary value, str is a String, test method + * insert(int offset, String str). + * -#step3: Create parameters: 0 =< offset < instance.length, offset test boundary value, b is true/false, test method + * insert(int offset, boolean b). + * -#step4: Create parameters: 0 =< offset < instance.length, offset test boundary value, c is a char, test method + * insert(int offset, char c). + * -#step5: Create parameters: 0 =< offset < instance.length, offset test boundary value, create a char[] data, test + * method insert(int offset, char[] data). + * -#step6: Create parameters: 0 =< offset < instance.length, offset test boundary value, s is a CharSequence, test + * method insert(int offset, CharSequence s). + * -#step7: Create parameters: 0 =< offset < instance.length, s is a CharSequence, 0 =< start < end, end <= s.length, + * offset/start/end test boundary value, test method insert(int offset, CharSequence s, int start, int end). + * -#step8: Create parameters: 0 =< offset < instance.length, offset test boundary value, d > 0 or d = 0, test method + * insert(int offset, double d). + * -#step9: Create parameters: 0 =< offset < instance.length, offset test boundary value, f > 0 or f = 0, test method + * insert(int offset, float f). + * -#step10: Create parameters: 0 =< offset < instance.length, offset test boundary value, i > 0 or i = 0, test method + * insert(int offset, int i). + * -#step11: Create parameters: 0 =< offset < instance.length, offset test boundary value, l > 0 or l = 0, test method + * insert(int offset, long l). + * -#step12: Create parameters: 0 =< offset < instance.length, offset test boundary value, obj is a Object, test method + * insert(int offset, Object obj). + * -#step13: Check the insert result is correctly and the Src instance is correctly. + * -#step14: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~13. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderInsertTest.java + * -@ExecuteClass: StringBuilderInsertTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderInsertTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderInsertTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderInsertTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + test1(strBuilder1_4); + test1(strBuilder1_5); + } + + private static void test1(StringBuilder strBuilder) { + char c = 'C'; + char[] data = {'A', 'B', 'C'}; + CharSequence chs1_1 = "xyz"; + double d = 8888.8888; + double dMin = 0; + float f = 99999999; + float fMin = 0; + int i = 77777777; + int iMin = 0; + long lng = 66666666; + long lngMin = 0; + Object obj = new String("object"); + String str = "-"; + + System.out.println(strBuilder.insert(0, str).insert(1, true).insert(strBuilder.length(), str) + .insert(strBuilder.length(), true).insert(0, str).insert(0, false).insert(strBuilder.length(), str) + .insert(strBuilder.length(), false).insert(0, str).insert(0, c).insert(strBuilder.length(), str) + .insert(strBuilder.length(), c).insert(0, str).insert(0, data).insert(strBuilder.length(), str) + .insert(strBuilder.length(), data).insert(0, str).insert(0, chs1_1).insert(strBuilder.length(), str) + .insert(strBuilder.length(), chs1_1).insert(0, str).insert(0, chs1_1, 1, 2) + .insert(strBuilder.length(), str).insert(strBuilder.length(), chs1_1, 1, 2).insert(0, str) + .insert(0, chs1_1, 0, 3).insert(strBuilder.length(), str).insert(strBuilder.length(), chs1_1, 0, 3) + .insert(0, str).insert(0, chs1_1, 3, 3).insert(strBuilder.length(), str) + .insert(strBuilder.length(), chs1_1, 3, 3).insert(0, str).insert(0, chs1_1, 0, 0) + .insert(strBuilder.length(), str).insert(strBuilder.length(), chs1_1, 0, 0).insert(0, str).insert(0, d) + .insert(strBuilder.length(), str).insert(strBuilder.length(), d).insert(0, str).insert(0, dMin) + .insert(0, str).insert(0, f).insert(strBuilder.length(), str).insert(strBuilder.length(), f) + .insert(0, str).insert(0, fMin).insert(0, str).insert(0, i).insert(strBuilder.length(), str) + .insert(strBuilder.length(), i).insert(0, str).insert(0, iMin).insert(0, str).insert(0, lng) + .insert(strBuilder.length(), str).insert(strBuilder.length(), lng).insert(0, str).insert(0, lngMin) + .insert(0, str).insert(0, obj).insert(strBuilder.length(), str).insert(strBuilder.length(), obj)); + System.out.println(strBuilder.subSequence(2, 8)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-\-trueqwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-\-true\s*\@\!\.\&\%\(\)\*\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-\-trueabc123abc\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-\-true\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*object\-0\-66666666\-0\-77777777\-0\.0\-1\.0E8\-0\.0\-8888\.8888\-\-\-xyz\-y\-xyz\-ABC\-C\-false\-\-true\-true\-false\-C\-ABC\-xyz\-y\-xyz\-\-\-8888\.8888\-1\.0E8\-77777777\-66666666\-object\s*ject\-0\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0016-rt-String-BuilderDeleteAndDeleteCharAtTest/StringBuilderDeleteAndDeleteCharAtTest.java b/test/testsuite/ouroboros/string_test/RT0016-rt-String-BuilderDeleteAndDeleteCharAtTest/StringBuilderDeleteAndDeleteCharAtTest.java new file mode 100755 index 0000000000000000000000000000000000000000..87c6c696d822900778ae775e83ac182843325d65 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0016-rt-String-BuilderDeleteAndDeleteCharAtTest/StringBuilderDeleteAndDeleteCharAtTest.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderDeleteAndDeleteCharAtTest.java + * -@TestCaseName: Test Method delete(int start, int end) and deleteCharAt(int index) of StringBuilder. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#case1 + * -#step1: Create StringBuilder instance. + * -#step2: Create parameters: 0 =< start =< end, end =< instance.length, start and end coverage boundary value. + * -#step3: Test Method delete(int start, int end) and check result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case2 + * -#step1: Create StringBuilder instance. + * -#step2: Create parameters: 0 =< index < instance.length, index coverage boundary value. + * -#step3: Test Method deleteCharAt(int index) and check result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderDeleteAndDeleteCharAtTest.java + * -@ExecuteClass: StringBuilderDeleteAndDeleteCharAtTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderDeleteAndDeleteCharAtTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderDeleteAndDeleteCharAtTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderDeleteAndDeleteCharAtTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + + StringBuilder strBuilder2_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder2_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder2_3 = new StringBuilder("abc123abc"); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + + test2(strBuilder2_1); + test2(strBuilder2_2); + test2(strBuilder2_3); + } + + // Test method delete(int start, int end). + private static void test1(StringBuilder strBuilder) { + // Test 0 < start < end, end < strBuffer.length(). + System.out.println(strBuilder.delete(3, 5)); + // Test start = 0. + System.out.println(strBuilder.delete(0, 1)); + // Test end = 0. + System.out.println(strBuilder.delete(0, 0)); + // Test start=strBuffer.length(). + System.out.println(strBuilder.delete(strBuilder.length(), strBuilder.length())); + // Test end=strBuffer.length(). + System.out.println(strBuilder.delete(2, strBuilder.length())); + } + + // Test method deleteCharAt(int index). + private static void test2(StringBuilder strBuilder) { + // Test 0 < index < strBuffer.length(). + System.out.println(strBuilder.deleteCharAt(1)); + // Test index = 0. + System.out.println(strBuilder.deleteCharAt(0)); + // Test index = strBuffer.length()-1. + System.out.println(strBuilder.deleteCharAt(strBuilder.length() - 1)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qweyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*weyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*weyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*weyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*we\s*\@\!\%\(\)\*\s*\@\!\%\(\)\*\s*\@\!\%\(\)\*\s*\@\!\%\(\)\*\s*\@\!\s*abc3abc\s*bc3abc\s*bc3abc\s*bc3abc\s*bc\s*qertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x9\s*\!\.\&\%\(\)\*\s*\!\.\&\%\(\)\*\s*\!\.\&\%\(\)\s*ac123abc\s*c123abc\s*c123ab\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0017-rt-String-BuilderCodePointExceptionTest/StringBuilderCodePointExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0017-rt-String-BuilderCodePointExceptionTest/StringBuilderCodePointExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a984a843fa57b2d134b83277cedb16f95136bc71 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0017-rt-String-BuilderCodePointExceptionTest/StringBuilderCodePointExceptionTest.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderCodePointExceptionTest.java + * -@TestCaseName: Test method codePointAt(int index)/codePointBefore(int index)/codePointCount(int beginIndex, int + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * endIndex)/offsetByCodePoints(int index, int codePointOffset) of StringBuilder, test + * StringIndexOutOfBoundsException throw in codePointAt and codePointBefore, test + * IndexOutOfBoundsException throw in codePointCount and offsetByCodePoints. + * -@Brief: + * -#case1 + * -#step1: Create StringBuilder instance. + * -#step2: Create parameters: index range from 0 to instance.length. + * -#step3: Test method codePointAt(int index). Check result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case2 + * -#step1: Create StringBuilder instance. + * -#step2: Create parameters: index range from 0 to instance.length. + * -#step3: Test method codePointBefore(int index). Check result is correctly, StringIndexOutOfBoundsException is thrown + * when index = 0. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case3 + * -#step1: Create StringBuilder instance. + * -#step2: Create parameters: beginIndex range from 0 to instance.length - 2, endIndex = beginIndex + 3. + * -#step3: Test method codePointCount(int beginIndex, int endIndex),Check result is correctly.IndexOutOfBoundsException + * is thrown when endIndex > instance.length - 1. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case4 + * -#step1: Create StringBuilder instance. + * -#step2: Create parameters: index range from 0 to instance.length - 2, codePointOffset = index + 3. + * -#step3: Test method int offsetByCodePoints(int index, int codePointOffset),Check result is correctly, + * StringIndexOutOfBoundsException is thrown when index + codePointOffset > instance.length. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderCodePointExceptionTest.java + * -@ExecuteClass: StringBuilderCodePointExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderCodePointExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderCodePointExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderCodePointExceptionTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`123456789" + + "0-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123"); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + + test2(strBuilder1_1); + test2(strBuilder1_2); + test2(strBuilder1_3); + + test3(strBuilder1_1); + test3(strBuilder1_2); + test3(strBuilder1_3); + + test4(strBuilder1_1); + test4(strBuilder1_2); + test4(strBuilder1_3); + } + + // Test method codePointAt(int index). + private static void test1(StringBuilder strBuilder) { + int codePoint = 0; + for (int i = 0; i < 6; i++) { + try { + codePoint = strBuilder.codePointAt(i); + System.out.println("i=" + i + " " + "codePointAt=" + codePoint); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("codePointAt(): " + i + "out of length"); + } finally { + try { + System.out.println(strBuilder.charAt(i) + " Unicode is" + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println(i + " out of length"); + } + } + } + } + + // Test method codePointBefore(int index). + private static void test2(StringBuilder strBuilder) { + int codePoint = 0; + for (int i = 0; i < 6; i++) { + try { + codePoint = strBuilder.codePointBefore(i); + System.out.println("i=" + i + " " + "codePointBefore=" + codePoint); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("codePointBefore(): " + i + "out of length"); + } finally { + try { + System.out.println(strBuilder.charAt(i - 1) + " Unicode is" + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println(i + " out of length"); + } + } + } + } + + // Test method codePointCount(int beginIndex, int endIndex). + private static void test3(StringBuilder strBuilder) { + int codePoint = 0; + for (int i = 0; i < 4; i++) { + try { + codePoint = strBuilder.codePointCount(i, i + 3); + System.out.println("i=" + i + " " + "codePointCount=" + codePoint); + } catch (IndexOutOfBoundsException e1) { + System.out.println("codePointCount(): " + i + " out of length"); + } finally { + try { + System.out.println(strBuilder.charAt(i) + "~" + strBuilder.charAt(i + 3) + + " codePointCount is " + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println(i + " out of length"); + } + } + } + } + + // Test method int offsetByCodePoints(int index, int codePointOffset). + private static void test4(StringBuilder strBuilder) { + int codePoint = 0; + for (int i = 0; i < 4; i++) { + try { + codePoint = strBuilder.offsetByCodePoints(i, i + 3); + System.out.println("i=" + i + " " + "offsetByCodePoints=" + codePoint); + } catch (IndexOutOfBoundsException e1) { + System.out.println("offsetByCodePoints(): " + i + "+3 out of length"); + } finally { + try { + System.out.println(strBuilder.charAt(i) + " offsetByCodePoints +3 is " + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " out of length"); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan i\=0\s*codePointAt\=113\s*q\s*Unicode\s*is\:113\s*i\=1\s*codePointAt\=119\s*w\s*Unicode\s*is\:119\s*i\=2\s*codePointAt\=101\s*e\s*Unicode\s*is\:101\s*i\=3\s*codePointAt\=114\s*r\s*Unicode\s*is\:114\s*i\=4\s*codePointAt\=116\s*t\s*Unicode\s*is\:116\s*i\=5\s*codePointAt\=121\s*y\s*Unicode\s*is\:121\s*i\=0\s*codePointAt\=32\s*Unicode\s*is\:32\s*i\=1\s*codePointAt\=64\s*\@\s*Unicode\s*is\:64\s*i\=2\s*codePointAt\=33\s*\!\s*Unicode\s*is\:33\s*i\=3\s*codePointAt\=46\s*\.\s*Unicode\s*is\:46\s*i\=4\s*codePointAt\=38\s*\&\s*Unicode\s*is\:38\s*i\=5\s*codePointAt\=37\s*\%\s*Unicode\s*is\:37\s*i\=0\s*codePointAt\=97\s*a\s*Unicode\s*is\:97\s*i\=1\s*codePointAt\=98\s*b\s*Unicode\s*is\:98\s*i\=2\s*codePointAt\=99\s*c\s*Unicode\s*is\:99\s*i\=3\s*codePointAt\=49\s*1\s*Unicode\s*is\:49\s*i\=4\s*codePointAt\=50\s*2\s*Unicode\s*is\:50\s*i\=5\s*codePointAt\=51\s*3\s*Unicode\s*is\:51\s*codePointBefore\(\)\:\s*0out\s*of\s*length\s*0\s*out\s*of\s*length\s*i\=1\s*codePointBefore\=113\s*q\s*Unicode\s*is\:113\s*i\=2\s*codePointBefore\=119\s*w\s*Unicode\s*is\:119\s*i\=3\s*codePointBefore\=101\s*e\s*Unicode\s*is\:101\s*i\=4\s*codePointBefore\=114\s*r\s*Unicode\s*is\:114\s*i\=5\s*codePointBefore\=116\s*t\s*Unicode\s*is\:116\s*codePointBefore\(\)\:\s*0out\s*of\s*length\s*0\s*out\s*of\s*length\s*i\=1\s*codePointBefore\=32\s*Unicode\s*is\:32\s*i\=2\s*codePointBefore\=64\s*\@\s*Unicode\s*is\:64\s*i\=3\s*codePointBefore\=33\s*\!\s*Unicode\s*is\:33\s*i\=4\s*codePointBefore\=46\s*\.\s*Unicode\s*is\:46\s*i\=5\s*codePointBefore\=38\s*\&\s*Unicode\s*is\:38\s*codePointBefore\(\)\:\s*0out\s*of\s*length\s*0\s*out\s*of\s*length\s*i\=1\s*codePointBefore\=97\s*a\s*Unicode\s*is\:97\s*i\=2\s*codePointBefore\=98\s*b\s*Unicode\s*is\:98\s*i\=3\s*codePointBefore\=99\s*c\s*Unicode\s*is\:99\s*i\=4\s*codePointBefore\=49\s*1\s*Unicode\s*is\:49\s*i\=5\s*codePointBefore\=50\s*2\s*Unicode\s*is\:50\s*i\=0\s*codePointCount\=3\s*q\~r\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*w\~t\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*e\~y\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*r\~u\s*codePointCount\s*is\s*\:3\s*i\=0\s*codePointCount\=3\s*\~\.\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*\@\~\&\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*\!\~\%\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*3\s*out\s*of\s*length\s*i\=0\s*codePointCount\=3\s*a\~1\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*b\~2\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*c\~3\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*3\s*out\s*of\s*length\s*i\=0\s*offsetByCodePoints\=3\s*q\s*offsetByCodePoints\s*\+3\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*w\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*i\=2\s*offsetByCodePoints\=7\s*e\s*offsetByCodePoints\s*\+3\s*is\s*\:7\s*i\=3\s*offsetByCodePoints\=9\s*r\s*offsetByCodePoints\s*\+3\s*is\s*\:9\s*i\=0\s*offsetByCodePoints\=3\s*offsetByCodePoints\s*\+3\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*\@\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*2\+3\s*out\s*of\s*length\s*\!\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*3\+3\s*out\s*of\s*length\s*\.\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*i\=0\s*offsetByCodePoints\=3\s*a\s*offsetByCodePoints\s*\+3\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*b\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*2\+3\s*out\s*of\s*length\s*c\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*3\+3\s*out\s*of\s*length\s*1\s*offsetByCodePoints\s*\+3\s*is\s*\:5\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0018-rt-String-BuilderCapacityAndEnsureCapacityTest/StringBuilderCapacityAndEnsureCapacityTest.java b/test/testsuite/ouroboros/string_test/RT0018-rt-String-BuilderCapacityAndEnsureCapacityTest/StringBuilderCapacityAndEnsureCapacityTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0e61c205742d957c833fbbbadb64830db03fe394 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0018-rt-String-BuilderCapacityAndEnsureCapacityTest/StringBuilderCapacityAndEnsureCapacityTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderCapacityAndEnsureCapacityTest.java + * -@TestCaseName: Test Method capacity()/ensureCapacity(int minimumCapacity) of StringBuilder. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create StringBuilder instance. + * -#step2: Test method int capacity(),check the result capacity and the length of instance is correctly. + * -#step3: Create str(str.length > 0), Invoke Append(String str),test method capacity(), check the result + * capacity and the length of instance is correctly. + * -#step4: Create minimumCapacity > old capacity(), Test method ensureCapacity(int minimumCapacity), test + * method capacity(), check the result capacity and the length of instance is correctly. + * -#step5: Create newLength > StringBuffer.length, Invoke setLength(int newLength), test method capacity(), check + * the result capacity and the length of instance is correctly. + * -#step6: Invoke trimToSize(), test method capacity(), check the result capacity and the length of instance is + * correctly. + * -#step7: Create minimumCapacity = 0 or minimumCapacity < 0 or 0 < minimumCapacity < old capacity(), Test method + * ensureCapacity(int minimumCapacity), test method capacity(), check the result capacity and the length of + * instance is correctly. + * -#step8: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~7. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderCapacityAndEnsureCapacityTest.java + * -@ExecuteClass: StringBuilderCapacityAndEnsureCapacityTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderCapacityAndEnsureCapacityTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderCapacityAndEnsureCapacityTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderCapacityAndEnsureCapacityTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + test1(strBuilder1_4); + test1(strBuilder1_5); + } + + private static void test1(StringBuilder strBuilder) { + System.out.println("1-capacity: " + strBuilder.capacity()); + System.out.println("1-lent: " + strBuilder.length()); + + strBuilder = strBuilder.append("01234567890123456789"); + System.out.println("2-capacity: " + strBuilder.capacity()); + System.out.println("2-lent: " + strBuilder.length()); + + strBuilder.ensureCapacity(80); + System.out.println("3-capacity: " + strBuilder.capacity()); + System.out.println("3-lent: " + strBuilder.length()); + + strBuilder.setLength(100); + System.out.println("4-capacity: " + strBuilder.capacity()); + System.out.println("4-lent: " + strBuilder.length()); + + strBuilder.trimToSize(); + System.out.println("5-capacity: " + strBuilder.capacity()); + System.out.println("5-lent: " + strBuilder.length()); + + strBuilder.ensureCapacity(-2); + System.out.println("6-capacity: " + strBuilder.capacity()); + System.out.println("6-lent: " + strBuilder.length()); + + strBuilder.ensureCapacity(0); + System.out.println("7-capacity: " + strBuilder.capacity()); + System.out.println("7-lent: " + strBuilder.length()); + + strBuilder.ensureCapacity(2); + System.out.println("8-capacity: " + strBuilder.capacity()); + System.out.println("8-lent: " + strBuilder.length()); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 1\-capacity\:\s*115\s*1\-lent\:\s*99\s*2\-capacity\:\s*232\s*2\-lent\:\s*119\s*3\-capacity\:\s*232\s*3\-lent\:\s*119\s*4\-capacity\:\s*232\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*1\-capacity\:\s*25\s*1\-lent\:\s*9\s*2\-capacity\:\s*52\s*2\-lent\:\s*29\s*3\-capacity\:\s*106\s*3\-lent\:\s*29\s*4\-capacity\:\s*106\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*1\-capacity\:\s*22\s*1\-lent\:\s*6\s*2\-capacity\:\s*46\s*2\-lent\:\s*26\s*3\-capacity\:\s*94\s*3\-lent\:\s*26\s*4\-capacity\:\s*190\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*1\-capacity\:\s*16\s*1\-lent\:\s*0\s*2\-capacity\:\s*34\s*2\-lent\:\s*20\s*3\-capacity\:\s*80\s*3\-lent\:\s*20\s*4\-capacity\:\s*162\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*1\-capacity\:\s*16\s*1\-lent\:\s*0\s*2\-capacity\:\s*34\s*2\-lent\:\s*20\s*3\-capacity\:\s*80\s*3\-lent\:\s*20\s*4\-capacity\:\s*162\s*4\-lent\:\s*100\s*5\-capacity\:\s*100\s*5\-lent\:\s*100\s*6\-capacity\:\s*100\s*6\-lent\:\s*100\s*7\-capacity\:\s*100\s*7\-lent\:\s*100\s*8\-capacity\:\s*100\s*8\-lent\:\s*100\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0019-rt-String-BuilderCharAtAndSetCharAtExceptionTest/StringBuilderCharAtAndSetCharAtExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0019-rt-String-BuilderCharAtAndSetCharAtExceptionTest/StringBuilderCharAtAndSetCharAtExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fb1e710399760827fce2396f11cd625f7361e58b --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0019-rt-String-BuilderCharAtAndSetCharAtExceptionTest/StringBuilderCharAtAndSetCharAtExceptionTest.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderCharAtAndSetCharAtExceptionTest.java + * -@TestCaseName: Test Method charAt(int index)/setCharAt(int index, char ch) of StringBuilder and + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * StringIndexOutOfBoundsException occured in charAt/setCharAt. + * -@Brief: + * -#case1 + * -#step1: Create StringBuilder instance. + * -#step2: Create parameters: index range from -1 to exceed instance.length. + * -#step3: Test method char charAt(int index) and StringIndexOutOfBoundsException is thrown. + * -#step4: Check the result char is correctly when index is range from 0 to (instance.length -1), + * StringIndexOutOfBoundsException is thrown when index < 0 or index > (instance.length -1). + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/"" to repeat step2~4. + * -#case2 + * -#step1: Create StringBuilder instance. + * -#step2: Create parameters: index range from -1 to exceed instance.length. ch is a Letter char. + * -#step3: Test Method void setCharAt(int index, char ch) and StringIndexOutOfBoundsException is thrown. + * -#step4: Check the instance after setCharAt is replaced correctly when index is range from 0 to (instance.length -1), + * or StringIndexOutOfBoundsException is thrown when index < 0 or index > (instance.length -1). + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/"" to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderCharAtAndSetCharAtExceptionTest.java + * -@ExecuteClass: StringBuilderCharAtAndSetCharAtExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderCharAtAndSetCharAtExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderCharAtAndSetCharAtExceptionTest_1(); + StringBuilderCharAtAndSetCharAtExceptionTest_2(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderCharAtAndSetCharAtExceptionTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + test1(strBuilder1_4); + } + + public static void StringBuilderCharAtAndSetCharAtExceptionTest_2() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + + test2(strBuilder1_1); + test2(strBuilder1_2); + test2(strBuilder1_3); + test2(strBuilder1_4); + } + + // Test method char charAt(int index). + private static void test1(StringBuilder strBuilder) { + int charAt = 0; + for (int i = -1; i < 8; i++) { + try { + charAt = strBuilder.charAt(i); + System.out.println("i=" + i + " " + "charAt=" + charAt); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("index: " + i + " String index out of range"); + } + } + } + + // Test Method void setCharAt(int index, char ch). + private static void test2(StringBuilder strBuilder) { + char ch = 'A'; + for (int i = -1; i < 8; i++) { + try { + strBuilder.setCharAt(i, ch); + System.out.println("i=" + i + " " + "setcharAt=" + strBuilder); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("index: " + i + " String index out of range"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*charAt\=113\s*i\=1\s*charAt\=119\s*i\=2\s*charAt\=101\s*i\=3\s*charAt\=114\s*i\=4\s*charAt\=116\s*i\=5\s*charAt\=121\s*i\=6\s*charAt\=117\s*i\=7\s*charAt\=105\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*charAt\=32\s*i\=1\s*charAt\=64\s*i\=2\s*charAt\=33\s*i\=3\s*charAt\=46\s*i\=4\s*charAt\=38\s*i\=5\s*charAt\=37\s*i\=6\s*charAt\=40\s*i\=7\s*charAt\=41\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*charAt\=97\s*i\=1\s*charAt\=98\s*i\=2\s*charAt\=99\s*i\=3\s*charAt\=49\s*i\=4\s*charAt\=50\s*i\=5\s*charAt\=51\s*index\:\s*6\s*String\s*index\s*out\s*of\s*range\s*index\:\s*7\s*String\s*index\s*out\s*of\s*range\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*index\:\s*0\s*String\s*index\s*out\s*of\s*range\s*index\:\s*1\s*String\s*index\s*out\s*of\s*range\s*index\:\s*2\s*String\s*index\s*out\s*of\s*range\s*index\:\s*3\s*String\s*index\s*out\s*of\s*range\s*index\:\s*4\s*String\s*index\s*out\s*of\s*range\s*index\:\s*5\s*String\s*index\s*out\s*of\s*range\s*index\:\s*6\s*String\s*index\s*out\s*of\s*range\s*index\:\s*7\s*String\s*index\s*out\s*of\s*range\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*setcharAt\=Awertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=1\s*setcharAt\=AAertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=2\s*setcharAt\=AAArtyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=3\s*setcharAt\=AAAAtyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=4\s*setcharAt\=AAAAAyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=5\s*setcharAt\=AAAAAAuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=6\s*setcharAt\=AAAAAAAiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*i\=7\s*setcharAt\=AAAAAAAAop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*setcharAt\=A\@\!\.\&\%\(\)\*\s*i\=1\s*setcharAt\=AA\!\.\&\%\(\)\*\s*i\=2\s*setcharAt\=AAA\.\&\%\(\)\*\s*i\=3\s*setcharAt\=AAAA\&\%\(\)\*\s*i\=4\s*setcharAt\=AAAAA\%\(\)\*\s*i\=5\s*setcharAt\=AAAAAA\(\)\*\s*i\=6\s*setcharAt\=AAAAAAA\)\*\s*i\=7\s*setcharAt\=AAAAAAAA\*\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*i\=0\s*setcharAt\=Abc123\s*i\=1\s*setcharAt\=AAc123\s*i\=2\s*setcharAt\=AAA123\s*i\=3\s*setcharAt\=AAAA23\s*i\=4\s*setcharAt\=AAAAA3\s*i\=5\s*setcharAt\=AAAAAA\s*index\:\s*6\s*String\s*index\s*out\s*of\s*range\s*index\:\s*7\s*String\s*index\s*out\s*of\s*range\s*index\:\s*\-1\s*String\s*index\s*out\s*of\s*range\s*index\:\s*0\s*String\s*index\s*out\s*of\s*range\s*index\:\s*1\s*String\s*index\s*out\s*of\s*range\s*index\:\s*2\s*String\s*index\s*out\s*of\s*range\s*index\:\s*3\s*String\s*index\s*out\s*of\s*range\s*index\:\s*4\s*String\s*index\s*out\s*of\s*range\s*index\:\s*5\s*String\s*index\s*out\s*of\s*range\s*index\:\s*6\s*String\s*index\s*out\s*of\s*range\s*index\:\s*7\s*String\s*index\s*out\s*of\s*range\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0020-rt-String-BuilderGetCharsTest/StringBuilderGetCharsTest.java b/test/testsuite/ouroboros/string_test/RT0020-rt-String-BuilderGetCharsTest/StringBuilderGetCharsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..45c9c6abfe5e6f7f81235d5df5dbb7ee7c2fd32e --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0020-rt-String-BuilderGetCharsTest/StringBuilderGetCharsTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderGetCharsTest.java + * -@TestCaseName: Test Method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) of StringBuilder. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create StringBuilder instance by new StringBuilder(String stringLine). + * -#step2: Create parameters: instance.length > srcEnd > srcBegin,dstBegin < dst(char[]).length, srcBegin/srcEnd + * /dstBegin coverage boundary value. + * -#step3: Test Method void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin). + * -#step4: Check some chars of dst(char[]) is replaced correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderGetCharsTest.java + * -@ExecuteClass: StringBuilderGetCharsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderGetCharsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderGetCharsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderGetCharsTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123"); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + } + + private static void test1(StringBuilder strBuilder) { + // Test srcBegin < srcEnd < instance.length, dstBegin < dst(char[]).length. + char[] dst = {'A', 'B', 'C', 'D', 'E', 'F'}; + strBuilder.getChars(2, 5, dst, 2); + System.out.println(dst); + + // Test srcBegin = 0. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuilder.getChars(0, 3, dst, 2); + System.out.println(dst); + + // Test srcEnd = 0. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuilder.getChars(0, 0, dst, 2); + System.out.println(dst); + + // Test dstBegin = 0. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuilder.getChars(2, 5, dst, 0); + System.out.println(dst); + + // Test strBuilder = srcEnd. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuilder.getChars(2, 2, dst, 0); + System.out.println(dst); + + // Test srcBegin = strBuffer.length() - 1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + int index = strBuilder.length() - 1; + strBuilder.getChars(index, index, dst, 0); + System.out.println(dst); + + // Test srcEnd = strBuffer.length() - 1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuilder.getChars(index - 2, index, dst, 0); + System.out.println(dst); + + // Test dstBegin = dst.length-1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + strBuilder.getChars(0, 1, dst, dst.length - 1); + System.out.println(dst); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ABertF\s*ABqweF\s*ABCDEF\s*ertDEF\s*ABCDEF\s*ABCDEF\s*x9CDEF\s*ABCDEq\s*AB\!\.\&F\s*AB\s*\@\!F\s*ABCDEF\s*\!\.\&DEF\s*ABCDEF\s*ABCDEF\s*\(\)CDEF\s*ABCDE\s*ABc12F\s*ABabcF\s*ABCDEF\s*c12DEF\s*ABCDEF\s*ABCDEF\s*12CDEF\s*ABCDEa\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0021-rt-String-BuilderIndexOfAndLastIndexOfTest/StringBuilderIndexOfAndLastIndexOfTest.java b/test/testsuite/ouroboros/string_test/RT0021-rt-String-BuilderIndexOfAndLastIndexOfTest/StringBuilderIndexOfAndLastIndexOfTest.java new file mode 100755 index 0000000000000000000000000000000000000000..20723a42f43c35295181827909637bf53054a638 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0021-rt-String-BuilderIndexOfAndLastIndexOfTest/StringBuilderIndexOfAndLastIndexOfTest.java @@ -0,0 +1,171 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderIndexOfAndLastIndexOfTest.java + * -@TestCaseName: Test Method int indexOf(String str)/int indexOf(String str, int fromIndex)/int lastIndexOf( + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * String str)/int lastIndexOf(String str, int fromIndex) of StringBuilder. + * -@Brief: + * -#case1 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameters: str is String with letter or empty String. + * -#step3: Test method indexOf(String str),check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~3. + * -#case2 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameters: str is String with letter, instance.length > fromIndex >= 0, fromIndex coverage boundary + * value. + * -#step3: Test method indexOf(String str, int fromIndex),check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~3. + * -#case3 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameters: str is String with letter or empty String. + * -#step3: Test method lastIndexOf(String str),check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~3. + * -#case4 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameters: str is String with letter, instance.length > fromIndex >= 0, fromIndex coverage boundary + * value. + * -#step3: Test method lastIndexOf(String str, int fromIndex),check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderIndexOfAndLastIndexOfTest.java + * -@ExecuteClass: StringBuilderIndexOfAndLastIndexOfTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderIndexOfAndLastIndexOfTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderIndexOfAndLastIndexOfTest_1(); + StringBuilderIndexOfAndLastIndexOfTest_2(); + StringBuilderIndexOfAndLastIndexOfTest_3(); + StringBuilderIndexOfAndLastIndexOfTest_4(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderIndexOfAndLastIndexOfTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + test1(strBuilder1_4); + test1(strBuilder1_5); + } + + public static void StringBuilderIndexOfAndLastIndexOfTest_2() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test2(strBuilder1_1); + test2(strBuilder1_2); + test2(strBuilder1_3); + test2(strBuilder1_4); + test2(strBuilder1_5); + } + + public static void StringBuilderIndexOfAndLastIndexOfTest_3() { + + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test3(strBuilder1_1); + test3(strBuilder1_2); + test3(strBuilder1_3); + test3(strBuilder1_4); + test3(strBuilder1_5); + } + + public static void StringBuilderIndexOfAndLastIndexOfTest_4() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test4(strBuilder1_1); + test4(strBuilder1_2); + test4(strBuilder1_3); + test4(strBuilder1_4); + test4(strBuilder1_5); + } + + // Test method indexOf(String str). + private static void test1(StringBuilder strBuilder) { + System.out.println(strBuilder.indexOf("b")); + // Test empty String. + System.out.println(strBuilder.indexOf("")); + } + + // Test method indexOf(String str, int fromIndex). + private static void test2(StringBuilder strBuilder) { + System.out.println(strBuilder.indexOf("b", 2)); + // Test fromIndex = 0. + System.out.println(strBuilder.indexOf("b", 0)); + // Test fromIndex = strBuilder.length() - 1. + System.out.println(strBuilder.indexOf("6", strBuilder.length() - 1)); + } + + // Test method lastIndexOf(String str). + private static void test3(StringBuilder strBuilder) { + System.out.println(strBuilder.lastIndexOf("b")); + // Test empty String. + System.out.println(strBuilder.lastIndexOf("")); + } + + // Test method lastIndexOf(String str, int fromIndex). + private static void test4(StringBuilder strBuilder) { + System.out.println(strBuilder.lastIndexOf("b", 1)); + // Test fromIndex = 0. + System.out.println(strBuilder.lastIndexOf("b", 0)); + // Test fromIndex = strBuilder.length() - 1. + System.out.println(strBuilder.lastIndexOf("6", strBuilder.length() - 1)); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 33\s*0\s*\-1\s*0\s*1\s*0\s*\-1\s*0\s*\-1\s*0\s*33\s*33\s*98\s*\-1\s*\-1\s*\-1\s*7\s*1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*33\s*99\s*\-1\s*9\s*7\s*9\s*\-1\s*0\s*\-1\s*0\s*\-1\s*\-1\s*98\s*\-1\s*\-1\s*\-1\s*1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0022-rt-String-BuilderReplaceAndReverseTest/StringBuilderReplaceAndReverseTest.java b/test/testsuite/ouroboros/string_test/RT0022-rt-String-BuilderReplaceAndReverseTest/StringBuilderReplaceAndReverseTest.java new file mode 100755 index 0000000000000000000000000000000000000000..52775695014022f41ee46b9b108bfbb5d22d6223 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0022-rt-String-BuilderReplaceAndReverseTest/StringBuilderReplaceAndReverseTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderReplaceAndReverseTest.java + * -@TestCaseName: Test Method StringBuffer replace(int start, int end, String str)/StringBuffer reverse() of + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * StringBuilder. + * -@Brief: + * -#case1 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameters: start < end < instance.length, start/end coverage boundary value. str is String with some + * letters. + * -#step3: Test method replace(int start, int end, String str), check return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -#case2 + * -#step1: Create StringBuilder instance. + * -#step2: Test method reverse(), check return result is correctly. + * -#step3: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderReplaceAndReverseTest.java + * -@ExecuteClass: StringBuilderReplaceAndReverseTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderReplaceAndReverseTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderReplaceAndReverseTest_1(); + StringBuilderReplaceAndReverseTest_2(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderReplaceAndReverseTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + } + + public static void StringBuilderReplaceAndReverseTest_2() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test2(strBuilder1_1); + test2(strBuilder1_2); + test2(strBuilder1_3); + test2(strBuilder1_4); + test2(strBuilder1_5); + } + + // Test method replace(int start, int end, String str). + private static void test1(StringBuilder strBuilder) { + System.out.println(strBuilder.replace(2, 6, "xyz")); + // end = 0 + System.out.println(strBuilder.replace(0, 0, "xyz")); + // start = 0 & end = strBuffer.length() + System.out.println(strBuilder.replace(0, strBuilder.length(), "xyz")); + // start = strBuffer.length() & end = strBuffer.length() + System.out.println(strBuilder.replace(strBuilder.length(), strBuilder.length(), "xyz")); + } + + // Test method reverse(). + private static void test2(StringBuilder strBuilder) { + strBuilder.reverse(); + System.out.println(strBuilder); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwxyzuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*xyzqwxyzuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*xyz\s*xyzxyz\s*\@xyz\s*xyz\s*\@xyz\s*xyz\s*xyzxyz\s*abxyzabc\s*xyzabxyzabc\s*xyz\s*xyzxyz\s*69x0MNBVCXZPOIUYTREWQLKJHGFDSA\s*\+_\)\(\*\&\^\%\$\#\@\!\=\-0987654321\`\~\?\/\>\<\.\,mnbvcxz\"\'\:\;lkjhgfdsa\|\\\]\[\}\{poiuytrewq\s*\%\&\.\!\@\s*cba321cba\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0023-rt-String-BuilderSubstringAndToStringTest/StringBuilderSubstringAndToStringTest.java b/test/testsuite/ouroboros/string_test/RT0023-rt-String-BuilderSubstringAndToStringTest/StringBuilderSubstringAndToStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c40090ca6ed018984e97cb1cb7f3794820d4d74f --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0023-rt-String-BuilderSubstringAndToStringTest/StringBuilderSubstringAndToStringTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderSubstringAndToStringTest.java + * -@TestCaseName: Test Method:String substring(int start)/String substring(int start, int end)/String toString() + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * of StringBuilder. + * -@Brief: + * -#case1 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameters: start < instance.length, start < end < instance.length, start and end coverage boundary + * value. + * -#step3: Test method substring(int start, int end). + * -#step4: Check the return result of substring is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -#case2 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameters: 0 =< start < instance.length, start coverage boundary value. + * -#step3: Test method substring(int start). + * -#step4: Check the return result of substring is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -#case3 + * -#step1: Create StringBuilder instance by new StringBuilder(String stringLine). + * -#step2: Test method toString(). + * -#step3: Check the return result of toString is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2-3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringBuilderSubstringAndToStringTest.java + * -@ExecuteClass: StringBuilderSubstringAndToStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderSubstringAndToStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringBuilderSubstringAndToStringTest_1(); + StringBuilderSubstringAndToStringTest_2(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringBuilderSubstringAndToStringTest_1() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%()*"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + + test1(strBuilder1_1); + test1(strBuilder1_2); + test1(strBuilder1_3); + + test2(strBuilder1_1); + test2(strBuilder1_2); + test2(strBuilder1_3); + } + + public static void StringBuilderSubstringAndToStringTest_2() { + StringBuilder strBuilder1_1 = new StringBuilder("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890" + + "-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + StringBuilder strBuilder1_2 = new StringBuilder(" @!.&%"); + StringBuilder strBuilder1_3 = new StringBuilder("abc123abc"); + StringBuilder strBuilder1_4 = new StringBuilder(""); + StringBuilder strBuilder1_5 = new StringBuilder(); + + test3(strBuilder1_1); + test3(strBuilder1_2); + test3(strBuilder1_3); + test3(strBuilder1_4); + test3(strBuilder1_5); + } + + // Test method substring(int start, int end). + private static void test1(StringBuilder strBuilder) { + System.out.println(strBuilder.substring(2, 7)); + // Test start = 0 & end = strBuffer.length(). + System.out.println(strBuilder.substring(0, strBuilder.length())); + // Test start = strBuffer.length(). + System.out.println(strBuilder.substring(strBuilder.length(), strBuilder.length())); + // Test end = 0. + System.out.println(strBuilder.substring(0, 0)); + } + + // Test method substring(int start). + private static void test2(StringBuilder strBuilder) { + System.out.println(strBuilder.substring(3)); + // Test start = 0. + System.out.println(strBuilder.substring(0)); + // Test start = strBuffer.length(). + System.out.println(strBuilder.substring(strBuilder.length())); + } + + // Test method toString(). + private static void test3(StringBuilder strBuilder) { + System.out.println(strBuilder.toString()); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ertyu\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\!\.\&\%\(\s*\@\!\.\&\%\(\)\*\s*c123a\s*abc123abc\s*rtyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\.\&\%\(\)\*\s*\@\!\.\&\%\(\)\*\s*123abc\s*abc123abc\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*abc123abc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0024-rt-String-ConsBytesIntIntIndexOutOfBoundsExceptionTest/StringConsBytesIntIntIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0024-rt-String-ConsBytesIntIntIndexOutOfBoundsExceptionTest/StringConsBytesIntIntIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..23f5ea908a16f588ab24547c1023437c78805ef0 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0024-rt-String-ConsBytesIntIntIndexOutOfBoundsExceptionTest/StringConsBytesIntIntIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsBytesIntIntIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test IndexOutOfBoundsException in String constructor:public String(byte[] bytes, int offset, + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * int length). + * -@Brief: + * -#step1: Create Parameters: byte[] str1_1,str1_1.length > 0, element is byte in normal. + * -#step2: Create offset < 0, 0 < length < str1_1.length, Test Constructors new String(byte[] bytes, int offset, + * int length), check IndexOutOfBoundsException is thrown. + * -#step3: Create 0 < offset < str1_1.length, length < 0, Test Constructors new String(byte[] bytes, int offset, + * int length), check IndexOutOfBoundsException is thrown. + * -#step4: Create 0 < offset < str1_1.length, length > str1_1.length, Test Constructors new String(byte[] bytes, + * int offset, int length), check IndexOutOfBoundsException is thrown. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsBytesIntIntIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: StringConsBytesIntIntIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsBytesIntIntIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + result = StringConsBytesIntIntIndexOutOfBoundsExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 96) { + result = 0; + } + return result; + } + + public static int StringConsBytesIntIntIndexOutOfBoundsExceptionTest_1() { + int result1 = 2; /* STATUS_Success */ + // IndexOutOfBoundsException - If the offset and length arguments index characters outside the bounds of the + // bytes array + byte[] str1_1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + try { + String str1 = new String(str1_1, -1, 3); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String str1 = new String(str1_1, 3, -1); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String str1 = new String(str1_1, 3, 10); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } +} + + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0025-rt-String-ConsCharArrayIndexOutOfBoundsExceptionTest/StringConsCharArrayIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0025-rt-String-ConsCharArrayIndexOutOfBoundsExceptionTest/StringConsCharArrayIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ef63f57d8ce7d64d0c9a418a8201e49e793ae577 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0025-rt-String-ConsCharArrayIndexOutOfBoundsExceptionTest/StringConsCharArrayIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsCharArrayIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test String constructor: String(char[] value, int offset, int count) throw + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * IndexOutOfBoundsException. + * -@Brief: + * -#step1: Create Parameters: char[] str1_1,str1_1.length > 0, element is letter or number. + * -#step2: Create offset < 0, 0 < length < str1_1.length, Test Constructors new String(char[] value, int offset, + * int count), check IndexOutOfBoundsException is thrown. + * -#step3: Create 0 =< offset < str1_1.length, length > str1_1.length, Test Constructors new String(char[] value, + * int offset, int count), check IndexOutOfBoundsException is thrown. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsCharArrayIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: StringConsCharArrayIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsCharArrayIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + result = StringConsCharArrayIndexOutOfBoundsExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 97) { + result = 0; + } + return result; + } + + public static int StringConsCharArrayIndexOutOfBoundsExceptionTest_1() { + int result1 = 2; /* STATUS_Success */ + // IndexOutOfBoundsException - If the offset and length arguments index characters outside the bounds of the + // bytes array + char[] str1_1 = {'a', 'b', 'c', '1', '2', '3'}; + try { + String str1 = new String(str1_1, -1, 3); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + try { + String str2 = new String(str1_1, 0, 10); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } +} + + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0026-rt-String-ConsIntArrayExceptionsTest/StringConsIntArrayExceptionsTest.java b/test/testsuite/ouroboros/string_test/RT0026-rt-String-ConsIntArrayExceptionsTest/StringConsIntArrayExceptionsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fab1d6eacf8eabcd8d2a655766e12cc6e5881219 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0026-rt-String-ConsIntArrayExceptionsTest/StringConsIntArrayExceptionsTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsIntArrayExceptionsTest.java + * -@TestCaseName: Test IndexOutOfBoundsException/IllegalArgumentException in String constructor: String(int[] + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * codePoints, int offset, int count). + * -@Brief: + * -#step1: Create Parameters: int[] str1_1,str1_1.length > 0, element is number. + * -#step2: Create offset < 0, count = str1_1.length, Test Constructors new String(int[] codePoints, int offset, + * int count), check IndexOutOfBoundsException is thrown. + * -#step3: Create 0 =< offset < str1_1.length, count > str1_1.length, Test Constructors new String(int[] codePoints, + * int offset, int count), check IndexOutOfBoundsException is thrown. + * -#step4: Create Parameters: int[] str1_2,str1_2.length > 0, element is Unicode code point include invalid num. + * -#step5: Create offset = 0, count = str1_2.length, Test Constructors new String(int[] codePoints, int offset, + * int count), check IllegalArgumentException is thrown. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsIntArrayExceptionsTest.java + * -@ExecuteClass: StringConsIntArrayExceptionsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsIntArrayExceptionsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + result = StringConsIntArrayExceptionsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 96) { + result = 0; + } + return result; + } + + public static int StringConsIntArrayExceptionsTest_1() { + int result1 = 2; /* STATUS_Success */ + // IndexOutOfBoundsException - If the offset and count arguments index characters outside the bounds of the + // codePoints array + int[] str1_1 = new int[]{97, 98, 99, 49, 50, 51}; + try { + String str1 = new String(str1_1, -1, str1_1.length); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String str1 = new String(str1_1, 0, 10); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + //IllegalArgumentException - If any invalid Unicode code point is found in codePoints + int[] str1_2 = new int[]{0xFFFFFFF, 0x62, 0x63, 0x31, 0x32, 0x33}; + try { + String str2 = new String(str1_2, 0, str1_2.length); + processResult -= 10; + } catch (IllegalArgumentException e1) { + processResult--; + } + return result1; + } +} + + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0027-rt-String-ConsBytesIntIntIntIndexOutOfBoundsExceptionTest/StringConsBytesIntIntIntIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0027-rt-String-ConsBytesIntIntIntIndexOutOfBoundsExceptionTest/StringConsBytesIntIntIntIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..49494a2089b3ade2dde46dfb682298ed28a1a2ea --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0027-rt-String-ConsBytesIntIntIntIndexOutOfBoundsExceptionTest/StringConsBytesIntIntIntIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsBytesIntIntIntIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test IndexOutOfBoundsException/IllegalArgumentException in String constructor: String(byte[] + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * ascii, int hibyte, int offset, int count). + * -@Brief: + * -#step1: Create Parameters: byte[] str1_1,str1_1.length > 0, element is byte in normal. + * -#step2: Create hibyte >= 0, offset < 0, 0 < count < str1_1.length, Test Constructors new String(byte[] bytes, int + * hibyte, int offset, int count), check IndexOutOfBoundsException is thrown. + * -#step3: Create hibyte >= 0, str1_1.length > offset >= 0, count > str1_1.length, Test Constructors new String(byte[] + * bytes, int hibyte, int offset, int count), check IndexOutOfBoundsException is thrown. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsBytesIntIntIntIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: StringConsBytesIntIntIntIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsBytesIntIntIntIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + result = StringConsBytesIntIntIntIndexOutOfBoundsExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 97) { + result = 0; + } + return result; + } + + public static int StringConsBytesIntIntIntIndexOutOfBoundsExceptionTest_1() { + int result1 = 2; /* STATUS_Success */ + // IndexOutOfBoundsException - If the offset and count arguments index characters outside the bounds of the + // codePoints array + byte[] str1_1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + try { + String str1 = new String(str1_1, 0, -1, 2); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String str1 = new String(str1_1, 0, 0, 10); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0028-rt-String-ConsBytesIntIntCharsetExceptionTest/StringConsBytesIntIntCharsetExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0028-rt-String-ConsBytesIntIntCharsetExceptionTest/StringConsBytesIntIntCharsetExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ea0c31b45554fc85730b862a86222c45443b1b0d --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0028-rt-String-ConsBytesIntIntCharsetExceptionTest/StringConsBytesIntIntCharsetExceptionTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsBytesIntIntCharsetExceptionTest.java + * -@TestCaseName: Test IndexOutOfBoundsException in String constructor: String(byte[] bytes, int offset, int + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * length, Charset charset). + * -@Brief: + * -#step1: Create Parameters: byte[] str1_1,str1_1.length > 0, element is byte in normal. + * -#step2: Create offset < 0, 0 < length < str1_1.length, Charset is a Unicode charset, Test Constructors new String( + * byte[] bytes, int offset, int length, Charset charset), check IndexOutOfBoundsException is thrown. + * -#step3: Create str1_1.length > offset >= 0, length < 0, Charset is a Unicode Charset, Test Constructors new String( + * byte[] bytes, int offset, int length, Charset charset), check IndexOutOfBoundsException is thrown. + * -#step4: Create str1_1.length > offset >= 0, length > str1_1.length, Charset is a Unicode Charset, Test Constructors + * new String(byte[] bytes, int offset, int length, Charset charset), check IndexOutOfBoundsException is thrown. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsBytesIntIntCharsetExceptionTest.java + * -@ExecuteClass: StringConsBytesIntIntCharsetExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.nio.charset.Charset; + +public class StringConsBytesIntIntCharsetExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + result = StringConsBytesIntIntCharsetExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 96) { + result = 0; + } + return result; + } + + public static int StringConsBytesIntIntCharsetExceptionTest_1() { + int result1 = 2; /* STATUS_Success */ + // IndexOutOfBoundsException - If the offset and length arguments index characters outside the bounds of the + // bytes array + byte[] str1_1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + try { + String str1 = new String(str1_1, -1, 3, Charset.forName("ASCII")); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String str1 = new String(str1_1, 3, -1, Charset.forName("ASCII")); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String str1 = new String(str1_1, 3, 10, Charset.forName("ASCII")); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0029-rt-String-CharAtIndexOutOfBoundsExceptionTest/StringCharAtIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0029-rt-String-CharAtIndexOutOfBoundsExceptionTest/StringCharAtIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9fff5fdf958684f5669323a1362956e129cd212b --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0029-rt-String-CharAtIndexOutOfBoundsExceptionTest/StringCharAtIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCharAtIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test IndexOutOfBoundsException in String Method: public char charAt(int index). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: str1.length > 0, index < 0, Test method charAt(int index), check IndexOutOfBoundsException + * is thrown. + * -#step3: Create Parameters: str1.length = 0, index > 0, Test method charAt(int index), check IndexOutOfBoundsException + * is thrown. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCharAtIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: StringCharAtIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCharAtIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + result = StringCharAtIndexOutOfBoundsExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 97) { + result = 0; + } + return result; + } + + public static int StringCharAtIndexOutOfBoundsExceptionTest_1() { + int result1 = 2; /* STATUS_Success */ + // IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string. + String str1_1 = new String("abc123"); + String str1_4 = new String(""); + try { + char ch = str1_1.charAt(-2); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + char ch = str1_4.charAt(2); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0030-rt-String-CodePointAtStringIndexOutOfBoundsExceptionTest/StringCodePointAtStringIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0030-rt-String-CodePointAtStringIndexOutOfBoundsExceptionTest/StringCodePointAtStringIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ada432ccebe577df3aacb11697e08bb6dc63cc9e --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0030-rt-String-CodePointAtStringIndexOutOfBoundsExceptionTest/StringCodePointAtStringIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCodePointAtStringIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test StringIndexOutOfBoundsException in String Method: public int codePointAt(int index). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: index range from -1 to instance.length + 1. + * -#step3: Check the result int is correctly when index is range from 0 to (instance.length -1), + * StringIndexOutOfBoundsException is thrown when index < 0 or index > (instance.length -1). + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2-3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCodePointAtStringIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: StringCodePointAtStringIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCodePointAtStringIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCodePointAtStringIndexOutOfBoundsExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCodePointAtStringIndexOutOfBoundsExceptionTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + int codePoint = 0; + for (int i = -1; i < 7; i++) { + try { + codePoint = str.codePointAt(i); + System.out.println("i=" + i + " " + "codePointAt=" + codePoint); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("codePointAt(): " + i + " StringIndexOutOfBounds"); + } finally { + try { + System.out.println(str.charAt(i) + " Unicode is" + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " StringIndexOutOfBounds"); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan codePointAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointAt\=113\s*q\s*Unicode\s*is\:113\s*i\=1\s*codePointAt\=119\s*w\s*Unicode\s*is\:119\s*i\=2\s*codePointAt\=101\s*e\s*Unicode\s*is\:101\s*i\=3\s*codePointAt\=114\s*r\s*Unicode\s*is\:114\s*i\=4\s*codePointAt\=116\s*t\s*Unicode\s*is\:116\s*i\=5\s*codePointAt\=121\s*y\s*Unicode\s*is\:121\s*i\=6\s*codePointAt\=117\s*u\s*Unicode\s*is\:117\s*codePointAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointAt\=32\s*Unicode\s*is\:32\s*i\=1\s*codePointAt\=64\s*\@\s*Unicode\s*is\:64\s*i\=2\s*codePointAt\=33\s*\!\s*Unicode\s*is\:33\s*i\=3\s*codePointAt\=46\s*\.\s*Unicode\s*is\:46\s*i\=4\s*codePointAt\=38\s*\&\s*Unicode\s*is\:38\s*i\=5\s*codePointAt\=37\s*\%\s*Unicode\s*is\:37\s*codePointAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointAt\=97\s*a\s*Unicode\s*is\:97\s*i\=1\s*codePointAt\=98\s*b\s*Unicode\s*is\:98\s*i\=2\s*codePointAt\=99\s*c\s*Unicode\s*is\:99\s*i\=3\s*codePointAt\=49\s*1\s*Unicode\s*is\:49\s*i\=4\s*codePointAt\=50\s*2\s*Unicode\s*is\:50\s*i\=5\s*codePointAt\=51\s*3\s*Unicode\s*is\:51\s*codePointAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*5\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*5\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*5\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*5\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointAt\=113\s*q\s*Unicode\s*is\:113\s*i\=1\s*codePointAt\=119\s*w\s*Unicode\s*is\:119\s*i\=2\s*codePointAt\=101\s*e\s*Unicode\s*is\:101\s*i\=3\s*codePointAt\=114\s*r\s*Unicode\s*is\:114\s*i\=4\s*codePointAt\=116\s*t\s*Unicode\s*is\:116\s*i\=5\s*codePointAt\=121\s*y\s*Unicode\s*is\:121\s*i\=6\s*codePointAt\=117\s*u\s*Unicode\s*is\:117\s*codePointAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointAt\=32\s*Unicode\s*is\:32\s*i\=1\s*codePointAt\=64\s*\@\s*Unicode\s*is\:64\s*i\=2\s*codePointAt\=33\s*\!\s*Unicode\s*is\:33\s*i\=3\s*codePointAt\=46\s*\.\s*Unicode\s*is\:46\s*i\=4\s*codePointAt\=38\s*\&\s*Unicode\s*is\:38\s*i\=5\s*codePointAt\=37\s*\%\s*Unicode\s*is\:37\s*codePointAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointAt\=97\s*a\s*Unicode\s*is\:97\s*i\=1\s*codePointAt\=98\s*b\s*Unicode\s*is\:98\s*i\=2\s*codePointAt\=99\s*c\s*Unicode\s*is\:99\s*i\=3\s*codePointAt\=49\s*1\s*Unicode\s*is\:49\s*i\=4\s*codePointAt\=50\s*2\s*Unicode\s*is\:50\s*i\=5\s*codePointAt\=51\s*3\s*Unicode\s*is\:51\s*codePointAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*5\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*5\s*StringIndexOutOfBounds\s*codePointAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0031-rt-String-CodePointBeforeExceptionTest/StringCodePointBeforeExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0031-rt-String-CodePointBeforeExceptionTest/StringCodePointBeforeExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..6d22cd61bfde1962294ad939f340067f423b2d80 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0031-rt-String-CodePointBeforeExceptionTest/StringCodePointBeforeExceptionTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCodePointBeforeExceptionTest.java + * -@TestCaseName: Test StringIndexOutOfBoundsException in String Method: int codePointBefore(int index). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: index range from -1 to instance.length + 1. + * -#step3: Check the result int is correctly when index is range from 0 to (instance.length -1), + * StringIndexOutOfBoundsException is thrown when index < 0 or index > (instance.length -1). + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2-3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCodePointBeforeExceptionTest.java + * -@ExecuteClass: StringCodePointBeforeExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCodePointBeforeExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCodePointBeforeExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCodePointBeforeExceptionTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + int codePoint = 0; + for (int i = -1; i < 7; i++) { + try { + codePoint = str.codePointBefore(i); + System.out.println("i=" + i + " " + "codePointBefore=" + codePoint); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("codePointBefore(): " + i + " StringIndexOutOfBounds"); + } finally { + try { + System.out.println(str.charAt(i) + " codePointBefore is" + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " StringIndexOutOfBounds"); + } + } + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan codePointBefore\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*0\s*StringIndexOutOfBounds\s*q\s*codePointBefore\s*is\:0\s*i\=1\s*codePointBefore\=113\s*w\s*codePointBefore\s*is\:113\s*i\=2\s*codePointBefore\=119\s*e\s*codePointBefore\s*is\:119\s*i\=3\s*codePointBefore\=101\s*r\s*codePointBefore\s*is\:101\s*i\=4\s*codePointBefore\=114\s*t\s*codePointBefore\s*is\:114\s*i\=5\s*codePointBefore\=116\s*y\s*codePointBefore\s*is\:116\s*i\=6\s*codePointBefore\=121\s*u\s*codePointBefore\s*is\:121\s*codePointBefore\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointBefore\s*is\:0\s*i\=1\s*codePointBefore\=32\s*\@\s*codePointBefore\s*is\:32\s*i\=2\s*codePointBefore\=64\s*\!\s*codePointBefore\s*is\:64\s*i\=3\s*codePointBefore\=33\s*\.\s*codePointBefore\s*is\:33\s*i\=4\s*codePointBefore\=46\s*\&\s*codePointBefore\s*is\:46\s*i\=5\s*codePointBefore\=38\s*\%\s*codePointBefore\s*is\:38\s*i\=6\s*codePointBefore\=37\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*0\s*StringIndexOutOfBounds\s*a\s*codePointBefore\s*is\:0\s*i\=1\s*codePointBefore\=97\s*b\s*codePointBefore\s*is\:97\s*i\=2\s*codePointBefore\=98\s*c\s*codePointBefore\s*is\:98\s*i\=3\s*codePointBefore\=99\s*1\s*codePointBefore\s*is\:99\s*i\=4\s*codePointBefore\=49\s*2\s*codePointBefore\s*is\:49\s*i\=5\s*codePointBefore\=50\s*3\s*codePointBefore\s*is\:50\s*i\=6\s*codePointBefore\=51\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*0\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*2\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*3\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*4\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*5\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*5\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*0\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*2\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*3\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*4\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*5\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*5\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*0\s*StringIndexOutOfBounds\s*q\s*codePointBefore\s*is\:0\s*i\=1\s*codePointBefore\=113\s*w\s*codePointBefore\s*is\:113\s*i\=2\s*codePointBefore\=119\s*e\s*codePointBefore\s*is\:119\s*i\=3\s*codePointBefore\=101\s*r\s*codePointBefore\s*is\:101\s*i\=4\s*codePointBefore\=114\s*t\s*codePointBefore\s*is\:114\s*i\=5\s*codePointBefore\=116\s*y\s*codePointBefore\s*is\:116\s*i\=6\s*codePointBefore\=121\s*u\s*codePointBefore\s*is\:121\s*codePointBefore\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointBefore\s*is\:0\s*i\=1\s*codePointBefore\=32\s*\@\s*codePointBefore\s*is\:32\s*i\=2\s*codePointBefore\=64\s*\!\s*codePointBefore\s*is\:64\s*i\=3\s*codePointBefore\=33\s*\.\s*codePointBefore\s*is\:33\s*i\=4\s*codePointBefore\=46\s*\&\s*codePointBefore\s*is\:46\s*i\=5\s*codePointBefore\=38\s*\%\s*codePointBefore\s*is\:38\s*i\=6\s*codePointBefore\=37\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*0\s*StringIndexOutOfBounds\s*a\s*codePointBefore\s*is\:0\s*i\=1\s*codePointBefore\=97\s*b\s*codePointBefore\s*is\:97\s*i\=2\s*codePointBefore\=98\s*c\s*codePointBefore\s*is\:98\s*i\=3\s*codePointBefore\=99\s*1\s*codePointBefore\s*is\:99\s*i\=4\s*codePointBefore\=49\s*2\s*codePointBefore\s*is\:49\s*i\=5\s*codePointBefore\=50\s*3\s*codePointBefore\s*is\:50\s*i\=6\s*codePointBefore\=51\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*0\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*1\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*2\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*3\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*4\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*5\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*5\s*StringIndexOutOfBounds\s*codePointBefore\(\)\:\s*6\s*StringIndexOutOfBounds\s*charAt\(\)\:\s*6\s*StringIndexOutOfBounds\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0032-rt-String-CodePointCountIndexOutOfBoundsExceptionTest/StringCodePointCountIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0032-rt-String-CodePointCountIndexOutOfBoundsExceptionTest/StringCodePointCountIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b3a0a74a37a9f6ba8d87873bccc28b8488fcf79d --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0032-rt-String-CodePointCountIndexOutOfBoundsExceptionTest/StringCodePointCountIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCodePointCountIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test IndexOutOfBoundsException in int codePointCount(int beginIndex, int endIndex) of String. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: beginIndex range from -1 to instance.length - 2, endIndex = beginIndex + 3. + * -#step3: Test Method codePointCount(int beginIndex, int endIndex), Check result is correctly. + * IndexOutOfBoundsException is thrown when beginIndex < 0 or endIndex > instance.length - 1. + * -#step4: Create Parameters index = beginIndex, Test Method charAt(int index), Check String instance is correctly. + * StringIndexOutOfBoundsException is thrown when index < 0 or index >= instance.length. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCodePointCountIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: StringCodePointCountIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCodePointCountIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCodePointCountIndexOutOfBoundsExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCodePointCountIndexOutOfBoundsExceptionTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + + private static void test(String str) { + int codePoint = 0; + for (int i = -1; i < 5; i++) { + try { + codePoint = str.codePointCount(i, i + 3); + System.out.println("i=" + i + " " + "codePointCount=" + codePoint); + } catch (IndexOutOfBoundsException e1) { + System.out.println("codePointCount(): " + i + " IndexOutOfBounds"); + } finally { + try { + System.out.println(str.charAt(i) + " codePointCount is " + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " StringIndexOutOfBounds"); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan codePointCount\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointCount\=3\s*q\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*w\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*e\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*r\s*codePointCount\s*is\s*\:3\s*i\=4\s*codePointCount\=3\s*t\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointCount\=3\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*\@\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*\!\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*\.\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*4\s*IndexOutOfBounds\s*\&\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointCount\=3\s*a\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*b\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*c\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*1\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*4\s*IndexOutOfBounds\s*2\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*0\s*IndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*1\s*IndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*2\s*IndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*3\s*IndexOutOfBounds\s*charAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*4\s*IndexOutOfBounds\s*charAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*0\s*IndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*1\s*IndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*2\s*IndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*3\s*IndexOutOfBounds\s*charAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*4\s*IndexOutOfBounds\s*charAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointCount\=3\s*q\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*w\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*e\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*r\s*codePointCount\s*is\s*\:3\s*i\=4\s*codePointCount\=3\s*t\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointCount\=3\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*\@\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*\!\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*\.\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*4\s*IndexOutOfBounds\s*\&\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*codePointCount\=3\s*a\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*b\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*c\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*1\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*4\s*IndexOutOfBounds\s*2\s*codePointCount\s*is\s*\:3\s*codePointCount\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*0\s*IndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*1\s*IndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*2\s*IndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*3\s*IndexOutOfBounds\s*charAt\(\)\:\s*3\s*StringIndexOutOfBounds\s*codePointCount\(\)\:\s*4\s*IndexOutOfBounds\s*charAt\(\)\:\s*4\s*StringIndexOutOfBounds\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0033-rt-String-OffsetByCodePointsIndexOutOfBoundsExceptionTest/StringOffsetByCodePointsIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0033-rt-String-OffsetByCodePointsIndexOutOfBoundsExceptionTest/StringOffsetByCodePointsIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..902c9d90a18bd18ce933d420b52f3405a47b59a2 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0033-rt-String-OffsetByCodePointsIndexOutOfBoundsExceptionTest/StringOffsetByCodePointsIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringOffsetByCodePointsIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test IndexOutOfBoundsException in String Method: int offsetByCodePoints(int index, + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * int codePointOffset). + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: index range from -1 to instance.length - 4, codePointOffset = index + 3. + * -#step3: Test Method offsetByCodePoints(int index, int codePointOffset), Check result is correctly. + * IndexOutOfBoundsException is thrown when beginIndex < 0 or index + codePointOffset > instance.length. + * -#step4: Create Parameters index = beginIndex, Test Method charAt(int index), Check String instance is correctly. + * StringIndexOutOfBoundsException is thrown when index < 0 or index >= instance.length. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringOffsetByCodePointsIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: StringOffsetByCodePointsIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringOffsetByCodePointsIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringOffsetByCodePointsIndexOutOfBoundsExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringOffsetByCodePointsIndexOutOfBoundsExceptionTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + int codePoint = 0; + for (int i = -1; i < 3; i++) { + try { + codePoint = str.offsetByCodePoints(i, i + 3); + System.out.println("i=" + i + " " + "offsetByCodePoints=" + codePoint); + } catch (IndexOutOfBoundsException e1) { + System.out.println("offsetByCodePoints(): " + i + " IndexOutOfBounds"); + } finally { + try { + System.out.println(str.charAt(i) + " offsetByCodePoints is " + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " StringIndexOutOfBounds"); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan offsetByCodePoints\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*offsetByCodePoints\=3\s*q\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*w\s*offsetByCodePoints\s*is\s*\:5\s*i\=2\s*offsetByCodePoints\=7\s*e\s*offsetByCodePoints\s*is\s*\:7\s*offsetByCodePoints\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*offsetByCodePoints\=3\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*\@\s*offsetByCodePoints\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*2\s*IndexOutOfBounds\s*\!\s*offsetByCodePoints\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*offsetByCodePoints\=3\s*a\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*b\s*offsetByCodePoints\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*2\s*IndexOutOfBounds\s*c\s*offsetByCodePoints\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*0\s*IndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*1\s*IndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*2\s*IndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*0\s*IndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*1\s*IndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*2\s*IndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*offsetByCodePoints\=3\s*q\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*w\s*offsetByCodePoints\s*is\s*\:5\s*i\=2\s*offsetByCodePoints\=7\s*e\s*offsetByCodePoints\s*is\s*\:7\s*offsetByCodePoints\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*offsetByCodePoints\=3\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*\@\s*offsetByCodePoints\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*2\s*IndexOutOfBounds\s*\!\s*offsetByCodePoints\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*i\=0\s*offsetByCodePoints\=3\s*a\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*b\s*offsetByCodePoints\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*2\s*IndexOutOfBounds\s*c\s*offsetByCodePoints\s*is\s*\:5\s*offsetByCodePoints\(\)\:\s*\-1\s*IndexOutOfBounds\s*charAt\(\)\:\s*\-1\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*0\s*IndexOutOfBounds\s*charAt\(\)\:\s*0\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*1\s*IndexOutOfBounds\s*charAt\(\)\:\s*1\s*StringIndexOutOfBounds\s*offsetByCodePoints\(\)\:\s*2\s*IndexOutOfBounds\s*charAt\(\)\:\s*2\s*StringIndexOutOfBounds\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0034-rt-String-GetCharsExceptionsTest/StringGetCharsExceptionsTest.java b/test/testsuite/ouroboros/string_test/RT0034-rt-String-GetCharsExceptionsTest/StringGetCharsExceptionsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f46618ec73b9607623c64fa89031ff4ead751a86 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0034-rt-String-GetCharsExceptionsTest/StringGetCharsExceptionsTest.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringGetCharsExceptionsTest.java + * -@TestCaseName: Test Exception in String Method: void getChars(int srcBegin, int srcEnd, char[] dst, + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * int dstBegin). + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: dst is null, 0 < srcBegin < srcEnd, srcEnd < instance.length, dstBegin > 0. + * -#step3: Test method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin), check NullPointerException is + * thrown, check dst is not replaced. + * -#step4: Create Parameters: dst.length > 0, data.element is letter, srcBegin < 0, 0 < srcEnd < instance.length, + * 0 < dstBegin < dst.length. + * -#step5: Test method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin), check + * StringIndexOutOfBoundsException is thrown, check dst is not replaced. + * -#step6: Create Parameters: dst.length > 0, data.element is letter, 0 < srcBegin < srcEnd, srcEnd < instance.length, + * 0 < dstBegin < dst.length, dstBegin + srcEnd - srcBegin > dst.length. + * -#step7: Test method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin), check + * ArrayIndexOutOfBoundsException is thrown, check dst is not replaced. + * -#step8: Create Parameters: dst.length > 0, data.element is letter, srcBegin > srcEnd, 0 < srcEnd < instance.length, + * 0 < dstBegin < dst.length. + * -#step9: Test method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin), check + * StringIndexOutOfBoundsException is thrown, check dst is not replaced. + * -#step10: Create Parameters: dst.length > 0, data.element is letter, 0 < srcBegin < srcEnd, srcEnd < instance.length, + * dstBegin < 0. + * -#step11: Test method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin), check + * StringIndexOutOfBoundsException is thrown, check dst is not replaced. + * -#step12: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~11. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringGetCharsExceptionsTest.java + * -@ExecuteClass: StringGetCharsExceptionsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringGetCharsExceptionsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringGetCharsExceptionsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringGetCharsExceptionsTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + char dst1_1[] = null; + try { + str.getChars(2, 5, dst1_1, 2); + } catch (NullPointerException e1) { + System.out.println("EXCEPTION 1_1"); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 1_2"); + } finally { + try { + System.out.println(dst1_1); + } catch (NullPointerException e2) { + System.out.println("EXCEPTION 1_3"); + } + } + + char dst1_2[] = {'A', 'B', 'C', 'D', 'E'}; + try { + str.getChars(-1, 5, dst1_2, 2); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 2_1"); + } finally { + try { + System.out.println(dst1_2); + } catch (NullPointerException e2) { + System.out.println("EXCEPTION 2_2"); + } + } + + char dst1_3[] = {'A', 'B', 'C', 'D', 'E'}; + try { + str.getChars(2, 6, dst1_3, 2); + } catch (ArrayIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 3_1"); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 3_2"); + } finally { + try { + System.out.println(dst1_3); + } catch (NullPointerException e2) { + System.out.println("EXCEPTION 3_3"); + } + } + + char dst1_4[] = {'A', 'B', 'C', 'D', 'E'}; + try { + str.getChars(4, 3, dst1_4, 2); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 4_1"); + } finally { + try { + System.out.println(dst1_4); + } catch (NullPointerException e2) { + System.out.println("EXCEPTION 4_2"); + } + } + + char dst1_5[] = {'A', 'B', 'C', 'D', 'E'}; + try { + str.getChars(4, 3, dst1_5, -1); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 5_1"); + } finally { + try { + System.out.println(dst1_5); + } catch (NullPointerException e2) { + System.out.println("EXCEPTION 5_2"); + } + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan EXCEPTION\s*1_1\s*EXCEPTION\s*1_3\s*EXCEPTION\s*2_1\s*ABCDE\s*EXCEPTION\s*3_1\s*ABCDE\s*EXCEPTION\s*4_1\s*ABCDE\s*EXCEPTION\s*5_1\s*ABCDE\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_3\s*EXCEPTION\s*2_1\s*ABCDE\s*EXCEPTION\s*3_1\s*ABCDE\s*EXCEPTION\s*4_1\s*ABCDE\s*EXCEPTION\s*5_1\s*ABCDE\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_3\s*EXCEPTION\s*2_1\s*ABCDE\s*EXCEPTION\s*3_1\s*ABCDE\s*EXCEPTION\s*4_1\s*ABCDE\s*EXCEPTION\s*5_1\s*ABCDE\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_3\s*EXCEPTION\s*2_1\s*ABCDE\s*EXCEPTION\s*3_2\s*ABCDE\s*EXCEPTION\s*4_1\s*ABCDE\s*EXCEPTION\s*5_1\s*ABCDE\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_3\s*EXCEPTION\s*2_1\s*ABCDE\s*EXCEPTION\s*3_2\s*ABCDE\s*EXCEPTION\s*4_1\s*ABCDE\s*EXCEPTION\s*5_1\s*ABCDE\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_3\s*EXCEPTION\s*2_1\s*ABCDE\s*EXCEPTION\s*3_1\s*ABCDE\s*EXCEPTION\s*4_1\s*ABCDE\s*EXCEPTION\s*5_1\s*ABCDE\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_3\s*EXCEPTION\s*2_1\s*ABCDE\s*EXCEPTION\s*3_1\s*ABCDE\s*EXCEPTION\s*4_1\s*ABCDE\s*EXCEPTION\s*5_1\s*ABCDE\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_3\s*EXCEPTION\s*2_1\s*ABCDE\s*EXCEPTION\s*3_1\s*ABCDE\s*EXCEPTION\s*4_1\s*ABCDE\s*EXCEPTION\s*5_1\s*ABCDE\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0035-rt-String-GetBytesExceptionTest/StringGetBytesExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0035-rt-String-GetBytesExceptionTest/StringGetBytesExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..250d63fb5b22e8069760f4bec848ff3bc4d6455a --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0035-rt-String-GetBytesExceptionTest/StringGetBytesExceptionTest.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringGetBytesExceptionTest.java + * -@TestCaseName: Test Exception in String Method: getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: dst is null, 0 < srcBegin < srcEnd, srcEnd < instance.length, dstBegin > 0. + * -#step3: Test method getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin), check NullPointerException is + * thrown, check dst is not replaced. + * -#step4: Create Parameters: dst.length > 0, data.element is normal byte, srcBegin < 0, 0 < srcEnd < instance.length, + * 0 < dstBegin < dst.length. + * -#step5: Test method getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin), check + * StringIndexOutOfBoundsException is thrown, check dst is not replaced. + * -#step6: Create Parameters: dst.length > 0, data.element is normal byte, 0 < srcBegin < srcEnd, srcEnd < + * instance.length, 0 < dstBegin < dst.length, dstBegin + srcEnd - srcBegin > dst.length. + * -#step7: Test method getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin), check + * ArrayIndexOutOfBoundsException is thrown, check dst is not replaced. + * -#step8: Create Parameters: dst.length > 0, data.element is normal byte, srcBegin > srcEnd, 0 < srcEnd + * < instance.length, 0 < dstBegin < dst.length. + * -#step9: Test method getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin), check + * StringIndexOutOfBoundsException is thrown, check dst is not replaced. + * -#step10: Create Parameters: dst.length > 0, data.element is normal byte, 0 < srcBegin < srcEnd, srcEnd < + * instance.length, dstBegin < 0. + * -#step11: Test method getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin), check + * StringIndexOutOfBoundsException is thrown, check dst is not replaced. + * -#step12: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~11. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringGetBytesExceptionTest.java + * -@ExecuteClass: StringGetBytesExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringGetBytesExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringGetBytesExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringGetBytesExceptionTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + byte[] dst1_1 = null; + try { + str.getBytes(2, 5, dst1_1, 2); + String str_new = new String(dst1_1); + } catch (NullPointerException e1) { + System.out.println("EXCEPTION 1_1"); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 1_2"); + } + + byte[] dst1_2 = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + try { + str.getBytes(-1, 5, dst1_2, 2); + String str_new = new String(dst1_2); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 2_1"); + } + + // if (srcEnd > length()) ...throw new StringIndexOutOfBoundsException(this, srcEnd); + byte[] dst1_3 = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + try { + str.getBytes(2, 6, dst1_3, 2); + String str_new = new String(dst1_3); + } catch (ArrayIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 3_1"); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 3_2"); + } + + byte[] dst1_4 = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + try { + str.getBytes(4, 3, dst1_4, 2); + String str_new = new String(dst1_4); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 4_1"); + } + + byte[] dst1_5 = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + try { + str.getBytes(4, 3, dst1_5, -1); + String str_new = new String(dst1_5); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 5_1"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan EXCEPTION\s*1_1\s*EXCEPTION\s*2_1\s*EXCEPTION\s*4_1\s*EXCEPTION\s*5_1\s*EXCEPTION\s*1_1\s*EXCEPTION\s*2_1\s*EXCEPTION\s*4_1\s*EXCEPTION\s*5_1\s*EXCEPTION\s*1_1\s*EXCEPTION\s*2_1\s*EXCEPTION\s*4_1\s*EXCEPTION\s*5_1\s*EXCEPTION\s*1_2\s*EXCEPTION\s*2_1\s*EXCEPTION\s*3_2\s*EXCEPTION\s*4_1\s*EXCEPTION\s*5_1\s*EXCEPTION\s*1_2\s*EXCEPTION\s*2_1\s*EXCEPTION\s*3_2\s*EXCEPTION\s*4_1\s*EXCEPTION\s*5_1\s*EXCEPTION\s*1_1\s*EXCEPTION\s*2_1\s*EXCEPTION\s*4_1\s*EXCEPTION\s*5_1\s*EXCEPTION\s*1_1\s*EXCEPTION\s*2_1\s*EXCEPTION\s*4_1\s*EXCEPTION\s*5_1\s*EXCEPTION\s*1_1\s*EXCEPTION\s*2_1\s*EXCEPTION\s*4_1\s*EXCEPTION\s*5_1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0036-rt-String-SubstringStringIndexOutOfBoundsExceptionTest/StringSubstringStringIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0036-rt-String-SubstringStringIndexOutOfBoundsExceptionTest/StringSubstringStringIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d9dfff5f2e3839ea475a166c9932a54e093909c9 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0036-rt-String-SubstringStringIndexOutOfBoundsExceptionTest/StringSubstringStringIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringSubstringStringIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test StringIndexOutOfBoundsException in String Method: String substring(int beginIndex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: beginIndex range from -1 to max (max > instance.length). + * -#step3: Test method substring(int beginIndex), Check result is correctly. StringIndexOutOfBoundsException is thrown + * when beginIndex < 0 or beginIndex > instance.length. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringSubstringStringIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: StringSubstringStringIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringSubstringStringIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringSubstringStringIndexOutOfBoundsExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringSubstringStringIndexOutOfBoundsExceptionTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + for (int i = -1; i < 8; i++) { + try { + System.out.println("beginIndex= " + i); + String dst1_1 = str.substring(i); + System.out.println(dst1_1); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("StringIndexOutOfBounds 1_1"); + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan beginIndex\=\s*\-1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*0\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*1\s*wertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*2\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*3\s*rtyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*4\s*tyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*5\s*yuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*6\s*uiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*7\s*iop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*\-1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*0\s*\@\!\.\&\%\s*beginIndex\=\s*1\s*\@\!\.\&\%\s*beginIndex\=\s*2\s*\!\.\&\%\s*beginIndex\=\s*3\s*\.\&\%\s*beginIndex\=\s*4\s*\&\%\s*beginIndex\=\s*5\s*\%\s*beginIndex\=\s*6\s*beginIndex\=\s*7\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*\-1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*0\s*abc123\s*beginIndex\=\s*1\s*bc123\s*beginIndex\=\s*2\s*c123\s*beginIndex\=\s*3\s*123\s*beginIndex\=\s*4\s*23\s*beginIndex\=\s*5\s*3\s*beginIndex\=\s*6\s*beginIndex\=\s*7\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*\-1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*0\s*beginIndex\=\s*1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*2\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*3\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*4\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*5\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*6\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*7\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*\-1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*0\s*beginIndex\=\s*1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*2\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*3\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*4\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*5\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*6\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*7\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*\-1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*0\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*1\s*wertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*2\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*3\s*rtyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*4\s*tyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*5\s*yuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*6\s*uiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*7\s*iop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*beginIndex\=\s*\-1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*0\s*\@\!\.\&\%\s*beginIndex\=\s*1\s*\@\!\.\&\%\s*beginIndex\=\s*2\s*\!\.\&\%\s*beginIndex\=\s*3\s*\.\&\%\s*beginIndex\=\s*4\s*\&\%\s*beginIndex\=\s*5\s*\%\s*beginIndex\=\s*6\s*beginIndex\=\s*7\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*\-1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*0\s*abc123\s*beginIndex\=\s*1\s*bc123\s*beginIndex\=\s*2\s*c123\s*beginIndex\=\s*3\s*123\s*beginIndex\=\s*4\s*23\s*beginIndex\=\s*5\s*3\s*beginIndex\=\s*6\s*beginIndex\=\s*7\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*\-1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*0\s*beginIndex\=\s*1\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*2\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*3\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*4\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*5\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*6\s*StringIndexOutOfBounds\s*1_1\s*beginIndex\=\s*7\s*StringIndexOutOfBounds\s*1_1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0037-rt-String-SubstringIntIntExceptionTest/StringSubstringIntIntExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0037-rt-String-SubstringIntIntExceptionTest/StringSubstringIntIntExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..307fb543d9037620ed34a8e10d5a377450f29e43 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0037-rt-String-SubstringIntIntExceptionTest/StringSubstringIntIntExceptionTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringSubstringIntIntExceptionTest.java + * -@TestCaseName: Test StringIndexOutOfBoundsException in String Method: String substring(int beginIndex, + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * int endIndex). + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: beginIndex > 0, beginIndex < endIndex < instance.length. + * -#step3: Test Method substring(int beginIndex,int endIndex), check the result correctly, throws + * StringIndexOutOfBoundsException when beginIndex < 0 or beginIndex > instance.length or + * endIndex > instance.length. + * -#step4: Create Parameters: beginIndex < 0, 0 < endIndex < instance.length. + * -#step5: Test Method substring(int beginIndex,int endIndex), check StringIndexOutOfBoundsException is thrown. + * -#step6: Create Parameters: beginIndex > endIndex > 0. + * -#step7: Test Method substring(int beginIndex,int endIndex), check StringIndexOutOfBoundsException is thrown. + * -#step6: Create Parameters: beginIndex > 0, instance.length < endIndex. + * -#step7: Test Method substring(int beginIndex,int endIndex), check StringIndexOutOfBoundsException is thrown. + * -#step8: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~7. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringSubstringIntIntExceptionTest.java + * -@ExecuteClass: StringSubstringIntIntExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringSubstringIntIntExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringSubstringIntIntExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringSubstringIntIntExceptionTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ " + + "ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%()*"); + String str1_3 = new String("abc123abc"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZ" + + "XCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + + test(str1_1); + test(str1_2); + test(str1_3); + + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + try { + System.out.println(str.substring(2, 6)); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 1_1"); + } + + try { + System.out.println(str.substring(-1, 6)); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 1_2"); + } + + try { + System.out.println(str.substring(2, 1)); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 1_3"); + } + + try { + System.out.println(str.substring(2, 9)); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("EXCEPTION 1_4"); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan erty\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_3\s*ertyuio\s*\!\.\&\%\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_3\s*\!\.\&\%\(\)\*\s*c123\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_3\s*c123abc\s*erty\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_3\s*ertyuio\s*\!\.\&\%\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_3\s*EXCEPTION\s*1_4\s*c123\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_3\s*c123ABC\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0038-rt-String-SubSequenceIndexOutOfBoundsExceptionTest/StringSubSequenceIndexOutOfBoundsExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0038-rt-String-SubSequenceIndexOutOfBoundsExceptionTest/StringSubSequenceIndexOutOfBoundsExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..87002c3a28f8caca4d1c70ad82345a77d60ba5f0 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0038-rt-String-SubSequenceIndexOutOfBoundsExceptionTest/StringSubSequenceIndexOutOfBoundsExceptionTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringSubSequenceIndexOutOfBoundsExceptionTest.java + * -@TestCaseName: Test IndexOutOfBoundsException in String Method: CharSequence subSequence(int beginIndex, + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * int endIndex). + * -@Brief: + * -#step1: Create String instance by new String(String str1) and not new. + * -#step2: Create Parameters: beginIndex < 0, 0 < endIndex < instance.length. + * -#step3: Test Method subSequence(int beginIndex, int endIndex), check IndexOutOfBoundsException is thrown + * StringIndexOutOfBoundsException. + * -#step4: Create Parameters: 0 < beginIndex < instance.length, endIndex < 0. + * -#step5: Test Method subSequence(int beginIndex,int endIndex), check IndexOutOfBoundsException is thrown. + * -#step6: Create Parameters: beginIndex > endIndex > 0. + * -#step7: Test Method subSequence(int beginIndex,int endIndex), check IndexOutOfBoundsException is thrown. + * -#step6: Create Parameters: beginIndex > 0, instance.length < endIndex. + * -#step7: Test Method subSequence(int beginIndex,int endIndex), check IndexOutOfBoundsException is thrown. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringSubSequenceIndexOutOfBoundsExceptionTest.java + * -@ExecuteClass: StringSubSequenceIndexOutOfBoundsExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringSubSequenceIndexOutOfBoundsExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = StringSubSequenceIndexOutOfBoundsExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 95) { + result = 0; + } + return result; + } + + public static int StringSubSequenceIndexOutOfBoundsExceptionTest_1() { + int result1 = 4; /*STATUS_FAILED*/ + //IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string. + String str1_1 = new String("abc123"); + + try { + str1_1.subSequence(-2, 6); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + str1_1.subSequence(2, -6); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + str1_1.subSequence(2, 1); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + str1_1.subSequence(2, 10); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0039-rt-String-ReplaceNullPointerExceptionTest/StringReplaceNullPointerExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0039-rt-String-ReplaceNullPointerExceptionTest/StringReplaceNullPointerExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9d3e09025ab067e8c5cca8bb1724a4edc6e85086 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0039-rt-String-ReplaceNullPointerExceptionTest/StringReplaceNullPointerExceptionTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringReplaceNullPointerExceptionTest.java + * -@TestCaseName: Test NullPointerException in String Method:String replace(CharSequence target, + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * CharSequence replacement). + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: target = null, replacement is a special symbols. + * -#step3: Test method replace(CharSequence target, CharSequence replacement), NullPointerException is thrown. + * -#step4: Create Parameters: target is a letter, replacement = null. + * -#step5: Test method replace(CharSequence target, CharSequence replacement), NullPointerException is thrown. + * -#step6: Create Parameters: target is a letter, replacement is a letter. + * -#step7: Test method replace(CharSequence target, CharSequence replacement), the result is replaced correctly. + * -#step8: Change instance as One or more kinds of letters, numbers, special symbols/""/null to repeat step2~7. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringReplaceNullPointerExceptionTest.java + * -@ExecuteClass: StringReplaceNullPointerExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringReplaceNullPointerExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringReplaceNullPointerExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringReplaceNullPointerExceptionTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ " + + "ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ " + + "ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + String str2_5 = null; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + test(str2_5); + } + + private static void test(String str) { + String target = null; + try { + System.out.println(str.replace(target, "@")); + } catch (NullPointerException e1) { + System.out.println("EXCEPTION 1_1"); + } + + String replacement = null; + try { + System.out.println(str.replace("a", replacement)); + } catch (NullPointerException e2) { + System.out.println("EXCEPTION 1_2"); + } + + try { + System.out.println(str.replace("a", "@")); + } catch (NullPointerException e2) { + System.out.println("EXCEPTION 1_3"); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*qwertyuiop\{\}\[\]\\\|\@sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*\@\!\.\&\%\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*\@bc123\@bc\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*qwertyuiop\{\}\[\]\\\|\@sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*\@\!\.\&\%\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*\@bc123ABC\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_1\s*EXCEPTION\s*1_2\s*EXCEPTION\s*1_3\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0040-rt-String-ValueOfAndCopyValueOfExceptionTest/StringValueOfAndCopyValueOfExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0040-rt-String-ValueOfAndCopyValueOfExceptionTest/StringValueOfAndCopyValueOfExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..78f38e50b2cf9089a72f67d850a992db4feecc93 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0040-rt-String-ValueOfAndCopyValueOfExceptionTest/StringValueOfAndCopyValueOfExceptionTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfAndCopyValueOfExceptionTest.java + * -@TestCaseName: Test Exception in String Static Method: String valueOf(char[] data, int offset, int count)/String + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * copyValueOf(char[] data, int offset, int count). + * -@Brief: + * -#step1: Create char[] instance initialization by some letters. + * -#step2: Create Parameters: offset < 0, 0 < count < instance.length. + * -#step3: Test method valueOf(char[] data, int offset, int count), check IndexOutOfBoundsException is thrown. + * -#step4: Create Parameters: 0 =< offset < instance.length, count < 0. + * -#step5: Test method valueOf(char[] data, int offset, int count), check IndexOutOfBoundsException is thrown. + * -#step6: Create Parameters: 0 =< offset < instance.length, count > instance.length. + * -#step7: Test method valueOf(char[] data, int offset, int count), check IndexOutOfBoundsException is thrown. + * -#step8: Create Parameters: offset < 0, 0 < count < instance.length. + * -#step9: Test method copyValueOf(char[] data, int offset, int count), check IndexOutOfBoundsException is thrown. + * -#step10: Create Parameters: 0 =< offset < instance.length, count < 0. + * -#step11: Test method copyValueOf(char[] data, int offset, int count), check IndexOutOfBoundsException is thrown. + * -#step12: Create Parameters: 0 =< offset < instance.length, count > instance.length. + * -#step13: Test method copyValueOf(char[] data, int offset, int count), check IndexOutOfBoundsException is thrown. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfAndCopyValueOfExceptionTest.java + * -@ExecuteClass: StringValueOfAndCopyValueOfExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfAndCopyValueOfExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + result = StringValueOfAndCopyValueOfExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 93) { + result = 0; + } + return result; + } + + public static int StringValueOfAndCopyValueOfExceptionTest_1() { + int result1 = 2; /* STATUS_Success */ + + char[] ch1_1 = {'a', 'b', 'c', '1', '2', '3'}; + /* IndexOutOfBoundsException - if offset is negative, or count is negative, or offset+count is larger than + data.length */ + try { + String.valueOf(ch1_1, -1, 3); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String.valueOf(ch1_1, 1, -3); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String.valueOf(ch1_1, 1, 10); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String.copyValueOf(ch1_1, -1, 3); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String.copyValueOf(ch1_1, 1, -3); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + try { + String.copyValueOf(ch1_1, 1, 10); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0041-rt-String-GetClassTest/StringGetClassTest.java b/test/testsuite/ouroboros/string_test/RT0041-rt-String-GetClassTest/StringGetClassTest.java new file mode 100755 index 0000000000000000000000000000000000000000..97f94cbf002da40f62c3a6884e097412536c828a --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0041-rt-String-GetClassTest/StringGetClassTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringGetClassTest.java + * -@TestCaseName: Test Method Class getClass() of String. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method of getClass(), check the result the correctly. + * -#step3: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringGetClassTest.java + * -@ExecuteClass: StringGetClassTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringGetClassTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringGetClassTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringGetClassTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.getClass()); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan class\s*java\.lang\.String\s*class\s*java\.lang\.String\s*class\s*java\.lang\.String\s*class\s*java\.lang\.String\s*class\s*java\.lang\.String\s*class\s*java\.lang\.String\s*class\s*java\.lang\.String\s*class\s*java\.lang\.String\s*class\s*java\.lang\.String\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0042-rt-String-EqualsAndEqualsIgnoreCaseAndLengthTest/StringEqualsAndEqualsIgnoreCaseAndLengthTest.java b/test/testsuite/ouroboros/string_test/RT0042-rt-String-EqualsAndEqualsIgnoreCaseAndLengthTest/StringEqualsAndEqualsIgnoreCaseAndLengthTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fede1237570ef117398825b2a3e0ba8345638a64 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0042-rt-String-EqualsAndEqualsIgnoreCaseAndLengthTest/StringEqualsAndEqualsIgnoreCaseAndLengthTest.java @@ -0,0 +1,275 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringEqualsAndEqualsIgnoreCaseAndLengthTest.java + * -@TestCaseName: Test method boolean equals(Object anObject)/boolean equalsIgnoreCase(String anotherString)/ + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * int length() of String. + * -@Brief: + * -#case1 + * -#step1: Create two same String instance consists of special symbols. + * -#step2: Test method equals(Object anObject), check get result true. + * -#step3: Test method length() of one String, check get result correctly. + * -#case2 + * -#step1: Create two same String instance consists of letters, numbers ,special symbols. + * -#step2: Test method equals(Object anObject), check get result true. + * -#step3: Test method length() of one String, check get result correctly. + * -#case3 + * -#step1: Create two different String instance consists of letters, numbers ,special symbols, the diff is Uppercase + * and lowercase letters. + * -#step2: Test method equals(Object anObject), check get result false. + * -#step3: Test method equalsIgnoreCase(String anotherString), check get result true. + * -#case4 + * -#step1: Create two different String instance, one consists of letters, space, one consists of space. + * -#step2: Test method equals(Object anObject), check get result false. + * -#step3: Test method length() of one String, check get result correctly. + * -#case5 + * -#step1: Create two different String instance, one consists of letters, one consists of space. + * -#step2: Test method equals(Object anObject), check get result false. + * -#case6 + * -#step1: Create two different String instance, one consists of lowercase letters, one consists of Uppercase letters. + * -#step2: Test method equals(Object anObject), check get result false. + * -#step3: Test method equalsIgnoreCase(String anotherString), check get result true. + * -#case7 + * -#step1: Create two different String instance, one consists of letters, space, one has One more space than another. + * -#step2: Test method equals(Object anObject), check get result false. + * -#case8 + * -#step1: Create two different String instance, one is $, one is ¥. + * -#step2: Test method equals(Object anObject), check get result false. + * -#step3: Test method length() of "$", check get result correctly. + * -#step4: Test method length() of "¥", check get result correctly. + * -#case9 + * -#step1: Create two different String instance, one consists of letters and \n, one consists of letters and \t. + * -#step2: Test method equals(Object anObject), check get result false. + * -#step3: Test method length() of of one String, check get result correctly. + * -#case10 + * -#step1: Create two String instance consists of letters and numbers and special symbols. + * -#step2: Test method equals(Object anObject), two instance compare to Corresponding constant, check get result true. + * -#case11 + * -#step1: Create two same long String instance consists of letters and numbers and special symbols. + * -#step2: Test method equals(Object anObject), check get result true. + * -#step3: Test method length() of of one String, check get result correctly. + * -#case12 + * -#step1: Create two different long String instance consists of letters and numbers and special symbols. + * -#step2: Test method equals(Object anObject), check get result false. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringEqualsAndEqualsIgnoreCaseAndLengthTest.java + * -@ExecuteClass: StringEqualsAndEqualsIgnoreCaseAndLengthTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringEqualsAndEqualsIgnoreCaseAndLengthTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 3; /* STATUS_Failed */ + + result = StringEqualsAndEqualsIgnoreCaseAndLengthTest_1(); + if (result == 2 && processResult == 87) { + result = 0; + } + return result; + } + + public static int StringEqualsAndEqualsIgnoreCaseAndLengthTest_1() { + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + test8(); + test9(); + test10(); + test11(); + test12(); + return 2; + } + + public static int test_equals(String str1, String str2) { + if (str1.equals(str2)) { + return 1; // right result + } + return 30; // wrong result + } + + public static int test_not_equals(String str1, String str2) { + if (!str1.equals(str2)) { + return 1; // right result + } + return 30; // wrong result + } + + public static int test_equalsIgnoreCase(String str1, String str2) { + if (str1.equalsIgnoreCase(str2)) { + return 1; // right result + } + return 30; // wrong result + } + + public static int test_length(String str1, int a) { + if (str1.length() == a) { + return 1; // right result + } + return 30; // wrong result + } + + private static void test1() { + String str1_1 = "{"; + String str1_2 = "{"; + if (test_equals(str1_1, str1_2) == 1 && test_length(str1_1, 1) == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test2() { + String str2_1 = "{12ab"; + String str2_2 = "{12ab"; + if (test_equals(str2_1, str2_2) == 1 && test_length(str2_1, 5) == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test3() { + String str2_1 = "{12ab"; + String str2_3 = "{12AB"; + + if (test_equalsIgnoreCase(str2_1, str2_3) == 1 && test_not_equals(str2_1, str2_3) == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test4() { + String str3_1 = " abc "; + String str3_3 = " "; + + if (test_not_equals(str3_1, str3_3) == 1 && test_length(str3_1, 5) == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test5() { + String str3_2 = "null"; + String str3_3 = " "; + + if (test_not_equals(str3_2, str3_3) == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test6() { + String str3_2 = "null"; + String str3_4 = "NULL"; + + if (test_not_equals(str3_2, str3_4) == 1 && test_equalsIgnoreCase(str3_2, str3_4) == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test7() { + String str3_1 = " abc "; + String str3_5 = " abc"; + + if (test_not_equals(str3_1, str3_5) == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test8() { + String str4_1 = "$"; + String str4_2 = "¥"; + + if (test_not_equals(str4_1, str4_2) == 1 && test_length(str4_1, 1) == 1 && test_length(str4_2, 1) == 1) + { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test9() { + String str5_1 = "abc\n"; + String str5_2 = "abc\t"; + + if (test_not_equals(str5_1, str5_2) == 1 && test_length(str5_1, 4) == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test10() { + String str6_1 = "‘OR‘1’=’1"; + String str6_2 = "<‘script’>alter(“Test,Bom~~~”)<‘/script’>"; + + if (test_equals(str6_1, "‘OR‘1’=’1") == 1 && test_equals(str6_2, "<‘script’>alter(“Test,Bom~~~”)" + + "<‘/script’>") == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test11() { + String str7_1 = "``_+-=asdfadfqwerqwz!@##$%&#*^%^&(&*^()*&^*)^&%^~@#%@#$%^sdfgrw5646843131324fshst{}|[]]:,\\," + + "dkd d/.';,;'mmm:\"<>?;',./"; + String str7_2 = "``_+-=asdfadfqwerqwz!@##$%&#*^%^&(&*^()*&^*)^&%^~@#%@#$%^sdfgrw5646843131324fshst{}|[]]:,\\," + + "dkd d/.';,;'mmm:\"<>?;',./"; + + if (test_equals(str7_1, str7_2) == 1 && test_length(str7_1, 116) == 1) { + processResult--; + } else { + processResult -= 10; + } + } + + private static void test12() { + String str7_1 = "``_+-=asdfadfqwerqwz!@##$%&#*^%^&(&*^()*&^*)^&%^~@#%@#$%^sdfgrw5646843131324fshst{}|[]]:,\\," + + "dkd d/.';,;'mmm:\"<>?;',./"; + String str7_3 = "``_+-=asdfadfqwerqwz!@##$%&#*^%^&(&*^()*&^*)^&%^~@#%@#$%^sdfgrw5646843131324fshst{}|[]]:,\\," + + "dkd d/.';,;'mmm:\"<>?;',./123"; + + if (test_not_equals(str7_1, str7_3) == 1) { + processResult--; + } else { + processResult -= 10; + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0043-rt-String-NoParamConstructorTest/StringNoParamConstructorTest.java b/test/testsuite/ouroboros/string_test/RT0043-rt-String-NoParamConstructorTest/StringNoParamConstructorTest.java new file mode 100755 index 0000000000000000000000000000000000000000..74d0f41c3fce538cbf737269428911c31ba36a28 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0043-rt-String-NoParamConstructorTest/StringNoParamConstructorTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringNoParamConstructorTest.java + * -@TestCaseName: Test String Constructor: public String(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Test Constructor String(). + * -#step2: Check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringNoParamConstructorTest.java + * -@ExecuteClass: StringNoParamConstructorTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringNoParamConstructorTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringNoParamConstructorTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringNoParamConstructorTest_1() { + String str1 = new String(); + System.out.println(str1); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0044-rt-String-ConsStringTest/StringConsStringTest.java b/test/testsuite/ouroboros/string_test/RT0044-rt-String-ConsStringTest/StringConsStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..4cbdabe304739d7efa246e5d0c0ee2757d254a93 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0044-rt-String-ConsStringTest/StringConsStringTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsStringTest.java + * -@TestCaseName: Test String constructor: String(String original). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: original as One or more kinds of letters, numbers, special symbols. + * -#step2: Test constructor String(String original). + * -#step3: Check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsStringTest.java + * -@ExecuteClass: StringConsStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsStringTest_1() { + String str1_1 = new String("abc123"); + String str1 = new String(str1_1); + System.out.println(str1); + + String str1_2 = new String(" @!.&%"); + String str2 = new String(str1_2); + System.out.println(str2); + + String str1_3 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str3 = new String(str1_3); + System.out.println(str3); + + String str1_4 = new String(""); + String str4 = new String(str1_4); + System.out.println(str4); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*\@\!\.\&\%\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0045-rt-String-ConsCharTest/StringConsCharTest.java b/test/testsuite/ouroboros/string_test/RT0045-rt-String-ConsCharTest/StringConsCharTest.java new file mode 100755 index 0000000000000000000000000000000000000000..1e98ca820a57d379ce4ce3392c1d6b887f089385 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0045-rt-String-ConsCharTest/StringConsCharTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsCharTest.java + * -@TestCaseName: Test String constructor: String(char[] value). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: value.length > 0, value.element is letter and number. + * -#step2: Test constructor String(char[] value). + * -#step3: Check the return String is correctly. + * -#step4: Create Parameters: value.length = 0. + * -#step5: Test constructor String(char[] value). + * -#step6: Check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsCharTest.java + * -@ExecuteClass: StringConsCharTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsCharTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsCharTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsCharTest_1() { + char[] value1_1 = {'a', 'b', 'c', '1', '2', '3'}; + String str1 = new String(value1_1); + System.out.println(str1); + + char[] value1_2 = {}; + String str2 = new String(value1_2); + System.out.println(str2); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0046-rt-String-ConsCharIntIntTest/StringConsCharIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0046-rt-String-ConsCharIntIntTest/StringConsCharIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5e1d09c46726e9b1cb09268b0c59f2c09ebc9d66 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0046-rt-String-ConsCharIntIntTest/StringConsCharIntIntTest.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsCharIntIntTest.java + * -@TestCaseName: Test String constructor: String(char[] value, int offset, int count). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: value.length > 0, value.element is letter and number. + * -#step2: Create Parameters: offset = 0, 0 < count < value.length. + * -#step3: Test Constructor String(char[] value, int offset, int count), check the return String is correctly. + * -#step4: Create Parameters: offset = 0, count = 0. + * -#step5: Test Constructor String(char[] value, int offset, int count), check the return String is correctly. + * -#step6: Create Parameters: offset = 0, count = value.length. + * -#step7: Test Constructor String(char[] value, int offset, int count), check the return String is correctly. + * -#step8: Create Parameters: offset = value.length -1, count = 1. + * -#step9: Test Constructor String(char[] value, int offset, int count), check the return String is correctly. + * -#step10: Create Parameters: offset = value.length -1, count = 0. + * -#step11: Test Constructor String(char[] value, int offset, int count), check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsCharIntIntTest.java + * -@ExecuteClass: StringConsCharIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsCharIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsCharIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsCharIntIntTest_1() { + char[] value1_1 = {'a', 'b', 'c', '1', '2', '3'}; + String str1 = new String(value1_1, 0, 3); + String str1_1 = new String(value1_1, 0, 0); + String str1_2 = new String(value1_1, 0, 6); + String str1_3 = new String(value1_1, 5, 1); + String str1_4 = new String(value1_1, 5, 0); + System.out.println(str1); + System.out.println(str1_1); + System.out.println(str1_2); + System.out.println(str1_3); + System.out.println(str1_4); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc\s*abc123\s*3\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0047-rt-String-ConsIntsIntIntTest/StringConsIntsIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0047-rt-String-ConsIntsIntIntTest/StringConsIntsIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c02cb54def97e8e4a99c4d990a3651ed7d047711 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0047-rt-String-ConsIntsIntIntTest/StringConsIntsIntIntTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsIntsIntIntTest.java + * -@TestCaseName: Test String constructor: String(int[] codePoints, int offset, int count). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: codePoints.length > 0, value.element is Decimal number. + * -#step2: Create Parameters: offset = 0, count = codePoints.length. + * -#step3: Test method String(int[] codePoints, int offset, int count), check the return String is correctly. + * -#step4: Create Parameters: offset = codePoints.length - 1, count = 1. + * -#step5: Test method String(int[] codePoints, int offset, int count), check the return String is correctly. + * -#step6: Create Parameters: offset = codePoints.length - 1, count = 0. + * -#step7: Test method String(int[] codePoints, int offset, int count), check the return String is correctly. + * -#step8: Create Parameters: codePoints.length > 0, value.element is Hexadecimal number. + * -#step9: Create Parameters: offset = 0, count = codePoints.length. + * -#step10: Test method String(int[] codePoints, int offset, int count), check the return String is correctly. + * -#step11: Create Parameters: offset = codePoints.length - 1, count = 1. + * -#step12: Test method String(int[] codePoints, int offset, int count), check the return String is correctly. + * -#step13: Create Parameters: offset = codePoints.length - 1, count = 0. + * -#step14: Test method String(int[] codePoints, int offset, int count), check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsIntsIntIntTest.java + * -@ExecuteClass: StringConsIntsIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsIntsIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsIntsIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsIntsIntIntTest_1() { + int[] charIntArray1_1 = new int[]{97, 98, 99, 49, 50, 51}; + String str1_1 = new String(charIntArray1_1, 0, charIntArray1_1.length); + String str1_2 = new String(charIntArray1_1, charIntArray1_1.length - 1, 1); + String str1_3 = new String(charIntArray1_1, charIntArray1_1.length - 1, 0); + System.out.println(str1_1); + System.out.println(str1_2); + System.out.println(str1_3); + + int[] charIntArray2_1 = new int[]{0x61, 0x62, 0x63, 0x31, 0x32, 0x33}; + String str2_1 = new String(charIntArray2_1, 0, charIntArray2_1.length); + String str2_2 = new String(charIntArray2_1, charIntArray2_1.length - 1, 1); + String str2_3 = new String(charIntArray2_1, charIntArray2_1.length - 1, 0); + System.out.println(str2_1); + System.out.println(str2_2); + System.out.println(str2_3); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*3\s*abc123\s*3\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0048-rt-String-ConsBytesIntTest/StringConsBytesIntTest.java b/test/testsuite/ouroboros/string_test/RT0048-rt-String-ConsBytesIntTest/StringConsBytesIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..eaac742e73b92b21c9d8fd136c3f512730669d06 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0048-rt-String-ConsBytesIntTest/StringConsBytesIntTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsBytesIntTest.java + * -@TestCaseName: Test String constructor: String(byte[] ascii, int hibyte). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: ascii.length > 0, ascii.element is ascii number. + * -#step2: Create Parameters: hibyte = 0, Test constructor String(byte[] ascii, int hibyte). + * -#step3: Test constructor String(byte[] ascii). + * -#step4: Check the two constructor result is same or not. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsBytesIntTest.java + * -@ExecuteClass: StringConsBytesIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsBytesIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsBytesIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsBytesIntTest_1() { + byte[] ascii1_1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + String str1 = new String(ascii1_1, 0); + String str0 = new String(ascii1_1); + System.out.println(str0); + System.out.println(str1); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*abc123\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0049-rt-String-ConsBytesIntIntStringTest/StringConsBytesIntIntStringTest.java b/test/testsuite/ouroboros/string_test/RT0049-rt-String-ConsBytesIntIntStringTest/StringConsBytesIntIntStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..26e7b6e9be4e30d54a9b4834d485634981bba0a5 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0049-rt-String-ConsBytesIntIntStringTest/StringConsBytesIntIntStringTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsBytesIntIntStringTest.java + * -@TestCaseName: Test String constructor: String(byte[] bytes, int offset, int length, String charsetName). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: bytes.length > 0, bytes.element is byte number. + * -#step2: Create Parameters: offset = 0, 0 < length < bytes.length, charsetName is Charset name. + * -#step3: Test String(byte[] bytes, int offset, int length, String charsetName), Check the return String is correctly. + * -#step4: Create Parameters: offset = 0, length = bytes.length, charsetName is Charset name. + * -#step5: Test String(byte[] bytes, int offset, int length, String charsetName), Check the return String is correctly. + * -#step6: Create Parameters: offset = 0, length = 0, charsetName is Charset name. + * -#step7: Test String(byte[] bytes, int offset, int length, String charsetName), Check the return String is correctly. + * -#step8: Create Parameters: offset = bytes.length - 1, length = 1, charsetName is Charset name. + * -#step9: Test String(byte[] bytes, int offset, int length, String charsetName), Check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsBytesIntIntStringTest.java + * -@ExecuteClass: StringConsBytesIntIntStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; + + +public class StringConsBytesIntIntStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsBytesIntIntStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsBytesIntIntStringTest_1() throws UnsupportedEncodingException { + byte[] str1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + String str1_1 = new String(str1, 0, 3, "ASCII"); + String str1_2 = new String(str1, 0, 6, "ASCII"); + String str1_3 = new String(str1, 0, 0, "ASCII"); + String str1_4 = new String(str1, 5, 1, "ASCII"); + System.out.println(str1_1); + System.out.println(str1_2); + System.out.println(str1_3); + System.out.println(str1_4); + } +} + + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc\s*abc123\s*3\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0050-rt-String-CosBytesIntIntCharsetTest/StringCosBytesIntIntCharsetTest.java b/test/testsuite/ouroboros/string_test/RT0050-rt-String-CosBytesIntIntCharsetTest/StringCosBytesIntIntCharsetTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ce3a74b2cc1ff9ad90671c011389ea7d51c88324 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0050-rt-String-CosBytesIntIntCharsetTest/StringCosBytesIntIntCharsetTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCosBytesIntIntCharsetTest.java + * -@TestCaseName: String constructor: String(byte[] bytes, int offset, int length, Charset charset). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: bytes.length > 0, bytes.element is byte number. + * -#step2: Create Parameters: 0 =< offset < bytes.length, 0 =< length < bytes.length, charset like ASCII.charset. + * -#step3: Test String(byte[] bytes, int offset, int length, Charset charset), check the return String is correctly. + * -#step4: Create Parameters: offset = 0, length = bytes.length, charset like ASCII.charset. + * -#step5: Test String(byte[] bytes, int offset, int length, Charset charset), Check the return String is correctly. + * -#step6: Create Parameters: offset = 0, length = 0, charset like ASCII.charset. + * -#step7: Test String(byte[] bytes, int offset, int length, Charset charset), Check the return String is correctly. + * -#step8: Create Parameters: offset = bytes.length - 1, length = 1, charset like ASCII.charset. + * -#step9: Test String(byte[] bytes, int offset, int length, Charset charset), Check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCosBytesIntIntCharsetTest.java + * -@ExecuteClass: StringCosBytesIntIntCharsetTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; + +public class StringCosBytesIntIntCharsetTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCosBytesIntIntCharsetTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCosBytesIntIntCharsetTest_1() throws UnsupportedEncodingException { + byte[] str1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + String str1_1 = new String(str1, 3, 3, Charset.forName("ASCII")); + String str1_2 = new String(str1, 0, 6, Charset.forName("ASCII")); + String str1_3 = new String(str1, 0, 0, Charset.forName("ASCII")); + String str1_4 = new String(str1, 5, 1, Charset.forName("ASCII")); + System.out.println(str1_1); + System.out.println(str1_2); + System.out.println(str1_3); + System.out.println(str1_4); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 123\s*abc123\s*3\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0051-rt-String-ConsBytesStringTest/StringConsBytesStringTest.java b/test/testsuite/ouroboros/string_test/RT0051-rt-String-ConsBytesStringTest/StringConsBytesStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..19ae2354aa487e0cbd609c9d5497223759c52941 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0051-rt-String-ConsBytesStringTest/StringConsBytesStringTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsBytesStringTest.java + * -@TestCaseName: Test String constructor: String(byte[] bytes, String charsetName). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: bytes.length > 0, bytes.element is byte number, charsetName is a Charset name. + * -#step2: Test constructor String(byte[] bytes, String charsetName). + * -#step3: Check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsBytesStringTest.java + * -@ExecuteClass: StringConsBytesStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; + + +public class StringConsBytesStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsBytesStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsBytesStringTest_1() throws UnsupportedEncodingException { + byte[] str1_1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + String str1 = new String(str1_1, "ASCII"); + System.out.println(str1); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0052-rt-String-ConsBytesCharsetTest/StringConsBytesCharsetTest.java b/test/testsuite/ouroboros/string_test/RT0052-rt-String-ConsBytesCharsetTest/StringConsBytesCharsetTest.java new file mode 100755 index 0000000000000000000000000000000000000000..dc0136f4b48f72ab2f7e16506133297bfc34875f --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0052-rt-String-ConsBytesCharsetTest/StringConsBytesCharsetTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsBytesCharsetTest.java + * -@TestCaseName: Test String constructor: String(byte[] bytes, Charset charset). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: bytes.length > 0, bytes.element is byte number. charset like ASCII.charset. + * -#step2: Test constructor: String(byte[] bytes, Charset charset). + * -#step3: Check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsBytesCharsetTest.java + * -@ExecuteClass: StringConsBytesCharsetTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.nio.charset.Charset; + + +public class StringConsBytesCharsetTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsBytesCharsetTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsBytesCharsetTest_1() { + byte[] str1_1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + String str1 = new String(str1_1, Charset.forName("ASCII")); + System.out.println(str1); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0053-rt-String-ConsBytesIntIntTest/StringConsBytesIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0053-rt-String-ConsBytesIntIntTest/StringConsBytesIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..faf97aab3ff410d6aa714871275e95e07d2a2b42 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0053-rt-String-ConsBytesIntIntTest/StringConsBytesIntIntTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsBytesIntIntTest.java + * -@TestCaseName: String constructor: String(byte[] bytes, int offset, int length). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: bytes.length > 0, bytes.element is byte number + * -#step2: Create Parameters: 0 =< offset < bytes.length, 0 =< length < bytes.length - offset. + * -#step3: Test constructor String(byte[] bytes, int offset, int length), check the return String is correctly. + * -#step4: Create Parameters: offset = 0, length = bytes.length. + * -#step5: Test constructor String(byte[] bytes, int offset, int length), check the return String is correctly. + * -#step6: Create Parameters: offset = 0, length = 0. + * -#step7: Test constructor String(byte[] bytes, int offset, int length), check the return String is correctly. + * -#step8: Create Parameters: offset = bytes.length - 1, length = 1. + * -#step9: Test constructor String(byte[] bytes, int offset, int length), check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsBytesIntIntTest.java + * -@ExecuteClass: StringConsBytesIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsBytesIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsBytesIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsBytesIntIntTest_1() { + byte[] str1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + String str1_1 = new String(str1, 3, 3); + String str1_2 = new String(str1, 0, 6); + String str1_3 = new String(str1, 0, 0); + String str1_4 = new String(str1, 5, 1); + System.out.println(str1_1); + System.out.println(str1_2); + System.out.println(str1_3); + System.out.println(str1_4); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 123\s*abc123\s*3\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0054-rt-String-ConsBytesTest/StringConsBytesTest.java b/test/testsuite/ouroboros/string_test/RT0054-rt-String-ConsBytesTest/StringConsBytesTest.java new file mode 100755 index 0000000000000000000000000000000000000000..930c166f845b543b0685b8c973d9011f4f461526 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0054-rt-String-ConsBytesTest/StringConsBytesTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsBytesTest.java + * -@TestCaseName: Test String constructor: String(byte bytes[]). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: bytes.length > 0, bytes.element is Hexadecimal number. + * -#step2: Test constructor String(byte bytes[]). + * -#step3: Check the return String is correctly. + * -#step4: Create Parameters: bytes.length > 0, bytes.element is Decimal number. + * -#step5: Test constructor String(byte bytes[]). + * -#step6: Check the return String is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsBytesTest.java + * -@ExecuteClass: StringConsBytesTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsBytesTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsBytesTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsBytesTest_1() { + byte[] str1_1 = new byte[]{(byte) 0x61, (byte) 0x62, (byte) 0x63, (byte) 0x31, (byte) 0x32, (byte) 0x33}; + String str1 = new String(str1_1); + byte[] str1_2 = new byte[]{97, 98, 99, 49, 50, 51}; + String str1_3 = new String(str1_2); + + System.out.println(str1); + System.out.println(str1_3); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*abc123\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0055-rt-String-ConsStringBufferTest/StringConsStringBufferTest.java b/test/testsuite/ouroboros/string_test/RT0055-rt-String-ConsStringBufferTest/StringConsStringBufferTest.java new file mode 100755 index 0000000000000000000000000000000000000000..11ed69cebbc0465396cc4346fd27c7228a0ed0fa --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0055-rt-String-ConsStringBufferTest/StringConsStringBufferTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsStringBufferTest.java + * -@TestCaseName: Test String constructor: String(StringBuffer buffer). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String1 by "String" + "String" + "String". + * -#step2: Create String2 by str2_1 + str2_2 + str2_3. + * -#step3: Create Parameters: buffer by new StringBuffer(String buffer).append(String str). + * -#step4: Test constructor String(StringBuffer buffer). + * -#step5: check return result is correctly as same as String1 and String2. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsStringBufferTest.java + * -@ExecuteClass: StringConsStringBufferTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsStringBufferTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsStringBufferTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsStringBufferTest_1() { + String str1 = "These " + "are " + "abcdefghijklmnopqrstuvwxyz"; + String str2_1 = "These "; + String str2_2 = "are "; + String str2_3 = "abcdefghijklmnopqrstuvwxyz"; + String str2 = str2_1 + str2_2 + str2_3; + StringBuffer str_b_1 = new StringBuffer("These ").append("are ").append("abcdefghijklmnopqrstuvwxyz"); + String str3 = new String(str_b_1); + System.out.println(str1); + System.out.println(str2); + System.out.println(str3); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan These\s*are\s*abcdefghijklmnopqrstuvwxyz\s*These\s*are\s*abcdefghijklmnopqrstuvwxyz\s*These\s*are\s*abcdefghijklmnopqrstuvwxyz\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0056-rt-String-ConsStringBuilderTest/StringConsStringBuilderTest.java b/test/testsuite/ouroboros/string_test/RT0056-rt-String-ConsStringBuilderTest/StringConsStringBuilderTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d2a8178a0877a2845cd6b4fc06b2027158d6b548 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0056-rt-String-ConsStringBuilderTest/StringConsStringBuilderTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConsStringBuilderTest.java + * -@TestCaseName: Test String constructor: String(StringBuilder builder). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String1 by "String" + "String" + "String". + * -#step2: Create String2 by str2_1 + str2_2 + str2_3. + * -#step3: Create Parameters: builder by constructor new StringBuilder(String builder). + * -#step4: Test constructor String(StringBuilder builder). + * -#step5: check return result is correctly as same as String1 and String2. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConsStringBuilderTest.java + * -@ExecuteClass: StringConsStringBuilderTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConsStringBuilderTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConsStringBuilderTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConsStringBuilderTest_1() { + String str1 = "These " + "are " + "abcdefghijklmnopqrstuvwxyz"; + String str2_1 = "These "; + String str2_2 = "are "; + String str2_3 = "abcdefghijklmnopqrstuvwxyz"; + String str2 = str2_1 + str2_2 + str2_3; + StringBuilder str_b_1 = new StringBuilder("These ").append("are ").append("abcdefghijklmnopqrstuvwxyz"); + String str3 = new String(str_b_1); + System.out.println(str1); + System.out.println(str2); + System.out.println(str3); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan These\s*are\s*abcdefghijklmnopqrstuvwxyz\s*These\s*are\s*abcdefghijklmnopqrstuvwxyz\s*These\s*are\s*abcdefghijklmnopqrstuvwxyz\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0057-rt-String-LengthTest/StringLengthTest.java b/test/testsuite/ouroboros/string_test/RT0057-rt-String-LengthTest/StringLengthTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9820ffaf63db1f6e41a22ff71ac8a0e072506614 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0057-rt-String-LengthTest/StringLengthTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringLengthTest.java + * -@TestCaseName: Test String Method: int length(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method length(), check the return length is correctly. + * -#step3: judge String stance is null/empty/"" or not. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringLengthTest.java + * -@ExecuteClass: StringLengthTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringLengthTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringLengthTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringLengthTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + int strLength = str1_1.length(); + System.out.println(strLength); + test(str1_1); + + System.out.println(str1_2.length()); + test(str1_2); + + System.out.println(str1_3.length()); + test(str1_3); + + System.out.println(str1_4.length()); + test(str1_4); + + System.out.println(str1_5.length()); + test(str1_5); + + System.out.println(str2_1.length()); + test(str2_1); + + System.out.println(str2_2.length()); + test(str2_2); + + System.out.println(str2_3.length()); + test(str2_3); + + System.out.println(str2_4.length()); + test(str2_4); + } + + private static void test(String str) { + if (str == null) { + System.out.println(str + " is:null"); + } + if (str.isEmpty()) { + System.out.println(str + " is:isEmpty"); + } + if (str.equals("")) { + System.out.println(str + " is:\"\""); + } + System.out.println("*****"); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 99\s*\*\*\*\*\*\s*6\s*\*\*\*\*\*\s*6\s*\*\*\*\*\*\s*0\s*is\:isEmpty\s*is\:\"\"\s*\*\*\*\*\*\s*0\s*is\:isEmpty\s*is\:\"\"\s*\*\*\*\*\*\s*99\s*\*\*\*\*\*\s*6\s*\*\*\*\*\*\s*6\s*\*\*\*\*\*\s*0\s*is\:isEmpty\s*is\:\"\"\s*\*\*\*\*\*\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0058-rt-String-IsEmptyTest/StringIsEmptyTest.java b/test/testsuite/ouroboros/string_test/RT0058-rt-String-IsEmptyTest/StringIsEmptyTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0a6957d3ab9e7385bd6721225ba535b6af6f26c4 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0058-rt-String-IsEmptyTest/StringIsEmptyTest.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringIsEmptyTest.java + * -@TestCaseName: Test String Method: boolean isEmpty(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method isEmpty(), check the return value is correctly. + * -#step3: judge String stance is null/empty/"" or not. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringIsEmptyTest.java + * -@ExecuteClass: StringIsEmptyTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringIsEmptyTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringIsEmptyTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringIsEmptyTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + System.out.println(str1_1.isEmpty()); + test(str1_1); + + System.out.println(str1_2.isEmpty()); + test(str1_2); + + System.out.println(str1_3.isEmpty()); + test(str1_3); + + System.out.println(str1_4.isEmpty()); + test(str1_4); + + System.out.println(str1_5.isEmpty()); + test(str1_5); + + System.out.println(str2_1.isEmpty()); + test(str2_1); + + System.out.println(str2_2.isEmpty()); + test(str2_2); + + System.out.println(str2_3.isEmpty()); + test(str2_3); + + System.out.println(str2_4.isEmpty()); + test(str2_4); + } + + private static void test(String str) { + if (str == null) { + System.out.println(str + " is:null"); + } + if (str.isEmpty()) { + System.out.println(str + " is:isEmpty"); + } + if (str.equals("")) { + System.out.println(str + " is:\"\""); + } + System.out.println("*****"); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan false\s*\*\*\*\*\*\s*false\s*\*\*\*\*\*\s*false\s*\*\*\*\*\*\s*true\s*is\:isEmpty\s*is\:\"\"\s*\*\*\*\*\*\s*true\s*is\:isEmpty\s*is\:\"\"\s*\*\*\*\*\*\s*false\s*\*\*\*\*\*\s*false\s*\*\*\*\*\*\s*false\s*\*\*\*\*\*\s*true\s*is\:isEmpty\s*is\:\"\"\s*\*\*\*\*\*\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0059-rt-String-CharAtTest/StringCharAtTest.java b/test/testsuite/ouroboros/string_test/RT0059-rt-String-CharAtTest/StringCharAtTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7d67db1919528e03dacd8f5a1c69c21e21d505a0 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0059-rt-String-CharAtTest/StringCharAtTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCharAtTest.java + * -@TestCaseName: String Method: char charAt(int index). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: instance.length > index >= 0, index cover boundary value. + * -#step3: Test method charAt(int index), check the return length is correctly. + * -#step4: judge String stance is null/empty/"" or not. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCharAtTest.java + * -@ExecuteClass: StringCharAtTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCharAtTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCharAtTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCharAtTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test1(str1_1); + test(str1_1); + + test1(str1_2); + test(str1_2); + + test1(str1_3); + test(str1_3); + + test(str1_4); + test(str1_5); + + test1(str2_1); + test(str2_1); + + test1(str2_2); + test(str2_2); + + test1(str2_3); + test(str2_3); + + test(str2_4); + } + + private static void test(String str) { + if (str == null) { + System.out.println(str + " is:null"); + } + if (str.isEmpty()) { + System.out.println(str + " is:isEmpty"); + } + if (str.equals("")) { + System.out.println(str + " is:\"\""); + } + System.out.println("*****"); + } + + private static void test1(String str) { + char ch = str.charAt(0); + System.out.println(ch); + System.out.println(str.charAt(str.length() - 1)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan q\s*6\s*\*\*\*\*\*\s*\%\s*\*\*\*\*\*\s*a\s*3\s*\*\*\*\*\*\s*is\:isEmpty\s*is\:\"\"\s*\*\*\*\*\*\s*is\:isEmpty\s*is\:\"\"\s*\*\*\*\*\*\s*q\s*6\s*\*\*\*\*\*\s*\%\s*\*\*\*\*\*\s*a\s*3\s*\*\*\*\*\*\s*is\:isEmpty\s*is\:\"\"\s*\*\*\*\*\*\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0060-rt-String-CodePointAtTest/StringCodePointAtTest.java b/test/testsuite/ouroboros/string_test/RT0060-rt-String-CodePointAtTest/StringCodePointAtTest.java new file mode 100755 index 0000000000000000000000000000000000000000..dc4e71ad45690b5d41cf3c5b1ed894b4603f12cb --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0060-rt-String-CodePointAtTest/StringCodePointAtTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCodePointAtTest.java + * -@TestCaseName: Test String Method: int codePointAt(int index). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: index range from 0 to instance.length - 1. + * -#step3: Test method codePointAt(int index), check the return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCodePointAtTest.java + * -@ExecuteClass: StringCodePointAtTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCodePointAtTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCodePointAtTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCodePointAtTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + int codePoint = 0; + for (int i = 0; i < 6; i++) { + try { + codePoint = str.codePointAt(i); + System.out.println("i=" + i + " " + "codePointAt=" + codePoint); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("codePointAt(): " + i + "out of length"); + } finally { + try { + System.out.println(str.charAt(i) + " Unicode is" + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " out of length"); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan i\=0\s*codePointAt\=113\s*q\s*Unicode\s*is\:113\s*i\=1\s*codePointAt\=119\s*w\s*Unicode\s*is\:119\s*i\=2\s*codePointAt\=101\s*e\s*Unicode\s*is\:101\s*i\=3\s*codePointAt\=114\s*r\s*Unicode\s*is\:114\s*i\=4\s*codePointAt\=116\s*t\s*Unicode\s*is\:116\s*i\=5\s*codePointAt\=121\s*y\s*Unicode\s*is\:121\s*i\=0\s*codePointAt\=32\s*Unicode\s*is\:32\s*i\=1\s*codePointAt\=64\s*\@\s*Unicode\s*is\:64\s*i\=2\s*codePointAt\=33\s*\!\s*Unicode\s*is\:33\s*i\=3\s*codePointAt\=46\s*\.\s*Unicode\s*is\:46\s*i\=4\s*codePointAt\=38\s*\&\s*Unicode\s*is\:38\s*i\=5\s*codePointAt\=37\s*\%\s*Unicode\s*is\:37\s*i\=0\s*codePointAt\=97\s*a\s*Unicode\s*is\:97\s*i\=1\s*codePointAt\=98\s*b\s*Unicode\s*is\:98\s*i\=2\s*codePointAt\=99\s*c\s*Unicode\s*is\:99\s*i\=3\s*codePointAt\=49\s*1\s*Unicode\s*is\:49\s*i\=4\s*codePointAt\=50\s*2\s*Unicode\s*is\:50\s*i\=5\s*codePointAt\=51\s*3\s*Unicode\s*is\:51\s*i\=0\s*codePointAt\=113\s*q\s*Unicode\s*is\:113\s*i\=1\s*codePointAt\=119\s*w\s*Unicode\s*is\:119\s*i\=2\s*codePointAt\=101\s*e\s*Unicode\s*is\:101\s*i\=3\s*codePointAt\=114\s*r\s*Unicode\s*is\:114\s*i\=4\s*codePointAt\=116\s*t\s*Unicode\s*is\:116\s*i\=5\s*codePointAt\=121\s*y\s*Unicode\s*is\:121\s*i\=0\s*codePointAt\=32\s*Unicode\s*is\:32\s*i\=1\s*codePointAt\=64\s*\@\s*Unicode\s*is\:64\s*i\=2\s*codePointAt\=33\s*\!\s*Unicode\s*is\:33\s*i\=3\s*codePointAt\=46\s*\.\s*Unicode\s*is\:46\s*i\=4\s*codePointAt\=38\s*\&\s*Unicode\s*is\:38\s*i\=5\s*codePointAt\=37\s*\%\s*Unicode\s*is\:37\s*i\=0\s*codePointAt\=97\s*a\s*Unicode\s*is\:97\s*i\=1\s*codePointAt\=98\s*b\s*Unicode\s*is\:98\s*i\=2\s*codePointAt\=99\s*c\s*Unicode\s*is\:99\s*i\=3\s*codePointAt\=49\s*1\s*Unicode\s*is\:49\s*i\=4\s*codePointAt\=50\s*2\s*Unicode\s*is\:50\s*i\=5\s*codePointAt\=51\s*3\s*Unicode\s*is\:51\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0061-rt-String-CodePointBeforeTest/StringCodePointBeforeTest.java b/test/testsuite/ouroboros/string_test/RT0061-rt-String-CodePointBeforeTest/StringCodePointBeforeTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3a9cd05784d840de60ee64e3c192ca2d264ac721 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0061-rt-String-CodePointBeforeTest/StringCodePointBeforeTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCodePointBeforeTest.java + * -@TestCaseName: Test String Method: int codePointBefore(int index). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: index range from 0 to instance.length - 1. + * -#step3: Test method codePointBefore(int index), check the return result is correctly. + * -#step4: check the String instance is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCodePointBeforeTest.java + * -@ExecuteClass: StringCodePointBeforeTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCodePointBeforeTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCodePointBeforeTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCodePointBeforeTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + int codePoint = 0; + for (int i = 1; i < 6; i++) { + try { + codePoint = str.codePointBefore(i); + System.out.println("i=" + i + " " + "codePointBefore=" + codePoint); + } catch (StringIndexOutOfBoundsException e1) { + System.out.println("codePointBefore(): " + i + " out of length"); + } finally { + try { + System.out.println(str.charAt(i) + " codePointBefore is" + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " out of length"); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan i\=1\s*codePointBefore\=113\s*w\s*codePointBefore\s*is\:113\s*i\=2\s*codePointBefore\=119\s*e\s*codePointBefore\s*is\:119\s*i\=3\s*codePointBefore\=101\s*r\s*codePointBefore\s*is\:101\s*i\=4\s*codePointBefore\=114\s*t\s*codePointBefore\s*is\:114\s*i\=5\s*codePointBefore\=116\s*y\s*codePointBefore\s*is\:116\s*i\=1\s*codePointBefore\=32\s*\@\s*codePointBefore\s*is\:32\s*i\=2\s*codePointBefore\=64\s*\!\s*codePointBefore\s*is\:64\s*i\=3\s*codePointBefore\=33\s*\.\s*codePointBefore\s*is\:33\s*i\=4\s*codePointBefore\=46\s*\&\s*codePointBefore\s*is\:46\s*i\=5\s*codePointBefore\=38\s*\%\s*codePointBefore\s*is\:38\s*i\=1\s*codePointBefore\=97\s*b\s*codePointBefore\s*is\:97\s*i\=2\s*codePointBefore\=98\s*c\s*codePointBefore\s*is\:98\s*i\=3\s*codePointBefore\=99\s*1\s*codePointBefore\s*is\:99\s*i\=4\s*codePointBefore\=49\s*2\s*codePointBefore\s*is\:49\s*i\=5\s*codePointBefore\=50\s*3\s*codePointBefore\s*is\:50\s*i\=1\s*codePointBefore\=113\s*w\s*codePointBefore\s*is\:113\s*i\=2\s*codePointBefore\=119\s*e\s*codePointBefore\s*is\:119\s*i\=3\s*codePointBefore\=101\s*r\s*codePointBefore\s*is\:101\s*i\=4\s*codePointBefore\=114\s*t\s*codePointBefore\s*is\:114\s*i\=5\s*codePointBefore\=116\s*y\s*codePointBefore\s*is\:116\s*i\=1\s*codePointBefore\=32\s*\@\s*codePointBefore\s*is\:32\s*i\=2\s*codePointBefore\=64\s*\!\s*codePointBefore\s*is\:64\s*i\=3\s*codePointBefore\=33\s*\.\s*codePointBefore\s*is\:33\s*i\=4\s*codePointBefore\=46\s*\&\s*codePointBefore\s*is\:46\s*i\=5\s*codePointBefore\=38\s*\%\s*codePointBefore\s*is\:38\s*i\=1\s*codePointBefore\=97\s*b\s*codePointBefore\s*is\:97\s*i\=2\s*codePointBefore\=98\s*c\s*codePointBefore\s*is\:98\s*i\=3\s*codePointBefore\=99\s*1\s*codePointBefore\s*is\:99\s*i\=4\s*codePointBefore\=49\s*2\s*codePointBefore\s*is\:49\s*i\=5\s*codePointBefore\=50\s*3\s*codePointBefore\s*is\:50\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0062-rt-String-CodePointCountTest/StringCodePointCountTest.java b/test/testsuite/ouroboros/string_test/RT0062-rt-String-CodePointCountTest/StringCodePointCountTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c965474f8802ed0693bd08348509273d7edff15b --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0062-rt-String-CodePointCountTest/StringCodePointCountTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCodePointCountTest.java + * -@TestCaseName: Test String Method: int codePointCount(int beginIndex, int endIndex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: beginIndex range from 0 to instance.length - 3, endIndex = beginIndex + 3. + * -#step3: Test method codePointCount(int beginIndex, int endIndex), check the return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCodePointCountTest.java + * -@ExecuteClass: StringCodePointCountTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCodePointCountTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCodePointCountTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCodePointCountTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + int codePoint = 0; + for (int i = 0; i < 4; i++) { + try { + codePoint = str.codePointCount(i, i + 3); + System.out.println("i=" + i + " " + "codePointCount=" + codePoint); + } catch (IndexOutOfBoundsException e1) { + System.out.println("codePointCount(): " + i + " out of length"); + } finally { + try { + System.out.println(str.charAt(i) + " codePointCount is " + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " out of length"); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan i\=0\s*codePointCount\=3\s*q\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*w\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*e\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*r\s*codePointCount\s*is\s*\:3\s*i\=0\s*codePointCount\=3\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*\@\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*\!\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*\.\s*codePointCount\s*is\s*\:3\s*i\=0\s*codePointCount\=3\s*a\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*b\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*c\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*1\s*codePointCount\s*is\s*\:3\s*i\=0\s*codePointCount\=3\s*q\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*w\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*e\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*r\s*codePointCount\s*is\s*\:3\s*i\=0\s*codePointCount\=3\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*\@\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*\!\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*\.\s*codePointCount\s*is\s*\:3\s*i\=0\s*codePointCount\=3\s*a\s*codePointCount\s*is\s*\:3\s*i\=1\s*codePointCount\=3\s*b\s*codePointCount\s*is\s*\:3\s*i\=2\s*codePointCount\=3\s*c\s*codePointCount\s*is\s*\:3\s*i\=3\s*codePointCount\=3\s*1\s*codePointCount\s*is\s*\:3\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0063-rt-String-OffsetByCodePointsTest/StringOffsetByCodePointsTest.java b/test/testsuite/ouroboros/string_test/RT0063-rt-String-OffsetByCodePointsTest/StringOffsetByCodePointsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..52acfa141c422620b42a2bced51c3350dc514cb5 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0063-rt-String-OffsetByCodePointsTest/StringOffsetByCodePointsTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringOffsetByCodePointsTest.java + * -@TestCaseName: Test String Method: int offsetByCodePoints(int index, int codePointOffset). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: index range from 0 to instance.length - 5, codePointOffset = index + 3. + * -#step3: Test method offsetByCodePoints(int index, int codePointOffset), check the return result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringOffsetByCodePointsTest.java + * -@ExecuteClass: StringOffsetByCodePointsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringOffsetByCodePointsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringOffsetByCodePointsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringOffsetByCodePointsTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + int codePoint = 0; + for (int i = 0; i < 2; i++) { + try { + codePoint = str.offsetByCodePoints(i, i + 3); + System.out.println("i=" + i + " " + "offsetByCodePoints=" + codePoint); + } catch (IndexOutOfBoundsException e1) { + System.out.println("offsetByCodePoints(): " + i + " out of length"); + } finally { + try { + System.out.println(str.charAt(i) + " offsetByCodePoints is " + ":" + codePoint); + } catch (StringIndexOutOfBoundsException e2) { + System.out.println("charAt(): " + i + " out of length"); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan i\=0\s*offsetByCodePoints\=3\s*q\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*w\s*offsetByCodePoints\s*is\s*\:5\s*i\=0\s*offsetByCodePoints\=3\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*\@\s*offsetByCodePoints\s*is\s*\:5\s*i\=0\s*offsetByCodePoints\=3\s*a\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*b\s*offsetByCodePoints\s*is\s*\:5\s*i\=0\s*offsetByCodePoints\=3\s*q\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*w\s*offsetByCodePoints\s*is\s*\:5\s*i\=0\s*offsetByCodePoints\=3\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*\@\s*offsetByCodePoints\s*is\s*\:5\s*i\=0\s*offsetByCodePoints\=3\s*a\s*offsetByCodePoints\s*is\s*\:3\s*i\=1\s*offsetByCodePoints\=5\s*b\s*offsetByCodePoints\s*is\s*\:5\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0064-rt-String-GetCharsTest/StringGetCharsTest.java b/test/testsuite/ouroboros/string_test/RT0064-rt-String-GetCharsTest/StringGetCharsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fd3675df97183a15a812a36d5d8197661923c8cd --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0064-rt-String-GetCharsTest/StringGetCharsTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringGetCharsTest.java + * -@TestCaseName: Test String Method: void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: dst.length > 0, dst.element some letters. 0 =< srcBegin < srcEnd, + * srcEnd < instance.length. 0 =< dstBegin < dst.length -1, srcBegin/srcEnd/dstBegin cover boundary value. + * -#step3: Test method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin). + * -#step4: check the dst is replaced correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringGetCharsTest.java + * -@ExecuteClass: StringGetCharsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringGetCharsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringGetCharsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringGetCharsTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + // 0 < srcBegin < srcEnd, srcEnd < instance.length. 0 =< dstBegin < dst.length -1. + char[] dst = {'A', 'B', 'C', 'D', 'E', 'F'}; + str.getChars(2, 5, dst, 2); + System.out.println(dst); + + // srcBegin = 0, srcEnd < instance.length. 0 =< dstBegin < dst.length -1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + str.getChars(0, 3, dst, 2); + System.out.println(dst); + + // srcBegin = instance.length, srcEnd = instance.length, 0 =< dstBegin < dst.length -1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + str.getChars(str.length(), str.length(), dst, 2); + System.out.println(dst); + + // srcBegin = 0, srcEnd = 0, 0 =< dstBegin < dst.length -1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + str.getChars(0, 0, dst, 2); + System.out.println(dst); + + // 0 < srcBegin < srcEnd, srcEnd < instance.length, dstBegin = 0. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + str.getChars(2, 3, dst, 0); + System.out.println(dst); + + // 0 < srcBegin < srcEnd, srcEnd < instance.length, dstBegin = dst.length -1. + dst = new char[]{'A', 'B', 'C', 'D', 'E', 'F'}; + str.getChars(2, 3, dst, 5); + System.out.println(dst); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ABertF\s*ABqweF\s*ABCDEF\s*ABCDEF\s*eBCDEF\s*ABCDEe\s*AB\!\.\&F\s*AB\s*\@\!F\s*ABCDEF\s*ABCDEF\s*\!BCDEF\s*ABCDE\!\s*ABc12F\s*ABabcF\s*ABCDEF\s*ABCDEF\s*cBCDEF\s*ABCDEc\s*ABertF\s*ABqweF\s*ABCDEF\s*ABCDEF\s*eBCDEF\s*ABCDEe\s*AB\!\.\&F\s*AB\s*\@\!F\s*ABCDEF\s*ABCDEF\s*\!BCDEF\s*ABCDE\!\s*ABc12F\s*ABabcF\s*ABCDEF\s*ABCDEF\s*cBCDEF\s*ABCDEc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0065-rt-String-GetBytesIntIntBytesIntTest/StringGetBytesIntIntBytesIntTest.java b/test/testsuite/ouroboros/string_test/RT0065-rt-String-GetBytesIntIntBytesIntTest/StringGetBytesIntIntBytesIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..1cee726a4b3e19ec79592bb92660a584e3574e3f --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0065-rt-String-GetBytesIntIntBytesIntTest/StringGetBytesIntIntBytesIntTest.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringGetBytesIntIntBytesIntTest.java + * -@TestCaseName: Test String Method: void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: dst.length > 0, dst.element is Hex number. 0 =< srcBegin < srcEnd, srcEnd < + * instance.length. 0 =< dstBegin < dst.length -1. srcBegin/srcEnd/dstBegin cover boundary value. + * -#step3: Test method getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin). + * -#step4: check the dst is replaced correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringGetBytesIntIntBytesIntTest.java + * -@ExecuteClass: StringGetBytesIntIntBytesIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringGetBytesIntIntBytesIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringGetBytesIntIntBytesIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringGetBytesIntIntBytesIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + // Test 0 < srcBegin < srcEnd, srcEnd < instance.length. 0 =< dstBegin < dst.length -1. + byte[] dst = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + str.getBytes(2, 5, dst, 2); + String str_new = new String(dst); + System.out.println(str_new); + + // Test srcBegin = 0, srcEnd < instance.length. 0 =< dstBegin < dst.length -1. + dst = new byte[]{0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + str.getBytes(0, 3, dst, 2); + str_new = new String(dst); + System.out.println(str_new); + + // Test srcBegin = instance.length, srcEnd = instance.length, 0 =< dstBegin < dst.length -1. + dst = new byte[]{0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + str.getBytes(str.length(), str.length(), dst, 2); + str_new = new String(dst); + System.out.println(str_new); + + // Test srcBegin = 0, srcEnd = 0, 0 =< dstBegin < dst.length -1. + dst = new byte[]{0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + str.getBytes(0, 0, dst, 2); + str_new = new String(dst); + System.out.println(str_new); + + // Test 0 < srcBegin < srcEnd, srcEnd < instance.length, dstBegin = 0. + dst = new byte[]{0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + str.getBytes(2, 3, dst, 0); + str_new = new String(dst); + System.out.println(str_new); + + // Test 0 < srcBegin < srcEnd, srcEnd < instance.length, dstBegin = dst.length -1. + dst = new byte[]{0x41, 0x42, 0x43, 0x44, 0x45, 0x46}; + str.getBytes(2, 3, dst, 5); + str_new = new String(dst); + System.out.println(str_new); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ABertF\s*ABqweF\s*ABCDEF\s*ABCDEF\s*eBCDEF\s*ABCDEe\s*AB\!\.\&F\s*AB\s*\@\!F\s*ABCDEF\s*ABCDEF\s*\!BCDEF\s*ABCDE\!\s*ABc12F\s*ABabcF\s*ABCDEF\s*ABCDEF\s*cBCDEF\s*ABCDEc\s*ABertF\s*ABqweF\s*ABCDEF\s*ABCDEF\s*eBCDEF\s*ABCDEe\s*AB\!\.\&F\s*AB\s*\@\!F\s*ABCDEF\s*ABCDEF\s*\!BCDEF\s*ABCDE\!\s*ABc12F\s*ABabcF\s*ABCDEF\s*ABCDEF\s*cBCDEF\s*ABCDEc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0066-rt-String-GetBytesStringTest/StringGetBytesStringTest.java b/test/testsuite/ouroboros/string_test/RT0066-rt-String-GetBytesStringTest/StringGetBytesStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c80e7f23b04fe259d507aa1b51710795dd2f899a --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0066-rt-String-GetBytesStringTest/StringGetBytesStringTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringGetBytesStringTest.java + * -@TestCaseName: Test String Method: byte[] getBytes(String charsetName). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: charsetName is Charset Name String. + * -#step3: Test method getBytes(String charsetName). + * -#step4: Check the return byte[] is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringGetBytesStringTest.java + * -@ExecuteClass: StringGetBytesStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; + +public class StringGetBytesStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringGetBytesStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringGetBytesStringTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + try { + byte[] test1_1 = str.getBytes("UTF-8"); + for (int i = 0; i < test1_1.length; i++) { + System.out.println(test1_1[i]); + } + } catch (UnsupportedEncodingException e) { + System.out.println("Unsupported character set"); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 113\s*119\s*101\s*114\s*116\s*121\s*117\s*105\s*111\s*112\s*123\s*125\s*91\s*93\s*92\s*124\s*97\s*115\s*100\s*102\s*103\s*104\s*106\s*107\s*108\s*59\s*58\s*39\s*34\s*122\s*120\s*99\s*118\s*98\s*110\s*109\s*44\s*46\s*60\s*62\s*47\s*63\s*126\s*96\s*49\s*50\s*51\s*52\s*53\s*54\s*55\s*56\s*57\s*48\s*45\s*61\s*33\s*64\s*35\s*36\s*37\s*94\s*38\s*42\s*40\s*41\s*95\s*43\s*32\s*65\s*83\s*68\s*70\s*71\s*72\s*74\s*75\s*76\s*81\s*87\s*69\s*82\s*84\s*89\s*85\s*73\s*79\s*80\s*90\s*88\s*67\s*86\s*66\s*78\s*77\s*48\s*120\s*57\s*54\s*32\s*64\s*33\s*46\s*38\s*37\s*97\s*98\s*99\s*49\s*50\s*51\s*113\s*119\s*101\s*114\s*116\s*121\s*117\s*105\s*111\s*112\s*123\s*125\s*91\s*93\s*92\s*124\s*97\s*115\s*100\s*102\s*103\s*104\s*106\s*107\s*108\s*59\s*58\s*39\s*34\s*122\s*120\s*99\s*118\s*98\s*110\s*109\s*44\s*46\s*60\s*62\s*47\s*63\s*126\s*96\s*49\s*50\s*51\s*52\s*53\s*54\s*55\s*56\s*57\s*48\s*45\s*61\s*33\s*64\s*35\s*36\s*37\s*94\s*38\s*42\s*40\s*41\s*95\s*43\s*32\s*65\s*83\s*68\s*70\s*71\s*72\s*74\s*75\s*76\s*81\s*87\s*69\s*82\s*84\s*89\s*85\s*73\s*79\s*80\s*90\s*88\s*67\s*86\s*66\s*78\s*77\s*48\s*120\s*57\s*54\s*32\s*64\s*33\s*46\s*38\s*37\s*97\s*98\s*99\s*49\s*50\s*51\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0067-rt-String-GetBytesCharsetTest/StringGetBytesCharsetTest.java b/test/testsuite/ouroboros/string_test/RT0067-rt-String-GetBytesCharsetTest/StringGetBytesCharsetTest.java new file mode 100755 index 0000000000000000000000000000000000000000..1b7e29c9cda4ac2e8643d46fa0d374656f6e7bb7 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0067-rt-String-GetBytesCharsetTest/StringGetBytesCharsetTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringGetBytesCharsetTest.java + * -@TestCaseName: Test String method: public byte[] getBytes(Charset charset). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: charset is Charset in normal. + * -#step3: Test method getBytes(Charset charset). + * -#step4: Check the return byte[] is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringGetBytesCharsetTest.java + * -@ExecuteClass: StringGetBytesCharsetTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; + +public class StringGetBytesCharsetTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringGetBytesCharsetTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringGetBytesCharsetTest_1() throws UnsupportedEncodingException { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) throws UnsupportedEncodingException { + Charset charset = Charset.defaultCharset(); + byte[] test1 = str.getBytes(charset); + for (int i = 0; i < test1.length; i++) { + System.out.println(test1[i]); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 113\s*119\s*101\s*114\s*116\s*121\s*117\s*105\s*111\s*112\s*123\s*125\s*91\s*93\s*92\s*124\s*97\s*115\s*100\s*102\s*103\s*104\s*106\s*107\s*108\s*59\s*58\s*39\s*34\s*122\s*120\s*99\s*118\s*98\s*110\s*109\s*44\s*46\s*60\s*62\s*47\s*63\s*126\s*96\s*49\s*50\s*51\s*52\s*53\s*54\s*55\s*56\s*57\s*48\s*45\s*61\s*33\s*64\s*35\s*36\s*37\s*94\s*38\s*42\s*40\s*41\s*95\s*43\s*32\s*65\s*83\s*68\s*70\s*71\s*72\s*74\s*75\s*76\s*81\s*87\s*69\s*82\s*84\s*89\s*85\s*73\s*79\s*80\s*90\s*88\s*67\s*86\s*66\s*78\s*77\s*48\s*120\s*57\s*54\s*32\s*64\s*33\s*46\s*38\s*37\s*97\s*98\s*99\s*49\s*50\s*51\s*113\s*119\s*101\s*114\s*116\s*121\s*117\s*105\s*111\s*112\s*123\s*125\s*91\s*93\s*92\s*124\s*97\s*115\s*100\s*102\s*103\s*104\s*106\s*107\s*108\s*59\s*58\s*39\s*34\s*122\s*120\s*99\s*118\s*98\s*110\s*109\s*44\s*46\s*60\s*62\s*47\s*63\s*126\s*96\s*49\s*50\s*51\s*52\s*53\s*54\s*55\s*56\s*57\s*48\s*45\s*61\s*33\s*64\s*35\s*36\s*37\s*94\s*38\s*42\s*40\s*41\s*95\s*43\s*32\s*65\s*83\s*68\s*70\s*71\s*72\s*74\s*75\s*76\s*81\s*87\s*69\s*82\s*84\s*89\s*85\s*73\s*79\s*80\s*90\s*88\s*67\s*86\s*66\s*78\s*77\s*48\s*120\s*57\s*54\s*32\s*64\s*33\s*46\s*38\s*37\s*97\s*98\s*99\s*49\s*50\s*51\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0068-rt-String-GetBytesTest/StringGetBytesTest.java b/test/testsuite/ouroboros/string_test/RT0068-rt-String-GetBytesTest/StringGetBytesTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9e187a16f21c1c8aa6e599d2d70bd13d5938907d --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0068-rt-String-GetBytesTest/StringGetBytesTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringGetBytesTest.java + * -@TestCaseName: Test String Method: byte[] getBytes(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method getBytes(). + * -#step3: Check the return byte[] is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringGetBytesTest.java + * -@ExecuteClass: StringGetBytesTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringGetBytesTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringGetBytesTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringGetBytesTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + byte[] test1_1 = str.getBytes(); + for (int i = 0; i < test1_1.length; i++) { + System.out.println(test1_1[i]); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 113\s*119\s*101\s*114\s*116\s*121\s*117\s*105\s*111\s*112\s*123\s*125\s*91\s*93\s*92\s*124\s*97\s*115\s*100\s*102\s*103\s*104\s*106\s*107\s*108\s*59\s*58\s*39\s*34\s*122\s*120\s*99\s*118\s*98\s*110\s*109\s*44\s*46\s*60\s*62\s*47\s*63\s*126\s*96\s*49\s*50\s*51\s*52\s*53\s*54\s*55\s*56\s*57\s*48\s*45\s*61\s*33\s*64\s*35\s*36\s*37\s*94\s*38\s*42\s*40\s*41\s*95\s*43\s*32\s*65\s*83\s*68\s*70\s*71\s*72\s*74\s*75\s*76\s*81\s*87\s*69\s*82\s*84\s*89\s*85\s*73\s*79\s*80\s*90\s*88\s*67\s*86\s*66\s*78\s*77\s*48\s*120\s*57\s*54\s*32\s*64\s*33\s*46\s*38\s*37\s*97\s*98\s*99\s*49\s*50\s*51\s*113\s*119\s*101\s*114\s*116\s*121\s*117\s*105\s*111\s*112\s*123\s*125\s*91\s*93\s*92\s*124\s*97\s*115\s*100\s*102\s*103\s*104\s*106\s*107\s*108\s*59\s*58\s*39\s*34\s*122\s*120\s*99\s*118\s*98\s*110\s*109\s*44\s*46\s*60\s*62\s*47\s*63\s*126\s*96\s*49\s*50\s*51\s*52\s*53\s*54\s*55\s*56\s*57\s*48\s*45\s*61\s*33\s*64\s*35\s*36\s*37\s*94\s*38\s*42\s*40\s*41\s*95\s*43\s*32\s*65\s*83\s*68\s*70\s*71\s*72\s*74\s*75\s*76\s*81\s*87\s*69\s*82\s*84\s*89\s*85\s*73\s*79\s*80\s*90\s*88\s*67\s*86\s*66\s*78\s*77\s*48\s*120\s*57\s*54\s*32\s*64\s*33\s*46\s*38\s*37\s*97\s*98\s*99\s*49\s*50\s*51\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0069-rt-String-EqualsTest/StringEqualsTest.java b/test/testsuite/ouroboros/string_test/RT0069-rt-String-EqualsTest/StringEqualsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f6f3e1f7b1897f8f8414f4421acfbadcce666a42 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0069-rt-String-EqualsTest/StringEqualsTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringEqualsTest.java + * -@TestCaseName: Test String Method: boolean equals(Object anObject). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance, Create anObject as a String instance. + * -#step2: Test method equals(Object anObject). + * -#step3: Change instance/anObject as one or more kinds of letters, numbers, special symbols/""/NoParam to repeat + * step2. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringEqualsTest.java + * -@ExecuteClass: StringEqualsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringEqualsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringEqualsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringEqualsTest_1() { + String str1_1 = new String("abc123"); + String str1_2 = new String("******"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + String str1_6 = new String("ABc123"); + + String str2_1 = "abc123"; + String str2_2 = "******"; + String str2_3 = "abc123"; + String str2_4 = ""; + String str2_5 = null; + + System.out.println(str1_1 + " equals " + str1_2 + " : " + str1_1.equals(str1_2)); + System.out.println(str1_1 + " equals " + str1_3 + " : " + str1_1.equals(str1_3)); + System.out.println(str1_1 + " equals " + str1_4 + " : " + str1_1.equals(str1_4)); + System.out.println(str1_1 + " equals " + str1_5 + " : " + str1_1.equals(str1_5)); + System.out.println(str1_1 + " equals " + str1_6 + " : " + str1_1.equals(str1_6)); + System.out.println(str1_2 + " equals " + str2_2 + " : " + str1_2.equals(str2_2)); + System.out.println(str2_1 + " equals " + str2_2 + " : " + str2_1.equals(str2_2)); + System.out.println(str2_1 + " equals " + str2_3 + " : " + str2_1.equals(str2_3)); + System.out.println(str2_1 + " equals " + str2_4 + " : " + str2_1.equals(str2_4)); + System.out.println(str2_1 + " equals " + str2_5 + " : " + str2_1.equals(str2_5)); + System.out.println(str1_1 + " equals " + str2_1 + " : " + str1_1.equals(str2_1)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*equals\s*\*\*\*\*\*\*\s*\:\s*false\s*abc123\s*equals\s*abc123\s*\:\s*true\s*abc123\s*equals\s*\:\s*false\s*abc123\s*equals\s*\:\s*false\s*abc123\s*equals\s*ABc123\s*\:\s*false\s*\*\*\*\*\*\*\s*equals\s*\*\*\*\*\*\*\s*\:\s*true\s*abc123\s*equals\s*\*\*\*\*\*\*\s*\:\s*false\s*abc123\s*equals\s*abc123\s*\:\s*true\s*abc123\s*equals\s*\:\s*false\s*abc123\s*equals\s*null\s*\:\s*false\s*abc123\s*equals\s*abc123\s*\:\s*true\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0070-rt-String-ContentEqualsTest/StringContentEqualsTest.java b/test/testsuite/ouroboros/string_test/RT0070-rt-String-ContentEqualsTest/StringContentEqualsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9ebf85e8a0ba41dcf60884254b4588d35d3a8e85 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0070-rt-String-ContentEqualsTest/StringContentEqualsTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringContentEqualsTest.java + * -@TestCaseName: Test String Method: boolean contentEquals(StringBuffer sb). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: sb is created by new StringBuffer(String str). + * -#step3: Test method contentEquals(StringBuffer sb). + * -#step4: Check the boolean result is correctly. + * -#step5: Change str as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringContentEqualsTest.java + * -@ExecuteClass: StringContentEqualsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringContentEqualsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringContentEqualsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringContentEqualsTest_1() { + String str1_1 = new String("abc123"); + String str1_2 = new String("******"); + String str1_3 = new String("ABc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "abc123"; + String str2_2 = "******"; + String str2_3 = "ABc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String test = "abc123"; + StringBuffer test1_1 = new StringBuffer(str); + boolean result = test.contentEquals(test1_1); + System.out.println(result); + } +} + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan true\s*false\s*false\s*false\s*false\s*true\s*false\s*false\s*false\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0071-rt-String-ContentEqualsCharSequenceTest/StringContentEqualsCharSequenceTest.java b/test/testsuite/ouroboros/string_test/RT0071-rt-String-ContentEqualsCharSequenceTest/StringContentEqualsCharSequenceTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0e5f391fde2b36da84cca10fa5b1f95ad454e969 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0071-rt-String-ContentEqualsCharSequenceTest/StringContentEqualsCharSequenceTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringContentEqualsCharSequenceTest.java + * -@TestCaseName: Test String Method: boolean contentEquals(CharSequence cs). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: cs is initialized by String str. + * -#step3: Test method contentEquals(CharSequence cs). + * -#step4: Check the boolean result is correctly. + * -#step5: Change cs as String 0f One or more kinds of letters, numbers, special symbols or as "" or as NoParam to + * repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringContentEqualsCharSequenceTest.java + * -@ExecuteClass: StringContentEqualsCharSequenceTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringContentEqualsCharSequenceTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringContentEqualsCharSequenceTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringContentEqualsCharSequenceTest_1() { + String str1_1 = new String("ABC123"); + String str1_2 = new String("******"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "ABC123"; + String str2_2 = "******"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String test = "abc123"; + CharSequence test1_1 = str; + boolean result = test.contentEquals(test1_1); + System.out.println(result); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan false\s*false\s*true\s*false\s*false\s*false\s*false\s*true\s*false\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0072-rt-String-EqualsIgnoreCaseTest/StringEqualsIgnoreCaseTest.java b/test/testsuite/ouroboros/string_test/RT0072-rt-String-EqualsIgnoreCaseTest/StringEqualsIgnoreCaseTest.java new file mode 100755 index 0000000000000000000000000000000000000000..65320e6377db3b1c81344f865bcfddaac1725041 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0072-rt-String-EqualsIgnoreCaseTest/StringEqualsIgnoreCaseTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringEqualsIgnoreCaseTest.java + * -@TestCaseName: Test String Method: boolean equalsIgnoreCase(String anotherString). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance and anotherString instance. + * -#step2: Test method test.equalsIgnoreCase(anotherString). + * -#step3: Check the boolean result is correctly. + * -#step4: Change anotherString as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringEqualsIgnoreCaseTest.java + * -@ExecuteClass: StringEqualsIgnoreCaseTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringEqualsIgnoreCaseTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringEqualsIgnoreCaseTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringEqualsIgnoreCaseTest_1() { + String str1_1 = new String("ABC123"); + String str1_2 = new String("******"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "ABC123"; + String str2_2 = "******"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String test = "ABC123"; + boolean result = test.equalsIgnoreCase(str); + System.out.println(result); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan true\s*false\s*true\s*false\s*false\s*true\s*false\s*true\s*false\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0073-rt-String-CompareToTest/StringCompareToTest.java b/test/testsuite/ouroboros/string_test/RT0073-rt-String-CompareToTest/StringCompareToTest.java new file mode 100755 index 0000000000000000000000000000000000000000..01dd9703678e6da13fe1fd52ea501a1c659bacb5 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0073-rt-String-CompareToTest/StringCompareToTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCompareToTest.java + * -@TestCaseName: Test String Method compareTo(String anotherString). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance and anotherString instance. + * -#step2: Test method compareTo(String anotherString). + * -#step3: Check the int result is correctly. + * -#step4: Change anotherString as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCompareToTest.java + * -@ExecuteClass: StringCompareToTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCompareToTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCompareToTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCompareToTest_1() { + String str1_1 = new String("ABC123"); + String str1_2 = new String("******"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "ABC123"; + String str2_2 = "******"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String test = "ABC123"; + int result = test.compareTo(str); + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\s*23\s*\-32\s*6\s*6\s*0\s*23\s*\-32\s*6\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0074-rt-String-CompareToIgnoreCaseTest/StringCompareToIgnoreCaseTest.java b/test/testsuite/ouroboros/string_test/RT0074-rt-String-CompareToIgnoreCaseTest/StringCompareToIgnoreCaseTest.java new file mode 100755 index 0000000000000000000000000000000000000000..680f46b09cbe398ed37accb6ccf5fffa261863b8 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0074-rt-String-CompareToIgnoreCaseTest/StringCompareToIgnoreCaseTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCompareToIgnoreCaseTest.java + * -@TestCaseName: Test String Method: int compareToIgnoreCase(String str). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance, parameter anotherString instance. + * -#step2: Test method test.compareTo(anotherString). + * -#step3: Check the int result is correctly. + * -#step4: Change anotherString as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCompareToIgnoreCaseTest.java + * -@ExecuteClass: StringCompareToIgnoreCaseTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCompareToIgnoreCaseTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCompareToIgnoreCaseTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCompareToIgnoreCaseTest_1() { + String str1_1 = new String("ABC123"); + String str1_2 = new String("******"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "ABC123"; + String str2_2 = "******"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String test = "ABC123"; + int result = test.compareToIgnoreCase(str); + System.out.println(result); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\s*55\s*0\s*6\s*6\s*0\s*55\s*0\s*6\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0075-rt-String-RegionMatchesIntStringIntIntTest/StringRegionMatchesIntStringIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0075-rt-String-RegionMatchesIntStringIntIntTest/StringRegionMatchesIntStringIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..122eb3bd2d10ba2b424a8901eaace2888c9f18ba --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0075-rt-String-RegionMatchesIntStringIntIntTest/StringRegionMatchesIntStringIntIntTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringRegionMatchesIntStringIntIntTest.java + * -@TestCaseName: Test String Method: boolean regionMatches(int toffset, String other, int ooffset, int len). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: 0 =< toffset < instance.length, 0 =< ooffset < other.length, 0 =< len < + * Min value of other.length - ooffset -1 and instance.length - toffset - 1, toffset/ooffset/len cover + * Boundary value. + * -#step3: Test method instance.regionMatches(int toffset, String other, int ooffset, int len). + * -#step4: Check the boolean result is correctly. + * -#step5: Change instance & String as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat + * step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringRegionMatchesIntStringIntIntTest.java + * -@ExecuteClass: StringRegionMatchesIntStringIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringRegionMatchesIntStringIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringRegionMatchesIntStringIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringRegionMatchesIntStringIntIntTest_1() { + String str1_1 = new String("abc123_SAME"); + String str1_2 = new String(" _same"); + String str1_3 = new String("abc123_same"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "abc123_SAME"; + String str2_2 = " _same"; + String str2_3 = "abc123_same"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String test = "same"; + // Test 0 =< toffset < instance.length, 0 =< ooffset < other.length, + // 0 =< len < 0 =< len < Min value of other.length - ooffset -1 and instance.length - toffset - 1 + System.out.println(str.regionMatches(7, test, 0, 4)); + System.out.println(str.regionMatches(7, test, 0, 5)); + System.out.println(str.regionMatches(8, test, 1, 3)); + // Test toffset < 0. + System.out.println(str.regionMatches(-2, test, 0, 2)); + // Test toffset = 0. + System.out.println(str.regionMatches(0, test, 1, 1)); + // Test toffset < instance.length - 1. + System.out.println(str.regionMatches(10, test, 1, 1)); + // Test ooffset = other.length - 1. + System.out.println(str.regionMatches(10, test, 3, 1)); + // Test len = 0. + System.out.println(str.regionMatches(7, test, 0, 0)); + // Test len = str.length(). + System.out.println(str.regionMatches(7, test, 0, str.length())); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan false\s*false\s*false\s*false\s*true\s*false\s*false\s*true\s*false\s*true\s*false\s*true\s*false\s*false\s*false\s*true\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*true\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*true\s*false\s*false\s*true\s*false\s*true\s*false\s*true\s*false\s*false\s*false\s*true\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*true\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0076-rt-String-RegionMatchesBooleanIntStringIntIntTest/StringRegionMatchesBooleanIntStringIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0076-rt-String-RegionMatchesBooleanIntStringIntIntTest/StringRegionMatchesBooleanIntStringIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fd09f522e8f165ed355d995726d8e302608d0bf2 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0076-rt-String-RegionMatchesBooleanIntStringIntIntTest/StringRegionMatchesBooleanIntStringIntIntTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringRegionMatchesBooleanIntStringIntIntTest.java + * -@TestCaseName: Test String Method: boolean regionMatches(boolean ignoreCase, int toffset, String other, int + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * ooffset, int len). + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: ignoreCase = true, 0 =< toffset < instance.length, 0 =< ooffset < other.length, 0 =< len + * < Min value of other.length - ooffset and instance.length - toffset. + * -#step3: Test method instance.regionMatches(int toffset, String other, int ooffset, int len), check the boolean + * result is correctly. + * -#step4: Create parameters: ignoreCase = false, 0 =< toffset < instance.length, 0 =< ooffset < other.length, 0 =< len + * < Min value of other.length - ooffset and instance.length - toffset. + * -#step5: Test method instance.regionMatches(int toffset, String other, int ooffset, int len), check the boolean + * result is correctly. + * -#step6: Create parameters: ignoreCase/toffset/ooffset/len cover boundary value. + * -#step7: Test method instance.regionMatches(int toffset, String other, int ooffset, int len), check the boolean + * result is correctly. + * -#step8: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~7. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringRegionMatchesBooleanIntStringIntIntTest.java + * -@ExecuteClass: StringRegionMatchesBooleanIntStringIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringRegionMatchesBooleanIntStringIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringRegionMatchesBooleanIntStringIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringRegionMatchesBooleanIntStringIntIntTest_1() { + String str1_1 = new String("abc123_SAME"); + String str1_2 = new String(" _same"); + String str1_3 = new String("abc123_same"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "abc123_SAME"; + String str2_2 = " _same"; + String str2_3 = "abc123_same"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String test = "SAME"; + // Test ooffset = 0, len = Min value of other.length - ooffset and instance.length - toffset. + System.out.println(str.regionMatches(true, 7, test, 0, 4)); + System.out.println(str.regionMatches(false, 7, test, 0, 4)); + + // Test toffset = 0. + System.out.println(str.regionMatches(true, 0, test, 1, 1)); + System.out.println(str.regionMatches(false, 0, test, 1, 1)); + + // Test toffset = str.length() - 1, ooffset = test.length() - 1. + System.out.println(str.regionMatches(true, str.length() - 1, test, 3, 1)); + System.out.println(str.regionMatches(false, str.length() - 1, test, 3, 1)); + + // Test len = 0. + System.out.println(str.regionMatches(true, 7, test, 0, 0)); + System.out.println(str.regionMatches(false, 7, test, 0, 0)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan true\s*true\s*true\s*false\s*true\s*true\s*true\s*true\s*true\s*false\s*false\s*false\s*true\s*false\s*true\s*true\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*true\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*true\s*true\s*true\s*false\s*true\s*true\s*true\s*true\s*true\s*false\s*false\s*false\s*true\s*false\s*true\s*true\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*true\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0077-rt-String-StartsWithStringIntTest/StringStartsWithStringIntTest.java b/test/testsuite/ouroboros/string_test/RT0077-rt-String-StartsWithStringIntTest/StringStartsWithStringIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..262507b2736016414d9b42e50208266449230d50 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0077-rt-String-StartsWithStringIntTest/StringStartsWithStringIntTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringStartsWithStringIntTest.java + * -@TestCaseName: Test String Method: boolean startsWith(String prefix, int toffset). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: prefix is some letters/numbers, 0 =< toffset < instance.length, toffset cover boundary + * value. + * -#step3: Test method startsWith(String prefix, int toffset). + * -#step4: Check the boolean result is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringStartsWithStringIntTest.java + * -@ExecuteClass: StringStartsWithStringIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringStartsWithStringIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringStartsWithStringIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringStartsWithStringIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.startsWith("123", 3)); + // Test toffset = 0. + System.out.println(str.startsWith("abc", 0)); + // Test toffset = str.length() - 1. + System.out.println(str.startsWith("%", str.length() - 1)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan false\s*false\s*false\s*false\s*false\s*true\s*true\s*true\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*false\s*true\s*true\s*true\s*false\s*false\s*false\s*false\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0078-rt-String-StartsWithStringTest/StringStartsWithStringTest.java b/test/testsuite/ouroboros/string_test/RT0078-rt-String-StartsWithStringTest/StringStartsWithStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ad23a433f2b35dac494fee521dcaec2ad454b66b --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0078-rt-String-StartsWithStringTest/StringStartsWithStringTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringStartsWithStringTest.java + * -@TestCaseName: Test String Method: boolean startsWith(String prefix). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: prefix is some letters/numbers or "". + * -#step3: Test method startsWith(String prefix). + * -#step4: Check the boolean result is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringStartsWithStringTest.java + * -@ExecuteClass: StringStartsWithStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringStartsWithStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringStartsWithStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringStartsWithStringTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.startsWith("ab")); + System.out.println(str.startsWith("")); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan false\s*true\s*false\s*true\s*true\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*true\s*true\s*false\s*true\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0079-rt-String-EndsWithTest/StringEndsWithTest.java b/test/testsuite/ouroboros/string_test/RT0079-rt-String-EndsWithTest/StringEndsWithTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2015e315ab455f06215e450c1799e440ae43b9fd --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0079-rt-String-EndsWithTest/StringEndsWithTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringEndsWithTest.java + * -@TestCaseName: Test String Method: boolean endsWith(String suffix). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: suffix is some letters/numbers or "". + * -#step3: Test method endsWith(String suffix). + * -#step4: Check the boolean result is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringEndsWithTest.java + * -@ExecuteClass: StringEndsWithTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringEndsWithTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringEndsWithTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringEndsWithTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.endsWith("bc")); + System.out.println(str.endsWith("")); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan false\s*true\s*false\s*true\s*true\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*false\s*true\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0080-rt-String-HashCodeTest/StringHashCodeTest.java b/test/testsuite/ouroboros/string_test/RT0080-rt-String-HashCodeTest/StringHashCodeTest.java new file mode 100755 index 0000000000000000000000000000000000000000..727b558894956df5454b6ab949cf93749a45b46a --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0080-rt-String-HashCodeTest/StringHashCodeTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringHashCodeTest.java + * -@TestCaseName: Test String Method: int hashCode(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method hashCode(). + * -#step3: Check the int result is correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringHashCodeTest.java + * -@ExecuteClass: StringHashCodeTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringHashCodeTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringHashCodeTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringHashCodeTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!" + + "@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.hashCode()); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan \-736345066\s*976266700\s*\-1113531438\s*0\s*0\s*\-736345066\s*976266700\s*\-1113563214\s*0\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0081-rt-String-IndexOfIntTest/StringIndexOfIntTest.java b/test/testsuite/ouroboros/string_test/RT0081-rt-String-IndexOfIntTest/StringIndexOfIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3235e515880291ab22a78136ebb1658941d640e9 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0081-rt-String-IndexOfIntTest/StringIndexOfIntTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringIndexOfIntTest.java + * -@TestCaseName: Test String Method: int indexOf(int ch). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: ch is ascii numbers. + * -#step3: Test method indexOf(int ch). + * -#step4: Check the int result is correctly. + * -#step5: replace instance or string which consists of one or more of the following:letters, numbers , "", + * special symbols and null, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringIndexOfIntTest.java + * -@ExecuteClass: StringIndexOfIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringIndexOfIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringIndexOfIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringIndexOfIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ " + + "ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUI" + + "OPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.indexOf(98)); + } +} + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 33\s*\-1\s*1\s*\-1\s*\-1\s*33\s*\-1\s*1\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0082-rt-String-IndexOfIntIntTest/StringIndexOfIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0082-rt-String-IndexOfIntIntTest/StringIndexOfIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0b2885db0e1ffaffe6a6e3ffecdc26e652615582 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0082-rt-String-IndexOfIntIntTest/StringIndexOfIntIntTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringIndexOfIntIntTest.java + * -@TestCaseName: Test String Method: int indexOf(int ch, int fromIndex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: ch is ascii numbers, 0 =< fromIndex = < instance.length. + * -#step3: Test method indexOf(int ch, int fromIndex). + * -#step4: Check the int result is correctly. + * -#step5: Replace instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringIndexOfIntIntTest.java + * -@ExecuteClass: StringIndexOfIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringIndexOfIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringIndexOfIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringIndexOfIntIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ " + + "ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZX" + + "CVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + // Test 0 < fromIndex < str.length(). + System.out.println(str.indexOf(98, 2)); + // Test fromIndex = 0. + System.out.println(str.indexOf(98, 0)); + // Test fromIndex = str.length(). + System.out.println(str.indexOf(98, str.length())); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 33\s*33\s*\-1\s*\-1\s*\-1\s*\-1\s*7\s*1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*33\s*33\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*1\s*\-1\s*\-1\s*\-1\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0083-rt-String-LastIndexOfIntTest/StringLastIndexOfIntTest.java b/test/testsuite/ouroboros/string_test/RT0083-rt-String-LastIndexOfIntTest/StringLastIndexOfIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3ce40335ee7e01f569c7e7bef43f7fddcf76a1ca --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0083-rt-String-LastIndexOfIntTest/StringLastIndexOfIntTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringLastIndexOfIntTest.java + * -@TestCaseName: Test String Method: int lastIndexOf(int ch). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: ch is ascii numbers. + * -#step3: Test method lastIndexOf(int ch). + * -#step4: Check the int result is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringLastIndexOfIntTest.java + * -@ExecuteClass: StringLastIndexOfIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringLastIndexOfIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringLastIndexOfIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringLastIndexOfIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+" + + "ASDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASDFGHJKLQWERTYUIOPZ" + + "XCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.lastIndexOf(98)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 33\s*\-1\s*7\s*\-1\s*\-1\s*33\s*\-1\s*1\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0084-rt-String-LastIndexOfIntIntTest/StringLastIndexOfIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0084-rt-String-LastIndexOfIntIntTest/StringLastIndexOfIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5cd2f38d6d03daf87b2fbaa31623ab7990f08a39 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0084-rt-String-LastIndexOfIntIntTest/StringLastIndexOfIntIntTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringLastIndexOfIntIntTest.java + * -@TestCaseName: Test String Method: int lastIndexOf(int ch, int fromIndex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: ch is ascii numbers, 0 =< fromIndex =< instance.length. + * -#step3: Test method lastIndexOf(int ch, int fromIndex). + * -#step4: Check the int result is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringLastIndexOfIntIntTest.java + * -@ExecuteClass: StringLastIndexOfIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringLastIndexOfIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringLastIndexOfIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringLastIndexOfIntIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASD" + + "FGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASDFGHJKLQWERTYUIO" + + "PZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + // Test fromIndex = 0. + System.out.println(str.lastIndexOf(49, 0)); + // Test 0 < fromIndex < str.length(). + System.out.println(str.lastIndexOf(49, 3)); + // Test fromIndex = str.length(). + System.out.println(str.lastIndexOf(49, str.length())); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan \-1\s*\-1\s*44\s*\-1\s*\-1\s*\-1\s*\-1\s*3\s*3\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*44\s*\-1\s*\-1\s*\-1\s*\-1\s*3\s*3\s*\-1\s*\-1\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0085-rt-String-IndexOfStringTest/StringIndexOfStringTest.java b/test/testsuite/ouroboros/string_test/RT0085-rt-String-IndexOfStringTest/StringIndexOfStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7bace9f14a4f6a958dbe708d10261500b029fff5 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0085-rt-String-IndexOfStringTest/StringIndexOfStringTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringIndexOfStringTest.java + * -@TestCaseName: Test String Method: int indexOf(String str). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: str1 is a letter. + * -#step3: Test method indexOf(String str). + * -#step4: Check the int result is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringIndexOfStringTest.java + * -@ExecuteClass: StringIndexOfStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringIndexOfStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringIndexOfStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringIndexOfStringTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+A" + + "SDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASDFGHJKLQWERTYUIOP" + + "ZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.indexOf("c")); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 31\s*\-1\s*2\s*\-1\s*\-1\s*31\s*\-1\s*2\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0086-rt-String-IndexOfStringIntTest/StringIndexOfStringIntTest.java b/test/testsuite/ouroboros/string_test/RT0086-rt-String-IndexOfStringIntTest/StringIndexOfStringIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d40a41b81f2f149a212ea0343f80ff569d005b7b --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0086-rt-String-IndexOfStringIntTest/StringIndexOfStringIntTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringIndexOfStringIntTest.java + * -@TestCaseName: Test String Method: int indexOf(String str, int fromIndex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: str is a letter, 0 =< fromIndex = < instance.length. + * -#step3: Test method indexOf(String str, int fromIndex). + * -#step4: Check the int result is correctly. + * -#step5: Replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringIndexOfStringIntTest.java + * -@ExecuteClass: StringIndexOfStringIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringIndexOfStringIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringIndexOfStringIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringIndexOfStringIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+A" + + "SDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASDFGHJKLQWERTYUIOP" + + "ZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + // Test fromIndex = 0. + System.out.println(str.indexOf("c", 0)); + // Test 0 < fromIndex < str.length(). + System.out.println(str.indexOf("c", 4)); + // Test fromIndex = str.length(). + System.out.println(str.indexOf("c", str.length())); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 31\s*31\s*\-1\s*\-1\s*\-1\s*\-1\s*2\s*8\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*31\s*31\s*\-1\s*\-1\s*\-1\s*\-1\s*2\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0087-rt-String-LastIndexOfStringTest/StringLastIndexOfStringTest.java b/test/testsuite/ouroboros/string_test/RT0087-rt-String-LastIndexOfStringTest/StringLastIndexOfStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9ea99472f7a991c1872f7117b692aa6b0194a847 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0087-rt-String-LastIndexOfStringTest/StringLastIndexOfStringTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringLastIndexOfStringTest.java + * -@TestCaseName: Test String Method: int lastIndexOf(String str). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: str1 is a letter. + * -#step3: Test method lastIndexOf(String str). + * -#step4: Check the int result is correctly. + * -#step5: Replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect:expected.txt + * -@Priority: High + * -@Source: StringLastIndexOfStringTest.java + * -@ExecuteClass: StringLastIndexOfStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringLastIndexOfStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringLastIndexOfStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringLastIndexOfStringTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASDFGHJKLQWERTYUIOPZX" + + "CVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.lastIndexOf("c")); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 31\s*\-1\s*8\s*\-1\s*\-1\s*31\s*\-1\s*2\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0088-rt-String-LastIndexOfStringIntTest/StringLastIndexOfStringIntTest.java b/test/testsuite/ouroboros/string_test/RT0088-rt-String-LastIndexOfStringIntTest/StringLastIndexOfStringIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..57510739abb7bd1c8a18601364513998e3b51e17 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0088-rt-String-LastIndexOfStringIntTest/StringLastIndexOfStringIntTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringLastIndexOfStringIntTest.java + * -@TestCaseName: Test String Method: int lastIndexOf(String str, int fromIndex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: str is a letter, 0 =< fromIndex =< instance.length. + * -#step3: Test method lastIndexOf(String str, int fromIndex). + * -#step4: Check the int result is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringLastIndexOfStringIntTest.java + * -@ExecuteClass: StringLastIndexOfStringIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringLastIndexOfStringIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringLastIndexOfStringIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringLastIndexOfStringIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASD" + + "FGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASDFGHJKLQWERTYUIOPZX" + + "CVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + // Test fromIndex = 0. + System.out.println(str.lastIndexOf("c", 0)); + // Test 0 < fromIndex < str.length(). + System.out.println(str.lastIndexOf("c", 2)); + // Test fromIndex = str.length(). + System.out.println(str.lastIndexOf("c", str.length())); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan \-1\s*\-1\s*31\s*\-1\s*\-1\s*\-1\s*\-1\s*2\s*8\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*\-1\s*31\s*\-1\s*\-1\s*\-1\s*\-1\s*2\s*2\s*\-1\s*\-1\s*\-1\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0089-rt-String-SubstringIntTest/StringSubstringIntTest.java b/test/testsuite/ouroboros/string_test/RT0089-rt-String-SubstringIntTest/StringSubstringIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8b6de5cbfde430066d0076f13af2074a3b12ef83 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0089-rt-String-SubstringIntTest/StringSubstringIntTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringSubstringIntTest.java + * -@TestCaseName: Test String Method: String substring(int beginIndex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: 0 =< beginIndex =< instance.length. + * -#step3: Test method substring(int beginIndex). + * -#step4: Check the String result is correctly. + * -#step5: Replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringSubstringIntTest.java + * -@ExecuteClass: StringSubstringIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringSubstringIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringSubstringIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringSubstringIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+A" + + "SDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASDFGHJKLQWERTY" + + "UIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + + test(str1_1); + test(str1_2); + test(str1_3); + + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + // Test beginIndex = 0. + System.out.println(str.substring(0)); + // Test 0 < beginIndex < str.length(). + System.out.println(str.substring(4)); + // Test beginIndex = str.length(). + System.out.println(str.substring(str.length())); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*tyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\&\%\s*abc123abc\s*23abc\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*tyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\&\%\s*abc123ABC\s*23ABC\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0090-rt-String-SubstringIntIntTest/StringSubstringIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0090-rt-String-SubstringIntIntTest/StringSubstringIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f939b6dd84ca801ada50626d68f0b875188f6b6b --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0090-rt-String-SubstringIntIntTest/StringSubstringIntIntTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringSubstringIntIntTest.java + * -@TestCaseName: String Method: String substring(int beginIndex, int endIndex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: 0 =< beginIndex < endIndex =< instance.length. + * -#step3: Test method substring(int beginIndex, int endIndex). + * -#step4: Check the String result is correctly. + * -#step5: Replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringSubstringIntIntTest.java + * -@ExecuteClass: StringSubstringIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringSubstringIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringSubstringIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringSubstringIntIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+A" + + "SDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ASDFGHJKLQWERTYUIOPZXC" + + "VBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + + test(str1_1); + test(str1_2); + test(str1_3); + + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + // Test 0 < beginIndex < endIndex < str.length(). + System.out.println(str.substring(2, 5)); + // Test beginIndex = 0. + System.out.println(str.substring(0, str.length() - 1)); + // Test endIndex = 0. + System.out.println(str.substring(0, 0)); + // Test beginIndex = str.length() - 1. + System.out.println(str.substring(str.length() - 1, str.length() - 1)); + // Test endIndex = str.length. + System.out.println(str.substring(2, str.length() - 1)); + + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ert\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+ASDFGHJKLQWERTYUIOPZXCVBNM0x9\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+ASDFGHJKLQWERTYUIOPZXCVBNM0x9\s*\!\.\&\s*\@\!\.\&\s*\!\.\&\s*c12\s*abc123ab\s*c123ab\s*ert\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+ASDFGHJKLQWERTYUIOPZXCVBNM0x9\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+ASDFGHJKLQWERTYUIOPZXCVBNM0x9\s*\!\.\&\s*\@\!\.\&\s*\!\.\&\s*c12\s*abc123AB\s*c123AB\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0091-rt-String-SubSequenceIntIntTest/StringSubSequenceIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0091-rt-String-SubSequenceIntIntTest/StringSubSequenceIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a9ba818760cf28ca89f4f5d41c602a7bb5e41fb5 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0091-rt-String-SubSequenceIntIntTest/StringSubSequenceIntIntTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringSubSequenceIntIntTest.java + * -@TestCaseName: Test String Method: CharSequence subSequence(int beginIndex, int endIndex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: 0 =< beginIndex < endIndex =< instance.length.Also,endIndex could be 0. + * -#step3: Test method subSequence(int beginIndex, int endIndex). + * -#step4: Check the CharSequence result is correctly. + * -#step5: replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringSubSequenceIntIntTest.java + * -@ExecuteClass: StringSubSequenceIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringSubSequenceIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringSubSequenceIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringSubSequenceIntIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ A" + + "SDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOPZ" + + "XCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + + test(str1_1); + test(str1_2); + test(str1_3); + + test(str2_1); + test(str2_2); + test(str2_3); + } + + private static void test(String str) { + // Test 0 < beginIndex < endIndex < str.length(). + System.out.println(str.subSequence(2, 6)); + // Test beginIndex = 0. + System.out.println(str.subSequence(0, str.length())); + // Test enfIndex = 0. + System.out.println(str.subSequence(0, 0)); + // Test beginIndex = str.length(). + System.out.println(str.subSequence(str.length(), str.length())); + // Test endIndex = str.length(). + System.out.println(str.subSequence(2, str.length())); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan erty\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\!\.\&\%\s*\@\!\.\&\%\s*\!\.\&\%\s*c123\s*abc123abc\s*c123abc\s*erty\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*ertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\!\.\&\%\s*\@\!\.\&\%\s*\!\.\&\%\s*c123\s*abc123ABC\s*c123ABC\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0092-rt-String-ConcatTest/StringConcatTest.java b/test/testsuite/ouroboros/string_test/RT0092-rt-String-ConcatTest/StringConcatTest.java new file mode 100755 index 0000000000000000000000000000000000000000..86bdda6f564c00ec59872d6f72f1ccee7051ab2e --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0092-rt-String-ConcatTest/StringConcatTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConcatTest.java + * -@TestCaseName: Test String Method: String concat(String str). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: test1_1 and test1_2 are some letters. + * -#step3: Test method test1_1.concat(instance).concat(test1_2). + * -#step4: Check the String result is correctly. + * -#step5: replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConcatTest.java + * -@ExecuteClass: StringConcatTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConcatTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringConcatTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringConcatTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ A" + + "SDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIO" + + "PZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String test1_1 = ""; + String test1_2 = ""; + System.out.println(test1_1.concat(str).concat(test1_2)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan \qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\\s*\\s*\@\!\.\&\%\\s*\abc123abc\\s*\\\s*\\\s*\qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\\s*\\s*\@\!\.\&\%\\s*\abc123ABC\\s*\\\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0093-rt-String-ReplaceCharCharTest/StringReplaceCharCharTest.java b/test/testsuite/ouroboros/string_test/RT0093-rt-String-ReplaceCharCharTest/StringReplaceCharCharTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c063c94f7f0d5ab380f950a0e4a0c4d33ebf6a79 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0093-rt-String-ReplaceCharCharTest/StringReplaceCharCharTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringReplaceCharCharTest.java + * -@TestCaseName: Test String Method: String replace(char oldChar, char newChar). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: oldChar and newChar is a char of letter or number or special symbols. + * -#step3: Test method replace(char oldChar, char newChar). + * -#step4: Check the String result is correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringReplaceCharCharTest.java + * -@ExecuteClass: StringReplaceCharCharTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringReplaceCharCharTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringReplaceCharCharTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringReplaceCharCharTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOP" + + "ZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.replace("a", "@").replace("1", "!")); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|\@sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`\!234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@bc\!23\@bc\s*qwertyuiop\{\}\[\]\\\|\@sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`\!234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@bc\!23ABC\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0094-rt-String-ContainsTest/StringContainsTest.java b/test/testsuite/ouroboros/string_test/RT0094-rt-String-ContainsTest/StringContainsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b98d1097d36c02ae3f4fb89004426517563b7e38 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0094-rt-String-ContainsTest/StringContainsTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringContainsTest.java + * -@TestCaseName: Test String Method: boolean contains(CharSequence s). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: s is some letters/numbers. + * -#step3: Test method contains(CharSequence s). + * -#step4: Check the boolean result is correctly. + * -#step5: replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringContainsTest.java + * -@ExecuteClass: StringContainsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringContainsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringContainsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringContainsTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ A" + + "SDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOP" + + "ZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.contains("c123A")); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan false\s*false\s*false\s*false\s*false\s*false\s*false\s*true\s*false\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0095-rt-String-ReplaceCharSequenceCharSequenceTest/StringReplaceCharSequenceCharSequenceTest.java b/test/testsuite/ouroboros/string_test/RT0095-rt-String-ReplaceCharSequenceCharSequenceTest/StringReplaceCharSequenceCharSequenceTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d6ef2470cd10792a389d0705f19e0f05dcfaa6ae --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0095-rt-String-ReplaceCharSequenceCharSequenceTest/StringReplaceCharSequenceCharSequenceTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringReplaceCharSequenceCharSequenceTest.java + * -@TestCaseName: Test String Method: String replace(CharSequence target, CharSequence replacement). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: target and replacement is a CharSequence mix with letter/number/special symbols. + * -#step3: Test method replace(CharSequence target, CharSequence replacement). + * -#step4: Check the String result is correctly. + * -#step5: replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringReplaceCharSequenceCharSequenceTest.java + * -@ExecuteClass: StringReplaceCharSequenceCharSequenceTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringReplaceCharSequenceCharSequenceTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringReplaceCharSequenceCharSequenceTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringReplaceCharSequenceCharSequenceTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYU" + + "IOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.replace("a", "@")); + System.out.println(str.replace("c123A", "@")); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|\@sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@bc123\@bc\s*abc123abc\s*qwertyuiop\{\}\[\]\\\|\@sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@bc123ABC\s*ab\@BC\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0096-rt-String-SplitStringIntTest/StringSplitStringIntTest.java b/test/testsuite/ouroboros/string_test/RT0096-rt-String-SplitStringIntTest/StringSplitStringIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a194b827dda1834065e1caa3df7432780c963ede --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0096-rt-String-SplitStringIntTest/StringSplitStringIntTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringSplitStringIntTest.java + * -@TestCaseName: Test String Method: String[] split(String regex, int limit). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: regex is a String mix with letter/number/special symbols, 0 = < limit =< instance.length. + * -#step3: Test method split(String regex, int limit). + * -#step4: Check the String[] result is correctly. + * -#step5: replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringSplitStringIntTest.java + * -@ExecuteClass: StringSplitStringIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringSplitStringIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringSplitStringIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringSplitStringIntTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ A" + + "SDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc.123.abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIO" + + "PZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc.123.ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String[] result; + // Test 0 < limit < instance.length. + result = str.split("a", 3); + for (int i = 0; i < result.length; i++) { + System.out.println(result[i]); + } + + // Test limit = instance.length. + result = str.split("a", str.length()); + for (int i = 0; i < result.length; i++) { + System.out.println(result[i]); + } + + // Test limit = 0. + result = str.split("a", 0); + for (int i = 0; i < result.length; i++) { + System.out.println(result[i]); + } + + // Test regex is a special symbols. + result = str.split("\\.", 2); + for (int i = 0; i < result.length; i++) { + System.out.println(result[i]); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|\s*sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|\s*sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|\s*sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\s*\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\s*\&\%\s*bc\.123\.\s*bc\s*bc\.123\.\s*bc\s*bc\.123\.\s*bc\s*abc\s*123\.abc\s*qwertyuiop\{\}\[\]\\\|\s*sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|\s*sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|\s*sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\s*\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\s*\&\%\s*bc\.123\.ABC\s*bc\.123\.ABC\s*bc\.123\.ABC\s*abc\s*123\.ABC\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0097-rt-String-SplitStringTest/StringSplitStringTest.java b/test/testsuite/ouroboros/string_test/RT0097-rt-String-SplitStringTest/StringSplitStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5de4a420257108f1981b47b2067536feb8c6cfa3 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0097-rt-String-SplitStringTest/StringSplitStringTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringSplitStringTest.java + * -@TestCaseName: Test String Method: String[] split(String regex). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create parameters: regex a String mix with letter/number/special symbols. + * -#step3: Test method split(String regex). + * -#step4: Check the String[] result is correctly. + * -#step5: replace instance or string which consists of one or more of the following: letters, numbers and special + * symbols, then to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringSplitStringTest.java + * -@ExecuteClass: StringSplitStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringSplitStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringSplitStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringSplitStringTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ A" + + "SDFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc.123.abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIOP" + + "ZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc.123.ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String[] result; + result = str.split("a"); + for (int i = 0; i < result.length; i++) { + System.out.println(result[i]); + } + + result = str.split("\\."); + for (int i = 0; i < result.length; i++) { + System.out.println(result[i]); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|\s*sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\s*\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\s*\&\%\s*bc\.123\.\s*bc\s*abc\s*123\s*abc\s*qwertyuiop\{\}\[\]\\\|\s*sdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\s*\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\s*\&\%\s*bc\.123\.ABC\s*abc\s*123\s*ABC\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0098-rt-String-JoinCharSequenceCharSequenceTest/StringJoinCharSequenceCharSequenceTest.java b/test/testsuite/ouroboros/string_test/RT0098-rt-String-JoinCharSequenceCharSequenceTest/StringJoinCharSequenceCharSequenceTest.java new file mode 100755 index 0000000000000000000000000000000000000000..c0b73fdc16b82ef785da46f91debb6d7cb90301e --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0098-rt-String-JoinCharSequenceCharSequenceTest/StringJoinCharSequenceCharSequenceTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringJoinCharSequenceCharSequenceTest.java + * -@TestCaseName: Test static String Method: join(CharSequence delimiter, CharSequence... elements). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: Create CharSequence delimiter, Create elements consist of String instance. + * -#step3: Test method join(CharSequence delimiter, CharSequence... elements). + * -#step4: Check the result get correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringJoinCharSequenceCharSequenceTest.java + * -@ExecuteClass: StringJoinCharSequenceCharSequenceTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringJoinCharSequenceCharSequenceTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringJoinCharSequenceCharSequenceTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringJoinCharSequenceCharSequenceTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIO" + + "PZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String[] test = new String[]{str, str, str}; + System.out.println(String.join("-", test)); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\-\s*\@\!\.\&\%\-\s*\@\!\.\&\%\s*abc123abc\-abc123abc\-abc123abc\s*\-\-\s*\-\-\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\-\s*\@\!\.\&\%\-\s*\@\!\.\&\%\s*abc123ABC\-abc123ABC\-abc123ABC\s*\-\-\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0099-rt-String-JoinCharSequenceIterableTest/StringJoinCharSequenceIterableTest.java b/test/testsuite/ouroboros/string_test/RT0099-rt-String-JoinCharSequenceIterableTest/StringJoinCharSequenceIterableTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0c908ae308a15d1b0bbff4393ee78d2050fe6c40 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0099-rt-String-JoinCharSequenceIterableTest/StringJoinCharSequenceIterableTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringJoinCharSequenceIterableTest.java + * -@TestCaseName: Test String Method: public static String join(CharSequence delimiter, Iterable elements). + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: Create CharSequence delimiter, Create elements as a List consist of String instance. + * -#step3: Test method join(CharSequence delimiter, Iterable elements). + * -#step4: Check the result get correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringJoinCharSequenceIterableTest.java + * -@ExecuteClass: StringJoinCharSequenceIterableTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +public class StringJoinCharSequenceIterableTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringJoinCharSequenceIterableTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringJoinCharSequenceIterableTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIO" + + "PZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + List test1_1 = new LinkedList<>(); + test1_1.add(str); + test1_1.add(str); + test1_1.add(str); + System.out.println(String.join("-", test1_1)); + + Set test1_2 = new LinkedHashSet<>(); + test1_2.add(str); + test1_2.add(str); + test1_2.add(str); + System.out.println(String.join("~", test1_2)); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\-\s*\@\!\.\&\%\-\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc123abc\-abc123abc\-abc123abc\s*abc123abc\s*\-\-\s*\-\-\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\-qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\-\s*\@\!\.\&\%\-\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc123ABC\-abc123ABC\-abc123ABC\s*abc123ABC\s*\-\-\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0100-rt-String-ToLowerCaseLocaleTest/StringToLowerCaseLocaleTest.java b/test/testsuite/ouroboros/string_test/RT0100-rt-String-ToLowerCaseLocaleTest/StringToLowerCaseLocaleTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3eae0bd462811862d2888e4b59ced9555ba70cf6 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0100-rt-String-ToLowerCaseLocaleTest/StringToLowerCaseLocaleTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringToLowerCaseLocaleTest.java + * -@TestCaseName: Test String Method: public String toLowerCase(Locale locale). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: Create locale random choose three country. + * -#step3: Test method toLowerCase(Locale locale). + * -#step4: Check the result get correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringToLowerCaseLocaleTest.java + * -@ExecuteClass: StringToLowerCaseLocaleTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.util.Locale; + + +public class StringToLowerCaseLocaleTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringToLowerCaseLocaleTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringToLowerCaseLocaleTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc.123.abc.~!@#$%^&*()_+;'/.?"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc.123.ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.toLowerCase(Locale.CHINESE)); + System.out.println(str.toLowerCase(Locale.ENGLISH)); + System.out.println(str.toLowerCase(Locale.FRENCH)); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*asdfghjklqwertyuiopzxcvbnm0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*asdfghjklqwertyuiopzxcvbnm0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*asdfghjklqwertyuiopzxcvbnm0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc\.123\.abc\.\~\!\@\#\$\%\^\&\*\(\)_\+\;\'\/\.\?\s*abc\.123\.abc\.\~\!\@\#\$\%\^\&\*\(\)_\+\;\'\/\.\?\s*abc\.123\.abc\.\~\!\@\#\$\%\^\&\*\(\)_\+\;\'\/\.\?\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*asdfghjklqwertyuiopzxcvbnm0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*asdfghjklqwertyuiopzxcvbnm0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*asdfghjklqwertyuiopzxcvbnm0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc\.123\.abc\s*abc\.123\.abc\s*abc\.123\.abc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0101-rt-String-ToLowerCaseTest/StringToLowerCaseTest.java b/test/testsuite/ouroboros/string_test/RT0101-rt-String-ToLowerCaseTest/StringToLowerCaseTest.java new file mode 100755 index 0000000000000000000000000000000000000000..95675dcd2b64e1149c8d540cb0b6d04eea9beacc --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0101-rt-String-ToLowerCaseTest/StringToLowerCaseTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringToLowerCaseTest.java + * -@TestCaseName: Test String Method: public String toLowerCase(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method toLowerCase(). + * -#step3: Check the result get correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringToLowerCaseTest.java + * -@ExecuteClass: StringToLowerCaseTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringToLowerCaseTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringToLowerCaseTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringToLowerCaseTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc.123.abc.~!@#$%^&*()_+;'/.?"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc.123.ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.toLowerCase()); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*asdfghjklqwertyuiopzxcvbnm0x96\s*\@\!\.\&\%\s*abc\.123\.abc\.\~\!\@\#\$\%\^\&\*\(\)_\+\;\'\/\.\?\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*asdfghjklqwertyuiopzxcvbnm0x96\s*\@\!\.\&\%\s*abc\.123\.abc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0102-rt-String-ToUpperCaseLocaleTest/StringToUpperCaseLocaleTest.java b/test/testsuite/ouroboros/string_test/RT0102-rt-String-ToUpperCaseLocaleTest/StringToUpperCaseLocaleTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a0558ac480eb0f3206110facffa6cae5cf883ad1 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0102-rt-String-ToUpperCaseLocaleTest/StringToUpperCaseLocaleTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringToUpperCaseLocaleTest.java + * -@TestCaseName: Test String Method: public String toUpperCase(Locale locale). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Create Parameters: Create locale random choose three country. + * -#step3: Test method toUpperCase(Locale locale). + * -#step4: Check the result get correctly. + * -#step5: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringToUpperCaseLocaleTest.java + * -@ExecuteClass: StringToUpperCaseLocaleTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +import java.util.Locale; + +public class StringToUpperCaseLocaleTest { + private static int processResult = 99; + + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringToUpperCaseLocaleTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringToUpperCaseLocaleTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc.123.abc.~!@#$%^&*()_+;'/.?"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc.123.ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.toUpperCase(Locale.CHINESE)); + System.out.println(str.toUpperCase(Locale.ENGLISH)); + System.out.println(str.toUpperCase(Locale.FRENCH)); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan QWERTYUIOP\{\}\[\]\\\|ASDFGHJKL\;\:\'\"ZXCVBNM\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0X96\s*QWERTYUIOP\{\}\[\]\\\|ASDFGHJKL\;\:\'\"ZXCVBNM\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0X96\s*QWERTYUIOP\{\}\[\]\\\|ASDFGHJKL\;\:\'\"ZXCVBNM\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0X96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*ABC\.123\.ABC\.\~\!\@\#\$\%\^\&\*\(\)_\+\;\'\/\.\?\s*ABC\.123\.ABC\.\~\!\@\#\$\%\^\&\*\(\)_\+\;\'\/\.\?\s*ABC\.123\.ABC\.\~\!\@\#\$\%\^\&\*\(\)_\+\;\'\/\.\?\s*QWERTYUIOP\{\}\[\]\\\|ASDFGHJKL\;\:\'\"ZXCVBNM\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0X96\s*QWERTYUIOP\{\}\[\]\\\|ASDFGHJKL\;\:\'\"ZXCVBNM\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0X96\s*QWERTYUIOP\{\}\[\]\\\|ASDFGHJKL\;\:\'\"ZXCVBNM\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0X96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*ABC\.123\.ABC\s*ABC\.123\.ABC\s*ABC\.123\.ABC\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0103-rt-String-ToUpperCaseTest/StringToUpperCaseTest.java b/test/testsuite/ouroboros/string_test/RT0103-rt-String-ToUpperCaseTest/StringToUpperCaseTest.java new file mode 100755 index 0000000000000000000000000000000000000000..83a0adc9669c022bdfda104015a706fdeb2114bf --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0103-rt-String-ToUpperCaseTest/StringToUpperCaseTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringToUpperCaseTest.java + * -@TestCaseName: Test String Method: public String toUpperCase(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method toUpperCase(). + * -#step3: Check the result get correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringToUpperCaseTest.java + * -@ExecuteClass: StringToUpperCaseTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringToUpperCaseTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringToUpperCaseTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringToUpperCaseTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc.123.abc.~!@#$%^&*()_+;'/.?"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc.123.ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str.toUpperCase()); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan QWERTYUIOP\{\}\[\]\\\|ASDFGHJKL\;\:\'\"ZXCVBNM\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0X96\s*\@\!\.\&\%\s*ABC\.123\.ABC\.\~\!\@\#\$\%\^\&\*\(\)_\+\;\'\/\.\?\s*QWERTYUIOP\{\}\[\]\\\|ASDFGHJKL\;\:\'\"ZXCVBNM\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0X96\s*\@\!\.\&\%\s*ABC\.123\.ABC\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0104-rt-String-TrimTest/StringTrimTest.java b/test/testsuite/ouroboros/string_test/RT0104-rt-String-TrimTest/StringTrimTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8af13e226e4db3bda1dc42b9a0c039006a499146 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0104-rt-String-TrimTest/StringTrimTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringTrimTest.java + * -@TestCaseName: Test String Method: public String trim(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method trim(). + * -#step3: Check the result get correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols(include\t、\n、\f、\b、\r、\、\\、 + * \" )/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringTrimTest.java + * -@ExecuteClass: StringTrimTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringTrimTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringTrimTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringTrimTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String(" abc.123.abc "); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = " abc.123.ABC "; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + + char data3_1[] = {'\t', 'a', 'b', 'c', '\t'}; + String str3_1 = new String(data3_1); + test(str3_1); + + char data3_2[] = {'\n', 'A', 'B', 'C', '\n'}; + String str3_2 = new String(data3_2); + test(str3_2); + + char data3_3[] = {'\f', 'a', 'b', 'c', '\f'}; + String str3_3 = new String(data3_3); + test(str3_3); + + + char data3_4[] = {'\b', 'A', 'B', 'C', '\b'}; + String str3_4 = new String(data3_4); + test(str3_4); + + char data3_5[] = {'\r', 'a', 'b', 'c', '\r'}; + String str3_5 = new String(data3_5); + test(str3_5); + + char data3_6[] = {'\'', 'A', 'B', 'C', '\''}; + String str3_6 = new String(data3_6); + test(str3_6); + + char data3_7[] = {'\\', 'a', 'b', 'c', '\\'}; + String str3_7 = new String(data3_7); + test(str3_7); + + + char data3_8[] = {'\"', 'A', 'B', 'C', '\"'}; + String str3_8 = new String(data3_8); + test(str3_8); + } + + private static void test(String str) { + System.out.println(str); + System.out.println(str.trim()); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc\.123\.abc\s*abc\.123\.abc\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc\.123\.ABC\s*abc\.123\.ABC\s*abc\s*abc\s*ABC\s*ABC\s*abc\s*abc\s*\ABC\\s*ABC\s*abc\s*abc\s*\'ABC\'\s*\'ABC\'\s*\\abc\\\s*\\abc\\\s*\"ABC\"\s*\"ABC\"\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0105-rt-String-ToStringTest/StringToStringTest.java b/test/testsuite/ouroboros/string_test/RT0105-rt-String-ToStringTest/StringToStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..46823f23a665e2238be38285056de099f734cbd8 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0105-rt-String-ToStringTest/StringToStringTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringToStringTest.java + * -@TestCaseName: Test String Method: public String toString(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method toString(). + * -#step3: Check the result get correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -#step5: Create String instance by char[]. + * -#step6: Test method toString(), check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringToStringTest.java + * -@ExecuteClass: StringToStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringToStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringToStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringToStringTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + + //new String() input : byte[], char[], StringBuffer, StringBuilder, String, int[](ASCII) + //byte[] char[] must USE new String + char data3_1[] = {0x61, 0x62, 0x63}; + String str3_1 = new String(data3_1); + System.out.println(str3_1); + System.out.println(str3_1.toString()); + } + + private static void test(String str) { + System.out.println(str.toString()); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*abc123abc\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*abc123ABC\s*abc\s*abc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0106-rt-String-ToCharArrayTest/StringToCharArrayTest.java b/test/testsuite/ouroboros/string_test/RT0106-rt-String-ToCharArrayTest/StringToCharArrayTest.java new file mode 100755 index 0000000000000000000000000000000000000000..394d06884111ba511a429d2b2ca5d6f5610e093b --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0106-rt-String-ToCharArrayTest/StringToCharArrayTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringToCharArrayTest.java + * -@TestCaseName: Test String Method: public char[] toCharArray(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance. + * -#step2: Test method toString(). + * -#step3: Check the result get correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringToCharArrayTest.java + * -@ExecuteClass: StringToCharArrayTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringToCharArrayTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringToCharArrayTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringToCharArrayTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc\n123\nabc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + System.out.println(str); + char[] ch1 = str.toCharArray(); + System.out.println("ch1 length: " + ch1.length); + System.out.println(ch1); + System.out.println(new String(ch1)); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*ch1\s*length\:\s*99\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*ch1\s*length\:\s*6\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc\s*123\s*abc\s*ch1\s*length\:\s*11\s*abc\s*123\s*abc\s*abc\s*123\s*abc\s*ch1\s*length\:\s*0\s*ch1\s*length\:\s*0\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*ch1\s*length\:\s*99\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*ch1\s*length\:\s*6\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc123ABC\s*ch1\s*length\:\s*9\s*abc123ABC\s*abc123ABC\s*ch1\s*length\:\s*0\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0107-rt-String-FormatStringObjectTest/StringFormatStringObjectTest.java b/test/testsuite/ouroboros/string_test/RT0107-rt-String-FormatStringObjectTest/StringFormatStringObjectTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ebafda7ef8250778b261b10259c19fbbbd591317 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0107-rt-String-FormatStringObjectTest/StringFormatStringObjectTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringFormatStringObjectTest.java + * -@TestCaseName: Test String Method: public static String format(String format, Object... args). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * + * -@Brief: + * -#step1: Create String instance as parameter args. + * -#step2: Create Parameters: format is a format string as %s. + * -#step3: Test method format(String format, Object... args). + * -#step4: Check the result get correctly. + * -#step5: Change instance as one or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -#step6: Create Parameters: format is a format string as %c %n, args is 'A'. + * -#step7: Test method format(String format, Object... args), check the result get correctly. + * -#step8: Create Parameters: format is a format string as %b %n, args Is an expression whose result is true/false. + * -#step9: Test method format(String format, Object... args), check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringFormatStringObjectTest.java + * -@ExecuteClass: StringFormatStringObjectTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringFormatStringObjectTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringFormatStringObjectTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringFormatStringObjectTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + + String str3_1 = null; + str3_1 = String.format("%c %n", 'A'); + System.out.println(str3_1); + str3_1 = String.format("%b %n", 3 > 7); + System.out.println(str3_1); + str3_1 = String.format("%b %n", 3 < 7); + System.out.println(str3_1); + } + + private static void test(String str) { + String test1 = null; + test1 = String.format("%s", str); + System.out.println(test1); + test1 = String.format("%s %s %s", str, str, str); + System.out.println(test1); } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc123abc\s*abc123abc\s*abc123abc\s*abc123abc\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*abc123ABC\s*abc123ABC\s*abc123ABC\s*abc123ABC\s*A\s*false\s*true\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0108-rt-String-ValueOfObjectTest/StringValueOfObjectTest.java b/test/testsuite/ouroboros/string_test/RT0108-rt-String-ValueOfObjectTest/StringValueOfObjectTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f123991ac713eca469a4e90557a33c9495dc8a63 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0108-rt-String-ValueOfObjectTest/StringValueOfObjectTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfObjectTest.java + * -@TestCaseName: Test String Method: public static String valueOf(Object obj). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance as parameter obj. + * -#step2: Test method valueOf(Object obj). + * -#step3: Check the result get correctly. + * -#step4: Change instance as one or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfObjectTest.java + * -@ExecuteClass: StringValueOfObjectTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfObjectTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringValueOfObjectTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringValueOfObjectTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + String str2_5 = null; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + test(str2_5); + } + + private static void test(Object obj) { + System.out.println(String.valueOf(obj)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*abc123abc\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*\@\!\.\&\%\s*abc123ABC\s*null\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0109-rt-String-ValueOfCharsTest/StringValueOfCharsTest.java b/test/testsuite/ouroboros/string_test/RT0109-rt-String-ValueOfCharsTest/StringValueOfCharsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ed329b346041e4dc049099a3da15e390fda35101 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0109-rt-String-ValueOfCharsTest/StringValueOfCharsTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfCharsTest.java + * -@TestCaseName: Test String Method: public static String valueOf(char[] data). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create char[] instance as parameter data. + * -#step2: Test method valueOf(char[] data). + * -#step3: Check the result get correctly. + * -#step4: Change data as the char array member type traversal letter, number Contains decimal、 hexadecimal、unix, + * empty to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfCharsTest.java + * -@ExecuteClass: StringValueOfCharsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfCharsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringValueOfCharsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringValueOfCharsTest_1() { + char[] ch1_1 = {'a', 'b', 'c', '1', '2', '3'}; + char[] ch1_2 = {0x61, 0x62, 0x63, 0x31, 0x32, 0x33}; + char[] ch1_3 = {'\u0061', '\u0062', '\u0063', '\u0031', '\u0032', '\u0033'}; + char[] ch1_4 = {0x0061, 0x0062, 0x0063, 0x0031, 0x0032, 0x0033}; + char[] ch1_5 = {}; + + test(ch1_1); + test(ch1_2); + test(ch1_3); + test(ch1_4); + test(ch1_5); + } + + private static void test(char[] ch1_1) { + System.out.println(String.valueOf(ch1_1)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*abc123\s*abc123\s*abc123\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0110-rt-String-ValueOfCharIntIntTest/StringValueOfCharIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0110-rt-String-ValueOfCharIntIntTest/StringValueOfCharIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3b0c74493bc84b8f0013dbbdbe4a10f03e6e9167 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0110-rt-String-ValueOfCharIntIntTest/StringValueOfCharIntIntTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfCharIntIntTest.java + * -@TestCaseName: Test String Method: public static String valueOf(char[] data, int offset, int count). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create char[] instance as parameter data. + * -#step2: Create other parameters: 0 =< offset < data.length, 0 =< count <= data.length, offset/count cover boundary + * value. + * -#step3: Test method valueOf(char[] data, int offset, int count). + * -#step4: Check the result get correctly. + * -#step5: Change data as the char array member type traversal letter, number Contains decimal、 hexadecimal、unix, + * empty to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfCharIntIntTest.java + * -@ExecuteClass: StringValueOfCharIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfCharIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringValueOfCharIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringValueOfCharIntIntTest_1() { + char ch1_1[] = {'a', 'b', 'c', '1', '2', '3'}; + char ch1_2[] = {0x61, 0x62, 0x63, 0x31, 0x32, 0x33}; + char ch1_3[] = {'\u0061', '\u0062', '\u0063', '\u0031', '\u0032', '\u0033'}; + char ch1_4[] = {0x0061, 0x0062, 0x0063, 0x0031, 0x0032, 0x0033}; + + test(ch1_1); + test(ch1_2); + test(ch1_3); + test(ch1_4); + } + + private static void test(char[] ch1_1) { + System.out.println(String.valueOf(ch1_1, 1, 3)); + // Test offset = 0. + System.out.println(String.valueOf(ch1_1, 0, 3)); + // Test count = 0. + System.out.println(String.valueOf(ch1_1, 1, 0)); + // Test count = ch1_1.length. + System.out.println(String.valueOf(ch1_1, 0, ch1_1.length)); + // Test offset = ch1_1.length - 1. + System.out.println(String.valueOf(ch1_1, ch1_1.length - 1, 1)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan bc1\s*abc\s*abc123\s*3\s*bc1\s*abc\s*abc123\s*3\s*bc1\s*abc\s*abc123\s*3\s*bc1\s*abc\s*abc123\s*3\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0111-rt-String-CopyValueOfCharIntIntTest/StringCopyValueOfCharIntIntTest.java b/test/testsuite/ouroboros/string_test/RT0111-rt-String-CopyValueOfCharIntIntTest/StringCopyValueOfCharIntIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..4d64bf2ca6d78445783e20bc5b3d9c1a002aaa83 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0111-rt-String-CopyValueOfCharIntIntTest/StringCopyValueOfCharIntIntTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCopyValueOfCharIntIntTest.java + * -@TestCaseName: Test String Method: public static String copyValueOf(char[] data, int offset, int count). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create char[] instance as parameter data. + * -#step2: Create other parameters: 0 =< offset < data.length, 0 =< count <= data.length, offset/count cover boundary + * value. + * -#step3: Test method copyValueOf(char[] data, int offset, int count). + * -#step4: Check the result get correctly. + * -#step5: Change data as the char array member type traversal letter, number Contains decimal、 hexadecimal、unix, + * empty to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCopyValueOfCharIntIntTest.java + * -@ExecuteClass: StringCopyValueOfCharIntIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCopyValueOfCharIntIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringCopyValueOfCharIntIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCopyValueOfCharIntIntTest_1() { + char ch1_1[] = {'a', 'b', 'c', '1', '2', '3'}; + char ch1_2[] = {0x61, 0x62, 0x63, 0x31, 0x32, 0x33}; + char ch1_3[] = {'\u0061', '\u0062', '\u0063', '\u0031', '\u0032', '\u0033'}; + char ch1_4[] = {0x0061, 0x0062, 0x0063, 0x0031, 0x0032, 0x0033}; + + test(ch1_1); + test(ch1_2); + test(ch1_3); + test(ch1_4); + } + + private static void test(char[] ch1_1) { + System.out.println(String.copyValueOf(ch1_1, 1, 3)); + // Test offset = 0. + System.out.println(String.copyValueOf(ch1_1, 0, 3)); + // Test count = 0. + System.out.println(String.copyValueOf(ch1_1, 1, 0)); + // Test count = ch1_1.length. + System.out.println(String.copyValueOf(ch1_1, 0, ch1_1.length)); + // Test offset = ch1_1.length - 1. + System.out.println(String.copyValueOf(ch1_1, ch1_1.length - 1, 1)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan bc1\s*abc\s*abc123\s*3\s*bc1\s*abc\s*abc123\s*3\s*bc1\s*abc\s*abc123\s*3\s*bc1\s*abc\s*abc123\s*3\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0112-rt-String-CopyValueOfCharTest/StringCopyValueOfCharTest.java b/test/testsuite/ouroboros/string_test/RT0112-rt-String-CopyValueOfCharTest/StringCopyValueOfCharTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7e559526eccdfb3e7857ecd374ac48368b4c2334 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0112-rt-String-CopyValueOfCharTest/StringCopyValueOfCharTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCopyValueOfCharTest.java + * -@TestCaseName: Test String Method: public static String copyValueOf(char[] data). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create char[] instance as parameter data. + * -#step2: Test method copyValueOf(char[] data). + * -#step3: Check the result get correctly. + * -#step4: Change data as the char array member type traversal letter, number Contains decimal、 hexadecimal、unix, + * empty to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCopyValueOfCharTest.java + * -@ExecuteClass: StringCopyValueOfCharTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCopyValueOfCharTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringCopyValueOfCharTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCopyValueOfCharTest_1() { + char ch1_1[] = {'a', 'b', 'c', '1', '2', '3'}; + char ch1_2[] = {0x61, 0x62, 0x63, 0x31, 0x32, 0x33}; + char ch1_3[] = {'\u0061', '\u0062', '\u0063', '\u0031', '\u0032', '\u0033'}; + char ch1_4[] = {0x0061, 0x0062, 0x0063, 0x0031, 0x0032, 0x0033}; + + test(ch1_1); + test(ch1_2); + test(ch1_3); + test(ch1_4); + } + + private static void test(char[] ch) { + System.out.println(String.copyValueOf(ch)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc123\s*abc123\s*abc123\s*abc123\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0113-rt-String-ValueOfBooleanTest/StringValueOfBooleanTest.java b/test/testsuite/ouroboros/string_test/RT0113-rt-String-ValueOfBooleanTest/StringValueOfBooleanTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fd766fc8fa1f8c651708d097cbf9deb86ba91ca5 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0113-rt-String-ValueOfBooleanTest/StringValueOfBooleanTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfBooleanTest.java + * -@TestCaseName: Test String Method: public static String valueOf(boolean b). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create boolean instance as parameter b. + * -#step2: Test method valueOf(boolean b). + * -#step3: Check the result get correctly. + * -#step4: Change b as the boolean instance traversal true/false expression to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfBooleanTest.java + * -@ExecuteClass: StringValueOfBooleanTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfBooleanTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringValueOfBooleanTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringValueOfBooleanTest_1() { + boolean bo1_1 = 3 > 7; + boolean bo1_2 = 9 > 7; + + test(bo1_1); + test(bo1_2); + } + + private static void test(boolean bo) { + System.out.println(String.valueOf(bo)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan false\s*true\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0114-rt-String-ValueOfCharTest/StringValueOfCharTest.java b/test/testsuite/ouroboros/string_test/RT0114-rt-String-ValueOfCharTest/StringValueOfCharTest.java new file mode 100755 index 0000000000000000000000000000000000000000..be4009ffd6fb87dd3ad25db0f6133ccfd49b56cd --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0114-rt-String-ValueOfCharTest/StringValueOfCharTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfCharTest.java + * -@TestCaseName: Test String Method: public static String valueOf(char c). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create char instance as parameter c. + * -#step2: Test method valueOf(char c). + * -#step3: Check the result get correctly. + * -#step4: Change c as char instance traversal letter, number Contains decimal、 hexadecimal、unix to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfCharTest.java + * -@ExecuteClass: StringValueOfCharTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfCharTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringValueOfCharTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringValueOfCharTest_1() { + char ch1_1 = 'a'; + char ch1_2 = 0x61; + char ch1_3 = '\u0061'; + char ch1_4 = 0x0061; + + test(ch1_1); + test(ch1_2); + test(ch1_3); + test(ch1_4); + } + + private static void test(char ch) { + System.out.println(String.valueOf(ch)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan a\s*a\s*a\s*a\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0115-rt-String-ValueOfIntTest/StringValueOfIntTest.java b/test/testsuite/ouroboros/string_test/RT0115-rt-String-ValueOfIntTest/StringValueOfIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a6007522c2aeba21629b2485c0da7d6b1ba4e4b5 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0115-rt-String-ValueOfIntTest/StringValueOfIntTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfIntTest.java + * -@TestCaseName: Test String Method: public static String valueOf(int i). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create int instance as parameter i. + * -#step2: Test method valueOf(int i). + * -#step3: Check the result get correctly. + * -#step4: Change i as int instance traversal number to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfIntTest.java + * -@ExecuteClass: StringValueOfIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringValueOfIntTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringValueOfIntTest_1() { + int in1_1 = 0; + int in1_2 = 12; + + test(in1_1); + test(in1_2); + } + + private static void test(int in) { + String test = String.valueOf(in); + System.out.println(test); + System.out.println(test + 13); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\s*013\s*12\s*1213\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0116-rt-String-ValueOfLongTest/StringValueOfLongTest.java b/test/testsuite/ouroboros/string_test/RT0116-rt-String-ValueOfLongTest/StringValueOfLongTest.java new file mode 100755 index 0000000000000000000000000000000000000000..4cc10a139e8dc1713f23e4efca55a9f9f493ad17 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0116-rt-String-ValueOfLongTest/StringValueOfLongTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfLongTest.java + * -@TestCaseName: Test String Method: public static String valueOf(long l). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create long instance as parameter l. + * -#step2: Test method valueOf(long l). + * -#step3: Check the result get correctly. + * -#step4: Change l as long instance traversal long number to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfLongTest.java + * -@ExecuteClass: StringValueOfLongTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfLongTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringValueOfLongTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringValueOfLongTest_1() { + long long1_1 = 0; + long long1_2 = 1234567890; + + test(long1_1); + test(long1_2); + } + + private static void test(long lo) { + String test = String.valueOf(lo); + System.out.println(test); + System.out.println(test + 13); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\s*013\s*1234567890\s*123456789013\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0117-rt-String-ValueOfFloatTest/StringValueOfFloatTest.java b/test/testsuite/ouroboros/string_test/RT0117-rt-String-ValueOfFloatTest/StringValueOfFloatTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d85be4fc493943efa206870f99046834b2cab370 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0117-rt-String-ValueOfFloatTest/StringValueOfFloatTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfFloatTest.java + * -@TestCaseName: Test String Method: public static String valueOf(float f). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create long instance as parameter f. + * -#step2: Test method valueOf(float f). + * -#step3: Check the result get correctly. + * -#step4: Change f as float instance traversal float number to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfFloatTest.java + * -@ExecuteClass: StringValueOfFloatTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfFloatTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringValueOfFloatTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringValueOfFloatTest_1() { + float fl1_1 = 0; + float fl1_2 = (float) 13.0; + + test(fl1_1); + test(fl1_2); + } + + private static void test(float fl) { + String test = String.valueOf(fl); + System.out.println(test); + System.out.println(test + 13); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\.0\s*0\.013\s*13\.0\s*13\.013\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0118-rt-String-ValueOfDoubleTest/StringValueOfDoubleTest.java b/test/testsuite/ouroboros/string_test/RT0118-rt-String-ValueOfDoubleTest/StringValueOfDoubleTest.java new file mode 100755 index 0000000000000000000000000000000000000000..606f6feacef3bcad6347f0514af28130f4b7ab85 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0118-rt-String-ValueOfDoubleTest/StringValueOfDoubleTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringValueOfDoubleTest.java + * -@TestCaseName: Test String Method: public static String valueOf(double d). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create double instance as parameter d. + * -#step2: Test method valueOf(double d). + * -#step3: Check the result get correctly. + * -#step4: Change d as double instance traversal double number to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringValueOfDoubleTest.java + * -@ExecuteClass: StringValueOfDoubleTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringValueOfDoubleTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringValueOfDoubleTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringValueOfDoubleTest_1() { + double d1_1 = 0; + double d1_2 = 1.23; + + test(d1_1); + test(d1_2); + } + + private static void test(double d) { + String test = String.valueOf(d); + System.out.println(test); + System.out.println(test + 13); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\.0\s*0\.013\s*1\.23\s*1\.2313\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0119-rt-String-InternTest/StringInternTest.java b/test/testsuite/ouroboros/string_test/RT0119-rt-String-InternTest/StringInternTest.java new file mode 100755 index 0000000000000000000000000000000000000000..e60c120e839607d6961a0b0a198f6c6ed9dc9226 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0119-rt-String-InternTest/StringInternTest.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringInternTest.java + * -@TestCaseName: Test String Method: public String intern(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance as some letters. + * -#step2: Test method intern(). + * -#step3: Check the result get correctly by compare with Various forms of strings. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringInternTest.java + * -@ExecuteClass: StringInternTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + + +public class StringInternTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + result = result-StringInternTest_1(); // 2-1=1 + } catch (Exception e) { + System.out.println(e); + StringInternTest.processResult = StringInternTest.processResult - 10; + } + + if (result == 1 && StringInternTest.processResult == 98) { + result = 0; + } + return result; + } + + + public static int StringInternTest_1() { + int result1 = 4; /* STATUS_FAILED */ + String str1 = "a"; + String str2 = "b"; + String str3 = "ab"; + String str4 = str1 + str2; + String str5 = new String("ab"); + String str6 = "a" + "b"; + String str7 = "a" + str2; + String str8 = new String("ab"); + if (str5.intern() == str3 && str5.intern() != str4 && str5.intern() == str6 && str5.intern() != str7 + && str5.intern() == str8.intern()) { + StringInternTest.processResult = StringInternTest.processResult - 1; + return 1; + } + StringInternTest.processResult = StringInternTest.processResult - 10; + return result1; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0120-rt-String-VoluationTest/StringVoluationTest.java b/test/testsuite/ouroboros/string_test/RT0120-rt-String-VoluationTest/StringVoluationTest.java new file mode 100755 index 0000000000000000000000000000000000000000..df7ad304cec8901925b6536cd630896f3fb2beaa --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0120-rt-String-VoluationTest/StringVoluationTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringVoluationTest.java + * -@TestCaseName: Test String create type by direct voluation. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String by = "String". + * -#step1: Check create string is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringVoluationTest.java + * -@ExecuteClass: StringVoluationTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringVoluationTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringVoluationTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringVoluationTest_1() { + String str1 = "abc"; + System.out.println(str1); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0121-rt-String-VoluationCharsTest/StringVoluationCharsTest.java b/test/testsuite/ouroboros/string_test/RT0121-rt-String-VoluationCharsTest/StringVoluationCharsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0004a5d9fb0ef850ab331a627322fece659563cb --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0121-rt-String-VoluationCharsTest/StringVoluationCharsTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringVoluationCharsTest.java + * -@TestCaseName: Test String create type by new String(char[] value). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameter: the element of value is some letter. + * -#step2: Test constructor String(char[] value). + * -#step3: Check the result get correctly. + * -#step4: Change the element of value is ascii num to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringVoluationCharsTest.java + * -@ExecuteClass: StringVoluationCharsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringVoluationCharsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringVoluationCharsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringVoluationCharsTest_1() { + char[] data2 = {'a', 'b', 'c'}; + String str2 = new String(data2); + char[] data3 = {0x61, 0x62, 0x63}; + String str3 = new String(data3); + String str4 = new String("abc"); + + System.out.println(str2); + System.out.println(str3); + System.out.println(str4); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan abc\s*abc\s*abc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0122-rt-String-SpliceStringTest/StringSpliceStringTest.java b/test/testsuite/ouroboros/string_test/RT0122-rt-String-SpliceStringTest/StringSpliceStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..09e63f5546971e2ca897737b88a8acc4a86d3492 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0122-rt-String-SpliceStringTest/StringSpliceStringTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringSpliceStringTest.java + * -@TestCaseName: Create String by one string + another string. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance str. + * -#step2: Test Create String by str + str, str + another string. + * -#step3: Check get the result correctly. + * -#step4: Change instance as One or more kinds of letters, numbers, special symbols/""/NoParam/null to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringSpliceStringTest.java + * -@ExecuteClass: StringSpliceStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringSpliceStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringSpliceStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringSpliceStringTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123"; + String str2_4 = ""; + String str2_5 = null; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + test(str2_5); + } + + private static void test(String str) { + String test1_1 = "test" + str; + String test1_2 = str + str; + System.out.println(test1_1); + System.out.println(test1_2); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan testqwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*test\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*testabc123\s*abc123abc123\s*test\s*test\s*testqwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96qwertyuiop\{\}\[\]\\\|asdfghjkl\;\:\'\"zxcvbnm\,\.\<\>\/\?\~\`1234567890\-\=\!\@\#\$\%\^\&\*\(\)_\+\s*ASDFGHJKLQWERTYUIOPZXCVBNM0x96\s*test\s*\@\!\.\&\%\s*\@\!\.\&\%\s*\@\!\.\&\%\s*testabc123\s*abc123abc123\s*test\s*testnull\s*nullnull\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0123-rt-String-CompareByDoubleEqualSignTest/StringCompareByDoubleEqualSignTest.java b/test/testsuite/ouroboros/string_test/RT0123-rt-String-CompareByDoubleEqualSignTest/StringCompareByDoubleEqualSignTest.java new file mode 100755 index 0000000000000000000000000000000000000000..48386c7513fb789ef00d383ef89f1b0a4fca3c55 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0123-rt-String-CompareByDoubleEqualSignTest/StringCompareByDoubleEqualSignTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCompareByDoubleEqualSignTest.java + * -@TestCaseName: User == compare strings. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance str1, str2. + * -#step2: Compare two strings with expression ==. + * -#step4: Check the result get correctly. + * -#step5: Change instance str2 as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCompareByDoubleEqualSignTest.java + * -@ExecuteClass: StringCompareByDoubleEqualSignTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCompareByDoubleEqualSignTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringCompareByDoubleEqualSignTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCompareByDoubleEqualSignTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIO" + + "PZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + String str2_5 = null; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + test(str2_5); + } + + private static void test(String str) { + String test1_1 = "abc123ABC"; + if (test1_1 == str) { + System.out.println("str == abc123abc"); + } else { + System.out.println("str1 !"); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan str1\s*\!\s*str1\s*\!\s*str1\s*\!\s*str1\s*\!\s*str1\s*\!\s*str1\s*\!\s*str1\s*\!\s*str\s*\=\=\s*abc123abc\s*str1\s*\!\s*str1\s*\!\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0124-rt-String-CompareByEqualsTest/StringCompareByEqualsTest.java b/test/testsuite/ouroboros/string_test/RT0124-rt-String-CompareByEqualsTest/StringCompareByEqualsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2d93be6f59bb2261379ef25df16b9cc914dbf25c --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0124-rt-String-CompareByEqualsTest/StringCompareByEqualsTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCompareByEqualsTest.java + * -@TestCaseName: User equals(Object anObject) compare strings. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance str1, str2. + * -#step2: Compare two strings by method equals(Object str1). + * -#step4: Check the result get correctly. + * -#step5: Change instance str2 as One or more kinds of letters, numbers, special symbols/""/NoParam to repeat step2~4. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCompareByEqualsTest.java + * -@ExecuteClass: StringCompareByEqualsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCompareByEqualsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringCompareByEqualsTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCompareByEqualsTest_1() { + String str1_1 = new String("qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ AS" + + "DFGHJKLQWERTYUIOPZXCVBNM0x96"); + String str1_2 = new String(" @!.&%"); + String str1_3 = new String("abc123abc"); + String str1_4 = new String(""); + String str1_5 = new String(); + + String str2_1 = "qwertyuiop{}[]\\|asdfghjkl;:'\"zxcvbnm,.<>/?~`1234567890-=!@#$%^&*()_+ ASDFGHJKLQWERTYUIO" + + "PZXCVBNM0x96"; + String str2_2 = " @!.&%"; + String str2_3 = "abc123ABC"; + String str2_4 = ""; + + test(str1_1); + test(str1_2); + test(str1_3); + test(str1_4); + test(str1_5); + test(str2_1); + test(str2_2); + test(str2_3); + test(str2_4); + } + + private static void test(String str) { + String test1_1 = "abc123abc"; + if (str.equals(test1_1)) { + System.out.println("str == abc123abc"); + } else { + System.out.println("str1 !"); + } + } +} + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan str1\s*\!\s*str1\s*\!\s*str\s*\=\=\s*abc123abc\s*str1\s*\!\s*str1\s*\!\s*str1\s*\!\s*str1\s*\!\s*str1\s*\!\s*str1\s*\!\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0125-rt-String-ConvertToByteTest/StringConvertToByteTest.java b/test/testsuite/ouroboros/string_test/RT0125-rt-String-ConvertToByteTest/StringConvertToByteTest.java new file mode 100755 index 0000000000000000000000000000000000000000..260d54ae568801f1e2af87a64729b05ea819af9a --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0125-rt-String-ConvertToByteTest/StringConvertToByteTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConvertToByteTest.java + * -@TestCaseName: Change String type to byte, test method of Byte: static byte parseByte(String s, int radix). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameter s, assign values to String's s1, s2. + * -#step2: Create Parameter radix, assign values to int r1, r2, their values represent octal and hexadecimal. + * -#step3: Test method parseByte(String s, int radix). + * -#step4: Check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConvertToByteTest.java + * -@ExecuteClass: StringConvertToByteTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConvertToByteTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringConvertToByteTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + // Test public static byte parseByte(String s). + public static void StringConvertToByteTest_1() { + // Create 2 byte primitives bt1, bt2. + byte b_1, b_2; + // Create and assign values to String's s1, s2. + String s1 = "123"; + String s2 = "-1a"; + // Create and assign values to int r1, r2. + int r1 = 8; // Represents octal. + int r2 = 16; // Represents hexadecimal. + b_1 = Byte.parseByte(s1, r1); + b_2 = Byte.parseByte(s2, r2); + String str1_1 = s1 + " convert(8) to Byte:" + b_1; + String str1_2 = s2 + " convert(16) to Byte:" + b_2; + System.out.println(str1_1); + System.out.println(str1_2); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 123\s*convert\(8\)\s*to\s*Byte\:83\s*\-1a\s*convert\(16\)\s*to\s*Byte\:\-26\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0126-rt-String-ConvertToShortTest/StringConvertToShortTest.java b/test/testsuite/ouroboros/string_test/RT0126-rt-String-ConvertToShortTest/StringConvertToShortTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5bf0a0ef8da1a5d63b8ba68bb83072663fa7aee5 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0126-rt-String-ConvertToShortTest/StringConvertToShortTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConvertToShortTest.java + * -@TestCaseName: Change String type to short, test method of Short: public static short parseShort(String s). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameter s, assign values to String's s. + * -#step2: Test method parseShort(String s). + * -#step3: Check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConvertToShortTest.java + * -@ExecuteClass: StringConvertToShortTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConvertToShortTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringConvertToShortTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + // Test public static short parseShort(String s). + public static void StringConvertToShortTest_1() { + String str1 = "04320"; + short s_1 = Short.parseShort(str1); + System.out.println(s_1); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 4320\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0127-rt-String-ConvertToIntTest/StringConvertToIntTest.java b/test/testsuite/ouroboros/string_test/RT0127-rt-String-ConvertToIntTest/StringConvertToIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..1b69746d15a0c3e72d3e4654239eb9d64703fd10 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0127-rt-String-ConvertToIntTest/StringConvertToIntTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConvertToIntTest.java + * -@TestCaseName: Change String type to int, test method of Integer: static int parseInt(String s), static int + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * parseInt(String s, int radix). + * -@Brief: + * -#case1 + * -#step1: Create Parameter s, assign values to String's s. + * -#step2: Test method parseInt(String s). + * -#step3: Check the result get correctly. + * -#case2 + * -#step1: Create Parameter s, assign values to String's s, radix is 8 represents octal. + * -#step2: Test method parseInt(String s, int radix). + * -#step3: Check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConvertToIntTest.java + * -@ExecuteClass: StringConvertToIntTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConvertToIntTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringConvertToIntTest_1(); + StringConvertToIntTest_2(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + // Test static int parseInt(String s). + public static void StringConvertToIntTest_1() { + int i_1 = Integer.parseInt("1234"); + System.out.println("convert(10) to int: " + i_1); + } + + // Test static int parseInt(String s, int radix). + public static void StringConvertToIntTest_2() { + int i_2 = Integer.parseInt("1234", 8); + System.out.println("convert(8) to int: " + i_2); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan convert\(10\)\s*to\s*int\:\s*1234\s*convert\(8\)\s*to\s*int\:\s*668\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0128-rt-String-ConvertToLongTest/StringConvertToLongTest.java b/test/testsuite/ouroboros/string_test/RT0128-rt-String-ConvertToLongTest/StringConvertToLongTest.java new file mode 100755 index 0000000000000000000000000000000000000000..39a1f8c80e4750b434a2e0f356c9367709dfb3dc --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0128-rt-String-ConvertToLongTest/StringConvertToLongTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConvertToLongTest.java + * -@TestCaseName: Change String type to long, test method of Long: static long parseLong(String s), + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * static long parseLong(String s, int radix). + * -@Brief: + * -#step1: Create Parameter s, assign values to String's s, radix is 10 represents Decimal. + * -#step2: Test method parseInt(String s, int radix). + * -#step3: Check the result get correctly. + * -#step4: Change s as 0, -0, Positive number, negative number, binary number, letters, change radix correspond cover + * 10, 16, 2, 27 to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConvertToLongTest.java + * -@ExecuteClass: StringConvertToLongTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConvertToLongTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringConvertToLongTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + // Test public static long parseLong(String s, int radix). + public static void StringConvertToLongTest_1() { + long l_1 = Long.parseLong("1234", 10); + // Test parses the string with specified radix + System.out.println(l_1); + long l_a = Long.parseLong("0", 10); + System.out.println(l_a); + long l_b = Long.parseLong("111", 10); + System.out.println(l_b); + long l_c = Long.parseLong("-0", 10); + System.out.println(l_c); + long l_d = Long.parseLong("-BB", 16); + System.out.println(l_d); + long l_e = Long.parseLong("1010110", 2); + System.out.println(l_e); + long l_f = Long.parseLong("2147483647", 10); + System.out.println(l_f); + long l_g = Long.parseLong("-2147483648", 10); + System.out.println(l_g); + long l_h = Long.parseLong("ADMIN", 27); + System.out.println(l_h); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 1234\s*0\s*111\s*0\s*\-187\s*86\s*2147483647\s*\-2147483648\s*5586836\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0129-rt-String-ConvertToFloatTest/StringConvertToFloatTest.java b/test/testsuite/ouroboros/string_test/RT0129-rt-String-ConvertToFloatTest/StringConvertToFloatTest.java new file mode 100755 index 0000000000000000000000000000000000000000..def25223ac264ae43466a304b5511569229a0bcf --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0129-rt-String-ConvertToFloatTest/StringConvertToFloatTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConvertToFloatTest.java + * -@TestCaseName: Change String type to float, test method of Float: public static float parseFloat(String s). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameter s, assign values to String's s. + * -#step2: Test method parseFloat(String s). + * -#step3: Check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConvertToFloatTest.java + * -@ExecuteClass: StringConvertToFloatTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConvertToFloatTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringConvertToFloatTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + // Test public static float parseFloat(String s). + public static void StringConvertToFloatTest_1() { + float f_1 = Float.parseFloat("12.34"); + System.out.println(f_1); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 12\.34\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0130-rt-String-ConvertToDoubleTest/StringConvertToDoubleTest.java b/test/testsuite/ouroboros/string_test/RT0130-rt-String-ConvertToDoubleTest/StringConvertToDoubleTest.java new file mode 100755 index 0000000000000000000000000000000000000000..be272f407bb179ae386388c6fca198f8f24ea6b0 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0130-rt-String-ConvertToDoubleTest/StringConvertToDoubleTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringConvertToDoubleTest.java + * -@TestCaseName: Change String type to double, test method of Double: public static double parseDouble(String s). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameter s, assign values to String's s. + * -#step2: Test method parseDouble(String s). + * -#step3: Check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringConvertToDoubleTest.java + * -@ExecuteClass: StringConvertToDoubleTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringConvertToDoubleTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringConvertToDoubleTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + // Test public static double parseDouble(String s). + public static void StringConvertToDoubleTest_1() { + double d_1 = Double.parseDouble("1.124"); + System.out.println(d_1); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 1\.124\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0131-rt-String-LongToBinaryStringTest/LongToBinaryStringTest.java b/test/testsuite/ouroboros/string_test/RT0131-rt-String-LongToBinaryStringTest/LongToBinaryStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0ddb34e8f9b30015ecbabe9b1f1f992673510700 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0131-rt-String-LongToBinaryStringTest/LongToBinaryStringTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: LongToBinaryStringTest.java + * -@TestCaseName: Test method of Long: static String toBinaryString(long i). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create long instance, value cover 0, normal number, bigger number. + * -#step2: Test method toBinaryString(long i). + * -#step3: Check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: LongToBinaryStringTest.java + * -@ExecuteClass: LongToBinaryStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class LongToBinaryStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + LongToBinaryStringTest_1(); + LongToBinaryStringTest_2(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + // Long.toBinaryString(long l) + public static void LongToBinaryStringTest_1() { + long l_a = 0L; + long l_b = 111L; + long l_c = 2147483647L; + + test(l_a); + test(l_b); + test(l_c); + } + + public static void LongToBinaryStringTest_2() { + Integer i_a = 0; + Integer i_b = 111; + Integer i_c = 2147483647; + + test2(i_a); + test2(i_b); + test2(i_c); + } + + private static void test(Long lo) { + System.out.println(Long.toBinaryString(lo)); + } + + private static void test2(Integer i) { + System.out.println(Integer.toBinaryString(i)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\s*1101111\s*1111111111111111111111111111111\s*0\s*1101111\s*1111111111111111111111111111111\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0132-rt-String-LongToOctalStringTest/LongToOctalStringTest.java b/test/testsuite/ouroboros/string_test/RT0132-rt-String-LongToOctalStringTest/LongToOctalStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ebb374d8f7d9839e7552cae3b14b40c7c1d35359 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0132-rt-String-LongToOctalStringTest/LongToOctalStringTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: LongToOctalStringTest.java + * -@TestCaseName: Test method of Long: static String toOctalString(long i). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create long instance, value cover 0, normal number, bigger number. + * -#step2: Test method toOctalString(long i). + * -#step3: Check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: LongToOctalStringTest.java + * -@ExecuteClass: LongToOctalStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class LongToOctalStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + LongToOctalStringTest_1(); + LongToOctalStringTest_2(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + // Long.toOctalString(long l) + public static void LongToOctalStringTest_1() { + long l_a = 0L; + long l_b = 111L; + long l_c = 2147483647L; + + test(l_a); + test(l_b); + test(l_c); + } + + public static void LongToOctalStringTest_2() { + Integer i_a = 0; + Integer i_b = 111; + Integer i_c = 2147483647; + + test2(i_a); + test2(i_b); + test2(i_c); + } + + private static void test(Long lo) { + System.out.println(Long.toOctalString(lo)); + } + + private static void test2(Integer i) { + System.out.println(Integer.toOctalString(i)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\s*157\s*17777777777\s*0\s*157\s*17777777777\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0133-rt-String-BasicToStringTest/BasicToStringTest.java b/test/testsuite/ouroboros/string_test/RT0133-rt-String-BasicToStringTest/BasicToStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7be64e6591be6af7f2bbf7c98276df2fbcfb5855 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0133-rt-String-BasicToStringTest/BasicToStringTest.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: BasicToStringTest.java + * -@TestCaseName:Test method of Long: static String toString(long i), test method of Integer: static String + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * toString(int i), test method of Float: static String toString(float f), test method of Double: + * static String toString(double d). + * -@Brief: + * -#case1 + * -#step1: Create long instance, value cover 0, normal number, bigger number. + * -#step2: Test method toString(long i). + * -#step3: Check the result get correctly. + * -#case2 + * -#step1: Create Integer instance, value cover 0, normal number, bigger number. + * -#step2: Test method toString(int i). + * -#step3: Check the result get correctly. + * -#case3 + * -#step1: Create float instance, value cover 0, normal number, bigger number. + * -#step2: Test method toString(float f). + * -#step3: Check the result get correctly. + * -#case4 + * -#step1: Create double instance, value cover 0, normal number, bigger number. + * -#step2: Test method toString(double d). + * -#step3: Check the result get correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: BasicToStringTest.java + * -@ExecuteClass: BasicToStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class BasicToStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + BasicToStringTest_1(); + BasicToStringTest_2(); + BasicToStringTest_3(); + BasicToStringTest_4(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + // Long.toString(long l, int p) + public static void BasicToStringTest_1() { + long l_a = 0; + long l_b = 111; + long l_c = 2147483647; + + test1(l_a); + test1(l_b); + test1(l_c); + } + + public static void BasicToStringTest_2() { + Integer i_a = 0; + Integer i_b = 111; + Integer i_c = 2147483647; + + test2(i_a); + test2(i_b); + test2(i_c); + } + + public static void BasicToStringTest_3() { + float f_a = 0f; + float f_b = 11.1f; + float f_c = 2147483.647f; + + test3(f_a); + test3(f_b); + test3(f_c); + } + + public static void BasicToStringTest_4() { + double d_a = 0; + double d_b = 1.11d; + double d_c = 21474836.47; + + test4(d_a); + test4(d_b); + test4(d_c); + } + + private static void test1(Long lo) { + System.out.println(Long.toString(lo)); + } + + private static void test2(Integer i) { + System.out.println(Integer.toString(i)); + } + + private static void test3(float f) { + System.out.println(Float.toString(f)); + } + + private static void test4(double f) { + System.out.println(Double.toString(f)); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\s*111\s*2147483647\s*0\s*111\s*2147483647\s*0\.0\s*11\.1\s*2147483\.8\s*0\.0\s*1\.11\s*2\.147483647E7\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0134-rt-String-NullToStringTest/NullToStringTest.java b/test/testsuite/ouroboros/string_test/RT0134-rt-String-NullToStringTest/NullToStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..09d44caa1685ed1c455dab94640cdecb80bf417a --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0134-rt-String-NullToStringTest/NullToStringTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: NullToStringTest.java + * -@TestCaseName: Test null to String. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#case1 + * -#step1: Create int instance, cover 0, normal, null value. + * -#step2: Create String by "<" + int instance + ">", check the string create correctly. + * -#case2 + * -#step1: Create String instance, cover "", normal, null value. + * -#step2: Create String by "<" + String instance + ">", check the string create correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: NullToStringTest.java + * -@ExecuteClass: NullToStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class NullToStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + NullToStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void NullToStringTest_1() { + int i1_1 = 0; + test1(i1_1); + int i1_2 = 123; + test1(i1_2); + Integer i1_3 = (Integer) null; + test3(i1_3); + + String str1_1 = ""; + test2(str1_1); + String str1_2 = "abc"; + test2(str1_2); + String str1_3 = null; + test2(str1_3); + + System.out.println((String) null); + System.out.println("<" + (String) null + ">"); + } + + private static void test1(int i) { + String str1 = "<" + i + ">"; + System.out.println("str1 : " + str1); + } + + private static void test2(String str) { + String str2 = "<" + str + ">"; + System.out.println("str2 : " + str2); + } + + private static void test3(final Integer i) { + String str1 = "<" + i + ">"; + System.out.println("str1 : " + str1); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan str1\s*\:\s*\<0\>\s*str1\s*\:\s*\<123\>\s*str1\s*\:\s*\\s*str2\s*\:\s*\<\>\s*str2\s*\:\s*\\s*str2\s*\:\s*\\s*null\s*\\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0135-rt-String-AsciiToStringTest/AsciiToStringTest.java b/test/testsuite/ouroboros/string_test/RT0135-rt-String-AsciiToStringTest/AsciiToStringTest.java new file mode 100755 index 0000000000000000000000000000000000000000..04e49a8d710794a141e6e1fa568808d0d1a23078 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0135-rt-String-AsciiToStringTest/AsciiToStringTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: AsciiToStringTest.java + * -@TestCaseName: Test ascii to string By test constructor of String: String(char[] value). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create char[] instance, the element is decimal number. + * -#step2: Test constructor of String: String(char[] value). + * -#step3: Check the string create correctly. + * -#step1: Create char[] instance, the element is hexadecimal number. + * -#step2: Test constructor of String: String(char[] value). + * -#step3: Check the string create correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: AsciiToStringTest.java + * -@ExecuteClass: AsciiToStringTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class AsciiToStringTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + AsciiToStringTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void AsciiToStringTest_1() { + String str1_1 = "a b^c~AB"; + //10 + char[] data1_2 = {97, 32, 98, 94, 99, 126, 65, 66}; + String str1_2 = new String(data1_2); + //16 + char[] data1_3 = {0x61, 0x20, 0x62, 0x5E, 0x63, 0x7E, 0x41, 0x42}; + String str1_3 = new String(data1_3); + + test1(str1_1); + test1(str1_2); + test1(str1_3); + } + + private static void test1(String str) { + System.out.println(str); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan a\s*b\^c\~AB\s*a\s*b\^c\~AB\s*a\s*b\^c\~AB\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0136-rt-String-ToHexStringCharTest/StringToHexStringCharTest.java b/test/testsuite/ouroboros/string_test/RT0136-rt-String-ToHexStringCharTest/StringToHexStringCharTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5eb4e5db8b718ae41865ce090f45889ef88cb32c --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0136-rt-String-ToHexStringCharTest/StringToHexStringCharTest.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringToHexStringCharTest.java + * -@TestCaseName: Test method toHesString(char ch). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create Parameters: Parameters should be Char type. + * -#step2: Test method toHesString(char ch). + * -#step3: Check the return String is correct. + * -#step4: Replace instance or string which consists of one or more of the following: letters, numbers Contains decimal + * and hexadecimal, special symbols, Chinese characters, unicode, then to repeat step2~3. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringToHexStringCharTest.java + * -@ExecuteClass: StringToHexStringCharTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringToHexStringCharTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringToHexStringCharTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringToHexStringCharTest_1() { + // 0x00~0x7F. + String str1_1 = "a b^c~AB"; + //10 + char data1_2[] = {97, 32, 98, 94, 99, 126, 65, 66}; + String str1_2 = new String(data1_2); + //16 + char data1_3[] = {0x61, 0x20, 0x62, 0x5E, 0x63, 0x7E, 0x41, 0x42}; + String str1_3 = new String(data1_3); + String str2_1 = "中国"; + // Test unicode + char data2_2[] = {'\u4E2D', '\u56FD'}; + String str2_2 = new String(data2_2); + String str3_1 = "中国abc"; + //unicode + char data3_2[] = {'\u4E2D', '\u56FD', 97, 98, 99}; + String str3_2 = new String(data3_2); + + test1(str1_1); + test1(str1_2); + test1(str1_3); + + test1(str2_1); + test1(str2_2); + test1(str3_1); + test1(str3_2); + } + + private static void test1(String str) { + for (int i = 0; i < str.length(); i++) { + char ch = str.charAt(i); + System.out.println(Integer.toHexString(ch)); + } + } +} + + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 61\s*20\s*62\s*5e\s*63\s*7e\s*41\s*42\s*61\s*20\s*62\s*5e\s*63\s*7e\s*41\s*42\s*61\s*20\s*62\s*5e\s*63\s*7e\s*41\s*42\s*4e2d\s*56fd\s*4e2d\s*56fd\s*4e2d\s*56fd\s*61\s*62\s*63\s*4e2d\s*56fd\s*61\s*62\s*63\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0137-rt-String-AsVariableAndFieldAndParamTest/StringAsVariableAndFieldAndParamTest.java b/test/testsuite/ouroboros/string_test/RT0137-rt-String-AsVariableAndFieldAndParamTest/StringAsVariableAndFieldAndParamTest.java new file mode 100755 index 0000000000000000000000000000000000000000..312a4a1e11c86bbcdefa02d46548a14e702c7219 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0137-rt-String-AsVariableAndFieldAndParamTest/StringAsVariableAndFieldAndParamTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringAsVariableAndFieldAndParamTest.java + * -@TestCaseName: User Scene: class use String. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create a null String. + * -#step2: Check the string is create correctly. + * -#step3: Create a string as the domain value of the class. + * -#step4: Check the string is create correctly. + * -#step5: Create a string as input param of function. + * -#step6: Check the return value of function is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringAsVariableAndFieldAndParamTest.java + * -@ExecuteClass: StringAsVariableAndFieldAndParamTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringAsVariableAndFieldAndParamTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringAsVariableAndFieldAndParamTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringAsVariableAndFieldAndParamTest_1() { + String str = null; + System.out.println(str); + System.out.println(StringAsVariableAndFieldAndParamTest_1.str1_1); + + str = "abc"; + System.out.println(StringAsVariableAndFieldAndParamTest_1.test(str)); + } +} + +class StringAsVariableAndFieldAndParamTest_1 { + static String str1_1 = "abc1_1"; + protected static String test(String str) { + String result = str + str; + System.out.println(result); + return result; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan null\s*abc1_1\s*abcabc\s*abcabc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0138-rt-String-VariableOfInterfaceTest/StringVariableOfInterfaceTest.java b/test/testsuite/ouroboros/string_test/RT0138-rt-String-VariableOfInterfaceTest/StringVariableOfInterfaceTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f3341cb78a7688f11bed9f0c133fed62c5eeee68 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0138-rt-String-VariableOfInterfaceTest/StringVariableOfInterfaceTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringVariableOfInterfaceTest.java + * -@TestCaseName: User Scene: interface use String as Filed and function param. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create a null String. + * -#step2: Check that null string is created correctly. + * -#step3: Create a string as the Filed of the interface. + * -#step4: Check that string created correctly. + * -#step5: Create a string as the param of function. + * -#step6: Check that string created correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringVariableOfInterfaceTest.java + * -@ExecuteClass: StringVariableOfInterfaceTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringVariableOfInterfaceTest implements StringVariableOfInterfaceTest_1 { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringVariableOfInterfaceTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + static String test(String str) { + String result = str + str; + System.out.println(result); + return result; + } + + public static void StringVariableOfInterfaceTest_1() { + String str = null; + System.out.println(str); + System.out.println(StringVariableOfInterfaceTest_1.str1_1); + + str = "abc"; + System.out.println(StringVariableOfInterfaceTest.test(str)); + } +} + +interface StringVariableOfInterfaceTest_1 { + static String str1_1 = "abc1_1"; + static void test(String str) { + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan null\s*abc1_1\s*abcabc\s*abcabc\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0139-rt-String-CreateStringArrayTest/StringCreateStringArrayTest.java b/test/testsuite/ouroboros/string_test/RT0139-rt-String-CreateStringArrayTest/StringCreateStringArrayTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8f2b394899d43f3c2fdab2058e96c705d10fd95e --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0139-rt-String-CreateStringArrayTest/StringCreateStringArrayTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringCreateStringArrayTest.java + * -@TestCaseName: Create String Array and Test String Array as param of function. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String array. + * -#step2: Check that String array is created correctly. + * -#step3: Create a string[] as param of function. + * -#step4: Check the return value of function is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringCreateStringArrayTest.java + * -@ExecuteClass: StringCreateStringArrayTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringCreateStringArrayTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringCreateStringArrayTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringCreateStringArrayTest_1() { + String[] strArray = {"a", "b", "c", "1", "2", "3"}; + System.out.println(strArray[1]); + System.out.println(test(strArray)[1]); + } + + private static String[] test(String[] str) { + for (int i = 0; i < str.length; i++) { + System.out.println(str[i]); + } + + str[1] = "B"; + return str; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan b\s*a\s*b\s*c\s*1\s*2\s*3\s*B\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0140-rt-String-GenericTest/StringGenericTest.java b/test/testsuite/ouroboros/string_test/RT0140-rt-String-GenericTest/StringGenericTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2191ee740af7144442978eb3e3835d5b2601af64 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0140-rt-String-GenericTest/StringGenericTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringGenericTest.java + * -@TestCaseName: User Scene: + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create ArrayList instance. + * -#step2: Add letters or numbers to the ArrayList. + * -#step3: Check the object belong to class java.util.ArrayList. + * -#step4: Check if return value is the second param of the template function. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringGenericTest.java + * -@ExecuteClass: StringGenericTest + * -@ExecuteArgs: + */ + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.io.PrintStream; + +public class StringGenericTest { + private static int processResult = 99; + + public static void main(String[] argv) throws IllegalAccessException, IllegalArgumentException, + InvocationTargetException, NoSuchMethodException, SecurityException { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringGenericTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 99) { + result = 0; + } + return result; + } + + public static void StringGenericTest_1() throws IllegalAccessException, IllegalArgumentException, + InvocationTargetException, NoSuchMethodException, SecurityException { + ArrayList arrayList1 = new ArrayList(); + arrayList1.add("abc"); + + ArrayList arrayList2 = new ArrayList(); + arrayList2.add(123); + + System.out.println(arrayList1.getClass() == arrayList2.getClass()); + + String str = StringGenericTest.add("1", "2"); + System.out.println(str); + } + + public static T add(T x, T y) { + return y; + } +} + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan true\s*2\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0141-rt-String-MultiThreadsTest/StringMultiThreadsTest.java b/test/testsuite/ouroboros/string_test/RT0141-rt-String-MultiThreadsTest/StringMultiThreadsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0e81e49b940e2ff68f1aa80615e9ec604524a0ce --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0141-rt-String-MultiThreadsTest/StringMultiThreadsTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringMultiThreadsTest.java + * -@TestCaseName: User Scene:multi-thread + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Inherit class Thread and override the run(). + * -#step2: Create ThreadGroup instance. + * -#step3: Name threads with string value. + * -#step4: Start all threads, check all threads run correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringMultiThreadsTest.java + * -@ExecuteClass: StringMultiThreadsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringMultiThreadsTest extends Thread { + static int retu = 1; + static int threadCount = 10; + static int stringCount = 10; + static int count = 0; + + public StringMultiThreadsTest(ThreadGroup group, String name) { + super(group, name); + } + + public void run() { + String[] str = new String[stringCount]; + for (int i = 0; i < stringCount; i++) { + str[i] = "ABC"; + count++; + + if (str[i] != "ABC") { + retu++; + } + } + } + + public static void main(String[] args) { + System.out.println(test(args, System.out)); + } + + public static int test(String[] args, PrintStream out) { + ThreadGroup thg = new ThreadGroup("threadg"); + String[] th = new String[threadCount]; + for (int i = 0; i < threadCount; i++) { + th[i] = "thread" + i; + new StringMultiThreadsTest(thg, th[i]).start(); + } + + try { + sleep(200); + } catch (InterruptedException e) { + } + + if (retu == 1) { + return 0; + } + return 2; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0142-rt-String-JoinNullPointerExceptionTest/StringJoinNullPointerExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0142-rt-String-JoinNullPointerExceptionTest/StringJoinNullPointerExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2db0b7176caa119460138065418e32fbc54dda6d --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0142-rt-String-JoinNullPointerExceptionTest/StringJoinNullPointerExceptionTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringJoinNullPointerExceptionTest.java + * -@TestCaseName: Test NullPointerException throw in String Method: static String join(CharSequence delimiter, + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * CharSequence... elements). + * -@Brief: + * -#step1: Create Parameters: delimiter is a null CharSequence, elements is a String array, element is null. + * -#step2: Test method join(CharSequence delimiter, CharSequence... elements). + * -#step3: NullPointerException is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: StringJoinNullPointerExceptionTest.java + * -@ExecuteClass: StringJoinNullPointerExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringJoinNullPointerExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringJoinNullPointerExceptionTest_1(null); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 97) { + result = 0; + } + return result; + } + + private static void StringJoinNullPointerExceptionTest_1(String str) { + try { + String[] test = new String[]{str, str, str}; + System.out.println(String.join(null, test)); + } catch (NullPointerException e) { + processResult -= 2; + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0143-rt-String-NullPointExceptionTest/StringNullPointExceptionTest.java b/test/testsuite/ouroboros/string_test/RT0143-rt-String-NullPointExceptionTest/StringNullPointExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ca0cdaa5002d9d84f4bc5949f22791ef66936f47 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0143-rt-String-NullPointExceptionTest/StringNullPointExceptionTest.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringNullPointExceptionTest.java + * -@TestCaseName: Test String Method: Test NullPointException throw in String Method: public char charAt (int + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * index), public char[] toCharArray (), public String substring (int beginIndex), public int + * compareTo (String anotherString), public String intern (), public String replace (CharSequence + * target, CharSequence replacement), public String concat (String str). + * -@Brief: + * -#case1 + * -#step1: Create String instance, parameter index < 0. + * -#step2: Test method charAt (int index), check StringIndexOutOfBoundsException is thrown. + * -#case2 + * -#step1: Create null String instance, parameter index >= 0. + * -#step2: Test method charAt (int index), check NullPointerException is thrown. + * -#case3 + * -#step1: Create null String instance. + * -#step2: Test method toCharArray(), check NullPointerException is thrown. + * -#case4 + * -#step1: Create null String instance, parameter beginIndex >= 0. + * -#step2: Test method substring (int beginIndex), check NullPointerException is thrown. + * -#case5 + * -#step1: Create null String instance, parameter anotherString as string instance. + * -#step2: Test method compareTo (String anotherString), check NullPointerException is thrown. + * -#case6 + * -#step1: Create null String instance. + * -#step2: Test method intern (), check NullPointerException is thrown. + * -#case7 + * -#step1: Create null String instance, parameter target/replacement as CharSequence instance. + * -#step2: Test method replace (CharSequence target, CharSequence replacement), check NullPointerException is thrown. + * -#case8 + * -#step1: Create null String instance, parameter str as String instance. + * -#step2: Test method concat (String str), check NullPointerException is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: StringNullPointExceptionTest.java + * -@ExecuteClass: StringNullPointExceptionTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringNullPointExceptionTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + StringNullPointExceptionTest_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 83) { + result = 0; + } + return result; + } + + public static void StringNullPointExceptionTest_1() { + String str2_1 = "abc123"; + String str2_5 = null; + + test0(str2_1); + test1(str2_5); + test2(str2_5); + test3(str2_5); + test4(str2_5); + test5(str2_5); + test6(str2_5); + test7(str2_5); + } + + private static void test0(String str) { + try { + char t0 = str.charAt(-2); + } catch (StringIndexOutOfBoundsException e) { + processResult -= 2; + } + } + + private static void test1(String str) { + try { + char t1 = str.charAt(0); + } catch (NullPointerException e) { + processResult -= 2; + } + } + + private static void test2(String str) { + char[] t2 = null; + try { + t2 = str.toCharArray(); + } catch (NullPointerException e) { + processResult -= 2; + } + } + + private static void test3(String str) { + String t3 = null; + try { + t3 = str.substring(1); + } catch (NullPointerException e) { + processResult -= 2; + } + } + + private static void test4(String str) { + try { + int t4 = str.compareTo("aaa"); + } catch (NullPointerException e) { + processResult -= 2; + } + } + + private static void test5(String str) { + try { + String t5 = str.intern(); + } catch (NullPointerException e) { + processResult -= 2; + } + } + + private static void test6(String str) { + try { + String t6 = str.replace("a", "b"); + } catch (NullPointerException e) { + processResult -= 2; + } + } + + private static void test7(String str) { + try { + String t7 = str.concat("aaa"); + } catch (NullPointerException e) { + processResult -= 2; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0144-rt-String-BufferExceptionsTest/StringBufferExceptionsTest.java b/test/testsuite/ouroboros/string_test/RT0144-rt-String-BufferExceptionsTest/StringBufferExceptionsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a0b03a0820ae856490fc986663896d009bcc4a86 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0144-rt-String-BufferExceptionsTest/StringBufferExceptionsTest.java @@ -0,0 +1,287 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBufferExceptionsTest.java + * -@TestCaseName: Test Exception in StringBuffer: test IndexOutOfBoundsException is thrown in public void + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin), test + * StringIndexOutOfBoundsException is thrown in public StringBuffer replace(int start, int end, + * String str), test StringIndexOutOfBoundsException is thrown in public String + * substring(int start, int end), test StringIndexOutOfBoundsException is thrown in public String + * substring(int start). + * -@Brief: + * -case1 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters:cover srcBegin/srcEnd < 0, srcBegin/srcEnd > instance.length, srcBegin > srcEnd, dstBegin + * < 0, dstBegin > dst.length, dst.length - dstBegin < srcEnd - srcBegin 8 scenes. + * -#step3: Test method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin), check IndexOutOfBoundsException is + * thrown. + * -case2 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters:cover start/end < 0, start > instance.length, start > end 4 scenes. + * -#step3: Test method replace(int start, int end, String str), check StringIndexOutOfBoundsException is thrown. + * -case3 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters:cover start/end < 0, start/end > instance.length, start > end 5 scenes. + * -#step3: Test method substring(int start, int end), check StringIndexOutOfBoundsException is thrown. + * -case4 + * -#step1: Create StringBuffer instance. + * -#step2: Create Parameters:cover start < 0, start > instance.length 2 scenes. + * -#step3: Test method substring(int start), check StringIndexOutOfBoundsException is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: StringBufferExceptionsTest.java + * -@ExecuteClass: StringBufferExceptionsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBufferExceptionsTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + result = StringBufferGetCharsIndexOutOfBoundsException_1(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBufferReplaceStringIndexOutOfBoundsException_2(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBufferSubstringStringIndexOutOfBoundsException_1(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBufferSubstringStringIndexOutOfBoundsException_2(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 2 && processResult == 80) { + result = 0; + } + return result; + } + + public static int StringBufferGetCharsIndexOutOfBoundsException_1() { + int result1 = 3; /*STATUS_FAILED*/ + + // IndexOutOfBoundsException- If either off or len is negative, or if off + len is greater than b.length. + // Test public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin). + StringBuffer buff = new StringBuffer("java programming"); + char[] chArr = new char[]{'t', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's'}; + + // Test dstBegin > dst.length. + try { + buff.getChars(5, 10, chArr, 30); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test dstBegin < 0. + try { + buff.getChars(5, 10, chArr, -2); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test dst.length - dstBegin < srcEnd - srcBegin. + try { + buff.getChars(5, 10, chArr, 7); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcBegin < 0. + try { + buff.getChars(-2, 10, chArr, 5); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcBegin > buff.length. + try { + buff.getChars(buff.length(), 10, chArr, 5); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcEnd < 0. + try { + buff.getChars(5, -2, chArr, 5); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcEnd < srcBegin. + try { + buff.getChars(5, 2, chArr, 5); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcEnd > buff.length. + try { + buff.getChars(5, buff.length(), chArr, 5); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + public static int StringBufferReplaceStringIndexOutOfBoundsException_2() { + int result1 = 3; /*STATUS_FAILED*/ + + // StringIndexOutOfBoundsException- Access parameter range of index. + // Test public StringBuffer replace(int start, int end, String str). + StringBuffer buff1 = new StringBuffer("HelloWorld"); + + // Test start > buff1.length. + try { + buff1.replace(20, 6, "QQQ"); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start < 0. + try { + buff1.replace(-2, 6, "QQQ"); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start > end. + try { + buff1.replace(7, 6, "QQQ"); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test end < 0. + try { + buff1.replace(7, -2, "QQQ"); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + public static int StringBufferSubstringStringIndexOutOfBoundsException_1() { + int result1 = 3; /*STATUS_FAILED*/ + + // StringIndexOutOfBoundsException- Intercept character string specifying scope, exceed the range error. + // Test public String substring(int start, int end). + StringBuffer buff2 = new StringBuffer("HelloWorld"); + + // Test end > buff2.length. + try { + String str = buff2.substring(9, 11); + System.out.println(str); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test end < 0. + try { + String str = buff2.substring(9, 11); + System.out.println(str); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start > buff2.length. + try { + String str = buff2.substring(11, 5); + System.out.println(str); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start > end. + try { + String str = buff2.substring(8, 5); + System.out.println(str); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start < 0. + try { + String str = buff2.substring(-2, 5); + System.out.println(str); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + public static int StringBufferSubstringStringIndexOutOfBoundsException_2() { + int result1 = 3; /*STATUS_FAILED*/ + + // StringIndexOutOfBoundsException- Intercept character string specifying scope, exceed the range error. + // Test public String substring(int start). + StringBuffer buff3 = new StringBuffer("HelloWorld"); + + // Test start > buff3.length. + try { + String str = buff3.substring(15); + System.out.println(str); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start < 0. + try { + String str = buff3.substring(-2); + System.out.println(str); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + result1 = 2; + processResult--; + } + return result1; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0145-rt-String-BuilderExceptionsTest/StringBuilderExceptionsTest.java b/test/testsuite/ouroboros/string_test/RT0145-rt-String-BuilderExceptionsTest/StringBuilderExceptionsTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f4606551c71ec41e3b965f619dde5eb2de971bd8 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0145-rt-String-BuilderExceptionsTest/StringBuilderExceptionsTest.java @@ -0,0 +1,485 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringBuilderExceptionsTest.java + * -@TestCaseName: Test Exception in StringBuilder: test StringIndexOutOfBoundsException is thrown in String + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * substring(int start, int end), test StringIndexOutOfBoundsException is thrown in String + * substring(int start), test IndexOutOfBoundsException is thrown in int codePointAt(int index), + * test IndexOutOfBoundsException is thrown in int codePointBefore(int index), test + * IndexOutOfBoundsException is thrown in int codePointCount(int beginIndex, int endIndex), test + * StringIndexOutOfBoundsException is thrown in StringBuilder + * replace(int start, int end, String str), test IndexOutOfBoundsException in void getChars(int + * srcBegin, int srcEnd, char[] dst, int dstBegin), test IndexOutOfBoundsException in int + * offsetByCodePoints(int index, int codePointOffset). + * -@Brief: + * -case1 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameters:cover start/end < 0, start/end > instance.length, start > end 5 scenes. + * -#step3: Test method substring(int start, int end), check StringIndexOutOfBoundsException is thrown. + * -case2 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameter: cover start < 0, start > instance.length 2 scenes. + * -#step3: Test method substring(int start), check StringIndexOutOfBoundsException is thrown. + * -case3 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameter: cover index < 0, index >= instance.length 2 scenes. + * -#step3: Test method codePointAt(int index), check IndexOutOfBoundsException is thrown. + * -case4 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameter: cover index < 0, index >= instance.length 2 scenes. + * -#step3: Test method codePointBefore(int index), check IndexOutOfBoundsException is thrown. + * -case5 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameter: cover beginIndex/endIndex < 0, beginIndex/endIndex > instance.length, beginIndex > + * endIndex 5 scenes. + * -#step3: Test method codePointCount(int beginIndex, int endIndex), check IndexOutOfBoundsException is thrown. + * -case6 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameter: cover start/end < 0, start/end > instance.length, start > end 5 scenes. + * -#step3: Test method replace(int start, int end, String str),check that if StringIndexOutOfBoundsException is thrown. + * -case7 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameter: cover srcBegin/srcEnd < 0, srcBegin/srcEnd > instance.length, srcBegin > srcEnd, dstBegin + * < 0, dstBegin > dst.length, dst.length - dstBegin < srcEnd - srcBegin 8 scenes. + * -#step3: Test method getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin), check IndexOutOfBoundsException is + * thrown. + * -case8 + * -#step1: Create StringBuilder instance. + * -#step2: Create Parameter: cover index < 0, index > instance.length, codePointOffset > stringBuilder.length - index + * 3 scenes. + * -#step3: Test method offsetByCodePoints(int index, int codePointOffset), check IndexOutOfBoundsException is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: StringBuilderExceptionsTest.java + * -@ExecuteClass: StringBuilderExceptionsTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringBuilderExceptionsTest { + private static int processResult = 99; + + public static void main(String argv[]) { + System.out.println(run(argv, System.out)); + } + + public static int run(String argv[], PrintStream out) { + int result = 2; /*STATUS_FAILED*/ + + try { + result = StringBuilderSubstringStringIndexOutOfBoundsException_1(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBuilderSubstringStringIndexOutOfBoundsException_2(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBuilderCodePointAtIndexOutOfBoundsException_1(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBuilderCodePointBeforeIndexOutOfBoundsException_1(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBuilderCodePointCountIndexOutOfBoundsException_1(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBuilderReplaceStringIndexOutOfBoundsException_1(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBuilderGetCharsIndexOutOfBoundsException_1(); + } catch (Exception e) { + processResult -= 10; + } + try { + result = StringBuilderOffsetByCodePointsIndexOutOfBoundsException_1(); + } catch (Exception e) { + processResult -= 10; + } + + if (result == 4 && processResult == 67) { + result = 0; + } + return result; + } + + // Test StringIndexOutOfBoundsException in String substring(int start, int end). + public static int StringBuilderSubstringStringIndexOutOfBoundsException_1() { + int result1 = 4; /* STATUS_FAILED */ + StringBuilder str = new StringBuilder("java is boring"); + + // Test end > str.length(). + try { + String test1 = str.substring(8, 20); + System.out.println(test1); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test end < 0. + try { + String test1 = str.substring(8, -2); + System.out.println(test1); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test end < start. + try { + String test1 = str.substring(8, 6); + System.out.println(test1); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start > str.length(). + try { + String test1 = str.substring(20, 6); + System.out.println(test1); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start < 0. + try { + String test1 = str.substring(-2, 6); + System.out.println(test1); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + // Test StringIndexOutOfBoundsException in String substring(int start). + public static int StringBuilderSubstringStringIndexOutOfBoundsException_2() { + int result1 = 4; /* STATUS_FAILED */ + StringBuilder str = new StringBuilder("java is boring"); + + // Test start > str.length. + try { + String test1 = str.substring(20); + System.out.println(test1); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start < 0. + try { + String test1 = str.substring(-2); + System.out.println(test1); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + // Test IndexOutOfBoundsException in int codePointAt(int index). + public static int StringBuilderCodePointAtIndexOutOfBoundsException_1() { + int result1 = 4; /* STATUS_FAILED */ + StringBuilder buff = new StringBuilder("programming"); + + // Test index >= stringBuilder.length. + try { + int str = buff.codePointAt(11); + System.out.println(str); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test index < 0. + try { + int str = buff.codePointAt(-1); + System.out.println(str); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + // Test IndexOutOfBoundsException in int codePointBefore(int index). + public static int StringBuilderCodePointBeforeIndexOutOfBoundsException_1() { + int result1 = 4; /* STATUS_FAILED */ + StringBuilder buff = new StringBuilder("HelloWorld"); + + // Test index > stringBuilder.length. + try { + int str = buff.codePointBefore(11); + System.out.println(str); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test index < 0. + try { + int str = buff.codePointBefore(-3); + System.out.println(str); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + // Test IndexOutOfBoundsException in int codePointCount(int beginIndex, int endIndex). + public static int StringBuilderCodePointCountIndexOutOfBoundsException_1() { + int result1 = 4; /*STATUS_FAILED*/ + StringBuilder buff = new StringBuilder("HelloWorld"); + + // Test endIndex > stringBuilder.length. + try { + int str = buff.codePointCount(5, 11); + System.out.println(str); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test endIndex < beginIndex. + try { + int str = buff.codePointCount(5, 4); + System.out.println(str); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test endIndex < 0. + try { + int str = buff.codePointCount(5, -2); + System.out.println(str); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test beginIndex < 0. + try { + int str = buff.codePointCount(-1, 5); + System.out.println(str); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test beginIndex > stringBuilder.length. + try { + int str = buff.codePointCount(11, 5); + System.out.println(str); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + // Test StringIndexOutOfBoundsException in StringBuilder replace(int start, int end, String str). + public static int StringBuilderReplaceStringIndexOutOfBoundsException_1() { + int result1 = 4; /* STATUS_FAILED */ + StringBuilder str = new StringBuilder("Java Util Package"); + + // Test end > stringBuilder.length. + try { + StringBuilder test1 = str.replace(18, 20, "Lang"); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test end < start. + try { + StringBuilder test1 = str.replace(18, 16, "Lang"); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test end < 0. + try { + StringBuilder test1 = str.replace(18, -2, "Lang"); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start < 0. + try { + StringBuilder test1 = str.replace(-2, 16, "Lang"); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + + // Test start > stringBuilder.length. + try { + StringBuilder test1 = str.replace(20, 16, "Lang"); + processResult -= 10; + } catch (StringIndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + // Test IndexOutOfBoundsException in void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin). + public static int StringBuilderGetCharsIndexOutOfBoundsException_1() { + int result1 = 4; /* STATUS_FAILED */ + StringBuilder str = new StringBuilder("java programming"); + char[] cArr = new char[]{'t', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's'}; + + // Test cArr.length - dstBegin < srcEnd - srcBegin + try { + str.getChars(5, 9, cArr, 6); + System.out.println(str); + System.out.println(cArr); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test dstBegin > cArr.length. + try { + str.getChars(0, 9, cArr, 10); + System.out.println(str); + System.out.println(cArr); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test dstBegin < 0. + try { + str.getChars(0, 9, cArr, -2); + System.out.println(str); + System.out.println(cArr); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcEnd < 0. + try { + str.getChars(0, -2, cArr, 0); + System.out.println(str); + System.out.println(cArr); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcBegin < 0. + try { + str.getChars(-2, 5, cArr, 0); + System.out.println(str); + System.out.println(cArr); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcBegin > srcEnd. + try { + str.getChars(5, 2, cArr, 0); + System.out.println(str); + System.out.println(cArr); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcBegin > stringBuilder.length. + try { + str.getChars(20, 2, cArr, 0); + System.out.println(str); + System.out.println(cArr); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test srcEnd > stringBuilder.length. + try { + str.getChars(2, 20, cArr, 0); + System.out.println(str); + System.out.println(cArr); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } + + // Test IndexOutOfBoundsException in int offsetByCodePoints(int index, int codePointOffset). + public static int StringBuilderOffsetByCodePointsIndexOutOfBoundsException_1() { + int result1 = 4; /* STATUS_FAILED */ + StringBuilder str = new StringBuilder("abcdefg"); + + // Test codePointOffset > stringBuilder.length - index. + try { + int result = str.offsetByCodePoints(1, 7); + System.out.println(str); + System.out.println(result); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test index < 0. + try { + int result = str.offsetByCodePoints(-1, 3); + System.out.println(str); + System.out.println(result); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + + // Test index > stringBuilder.length. + try { + int result = str.offsetByCodePoints(8, 0); + System.out.println(str); + System.out.println(result); + processResult -= 10; + } catch (IndexOutOfBoundsException e1) { + processResult--; + } + return result1; + } +} + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0146-rt-String-ClassNewInstanceTest/StringClassNewInstanceTest.java b/test/testsuite/ouroboros/string_test/RT0146-rt-String-ClassNewInstanceTest/StringClassNewInstanceTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b4e47aa342d2af3555adc9514a03797a8dae5354 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0146-rt-String-ClassNewInstanceTest/StringClassNewInstanceTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringClassNewInstanceTest.java + * -@TestCaseName: Calling String's no-argument constructor by reflection String.class.newInstance(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Test String.class.newInstance(). + * -#step2: Check newInstance() is correctly, and no Exception is thrown. + * -@Expect: 0\n + * -@Priority: High + * -@Source: StringClassNewInstanceTest.java + * -@ExecuteClass: StringClassNewInstanceTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringClassNewInstanceTest { + private static int processResult = 99; + + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + + try { + StringClassNewInstanceTest_1(); + } catch (Exception e) { + processResult -= 10; + } + if (result == 2 && processResult == 98) { + result = 0; + } + return result; + } + + public static void StringClassNewInstanceTest_1() { + Object test1 = null; + try { + test1 = String.class.newInstance(); + processResult--; + } catch (InstantiationException e1) { + System.err.println(e1); + } catch (IllegalAccessException e2) { + System.err.println(e2); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0147-rt-String-PoolEnlargeTest/StringPoolEnlargeTest.java b/test/testsuite/ouroboros/string_test/RT0147-rt-String-PoolEnlargeTest/StringPoolEnlargeTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a58c535074650fc6042e753f81faf038acde36e3 --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0147-rt-String-PoolEnlargeTest/StringPoolEnlargeTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringPoolEnlargeTest.java + * -@TestCaseName: Test mapleStringPool large and large by public String intern(). + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create String instance by Integer.toHexString(int index), index cover 0 to 47000. + * -#step2: Test method intern(), check get result correctly. + * -#step3: Change String instance create by Integer.toHexString(int index), index cover 0 to 470000, repeat step 2. + * -@Expect: 0\n + * -@Priority: High + * -@Source: StringPoolEnlargeTest.java + * -@ExecuteClass: StringPoolEnlargeTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; + +public class StringPoolEnlargeTest { + private static int processResult = 99; + public static void main(String[] argv) { + System.out.println(run(argv, System.out)); + } + + public static int run(String[] argv, PrintStream out) { + int result = 2; /* STATUS_Success */ + try { + result = result - StringPoolEnlargeTest_1(47000); + result = result - StringPoolEnlargeTest_1(470000); + } catch (Exception e) { + System.out.println(e); + StringPoolEnlargeTest.processResult = StringPoolEnlargeTest.processResult - 10; + } + + if (result == 0 && StringPoolEnlargeTest.processResult == 95) { + result = 0; + } + return result; + } + + public static int StringPoolEnlargeTest_1(int len) { + int length = len; // 47 mapleStringPool/process, 1000 key-value/mapleStringPool + try { + String[] s; + s = new String[length]; + for (int i = 0; i < length; i++) { + s[i] = Integer.toHexString(i); + if (s[i].intern() == Integer.toHexString(func1(len-1)).intern()) { + StringPoolEnlargeTest.processResult = StringPoolEnlargeTest.processResult - 2; + return 1; + } + } + } catch (OutOfMemoryError e) { + return 114; + } + StringPoolEnlargeTest.processResult = StringPoolEnlargeTest.processResult - 10; + return 102; + } + + public static int func1(int i) { + return i; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/string_test/RT0148-rt-String-XByteTest/StringXByteTest.java b/test/testsuite/ouroboros/string_test/RT0148-rt-String-XByteTest/StringXByteTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3ddab529118574e94febcafbff8f156c7e2c17cc --- /dev/null +++ b/test/testsuite/ouroboros/string_test/RT0148-rt-String-XByteTest/StringXByteTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StringXByteTest.java + * -@TestCaseName: Test String(byte[] bytes), bytes cover 1、2、3、4 byte. + * -@TestCaseType: Function Test + * -@RequirementName: Java字符串实现 + * -@Brief: + * -#step1: Create string value and get the random string byte by string value. + * -#step2: Get byte array by random string cover with 1、2、3、4 byte. + * -#step3: Test constructor String(byte[] bytes), check the byte array change to string is correctly. + * -@Expect: expected.txt + * -@Priority: High + * -@Source: StringXByteTest.java + * -@ExecuteClass: StringXByteTest + * -@ExecuteArgs: + */ + +import java.io.PrintStream; +import java.io.*; +import java.util.Random; + +public class StringXByteTest { + static int seed = 20; + static Random random = new Random(seed); + + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + public static int run(String[] args, PrintStream out) { + int result = 2; + + try { + result = StringXByteTest1(); + } catch (Exception e) { + e.printStackTrace(); + } + + if (result == 1 ) { + result = 0; + } + return result; + } + + public static int StringXByteTest1() { + String string_byte1 = getByteString(1); + String string_byte2 = getByteString(2); + String string_byte3 = getByteString(3); + String string_byte4 = getByteString(4); + + byte[] by = new byte[]{(byte) 0x59,(byte) 0xCF,(byte) 0xB9,(byte) 0xE2,(byte) 0xA2,(byte) 0xA4, + (byte) 0xF3,(byte) 0x90,(byte) 0xA2,(byte) 0x85}; + + if ((string_byte1+string_byte2+string_byte3+string_byte4).equals(new String(by))) { + return 1; + } + return 3; + } + + public static String getByteString(int lengthIn) { + String strCd = "CD"; + String str0f = "0123456789ABCDEF"; + String str8b = "89AB"; + String str07 = "01234567"; + String hexString = "0123456789ABCDEF"; + StringBuffer byte5= new StringBuffer(); + + if (lengthIn == 1) { + // 1Byte: 0-7|0-F + byte5.append(str07.charAt( random.nextInt(8))); // 0-7 + byte5.append(str0f.charAt( random.nextInt(16))); // 0-F + }else if (lengthIn == 2) { + // 2Byte: C-D|0-F 8-B|0-F + byte5.append(strCd.charAt(random.nextInt(2))); + byte5.append(str0f.charAt(random.nextInt(16))); + byte5.append(str8b.charAt(random.nextInt(4))); + byte5.append(str0f.charAt(random.nextInt(16))); + }else if (lengthIn == 3) { + // 3Byte: E|0-F 8-B|0-F 8-B|0-F + byte5.append("E"); + byte5.append(str0f.charAt(random.nextInt(16))); + byte5.append(str8b.charAt(random.nextInt(4))); + byte5.append(str0f.charAt(random.nextInt(16))); + byte5.append(str8b.charAt(random.nextInt(4))); + byte5.append(str0f.charAt(random.nextInt(16))); + }else if (lengthIn == 4) { + // 4Byte: F|0-7 8-B|0-F 8-B|0-F 8-B|0-F + byte5.append("F"); + byte5.append(str07.charAt(random.nextInt(8))); + byte5.append(str8b.charAt(random.nextInt(4))); + byte5.append(str0f.charAt(random.nextInt(16))); + byte5.append(str8b.charAt(random.nextInt(4))); + byte5.append(str0f.charAt(random.nextInt(16))); + byte5.append(str8b.charAt(random.nextInt(4))); + byte5.append(str0f.charAt(random.nextInt(16))); + } + + ByteArrayOutputStream scb=new ByteArrayOutputStream(byte5.length()/2); + for(int i=0;i0 ) { + loop--; + try { + s = new String(Integer.toBinaryString(loop)); + } catch (OutOfMemoryError e) { + processResult = processResult - 2; + return 1; + } + } + System.out.println("s: "+ s); + processResult = processResult - 10; + return 40; + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0001-rt-compiler-LiverangeSubsumeRCTest01/LiverangeSubsumeRCTest01.java b/test/testsuite/ouroboros/subsumeRC_test/RT0001-rt-compiler-LiverangeSubsumeRCTest01/LiverangeSubsumeRCTest01.java new file mode 100755 index 0000000000000000000000000000000000000000..3d7a7adf6f9e10a221f9c29b706da30adae2226b --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0001-rt-compiler-LiverangeSubsumeRCTest01/LiverangeSubsumeRCTest01.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest01 + *- @TestCaseName: LiverangeSubsumeRCTest01 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1: 创建一个1个数组,先后用array1指针和array2指针指向了它; + * -#step2: 数组越界式的用一下这俩数组指针,第27行代码可以看出,array1指针存活状态包含了array2,所以array2的incref和decref都应该被优化掉。 + * -#step3: str1 和str2同时指向一个字符串,str1指针存活状态包含了str2,所以str2的incref和decref都应该被优化掉。 + * 校验中间文件LiverangeSubsumeRCTest01.VtableImpl.mpl中无IncRef + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest01.java + *- @ExecuteClass: LiverangeSubsumeRCTest01 + *- @ExecuteArgs: + */ + +public class LiverangeSubsumeRCTest01 { + public static void main(String[] args) { + int[] array1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + int[] array2 = array1; + String str1 = "ExpectResult"; + String str2 = str1; + try { + if (array2[10] == array1[10]) { + System.out.print(str2); // 错误输出 + } + } catch (Exception e) { + System.out.println(str1); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0002-rt-compiler-LiverangeSubsumeRCTest02/LiverangeSubsumeRCTest02.java b/test/testsuite/ouroboros/subsumeRC_test/RT0002-rt-compiler-LiverangeSubsumeRCTest02/LiverangeSubsumeRCTest02.java new file mode 100755 index 0000000000000000000000000000000000000000..608192a6300765d7fb10b85884080e8398f7af66 --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0002-rt-compiler-LiverangeSubsumeRCTest02/LiverangeSubsumeRCTest02.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest02 + *- @TestCaseName: LiverangeSubsumeRCTest02 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的不在某个生存区间内的存活状态时,不能去掉这个区间内的此对象的RC操作 + * -#step1: 创建一个1个数组,先后用array1指针和array2指针指向了它; + * -#step2: 数组越界式的用一下这俩数组指针,第29行代码可以看出,array1指针存活状态和array2相同,array2的incref和decref都能被优化掉。 + * -#step3: str1 和str2同时指向一个字符串,str1指针存活状态不能包含str2,所以str2的incref和decref都不能被优化掉。 + * 校验中间文件LiverangeSubsumeRCTest01.VtableImpl.mpl无IncRef + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest02.java + *- @ExecuteClass: LiverangeSubsumeRCTest02 + *- @ExecuteArgs: + */ +public class LiverangeSubsumeRCTest02 { + public static void main(String[] args) { + int[] array1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + int[] array2 = array1; + String str1 = "ExpectResult"; + String str2 = str1; //被优化掉了 + try { + if (array1[10] == array2[10]) { + System.out.print(str1); // 错误输出 + } + } catch (Exception e) { + System.out.println(str2); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0003-rt-compiler-LiverangeSubsumeRCTest03/LiverangeSubsumeRCTest03.java b/test/testsuite/ouroboros/subsumeRC_test/RT0003-rt-compiler-LiverangeSubsumeRCTest03/LiverangeSubsumeRCTest03.java new file mode 100755 index 0000000000000000000000000000000000000000..32724f2340f613833d95bb42125408f40fbc6db8 --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0003-rt-compiler-LiverangeSubsumeRCTest03/LiverangeSubsumeRCTest03.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest03 + *- @TestCaseName: LiverangeSubsumeRCTest03 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1: 创建一个1个数组,先后用array1、array2、array3指针指向了它; + * -#step2: str1、str2和str3同时指向一个字符串,step1和step2里他们的生命周期都是按照这个流程来的: + * incref(array1) + * array2 = array1 incref优化掉 + * array3 = array2 incref优化掉 + * decref(array2) 优化掉 + * decref(array3) 优化掉 + * decref(array1) + * -#step3: + * 校验中间文件LiverangeSubsumeRCTest01.VtableImpl.mpl中无IncRef + *- @Expect:falsefalseExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest03.java + *- @ExecuteClass: LiverangeSubsumeRCTest03 + *- @ExecuteArgs: + */ + +public class LiverangeSubsumeRCTest03 { + public static void main(String[] args) { + int[] array1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + int[] array2 = array1; + int[] array3 = array2; + String str1 = "ExpectResult"; + String str2 = str1; + String str3 = str2; + boolean check = String.valueOf(array2[0]).equals(str2); // false + System.out.print(check); + check = String.valueOf(array3[1]) == str3; + System.out.print(check); // false + if (array1.length == 10) { + System.out.println(str1); + } else { + System.out.print(str1); // 错误输出,无换行符 + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan falsefalseExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0004-rt-compiler-LiverangeSubsumeRCTest04/LiverangeSubsumeRCTest04.java b/test/testsuite/ouroboros/subsumeRC_test/RT0004-rt-compiler-LiverangeSubsumeRCTest04/LiverangeSubsumeRCTest04.java new file mode 100755 index 0000000000000000000000000000000000000000..12349668f1686e4a63cb519923e124f38bde9c0d --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0004-rt-compiler-LiverangeSubsumeRCTest04/LiverangeSubsumeRCTest04.java @@ -0,0 +1,286 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest04 + *- @TestCaseName: LiverangeSubsumeRCTest04 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1: 构造是个类对象A1、A2、A3···A10,他们同时有实例变量同时指向一块内存地址b1; + * -#step2: b1的生命周期包含了这十个成员变量(A1···A10)的生命周期。代码51行--66行不再出现实例变量 + * -#step3: A1到A10的十个实例变量的incref和decRef都应该被优化掉都应该被优化掉。 + * 校验中间文件LiverangeSubsumeRCTest04.VtableImpl.mpl无IncRef。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest04.java + *- @ExecuteClass: LiverangeSubsumeRCTest04 + *- @ExecuteArgs: + */ + +public class LiverangeSubsumeRCTest04 { + + public static void main(String[] args) { + rc_testcase_main_wrapper(); + } + + private static void rc_testcase_main_wrapper() { + LiverangeSubsumeRCTest04_A1 a1_main = new LiverangeSubsumeRCTest04_A1("a1_main"); + LiverangeSubsumeRCTest04_A2 a2_main = new LiverangeSubsumeRCTest04_A2("a2_main"); + LiverangeSubsumeRCTest04_A3 a3_main = new LiverangeSubsumeRCTest04_A3("a3_main"); + LiverangeSubsumeRCTest04_A4 a4_main = new LiverangeSubsumeRCTest04_A4("a4_main"); + LiverangeSubsumeRCTest04_A5 a5_main = new LiverangeSubsumeRCTest04_A5("a5_main"); + LiverangeSubsumeRCTest04_A6 a6_main = new LiverangeSubsumeRCTest04_A6("a6_main"); + LiverangeSubsumeRCTest04_A7 a7_main = new LiverangeSubsumeRCTest04_A7("a7_main"); + LiverangeSubsumeRCTest04_A8 a8_main = new LiverangeSubsumeRCTest04_A8("a8_main"); + LiverangeSubsumeRCTest04_A9 a9_main = new LiverangeSubsumeRCTest04_A9("a9_main"); + LiverangeSubsumeRCTest04_A10 a10_main = new LiverangeSubsumeRCTest04_A10("a10_main"); + LiverangeSubsumeRCTest04_B1 b1 = new LiverangeSubsumeRCTest04_B1("b1_0"); + a1_main.b1_0 = b1; + a2_main.b1_0 = b1; + a3_main.b1_0 = b1; + a4_main.b1_0 = b1; + a5_main.b1_0 = b1; + a6_main.b1_0 = b1; + a7_main.b1_0 = b1; + a8_main.b1_0 = b1; + a9_main.b1_0 = b1; + a10_main.b1_0 = b1; + a1_main.add(); + a2_main.add(); + a3_main.add(); + a4_main.add(); + a5_main.add(); + a6_main.add(); + a7_main.add(); + a8_main.add(); + a9_main.add(); + a10_main.add(); + b1.add(); + int result = a1_main.sum + a2_main.sum + a3_main.sum + a4_main.sum + a5_main.sum + a6_main.sum + a7_main.sum + a8_main.sum + a9_main.sum + a10_main.sum + b1.sum; + if (result == 3467) + System.out.println("ExpectResult"); + } +} + +class LiverangeSubsumeRCTest04_A1 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A1(String strObjectName) { + b1_0 = null; + a = 101; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A1_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + +class LiverangeSubsumeRCTest04_A2 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A2(String strObjectName) { + b1_0 = null; + a = 102; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A2_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + + +class LiverangeSubsumeRCTest04_A3 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A3(String strObjectName) { + b1_0 = null; + a = 103; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A3_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + +class LiverangeSubsumeRCTest04_A4 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A4(String strObjectName) { + b1_0 = null; + a = 104; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A4_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + +class LiverangeSubsumeRCTest04_A5 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A5(String strObjectName) { + b1_0 = null; + a = 105; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A5_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + + +class LiverangeSubsumeRCTest04_A6 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A6(String strObjectName) { + b1_0 = null; + a = 106; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A6_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + +class LiverangeSubsumeRCTest04_A7 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A7(String strObjectName) { + b1_0 = null; + a = 107; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A7_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + +class LiverangeSubsumeRCTest04_A8 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A8(String strObjectName) { + b1_0 = null; + a = 108; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A8_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + +class LiverangeSubsumeRCTest04_A9 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A9(String strObjectName) { + b1_0 = null; + a = 109; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A9_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + +class LiverangeSubsumeRCTest04_A10 { + LiverangeSubsumeRCTest04_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_A10(String strObjectName) { + b1_0 = null; + a = 110; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_A10_"+strObjectName); + } + + void add() { + sum = a + b1_0.a; + } +} + + +class LiverangeSubsumeRCTest04_B1 { + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest04_B1(String strObjectName) { + a = 201; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_B1_"+strObjectName); + } + + void add() { + sum = a + a; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0005-rt-compiler-LiverangeSubsumeRCTest05/LiverangeSubsumeRCTest05.java b/test/testsuite/ouroboros/subsumeRC_test/RT0005-rt-compiler-LiverangeSubsumeRCTest05/LiverangeSubsumeRCTest05.java new file mode 100755 index 0000000000000000000000000000000000000000..c6bfb07a3881b787b333dc2689bc33090ae487a6 --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0005-rt-compiler-LiverangeSubsumeRCTest05/LiverangeSubsumeRCTest05.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest05 + *- @TestCaseName: LiverangeSubsumeRCTest05 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1: 构造是个同一个类对象的引用指针test1,test2,test3和test4,他们同时有实例变量同时指向一块内存地址b1; + * -#step2: b1的生命周期包含了这test1.b1_0,test2.b1_0和test3.b1_0的生命周期,没有包含test4.b1_0的生命周期。 + * -#step3: test1.b1_0,test2.b1_0和test3.b1_0的incref和decRef都应该被优化掉都应该被优化掉;test4.b1_0的incref和decRef被保留。 + * 校验中间文件LiverangeSubsumeRCTest05.VtableImpl.mpl中无IncRef。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest05.java + *- @ExecuteClass: LiverangeSubsumeRCTest05 + *- @ExecuteArgs: + */ + +public class LiverangeSubsumeRCTest05 { + public static void main(String[] args) { + LiverangeSubsumeRCTest05_Node test1 = new LiverangeSubsumeRCTest05_Node("test1"); + LiverangeSubsumeRCTest05_Node test2 = new LiverangeSubsumeRCTest05_Node("test2"); + LiverangeSubsumeRCTest05_Node test3 = new LiverangeSubsumeRCTest05_Node("test3"); + LiverangeSubsumeRCTest05_Node test4 = new LiverangeSubsumeRCTest05_Node("test4"); + LiverangeSubsumeRCTest05_B1 b1 = new LiverangeSubsumeRCTest05_B1("b1"); + test1.b1_0 = b1; + test2.b1_0 = b1; + test3.b1_0 = b1; + test4.b1_0 = b1; + test1.b1_0.add(); + test2.b1_0.add(); + test3.b1_0.add(); + test4.b1_0.add(); + b1.add(); + int result = test1.sum + test2.sum + test3.sum + test4.sum + test4.b1_0.sum; + if (result == 402) { + System.out.println("ExpectResult"); + } + } +} + +class LiverangeSubsumeRCTest05_Node { + LiverangeSubsumeRCTest05_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest05_Node(String strObjectName) { + b1_0 = null; + a = 101; + sum = 0; + this.strObjectName = strObjectName; + } + + void add() { + sum = a + b1_0.a; + } +} + +class LiverangeSubsumeRCTest05_B1 { + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest05_B1(String strObjectName) { + a = 201; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_B1_"+strObjectName); + } + + void add() { + sum = a + a; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0006-rt-compiler-LiverangeSubsumeRCTest06/LiverangeSubsumeRCTest06.java b/test/testsuite/ouroboros/subsumeRC_test/RT0006-rt-compiler-LiverangeSubsumeRCTest06/LiverangeSubsumeRCTest06.java new file mode 100755 index 0000000000000000000000000000000000000000..01cc960238172b402ba3a926168263c121608c5c --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0006-rt-compiler-LiverangeSubsumeRCTest06/LiverangeSubsumeRCTest06.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest06 + *- @TestCaseName: LiverangeSubsumeRCTest06 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1: 构造是个同一个类对象的引用指针test1,test2,test3和test4,他们同时指向一块内存地址,并且他们的实例变量b1_0同时指向一块内存地址b1; + * -#step2: test1的生命周期包含了test2,test3 和test4,所以test2,test3和test4的incref和dec ref都应该被优化掉。 + * -#step3: b1指针的生命周期包含了四个b1_0的生命周期,四个b1_0的incref,decref应该被优化掉 + * 校验中间文件LiverangeSubsumeRCTest06.VtableImpl.mpl无IncRef + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest06.java + *- @ExecuteClass: LiverangeSubsumeRCTest06 + *- @ExecuteArgs: + */ + +public class LiverangeSubsumeRCTest06 { + public static void main(String[] args) { + LiverangeSubsumeRCTest06_Node test1 = new LiverangeSubsumeRCTest06_Node("test1"); + LiverangeSubsumeRCTest06_Node test2 = test1; + LiverangeSubsumeRCTest06_Node test3 = test1; + LiverangeSubsumeRCTest06_Node test4 = test1; + LiverangeSubsumeRCTest06_B1 b1 = new LiverangeSubsumeRCTest06_B1("b1"); + test2.b1_0 = b1; + test2.b1_0.add(); + test3.b1_0 = b1; + test3.b1_0.add(); + test4.b1_0 = b1; + test4.b1_0.add(); + test1.b1_0 = b1; + test1.b1_0.add(); + int result = test1.sum + b1.sum; + if (result == 402) { + System.out.println("ExpectResult"); + } + } +} + +class LiverangeSubsumeRCTest06_Node { + LiverangeSubsumeRCTest06_B1 b1_0; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest06_Node(String strObjectName) { + b1_0 = null; + a = 101; + sum = 0; + this.strObjectName = strObjectName; + } + + void add() { + sum = a + b1_0.a; + } +} + +class LiverangeSubsumeRCTest06_B1 { + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest06_B1(String strObjectName) { + a = 201; + sum = 0; + this.strObjectName = strObjectName; +// System.out.println("RC-Testing_Construction_B1_"+strObjectName); + } + + void add() { + sum = a + a; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0007-rt-compiler-LiverangeSubsumeRCTest07/LiverangeSubsumeRCTest07.java b/test/testsuite/ouroboros/subsumeRC_test/RT0007-rt-compiler-LiverangeSubsumeRCTest07/LiverangeSubsumeRCTest07.java new file mode 100755 index 0000000000000000000000000000000000000000..ab9e80fb71422bbadd7c78e0c9f5c0320456198e --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0007-rt-compiler-LiverangeSubsumeRCTest07/LiverangeSubsumeRCTest07.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest07 + *- @TestCaseName: LiverangeSubsumeRCTest07 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作:自成环的场景应该会被优化 + * -#step1: test07与test07./,而且test07.next的生命周期被test07包含,所以 test07.next的incref和dec ref都应该被优化掉。 + * -#step2: 这样RC的自成环问题会被优化掉,该种场景仅通过RC就可以做到内存回收 + * 校验中间文件LiverangeSubsumeRCTest07.VtableImpl.mpl中无IncRef。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest07.java + *- @ExecuteClass: LiverangeSubsumeRCTest07 + *- @ExecuteArgs: + */ +public class LiverangeSubsumeRCTest07 { + LiverangeSubsumeRCTest07 next; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest07(String strObjectName) { + next = null; + a = 101; + sum = 0; + this.strObjectName = strObjectName; + } + + public static void main(String[] args) { + LiverangeSubsumeRCTest07 test07 = new LiverangeSubsumeRCTest07("test1"); + test07.next = test07; // 使用intrinsiccall MCCWriteNoDec()代替 + test07.next.add(); + test07.add(); + if (test07.sum == 202) { + System.out.println("ExpectResult"); + } else { + System.out.println(test07.sum); + } + } + + void add() { + sum = a + next.a; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0008-rt-compiler-LiverangeSubsumeRCTest08/LiverangeSubsumeRCTest08.java b/test/testsuite/ouroboros/subsumeRC_test/RT0008-rt-compiler-LiverangeSubsumeRCTest08/LiverangeSubsumeRCTest08.java new file mode 100755 index 0000000000000000000000000000000000000000..595b521af95dfba04696dbfe30f749e8c451fa5d --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0008-rt-compiler-LiverangeSubsumeRCTest08/LiverangeSubsumeRCTest08.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest08 + *- @TestCaseName: LiverangeSubsumeRCTest08 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作:两个对象成环的场景应该会被优化 + * -#step1: test1与test1.next是两个不同的对象,占用不同的内存空间,而且test08.next.next的生命周期被test1包含,所以 test08.next的incref和dec ref都应该被优化掉。 + * -#step2: 这样RC的自成环问题会被优化掉,该种场景仅通过RC就可以做到内存回收 + * 校验中间文件LiverangeSubsumeRCTest08.VtableImpl.mpl中无IncRef。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest08.java + *- @ExecuteClass: LiverangeSubsumeRCTest08 + *- @ExecuteArgs: + */ +public class LiverangeSubsumeRCTest08 { + LiverangeSubsumeRCTest08 next; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest08(String strObjectName) { + next = null; + a = 101; + sum = 0; + this.strObjectName = strObjectName; + } + + public static void main(String[] args) { + LiverangeSubsumeRCTest08 test1 = new LiverangeSubsumeRCTest08("test1"); + test1.next = new LiverangeSubsumeRCTest08("test2"); + test1.next.next = test1; + test1.next.add(); + test1.next.next.add(); + test1.add(); + if (test1.sum == 202) { + System.out.println("ExpectResult"); + } else { + System.out.println(test1.sum); + } + } + + void add() { + sum = a + next.a; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0009-rt-compiler-LiverangeSubsumeRCTest09/LiverangeSubsumeRCTest09.java b/test/testsuite/ouroboros/subsumeRC_test/RT0009-rt-compiler-LiverangeSubsumeRCTest09/LiverangeSubsumeRCTest09.java new file mode 100755 index 0000000000000000000000000000000000000000..ff86abc2c3c945c76bdeaae0eb4c67a3c9d9d7e7 --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0009-rt-compiler-LiverangeSubsumeRCTest09/LiverangeSubsumeRCTest09.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest09 + *- @TestCaseName: LiverangeSubsumeRCTest09 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作:n(n>=3)个对象成环的场景应该会被优化 + * -#step1: test9与它后面的next是总共5个不同的对象,并且自成环,而且并且后面的所有next的生命周期被test9包含,所以所有的.next的incref和dec ref都应该被优化掉。 + * -#step2: 这样RC的自成环问题也会被优化掉,该种场景仅通过RC就可以做到内存回收 + * 校验中间文件LiverangeSubsumeRCTest09.VtableImpl.mpl中无IncRef + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest09.java + *- @ExecuteClass: LiverangeSubsumeRCTest09 + *- @ExecuteArgs: + */ +public class LiverangeSubsumeRCTest09 { + LiverangeSubsumeRCTest09 next; + int a; + int sum; + String strObjectName; + + LiverangeSubsumeRCTest09(String strObjectName) { + next = null; + a = 101; + sum = 0; + this.strObjectName = strObjectName; + } + + public static void main(String[] args) { + LiverangeSubsumeRCTest09 test9 = new LiverangeSubsumeRCTest09("test9"); + test9.next = new LiverangeSubsumeRCTest09("test2"); + test9.next.next = new LiverangeSubsumeRCTest09("test3"); + test9.next.next.next = new LiverangeSubsumeRCTest09("test4"); + test9.next.next.next.next = new LiverangeSubsumeRCTest09("test5"); + test9.next.next.next.next = test9; + test9.next.next.next.next.add(); + test9.add(); + if (test9.sum == 202) { + System.out.println("ExpectResult"); + } else { + System.out.println(test9.next.sum); + } + } + + void add() { + sum = a + next.a; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0010-rt-compiler-LiverangeSubsumeRCTest10/LiverangeSubsumeRCTest10.java b/test/testsuite/ouroboros/subsumeRC_test/RT0010-rt-compiler-LiverangeSubsumeRCTest10/LiverangeSubsumeRCTest10.java new file mode 100755 index 0000000000000000000000000000000000000000..6e2a69592bc2f4eeb74cc08245478ac80f9fedb2 --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0010-rt-compiler-LiverangeSubsumeRCTest10/LiverangeSubsumeRCTest10.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest10 + *- @TestCaseName: LiverangeSubsumeRCTest10 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:检测在循环语句(for, while, do-while)控制流中,当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1:函数1测试场景:周期大的对象a1初始化在for循环外,只在for循环内部使用生命周期小的a2;a2的incref和decRef都应该被优化掉 + * -#step2:函数2测试场景:周期大的对象a1和生命周期小的对象a2对象初始化和使用都在for循环内,因为a1的生命周期完全覆盖了a2的生命周期,a2的incref和decRef都应该被优化掉; + * -#step3:函数3测试场景:对象初始化在do-while循环内,循环之后,仍有使用;a2的生命周期因为被完全覆盖,所以它的incref和decRef都应该被优化掉; + * 校验中间文件LiverangeSubsumeRCTest10.VtableImpl.mpl中无IncRef。 + *- @Expect:a1_1a1_1a1_1a1_1a1_1a1_1a1_1a1_1a1_1a1_1100ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest10.java + *- @ExecuteClass: LiverangeSubsumeRCTest10 + *- @ExecuteArgs: + */ +class A { + public int count = 0; + public String className = "A"; + + public A(String name) { + this.className = name; + } + + public void changeName(String name) { + this.className = name; + } +} + +public class LiverangeSubsumeRCTest10 { + private static volatile int count = 0; + private static A infiniteLoop = null; + private A defInsideUseOutside = null; + + public static boolean onlyUseInsideLoop() { + A a1 = new A("a1"); + for (count = 0; count < 100; count++) { + A a2 = a1; + a2.changeName("a" + count); + a2.count = count; + if (count == 99) + a2.toString(); + } + return a1.className.equals("a99"); + } + + public static void defAndUseInsideLoop() { + for (count = 0; count < 10; count++) { + A a1 = new A("a1_" + count); + a1.changeName("a1"); + A a2 = a1; + for (int j = 0; j < 2; j++) { + a2.changeName("a1_" + j); + } + System.out.print(a1.className); + } + } + + public static void main(String[] args) { + defAndUseInsideLoop(); + new LiverangeSubsumeRCTest10().defInsideAndUseOutsideLoop(); + if (onlyUseInsideLoop()) { + System.out.println("ExpectResult"); + } else { + System.out.println("ErrorResult"); + } + } + + public void defInsideAndUseOutsideLoop() { + count = 0; + do { + this.defInsideUseOutside = new A("a1_i" + count); + A a2 = this.defInsideUseOutside; + a2.count = count; + for (int j = 0; j < 2; j++) + a2 = new A("a2_i" + count + "_j" + j); + if (count == 99) + a2.toString(); + count++; + } while (this.defInsideUseOutside.count < 100 && count < 100); + System.out.print(count); + } + + +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan a1_1a1_1a1_1a1_1a1_1a1_1a1_1a1_1a1_1a1_1100ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0011-rt-compiler-LiverangeSubsumeRCTest11/LiverangeSubsumeRCTest11.java b/test/testsuite/ouroboros/subsumeRC_test/RT0011-rt-compiler-LiverangeSubsumeRCTest11/LiverangeSubsumeRCTest11.java new file mode 100755 index 0000000000000000000000000000000000000000..cdf0f93a9589929f0663b0717cb7795064d108b1 --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0011-rt-compiler-LiverangeSubsumeRCTest11/LiverangeSubsumeRCTest11.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest11 + *- @TestCaseName: LiverangeSubsumeRCTest11 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:检测在循环语句(if-then, if-then-else, switch)控制流中,当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1:函数1测试场景:周期大的对象a1初始化在for循环外,只在for循环内部使用生命周期小的a2;a1的最后调用放到for循环外的if语句里,a2的incRef和decRef会被优化掉。 + * -#step2:函数2测试场景:a2 = a1,q且在for循环内使用,在if逻辑体,a2的incref和decRef不会被优化掉,在else逻辑体内,a2的incRef和decRef会被优化掉。 + * -#step3:函数3测试场景:a2 =a1,在不同的switch--多case里,case1:a1包含了a2,会有优化;case2:没有包含住,不做优化;case3:无代码;case4: a2 = a1; + * 校验中间文件LiverangeSubsumeRCTest11.VtableImpl.mpl无IncRef。 + *- @Expect:a100\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest11.java + *- @ExecuteClass: LiverangeSubsumeRCTest11 + *- @ExecuteArgs: + */ + +class A2 { + public int count = 0; + public String className = "A"; + + public A2(String name) { + this.className = name; + } + + public void changeName(String name) { + this.className = name; + } +} + +public class LiverangeSubsumeRCTest11 { + private volatile static int count = 0; + + public static void onlyUseInsideLoop() { + A2 a1 = new A2("a1"); + for (count = 0; count < 100; count++) { + A2 a2 = new A2("a2"); + a2.changeName("a" + count); + a2.count = count; + } + if (count % 10 == 0) { + a1.changeName("a" + 100); + System.out.println(a1.className); + } + } + + public static void defAndUseInsideLoop() { + for (count = 0; count < 10; count++) { + A2 a1 = new A2("a1"); + a1.count = count; + A2 a2 = a1; + a2.changeName("null"); + if (count % 2 == 0) { + a2.changeName("a" + 100); + a2 = new A2("a10"); + a2.toString(); + } else { + a1.changeName("a" + 100); + a1.toString(); + } + } + } + + public static void main(String[] args) { + onlyUseInsideLoop(); + defAndUseInsideLoop(); + new LiverangeSubsumeRCTest11().defInsideAndUseOutsideLoop(); + } + + public void defInsideAndUseOutsideLoop() { + count = 0; + do { + int choice = count % 4; + A2 a1 = new A2("a2_i" + count); + A2 a2 = a1; + switch (choice) { + case 1: + a1.changeName("case 1"); + break; + case 2: + a2.changeName("case 2"); + break; + case 3: + break; + default: + a1 = a2; + } + count++; + } while (count < 10); + + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan a100\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0012-rt-compiler-LiverangeSubsumeRCTest12/LiverangeSubsumeRCTest12.java b/test/testsuite/ouroboros/subsumeRC_test/RT0012-rt-compiler-LiverangeSubsumeRCTest12/LiverangeSubsumeRCTest12.java new file mode 100755 index 0000000000000000000000000000000000000000..81ccceddd8750736ea003864a21a5d046b85c743 --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0012-rt-compiler-LiverangeSubsumeRCTest12/LiverangeSubsumeRCTest12.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest12 + *- @TestCaseName: LiverangeSubsumeRCTest12 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:检测在跳转语句(break, continue, return)控制流中,当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1:函数1做在continue ; continue tag的跳转for循环里,在if -else里,a1的生命周期都包含住了a3,所以a3会被优化掉 + * -#step2:函数2测试场景:a3 = a2,且在for循环内使用,在if逻辑体,a2的incref和decRef会被优化掉,在else逻辑体内,a2的incRef和decRef不会被优化掉。 + * 校验中间文件LiverangeSubsumeRCTest12.VtableImpl.mpl中有1个IncRef。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest12.java + *- @ExecuteClass: LiverangeSubsumeRCTest12 + *- @ExecuteArgs: + */ + +class A3 { + public int count = 0; + public String className = "temp"; + + public A3(String name) { + this.className = name; + } + + public void changeName(String name) { + this.className = name; + } +} + +public class LiverangeSubsumeRCTest12 { + private volatile static int count = 0; + private A3 defInsideUseOutside = null; + + //def outside, only use inside loop + public static void onlyUseInsideLoop() { + A3 a1 = new A3("a1"); + continueTag: + for (count = 0; count < 10; count++) { + A3 a3 = a1; + a1.changeName("a" + count); + a3.count = count; + if (count % 8 == 0) { + a1.changeName("Right"); // a3没有incRef和decRef + continue continueTag; + } else { + a1.className = "a1_" + count; // a3没有incRef和decRef + continue; + } + } + } + + public static A3 defAndUseInsideLoop() { + for (count = 0; count < 10; count++) { + A3 a2 = new A3("a2_i" + count); + A3 a3 = a2; //因为else分支,这边会有一个incRef + a2.count = count; + a3.changeName("null"); + if (count % 4 == 0 && count > 0) { + a2.changeName("Optimization"); + return a2; + } else if (count == 3) { + a3.changeName("NoOptimization"); + return a3; + } + } + return new A3("Error"); + } + + public static void main(String[] args) { + onlyUseInsideLoop(); + if (defAndUseInsideLoop().className.equals("NoOptimization")) { + System.out.println("ExpectResult"); + } else { + System.out.println("ErrorResult"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0013-rt-compiler-LiverangeSubsumeRCTest13/LiverangeSubsumeRCTest13.java b/test/testsuite/ouroboros/subsumeRC_test/RT0013-rt-compiler-LiverangeSubsumeRCTest13/LiverangeSubsumeRCTest13.java new file mode 100755 index 0000000000000000000000000000000000000000..3b37fee5a9f67c8b67eff82aaa9ca4b7b1caa0e4 --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0013-rt-compiler-LiverangeSubsumeRCTest13/LiverangeSubsumeRCTest13.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest13 + *- @TestCaseName: LiverangeSubsumeRCTest13 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:检测在跳转语句(try---多catch)控制流中,当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1:str2 = str;空指针的catch包含不住,不做优化外;另外两个catch都应该做incRef和decRef的优化。 + * 校验中间文件LiverangeSubsumeRCTest13.VtableImpl.mpl中无IncRef。 + *- @Expect:ExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest13.java + *- @ExecuteClass: LiverangeSubsumeRCTest13 + *- @ExecuteArgs: + */ + +public class LiverangeSubsumeRCTest13 { + public static void main(String[] argv) { + int result = 2; + boolean check; + String str = "123#"; + String str2 = str; + try { + str.notifyAll(); + str = str2; + Integer.parseInt(str); + } catch (NumberFormatException e) { + str = "123#456"; // 2 + result--; + } catch (NullPointerException e) { + str2 = "123456"; // 3 + result = 2; + } catch (IllegalMonitorStateException e) { + str2 = str; + result = 0; + } + if (result == 0) { + System.out.println("ExpectResult"); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/subsumeRC_test/RT0014-rt-compiler-LiverangeSubsumeRCTest14/LiverangeSubsumeRCTest14.java b/test/testsuite/ouroboros/subsumeRC_test/RT0014-rt-compiler-LiverangeSubsumeRCTest14/LiverangeSubsumeRCTest14.java new file mode 100755 index 0000000000000000000000000000000000000000..7ebd1f0260eaf9f83aa9b4bd9cc0b33cf4908b60 --- /dev/null +++ b/test/testsuite/ouroboros/subsumeRC_test/RT0014-rt-compiler-LiverangeSubsumeRCTest14/LiverangeSubsumeRCTest14.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Maple_CompilerOptimization_LiverangeSubsumeRCTest14 + *- @TestCaseName: LiverangeSubsumeRCTest14 + *- @TestCaseType: Function Testing + *- @RequirementName: Liverange subsumeRC优化 + *- @Brief:当确定一个对象的在某个生存区间内的存活状态时,去掉这个区间内的此对象的RC操作 + * -#step1: str2 = str1;这俩指向同一个字符串地址。 + * -#step2: 在try里有str1 = str2; 仍然是str1的生命周期包含住了str2;所以str2的incref和decRef都会被优化掉 + * 校验中间文件LiverangeSubsumeRCTest14.VtableImpl.mpl中无IncRef。 + *- @Expect:ExpectResultExpectResult\n + *- @Priority: High + *- @Source: LiverangeSubsumeRCTest14.java + *- @ExecuteClass: LiverangeSubsumeRCTest14 + *- @ExecuteArgs: + */ + +public class LiverangeSubsumeRCTest14 { + public static void main(String[] args) { + String str1 = "ExpectResult"; + String str2 = str1; + try { + String temp = str2.substring(0, 3); + temp = str1.toLowerCase(); + str1 = str2; + temp = temp.equals("ExpectResult") ? temp : str1; + temp.notifyAll(); + str1.notifyAll(); + } catch (Exception e) { + System.out.print(str1); + } finally { + System.out.println(str1); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ExpectResultExpectResult\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/testlist b/test/testsuite/ouroboros/testlist index 440c53fc12b354bcd74ececb13afc6f95cb46d2f..c2172fee9d9e33fa2121874839d7f2dcde8dc6bd 100755 --- a/test/testsuite/ouroboros/testlist +++ b/test/testsuite/ouroboros/testlist @@ -1,2 +1,13 @@ [ALL-TEST-CASE] + arrayboundary_test clinit_test + eh_test + fuzzapi_test + other_test + parent_test + reflection_test + stmtpre_test + string_test + subsumeRC_test + thread_test + unsafe_test diff --git a/test/testsuite/ouroboros/thread_test/RT0001-rt-thread-ThreadactiveCount/ThreadActiveCount.java b/test/testsuite/ouroboros/thread_test/RT0001-rt-thread-ThreadactiveCount/ThreadActiveCount.java new file mode 100755 index 0000000000000000000000000000000000000000..61819ed5c0fcae75f7b5d538dd329e33112024cc --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0001-rt-thread-ThreadactiveCount/ThreadActiveCount.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadActiveCount + *- @TestCaseName: Thread_ThreadActiveCount.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread.activeCount() returns an estimate of the number of active threads in the current thread's + * thread group and its subgroups. + *- @Brief: see below + * -#step1: 以god为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 以threadGroup、"banana" + i(i < 10)为参数,新建一个ThreadActiveCount线程,并调用start()方法启动该线程; + * -#step3: 让当前线程休眠500ms; + * -#step4: 因ThreadActiveCount类继承自Thread类,导致静态int型变量p的值经内部多次调用run()方法后变为10; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadActiveCount.java + *- @ExecuteClass: ThreadActiveCount + *- @ExecuteArgs: + */ + +public class ThreadActiveCount extends Thread { + static int num; + static Object ob = "aa"; + + public ThreadActiveCount(ThreadGroup group, String name) { + super(group, name); + } + + public static void main(String[] args) { + ThreadGroup threadGroup = new ThreadGroup("god"); + for (int i = 0; i < 10; i++) { + (new ThreadActiveCount(threadGroup, "banana" + i)).start(); + } + try { + sleep(500); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + if (num == 10) { + System.out.println(0); + } else { + System.out.println(2); + } + } + + public void run() { + synchronized (ob) { + num = activeCount(); + try { + ob.wait(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0002-rt-thread-ThreadcheckAccess/ThreadCheckAccess.java b/test/testsuite/ouroboros/thread_test/RT0002-rt-thread-ThreadcheckAccess/ThreadCheckAccess.java new file mode 100755 index 0000000000000000000000000000000000000000..7c10133b53f629da644c0d1840f4c49ad1a021ef --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0002-rt-thread-ThreadcheckAccess/ThreadCheckAccess.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadCheckAccess + *- @TestCaseName: Thread_ThreadCheckAccess.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread.checkAccess() returns if the current running thread has permission to modify this thread. + *- @Brief: see below + * -#step1: 创建一个Thread的实例对象threadCheckAccess; + * -#step2: 调用threadCheckAccess的checkAccess()方法,发现程序完整运行并未抛出任何异常; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadCheckAccess.java + *- @ExecuteClass: ThreadCheckAccess + *- @ExecuteArgs: + */ + +public class ThreadCheckAccess extends Thread { + public static void main(String[] args) { + ThreadCheckAccess threadCheckAccess = new ThreadCheckAccess(); + try { + threadCheckAccess.checkAccess(); + } catch (Exception e) { + System.out.println(2); + return; + } + System.out.println(0); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0003-rt-thread-Threadclone/ThreadClone.java b/test/testsuite/ouroboros/thread_test/RT0003-rt-thread-Threadclone/ThreadClone.java new file mode 100755 index 0000000000000000000000000000000000000000..bf7941e36324b24394ac871c784760b6a2806329 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0003-rt-thread-Threadclone/ThreadClone.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadClone + *- @TestCaseName: Thread_ThreadClone.java + *- @RequirementName: Java Thread + *- @Title/Destination: Using clones in threads throws CloneNotSupportedException + *- @Brief: see below + * -#step1: 创建一个Thread类的实例对象threadClone; + * -#step2: 调用threadClone的clone()方法会抛出CloneNotSupportedException; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadClone.java + *- @ExecuteClass: ThreadClone + *- @ExecuteArgs: + */ + +public class ThreadClone extends Thread { + public static void main(String[] args) { + ThreadClone threadClone = new ThreadClone(); + try { + threadClone.clone(); + System.out.println(2); + } catch (CloneNotSupportedException e) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0004-rt-thread-ThreadConstructors1/ThreadConstructors1.java b/test/testsuite/ouroboros/thread_test/RT0004-rt-thread-ThreadConstructors1/ThreadConstructors1.java new file mode 100755 index 0000000000000000000000000000000000000000..71900434612e374cc80cf5ee617f64ca7467490a --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0004-rt-thread-ThreadConstructors1/ThreadConstructors1.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors1 + *- @TestCaseName: Thread_ThreadConstructors1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Constructors Thread(): create a new Thread with no parameter + *- @Brief: see below + * -#step1: 创建一个Thread类的实例对象threadConstructors1; + * -#step2: 调用threadConstructors1的toString()的返回值与字符串"Thread[Thread-0,5,main]"相同,表明创建一个没有参数的新 + * 线程成功; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors1.java + *- @ExecuteClass: ThreadConstructors1 + *- @ExecuteArgs: + */ + +public class ThreadConstructors1 extends Thread { + public ThreadConstructors1() { + } + + public static void main(String[] args) { + ThreadConstructors1 threadConstructors1 = new ThreadConstructors1(); + if (threadConstructors1.toString().equals("Thread[Thread-0,5,main]")) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0005-rt-thread-ThreadConstructors10/ThreadConstructors10.java b/test/testsuite/ouroboros/thread_test/RT0005-rt-thread-ThreadConstructors10/ThreadConstructors10.java new file mode 100755 index 0000000000000000000000000000000000000000..8b55e25e04300a4ac332cbe961866ddf6c4fee10 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0005-rt-thread-ThreadConstructors10/ThreadConstructors10.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors10 + *- @TestCaseName: Thread_ThreadConstructors10.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verifying that the Run method is not overridden in the thread object invokes the Run method in + * the target object. + *- @Brief: see below + * -#step1: 创建一个ThreadConstructors10_a类的实例对象threadConstructors10_a; + * -#step2: 以threadConstructors10_a为参数,创建一个ThreadConstructors10类的实例对象threadConstructors10; + * -#step3: 调用threadConstructors10的start()方法启动该线程; + * -#step4: 调用threadConstructors10的join()方法; + * -#step5: 经判断得知ThreadConstructors10_a类的int类型的静态变量t的值经其内部调用run()方法后由0变为1; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors10.java + *- @ExecuteClass: ThreadConstructors10 + *- @ExecuteArgs: + */ + +class ThreadConstructors10_a implements Runnable { + static int t = 0; + + public void run() { + t++; + } +} + +public class ThreadConstructors10 extends Thread { + public ThreadConstructors10(Runnable target) { + super(target); + } + + public static void main(String[] args) { + ThreadConstructors10_a threadConstructors10_a = new ThreadConstructors10_a(); + ThreadConstructors10 threadConstructors10 = new ThreadConstructors10(threadConstructors10_a); + threadConstructors10.start(); + try { + threadConstructors10.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (ThreadConstructors10_a.t == 1) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0006-rt-thread-ThreadConstructors2/ThreadConstructors2.java b/test/testsuite/ouroboros/thread_test/RT0006-rt-thread-ThreadConstructors2/ThreadConstructors2.java new file mode 100755 index 0000000000000000000000000000000000000000..3c06314e12087573245ed563aba31b9e4191efab --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0006-rt-thread-ThreadConstructors2/ThreadConstructors2.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors2 + *- @TestCaseName: Thread_ThreadConstructors2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Constructors Thread(Runnable target), use super() in subclass of Thread, both run() in target + * and subclass will be executed + *- @Brief: see below + * -#step1: 创建一个ThreadConstructors2_a类的实例对象threadConstructors2_a; + * -#step2: 以threadConstructors2_a为参数,创建一个ThreadConstructors2类的实例对象threadConstructors2,并且 + * ThreadConstructors2类的run()中含有super.run(); + * -#step3: 调用threadConstructors2的start()方法启动该线程; + * -#step4: 调用threadConstructors2的join()方法; + * -#step5: 经判断得知ThreadConstructors2类和ThreadConstructors2_a类的int类型的静态变量i和t经调用各自类的内部的run()方法 + * 后均由0变为1; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors2.java + *- @ExecuteClass: ThreadConstructors2 + *- @ExecuteArgs: + */ + +class ThreadConstructors2_a implements Runnable { + static int t = 0; + + public void run() { + t++; + } +} + +public class ThreadConstructors2 extends Thread { + static int i = 0; + + public ThreadConstructors2(Runnable target) { + super(target); + } + + public static void main(String[] args) { + ThreadConstructors2_a threadConstructors2_a = new ThreadConstructors2_a(); + ThreadConstructors2 threadConstructors2 = new ThreadConstructors2(threadConstructors2_a); + threadConstructors2.start(); + try { + threadConstructors2.join(); + } catch (InterruptedException e) { + } + if (i == 1) { + if (ThreadConstructors2_a.t == 1) { + System.out.println(0); + return; + } + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0007-rt-thread-ThreadConstructors3/ThreadConstructors3.java b/test/testsuite/ouroboros/thread_test/RT0007-rt-thread-ThreadConstructors3/ThreadConstructors3.java new file mode 100755 index 0000000000000000000000000000000000000000..0e0615d9314ba5c382960e2fc02ced3708b3382a --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0007-rt-thread-ThreadConstructors3/ThreadConstructors3.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors3 + *- @TestCaseName: Thread_ThreadConstructors3.java + *- @RequirementName: Java Thread + *- @Title/Destination: Constructors Thread(Runnable target) don't use super() in subclass of Thread, only run() in + * subclass will be executed. + *- @Brief: see below + * -#step1: 创建一个ThreadConstructors3_a类的实例对象threadConstructors3_a; + * -#step2: 以threadConstructors3_a为参数,创建一个ThreadConstructors3类的实例对象threadConstructors3,并且 + * ThreadConstructors3类的run()中不含有super.run(); + * -#step3: 调用threadConstructors3的start()方法启动该线程; + * -#step4: 调用threadConstructors3的join()方法; + * -#step5: 经判断得知ThreadConstructors3类的int类型的静态变量i经调用其内部的run()方法后由0变为1,而 + * ThreadConstructors3_a类的int类型的静态变量t始终为0; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors3.java + *- @ExecuteClass: ThreadConstructors3 + *- @ExecuteArgs: + */ + +class ThreadConstructors3_a implements Runnable { + static int t = 0; + + public void run() { + t++; + } +} + +public class ThreadConstructors3 extends Thread { + static int i = 0; + + public ThreadConstructors3(Runnable target) { + super(target); + } + + public static void main(String[] args) { + ThreadConstructors3_a threadConstructors3_a = new ThreadConstructors3_a(); + ThreadConstructors3 threadConstructors3 = new ThreadConstructors3(threadConstructors3_a); + threadConstructors3.start(); + try { + threadConstructors3.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + if (i == 1) { + if (ThreadConstructors3_a.t == 0) { + System.out.println(0); + return; + } + } + System.out.println(2); + } + + public void run() { + i++; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0008-rt-thread-ThreadConstructors4/ThreadConstructors4.java b/test/testsuite/ouroboros/thread_test/RT0008-rt-thread-ThreadConstructors4/ThreadConstructors4.java new file mode 100755 index 0000000000000000000000000000000000000000..b9f0bdd2b2020a3c9139f6a5b887022acca8c519 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0008-rt-thread-ThreadConstructors4/ThreadConstructors4.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors4 + *- @TestCaseName: Thread_ThreadConstructors4.java + *- @RequirementName: Java Thread + *- @Title/Destination: Constructors Thread(ThreadGroup group, Runnable target), use super() in subclass of Thread, + * both run() in target and subclass will be executed + *- @Brief: see below + * -#step1: 以god为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 创建一个ThreadConstructors4_a类的实例对象threadConstructors4_a; + * -#step3: 以threadGroup、threadConstructors4_a为参数,创建一个ThreadConstructors4类的实例对象threadConstructors4,并且 + * ThreadConstructors4类的run()中含有super.run(); + * -#step4: 令threadConstructors4.getThreadGroup().toString()的返回值为message; + * -#step5: 调用threadConstructors4的start()方法启动该线程; + * -#step6: 调用threadConstructors4的join()方法; + * -#step7: 经判断得知ThreadConstructors4类和ThreadConstructors4_a类的int类型的静态变量经调用各自类内部的run()方法后均由 + * 0变为1,且message的信息与字符串"java.lang.ThreadGroup[name=god,maxpri=10]"相同; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors4.java + *- @ExecuteClass: ThreadConstructors4 + *- @ExecuteArgs: + */ + +class ThreadConstructors4_a implements Runnable { + static int t = 0; + + public void run() { + t++; + } +} + +public class ThreadConstructors4 extends Thread { + static int i = 0; + + public ThreadConstructors4(ThreadGroup group, Runnable target) { + super(group, target); + } + + public static void main(String[] args) { + String message; + ThreadGroup threadGroup = new ThreadGroup("god"); + ThreadConstructors4_a threadConstructors4_a = new ThreadConstructors4_a(); + ThreadConstructors4 threadConstructors4 = new ThreadConstructors4(threadGroup, threadConstructors4_a); + message = threadConstructors4.getThreadGroup().toString(); + threadConstructors4.start(); + try { + threadConstructors4.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (i == 1) { + if (ThreadConstructors4_a.t == 1) { + if (message.equals("java.lang.ThreadGroup[name=god,maxpri=10]")) { + System.out.println(0); + return; + } + } + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0009-rt-thread-ThreadConstructors5/ThreadConstructors5.java b/test/testsuite/ouroboros/thread_test/RT0009-rt-thread-ThreadConstructors5/ThreadConstructors5.java new file mode 100755 index 0000000000000000000000000000000000000000..9a599cd51e633933046b649ac811dcab8a3a7b23 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0009-rt-thread-ThreadConstructors5/ThreadConstructors5.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors5 + *- @TestCaseName: Thread_ThreadConstructors5.java + *- @RequirementName: Java Thread + *- @Title/Destination: Constructors Thread(String name), Thread.getName() return the name set in constructors. + *- @Brief: see below + * -#step1: 以good为参数,创建一个ThreadConstructors5类的实例对象threadConstructors5; + * -#step2: 调用threadConstructors5的getName()方法,得知其返回值与字符串"good"相同; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadConstructors5.java + *- @ExecuteClass: ThreadConstructors5 + *- @ExecuteArgs: + */ + +public class ThreadConstructors5 extends Thread { + public ThreadConstructors5(String name) { + super(name); + } + + public static void main(String[] args) { + ThreadConstructors5 threadConstructors5 = new ThreadConstructors5("good"); + if (threadConstructors5.getName().equals("good")) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0010-rt-thread-ThreadConstructors6/ThreadConstructors6.java b/test/testsuite/ouroboros/thread_test/RT0010-rt-thread-ThreadConstructors6/ThreadConstructors6.java new file mode 100755 index 0000000000000000000000000000000000000000..498e4ce17b0719984890fa26841cb7366036b71c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0010-rt-thread-ThreadConstructors6/ThreadConstructors6.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors6 + *- @TestCaseName: Thread_ThreadConstructors6.java + *- @RequirementName: Java Thread + *- @Title/Destination: Constructors Thread(ThreadGroup group, String name). + *- @Brief: see below + * -#step1: 以god为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 以threadGroup、good为参数,创建一个ThreadConstructors6类的实例对象threadConstructors6; + * -#step3: 经判断得知threadConstructors6.toString()的返回值与字符串"Thread[good,5,god]"相同; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors6.java + *- @ExecuteClass: ThreadConstructors6 + *- @ExecuteArgs: + */ + +public class ThreadConstructors6 extends Thread { + public ThreadConstructors6(ThreadGroup group, String name) { + super(group, name); + } + + public static void main(String[] args) { + ThreadGroup threadGroup = new ThreadGroup("god"); + ThreadConstructors6 threadConstructors6 = new ThreadConstructors6(threadGroup, "good"); + if (threadConstructors6.toString().equals("Thread[good,5,god]")) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0011-rt-thread-ThreadConstructors7/ThreadConstructors7.java b/test/testsuite/ouroboros/thread_test/RT0011-rt-thread-ThreadConstructors7/ThreadConstructors7.java new file mode 100755 index 0000000000000000000000000000000000000000..ea64249f9a665eda45b4202dc4e1bd3e62903a76 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0011-rt-thread-ThreadConstructors7/ThreadConstructors7.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors7 + *- @TestCaseName: Thread_ThreadConstructors7.java + *- @RequirementName: Java Thread + *- @Title/Destination: Constructors Thread(Runnable target, String name), use super() in subclass of Thread, both run() + * in target and subclass will be executed. + *- @Brief: see below + * -#step1: 创建一个ThreadConstructors7_a类的实例对象threadConstructors7_a; + * -#step2: 以threadConstructors7_a、good为参数,创建一个ThreadConstructors7类的实例对象threadConstructors7,并且 + * ThreadConstructors7类的run()方法中含有super.run(); + * -#step3: 调用threadConstructors7的start()方法启动该线程; + * -#step4: 调用threadConstructors7的join()方法; + * -#step5: 经判断得知ThreadConstructors7类和ThreadConstructors7_a类的int类型的静态变量i和t经调用各自内部的run()方法后均 + * 为1,并且threadConstructors7.getName()的返回值与字符串"good"相同; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors7.java + *- @ExecuteClass: ThreadConstructors7 + *- @ExecuteArgs: + */ + +class ThreadConstructors7_a implements Runnable { + static int t = 0; + + public void run() { + t++; + } +} + +public class ThreadConstructors7 extends Thread { + static int i = 0; + + public ThreadConstructors7(Runnable target, String name) { + super(target, name); + } + + public static void main(String[] args) { + ThreadConstructors7_a threadConstructors7_a = new ThreadConstructors7_a(); + ThreadConstructors7 threadConstructors7 = new ThreadConstructors7(threadConstructors7_a, "good"); + threadConstructors7.start(); + try { + threadConstructors7.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + if (i == 1) { + if (ThreadConstructors7_a.t == 1) { + if (threadConstructors7.getName().equals("good")) { + System.out.println(0); + return; + } + } + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0012-rt-thread-ThreadConstructors8/ThreadConstructors8.java b/test/testsuite/ouroboros/thread_test/RT0012-rt-thread-ThreadConstructors8/ThreadConstructors8.java new file mode 100755 index 0000000000000000000000000000000000000000..1102fbb0480c633ed9589a9bbd7e11057b39fb9c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0012-rt-thread-ThreadConstructors8/ThreadConstructors8.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors8 + *- @TestCaseName: Thread_ThreadConstructors8.java + *- @RequirementName: Java Thread + *- @Title/Destination: Constructors Thread(ThreadGroup group, Runnable target, String name), use super() in subclass of + * Thread, both run() in target and subclass will be executed + *- @Brief: see below + * -#step1: 以god为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 创建一个ThreadConstructors8_a类的实例对象threadConstructors8_a; + * -#step3: 以threadGroup、threadConstructors8_a、good为参数,创建一个ThreadConstructors8类的实例对象 + * threadConstructors8,并且ThreadConstructors8类的run()方法中含有super.run(); + * -#step4: 令threadConstructors8.getThreadGroup().toString()的返回值为message; + * -#step5: 调用threadConstructors8的start()方法启动该线程; + * -#step6: 调用threadConstructors8的join()方法; + * -#step7: 经判断得知ThreadConstructors8类和ThreadConstructors8_a类的int类型的静态变量i和t经调用各自内部的run()方法后均 + * 由0变为1,并且message的信息与字符串"java.lang.ThreadGroup[name=god,maxpri=10]"相同,另外 + * threadConstructors8.getName()的返回值与字符串"good"相同; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors8.java + *- @ExecuteClass: ThreadConstructors8 + *- @ExecuteArgs: + */ + +class ThreadConstructors8_a implements Runnable { + static int t = 0; + + public void run() { + t++; + } +} + +public class ThreadConstructors8 extends Thread { + static int i = 0; + + public ThreadConstructors8(ThreadGroup group, Runnable target, String name) { + super(group, target, name); + } + + public static void main(String[] args) { + String message; + ThreadGroup threadGroup = new ThreadGroup("god"); + ThreadConstructors8_a threadConstructors8_a = new ThreadConstructors8_a(); + ThreadConstructors8 threadConstructors8 = new ThreadConstructors8(threadGroup, threadConstructors8_a, + "good"); + message = threadConstructors8.getThreadGroup().toString(); + threadConstructors8.start(); + try { + threadConstructors8.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + if (i == 1 && ThreadConstructors8_a.t == 1) { + if (message.equals("java.lang.ThreadGroup[name=god,maxpri=10]")) { + if (threadConstructors8.getName().equals("good")) { + System.out.println(0); + return; + } + } + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0013-rt-thread-ThreadConstructors9/ThreadConstructors9.java b/test/testsuite/ouroboros/thread_test/RT0013-rt-thread-ThreadConstructors9/ThreadConstructors9.java new file mode 100755 index 0000000000000000000000000000000000000000..b299f7d859ee2bb0454f7dcf54dc5fc88ea8a56c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0013-rt-thread-ThreadConstructors9/ThreadConstructors9.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors9 + *- @TestCaseName: Thread_ThreadConstructors9.java + *- @RequirementName: Java Thread + *- @Title/Destination: Constructors Thread(ThreadGroup group, Runnable target, String name, long stackSize),use super() + * in subclass of Thread, both run() in target and subclass will be executed + *- @Brief: see below + * -#step1: 以god为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 创建一个ThreadConstructors9_a类的实例对象threadConstructors9_a; + * -#step3: 以threadGroup、threadConstructors9_a、good为参数,创建一个ThreadConstructors9类的实例对象 + * threadConstructors9,并且ThreadConstructors9类的run()方法中含有super.run(); + * -#step4: 令threadConstructors9.getThreadGroup().toString()的返回值为message; + * -#step5: 调用threadConstructors9的start()方法启动该线程; + * -#step6: 调用threadConstructors9的join()方法; + * -#step7: 经判断得知ThreadConstructors9类和ThreadConstructors9_a类的int类型的静态变量i和t经调用各自内部的run()方法后均 + * 由0变为1,并且k = stackSize= 1073741824, message的信息与字符串"java.lang.ThreadGroup[name=god,maxpri=10]"相 + * 同,另外threadConstructors9.getName()的返回值与字符串"good"相同; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors9.java + *- @ExecuteClass: ThreadConstructors9 + *- @ExecuteArgs: + */ + +class ThreadConstructors9_a implements Runnable { + static int t = 0; + + public void run() { + t++; + } +} + +public class ThreadConstructors9 extends Thread { + static int i = 0; + static long k; + + public ThreadConstructors9(ThreadGroup group, Runnable target, String name, long stackSize) { + super(group, target, name, stackSize); + k = stackSize; + } + + public static void main(String[] args) { + String message; + ThreadGroup threadGroup = new ThreadGroup("god"); + ThreadConstructors9_a threadConstructors9_a = new ThreadConstructors9_a(); + ThreadConstructors9 threadConstructors9 = new ThreadConstructors9(threadGroup, threadConstructors9_a, + "good", 1 << 30); + message = threadConstructors9.getThreadGroup().toString(); + threadConstructors9.start(); + try { + threadConstructors9.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + if (i == 1 && k == 1073741824 && ThreadConstructors9_a.t == 1) { + if (message.equals("java.lang.ThreadGroup[name=god,maxpri=10]")) { + if (threadConstructors9.getName().equals("good")) { + System.out.println(0); + return; + } + } + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0014-rt-thread-ThreadcurrentThread/ThreadCurrentThread.java b/test/testsuite/ouroboros/thread_test/RT0014-rt-thread-ThreadcurrentThread/ThreadCurrentThread.java new file mode 100755 index 0000000000000000000000000000000000000000..863574edc47fe5ec8404443e129f19ebcb624004 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0014-rt-thread-ThreadcurrentThread/ThreadCurrentThread.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadcurrentThread + *- @TestCaseName: Thread_ThreadCurrentThread.java + *- @RequirementName: Java Thread + *- @Title/Destination: currentThread() Returns a reference to the currently executing thread object. + *- @Brief: see below + * -#step1: 创建两个ThreadCurrentThread类的实例对象并分别命名为threadCurrentThread1、threadCurrentThread2; + * -#step2: 给threadCurrentThread1起一个线程名为good,并调用其start()方法启动该线程,给threadCurrentThread2起一个线程名 + * 为bad,并调用其start()方法启动该线程; + * -#step3: 分别调用threadCurrentThread1、threadCurrentThread2的join()方法; + * -#step4: 经判断得知currentThread().getName()的返回值与字符串"main"相同,并且ThreadCurrentThread类因继承自Thread类,其 + * 内部调用了两次run()方法后使得int类型的静态变量nameMatch由0变为2; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadCurrentThread.java + *- @ExecuteClass: ThreadCurrentThread + *- @ExecuteArgs: + */ + +public class ThreadCurrentThread extends Thread { + static int nameMatch = 0; + Object a = new Object(); + + public static void main(String[] args) { + ThreadCurrentThread threadCurrentThread1 = new ThreadCurrentThread(); + ThreadCurrentThread threadCurrentThread2 = new ThreadCurrentThread(); + threadCurrentThread1.setName("good"); + threadCurrentThread2.setName("bad"); + threadCurrentThread1.start(); + threadCurrentThread2.start(); + try { + threadCurrentThread1.join(); + threadCurrentThread2.join(); + } catch (Exception e) { + System.out.println("Join is interrupted"); + } + if (currentThread().getName().equals("good")) { + System.out.println(2); + } + if (currentThread().getName().equals("bad")) { + System.out.println(3); + } + if (currentThread().getName().equals("main")) { + if (nameMatch == 2) { + System.out.println(0); + return; + } + } + System.out.println(2); + } + + public synchronized void run() { + if (currentThread().getName() == getName()) { + synchronized (a) { + nameMatch++; + } + } + try { + wait(500); + } catch (InterruptedException e1) { + System.out.println("Wait is interrupted"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0015-rt-thread-ThreadDMcountStackFrames1/ThreadDMCountStackFrames1.java b/test/testsuite/ouroboros/thread_test/RT0015-rt-thread-ThreadDMcountStackFrames1/ThreadDMCountStackFrames1.java new file mode 100755 index 0000000000000000000000000000000000000000..2e803813f0089c04ff632a5f0754069b5db6abda --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0015-rt-thread-ThreadDMcountStackFrames1/ThreadDMCountStackFrames1.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadDMCountStackFrames1 + *- @TestCaseName: Thread_ThreadDMCountStackFrames1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Get the count of stack frames of a suspended thread by calling method countStackFrames(), the + * count should be >= 0. + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Override method run() and call suspend() in it. + * -#step3: Start the thread. + * -#step4: Get the count of stack frames of a suspended thread by calling method countStackFrames() + * -#step5: Check the count of stack frames of a suspended thread Greater than or equal to 0. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadDMCountStackFrames1.java + *- @ExecuteClass: ThreadDMCountStackFrames1 + *- @ExecuteArgs: + */ + +public class ThreadDMCountStackFrames1 extends Thread{ + static int eCnt = 0; + + public static void main(String[] args) { + ThreadDMCountStackFrames1 thread_obj = new ThreadDMCountStackFrames1(); + thread_obj.start(); + try { + sleep(50); + } catch (InterruptedException e1) { + System.err.println(e1); + } + + if (thread_obj.countStackFrames() >= 0 && eCnt == 1) { + System.out.println(0); + return; + } + + thread_obj.stop(); + System.out.println(2); + } + + public void run() { + synchronized (this) { + try { + this.suspend(); + } catch (UnsupportedOperationException e2) { + eCnt ++; + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0016-rt-thread-ThreadDMcountStackFrames2/ThreadDMCountStackFrames2.java b/test/testsuite/ouroboros/thread_test/RT0016-rt-thread-ThreadDMcountStackFrames2/ThreadDMCountStackFrames2.java new file mode 100755 index 0000000000000000000000000000000000000000..1bb2b8ee9891b52cefad3c686fca9d99b24a7e42 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0016-rt-thread-ThreadDMcountStackFrames2/ThreadDMCountStackFrames2.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadDMCountStackFrames2 + *- @TestCaseName: Thread_ThreadDMCountStackFrames2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Get the stack frame with no pending thread to report IllegalThreadStateException. + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Override method run() without suspend(). + * -#step3: Start the thread. + * -#step4: Check that IllegalThreadStateException occurs when calling method countStackFrames(). + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadDMCountStackFrames2.java + *- @ExecuteClass: ThreadDMCountStackFrames2 + *- @ExecuteArgs: + */ + +public class ThreadDMCountStackFrames2 extends Thread { + public static void main(String[] args) { + ThreadDMCountStackFrames2 thread_obj = new ThreadDMCountStackFrames2(); + thread_obj.start(); + try { + sleep(50); + } catch (InterruptedException e1) { + System.err.println(e1); + } + try { + thread_obj.countStackFrames(); + } catch (IllegalThreadStateException e3) { + System.out.println(2); + return; + } + + System.out.println(0); + } + + public void run() { + synchronized (this) { + try { + sleep(100); + } catch (InterruptedException e2) { + System.err.println(e2); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0017-rt-thread-ThreadDMdestroy/ThreadDMDestroy.java b/test/testsuite/ouroboros/thread_test/RT0017-rt-thread-ThreadDMdestroy/ThreadDMDestroy.java new file mode 100755 index 0000000000000000000000000000000000000000..bcc0f5e4d54b714204b669e599b912d11cdadeff --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0017-rt-thread-ThreadDMdestroy/ThreadDMDestroy.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadDMDestroy + *- @TestCaseName: Thread_ThreadDMDestroy.java + *- @RequirementName: Java Thread + *- @Title/Destination: Destroy() is Deprecated and throws UnsupportedOperationException in + * Android(throws NoSuchMethodError in JDK). + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Override method run(). + * -#step3: Start the thread. + * -#step4: Check that UnsupportedOperationException occurs when calling method Destroy(). + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadDMDestroy.java + *- @ExecuteClass: ThreadDMDestroy + *- @ExecuteArgs: + */ + +public class ThreadDMDestroy extends Thread { + public static void main(String[] args) { + ThreadDMDestroy thread_obj = new ThreadDMDestroy(); + thread_obj.start(); + try { + sleep(50); + } catch (InterruptedException e1) { + System.err.println(e1); + } + try { + thread_obj.destroy(); + } catch (UnsupportedOperationException e2) { + System.out.println(0); + return; + } catch (NoSuchMethodError e3) { + System.out.println(1); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (this) { + try { + sleep(100); + } catch (InterruptedException e4) { + System.err.println(e4); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0018-rt-thread-ThreadDMresume/ThreadDMResume.java b/test/testsuite/ouroboros/thread_test/RT0018-rt-thread-ThreadDMresume/ThreadDMResume.java new file mode 100755 index 0000000000000000000000000000000000000000..42cb6ba6028bc0d186622def3e1c790258eba0b2 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0018-rt-thread-ThreadDMresume/ThreadDMResume.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadDMResume + *- @TestCaseName: Thread_ThreadDMResume.java + *- @RequirementName: Java Thread + *- @Title/Destination: Use of deprecated method resume() throws UnsupportedOperationException in Android. + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Override method run(). + * -#step3: Start the thread. + * -#step4: Check that UnsupportedOperationException occurs when calling method resume(). + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadDMResume.java + *- @ExecuteClass: ThreadDMResume + *- @ExecuteArgs: + */ + +public class ThreadDMResume extends Thread { + static int i = 0; + + public static void main(String[] args) { + ThreadDMResume thread_obj = new ThreadDMResume(); + thread_obj.start(); + try { + sleep(50); + } catch (InterruptedException e1) { + System.err.println(e1); + } + try { + thread_obj.resume(); + } catch (UnsupportedOperationException e2) { + System.out.println(0); + return; + } + + System.out.println(2); + } + + public void run() { + synchronized (this) { + i++; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0019-rt-thread-ThreadDMstop/ThreadDMStop.java b/test/testsuite/ouroboros/thread_test/RT0019-rt-thread-ThreadDMstop/ThreadDMStop.java new file mode 100755 index 0000000000000000000000000000000000000000..7df97b766d2bb9c88b3ac6ac91c98127032b49e0 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0019-rt-thread-ThreadDMstop/ThreadDMStop.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadDMStop + *- @TestCaseName: Thread_ThreadDMStop.java + *- @RequirementName: Java Thread + *- @Title/Destination: Stop() is Deprecated and throws UnsupportedOperationException in Android. Other threads + * interrupt Target thread behavior. + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Override method run(). + * -#step3: Start the thread. + * -#step4: Check that UnsupportedOperationException occurs when calling method stop(). + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadDMStop.java + *- @ExecuteClass: ThreadDMStop + *- @ExecuteArgs: + */ + +public class ThreadDMStop extends Thread { + static int i = 0; + + public static void main(String[] args) { + long j; + long k; + ThreadDMStop thread_obj = new ThreadDMStop(); + thread_obj.start(); + j = System.currentTimeMillis(); + try { + sleep(50); + } catch (InterruptedException e1) { + System.err.println(e1); + } + try { + thread_obj.stop(); + } catch (UnsupportedOperationException e2) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (this) { + try { + wait(100); + i++; + } catch (InterruptedException e3) { + System.err.println(e3); + } + } + synchronized (this) { + for (int a = 0; a < 3; a++) { + try { + sleep(1000); + i++; + } catch (InterruptedException e4) { + System.err.println(e4); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0020-rt-thread-ThreadDMstopTh/ThreadDMStopThrowable.java b/test/testsuite/ouroboros/thread_test/RT0020-rt-thread-ThreadDMstopTh/ThreadDMStopThrowable.java new file mode 100755 index 0000000000000000000000000000000000000000..016ede455445c7123fa4d2f7c86685e485ae4919 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0020-rt-thread-ThreadDMstopTh/ThreadDMStopThrowable.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadDMStopThrowable + *- @TestCaseName: Thread_ThreadDMStopThrowable.java + *- @RequirementName: Java Thread + *- @Title/Destination: Stop(Throwable) is Deprecated and throws UnsupportedOperationException in Android. + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Override method run(). + * -#step3: Start the thread. + * -#step4: Check that UnsupportedOperationException occurs when calling method stop(Throwable). + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadDMStopThrowable.java + *- @ExecuteClass: ThreadDMStopThrowable + *- @ExecuteArgs: + */ + +public class ThreadDMStopThrowable extends Thread { + public static void main(String[] args) { + Throwable aaa = null; + ThreadDMStopThrowable thread_obj = new ThreadDMStopThrowable(); + thread_obj.start(); + try { + sleep(50); + } catch (InterruptedException e1) { + System.err.println(e1); + } + try { + thread_obj.stop(aaa); + } catch (UnsupportedOperationException e2) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (this) { + try { + sleep(100); + } catch (InterruptedException e4) { + System.err.println(e4); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0021-rt-thread-ThreadDMsuspend/ThreadDMSuspend.java b/test/testsuite/ouroboros/thread_test/RT0021-rt-thread-ThreadDMsuspend/ThreadDMSuspend.java new file mode 100755 index 0000000000000000000000000000000000000000..cfe0b87d38f142410da2b2da338942b1bf992652 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0021-rt-thread-ThreadDMsuspend/ThreadDMSuspend.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadDMSuspend + *- @TestCaseName: Thread_ThreadDMSuspend.java + *- @RequirementName: Java Thread + *- @Title/Destination: suspend() is Deprecated and throws UnsupportedOperationException in Android. + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Override method run(). + * -#step3: Start the thread. + * -#step4: Check that UnsupportedOperationException occurs when calling method suspend(). + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadDMSuspend.java + *- @ExecuteClass: ThreadDMSuspend + *- @ExecuteArgs: + */ + +public class ThreadDMSuspend extends Thread { + static int i = 0; /* STATUS_Success */ + + public static void main(String[] args) { + ThreadDMSuspend thread_obj = new ThreadDMSuspend(); + thread_obj.start(); + try { + sleep(50); + } catch (InterruptedException e2) { + System.err.println(e2); + } + try { + thread_obj.suspend(); + thread_obj.stop(); + } catch (UnsupportedOperationException e3) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (this) { + try { + sleep(100); + } catch (InterruptedException e1) { + System.err.println(e1); + } + i++; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0022-rt-thread-Threadenumerate/ThreadEnumerate.java b/test/testsuite/ouroboros/thread_test/RT0022-rt-thread-Threadenumerate/ThreadEnumerate.java new file mode 100755 index 0000000000000000000000000000000000000000..bf2e1b0b69b8612096a40a33d2d4ec175b2bc8bd --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0022-rt-thread-Threadenumerate/ThreadEnumerate.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadEnumerate + *- @TestCaseName: Thread_ThreadEnumerate.java + *- @RequirementName: Java Thread + *- @Title/Destination: enumerate(Thread[] tarray) Copies into the specified array every active thread in the current + * thread's thread group and its subgroups. + *- @Brief: see below + * -#step1: 定义线程类继承Thread类,包含静态线程组变量,并构造含参的构造方法。 + * -#step2:定义线程安全的run()方法。 + * -#step3:调用ThreadGroup()并实例化对象,启动线程并将线程添加到指定线程组。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadEnumerate.java + *- @ExecuteClass: ThreadEnumerate + *- @ExecuteArgs: + */ + +public class ThreadEnumerate extends Thread { + static Thread[] p; + static int w, q; + static Object ob = "aa"; + + public ThreadEnumerate(ThreadGroup group, String name) { + super(group, name); + } + + public static void main(String[] args) { + ThreadGroup cls1 = new ThreadGroup("god"); + for (int i = 0; i < 10; i++) { + (new ThreadEnumerate(cls1, "banana" + i)).start(); + } + try { + sleep(500); + } catch (InterruptedException e1) { + } + if (w == 10) { + System.out.println(0); + } + } + + public void run() { + synchronized (ob) { + q = activeCount(); + p = new Thread[q + 1]; + w = enumerate(p); + try { + ob.wait(1000); + } catch (InterruptedException e) { + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0023-rt-thread-Threadextends1/ThreadExtends1.java b/test/testsuite/ouroboros/thread_test/RT0023-rt-thread-Threadextends1/ThreadExtends1.java new file mode 100755 index 0000000000000000000000000000000000000000..680225f4b2f1c2fa349572694423557b568419e0 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0023-rt-thread-Threadextends1/ThreadExtends1.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadExtends1 + *- @TestCaseName: Thread_ThreadExtends1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Repeat start a thread. IllegalThreadStateException is thrown if the thread was already started. + *- @Brief: see below + * -#step1: 定义含私有变量的类ThreadExtends1,继承于Thread类。 + * -#step2: 创建线程安全的run()方法。 + * -#step3: 利用new得到ThreadExtends1的对象,启动一个对象线程,抛出IllegalThreadStateException。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadExtends1.java + *- @ExecuteClass: ThreadExtends1 + *- @ExecuteArgs: + */ + +class ThreadExtends1 extends Thread { + private int ticket = 10; + + public static void main(String[] args) { + ThreadExtends1 cls1 = new ThreadExtends1(); + ThreadExtends1 cls2 = new ThreadExtends1(); + ThreadExtends1 cls3 = new ThreadExtends1(); + try { + cls1.start(); + cls1.start(); + cls1.start(); + } catch (IllegalThreadStateException e) { + System.out.println(0); + } + } + + public synchronized void run() { + for (int i = 0; i < 20; i++) { + if (this.ticket > 0) { + this.ticket--; + } else { + break; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0024-rt-thread-Threadextends2/ThreadExtends2.java b/test/testsuite/ouroboros/thread_test/RT0024-rt-thread-Threadextends2/ThreadExtends2.java new file mode 100755 index 0000000000000000000000000000000000000000..672129048235ac3a3d315cbf48142f8c0ffd561a --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0024-rt-thread-Threadextends2/ThreadExtends2.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadExtends2 + *- @TestCaseName: Thread_ThreadExtends2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Start different threads after inheritance + *- @Brief: see below + * -#step1: 定义含私有变量的类ThreadExtends1,继承于Thread类。 + * -#step2: 创建线程安全的run()方法。 + * -#step3: 利用new得到ThreadExtends1的对象,启动每一个对象线程。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadExtends2.java + *- @ExecuteClass: ThreadExtends2 + *- @ExecuteArgs: + */ + +class ThreadExtends2 extends Thread { + private int ticket = 10; + + public static void main(String[] args) { + ThreadExtends2 cls1 = new ThreadExtends2(); + ThreadExtends2 cls2 = new ThreadExtends2(); + ThreadExtends2 cls3 = new ThreadExtends2(); + try { + cls1.start(); + cls2.start(); + cls3.start(); + } catch (Exception e) { + System.out.println(2); + } + System.out.println(0); + } + + public synchronized void run() { + for (int i = 0; i < 20; i++) { + if (this.ticket > 0) { + this.ticket--; + } else { + break; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0025-rt-thread-ThreadgetDefaultUncaughtExceptionHandler1/ThreadGetDefaultUncaughtExceptionHandler1.java b/test/testsuite/ouroboros/thread_test/RT0025-rt-thread-ThreadgetDefaultUncaughtExceptionHandler1/ThreadGetDefaultUncaughtExceptionHandler1.java new file mode 100755 index 0000000000000000000000000000000000000000..c2132060183aec2e65b67b7206617b826f93d7d4 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0025-rt-thread-ThreadgetDefaultUncaughtExceptionHandler1/ThreadGetDefaultUncaughtExceptionHandler1.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetDefaultUncaughtExceptionHandler1 + *- @TestCaseName: Thread_ThreadGetDefaultUncaughtExceptionHandler1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Use setDefaultUncaughtExceptionHandler to set the default exception handling subroutine, call + * getDefaultExceptionHandler() can get the handler. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadGetDefaultUncaughtExceptionHandler1,含run()方法。 + * -#step2: New一个ThreadGetDefaultUncaughtExceptionHandler1的对象,使用setDefaultUncaughtExceptionHandler()设置默认的 + * 异常处理程序。 + * -#step3:启动线程对象,可以获取处理程序,确认结果正确。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadGetDefaultUncaughtExceptionHandler1.java + *- @ExecuteClass: ThreadGetDefaultUncaughtExceptionHandler1 + *- @ExecuteArgs: + */ + +public class ThreadGetDefaultUncaughtExceptionHandler1 extends Thread{ + static String p; + public void run() { + System.out.println(3/0); + } + public static void main(String[] args) { + ThreadGetDefaultUncaughtExceptionHandler1 cls=new ThreadGetDefaultUncaughtExceptionHandler1(); + Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + } + }); + cls.start(); + try { + cls.join(); + } catch (InterruptedException e1) { + } + p=Thread.getDefaultUncaughtExceptionHandler().toString(); + if (p.indexOf("ThreadGetDefaultUncaughtExceptionHandle") !=-1) { + if (p.toString().indexOf("$") !=-1) { + if (p.toString().indexOf("@") !=-1) { + System.out.println(0); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0026-rt-thread-ThreadgetDefaultUncaughtExceptionHandler2/ThreadGetDefaultUncaughtExceptionHandler2.java b/test/testsuite/ouroboros/thread_test/RT0026-rt-thread-ThreadgetDefaultUncaughtExceptionHandler2/ThreadGetDefaultUncaughtExceptionHandler2.java new file mode 100755 index 0000000000000000000000000000000000000000..8921fa70f1180051c226a308ada4cb3d10080034 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0026-rt-thread-ThreadgetDefaultUncaughtExceptionHandler2/ThreadGetDefaultUncaughtExceptionHandler2.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetDefaultUncaughtExceptionHandler2 + *- @TestCaseName: Thread_ThreadGetDefaultUncaughtExceptionHandler2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Failed to get default exception handler after setting non-default exception capture subroutine + * (setUncaughtExceptionHandler) + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadGetDefaultUncaughtExceptionHandler1,含run()方法。 + * -#step2: New一个ThreadGetDefaultUncaughtExceptionHandler1的对象,使用setDefaultUncaughtExceptionHandler()设置默认的 + * 异常处理程序。 + * -#step3: 启动线程对象,不可以获取处理程序,NullPointerException抛出。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadGetDefaultUncaughtExceptionHandler2.java + *- @ExecuteClass: ThreadGetDefaultUncaughtExceptionHandler2 + *- @ExecuteArgs: + */ + +public class ThreadGetDefaultUncaughtExceptionHandler2 extends Thread{ + public void run() { + System.out.println(3/0); + } + public static void main(String[] args) { + ThreadGetDefaultUncaughtExceptionHandler2 cls=new ThreadGetDefaultUncaughtExceptionHandler2(); + cls.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + } + }); + cls.start(); + try { + cls.join(); + } catch (InterruptedException e1) { + } + try { + Thread.getDefaultUncaughtExceptionHandler().toString(); + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0027-rt-thread-ThreadgetId/ThreadGetId.java b/test/testsuite/ouroboros/thread_test/RT0027-rt-thread-ThreadgetId/ThreadGetId.java new file mode 100755 index 0000000000000000000000000000000000000000..bf46b4d8b813a835db945892b5c6ce2378ea5a5b --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0027-rt-thread-ThreadgetId/ThreadGetId.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetId + *- @TestCaseName: Thread_ThreadGetId.java + *- @RequirementName: Java Thread + *- @Title/Destination: GetId() Returns the identifier of this Thread as a positive long number. + *- @Brief: see below + * -#step1: 创建一个ThreadGetId类的实例对象threadGetId,且ThreadGetId类继承自Thread类; + * -#step2: 调用threadGetId的start()方法启动该线程; + * -#step3: 通过threadGetId的getId()方法获取到其id,并赋值给Long类型的变量i; + * -#step4: 确定变量i是Long类型的一个实例; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadGetId.java + *- @ExecuteClass: ThreadGetId + *- @ExecuteArgs: + */ + +public class ThreadGetId extends Thread { + public static void main(String[] args) { + Long i; + ThreadGetId threadGetId = new ThreadGetId(); + threadGetId.start(); + i = threadGetId.getId(); + if (i instanceof Long) { + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0028-rt-thread-ThreadgetName/ThreadGetName.java b/test/testsuite/ouroboros/thread_test/RT0028-rt-thread-ThreadgetName/ThreadGetName.java new file mode 100755 index 0000000000000000000000000000000000000000..81a8b72e39d6222a10b1a1bc448ff5a72dec21eb --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0028-rt-thread-ThreadgetName/ThreadGetName.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetName + *- @TestCaseName: Thread_ThreadGetName.java + *- @RequirementName: Java Thread + *- @Title/Destination: Get Thread Name. + *- @Brief: see below + * -#step1: 创建一个ThreadGetName类的实例对象threadGetName,且继承自Thread类; + * -#step2: 调用threadGetName的start()方法启动该线程; + * -#step3: 通过threadGetName的getName()方法返回的线程名与字符串"Thread-0"相同; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadGetName.java + *- @ExecuteClass: ThreadGetName + *- @ExecuteArgs: + */ + +public class ThreadGetName extends Thread { + public static void main(String[] args) { + ThreadGetName threadGetName = new ThreadGetName(); + threadGetName.start(); + if (threadGetName.getName().equals("Thread-0")) { + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0029-rt-thread-ThreadgetPriority/ThreadGetPriority.java b/test/testsuite/ouroboros/thread_test/RT0029-rt-thread-ThreadgetPriority/ThreadGetPriority.java new file mode 100755 index 0000000000000000000000000000000000000000..7eec9ca53d7d6e8a927a3b28038454f89f7bcef2 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0029-rt-thread-ThreadgetPriority/ThreadGetPriority.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetPriority + *- @TestCaseName: Thread_ThreadGetPriority.java + *- @RequirementName: Java Thread + *- @Title/Destination: Get Thread Default Priority + *- @Brief: see below + * -#step1: 创建一个ThreadGetPriority类的实例对象threadGetPriority,且ThreadGetId类继承自Thread类; + * -#step2: 调用threadGetPriority的start()方法启动该线程; + * -#step3: 经判断得知通过threadGetPriority的getPriority()方法的返回值等于5; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadGetPriority.java + *- @ExecuteClass: ThreadGetPriority + *- @ExecuteArgs: + */ + +public class ThreadGetPriority extends Thread { + public static void main(String[] args) { + ThreadGetPriority threadGetPriority = new ThreadGetPriority(); + threadGetPriority.start(); + if (threadGetPriority.getPriority() == 5) { + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0030-rt-thread-ThreadgetThreadGroup1/ThreadGetThreadGroup1.java b/test/testsuite/ouroboros/thread_test/RT0030-rt-thread-ThreadgetThreadGroup1/ThreadGetThreadGroup1.java new file mode 100755 index 0000000000000000000000000000000000000000..9e936c3c7e34d7e44406cf1e547fd06f88bc1417 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0030-rt-thread-ThreadgetThreadGroup1/ThreadGetThreadGroup1.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetThreadGroup1 + *- @TestCaseName: Thread_ThreadGetThreadGroup1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Get thread groups for threads + *- @Brief: see below + * -#step1: 以god为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 通过threadGroup的setMaxPriority()方法设置其属性为7; + * -#step3: 以threadGroup、banana为参数,创建一个ThreadGetThreadGroup1类的实例对象threadGetThreadGroup1,且 + * ThreadGetThreadGroup1类继承自Thread类; + * -#step4: 通过threadGetThreadGroup1的getThreadGroup()方法的返回值记为string; + * -#step5: 经判断得知string与字符串"java.lang.ThreadGroup[name=god,maxpri=7]"相同; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadGetThreadGroup1.java + *- @ExecuteClass: ThreadGetThreadGroup1 + *- @ExecuteArgs: + */ + +public class ThreadGetThreadGroup1 extends Thread { + public ThreadGetThreadGroup1(ThreadGroup group, String name) { + super(group, name); + } + + public static void main(String[] args) { + String string; + ThreadGroup threadGroup = new ThreadGroup("god"); + threadGroup.setMaxPriority(7); + ThreadGetThreadGroup1 threadGetThreadGroup1 = new ThreadGetThreadGroup1(threadGroup, "banana"); + string = threadGetThreadGroup1.getThreadGroup().toString(); + if (string.equals("java.lang.ThreadGroup[name=god,maxpri=7]")) { + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0031-rt-thread-ThreadgetThreadGroup2/ThreadGetThreadGroup2.java b/test/testsuite/ouroboros/thread_test/RT0031-rt-thread-ThreadgetThreadGroup2/ThreadGetThreadGroup2.java new file mode 100755 index 0000000000000000000000000000000000000000..e72989527dfe55681224f2e3f4d64d0a6e560d5f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0031-rt-thread-ThreadgetThreadGroup2/ThreadGetThreadGroup2.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetThreadGroup2 + *- @TestCaseName: Thread_ThreadGetThreadGroup2.java + *- @RequirementName: Java Thread + *- @Title/Destination: getThreadGroup() returns null if this thread has died (been stopped). + *- @Brief: see below + * -#step1: 以god为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 通过threadGroup的setMaxPriority()方法设置其属性为7; + * -#step3: 以threadGroup、banana为参数,创建一个ThreadGetThreadGroup2类的实例对象threadGetThreadGroup2,且 + * ThreadGetThreadGroup2类继承自Thread类; + * -#step4: 调用threadGetThreadGroup2的start()方法启动该线程; + * -#step5: 调用threadGetThreadGroup2的join()方法; + * -#step6: 尝试将threadGetThreadGroup2的getThreadGroup()方法的返回值赋值给string; + * -#step7: 经判断得知step6将会抛出NullPointerException; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadGetThreadGroup2.java + *- @ExecuteClass: ThreadGetThreadGroup2 + *- @ExecuteArgs: + */ + +public class ThreadGetThreadGroup2 extends Thread { + public ThreadGetThreadGroup2(ThreadGroup group, String name) { + super(group, name); + } + + public static void main(String[] args) { + String string; + ThreadGroup threadGroup = new ThreadGroup("god"); + threadGroup.setMaxPriority(7); + ThreadGetThreadGroup2 threadGetThreadGroup2 = new ThreadGetThreadGroup2(threadGroup, "banana"); + threadGetThreadGroup2.start(); + try { + threadGetThreadGroup2.join(); + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + try { + string = threadGetThreadGroup2.getThreadGroup().toString(); + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0032-rt-thread-ThreadgetUncaughtExceptionHandler1/ThreadGetUncaughtExceptionHandler1.java b/test/testsuite/ouroboros/thread_test/RT0032-rt-thread-ThreadgetUncaughtExceptionHandler1/ThreadGetUncaughtExceptionHandler1.java new file mode 100755 index 0000000000000000000000000000000000000000..2b94a097ddc873a1138efcdc35eb2d18cb9229dc --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0032-rt-thread-ThreadgetUncaughtExceptionHandler1/ThreadGetUncaughtExceptionHandler1.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetUncaughtExceptionHandler1 + *- @TestCaseName: Thread_ThreadGetUncaughtExceptionHandler1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Call setUncaughtExceptionHandler to for a child thread, can use getUncaughtExceptionHandler to + * get exception handler program in main thread + *- @Brief: see below + * -#step1: 创建一个ThreadGetUncaughtExceptionHandler1类的实例对象threadGetUncaughtExceptionHandler1,且 + * ThreadGetUncaughtExceptionHandler1类继承自Thread类; + * -#step2: 通过threadGetUncaughtExceptionHandler1的setUncaughtExceptionHandler()方法设置其相关属性; + * -#step3: 通过threadGetUncaughtExceptionHandler1的start()方法启动该线程; + * -#step4: 让当前线程休眠10ms; + * -#step5: 将threadGetUncaughtExceptionHandler1的getUncaughtExceptionHandler()方法的返回值赋值给string; + * -#step6: 经判断得知string包含字符串"ThreadGetUncaughtExceptionHandler1"、"$"和"@"; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadGetUncaughtExceptionHandler1.java + *- @ExecuteClass: ThreadGetUncaughtExceptionHandler1 + *- @ExecuteArgs: + */ + +public class ThreadGetUncaughtExceptionHandler1 extends Thread{ + static String string; + + public void run() { + try { + sleep(50); + } catch (InterruptedException e2) { + System.out.println("Sleep is interrupted"); + } + System.out.println(3/0); + } + + public static void main(String[] args) { + ThreadGetUncaughtExceptionHandler1 threadGetUncaughtExceptionHandler1 = new + ThreadGetUncaughtExceptionHandler1(); + threadGetUncaughtExceptionHandler1.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + } + }); + threadGetUncaughtExceptionHandler1.start(); + try { + sleep(10); + } catch (InterruptedException e1) { + System.out.println("Sleep is interrupted"); + } + string = threadGetUncaughtExceptionHandler1.getUncaughtExceptionHandler().toString(); + if (string.indexOf("ThreadGetUncaughtExceptionHandler1") != -1) { + if (string.toString().indexOf("$") != -1) { + if (string.toString().indexOf("@") != -1) { + System.out.println(0); + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0033-rt-thread-ThreadgetUncaughtExceptionHandler2/ThreadGetUncaughtExceptionHandler2.java b/test/testsuite/ouroboros/thread_test/RT0033-rt-thread-ThreadgetUncaughtExceptionHandler2/ThreadGetUncaughtExceptionHandler2.java new file mode 100755 index 0000000000000000000000000000000000000000..bd6f03ab820e12e300bdcd4913e9136d4e9fd59f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0033-rt-thread-ThreadgetUncaughtExceptionHandler2/ThreadGetUncaughtExceptionHandler2.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetUncaughtExceptionHandler2 + *- @TestCaseName: Thread_ThreadGetUncaughtExceptionHandler2.java + *- @RequirementName: Java Thread + *- @Title/Destination: When a thread does not have an uncaught exception explicitly, the thread's ThreadGroup is + * returned when call getUncaughtExceptionHandler. + *- @Brief: see below + * -#step1: 创建一个ThreadGetUncaughtExceptionHandler2类的实例对象threadGetUncaughtExceptionHandler2,且 + * ThreadGetUncaughtExceptionHandler2类继承自Thread类; + * -#step2: 通过Thread类的setUncaughtExceptionHandler()方法设置其相关属性; + * -#step3: 通过threadGetUncaughtExceptionHandler2的start()方法启动该线程; + * -#step4: 将threadGetUncaughtExceptionHandler2的getUncaughtExceptionHandler()方法的返回值赋值给string; + * -#step5: 经判断得知string中含有字符串"java.lang.ThreadGroup"; + *- @Expect: expected.txt + * -#step1xt + *- @Priority: High + *- @Source: ThreadGetUncaughtExceptionHandler2.java + *- @ExecuteClass: ThreadGetUncaughtExceptionHandler2 + *- @ExecuteArgs: + */ + +public class ThreadGetUncaughtExceptionHandler2 extends Thread{ + static String string; + + public void run() { + System.out.println(3/0); + } + + public static void main(String[] args) { + ThreadGetUncaughtExceptionHandler2 threadGetUncaughtExceptionHandler2 = new + ThreadGetUncaughtExceptionHandler2(); + Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + } + }); + threadGetUncaughtExceptionHandler2.start(); + string = threadGetUncaughtExceptionHandler2.getUncaughtExceptionHandler().toString(); + if (string.indexOf("java.lang.ThreadGroup") != -1) { + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0034-rt-thread-ThreadgetUncaughtExceptionHandler3/ThreadGetUncaughtExceptionHandler3.java b/test/testsuite/ouroboros/thread_test/RT0034-rt-thread-ThreadgetUncaughtExceptionHandler3/ThreadGetUncaughtExceptionHandler3.java new file mode 100755 index 0000000000000000000000000000000000000000..126a12f39fb48e6556fee6c0339f0fd1076a486f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0034-rt-thread-ThreadgetUncaughtExceptionHandler3/ThreadGetUncaughtExceptionHandler3.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetUncaughtExceptionHandler3 + *- @TestCaseName: Thread_ThreadGetUncaughtExceptionHandler3.java + *- @RequirementName: Java Thread + *- @Title/Destination: Cannot get exception in main thread after child thread ends(in Android, it does not return null). + *- @Brief: see below + * -#step1: 创建一个ThreadGetUncaughtExceptionHandler3类的实例对象threadGetUncaughtExceptionHandler3,且 + * ThreadGetUncaughtExceptionHandler3类继承自Thread类; + * -#step2: 通过threadGetUncaughtExceptionHandler3的setUncaughtExceptionHandler()方法设置其相关属性; + * -#step3: 通过threadGetUncaughtExceptionHandler3的start()方法启动该线程; + * -#step4: 调用threadGetUncaughtExceptionHandler3的join()方法; + * -#step5: 将threadGetUncaughtExceptionHandler3的getUncaughtExceptionHandler()方法的返回值赋值给string; + * -#step6: 经判断得知string中含有字符串"ThreadGetUncaughtExceptionHandler3"、"$"和"@"; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadGetUncaughtExceptionHandler3.java + *- @ExecuteClass: ThreadGetUncaughtExceptionHandler3 + *- @ExecuteArgs: + */ + +public class ThreadGetUncaughtExceptionHandler3 extends Thread{ + static String string; + + public void run() { + System.out.println(3/0); + } + + public static void main(String[] args) { + ThreadGetUncaughtExceptionHandler3 threadGetUncaughtExceptionHandler3 = new + ThreadGetUncaughtExceptionHandler3(); + threadGetUncaughtExceptionHandler3.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + } + }); + threadGetUncaughtExceptionHandler3.start(); + try { + threadGetUncaughtExceptionHandler3.join(); + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + try { + string = threadGetUncaughtExceptionHandler3.getUncaughtExceptionHandler().toString(); + if (string.indexOf("ThreadGetUncaughtExceptionHandler3") != -1) { + if (string.toString().indexOf("$") != -1) { + if (string.toString().indexOf("@") != -1) { + System.out.println(0); + return; + } + } + } + } catch (NullPointerException e2) { + System.out.println(2); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0035-rt-thread-ThreadholdsLock1/ThreadHoldsLock1.java b/test/testsuite/ouroboros/thread_test/RT0035-rt-thread-ThreadholdsLock1/ThreadHoldsLock1.java new file mode 100755 index 0000000000000000000000000000000000000000..c3b610c3636d0035897e3f3c8fac01d9c16466d7 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0035-rt-thread-ThreadholdsLock1/ThreadHoldsLock1.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadHoldsLock1 + *- @TestCaseName: Thread_ThreadHoldsLock1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread.holdsLock(Object) returns true if and only if the current thread holds the monitor lock + * on the specified object. before and after the wait, holdsLock return true. + *- @Brief: see below + * -#step1: 创建两个ThreadHoldsLock1类的实例对象threadHoldsLock1、threadHoldsLock2; + * -#step2: 调用threadHoldsLock1的start()方法启动该线程; + * -#step3: 让该线程休眠200ms; + * -#step4: 调用threadHoldsLock2的start()方法启动该线程; + * -#step5: 经判断得知,在经过ThreadHoldsLock1类内部的run()方法执行后int类型的静态变量都由0变为1; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadHoldsLock1.java + *- @ExecuteClass: ThreadHoldsLock1 + *- @ExecuteArgs: + */ + +public class ThreadHoldsLock1 extends Thread { + static Object object = "aa"; + static int i = 0; + static int t = 0; + + public static void main(String[] args) { + ThreadHoldsLock1 threadHoldsLock1 = new ThreadHoldsLock1(); + ThreadHoldsLock1 threadHoldsLock2 = new ThreadHoldsLock1(); + threadHoldsLock1.start(); + try { + sleep(200); + } catch (InterruptedException e1) { + System.out.println("Sleep is interrupted"); + } + threadHoldsLock2.start(); + if (i == 1 && t == 1) { + System.out.println(0); + } else { + System.out.println(2); + } + } + + public void run() { + synchronized (object) { + try { + if (holdsLock(object)) { + t = 1; + } + object.wait(100); + } catch (InterruptedException e1) { + System.out.println("Wait is interrupted"); + } + if (holdsLock(object)) { + i = 1; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0036-rt-thread-ThreadholdsLock2/ThreadHoldsLock2.java b/test/testsuite/ouroboros/thread_test/RT0036-rt-thread-ThreadholdsLock2/ThreadHoldsLock2.java new file mode 100755 index 0000000000000000000000000000000000000000..55f3b240384a10249964f2ea15fc25e39196102c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0036-rt-thread-ThreadholdsLock2/ThreadHoldsLock2.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadHoldsLock2 + *- @TestCaseName: Thread_ThreadHoldsLock2.java + *- @RequirementName: Java Thread + *- @Title/Destination: only one of the threads holdsLock on the Object if they synchronized on the same object. + *- @Brief: see below + * -#step1: 创建两个ThreadHoldsLock2类的实例对象threadHoldsLock21、threadHoldsLock22; + * -#step2: 调用threadHoldsLock21的start()方法启动该线程; + * -#step3: 让该线程休眠200ms; + * -#step4: 调用threadHoldsLock22的start()方法启动该线程; + * -#step5: 经判断得知,在经过ThreadHoldsLock2类内部的run()方法执行后holdsLock(object)的返回值为false; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadHoldsLock2.java + *- @ExecuteClass: ThreadHoldsLock2 + *- @ExecuteArgs: + */ + +public class ThreadHoldsLock2 extends Thread { + static Object object = "aa"; + + public static void main(String[] args) { + ThreadHoldsLock2 threadHoldsLock21 = new ThreadHoldsLock2(); + ThreadHoldsLock2 threadHoldsLock22 = new ThreadHoldsLock2(); + threadHoldsLock21.start(); + try { + sleep(200); + } catch (InterruptedException e1) { + System.out.println("Sleep is interrupted"); + } + threadHoldsLock22.start(); + if ((holdsLock(object))) { + System.out.println(2); + return; + } + System.out.println(0); + } + + public void run() { + synchronized (object) { + try { + object.wait(100); + } catch (InterruptedException e1) { + System.out.println("Wait is interrupted"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0037-rt-thread-ThreadholdsLock3/ThreadHoldsLock3.java b/test/testsuite/ouroboros/thread_test/RT0037-rt-thread-ThreadholdsLock3/ThreadHoldsLock3.java new file mode 100755 index 0000000000000000000000000000000000000000..ad45a0070744e6a2b1bdc11b44f104989c7174bd --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0037-rt-thread-ThreadholdsLock3/ThreadHoldsLock3.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadHoldsLock3 + *- @TestCaseName: Thread_ThreadHoldsLock3.java + *- @RequirementName: Java Thread + *- @Title/Destination: holdsLock(ob1) throws NullPointerException when object is null. + *- @Brief: see below + * -#step1: 创建两个ThreadHoldsLock3类的实例对象threadHoldsLock31、threadHoldsLock32; + * -#step2: 调用threadHoldsLock31的start()方法启动该线程; + * -#step3: 让该线程休眠200ms; + * -#step4: 调用threadHoldsLock32的start()方法启动该线程; + * -#step5: 以object1=null为参数,尝试执行holdsLock()方法; + * -#step6: 确定step5中会抛出NullPointerException; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadHoldsLock3.java + *- @ExecuteClass: ThreadHoldsLock3 + *- @ExecuteArgs: + */ + +public class ThreadHoldsLock3 extends Thread { + static Object object = "aa"; + static Object object1 = null; + + public static void main(String[] args) { + ThreadHoldsLock3 threadHoldsLock31 = new ThreadHoldsLock3(); + ThreadHoldsLock3 threadHoldsLock32 = new ThreadHoldsLock3(); + threadHoldsLock31.start(); + try { + sleep(200); + } catch (InterruptedException e1) { + System.out.println("Sleep is interrupted"); + } + threadHoldsLock32.start(); + try { + holdsLock(object1); + System.out.println(2); + } catch (NullPointerException e) { + System.out.println(0); + } + } + + public void run() { + synchronized (object) { + try { + object.wait(100); + } catch (InterruptedException e1) { + System.out.println("Wait is interrupted"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0038-rt-thread-ThreadisAlive1/ThreadIsAlive1.java b/test/testsuite/ouroboros/thread_test/RT0038-rt-thread-ThreadisAlive1/ThreadIsAlive1.java new file mode 100755 index 0000000000000000000000000000000000000000..bb95db418b3909af52d58fdc484b8aa9c60c30c4 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0038-rt-thread-ThreadisAlive1/ThreadIsAlive1.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadIsAlive1 + *- @TestCaseName: Thread_ThreadIsAlive1.java + *- @RequirementName: Java Thread + *- @Title/Destination: isAlive() return false when a thread haven't been started yet + *- @Brief: see below + * -#step1: 创建一个ThreadIsAlive1类的实例对象threadIsAlive1,并且ThreadIsAlive1类继承自Thread类; + * -#step2: 经判断得知调用threadIsAlive1的isAlive()方法其返回值为false; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadIsAlive1.java + *- @ExecuteClass: ThreadIsAlive1 + *- @ExecuteArgs: + */ + +public class ThreadIsAlive1 extends Thread { + public static void main(String[] args) { + ThreadIsAlive1 threadIsAlive1 = new ThreadIsAlive1(); + if (threadIsAlive1.isAlive()) { + System.out.println(2); + return; + } + System.out.println(0); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0039-rt-thread-ThreadisAlive2/ThreadIsAlive2.java b/test/testsuite/ouroboros/thread_test/RT0039-rt-thread-ThreadisAlive2/ThreadIsAlive2.java new file mode 100755 index 0000000000000000000000000000000000000000..93e176e074173c615d8b2e3512217b463139446f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0039-rt-thread-ThreadisAlive2/ThreadIsAlive2.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadIsAlive2 + *- @TestCaseName: Thread_ThreadIsAlive2.java + *- @RequirementName: Java Thread + *- @Title/Destination: isAlive() return false when a thread is running + *- @Brief: see below + * -#step1: 创建一个ThreadIsAlive2类的实例对象threadIsAlive2,并且ThreadIsAlive2类继承自Thread类; + * -#step2: 调用threadIsAlive2的start()方法启动该线程; + * -#step3: 经判断得知调用threadIsAlive2的isAlive()方法其返回值为true; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadIsAlive2.java + *- @ExecuteClass: ThreadIsAlive2 + *- @ExecuteArgs: + */ + +public class ThreadIsAlive2 extends Thread { + public static void main(String[] args) { + ThreadIsAlive2 threadIsAlive2 = new ThreadIsAlive2(); + threadIsAlive2.start(); + if (!threadIsAlive2.isAlive()) { + System.out.println(2); + return; + } + System.out.println(0); + } + + public void run() { + try { + sleep(50); + } catch (InterruptedException e) { + System.out.println("Sleep is interrupted"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0040-rt-thread-ThreadisAlive3/ThreadIsAlive3.java b/test/testsuite/ouroboros/thread_test/RT0040-rt-thread-ThreadisAlive3/ThreadIsAlive3.java new file mode 100755 index 0000000000000000000000000000000000000000..8a696a42c1ea2b43a021501eecdcb822e79c4406 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0040-rt-thread-ThreadisAlive3/ThreadIsAlive3.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadIsAlive3 + *- @TestCaseName: Thread_ThreadIsAlive3.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test isAlive() return false when a thread died. + *- @Brief: see below + * -#step1: 创建一个ThreadIsAlive3类的实例对象threadIsAlive3,并且ThreadIsAlive3类继承自Thread类; + * -#step2: 调用threadIsAlive3的start()方法启动该线程; + * -#step3: 调用threadIsAlive3的join()方法; + * -#step4: 经判断得知调用threadIsAlive3的isAlive()方法其返回值为false; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadIsAlive3.java + *- @ExecuteClass: ThreadIsAlive3 + *- @ExecuteArgs: + */ + +public class ThreadIsAlive3 extends Thread { + public static void main(String[] args) { + ThreadIsAlive3 threadIsAlive3 = new ThreadIsAlive3(); + threadIsAlive3.start(); + try { + threadIsAlive3.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + if (threadIsAlive3.isAlive()) { + System.out.println(2); + return; + } + System.out.println(0); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0041-rt-thread-ThreadisDaemon1/ThreadIsDaemon1.java b/test/testsuite/ouroboros/thread_test/RT0041-rt-thread-ThreadisDaemon1/ThreadIsDaemon1.java new file mode 100755 index 0000000000000000000000000000000000000000..36824b177861350a5bdb970a46c4de203e86f843 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0041-rt-thread-ThreadisDaemon1/ThreadIsDaemon1.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadIsDaemon1 + *- @TestCaseName: Thread_ThreadIsDaemon1.java + *- @RequirementName: Java Thread + *- @Title/Destination: To set a child thread as a daemon thread + *- @Brief: see below + * -#step1: 创建ThreadIsDaemon1类的实例对象threadIsDaemon1,并且ThreadIsDaemon1类继承自Thread类; + * -#step2: 通过threadIsDaemon1的setDaemon()方法设置其属性为true; + * -#step3: 调用threadIsDaemon1的start()方法启动该线程; + * -#step4: 经判断得知调用threadIsDaemon1的isDaemon()方法其返回值为true; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadIsDaemon1.java + *- @ExecuteClass: ThreadIsDaemon1 + *- @ExecuteArgs: + */ + +public class ThreadIsDaemon1 extends Thread { + public static void main(String[] args) { + ThreadIsDaemon1 threadIsDaemon1 = new ThreadIsDaemon1(); + threadIsDaemon1.setDaemon(true); + threadIsDaemon1.start(); + if (threadIsDaemon1.isDaemon()) { + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0042-rt-thread-ThreadisDaemon2/ThreadIsDaemon2.java b/test/testsuite/ouroboros/thread_test/RT0042-rt-thread-ThreadisDaemon2/ThreadIsDaemon2.java new file mode 100755 index 0000000000000000000000000000000000000000..5b98b7d3e4e65120e96d8b40ae15f24f1776a8eb --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0042-rt-thread-ThreadisDaemon2/ThreadIsDaemon2.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadIsDaemon2 + *- @TestCaseName: Thread_ThreadIsDaemon2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Setting child threads to daemon threads has no effect on the main thread. + *- @Brief: see below + * -#step1: 创建ThreadIsDaemon2类的实例对象threadIsDaemon2,并且ThreadIsDaemon2类继承自Thread类; + * -#step2: 通过threadIsDaemon2的setDaemon()方法设置其属性为true; + * -#step3: 调用threadIsDaemon2的start()方法启动该线程; + * -#step4: 经判断得知调用currentThread()的isDaemon()方法其返回值为false; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadIsDaemon2.java + *- @ExecuteClass: ThreadIsDaemon2 + *- @ExecuteArgs: + */ + +public class ThreadIsDaemon2 extends Thread { + public static void main(String[] args) { + ThreadIsDaemon2 threadIsDaemon2 = new ThreadIsDaemon2(); + threadIsDaemon2.setDaemon(true); + threadIsDaemon2.start(); + if (currentThread().isDaemon()) { + System.out.println(2); + return; + } + System.out.println(0); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0043-rt-thread-ThreadRunnable/ThreadRunnable.java b/test/testsuite/ouroboros/thread_test/RT0043-rt-thread-ThreadRunnable/ThreadRunnable.java new file mode 100755 index 0000000000000000000000000000000000000000..eaa7928878676756245569c7293e25e660bce04e --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0043-rt-thread-ThreadRunnable/ThreadRunnable.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadRunnable + *- @TestCaseName: Thread_ThreadRunnable.java + *- @RequirementName: Java Thread + *- @Title/Destination: Validation creates a thread by implementing the Runnable interface. + *- @Brief: see below + * -#step1: 创建一个ThreadRunnable类的实例对象threadRunnable,并且ThreadRunnable类实现了Runnable接口; + * -#step2: 以threadRunnable为参数,通过new Thread()方法创建一个新线程,并调用start()方法启动该线程; + * -#step3: 重复step2两次; + * -#step4: 经判断得知step2和step3以及ThreadRunnable类在执行其内部的run()方法后均未抛出异常; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadRunnable.java + *- @ExecuteClass: ThreadRunnable + *- @ExecuteArgs: + */ + +public class ThreadRunnable implements Runnable { + private int ticket = 10; + + public static void main(String[] args) { + ThreadRunnable threadRunnable = new ThreadRunnable(); + try { + new Thread(threadRunnable).start(); + new Thread(threadRunnable).start(); + new Thread(threadRunnable).start(); + } catch (Exception e) { + System.out.println(2); + return; + } + System.out.println(0); + } + + public synchronized void run() { + for (int i = 0; i < 20; i++) { + if (this.ticket > 0) { + this.ticket--; + } else { + break; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0044-rt-thread-ThreadsetDaemon1/ThreadSetDaemon1.java b/test/testsuite/ouroboros/thread_test/RT0044-rt-thread-ThreadsetDaemon1/ThreadSetDaemon1.java new file mode 100755 index 0000000000000000000000000000000000000000..7f51f161912f1e317577d99c83236006c8f8a5ce --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0044-rt-thread-ThreadsetDaemon1/ThreadSetDaemon1.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetDaemon1 + *- @TestCaseName: Thread_ThreadSetDaemon1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verify that the main thread end daemon ends directly when the daemon exists. + *- @Brief: see below + * -#step1: 创建ThreadSetDaemon1类的实例对象threadSetDaemon1,并且ThreadSetDaemon1类继承自Thread类; + * -#step2: 通过threadSetDaemon1的setDaemon()方法设置其属性为true; + * -#step3: 调用threadSetDaemon1的start()方法启动该线程; + * -#step4: 让当前线程休眠100ms; + * -#step5: 令int类型的全局静态变量t的值加1; + * -#step6: 确定step4、step5以及ThreadSetDaemon1类在执行其内部的run()后均未抛出异常; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadSetDaemon1.java + *- @ExecuteClass: ThreadSetDaemon1 + *- @ExecuteArgs: + */ + +public class ThreadSetDaemon1 extends Thread { + static int i = 0; + static int t = 0; + + public static void main(String[] args) { + ThreadSetDaemon1 threadSetDaemon1 = new ThreadSetDaemon1(); + threadSetDaemon1.setDaemon(true); + threadSetDaemon1.start(); + try { + sleep(100); + t++; + } catch (InterruptedException e2) { + System.out.println("Sleep is interrupted"); + } + System.out.println(0); + } + + public void run() { + try { + sleep(1000); + i++; + System.out.println(2); + } catch (InterruptedException e1) { + System.out.println("Sleep is interrupted"); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0045-rt-thread-ThreadsetDaemon2/ThreadSetDaemon2.java b/test/testsuite/ouroboros/thread_test/RT0045-rt-thread-ThreadsetDaemon2/ThreadSetDaemon2.java new file mode 100755 index 0000000000000000000000000000000000000000..d4a379a1d756a53687c8768d3d6e298099805ed1 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0045-rt-thread-ThreadsetDaemon2/ThreadSetDaemon2.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetDaemon2 + *- @TestCaseName: Thread_ThreadSetDaemon2.java + *- @RequirementName: Java Thread + *- @Title/Destination: If this thread is alive, thread.setDaemon() throws IllegalThreadStateException. + *- @Brief: see below + * -#step1: 创建一个ThreadSetDaemon2类的实例对象threadSetDaemon2,并且ThreadSetDaemon2类继承自Thread类; + * -#step2: 调用threadSetDaemon2的start()方法启动该线程; + * -#step3: 尝试通过threadSetDaemon2的setDaemon()方法为其设置属性为true; + * -#step4: 确定step3中会抛出IllegalThreadStateException; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetDaemon2.java + *- @ExecuteClass: ThreadSetDaemon2 + *- @ExecuteArgs: + */ + +public class ThreadSetDaemon2 extends Thread { + public static void main(String[] args) { + ThreadSetDaemon2 threadSetDaemon2 = new ThreadSetDaemon2(); + threadSetDaemon2.start(); + try { + threadSetDaemon2.setDaemon(true); + System.out.println(2); + } catch (IllegalThreadStateException e2) { + System.out.println(0); + } + } + + public void run() { + for (int i = 0; i < 5; i++) { + try { + sleep(200); + } catch (InterruptedException e1) { + System.out.println("Sleep is interrupted"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0046-rt-thread-ThreadsetDaemon3/ThreadSetDaemon3.java b/test/testsuite/ouroboros/thread_test/RT0046-rt-thread-ThreadsetDaemon3/ThreadSetDaemon3.java new file mode 100755 index 0000000000000000000000000000000000000000..8e860cef3ee84fbcc50d5b42e23ea42987fb5722 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0046-rt-thread-ThreadsetDaemon3/ThreadSetDaemon3.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetDaemon3 + *- @TestCaseName: Thread_ThreadSetDaemon3.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verify that the main thread end daemon does not end directly when some other non-daemon thread + * still running + *- @Brief: see below + * -#step1: 创建两个ThreadSetDaemon3类的实例对象threadSetDaemon31、threadSetDaemon32,并且ThreadSetDaemon3类继承自 + * Thread类; + * -#step2: 通过threadSetDaemon31的setDaemon()方法为其设置属性为true; + * -#step3: 通过threadSetDaemon31的start()方法启动该线程; + * -#step4: 让当前线程休眠50ms; + * -#step5: 将int类型的全局静态变量t的值加1; + * -#step6: 通过threadSetDaemon32的start()方法启动该线程; + * -#step7: 让当前线程休眠50ms; + * -#step8: 将int类型的全局静态变量t的值加1; + * -#step9: 确定以上步骤以及ThreadSetDaemon3类在执行其内部的run()后均未抛出异常; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadSetDaemon3.java + *- @ExecuteClass: ThreadSetDaemon3 + *- @ExecuteArgs: + */ + +public class ThreadSetDaemon3 extends Thread { + static int i = 0; + static int t = 0; + + public static void main(String[] args) { + ThreadSetDaemon3 threadSetDaemon31 = new ThreadSetDaemon3(); + ThreadSetDaemon3 threadSetDaemon32 = new ThreadSetDaemon3(); + threadSetDaemon31.setDaemon(true); + threadSetDaemon31.start(); + try { + sleep(50); + t++; + } catch (InterruptedException e3) { + System.out.println("Sleep is interrupted"); + } + threadSetDaemon32.start(); + try { + sleep(50); + t++; + } catch (InterruptedException e2) { + System.out.println("Sleep is interrupted"); + } + System.out.println(0); + } + + public void run() { + try { + sleep(300); + i++; + } catch (InterruptedException e1) { + System.out.println("Sleep is interrupted"); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0047-rt-thread-ThreadsetDefaultUncaughtExceptionHandler/ThreadSetDefaultUncaughtExceptionHandler.java b/test/testsuite/ouroboros/thread_test/RT0047-rt-thread-ThreadsetDefaultUncaughtExceptionHandler/ThreadSetDefaultUncaughtExceptionHandler.java new file mode 100755 index 0000000000000000000000000000000000000000..733f3e1cc8a1bac796cb1bdb58df618af2aa87ed --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0047-rt-thread-ThreadsetDefaultUncaughtExceptionHandler/ThreadSetDefaultUncaughtExceptionHandler.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetDefaultUncaughtExceptionHandler + *- @TestCaseName: Thread_ThreadSetDefaultUncaughtExceptionHandler.java + *- @RequirementName: Java Thread + *- @Title/Destination: SetDefaultUncaughtExceptionHandler set the exception handler for Thread class, all thread will + * have the same exception handler + *- @Brief: see below + * -#step1: Override method run() include a uncaught error. + * -#step2: Create two ThreadSetDefaultUncaughtExceptionHandler instance. + * -#step3: Start the threads. + * -#step4: Check that two times java.lang.ArithmeticException were handled by + * Thread.setDefaultUncaughtExceptionHandler,rather than catch. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetDefaultUncaughtExceptionHandler.java + *- @ExecuteClass: ThreadSetDefaultUncaughtExceptionHandler + *- @ExecuteArgs: + */ + +public class ThreadSetDefaultUncaughtExceptionHandler extends Thread{ + static int i=0; + static String p; + public void run() { + System.out.println(3/0); + } + public static void main(String[] args) { + + ThreadSetDefaultUncaughtExceptionHandler thread_obj1 = new ThreadSetDefaultUncaughtExceptionHandler(); + ThreadSetDefaultUncaughtExceptionHandler thread_obj2 = new ThreadSetDefaultUncaughtExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + p = e.toString(); + if (p.indexOf("java.lang.ArithmeticException") != -1) { + i++; + } + } + }); + thread_obj1.start(); + thread_obj2.start(); + try { + thread_obj1.join(); + thread_obj2.join(); + } catch (InterruptedException e1) { + } + if (i == 2) { + System.out.println(0); + return; + } + System.out.println(2); + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0048-rt-thread-ThreadsetName1/ThreadSetName1.java b/test/testsuite/ouroboros/thread_test/RT0048-rt-thread-ThreadsetName1/ThreadSetName1.java new file mode 100755 index 0000000000000000000000000000000000000000..ef58c2f602e1aceea56ed02ade3f63d0ec8db230 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0048-rt-thread-ThreadsetName1/ThreadSetName1.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetName1 + *- @TestCaseName: Thread_ThreadSetName1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Set Thread name + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Start the thread. + * -#step3: Set a name for thread. + * -#step4: Check that name of thread is right. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetName1.java + *- @ExecuteClass: ThreadSetName1 + *- @ExecuteArgs: + */ + +public class ThreadSetName1 extends Thread { + public static void main(String[] args) { + ThreadSetName1 thread_obj = new ThreadSetName1(); + thread_obj.start(); + thread_obj.setName("我abc123!?*{$"); + if (thread_obj.getName().equals("我abc123!?*{$")) { + System.out.println(0); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0049-rt-thread-ThreadsetName2/ThreadSetName2.java b/test/testsuite/ouroboros/thread_test/RT0049-rt-thread-ThreadsetName2/ThreadSetName2.java new file mode 100755 index 0000000000000000000000000000000000000000..016a3b51f055987e9010c394ebc0d0e879e58186 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0049-rt-thread-ThreadsetName2/ThreadSetName2.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetName2 + *- @TestCaseName: Thread_ThreadSetName2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread.setName(NULL) throws NullPointerException + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Start the thread. + * -#step3: Set a null name for thread. + * -#step4: Check that throw NullPointerException when setName(String str)'s param is null. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetName2.java + *- @ExecuteClass: ThreadSetName2 + *- @ExecuteArgs: + */ + +public class ThreadSetName2 extends Thread { + public static void main(String[] args) { + String string = null; + ThreadSetName2 threa_obj = new ThreadSetName2(); + try { + threa_obj.setName(string); + System.out.println(2); + } catch (NullPointerException e) { + System.out.println(0); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0050-rt-thread-ThreadsetPriority1/ThreadSetPriority1.java b/test/testsuite/ouroboros/thread_test/RT0050-rt-thread-ThreadsetPriority1/ThreadSetPriority1.java new file mode 100755 index 0000000000000000000000000000000000000000..704ec4b2e7648a4c9be0d53985e511bb2966f64d --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0050-rt-thread-ThreadsetPriority1/ThreadSetPriority1.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetPriority1 + *- @TestCaseName: Thread_ThreadSetPriority1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Repeatedly set thread priority + *- @Brief: see below + * -#step1: Create four thread instance. + * -#step2: Set priority for four thread. + * -#step3: Start the threads. + * -#step4: Check that priority of instances was set correctly. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetPriority1.java + *- @ExecuteClass: ThreadSetPriority1 + *- @ExecuteArgs: + */ + +public class ThreadSetPriority1 extends Thread { + public static void main(String[] args) { + ThreadSetPriority1 thread_obj1 = new ThreadSetPriority1(); + ThreadSetPriority1 thread_obj2 = new ThreadSetPriority1(); + ThreadSetPriority1 thread_obj3 = new ThreadSetPriority1(); + ThreadSetPriority1 thread_obj4 = new ThreadSetPriority1(); + thread_obj1.setPriority(6); + thread_obj4.setPriority(MIN_PRIORITY); + thread_obj2.setPriority(MAX_PRIORITY); + thread_obj3.setPriority(3); + thread_obj1.setPriority(2); + thread_obj2.setPriority(MIN_PRIORITY); + thread_obj3.setPriority(NORM_PRIORITY); + thread_obj4.setPriority(7); + thread_obj1.start(); + thread_obj2.start(); + thread_obj3.start(); + thread_obj4.start(); + if (thread_obj1.getPriority() != 2) { + System.out.println(2); + } + if (thread_obj2.getPriority() != 1) { + System.out.println(2); + } + if (thread_obj3.getPriority() != 5) { + System.out.println(2); + } + if (thread_obj4.getPriority() != 7) { + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0051-rt-thread-ThreadsetPriority2/ThreadSetPriority2.java b/test/testsuite/ouroboros/thread_test/RT0051-rt-thread-ThreadsetPriority2/ThreadSetPriority2.java new file mode 100755 index 0000000000000000000000000000000000000000..ab99de834df65c615b80ea1f17d04076e38c4504 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0051-rt-thread-ThreadsetPriority2/ThreadSetPriority2.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetPriority2 + *- @TestCaseName: Thread_ThreadSetPriority2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Child thread inherits the priority of the main thread + *- @Brief: see below + * -#step1: Define a test class that inherited from thread class and override run(). + * -#step2: Set current thread's priority. + * -#step3: Create two thread instance and start them. + * -#step4: Check that all priority of child thread was same. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetPriority2.java + *- @ExecuteClass: ThreadSetPriority2 + *- @ExecuteArgs: + */ + +class ThreadSetPriority_a extends Thread { + public synchronized void run() { + for (int i = 0; i < 10; i++) { + } + } +} + +public class ThreadSetPriority2 extends ThreadSetPriority_a { + public static void main(String[] args) { + currentThread().setPriority(2); + ThreadSetPriority2 thread_obj1 = new ThreadSetPriority2(); + ThreadSetPriority2 thread_obj2 = new ThreadSetPriority2(); + thread_obj1.start(); + thread_obj2.start(); + if (thread_obj1.getPriority() != 2) { + System.out.println(2); + return ; + } + if (thread_obj2.getPriority() != 2) { + System.out.println(2); + return ; + } + System.out.println(0); + return; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0052-rt-thread-ThreadsetPriority3/ThreadsSetPriority3.java b/test/testsuite/ouroboros/thread_test/RT0052-rt-thread-ThreadsetPriority3/ThreadsSetPriority3.java new file mode 100755 index 0000000000000000000000000000000000000000..af1c0384c7302179e0ab28a6ee679abe4d9db605 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0052-rt-thread-ThreadsetPriority3/ThreadsSetPriority3.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadsSetPriority3 + *- @TestCaseName: Thread_ThreadsSetPriority3.java + *- @RequirementName: Java Thread + *- @Title/Destination: SetPriority() throws IllegalArgumentException If the priority is not in the range MIN_PRIORITY + * to MAX_PRIORITY + *- @Brief: see below + * -#step1: Create four thread instance. + * -#step2: Set priority of thread. + * -#step3: Check that throw the IllegalArgumentException when priority out of range. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadsSetPriority3.java + *- @ExecuteClass: ThreadsSetPriority3 + *- @ExecuteArgs: + */ + +public class ThreadsSetPriority3 extends Thread { + public static void main(String[] args) { + ThreadsSetPriority3 thread_obj1 = new ThreadsSetPriority3(); + ThreadsSetPriority3 thread_obj2 = new ThreadsSetPriority3(); + ThreadsSetPriority3 thread_obj3 = new ThreadsSetPriority3(); + ThreadsSetPriority3 thread_obj4 = new ThreadsSetPriority3(); + try { + thread_obj1.setPriority(11); + System.out.println(2); + } catch (IllegalArgumentException e1) { + try { + thread_obj2.setPriority(0); + System.out.println(2); + } catch (IllegalArgumentException e2) { + try { + thread_obj3.setPriority(MAX_PRIORITY + 1); + System.out.println(2); + } catch (IllegalArgumentException e3) { + try { + thread_obj4.setPriority(MIN_PRIORITY - 1); + System.out.println(2); + } catch (IllegalArgumentException e4) { + System.out.println(0); + } + } + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0053-rt-thread-ThreadsetPriority4/ThreadSetPriority4.java b/test/testsuite/ouroboros/thread_test/RT0053-rt-thread-ThreadsetPriority4/ThreadSetPriority4.java new file mode 100755 index 0000000000000000000000000000000000000000..411cf81393ba7d3e6209bb229bdb9d37e823d74f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0053-rt-thread-ThreadsetPriority4/ThreadSetPriority4.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetPriority4 + *- @TestCaseName: Thread_ThreadSetPriority4.java + *- @RequirementName: Java Thread + *- @Title/Destination: SetPriority() after the thread dies will not change the priority successfully. + *- @Brief: see below + * -#step1: Create three thread instance. + * -#step2: Start the threads. + * -#step3: Run all threads until them die. + * -#step4: Check that priority was not changed when the thread was died. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetPriority4.java + *- @ExecuteClass: ThreadSetPriority4 + *- @ExecuteArgs: + */ + +public class ThreadSetPriority4 extends Thread { + public static void main(String[] args) { + ThreadSetPriority4 thread_obj1 = new ThreadSetPriority4(); + ThreadSetPriority4 thread_obj2 = new ThreadSetPriority4(); + ThreadSetPriority4 thread_obj3 = new ThreadSetPriority4(); + thread_obj1.start(); + thread_obj2.start(); + thread_obj3.start(); + try { + thread_obj1.join(); + thread_obj2.join(); + thread_obj3.join(); + } catch (InterruptedException e) { + } + thread_obj1.setPriority(7); + thread_obj2.setPriority(MAX_PRIORITY); + thread_obj3.setPriority(MIN_PRIORITY + 1); + if (thread_obj1.getPriority() != 5) { + System.out.println(2); + } + if (thread_obj2.getPriority() != 5) { + System.out.println(2); + } + if (thread_obj3.getPriority() != 5) { + 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 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0054-rt-thread-ThreadsetPriority5/ThreadSetPriority5.java b/test/testsuite/ouroboros/thread_test/RT0054-rt-thread-ThreadsetPriority5/ThreadSetPriority5.java new file mode 100755 index 0000000000000000000000000000000000000000..28eb97cafbd856f174b1b542bb7dd7b27c1a804b --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0054-rt-thread-ThreadsetPriority5/ThreadSetPriority5.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetPriority5 + *- @TestCaseName: Thread_ThreadSetPriority5.java + *- @RequirementName: Java Thread + *- @Title/Destination: SetPriority(NULL) throws NullPointerException + *- @Brief: see below + * -#step1: Create thread instance. + * -#step2: Test SetPriority(NULL) when its param is null. + * -#step3: Check that NullPointerException was threw. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetPriority5.java + *- @ExecuteClass: ThreadSetPriority5 + *- @ExecuteArgs: + */ + +public class ThreadSetPriority5 extends Thread { + public static void main(String[] args) { + Integer i = null; + ThreadSetPriority5 thread_obj1 = new ThreadSetPriority5(); + try { + thread_obj1.setPriority(i); + System.out.println(2); + } catch (IllegalArgumentException e) { + System.out.println(2); + } catch (NullPointerException e) { + System.out.println(0); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0055-rt-thread-ThreadsetPriority6/ThreadSetPriority6.java b/test/testsuite/ouroboros/thread_test/RT0055-rt-thread-ThreadsetPriority6/ThreadSetPriority6.java new file mode 100755 index 0000000000000000000000000000000000000000..d3ad1fd227a5e254b8bc1be5e0b738f57088625f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0055-rt-thread-ThreadsetPriority6/ThreadSetPriority6.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetPriority6 + *- @TestCaseName: Thread_ThreadSetPriority6.java + *- @RequirementName: Java Thread + *- @Title/Destination: SetMaxPriority() does not change the priority of threads in the Thread Group + *- @Brief: see below + * -#step1: Create a new ThreadGroup instance. + * -#step2: Assign the new thread to thread group. + * -#step3: Set priority to thread group. + * -#step4: Check that the priority of threads in the Thread Group was not change by calling SetMaxPriority(). + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetPriority6.java + *- @ExecuteClass: ThreadSetPriority6 + *- @ExecuteArgs: + */ + +public class ThreadSetPriority6 extends Thread { + public ThreadSetPriority6(ThreadGroup group, String name) { + super(group, name); + } + + public static void main(String[] args) { + ThreadGroup cls1 = new ThreadGroup("god"); + ThreadSetPriority6 cls2 = new ThreadSetPriority6(cls1, "good"); + cls1.setMaxPriority(3); + if (cls1.getMaxPriority() == 3 && cls2.getPriority() == 5) { + System.out.println(0); + return; + } + System.out.println(2); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0056-rt-thread-ThreadsetPriority7/ThreadSetPriority7.java b/test/testsuite/ouroboros/thread_test/RT0056-rt-thread-ThreadsetPriority7/ThreadSetPriority7.java new file mode 100755 index 0000000000000000000000000000000000000000..5932a00878fdaef04303282bb9f0fcaf868ab369 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0056-rt-thread-ThreadsetPriority7/ThreadSetPriority7.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetPriority7 + *- @TestCaseName: Thread_ThreadSetPriority7.java + *- @RequirementName: Java Thread + *- @Title/Destination: SetPriority() with value exceeds ThreadGroup's MaxPriority will not success,and does not throws + * exception. + *- @Brief: see below + * -#step1: Create a new ThreadGroup instance. + * -#step2: Assign the new thread to thread group. + * -#step3: Set thread and thread group priority. + * -#step4: Check that thread's priority will not greater than thread-group's. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetPriority7.java + *- @ExecuteClass: ThreadSetPriority7 + *- @ExecuteArgs: + */ + +public class ThreadSetPriority7 extends Thread { + public ThreadSetPriority7(ThreadGroup group, String name) { + super(group, name); + } + + public static void main(String[] args) { + ThreadGroup threadGroup = new ThreadGroup("god"); + ThreadSetPriority7 threadSetPriority7 = new ThreadSetPriority7(threadGroup, "good"); + threadGroup.setMaxPriority(3); + threadSetPriority7.setPriority(8); + if (threadGroup.getMaxPriority() == 3 && threadSetPriority7.getPriority() == 3) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0057-rt-thread-ThreadsetUncaughtExceptionHandler/ThreadSetUncaughtExceptionHandler.java b/test/testsuite/ouroboros/thread_test/RT0057-rt-thread-ThreadsetUncaughtExceptionHandler/ThreadSetUncaughtExceptionHandler.java new file mode 100755 index 0000000000000000000000000000000000000000..f905c105cb8565e2dda2aef31032993fb8a7d4fc --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0057-rt-thread-ThreadsetUncaughtExceptionHandler/ThreadSetUncaughtExceptionHandler.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetUncaughtExceptionHandler + *- @TestCaseName: Thread_ThreadSetUncaughtExceptionHandler.java + *- @RequirementName: Java Thread + *- @Title/Destination: SetUncaughtExceptionHandler set he exception handler for a child thread. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadSetDefaultUncaughtExceptionHandler1,含run()方法设置3/0的异常。 + * -#step2: 通过new得到两个ThreadGetDefaultUncaughtExceptionHandler1的对象,分别使用setDefaultUncaughtExceptionHandler() + * 设置默认的异常处理程序。 + * -#step3: 启动线程对象,等待线程结束,确认异常处理程序被调用。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadSetUncaughtExceptionHandler.java + *- @ExecuteClass: ThreadSetUncaughtExceptionHandler + *- @ExecuteArgs: + */ + +public class ThreadSetUncaughtExceptionHandler extends Thread { + static int i = 0; + static String p; + + public void run() { + System.out.println(3/0); + } + + public static void main(String[] args) { + ThreadSetUncaughtExceptionHandler cls = new ThreadSetUncaughtExceptionHandler(); + ThreadSetUncaughtExceptionHandler cls2 = new ThreadSetUncaughtExceptionHandler(); + cls.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + p = e.toString(); + if (p.indexOf("java.lang.ArithmeticException") != -1) { + i++; + } + } + }); + cls2.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + } + }); + cls.start(); + cls2.start(); + try { + cls.join(); + cls2.join(); + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (i == 1) { + System.out.println(0); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0058-rt-thread-ThreadStateinterrupt1/ThreadStateInterrupt1.java b/test/testsuite/ouroboros/thread_test/RT0058-rt-thread-ThreadStateinterrupt1/ThreadStateInterrupt1.java new file mode 100755 index 0000000000000000000000000000000000000000..5c67a31c4c8eadcb2c4e6299cb02950e643219ba --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0058-rt-thread-ThreadStateinterrupt1/ThreadStateInterrupt1.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateInterrupt1 + *- @TestCaseName: Thread_ThreadStateInterrupt1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Interrupt a thread blocked in an invocation of the wait(), wait(long), or wait(long, int) + * methods of the Object class, then its interrupt status will be cleared and it will receive an + * InterruptedException. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadStateInterrupt1。 + * -#step2: 定义线程安全的run()方法,中断调用wait()的线程时会捕获通过InterruptedException异常。 + * -#step3: 通过new关键字得到Thread类的线程对象。 + * -#step4:启动线程对象,等待50毫秒后中断线程,抛出InterruptedException,线程后续操作未被执行。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateInterrupt1.java + *- @ExecuteClass: ThreadStateInterrupt1 + *- @ExecuteArgs: + */ + +public class ThreadStateInterrupt1 extends Thread { + static int i = 0; + static boolean j; + + public static void main(String[] args) { + ThreadStateInterrupt1 cls = new ThreadStateInterrupt1(); + cls.start(); + try { + sleep(50); + } catch (InterruptedException e2) { + System.err.println(e2); + } + cls.interrupt(); + try { + sleep(50); + } catch (InterruptedException e3) { + System.err.println(e3); + } + if (j && i == 0) { + System.out.println(0); + } + } + + public synchronized void run() { + try { + while (!Thread.currentThread().isInterrupted()) { + wait(); + i++; + } + } catch (InterruptedException e1) { + Thread.currentThread().interrupt(); + j = Thread.currentThread().isInterrupted(); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0059-rt-thread-ThreadStateinterrupt2/ThreadStateInterrupt2.java b/test/testsuite/ouroboros/thread_test/RT0059-rt-thread-ThreadStateinterrupt2/ThreadStateInterrupt2.java new file mode 100755 index 0000000000000000000000000000000000000000..15a4b9e82f58e886b00937efa61f60c2c867b663 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0059-rt-thread-ThreadStateinterrupt2/ThreadStateInterrupt2.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateInterrupt2 + *- @TestCaseName: Thread_ThreadStateInterrupt2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Threads that are not interrupted keep waiting till time up. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadStateInterrupt2。 + * -#step2: 定义线程安全的run()方法,线程未中断直到等待时间结束。 + * -#step3: 通过new关键字得到ThreadStateInterrupt2类的线程对象。 + * -#step4:启动线程对象,调用sleep()方法,线程未中断直到等待时间结束。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateInterrupt2.java + *- @ExecuteClass: ThreadStateInterrupt2 + *- @ExecuteArgs: + */ + +public class ThreadStateInterrupt2 extends Thread { + static int i = 0; + static boolean j = false; + + public static void main(String[] args) { + ThreadStateInterrupt2 cls = new ThreadStateInterrupt2(); + cls.start(); + try { + sleep(50); + } catch (InterruptedException e2) { + System.err.println(e2); + } + if (!j && !cls.isInterrupted() && i == 0) { + System.out.println(0); + } + } + + public synchronized void run() { + try { + while (!Thread.currentThread().isInterrupted()) { + wait(2000); + break; + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + j = Thread.currentThread().isInterrupted(); + i++; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0060-rt-thread-ThreadStatejoin1/ThreadStateJoin1.java b/test/testsuite/ouroboros/thread_test/RT0060-rt-thread-ThreadStatejoin1/ThreadStateJoin1.java new file mode 100755 index 0000000000000000000000000000000000000000..1962de7c68d1152a6da534262fd6073427969d2a --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0060-rt-thread-ThreadStatejoin1/ThreadStateJoin1.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin1 + *- @TestCaseName: Thread_ThreadStateJoin1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Wait for target thread to end. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadStateJoin1。 + * -#step2: 通过new关键字得到ThreadStateInterrupt2类的线程对象。 + * -#step3:启动线程对象,调用join()方法确认该线程的状态为TERMINATED。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateJoin1.java + *- @ExecuteClass: ThreadStateJoin1 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin1 extends Thread { + public static void main(String[] args) { + ThreadStateJoin1 cls = new ThreadStateJoin1(); + cls.start(); + try { + cls.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + if (cls.getState().toString().equals("TERMINATED")) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0061-rt-thread-ThreadStatejoin11/ThreadStateJoin11.java b/test/testsuite/ouroboros/thread_test/RT0061-rt-thread-ThreadStatejoin11/ThreadStateJoin11.java new file mode 100755 index 0000000000000000000000000000000000000000..6ea408f307e991b07b6fd89ee1465414b0959e18 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0061-rt-thread-ThreadStatejoin11/ThreadStateJoin11.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin11 + *- @TestCaseName: Thread_ThreadStateJoin11.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verify the accuracy of join time. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadStateJoin11。 + * -#step2: 定义run()方法,指定synchronized的对象,指定休眠时间。 + * -#step2: 通过new关键字得到ThreadStateJoin11类的线程对象。 + * -#step3:启动线程对象,获取启动时的当前时间。调用join()方法,获取线程结束时的当前时间。计算花费时间在970~1030毫秒之间。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin11.java + *- @ExecuteClass: ThreadStateJoin11 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin11 extends Thread { + static Object ob = "aa"; + + public static void main(String[] args) { + long startTime; + long endTime; + ThreadStateJoin11 cls = new ThreadStateJoin11(); + cls.start(); + startTime = System.currentTimeMillis(); + try { + cls.join(1000); + } catch (InterruptedException ex) { + System.out.println("Join is interrupted"); + } + endTime = System.currentTimeMillis(); + if (endTime - startTime > 970 && endTime - startTime < 1030) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (ob) { + try { + sleep(2000); + } catch (InterruptedException e) { + System.out.println("Sleep is interrupted"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0062-rt-thread-ThreadStatejoin12/ThreadStateJoin12.java b/test/testsuite/ouroboros/thread_test/RT0062-rt-thread-ThreadStatejoin12/ThreadStateJoin12.java new file mode 100755 index 0000000000000000000000000000000000000000..9a5164defedcc8cd8204f18b7039d822b1b470c1 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0062-rt-thread-ThreadStatejoin12/ThreadStateJoin12.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin12 + *- @TestCaseName: Thread_ThreadStateJoin12.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verify the accuracy of the wait time after the join gets the object lock. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadStateJoin12。 + * -#step2: 定义run()方法,指定synchronized的对象,指定休眠时间。 + * -#step2: 通过new关键字得到ThreadStateJoin12类的线程对象。 + * -#step3:启动线程对象,获取启动时的当前时间。调用join()方法,获取线程结束时的当前时间。计算花费时间在590~1010毫秒之间。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateJoin12.java + *- @ExecuteClass: ThreadStateJoin12 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin12 extends Thread { + public static void main(String[] args) { + long startTime; + long endTime; + ThreadStateJoin12 cls = new ThreadStateJoin12(); + cls.start(); + startTime = System.currentTimeMillis(); + try { + cls.join(600); + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + endTime = System.currentTimeMillis(); + if (endTime - startTime > 590 && endTime - startTime < 1010) { + System.out.println(0); + } + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 5; i++) { + try { + sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0063-rt-thread-ThreadStatejoin13/ThreadStateJoin13.java b/test/testsuite/ouroboros/thread_test/RT0063-rt-thread-ThreadStatejoin13/ThreadStateJoin13.java new file mode 100755 index 0000000000000000000000000000000000000000..c6113a242136cb6d7e2e214ed329fed9d42f7ef9 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0063-rt-thread-ThreadStatejoin13/ThreadStateJoin13.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin13 + *- @TestCaseName: Thread_ThreadStateJoin13.java + *- @RequirementName: Java Thread + *- @Title/Destination: Validation join(0) equals infinite wait. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadStateJoin13。 + * -#step2: 定义run()方法,循环三次,指定synchronized的对象,指定休眠时间,t自增1。 + * -#step3: 通过new关键字得到ThreadStateJoin13类的线程对象。 + * -#step4:启动线程对象,调用join()方法,等待线程运行结束。获取线程的状态为TERMINATED。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin13.java + *- @ExecuteClass: ThreadStateJoin13 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin13 extends Thread { + static int t = 0; + + public static void main(String[] args) { + ThreadStateJoin13 cls = new ThreadStateJoin13(); + cls.start(); + try { + cls.join(0); + t++; + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (cls.getState().toString().equals("TERMINATED") && t == 4) { + System.out.println(0); + } + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 3; i++) { + try { + sleep(200); + t++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0064-rt-thread-ThreadStatejoin14/ThreadStateJoin14.java b/test/testsuite/ouroboros/thread_test/RT0064-rt-thread-ThreadStatejoin14/ThreadStateJoin14.java new file mode 100755 index 0000000000000000000000000000000000000000..86c4471383ff5fc7b9699b2f1cf5895c504b5e58 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0064-rt-thread-ThreadStatejoin14/ThreadStateJoin14.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin14 + *- @TestCaseName: Thread_ThreadStateJoin14.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verify waiting for negative seconds throws IllegalArgumentException. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadStateJoin14。 + * -#step2: 定义run()方法,循环三次,指定synchronized的对象,指定休眠时间。 + * -#step2: 通过new关键字得到ThreadStateJoin14类的线程对象。 + * -#step3:启动线程对象。调用join()方法,指定否定秒为负值。确认抛出IllegalArgumentException。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin14.java + *- @ExecuteClass: ThreadStateJoin14 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin14 extends Thread { + public static void main(String[] args) { + ThreadStateJoin14 cls = new ThreadStateJoin14(); + cls.start(); + try { + cls.join(-10); + } catch (InterruptedException e1) { + System.out.println(2); + } catch (IllegalArgumentException e2) { + System.out.println(0); + } + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 3; i++) { + try { + sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0065-rt-thread-ThreadStatejoin15/ThreadStateJoin15.java b/test/testsuite/ouroboros/thread_test/RT0065-rt-thread-ThreadStatejoin15/ThreadStateJoin15.java new file mode 100755 index 0000000000000000000000000000000000000000..e9bb03a226e56d116a2f7fa0b08a2e77e1765927 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0065-rt-thread-ThreadStatejoin15/ThreadStateJoin15.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin15 + *- @TestCaseName: Thread_ThreadStateJoin15.java + *- @RequirementName: Java Thread + *- @Title/Destination: Validation waits for negative milliseconds throws IllegalArgumentException. + *- @Brief: see below + * -#step1: 定义继承Thread类的线程类ThreadStateJoin15。 + * -#step2: 定义run()方法,循环三次,指定synchronized的对象,指定休眠时间。 + * -#step2: 通过new关键字得到ThreadStateJoin15类的线程对象。 + * -#step3:启动线程对象。调用join()方法,构造参数nanos为负值,millis为1000。确认会抛出IllegalArgumentException。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateJoin15.java + *- @ExecuteClass: ThreadStateJoin15 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin15 extends Thread { + public static void main(String[] args) { + ThreadStateJoin15 cls = new ThreadStateJoin15(); + cls.start(); + try { + cls.join(1000, -10); + } catch (InterruptedException e1) { + System.out.println(2); + } catch (IllegalArgumentException e2) { + System.out.println(0); + } + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 3; i++) { + try { + sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0066-rt-thread-ThreadStatejoin2/ThreadStateJoin2.java b/test/testsuite/ouroboros/thread_test/RT0066-rt-thread-ThreadStatejoin2/ThreadStateJoin2.java new file mode 100755 index 0000000000000000000000000000000000000000..203213dac5f6df72268859c0b77c272f7010803b --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0066-rt-thread-ThreadStatejoin2/ThreadStateJoin2.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin2 + *- @TestCaseName: Thread_ThreadStateJoin2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Wait time unit is seconds target thread ends. + *- @Brief: see below + * -#step1: 创建一个ThreadStateJoin2类的实例对象threadStateJoin2,并且ThreadStateJoin2类继承自Thread类; + * -#step2: 调用threadStateJoin2的start()方法启动该线程; + * -#step3: 调用threadStateJoin2的join()方法,参数为1000; + * -#step4: run方法循环三次,每次令int类型的全局静态变量t的值加1; + * -#step5: 经判断得知threadStateJoin2.getState().toString()的返回值与字符串"TERMINATED"相同,并且ThreadStateJoin2类在其 + * 内部的run()方法执行完之后t的值变为4; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin2.java + *- @ExecuteClass: ThreadStateJoin2 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin2 extends Thread { + static int t = 0; + + public static void main(String[] args) { + ThreadStateJoin2 threadStateJoin2 = new ThreadStateJoin2(); + threadStateJoin2.start(); + try { + threadStateJoin2.join(1000); + t++; + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (threadStateJoin2.getState().toString().equals("TERMINATED") && t == 4) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 3; i++) { + try { + sleep(200); + t++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0067-rt-thread-ThreadStatejoin3/ThreadStateJoin3.java b/test/testsuite/ouroboros/thread_test/RT0067-rt-thread-ThreadStatejoin3/ThreadStateJoin3.java new file mode 100755 index 0000000000000000000000000000000000000000..aaa7db2bd1bbfdfa9861c6043c523adde32e1118 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0067-rt-thread-ThreadStatejoin3/ThreadStateJoin3.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin3 + *- @TestCaseName: Thread_ThreadStateJoin3.java + *- @RequirementName: Java Thread + *- @Title/Destination: Wait time unit is millisecond target thread ends. + *- @Brief: see below + * -#step1: 创建一个ThreadStateJoin3类的实例对象threadStateJoin3,并且ThreadStateJoin3类继承自Thread类; + * -#step2: 调用threadStateJoin3的start()方法启动该线程; + * -#step3: 调用threadStateJoin3的join()方法,参数1为1000、参数2为300; + * -#step4: run方法循环三次,每次令int类型的全局静态变量t的值加1; + * -#step5: 经判断得知threadStateJoin3.getState().toString()的返回值与字符串"TERMINATED"相同,并且ThreadStateJoin3类在其 + * 内部的run()方法执行完之后t的值变为4; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin3.java + *- @ExecuteClass: ThreadStateJoin3 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin3 extends Thread { + static int t = 0; + + public static void main(String[] args) { + ThreadStateJoin3 threadStateJoin3 = new ThreadStateJoin3(); + threadStateJoin3.start(); + try { + threadStateJoin3.join(1000, 300); + t++; + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (threadStateJoin3.getState().toString().equals("TERMINATED") && t == 4) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 3; i++) { + try { + sleep(200); + t++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0068-rt-thread-ThreadStatejoin4/ThreadStateJoin4.java b/test/testsuite/ouroboros/thread_test/RT0068-rt-thread-ThreadStatejoin4/ThreadStateJoin4.java new file mode 100755 index 0000000000000000000000000000000000000000..13a2e16e47ed9ec3b60f8c8405da89ae06c811e3 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0068-rt-thread-ThreadStatejoin4/ThreadStateJoin4.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin4 + *- @TestCaseName: Thread_ThreadStateJoin4.java + *- @RequirementName: Java Thread + *- @Title/Destination: Wait time unit seconds and target thread is not finished after wait. + *- @Brief: see below + * -#step1: 创建一个ThreadStateJoin4类的实例对象threadStateJoin4,并且ThreadStateJoin4类继承自Thread类; + * -#step2: 调用threadStateJoin4的start()方法启动该线程; + * -#step3: 调用threadStateJoin4的join()方法,参数为500; + * -#step4: run方法循环5次,每次令int类型的全局静态变量t的值加1; + * -#step5: 经判断得知threadStateJoin4.getState().toString()的返回值与字符串"TIMED_WAITING"相同,并且ThreadStateJoin4类 + * 在其内部的run()方法执行完之后t的值变为3; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin4.java + *- @ExecuteClass: ThreadStateJoin4 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin4 extends Thread { + static int t = 0; + + public static void main(String[] args) { + ThreadStateJoin4 threadStateJoin4 = new ThreadStateJoin4(); + threadStateJoin4.start(); + try { + threadStateJoin4.join(500); + t++; + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (threadStateJoin4.getState().toString().equals("TIMED_WAITING") && t == 3) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 5; i++) { + try { + wait(200); + t++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0069-rt-thread-ThreadStatejoin5/ThreadStateJoin5.java b/test/testsuite/ouroboros/thread_test/RT0069-rt-thread-ThreadStatejoin5/ThreadStateJoin5.java new file mode 100755 index 0000000000000000000000000000000000000000..0e91ea338a2da9c1574ca81dadf9ae4944b3bebe --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0069-rt-thread-ThreadStatejoin5/ThreadStateJoin5.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin5 + *- @TestCaseName: Thread_ThreadStateJoin5.java + *- @RequirementName: Java Thread + *- @Title/Destination: Wait time unit is millisecond target thread is not finished after wait. + *- @Brief: see below + * -#step1: 创建一个ThreadStateJoin5类的实例对象threadStateJoin5,并且ThreadStateJoin5类继承自Thread类; + * -#step2: 调用threadStateJoin5的start()方法启动该线程; + * -#step3: 调用threadStateJoin5的join()方法,参数为500、300; + * -#step4: run方法循环5次,每次令int类型的全局静态变量t的值加1; + * -#step5: 经判断得知threadStateJoin5.getState().toString()的返回值与字符串"TIMED_WAITING"相同,并且ThreadStateJoin5类 + * 在其内部的run()方法执行完之后t的值变为3; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin5.java + *- @ExecuteClass: ThreadStateJoin5 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin5 extends Thread { + static int t = 0; + + public static void main(String[] args) { + ThreadStateJoin5 threadStateJoin5 = new ThreadStateJoin5(); + threadStateJoin5.start(); + try { + threadStateJoin5.join(500, 300); + t++; + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (threadStateJoin5.getState().toString().equals("TIMED_WAITING") && t == 3) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 5; i++) { + try { + wait(200); + t++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0070-rt-thread-ThreadStatejoin6/ThreadStateJoin6.java b/test/testsuite/ouroboros/thread_test/RT0070-rt-thread-ThreadStatejoin6/ThreadStateJoin6.java new file mode 100755 index 0000000000000000000000000000000000000000..d33f5e6568c9efed483ab4c8328605d14552dd71 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0070-rt-thread-ThreadStatejoin6/ThreadStateJoin6.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin6 + *- @TestCaseName: Thread_ThreadStateJoin6.java + *- @RequirementName: Java Thread + *- @Title/Destination: Wait time unit seconds target thread does not end. + *- @Brief: see below + * -#step1: 创建一个ThreadStateJoin6类的实例对象threadStateJoin6,并且ThreadStateJoin6类继承自Thread类; + * -#step2: 调用threadStateJoin6的start()方法启动该线程; + * -#step3: 调用threadStateJoin6的join()方法,参数为500; + * -#step4: run方法循环5次,每次int类型的全局静态变量t的值加1,然后wait,然后再加1; + * -#step5: 经判断得知threadStateJoin6.getState().toString()的返回值与字符串"TIMED_WAITING"相同,并且ThreadStateJoin6类 + * 在其内部的run()方法执行完之后t的值变为2; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin6.java + *- @ExecuteClass: ThreadStateJoin6 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin6 extends Thread { + static int t = 0; + + public static void main(String[] args) { + ThreadStateJoin6 threadStateJoin6 = new ThreadStateJoin6(); + threadStateJoin6.start(); + try { + threadStateJoin6.join(500); + t++; + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (threadStateJoin6.getState().toString().equals("TIMED_WAITING") && t == 2) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 5; i++) { + try { + t++; + wait(1000); + t++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0071-rt-thread-ThreadStatejoin7/ThreadStateJoin7.java b/test/testsuite/ouroboros/thread_test/RT0071-rt-thread-ThreadStatejoin7/ThreadStateJoin7.java new file mode 100755 index 0000000000000000000000000000000000000000..0b4575d300023c2155f09461dc5f66e5bd184153 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0071-rt-thread-ThreadStatejoin7/ThreadStateJoin7.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin7 + *- @TestCaseName: Thread_ThreadStateJoin7.java + *- @RequirementName: Java Thread + *- @Title/Destination: Wait time unit is millisecond target thread does not end. + *- @Brief: see below + * -#step1: 创建一个ThreadStateJoin7类的实例对象threadStateJoin7,并且ThreadStateJoin7类继承自Thread类; + * -#step2: 调用threadStateJoin7的start()方法启动该线程; + * -#step3: 调用threadStateJoin7的join()方法,参数为500、300; + * -#step4: run方法循环5次,每次令int类型的全局静态变量t的值加1,然后wait,然后再加1; + * -#step5: 经判断得知threadStateJoin7.getState().toString()的返回值与字符串"TIMED_WAITING"相同,并且ThreadStateJoin7类 + * 在其内部的run()方法执行完之后t的值变为2; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin7.java + *- @ExecuteClass: ThreadStateJoin7 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin7 extends Thread { + static int t = 0; + + public static void main(String[] args) { + ThreadStateJoin7 threadStateJoin7 = new ThreadStateJoin7(); + threadStateJoin7.start(); + try { + threadStateJoin7.join(500, 300); + t++; + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (threadStateJoin7.getState().toString().equals("TIMED_WAITING") && t == 2) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (currentThread()) { + for (int i = 1; i <= 5; i++) { + try { + t++; + wait(1000); + t++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0072-rt-thread-ThreadStatejoin8/ThreadStateJoin8.java b/test/testsuite/ouroboros/thread_test/RT0072-rt-thread-ThreadStatejoin8/ThreadStateJoin8.java new file mode 100755 index 0000000000000000000000000000000000000000..de69847ce8ae5fd29a6ca875d2b0c565b3fd7982 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0072-rt-thread-ThreadStatejoin8/ThreadStateJoin8.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin8 + *- @TestCaseName: Thread_ThreadStateJoin8.java + *- @RequirementName: Java Thread + *- @Title/Destination: Wait time unit seconds target thread is still sleeping. + *- @Brief: see below + * -#step1: 创建一个ThreadStateJoin8类的实例对象threadStateJoin8,并且ThreadStateJoin8类继承自Thread类; + * -#step2: 调用threadStateJoin8的start()方法启动该线程; + * -#step3: 调用threadStateJoin8的join()方法,参数为1000; + * -#step4: run方法循环5次,每次sleep后int类型的全局静态变量t的值加1; + * -#step5: 经判断得知threadStateJoin8.getState().toString()的返回值与字符串"TIMED_WAITING"相同,并且ThreadStateJoin8类 + * 在其内部的run()方法执行完之后t的值变为3; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateJoin8.java + *- @ExecuteClass: ThreadStateJoin8 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin8 extends Thread { + static int t = 0; + + public static void main(String[] args) { + ThreadStateJoin8 threadStateJoin8 = new ThreadStateJoin8(); + threadStateJoin8.start(); + try { + threadStateJoin8.join(1000); + t++; + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (threadStateJoin8.getState().toString().equals("TIMED_WAITING") && t == 3) { + System.out.println(0); + return; + } + } + + public void run() { + for (int i = 1; i <= 5; i++) { + try { + sleep(400); + t++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0073-rt-thread-ThreadStatejoin9/ThreadStateJoin9.java b/test/testsuite/ouroboros/thread_test/RT0073-rt-thread-ThreadStatejoin9/ThreadStateJoin9.java new file mode 100755 index 0000000000000000000000000000000000000000..b758a48ef521080d0c2400f8a5fb0feaccc2d455 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0073-rt-thread-ThreadStatejoin9/ThreadStateJoin9.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateJoin9 + *- @TestCaseName: Thread_ThreadStateJoin9.java + *- @RequirementName: Java Thread + *- @Title/Destination: Wait time unit is millisecond target thread is still sleeping. + *- @Brief: see below + * -#step1: 创建一个ThreadStateJoin9类的实例对象threadStateJoin9,并且ThreadStateJoin9类继承自Thread类; + * -#step2: 调用threadStateJoin9的start()方法启动该线程; + * -#step3: 调用threadStateJoin9的join()方法,参数为500,300; + * -#step4: run方法循环5次,每次sleep后int类型的全局静态变量t的值加1; + * -#step5: 经判断得知threadStateJoin9.getState().toString()的返回值与字符串"TIMED_WAITING"相同,并且ThreadStateJoin9类 + * 在其内部的run()方法执行完之后t的值变为3; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateJoin9.java + *- @ExecuteClass: ThreadStateJoin9 + *- @ExecuteArgs: + */ + +public class ThreadStateJoin9 extends Thread { + static int t = 0; + + public static void main(String[] args) { + ThreadStateJoin9 threadStateJoin9 = new ThreadStateJoin9(); + threadStateJoin9.start(); + try { + threadStateJoin9.join(500, 300); + t++; + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + if (threadStateJoin9.getState().toString().equals("TIMED_WAITING") && t == 3) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + for (int i = 1; i <= 5; i++) { + try { + sleep(200); + t++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0074-rt-thread-ThreadStatenotify1/ThreadStateNotify1.java b/test/testsuite/ouroboros/thread_test/RT0074-rt-thread-ThreadStatenotify1/ThreadStateNotify1.java new file mode 100755 index 0000000000000000000000000000000000000000..a36d24c5de291460f9ee71780865a9f450de368b --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0074-rt-thread-ThreadStatenotify1/ThreadStateNotify1.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateNotify1 + *- @TestCaseName: Thread_ThreadStateNotify1.java + *- @RequirementName: Java Thread + *- @Title/Destination: notify() wakes up a single thread that is waiting on this object's monitor. If any threads are + * waiting on this object, one of them is chosen randomly to be awakened. + *- @Brief: see below + * -#step1: 创建一个Object的对象并赋值给变量lock; + * -#step2: 以lock为参数,创建两个ThreadA类的实例对象threadA、threadA2,并且ThreadA类继承自Thread类; + * -#step3: 以lock为参数,创建SynNotifyMethodThreadA类的实例对象synNotifyMethodThreadA,并且SynNotifyMethodThreadA类继承 + * 自Thread类; + * -#step4: 分别调用threadA、threadA2、synNotifyMethodThreadA的start()方法启动这三个线程; + * -#step5: 让当前线程休眠1000ms; + * -#step6: 确定在执行完ThreadA类和SynNotifyMethodThreadA类的内部的run()方法后,线程threadA、threadA2的状态有且仅有一个 + * 与枚举类型Thread.State.TIMED_WAITING相同,并且Service1类中定义的int类型的静态变量i和t都由0变为1; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateNotify1.java + *- @ExecuteClass: ThreadStateNotify1 + *- @ExecuteArgs: + */ + +class Service1 { + static int i = 0; + static int t = 0; + + public void testMethod(Object lock) { + try { + synchronized (lock) { + lock.wait(3000); + i++; + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void syncNotifyMethod(Object lock) { + try { + Thread.sleep(100); + synchronized (lock) { + lock.notify(); + t++; + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} + +class ThreadA extends Thread { + private Object lock; + + public ThreadA(Object lock) { + this.lock = lock; + } + + public void run() { + Service1 service = new Service1(); + service.testMethod(lock); + } +} + +class SynNotifyMethodThreadA extends Thread { + private Object lock; + + public SynNotifyMethodThreadA(Object lock) { + this.lock = lock; + } + + public void run() { + Service1 service = new Service1(); + service.syncNotifyMethod(lock); + } +} + +public class ThreadStateNotify1 { + public static void main(String[] args) { + Object lock = new Object(); + ThreadA threadA = new ThreadA(lock); + ThreadA threadA2 = new ThreadA(lock); + SynNotifyMethodThreadA synNotifyMethodThreadA = new SynNotifyMethodThreadA(lock); + try { + threadA.start(); + threadA2.start(); + synNotifyMethodThreadA.start(); + Thread.sleep(1000); + } catch (Exception e) { + e.printStackTrace(); + } + if (!threadA.getState().equals(Thread.State.TIMED_WAITING) && Service1.i == 1 && Service1.t == 1) { + System.out.println(0); + return; + } + if (!threadA2.getState().equals(Thread.State.TIMED_WAITING) && Service1.i == 1 && Service1.t == 1) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0075-rt-thread-ThreadStatenotify2/ThreadStateNotify2.java b/test/testsuite/ouroboros/thread_test/RT0075-rt-thread-ThreadStatenotify2/ThreadStateNotify2.java new file mode 100755 index 0000000000000000000000000000000000000000..0b0d3e7fbb9823a109e27be7dc9b7a45b078d974 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0075-rt-thread-ThreadStatenotify2/ThreadStateNotify2.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateNotify2 + *- @TestCaseName: Thread_ThreadStateNotify2.java + *- @RequirementName: Java Thread + *- @Title/Destination: If the current thread is not the owner of this object's monitor, notify throws + * IllegalMonitorStateException. + *- @Brief: see below + * -#step1: 定义一个Object类型的变量object,并赋初始值为"aa"; + * -#step2: 尝试调用object的notify()方法; + * -#step3: step2中方法调用失败,会抛出IllegalMonitorStateException; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateNotify2.java + *- @ExecuteClass: ThreadStateNotify2 + *- @ExecuteArgs: + */ + +public class ThreadStateNotify2 extends Thread { + static Object object = "aa"; + + public static void main(String[] args) { + try { + object.notify(); + System.out.println(2); + } catch (IllegalMonitorStateException e) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0076-rt-thread-ThreadStatenotifyAll1/ThreadStateNotifyAll1.java b/test/testsuite/ouroboros/thread_test/RT0076-rt-thread-ThreadStatenotifyAll1/ThreadStateNotifyAll1.java new file mode 100755 index 0000000000000000000000000000000000000000..a31463ede0bd6109c1feb5034f62b5020f9e0a14 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0076-rt-thread-ThreadStatenotifyAll1/ThreadStateNotifyAll1.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateNotifyAll1 + *- @TestCaseName: Thread_ThreadStateNotifyAll1.java + *- @RequirementName: Java Thread + *- @Title/Destination: NotifyAll wakes up all threads that are waiting on this object's monitor. + *- @Brief: see below + * -#step1: 新建一个Object类型的对象lock; + * -#step2: 以lock为参数,创建两个ThreadB类的实例对象threadB、threadB2,并且ThreadB类继承自Thread类; + * -#step3: 以lock为参数,创建SynNotifyMethodThreadB类的实例对象synNotifyMethodThreadB,并且SynNotifyMethodThreadB类继承 + * 自Thread类; + * -#step4: 分别调用threadB、threadB2、synNotifyMethodThreadB的start()方法启动这三个线程; + * -#step5: 让当前线程休眠1000ms; + * -#step6: 经判断得知,在执行完ThreadB类和SynNotifyMethodThreadB类的内部的run()方法后,线程threadB、threadB2的状态与枚 + * 举类Thread.State.WAITING均不相同,并且Service2类的int类型的静态变量i由0变为2,t由0变为1; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateNotifyAll1.java + *- @ExecuteClass: ThreadStateNotifyAll1 + *- @ExecuteArgs: + */ + +class Service2 { + static int i = 0; + static int t = 0; + + public void testMethod(Object lock) { + try { + synchronized (lock) { + lock.wait(); + i++; + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void synNotifyMethod(Object lock) { + try { + Thread.sleep(100); + synchronized (lock) { + lock.notifyAll(); + t++; + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} + +class ThreadB extends Thread { + private Object lock; + + public ThreadB(Object lock) { + this.lock = lock; + } + + public void run() { + Service2 service = new Service2(); + service.testMethod(lock); + } +} + +class SynNotifyMethodThreadB extends Thread { + private Object lock; + + public SynNotifyMethodThreadB(Object lock) { + this.lock = lock; + } + + public void run() { + Service2 service = new Service2(); + service.synNotifyMethod(lock); + } +} + +public class ThreadStateNotifyAll1 { + public static void main(String[] args) { + Object lock = new Object(); + ThreadB threadB = new ThreadB(lock); + ThreadB threadB2 = new ThreadB(lock); + SynNotifyMethodThreadB synNotifyMethodThreadB = new SynNotifyMethodThreadB(lock); + try { + threadB.start(); + threadB2.start(); + synNotifyMethodThreadB.start(); + Thread.sleep(1000); + } catch (Exception e) { + e.printStackTrace(); + } + if (!threadB.getState().equals(Thread.State.WAITING)) { + if (!threadB2.getState().equals(Thread.State.WAITING) && Service2.i == 2 && Service2.t == 1) { + System.out.println(0); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0077-rt-thread-ThreadStatenotifyAll2/ThreadStateNotifyAll2.java b/test/testsuite/ouroboros/thread_test/RT0077-rt-thread-ThreadStatenotifyAll2/ThreadStateNotifyAll2.java new file mode 100755 index 0000000000000000000000000000000000000000..20822bc6101e3e5fc51db8a9d1b781f5aee511b0 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0077-rt-thread-ThreadStatenotifyAll2/ThreadStateNotifyAll2.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateNotifyAll2 + *- @TestCaseName: Thread_ThreadStateNotifyAll2.java + *- @RequirementName: Java Thread + *- @Title/Destination: if the current thread is not the owner of this object's monitor, notifyAll() throws + * IllegalMonitorStateException + *- @Brief: see below + * -#step1: 定义一个Object类型的变量object,并赋初始值为"aa"; + * -#step2: 尝试调用object的notifyAll()方法; + * -#step3: step2中方法调用失败,会抛出IllegalMonitorStateException; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateNotifyAll2.java + *- @ExecuteClass: ThreadStateNotifyAll2 + *- @ExecuteArgs: + */ + +public class ThreadStateNotifyAll2 extends Thread { + static Object object = "aa"; + + public static void main(String[] args) { + try { + object.notifyAll(); + System.out.println(2); + } catch (IllegalMonitorStateException e) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0078-rt-thread-ThreadStatesleep1/ThreadStateSleep1.java b/test/testsuite/ouroboros/thread_test/RT0078-rt-thread-ThreadStatesleep1/ThreadStateSleep1.java new file mode 100755 index 0000000000000000000000000000000000000000..ce714a7da7c03059093cde9eb5db125c59e34c09 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0078-rt-thread-ThreadStatesleep1/ThreadStateSleep1.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateSleep1 + *- @TestCaseName: Thread_ThreadStateSleep1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Primary thread sleep second-level time, target thread has ended. + *- @Brief: see below + * -#step1: 创建四个ThreadStateSleep1类的实例对象threadStateSleep1、threadStateSleep2、threadStateSleep3、 + * threadStateSleep4,并且ThreadStateSleep1类继承自Thread类; + * -#step2: 分别调用threadStateSleep1、threadStateSleep2的start()方法启动这两个线程; + * -#step3: 让当前线程休眠1000ms; + * -#step4: 分别调用threadStateSleep3、threadStateSleep4的start()方法启动这两个线程; + * -#step5: 经判断得知,线程threadStateSleep1的状态是"TERMINATED"的;另外线程threadStateSleep4的状态 + * 要么是"RUNNABLE"的,,要么是"TERMINATED"的,并且只能是两种情况中的一种; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateSleep1.java + *- @ExecuteClass: ThreadStateSleep1 + *- @ExecuteArgs: + */ + +public class ThreadStateSleep1 extends Thread { + public static void main(String[] args) { + ThreadStateSleep1 threadStateSleep1 = new ThreadStateSleep1(); + ThreadStateSleep1 threadStateSleep2 = new ThreadStateSleep1(); + ThreadStateSleep1 threadStateSleep3 = new ThreadStateSleep1(); + ThreadStateSleep1 threadStateSleep4 = new ThreadStateSleep1(); + threadStateSleep1.start(); + threadStateSleep2.start(); + try { + sleep(1000); + } catch (Exception e) { + e.printStackTrace(); + } + threadStateSleep3.start(); + threadStateSleep4.start(); + if (threadStateSleep1.getState().toString().equals("TERMINATED") + && threadStateSleep4.getState().toString().equals("RUNNABLE")) { + System.out.println(0); + return; + } + if (threadStateSleep1.getState().toString().equals("TERMINATED") + && threadStateSleep4.getState().toString().equals("TERMINATED")) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0079-rt-thread-ThreadStatesleep2/ThreadStateSleep2.java b/test/testsuite/ouroboros/thread_test/RT0079-rt-thread-ThreadStatesleep2/ThreadStateSleep2.java new file mode 100755 index 0000000000000000000000000000000000000000..a6b08a7b4e2d15261bc2400607b9a21c389d6a42 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0079-rt-thread-ThreadStatesleep2/ThreadStateSleep2.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateSleep2 + *- @TestCaseName: Thread_ThreadStateSleep2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Main thread sleep time is lower than target threads + *- @Brief: see below + * -#step1: 创建两个ThreadStateSleep2类的实例对象ThreadStateSleep21、ThreadStateSleep22,并且ThreadStateSleep2类继承自 + * Thread类; + * -#step2: 分别调用ThreadStateSleep21、ThreadStateSleep22的start()方法启动这两个线程; + * -#step3: 让当前线程休眠100ms; + * -#step4: 在经过ThreadStateSleep2类的内部的run()方法执行后,线程threadStateSleep21的状态如果是阻塞的,那么线程 + * threadStateSleep22的状态就是"TIMED_WAITING"的;同理,如果线程threadStateSleep21的状态是"TIMED_WAITING"的, + * 那么线程threadStateSleep22的状态就是阻塞的,并且只能是两种情况中的一种,而b的值始终为0; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateSleep2.java + *- @ExecuteClass: ThreadStateSleep2 + *- @ExecuteArgs: + */ + +public class ThreadStateSleep2 extends Thread { + static Object object = "aa"; + static int t = 0; + static int b = 0; + + public static void main(String[] args) { + ThreadStateSleep2 threadStateSleep21 = new ThreadStateSleep2(); + ThreadStateSleep2 threadStateSleep22 = new ThreadStateSleep2(); + threadStateSleep21.start(); + threadStateSleep22.start(); + try { + sleep(100); + } catch (InterruptedException e1) { + } + if (threadStateSleep21.getState().toString().equals("BLOCKED") + && threadStateSleep22.getState().toString().equals("TIMED_WAITING") && t == 1 && b == 0) { + System.out.println(0); + } + if (threadStateSleep22.getState().toString().equals("BLOCKED") + && threadStateSleep21.getState().toString().equals("TIMED_WAITING") && t == 1 && b == 0) { + System.out.println(0); + } + } + + public void run() { + for (int i = 0; i < 1; i++) { + synchronized (object) { + try { + t++; + sleep(1000); + b++; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0080-rt-thread-ThreadStatesleep3/ThreadStateSleep3.java b/test/testsuite/ouroboros/thread_test/RT0080-rt-thread-ThreadStatesleep3/ThreadStateSleep3.java new file mode 100755 index 0000000000000000000000000000000000000000..6a8990f1d9d3af77bc63a6519e1f3e0694ba1585 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0080-rt-thread-ThreadStatesleep3/ThreadStateSleep3.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateSleep3 + *- @TestCaseName: Thread_ThreadStateSleep3.java + *- @RequirementName: Java Thread + *- @Title/Destination: Sleep millisecond Time + *- @Brief: see below + * -#step1: 创建一个ThreadStateSleep3类的实例对象threadStateSleep3,并且ThreadStateSleep3类继承自Thread类; + * -#step2: 调用threadStateSleep3的start()方法启动该线程; + * -#step3: 执行sleep()方法让当前线程休眠,参数为100、100; + * -#step4: 经判断得知线程threadStateSleep3的状态为"TERMINATED"的; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateSleep3.java + *- @ExecuteClass: ThreadStateSleep3 + *- @ExecuteArgs: + */ + +public class ThreadStateSleep3 extends Thread { + public static void main(String[] args) { + ThreadStateSleep3 threadStateSleep3 = new ThreadStateSleep3(); + threadStateSleep3.start(); + try { + sleep(100, 100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (threadStateSleep3.getState().toString().equals("TERMINATED")) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0081-rt-thread-ThreadStatesleep4/ThreadStateSleep4.java b/test/testsuite/ouroboros/thread_test/RT0081-rt-thread-ThreadStatesleep4/ThreadStateSleep4.java new file mode 100755 index 0000000000000000000000000000000000000000..213bf075681cbe4b1dc51d7d72c96f48e5874305 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0081-rt-thread-ThreadStatesleep4/ThreadStateSleep4.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateSleep4 + *- @TestCaseName: Thread_ThreadStateSleep4.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verify the accuracy of sleep time. + *- @Brief: see below + * -#step1: 创建一个ThreadStateSleep4类的实例对象threadStateSleep4,并且ThreadStateSleep4类继承自Thread类; + * -#step2: 调用threadStateSleep4的start()方法启动该线程; + * -#step3: 调用threadStateSleep4的join()方法; + * -#step4: 在ThreadStateSleep4类的内部的run()方法执行后,经判断得知,在让当前线程休眠1000ms之后的当前系统时间end与休眠 + * 之前的当前系统时间start的差值大于970且小于1030; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateSleep4.java + *- @ExecuteClass: ThreadStateSleep4 + *- @ExecuteArgs: + */ + +public class ThreadStateSleep4 extends Thread { + static Object object = "aa"; + static long start = 0; + static long end = 0; + + public static void main(String[] args) { + ThreadStateSleep4 threadStateSleep4 = new ThreadStateSleep4(); + threadStateSleep4.start(); + + try { + threadStateSleep4.join(); + } catch (InterruptedException ex) { + System.out.println(ex); + } + + if (end - start > 970 && end - start < 1030) { + System.out.println(0); + } else { + System.out.println(2); + } + } + + public void run() { + synchronized (object) { + try { + start = System.currentTimeMillis(); + sleep(1000); + end = System.currentTimeMillis(); + } catch (InterruptedException e) { + System.out.println(e); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0082-rt-thread-ThreadStatesleep5/ThreadStateSleep5.java b/test/testsuite/ouroboros/thread_test/RT0082-rt-thread-ThreadStatesleep5/ThreadStateSleep5.java new file mode 100755 index 0000000000000000000000000000000000000000..9e7028ff46f48856018242437e36c2558d3c4cb1 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0082-rt-thread-ThreadStatesleep5/ThreadStateSleep5.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateSleep5 + *- @TestCaseName: Thread_ThreadStateSleep5.java + *- @RequirementName: Java Thread + *- @Title/Destination: Sleep negative second grade time will throw IllegalArgumentException. + *- @Brief: see below + * -#step1: 创建一个ThreadStateSleep5类的实例对象threadStateSleep5,并且ThreadStateSleep5类继承自Thread类; + * -#step2: 调用threadStateSleep5的start()方法启动该线程; + * -#step3: 尝试执行sleep()方法,参数为-10; + * -#step4: step3运行失败,会抛出IllegalArgumentException; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateSleep5.java + *- @ExecuteClass: ThreadStateSleep5 + *- @ExecuteArgs: + */ + +public class ThreadStateSleep5 extends Thread { + public static void main(String[] args) { + ThreadStateSleep5 threadStateSleep5 = new ThreadStateSleep5(); + threadStateSleep5.start(); + try { + sleep(-10); + } catch (InterruptedException e) { + System.out.println(2); + } catch (IllegalArgumentException e1) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0083-rt-thread-ThreadStatesleep6/ThreadStateSleep6.java b/test/testsuite/ouroboros/thread_test/RT0083-rt-thread-ThreadStatesleep6/ThreadStateSleep6.java new file mode 100755 index 0000000000000000000000000000000000000000..8f6f509fc3db24f2f473b6b420da5a597060637a --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0083-rt-thread-ThreadStatesleep6/ThreadStateSleep6.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateSleep6 + *- @TestCaseName: Thread_ThreadStateSleep6.java + *- @RequirementName: Java Thread + *- @Title/Destination: Sleep negative millisecond time will throw IllegalArgumentException. + *- @Brief: see below + * -#step1: 创建一个ThreadStateSleep6类的实例对象threadStateSleep6,并且ThreadStateSleep6类继承自Thread类; + * -#step2: 调用threadStateSleep6的start()方法启动该线程; + * -#step3: 尝试执行sleep()方法,参数为1000、-100; + * -#step4: step3运行失败,会抛出IllegalArgumentException; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateSleep6.java + *- @ExecuteClass: ThreadStateSleep6 + *- @ExecuteArgs: + */ + +public class ThreadStateSleep6 extends Thread { + public static void main(String[] args) { + ThreadStateSleep6 threadStateSleep6 = new ThreadStateSleep6(); + threadStateSleep6.start(); + try { + sleep(1000, -100); + } catch (InterruptedException e) { + System.out.println(2); + } catch (IllegalArgumentException e1) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0084-rt-thread-ThreadStatestart1/ThreadStateStart1.java b/test/testsuite/ouroboros/thread_test/RT0084-rt-thread-ThreadStatestart1/ThreadStateStart1.java new file mode 100755 index 0000000000000000000000000000000000000000..22e259685de59e3f5aa557a255cad3bfc45ab75c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0084-rt-thread-ThreadStatestart1/ThreadStateStart1.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateStart1 + *- @TestCaseName: Thread_ThreadStateStart1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Start thread + *- @Brief: see below + * -#step1: 创建一个ThreadStateStart1类的实例对象threadStateStart1,并且ThreadStateStart1类继承自Thread类; + * -#step2: 调用threadStateStart1的start()方法开启此线程; + * -#step3: 令int类型的静态全局变量i的值加1; + * -#step5: 在ThreadStateStart1类的内部的run()方法执行完之后,经判断得知,线程threadStateStart1的状态是"RUNNABLE"的,并 + * 且i的值由0变为1; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateStart1.java + *- @ExecuteClass: ThreadStateStart1 + *- @ExecuteArgs: + */ + +public class ThreadStateStart1 extends Thread { + static int i = 0; + + public static void main(String[] args) { + ThreadStateStart1 threadStateStart1 = new ThreadStateStart1(); + threadStateStart1.start(); + i++; + if (threadStateStart1.getState().toString().equals("RUNNABLE") && i == 1) { + System.out.println(0); + } + } + + public void run() { + try { + sleep(50); + } catch (InterruptedException e) { + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0085-rt-thread-ThreadStatestart2/ThreadStateStart2.java b/test/testsuite/ouroboros/thread_test/RT0085-rt-thread-ThreadStatestart2/ThreadStateStart2.java new file mode 100755 index 0000000000000000000000000000000000000000..48ae27f43efa651457e4c49a51322b7837392e38 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0085-rt-thread-ThreadStatestart2/ThreadStateStart2.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateStart2 + *- @TestCaseName: Thread_ThreadStateStart2.java + *- @RequirementName: Java Thread + *- @Title/Destination: start a thread already started throws IllegalThreadStateException + *- @Brief: see below + * -#step1: 创建一个ThreadStateStart2类的实例对象threadStateStart2,并且ThreadStateStart2类继承自Thread类; + * -#step2: 调用threadStateStart2的start()方法开启此线程; + * -#step3: 重复调用threadStateStart2的start()方法; + * -#step4: step3运行失败,会抛出IllegalThreadStateException; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateStart2.java + *- @ExecuteClass: ThreadStateStart2 + *- @ExecuteArgs: + */ + +public class ThreadStateStart2 extends Thread { + public static void main(String[] args) { + ThreadStateStart2 threadStateStart2 = new ThreadStateStart2(); + threadStateStart2.start(); + try { + threadStateStart2.start(); + } catch (IllegalThreadStateException e1) { + System.out.println(0); + } + } + + public void run() { + try { + sleep(50); + } catch (InterruptedException e) { + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0086-rt-thread-ThreadStatewait1/ThreadStateWait1.java b/test/testsuite/ouroboros/thread_test/RT0086-rt-thread-ThreadStatewait1/ThreadStateWait1.java new file mode 100755 index 0000000000000000000000000000000000000000..c029f0ce7c5368512cddbd8f1bd52c0799d0c0fb --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0086-rt-thread-ThreadStatewait1/ThreadStateWait1.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateWait1 + *- @TestCaseName: Thread_ThreadStateWait1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread state when the target thread is waiting for a second-level time + *- @Brief: see below + * -#step1: 创建两个ThreadStateWait1类的实例对象threadStateWait1、threadStateWait2,且ThreadStateWait1类继承自Thread类; + * -#step2: 分别调用threadStateWait1、threadStateWait2的start()方法启动这两个线程; + * -#step3: 让当前线程休眠100ms; + * -#step4: 在ThreadStateWait1类内部的run()执行完之后,经判断得出,线程threadStateWait1、threadStateWait2的状态均是 + * "TIMED_WAITING",并且int类型的静态全局变量i的值由0变为2,t的值始终为0; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateWait1.java + *- @ExecuteClass: ThreadStateWait1 + *- @ExecuteArgs: + */ + +public class ThreadStateWait1 extends Thread { + static Object object = "aa"; + static int i = 0; + static int t = 0; + + public static void main(String[] args) { + ThreadStateWait1 threadStateWait1 = new ThreadStateWait1(); + ThreadStateWait1 threadStateWait2 = new ThreadStateWait1(); + threadStateWait1.start(); + threadStateWait2.start(); + try { + sleep(100); + } catch (InterruptedException e1) { + } + if (threadStateWait1.getState().toString().equals("TIMED_WAITING") + && threadStateWait2.getState().toString().equals("TIMED_WAITING") && i == 2 && t == 0) { + System.out.println(0); + } + } + + public void run() { + synchronized (object) { + try { + i++; + object.wait(1000); + t++; + } catch (InterruptedException e) { + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0087-rt-thread-ThreadStatewait2/ThreadStateWait2.java b/test/testsuite/ouroboros/thread_test/RT0087-rt-thread-ThreadStatewait2/ThreadStateWait2.java new file mode 100755 index 0000000000000000000000000000000000000000..ff43fc7801a61c9cff70394a6a67e00803349631 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0087-rt-thread-ThreadStatewait2/ThreadStateWait2.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateWait2 + *- @TestCaseName: Thread_ThreadStateWait2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread state when the target thread is in an infinite wait + *- @Brief: see below + * -#step1: 创建两个ThreadStateWait2类的实例对象threadStateWait21、threadStateWait22,并且ThreadStateWait2类继承自 + * Thread类; + * -#step2: 分别调用threadStateWait21、threadStateWait22的start()方法启动这两个线程; + * -#step3: 让当前线程休眠100ms; + * -#step4: 在ThreadStateWait2类内部的run()方法执行完之后(run()方法内会以object为对象锁,并在执行完对i的值加1后,会调用 + * object的wait()方法),经判断得知,线程threadStateWait21、threadStateWait22的状态均是"WAITING"的,并且int类型 + * 的静态全局变量i的值由0变为2,t的值始终为0; + * -#step5: 分别调用threadStateWait21、threadStateWait22的interrupt()方法; + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateWait2.java + *- @ExecuteClass: ThreadStateWait2 + *- @ExecuteArgs: + */ + +public class ThreadStateWait2 extends Thread { + static Object object = "aa"; + static int i = 0; + static int t = 0; + + public static void main(String[] args) { + ThreadStateWait2 threadStateWait21 = new ThreadStateWait2(); + ThreadStateWait2 threadStateWait22 = new ThreadStateWait2(); + threadStateWait21.start(); + threadStateWait22.start(); + try { + sleep(100); + } catch (InterruptedException e1) { + } + if (threadStateWait21.getState().toString().equals("WAITING") + && threadStateWait22.getState().toString().equals("WAITING") && i == 2 && t == 0) { + threadStateWait21.interrupt(); + threadStateWait22.interrupt(); + System.out.println(0); + } + } + + public void run() { + synchronized (object) { + try { + i++; + object.wait(); + t++; + } catch (InterruptedException e) { + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0088-rt-thread-ThreadStatewait3/ThreadStateWait3.java b/test/testsuite/ouroboros/thread_test/RT0088-rt-thread-ThreadStatewait3/ThreadStateWait3.java new file mode 100755 index 0000000000000000000000000000000000000000..407caf76d3cf31163ffcb93b2db21ac28c79afe3 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0088-rt-thread-ThreadStatewait3/ThreadStateWait3.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateWait3 + *- @TestCaseName: Thread_ThreadStateWait3.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread state when the target thread is waiting for the millisecond-level time + *- @Brief: see below + * -#step1: 创建两个ThreadStateWait3类的实例对象threadStateWait31、threadStateWait32,并且ThreadStateWait3类继承自 + * Thread类; + * -#step2: 分别调用threadStateWait31、threadStateWait32的start()方法启动这两个线程; + * -#step3: 让当前线程休眠100ms; + * -#step4: 在ThreadStateWait3类内部的run()方法执行完之后(run()方法内会以object为对象锁,并在执行完对i的值加1后,会调用 + * object的wait()方法,参数为1000、500),经判断得知,线程threadStateWait21、threadStateWait22的状态均是 + * "TIMED_WAITING"的,并且int类型的静态全局变量i的值由0变为2,t的值始终为0; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateWait3.java + *- @ExecuteClass: ThreadStateWait3 + *- @ExecuteArgs: + */ + +public class ThreadStateWait3 extends Thread { + static Object object = "aa"; + static int i = 0; + static int t = 0; + + public static void main(String[] args) { + ThreadStateWait3 threadStateWait31 = new ThreadStateWait3(); + ThreadStateWait3 threadStateWait32 = new ThreadStateWait3(); + threadStateWait31.start(); + threadStateWait32.start(); + try { + sleep(100); + } catch (InterruptedException e1) { + } + if (threadStateWait31.getState().toString().equals("TIMED_WAITING") + && threadStateWait32.getState().toString().equals("TIMED_WAITING") && i == 2 && t == 0) { + System.out.println(0); + } + } + + public void run() { + synchronized (object) { + try { + i++; + object.wait(1000, 500); + t++; + } catch (InterruptedException e) { + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0089-rt-thread-ThreadStatewait4/ThreadStateWait4.java b/test/testsuite/ouroboros/thread_test/RT0089-rt-thread-ThreadStatewait4/ThreadStateWait4.java new file mode 100755 index 0000000000000000000000000000000000000000..df6e76c21e8740765cfdb32d72df1b6437bbe630 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0089-rt-thread-ThreadStatewait4/ThreadStateWait4.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateWait4 + *- @TestCaseName: Thread_ThreadStateWait4.java + *- @RequirementName: Java Thread + *- @Title/Destination: IllegalMonitorStateException is thrown by wait() if the current thread is not the owner of the + * object's monitor. + *- @Brief: see below + * -#step1: 定义一个Object类型的变量object,并赋初始值为aa; + * -#step2: 尝试调用object的wait()方法; + * -#step3: step2中方法调用失败,会抛出IllegalMonitorStateException; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateWait4.java + *- @ExecuteClass: ThreadStateWait4 + *- @ExecuteArgs: + */ + +public class ThreadStateWait4 extends Thread { + static Object object = "aa"; + + public static void main(String[] args) { + try { + object.wait(); + System.out.println(2); + } catch (InterruptedException e) { + System.out.println(2); + } catch (IllegalMonitorStateException e) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0090-rt-thread-ThreadStatewait5/ThreadStateWait5.java b/test/testsuite/ouroboros/thread_test/RT0090-rt-thread-ThreadStatewait5/ThreadStateWait5.java new file mode 100755 index 0000000000000000000000000000000000000000..3424bde881da5b9070d66cfc7e9989502a424cfb --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0090-rt-thread-ThreadStatewait5/ThreadStateWait5.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateWait5 + *- @TestCaseName: Thread_ThreadStateWait5.java + *- @RequirementName: Java Thread + *- @Title/Destination: IllegalMonitorStateException is thrown by wait(long timeout) if the current thread is not the + * owner of the object's monitor. + *- @Brief: see below + * -#step1: 定义一个Object类型的变量object,并赋初始值为aa; + * -#step2: 尝试调用object的wait()方法让当前线程等待1000ms; + * -#step3: step2中方法调用失败,会抛出IllegalMonitorStateException; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateWait5.java + *- @ExecuteClass: ThreadStateWait5 + *- @ExecuteArgs: + */ + +public class ThreadStateWait5 extends Thread { + static Object object = "aa"; + + public static void main(String[] args) { + try { + object.wait(1000); + System.out.println(2); + } catch (InterruptedException e) { + System.out.println(2); + } catch (IllegalMonitorStateException e) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0091-rt-thread-ThreadStatewait6/ThreadStateWait6.java b/test/testsuite/ouroboros/thread_test/RT0091-rt-thread-ThreadStatewait6/ThreadStateWait6.java new file mode 100755 index 0000000000000000000000000000000000000000..21fc7ece9a8cb01e7acdbb1fad1b3bee9f6f6b76 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0091-rt-thread-ThreadStatewait6/ThreadStateWait6.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateWait6 + *- @TestCaseName: Thread_ThreadStateWait6.java + *- @RequirementName: Java Thread + *- @Title/Destination: IllegalMonitorStateException is thrown by wait(long timeout, int nanos) if the current thread is + * not the owner of the object's monitor. + *- @Brief: see below + * -#step1: 定义一个Object类型的变量object,并赋初始值为aa; + * -#step2: 尝试调用object的wait()方法,参数为1000,100; + * -#step3: step2中方法调用失败,会抛出IllegalMonitorStateException; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateWait6.java + *- @ExecuteClass: ThreadStateWait6 + *- @ExecuteArgs: + */ + +public class ThreadStateWait6 extends Thread { + static Object object = "aa"; + + public static void main(String[] args) { + try { + object.wait(1000, 100); + System.out.println(2); + } catch (InterruptedException e) { + System.out.println(2); + } catch (IllegalMonitorStateException e) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0092-rt-thread-ThreadStatewait7/ThreadStateWait7.java b/test/testsuite/ouroboros/thread_test/RT0092-rt-thread-ThreadStatewait7/ThreadStateWait7.java new file mode 100755 index 0000000000000000000000000000000000000000..35f964387ccdb484359b92bf65a195877d2639ad --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0092-rt-thread-ThreadStatewait7/ThreadStateWait7.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateWait7 + *- @TestCaseName: Thread_ThreadStateWait7.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verify the accuracy of the wait time + *- @Brief: see below + * -#step1: 创建一个ThreadStateWait7类的实例对象threadStateWait7,并且ThreadStateWait7类继承自Thread类; + * -#step2: 调用threadStateWait7的start()方法启动该线程; + * -#step3: 将当前系统时间赋值给long型变量j; + * -#step4: 调用threadStateWait7的join()方法; + * -#step5: 将当前系统时间赋值给long型变量k; + * -#step6: 在ThreadStateWait7类内部的run()方法执行完之后(run()方法内以object为对象锁,并对object调用wait()方法令线程等 + * 待1000ms),经判断得知k与j的差值大于950且小于1050; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateWait7.java + *- @ExecuteClass: ThreadStateWait7 + *- @ExecuteArgs: + */ + +public class ThreadStateWait7 extends Thread { + static Object object = "aa"; + + public static void main(String[] args) { + long j; + long k; + ThreadStateWait7 threadStateWait7 = new ThreadStateWait7(); + threadStateWait7.start(); + j = System.currentTimeMillis(); + try { + threadStateWait7.join(); + } catch (InterruptedException ex) { + } + k = System.currentTimeMillis(); + if (k - j > 950 && k - j < 1050) { + System.out.println(0); + } + } + + public void run() { + synchronized (object) { + try { + object.wait(1000); + } catch (InterruptedException e) { + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0093-rt-thread-ThreadStatewait8/ThreadStateWait8.java b/test/testsuite/ouroboros/thread_test/RT0093-rt-thread-ThreadStatewait8/ThreadStateWait8.java new file mode 100755 index 0000000000000000000000000000000000000000..9e98223d2a49c6126c632785440e5d5d1c148c70 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0093-rt-thread-ThreadStatewait8/ThreadStateWait8.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateWait8 + *- @TestCaseName: Thread_ThreadStateWait8.java + *- @RequirementName: Java Thread + *- @Title/Destination: InterruptedException is thrown if any thread interrupted the current thread before or while the + * current thread was waiting for a notification. + *- @Brief: see below + * -#step1: 新建一个Thread类的数组tt,数组长度为10; + * -#step2: 对于i < tt.length = 10,令tt[i] = new Thread(),其内重写的run()方法执行的是以object为对象锁,并尝试对object + * 调用wait()方法,若出现异常,则int类型的静态全局变量k的值会加1; + * -#step3: 对于i < tt.length = 10,执行线程tt[i]的start()方法启动该线程; + * -#step4: 对于i < tt.length = 10,执行线程tt[i]的interrupt()方法; + * -#step5: 对于i < tt.length = 10,尝试调用线程tt[i]的join()方法; + * -#step6: step5成功执行,并且经判断得知,k的值最终等于10; + + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateWait8.java + *- @ExecuteClass: ThreadStateWait8 + *- @ExecuteArgs: + */ + +public class ThreadStateWait8 extends Thread { + static int k = 0; + + public static void main(String[] args) { + Object object = "aa"; + Thread[] tt = new Thread[10]; + for (int i = 0; i < tt.length; i++) { + tt[i] = new Thread() { + public void run() { + synchronized (object) { + try { + object.wait(); + } catch (InterruptedException e1) { + k++; + } + } + } + }; + } + for (int i = 0; i < tt.length; i++) { + tt[i].start(); + } + for (int i = 0; i < tt.length; i++) { + tt[i].interrupt(); + } + for (int i = 0; i < tt.length; i++) { + try { + tt[i].join(); + } catch (InterruptedException e2) { + System.err.println(e2); + } + } + if (k == 10) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0094-rt-thread-ThreadStateyield/ThreadStateyield.java b/test/testsuite/ouroboros/thread_test/RT0094-rt-thread-ThreadStateyield/ThreadStateyield.java new file mode 100755 index 0000000000000000000000000000000000000000..628914a9a439783f62fd5bf59e62be2dcecc15cc --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0094-rt-thread-ThreadStateyield/ThreadStateyield.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Ouroboros/rt_test/ThreadStateyield + *- @TestCaseName: Thread_ThreadStateyield.java + *- @RequirementName: Java Thread + *- @Title/Destination:yield() give a hint to the scheduler that the current thread is willing to yield its current use of a processor. other threads will be executed before current thread. + *- @Brief: see below + * -#step1:分别以cls1、cls2为参数,创建ThreadStateYield类的两个实例对象threadStateYield1、threadStateYield2,并且ThreadStateYield类继承自Thread类; + * -#step2:调用threadStateYield1的start()方法启动该线程;然后休眠10ms + * -#step3:调用threadStateYield2的start()方法启动该线程;然后休眠1000ms; + * -#step4:在ThreadStateYield类内部的run()方法执行完之后(run()方法内的逻辑是:如果当前线程名与"cls1"相同时,则执行yield()方法,并对int类型的静态全局变量i的值加1,并尝试让当前线程休眠10ms;如若不相同,则直接跳出循环),经判断得知,线程threadStateYield1的状态是"TIMED_WAITING"的,线程threadStateYield2的状态是"TERMINATED"的,并且i的值不为0; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadStateyield.java + *- @ExecuteClass: ThreadStateyield + *- @ExecuteArgs: + */ + +import java.io.PrintStream; + +public class ThreadStateyield extends Thread { + static int i = 0; + + public ThreadStateyield(String name) { + super(name); + } + + public static void main(String[] args) { + System.exit(run(args, System.out)); + } + + public static int run(String[] args, PrintStream out) { + ThreadStateyield zqp1 = new ThreadStateyield("zqp1"); + ThreadStateyield zqp2 = new ThreadStateyield("zqp2"); + zqp1.start(); + try { + sleep(10); + } catch (InterruptedException e1) { + } + zqp2.start(); + try { + sleep(1000); + } catch (InterruptedException e1) { + } + System.out.println(zqp2.getState()); + System.out.println(zqp1.getState()); + if (zqp2.getState().toString().equals("TERMINATED") && zqp1.getState().toString().equals("TIMED_WAITING") && i != 0) { + return 0; + } + return 2; + } + + public void run() { + for (; ; ) { + if (currentThread().getName().equals("zqp1")) { + yield(); + i++; + try { + sleep(10); + } catch (InterruptedException e) { + } + } else break; + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan TERMINATED\s*TIMED_WAITING \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0095-rt-thread-ThreadtoString/ThreadToString.java b/test/testsuite/ouroboros/thread_test/RT0095-rt-thread-ThreadtoString/ThreadToString.java new file mode 100755 index 0000000000000000000000000000000000000000..dc072d4ef9084ed4ab72a2d84d9714025ee59c7c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0095-rt-thread-ThreadtoString/ThreadToString.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadToString + *- @TestCaseName: Thread_ThreadToString.java + *- @RequirementName: Java Thread + *- @Title/Destination: toString() Returns a string representation of this thread, including the thread's name, + * priority, and thread group. + *- @Brief: see below + * -#step1: 以god为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 以threadGroup、good为参数,创建一个ThreadToString类的实例对象threadToString,并且ThreadToString类继承自 + * Thread类; + * -#step3: 通过threadToString的setPriority()方法设置其优先级为8; + * -#step4: 令threadToString.toString()的返回值为string; + * -#step5: 经判断得知string的信息与字符串"Thread[good,8,god]"相同; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadToString.java + *- @ExecuteClass: ThreadToString + *- @ExecuteArgs: + */ + +public class ThreadToString extends Thread { + public ThreadToString(ThreadGroup group, String name) { + super(group, name); + } + + public static void main(String[] args) { + String string; + ThreadGroup threadGroup = new ThreadGroup("god"); + ThreadToString threadToString = new ThreadToString(threadGroup, "good"); + threadToString.setPriority(8); + string = threadToString.toString(); + if (string.equals("Thread[good,8,god]")) { + System.out.println(0); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0096-rt-thread-ThreadTest23/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0096-rt-thread-ThreadTest23/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a7cf77dc403b0008302f3096d6f4d4f7430e497f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0096-rt-thread-ThreadTest23/ThreadTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test for interrupt() -- Interrupt a running thread + *- @Brief: see below + * -#step1: 定义一个ThreadRunning类,并且该类继承自Thread类,其内run()方法的逻辑是当boolean类型的变量stopWork等于false + * 时,对int类型的变量i的值进行加1; + * -#step2: 创建一个ThreadRunning类的实例对象threadRunning; + * -#step3: 调用threadRunning的start()方法启动该线程; + * -#step4: 让当前线程休眠2000ms; + * -#step5: 调用threadRunning的interrupt()方法使线程中断; + * -#step6: 让当前线程休眠1000ms; + * -#step7: 将类变量threadRunning.stopWork赋值为true,经判断得知,在执行完ThreadRunning类的内部的run()方法后程序可以正常 + * 结束; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +class ThreadTest { + public static void main(String[] args) { + ThreadRunning threadRunning = new ThreadRunning(); + + threadRunning.start(); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + System.out.println("unexpected InterruptedException while sleeping"); + } + threadRunning.interrupt(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + System.out.println("unexpected InterruptedException while sleeping"); + } + System.out.println("isInterrupted() finally returns -- " + threadRunning.isInterrupted()); + threadRunning.stopWork = true; + System.out.println("PASS"); + } + + //test for interrupt() -- Interrupt a running thread + /* If this thread is blocked in an invocation + * of the wait(), wait(long), or wait(long, int) methods of the Object class, or + * of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, + * then its interrupt status will be cleared and it will receive an InterruptedException. + */ + + static class ThreadRunning extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan isInterrupted\(\)\s*finally\s*returns\s*\-\-\s*true\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0097-rt-thread-ThreadTest31/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0097-rt-thread-ThreadTest31/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b169cb9a43e10ddfe34b8e3b6ccd3ab881c4d235 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0097-rt-thread-ThreadTest31/ThreadTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test for call of static method interrupted(), and method interrupt() + *- @Brief: see below + * -#step1: 创建一个ThreadTest类的实例对象threadTest,并且ThreadTest类继承自Thread类; + * -#step2: 调用threadTest的start()方法启动该线程; + * -#step3: 调用threadTest的join()方法; + * -#step4: 在ThreadTest类的内部的run()方法执行完之后(run()方法内的执行逻辑是打印相关信息,并使当前线程中断),程序可以 + * 正常终止; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest extends Thread { + public static void main(String[] args) throws Exception { + ThreadTest threadTest = new ThreadTest(); + threadTest.start(); + threadTest.join(); + System.out.println("PASS"); + } + + //test for call of static method interrupted(), and method interrupt() + // in java a static method can be called by className.staticMethod and by objectName.staticMethod + public void run() { + System.out.println("isInterrupted() returns -- " + isInterrupted()); + interrupt(); + System.out.println("after executing interrupt()"); + System.out.println("isInterrupted() returns -- " + isInterrupted()); + System.out.println("1st should true -- " + interrupted()); + System.out.println("isInterrupted() returns -- " + isInterrupted()); + System.out.println("2nd should false -- " + interrupted()); + System.out.println("isInterrupted() returns -- " + isInterrupted()); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan isInterrupted\(\)\s*returns\s*\-\-\s*false\s*after\s*executing\s*interrupt\(\)\s*isInterrupted\(\)\s*returns\s*\-\-\s*true\s*1st\s*should\s*true\s*\-\-\s*true\s*isInterrupted\(\)\s*returns\s*\-\-\s*false\s*2nd\s*should\s*false\s*\-\-\s*false\s*isInterrupted\(\)\s*returns\s*\-\-\s*false\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0098-rt-thread-ThreadTest11/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0098-rt-thread-ThreadTest11/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8ae7b83b03cff37f6a839dcb3896184ac6bb02f2 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0098-rt-thread-ThreadTest11/ThreadTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test for isDaemon() and setDaemon() + *- @Brief: see below + * -#step1: 创建一个Thread类的实例对象thread; + * -#step2: 打印thread的isDaemon()属性; + * -#step3: 调用thread的setDaemon()方法,参数为true; + * -#step4: 打印thread的isDaemon()属性; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + public static void main(String[] args) throws Exception { + Thread thread = new Thread(); + System.out.println( + "The newly created thread must not be daemon, and isDaemon()'s result is -- " + + thread.isDaemon()); + thread.setDaemon(true); + System.out.println("The thread must be daemon, and isDaemon()'s result is -- " + thread.isDaemon()); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan The\s*newly\s*created\s*thread\s*must\s*not\s*be\s*daemon\,\s*and\s*isDaemon\(\)\'s\s*result\s*is\s*\-\-\s*false\s*The\s*thread\s*must\s*be\s*daemon\,\s*and\s*isDaemon\(\)\'s\s*result\s*is\s*\-\-\s*true \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0099-rt-thread-ThreadTest21/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0099-rt-thread-ThreadTest21/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..45d89bea734aa817bcd267e141bea69ab415b7bc --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0099-rt-thread-ThreadTest21/ThreadTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test for interrupt(), interrupted(), isInterrupted() + *- @Brief: see below + * -#step1: 创建一个Thread类的实例对象thread,其内的run()方法实现是打印相关信息并调用interrupt()方法中断线程; + * -#step2: 调用thread的start()方法启动该线程; + * -#step3: 调用thread的join()方法; + * -#step4: 确定程序可以正常终止; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + // test for interrupt(), interrupted(), isInterrupted() + public static void main(String[] args) throws Exception { + Thread thread = new Thread() { + public void run() { + System.out.println("helloworld executes interrupt()"); + interrupt(); + System.out.println("isInterrupted() returns -- " + isInterrupted()); + System.out.println("1st interrupted() should true -- " + Thread.interrupted()); + System.out.println("isInterrupted() returns -- " + isInterrupted()); + System.out.println("2nd interrupted() should false -- " + Thread.interrupted()); + System.out.println("isInterrupted() returns -- " + isInterrupted()); + } + }; + thread.start(); + thread.join(); + System.out.println("PASS"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan helloworld\s*executes\s*interrupt\(\)\s*isInterrupted\(\)\s*returns\s*\-\-\s*true\s*1st\s*interrupted\(\)\s*should\s*true\s*\-\-\s*true\s*isInterrupted\(\)\s*returns\s*\-\-\s*false\s*2nd\s*interrupted\(\)\s*should\s*false\s*\-\-\s*false\s*isInterrupted\(\)\s*returns\s*\-\-\s*false\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0100-rt-thread-ThreadTest34/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0100-rt-thread-ThreadTest34/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..072501974b664266d00f9863da04ad519b6b236f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0100-rt-thread-ThreadTest34/ThreadTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test for run(), here t1 and t2 will be treated as normal object not thread object + *- @Brief: see below + * -#step1: 以t1、t2为参数,创建ThreadTest类的两个实例对象threadTest1、threadTest2,并且ThreadTest类继承自Thread类; + * -#step2: 分别调用threadTest1、threadTest2的run()方法,其内的逻辑是当i < 5 时,让当前线程休眠500ms,之后打印当前线程的 + * 名字; + * -#step3: 确定程序执行成功并正常终止; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +class ThreadTest extends Thread { + private String name; + + public ThreadTest(String name) { + this.name = name; + } + + public static void main(String[] args) { + ThreadTest threadTest1 = new ThreadTest("t1"); + ThreadTest threadTest2 = new ThreadTest("t2"); + + threadTest1.run(); + threadTest2.run(); + } + + public void run() { + for (int i = 1; i < 5; i++) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + System.out.println(e); + } + System.out.println(name + " -- " + i); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan t1\s*\-\-\s*1\s*t1\s*\-\-\s*2\s*t1\s*\-\-\s*3\s*t1\s*\-\-\s*4\s*t2\s*\-\-\s*1\s*t2\s*\-\-\s*2\s*t2\s*\-\-\s*3\s*t2\s*\-\-\s*4 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0101-rt-thread-ThreadTest25/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0101-rt-thread-ThreadTest25/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9f08ae4711f8dec3cc43405a80a9673280d0effc --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0101-rt-thread-ThreadTest25/ThreadTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test for interrupt() -- Interrupt a terminated thread + *- @Brief: see below + * -#step1: 定义一个ThreadRunning类,并且该类继承自Thread类,其内run()方法的逻辑是当boolean类型的变量stopWork等于false + * 时,对int类型的变量i的值进行加1; + * -#step2: 创建一个ThreadRunning类的实例对象threadRunning; + * -#step3: 调用threadRunning的start()方法启动该线程; + * -#step4: 将类变量threadRunning.stopWork赋值为true; + * -#step5: 调用threadRunning的join()方法; + * -#step6: 调用threadRunning的interrupt()方法中断线程; + * -#step7: 确认程序执行成功并且正常终止; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +class ThreadTest { + private static final long waitDuration = 3000; + private static long waitTime = 0; + + public static void main(String[] args) { + boolean expired = false; + ThreadRunning threadRunning = new ThreadRunning(); + threadRunning.start(); + waitTime = waitDuration; + + if (expired) { + System.out.println("thread' run() method has not started"); + } + threadRunning.stopWork = true; + try { + threadRunning.join(); + } catch (InterruptedException e) { + System.out.println("INTERRUPTED_MESSAGE"); + } + threadRunning.interrupt(); + System.out.println("interrupt status has not changed to true -- " + threadRunning.isInterrupted()); + System.out.println("PASS"); + } + + //test for interrupt() -- Interrupt a terminated thread + /* If this thread is blocked in an invocation + * of the wait(), wait(long), or wait(long, int) methods of the Object class, or + * of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, + * then its interrupt status will be cleared and it will receive an InterruptedException. + */ + + static class ThreadRunning extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan interrupt\s*status\s*has\s*not\s*changed\s*to\s*true\s*\-\-\s*false\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0102-rt-thread-ThreadTest9/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0102-rt-thread-ThreadTest9/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..01dee08c205069a538449f0f776c74cf7589d3f0 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0102-rt-thread-ThreadTest9/ThreadTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verify currentThread() and toString() + *- @Brief: see below + * -#step1: 打印当前线程及当前线程名; + * -#step2: 创建一个Thread类的实例对象thread,将thread.toString()赋值给info,thread.getName()赋值给name; + * -#step3: 打印name的相关信息; + * -#step4: 将new Integer(thread.getPriority()).toString()赋值给stringPriority,并打印其相关信息; + * -#step5: 将thread.getThreadGroup().getName()赋值给groupName,并打印相关信息; + * -#step6: 创建一个Thread类的实例对象thread2,并打印此线程及其相关信息; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + /** + * Verify currentThread() and toString() + */ + public static void main(String[] args) throws Exception { + System.out.println(Thread.currentThread().toString()); + System.out.println(Thread.currentThread()); + System.out.println(Thread.currentThread().getName()); + + Thread thread = new Thread(); + String info = thread.toString(); + String name = thread.getName(); + + System.out.println("thread's name is -- " + name + " -- " + info.indexOf(name)); + String stringPriority = new Integer(thread.getPriority()).toString(); + System.out.println("thread's priority is -- " + stringPriority + " -- " + info.indexOf("," + + stringPriority + ",")); + String groupName = thread.getThreadGroup().getName(); + System.out.println("thread's group is -- " + groupName + " -- " + info.indexOf(groupName)); + + Thread thread2 = new Thread(); + System.out.println("thread name -- " + + thread2.toString()); + System.out.println("thread group --- " + Thread.currentThread().getThreadGroup() + + " --- " + thread2.getThreadGroup()); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan Thread\[main\,5\,main\]\s*Thread\[main\,5\,main\]\s*main\s*thread\'s\s*name\s*is\s*\-\-\s*Thread\-0\s*\-\-\s*7\s*thread\'s\s*priority\s*is\s*\-\-\s*5\s*\-\-\s*15\s*thread\'s\s*group\s*is\s*\-\-\s*main\s*\-\-\s*18\s*thread\s*name\s*\-\-\s*Thread\[Thread\-1\,5\,main\]\s*thread\s*group\s*\-\-\-\s*java\.lang\.ThreadGroup\[name\=main\,maxpri\=10\]\s*\-\-\-\s*java\.lang\.ThreadGroup\[name\=main\,maxpri\=10\] \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0103-rt-thread-ThreadTest8/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0103-rt-thread-ThreadTest8/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b2d446e83d0343cf48de346a6cbc621a4fef65db --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0103-rt-thread-ThreadTest8/ThreadTest.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: check status of thread when thety are NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED + *- @Brief: see below + * -#step1: 创建一个Object类的实例对象object; + * -#step2: 分别以object为参数,创建ThreadRunning1类、ThreadRunning3类的实例对象threadRunning1、threadRunning3,创建一个 + * ThreadRunning2类的实例对象threadRunning2,并且这三个类继承自Thread类; + * -#step3: 打印线程threadRunning1的状态; + * -#step4: 分别调用threadRunning1、threadRunning2的start()方法启动这两个线程; + * -#step5: 打印线程threadRunning1的状态; + * -#step6: 让当前线程休眠200ms; + * -#step7: 调用threadRunning3的start()方法启动这个线程; + * -#step8: 让当前线程休眠200ms; + * -#step9: 打印线程threadRunning3的状态; + * -#step10: 将ThreadRunning1类中的类变量threadRunning1.stopWork赋值为true; + * -#step11: 让当前线程休眠100ms; + * -#step12: 依次打印threadRunning3、threadRunning2、threadRunning1的线程状态; + * -#step13: 将ThreadRunning3类中的类变量threadRunning3.stopWork赋值为true; + * -#step14: 以object为对象锁,在同步代码块中对object调用notify()方法; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +class ThreadRunning1 extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + Object mylock; + + ThreadRunning1(Object obj) { + mylock = obj; + } + + public void run() { + synchronized (mylock) { + while (!stopWork) { + i++; + i--; + } + } + } +} + +class ThreadRunning2 extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + public void run() { + try { + Thread.sleep(1000); + } catch (Exception e) { + } + } +} + +class ThreadRunning3 extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + Object mylock; + + ThreadRunning3(Object obj) { + mylock = obj; + } + + public void run() { + synchronized (mylock) { + try { + mylock.wait(); + while (!stopWork) { + i++; + i--; + } + } catch (Exception e) { + } + } + } +} + +public class ThreadTest { + public static void main(String[] args) throws Exception { + Object object = new Object(); + ThreadRunning1 threadRunning1 = new ThreadRunning1(object); + ThreadRunning2 threadRunning2 = new ThreadRunning2(); + ThreadRunning3 threadRunning3 = new ThreadRunning3(object); + // t1 NEW; t2 NEW; t3 NEW + System.out.println(threadRunning1.getState()); + threadRunning1.start(); + threadRunning2.start(); + // t1 RUNNABLE; t2 TIMED_WAITING; t3 NEW + System.out.println(threadRunning1.getState()); + try { + Thread.sleep(200); + } catch (Exception e) { + } + threadRunning3.start(); + try { + Thread.sleep(200); + } catch (Exception e) { + } + // t1 RUNNABLE; t2 TIMED_WAITING; t3 BmymylockED + System.out.println(threadRunning3.getState()); + threadRunning1.stopWork = true; + try { + Thread.sleep(100); + } catch (Exception e) { + } + // t1 TERMINATED; t2 TIMED_WAITING; t3 WAITING + System.out.println(threadRunning3.getState()); + System.out.println(threadRunning2.getState()); + System.out.println(threadRunning1.getState()); + threadRunning3.stopWork = true; + synchronized (object) { + object.notify(); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan NEW\s*RUNNABLE\s*BLOCKED\s*WAITING\s*TIMED_WAITING\s*TERMINATED \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0104-rt-thread-ThreadTest38/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0104-rt-thread-ThreadTest38/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..747d4f98e896533d3c9c9cc237a98c0590ed61b5 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0104-rt-thread-ThreadTest38/ThreadTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test start(), start a already started thread throws IllegalThreadStateException; start a + * finished thread throws IllegalThreadStateException + *- @Brief: see below + * -#step1: Define a class that inherit from thread class and override run(). + * -#step2: Start the thread1 repeatedly. + * -#step3: Check that IllegalThreadStateException was threw correctly. + * -#step4: Start the finished thread2 which. + * -#step5: Check that IllegalThreadStateException was threw correctly. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + public static void main(String[] args) throws Exception { + /** + * Start the already started thread + */ + ThreadRunning thread_obj1 = new ThreadRunning(); + thread_obj1.start(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException("InterruptedException from sleep"); + } + System.out.println("Thread 1' state -- " + thread_obj1.getState()); + try { + thread_obj1.start(); + System.out.println("IllegalThreadStateException is expected when starting a started thread"); + } catch (IllegalThreadStateException e) { + System.out.println("IllegalThreadStateException has been thrown when start the already started thread"); + } + + /** + * Start the already finished thread + */ + ThreadRunning thread_obj2 = new ThreadRunning(); + thread_obj2.start(); + try { + thread_obj2.join(); + } catch (InterruptedException e) { + System.out.println("INTERRUPTED_MESSAGE"); + } + System.out.println("Thread 2' state -- " + thread_obj2.getState()); + try { + thread_obj2.start(); + System.out.println("IllegalThreadStateException is expected when starting a finished thread"); + } catch (IllegalThreadStateException e) { + System.out.println("IllegalThreadStateException has been thrown when start the already finished thread"); + } + System.out.println("PASS"); + } + + // test for start() + static class ThreadRunning extends Thread { + ThreadRunning() { + super(); + } + + public void run() { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + throw new RuntimeException("InterruptedException from sleep"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan Thread\s*1\'\s*state\s*\-\-\s*TIMED_WAITING\s*IllegalThreadStateException\s*has\s*been\s*thrown\s*when\s*start\s*the\s*already\s*started\s*thread\s*Thread\s*2\'\s*state\s*\-\-\s*TERMINATED\s*IllegalThreadStateException\s*has\s*been\s*thrown\s*when\s*start\s*the\s*already\s*finished\s*thread\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0105-rt-thread-ThreadTest30/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0105-rt-thread-ThreadTest30/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..43f3cd842722a350dd4fe3f0a9e3b0f07c3a6025 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0105-rt-thread-ThreadTest30/ThreadTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test for interrupt() -- Interrupt a waiting thread + *- @Brief: see below + * -#step1: Define test class which inherited from thread class. + * -#step2: Create a ThreadWaiting instance. + * -#step3: Start the thread. + * -#step4: Block the thread with wait(). + * -#step5: Check that interrupt status was cleared by calling interrupt(). + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +class ThreadTest { + public static void main(String[] args) { + ThreadWaiting t = new ThreadWaiting(5000, 0); + t.start(); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + System.out.println("main throws InterruptedException"); + } + t.interrupt(); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + System.out.println("main throws InterruptedException"); + } + System.out.println("interrupt status has been cleared, if the output is false -- " + + t.isInterrupted()); + } + + private static class ThreadWaiting extends Thread { + private long millis; + private int nanos; + + ThreadWaiting(long millis, int nanos) { + this.millis = millis; + this.nanos = nanos; + } + + public void run() { + synchronized (this) { + try { + this.wait(millis, nanos); + System.out.println("Fail -- waiting thread has not received the InterruptedException"); + } catch (InterruptedException e) { + System.out.println("waiting thread has received the InterruptedException"); + } + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan waiting\s*thread\s*has\s*received\s*the\s*InterruptedException\s*interrupt\s*status\s*has\s*been\s*cleared\,\s*if\s*the\s*output\s*is\s*false\s*\-\-\s*false \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0106-rt-thread-ThreadTest28/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0106-rt-thread-ThreadTest28/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..bd89ce0633a7b5e5436a299fcfd003950d5d694d --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0106-rt-thread-ThreadTest28/ThreadTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test for interrupt() -- Interrupt a sleeping thread + *- @Brief: see below + * -#step1: Define test class which inherited from thread class. + * -#step2: Create a ThreadSleeping instance. + * -#step3: Start the thread. + * -#step4: Block the thread with wait(). + * -#step5: Check that interrupt status was cleared by calling interrupt(). + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +class ThreadTest { + public static void main(String[] args) { + ThreadSleeping t = new ThreadSleeping(10000, 0); + t.start(); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + System.out.println("main throws InterruptedException"); + } + t.interrupt(); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + System.out.println("main throws InterruptedException"); + } + System.out.println("interrupt status has been cleared, if the output is false -- " + + t.isInterrupted()); + } + + private static class ThreadSleeping extends Thread { + private long millis; + private int nanos; + + ThreadSleeping(long millis, int nanos) { + this.millis = millis; + this.nanos = nanos; + } + + public void run() { + try { + Thread.sleep(millis, nanos); + System.out.println("Fail -- sleeping thread has not received the InterruptedException"); + } catch (InterruptedException e) { + System.out.println("sleeping thread has received the InterruptedException"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan sleeping\s*thread\s*has\s*received\s*the\s*InterruptedException\s*interrupt\s*status\s*has\s*been\s*cleared\,\s*if\s*the\s*output\s*is\s*false\s*\-\-\s*false \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0107-rt-thread-ThreadTest39/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0107-rt-thread-ThreadTest39/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..443008425c186c70234b9e839a21c774677c6ef3 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0107-rt-thread-ThreadTest39/ThreadTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: GetThreadGroup() Returns the thread group to which this thread belongs. This method returns + * null if this thread has died (been stopped). + *- @Brief: see below + * -#step1: Define test class which inherited from thread class. + * -#step2: Create a ThreadRunning instance. + * -#step3: Start the thread. + * -#step4: Finish the thread by calling join(). + * -#step5: Check that GetThreadGroup() returns null. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + public static void main(String[] args) throws Exception { + ThreadRunning threadRunning = new ThreadRunning(); + threadRunning.start(); + threadRunning.stopWork = true; + threadRunning.join(); + System.out.println("Thread group of a dead thread must be null --- " + + threadRunning.getThreadGroup()); + System.out.println("PASS"); + } + + static class ThreadRunning extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + i--; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan Thread\s*group\s*of\s*a\s*dead\s*thread\s*must\s*be\s*null\s*\-\-\-\s*null\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0109-rt-thread-Basic/Basic.java b/test/testsuite/ouroboros/thread_test/RT0109-rt-thread-Basic/Basic.java new file mode 100755 index 0000000000000000000000000000000000000000..6482cc18f43cd79027f76ff6f81934634da55272 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0109-rt-thread-Basic/Basic.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Basic + *- @TestCaseName: Thread_Basic.java + *- @RequirementName: Java Thread + *- @Title/Destination: Basic functional test of ThreadLocal + *- @Brief: see below + * -#step1: Define a test class. + * -#step2: Create thread instance. + * -#step3: Start the thread. + * -#step4: Wait for the threads to finish. + * -#step5: Check that result without exception. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: Basic.java + *- @ExecuteClass: Basic + *- @ExecuteArgs: + */ + +public class Basic { + static ThreadLocal n = new ThreadLocal() { + int i = 0; + + protected synchronized Object initialValue() { + return new Integer(i++); + } + }; + + public static void main(String[] args) throws Exception { + int threadCount = 100; + Thread[] th = new Thread[threadCount]; + final int[] x = new int[threadCount]; + + // Start the threads + for (int i = 0; i < threadCount; i++) { + th[i] = new Thread() { + public void run() { + int threadId = ((Integer) (n.get())).intValue(); + for (int j = 0; j < threadId; j++) { + x[threadId]++; + yield(); + } + } + }; + th[i].start(); + } + + // Wait for the threads to finish + for (int i = 0; i < threadCount; i++) + th[i].join(); + + // Check results + for (int i = 0; i < threadCount; i++) { + if (x[i] != i) + throw (new Exception("x[" + i + "] =" + x[i])); + System.out.println(x[i]); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\s*1\s*2\s*3\s*4\s*5\s*6\s*7\s*8\s*9\s*10\s*11\s*12\s*13\s*14\s*15\s*16\s*17\s*18\s*19\s*20\s*21\s*22\s*23\s*24\s*25\s*26\s*27\s*28\s*29\s*30\s*31\s*32\s*33\s*34\s*35\s*36\s*37\s*38\s*39\s*40\s*41\s*42\s*43\s*44\s*45\s*46\s*47\s*48\s*49\s*50\s*51\s*52\s*53\s*54\s*55\s*56\s*57\s*58\s*59\s*60\s*61\s*62\s*63\s*64\s*65\s*66\s*67\s*68\s*69\s*70\s*71\s*72\s*73\s*74\s*75\s*76\s*77\s*78\s*79\s*80\s*81\s*82\s*83\s*84\s*85\s*86\s*87\s*88\s*89\s*90\s*91\s*92\s*93\s*94\s*95\s*96\s*97\s*98\s*99 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0110-rt-thread-NullStackTrace/NullStackTrace.java b/test/testsuite/ouroboros/thread_test/RT0110-rt-thread-NullStackTrace/NullStackTrace.java new file mode 100755 index 0000000000000000000000000000000000000000..1e08c466d4fe9851c0cd4ffa958bf59303f0e660 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0110-rt-thread-NullStackTrace/NullStackTrace.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: NullStackTrace + *- @TestCaseName: Thread_NullStackTrace.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread.getStackTrace() on runnable threads, should not return null + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Start the thread. + * -#step3: Check that Thread.getStackTrace() doesn't return null. + * -#step4: Execute step 1~3 repeatedly 1000 times. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: NullStackTrace.java + *- @ExecuteClass: NullStackTrace + *- @ExecuteArgs: + */ + +public class NullStackTrace { + static final int TIMES = 1000; + + public static void main(String[] args) { + for (int i = 0; i < TIMES; i++) { + Thread t = new Thread(); + t.start(); + + StackTraceElement[] ste = t.getStackTrace(); + if (ste == null) + throw new RuntimeException("Failed: Thread.getStackTrace should not return null"); + } + System.out.println("Passed"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan Passed \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0111-rt-thread-ThreadTest6/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0111-rt-thread-ThreadTest6/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7760a940600f61112a8515107b4519b05461c6b3 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0111-rt-thread-ThreadTest6/ThreadTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread.getId() return identifier for each thread, the id is unique and remain same when thread + * state changes + *- @Brief: see below + * -#step1: Create two thread. + * -#step2: Change the thread state. + * -#step3: Check that threads id doesn't changed. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + public static void main(String[] args) throws Exception { + Thread thread1 = new Thread(); + Thread thread2 = new Thread(); + long tId1 = thread1.getId(); + long tId2 = thread2.getId(); + System.out.println(tId1 != tId2); + thread1.join(); + thread2.join(); + long tId3 = thread1.getId(); + long tId4 = thread2.getId(); + System.out.println(tId1 == tId3); + System.out.println(tId2 == tId4); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan true\s*true\s*true \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0112-rt-thread-TestThreadId/TestThreadId.java b/test/testsuite/ouroboros/thread_test/RT0112-rt-thread-TestThreadId/TestThreadId.java new file mode 100755 index 0000000000000000000000000000000000000000..d391f839a27684b5296c7869ac17e20f579ce3cb --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0112-rt-thread-TestThreadId/TestThreadId.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: TestThreadId + *- @TestCaseName: Thread_TestThreadId.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for Constructors Thread(Runnable target) + *- @Brief: see below + * -#step1: Define a test class. + * -#step2: Create TestThreadId instance. + * -#step3: Start all thread. + * -#step4: Finish the thread by calling join(). + * -#step5: Returns the value in the current thread copy of this thread local variable + * -#step6: Check that thread local variable exists. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: TestThreadId.java + *- @ExecuteClass: TestThreadId + *- @ExecuteArgs: + */ + +import java.util.concurrent.atomic.AtomicInteger; + +class ThreadId { + private static final AtomicInteger nextId = new AtomicInteger(0); + + private static final ThreadLocal threadId = new ThreadLocal() { + @Override + protected Integer initialValue() { + return nextId.getAndIncrement(); + } + }; + + public static int get() { + return threadId.get(); + } +} + +public final class TestThreadId extends Thread { + private static final int ITERATIONCOUNT = 50; + private static final int THREADCOUNT = 50; + + private static ThreadId id = new ThreadId(); + + private int value; + + public static void main(String[] args) throws Throwable { + boolean[] check = new boolean[THREADCOUNT * ITERATIONCOUNT]; + + TestThreadId[] u = new TestThreadId[THREADCOUNT]; + + for (int i = 0; i < ITERATIONCOUNT; i++) { + for (int t = 0; t < THREADCOUNT; t++) { + u[t] = new TestThreadId(); + u[t].start(); + } + + for (int t = 0; t < THREADCOUNT; t++) { + try { + u[t].join(); + } catch (InterruptedException e) { + throw new RuntimeException( + "TestThreadId: Failed with unexpected exception" + e); + } + try { + if (check[u[t].getIdValue()]) { + throw new RuntimeException( + "TestThreadId: Failed with duplicated id: " + + u[t].getIdValue()); + } else { + check[u[t].getIdValue()] = true; + } + } catch (Exception e) { + throw new RuntimeException( + "TestThreadId: Failed with unexpected id value" + e); + } + } + } + System.out.println("0"); + } + + private synchronized int getIdValue() { + return value; + } + + public void run() { + value = ThreadId.get(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0113-rt-thread-ImmutableLocal/ImmutableLocal.java b/test/testsuite/ouroboros/thread_test/RT0113-rt-thread-ImmutableLocal/ImmutableLocal.java new file mode 100755 index 0000000000000000000000000000000000000000..48a24dcf64ec7c4863adabdf6f9d70933e5b95fd --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0113-rt-thread-ImmutableLocal/ImmutableLocal.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ImmutableLocal + *- @TestCaseName: Thread_ImmutableLocal.java + *- @RequirementName: Java Thread + *- @Title/Destination: Confirm ThreadLocal.set() usage is not a side effect of get(). + *- @Brief: see below + * -#step1:定义继承ThreadLocal类的抽象类ImmutableThreadLocal,定义抛出new RuntimeException的set()和私有的受保护 + * initialValue()。 + * -#step2:通过new得到一个私有的不可变的线程对象cache,运行initialValue(),调用getName()获取当前执行线程对象的引用。 + * -#step3:在主函数中调用cache.get()获取对象引用,确认获取正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ImmutableLocal.java + *- @ExecuteClass: ImmutableLocal + *- @ExecuteArgs: + */ + +public class ImmutableLocal { + private static final ThreadLocal cache = new ImmutableThreadLocal() { + public Object initialValue() { + return Thread.currentThread().getName(); + } + }; + + public static void main(final String[] args) { + if (cache.get().equals("main")) { + System.out.println(0); + } + } + + /** + * {@link ThreadLocal} guaranteed to always return the same reference. + */ + abstract public static class ImmutableThreadLocal extends ThreadLocal { + public void set(final Object value) { + throw new RuntimeException("ImmutableThreadLocal set called"); + } + + // Force override + abstract protected Object initialValue(); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0114-rt-thread-ThreadTest24/ThreadTest_24.java b/test/testsuite/ouroboros/thread_test/RT0114-rt-thread-ThreadTest24/ThreadTest_24.java new file mode 100755 index 0000000000000000000000000000000000000000..3cad4d2155f73186d3653ec3babfe5eb2462bd21 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0114-rt-thread-ThreadTest24/ThreadTest_24.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest_24 + *- @TestCaseName: Thread_ThreadTest_24.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test for interrupt() -- Interrupt the current thread. + *- @Brief: see below + * -#step1:通过new得到一个新的线程对象,定义run()方法,在run方法里调用isInterrupted。 + * -#step2: 启动线程,通过sleep()指定休眠时间。 + * -#step3: 确认run里调用interrupt()返回true, main函数里调用interrupt()返回false。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest_24.java + *- @ExecuteClass: ThreadTest_24 + *- @ExecuteArgs: + */ + +class ThreadTest_24 { + /* Test for interrupt() -- Interrupt the current thread + * If this thread is blocked in an invocation + * of the wait(), wait(long), or wait(long, int) methods of the Object class, or + * of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, + * then its interrupt status will be cleared and it will receive an InterruptedException. + */ + public static void main(String[] args) { + Thread t = new Thread() { + public void run() { + interrupt(); + System.out.println("in the new thread, isInterrupted() returns -- " + isInterrupted()); + } + }; + + t.start(); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + System.out.println("unexpected InterruptedException while sleeping"); + } + System.out.println("isInterrupted() finally returns -- " + t.isInterrupted()); + System.out.println("PASS"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan in\s*the\s*new\s*thread\,\s*isInterrupted\(\)\s*returns\s*\-\-\s*true\s*isInterrupted\(\)\s*finally\s*returns\s*\-\-\s*false\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0115-rt-thread-ThreadTest13/ThreadTest_13.java b/test/testsuite/ouroboros/thread_test/RT0115-rt-thread-ThreadTest13/ThreadTest_13.java new file mode 100755 index 0000000000000000000000000000000000000000..58d8d678edc71379e310db7544402ec98da37dcb --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0115-rt-thread-ThreadTest13/ThreadTest_13.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest_13 + *- @TestCaseName: Thread_ThreadTest_13.java + *- @RequirementName: Java Thread + *- @Title/Destination: test run() of Thread and the runnable object. + *- @Brief: see below + * -#step1:定义私有静态类ThreadRun实现Runnable接口,定义ThreadRun()和run()。 + * -#step2: 通过new得到一个线程对象,通过getState()获取启动前状态。运行线程。通过getState()启动后状态。确认得到的状态正确。 + * -#step3:通过new得到一个runnable线程对象,通过getState()启动前状态。运行线程,通过getState()启动后状态。确认得到的状 + * 态正确。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest_13.java + *- @ExecuteClass: ThreadTest_13 + *- @ExecuteArgs: + */ + +public class ThreadTest_13 { + /** + * Test for run(). Should do nothing. + */ + public static void main(String[] args) throws Exception { + Thread t = new Thread(); // Test run() for thread + Thread.State tsBefore = t.getState(); + t.run(); + Thread.State tsAfter = t.getState(); + System.out.println("run() should do nothing --- " + tsBefore.equals(Thread.State.NEW)); + System.out.println("run() should do nothing --- " + tsBefore.equals(tsAfter)); + System.out.println("run() should do nothing --- " + tsBefore); + + Thread tt = new Thread(new ThreadRun("helloworld")); // Test run() for runnable object + Thread.State ttsBefore = tt.getState(); + tt.run(); + Thread.State ttsAfter = tt.getState(); + System.out.println("run() should do nothing --- " + ttsBefore.equals(Thread.State.NEW)); + System.out.println("run() should do nothing --- " + ttsBefore.equals(ttsAfter)); + } + + private static class ThreadRun implements Runnable { + private final String helloWorld; + + public ThreadRun(String str) { + helloWorld = str; + } + + public void run() { + System.out.println(helloWorld); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan run\(\)\s*should\s*do\s*nothing\s*\-\-\-\s*true\s*run\(\)\s*should\s*do\s*nothing\s*\-\-\-\s*true\s*run\(\)\s*should\s*do\s*nothing\s*\-\-\-\s*NEW\s*helloworld\s*run\(\)\s*should\s*do\s*nothing\s*\-\-\-\s*true\s*run\(\)\s*should\s*do\s*nothing\s*\-\-\-\s*true \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0116-rt-thread-NullThreadName/NullThreadName.java b/test/testsuite/ouroboros/thread_test/RT0116-rt-thread-NullThreadName/NullThreadName.java new file mode 100755 index 0000000000000000000000000000000000000000..b67311423b668ec7ed2618c4639cfaa035263586 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0116-rt-thread-NullThreadName/NullThreadName.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: NullThreadName + *- @TestCaseName: Thread_NullThreadName.java + *- @RequirementName: Java Thread + *- @Title/Destination: Out-of-date testcase. + *- @Brief: see below + * -#step1;通过new得到构造使用给定计数初始化的对象done。 + * -#step2:定义类GoodThread实现Runnable接口,重写run(),在run()中通过done对象调用countDown()。 + * -#step3: 在主函数中简单输出0为了用例通过。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: NullThreadName.java + *- @ExecuteClass: NullThreadName + *- @ExecuteArgs: + */ + +import java.util.concurrent.CountDownLatch; +import static java.lang.System.out; + +public class NullThreadName { + static CountDownLatch done = new CountDownLatch(1); + + public static void main(String[] args) throws Exception { + /* Because AOSP modify Implementation of Thread.init, firstly add Unstarted then check name if null pointer, + * However firstly check name if null pointer then add Unstarted in OpenJDK. Change this case simply for passed. + */ + System.out.println(0); + } + + static class GoodThread implements Runnable { + @Override + public void run() { + out.println("Good Thread started..."); + out.println("Good Thread finishing"); + done.countDown(); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0117-rt-thread-ThreadTest36/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0117-rt-thread-ThreadTest36/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..6a5d64b56f29e59b8e7f45046846ac1d9d85d5ee --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0117-rt-thread-ThreadTest36/ThreadTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test setPriority(), if set with value higher than threadGroup's maxPriority or a dead thread, do + * nothing , if set with value out of legal range, throw exception. + *- @Brief: see below + * -#step1:定义静态私有类实现Runnable接口,含private final修饰的成员变量、ThreadRun()方法和run()方法。 + * -#step2:通过new得到线程组对象,通过setMaxPriority()设置线程组的最大优先级为9。 + * -#step3:通过new得到线程对象,通过setPriority()设置线程的优先级为最大优先级10,确认设置失败。 + * -#step4:通过new得到线程对象,得到当前线程对象的优先级。通过调用setPriority()方法使新优先级大于最小优先级,确认设置成功。 + * -#step5:通过new得到又一个的线程对象,通过setPriority()方法设置比线程最大优先级更大的值,确认抛出IllegalArgumentException。 + * -#step6:通过new得到线程对象t4,启动对象线程,直到线程结束。相应的状态和优先级获取正确。通过调用setPriority()方法设置线程的最 + * 大优先级,确认设置不生效。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + public static void main(String[] args) throws Exception { + /** + * Verify the setPriority() method with new priority higher + * than the maximum permitted priority for the thread's group. + */ + ThreadGroup tg = new ThreadGroup("group1"); + int maxTGPriority = Thread.MAX_PRIORITY - 1; + tg.setMaxPriority(maxTGPriority); + Thread t = new Thread(tg, new ThreadRun("helloworld!")); + t.setPriority(Thread.MAX_PRIORITY); + System.out.println(maxTGPriority); + System.out.println(tg.getMaxPriority() + " -- " + Thread.MAX_PRIORITY + " -- " + t.getPriority()); + + /** + * Verify the setPriority() method with new priority lower + * than the current one. + */ + Thread tt = new Thread(); + int p = tt.getPriority(); + int newPriority = p - 1; + if (newPriority >= Thread.MIN_PRIORITY) { + tt.setPriority(newPriority); + System.out.println(newPriority + " === " + tt.getPriority()); + } + + /** + * Verify the setPriority() method with new priority out of the legal range. + */ + Thread ttt = new Thread(); + try { + ttt.setPriority(Thread.MAX_PRIORITY + 2); + System.out.println("Fail -- IllegalArgumentException should be thrown when new priority out of the legal range"); + } catch (IllegalArgumentException e) { + System.out.println("IllegalArgumentException has be thrown when new priority out of the legal range"); + } + + /** + * Verify the setPriority() method to a dead thread. do nothing + */ + Thread t4 = new Thread(tg, new ThreadRun("helloworld2")); + t4.start(); + t4.join(); + System.out.println(t4.getState()); + System.out.println(t4.getPriority()); + t4.setPriority(Thread.MAX_PRIORITY); + System.out.println(t4.getPriority()); + } + + // Test for setPriority() + private static class ThreadRun implements Runnable { + private final String helloWorld; + + public ThreadRun(String str) { + helloWorld = str; + } + + public void run() { + System.out.println(helloWorld); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 9\s*9\s*\-\-\s*10\s*\-\-\s*9\s*4\s*\=\=\=\s*4\s*IllegalArgumentException\s*has\s*be\s*thrown\s*when\s*new\s*priority\s*out\s*of\s*the\s*legal\s*range\s*helloworld2\s*TERMINATED\s*5\s*5 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0118-rt-thread-ThreadTest19/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0118-rt-thread-ThreadTest19/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..eca8bb89f23694ee86fa12b15d322160860d3558 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0118-rt-thread-ThreadTest19/ThreadTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Try to make a running thread daemon, test SetDaemonLiveThread. + *- @Brief: see below + * -#step1:定义Thread的子类ThreadRunning,调用super()引用父类的成员,定义run()方法。 + * -#step2:通过new得到ThreadRunning的对象。启动对象线程。指定join()的时间。 + * -#step3:线程结束后输出执行结果。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + public static void main(String[] args) throws Exception { + // Try to make a running thread daemon, test SetDaemonLiveThread + ThreadRunning t = new ThreadRunning(); + t.start(); + t.join(1000); + System.out.println("pass"); + t.stopWork = true; + } + + static class ThreadRunning extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + i--; + } + System.out.println("exit"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan pass\s*exit \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0119-rt-thread-ThreadTest15/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0119-rt-thread-ThreadTest15/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..115a432163cffd73a6e282ebeea33b0a3ba8e48f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0119-rt-thread-ThreadTest15/ThreadTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test getThreadGroup(). + *- @Brief: see below + * -#step1:通过new得到线程对象,通过getThreadGroup()得到线程对象所在的线程组对象。通过currentThread().getThreadGroup() + * 得到当前正在执行的线程组对象。 + * -#step2:通过getName()得到线程组对象的引用并确认为main,与当前正常执行的线程组比较并打印,确认结果为true。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + // Test for getThreadGroup() + public static void main(String[] args) throws Exception { + Thread t = new Thread(); + ThreadGroup threadGroup = t.getThreadGroup(); + ThreadGroup curThreadGroup = Thread.currentThread().getThreadGroup(); + System.out.println(threadGroup.getName()); + System.out.println(threadGroup.equals(curThreadGroup)); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan main\s*true \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0120-rt-thread-ThreadTest3/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0120-rt-thread-ThreadTest3/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..73d3241b1c460dac99193f0fa8e6177653c82245 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0120-rt-thread-ThreadTest3/ThreadTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test getName(). + *- @Brief: see below + * -#step1:调用Thread.currentThread()的getName(),确认返回main。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + /** + * Verify currentThread() + */ + public static void main(String[] args) throws Exception { + System.out.println(Thread.currentThread().getName()); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan main \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0121-rt-thread-InitialValue/InitialValue.java b/test/testsuite/ouroboros/thread_test/RT0121-rt-thread-InitialValue/InitialValue.java new file mode 100755 index 0000000000000000000000000000000000000000..f566d905ff16bfd7283dc15c0a63377f01721064 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0121-rt-thread-InitialValue/InitialValue.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_InitialValue.java + *- @RequirementName: Java Thread + *- @Title/Destination: Tests to see that a set nested in initialValue works OK. + *- @Brief: see below + * -#step1: 以new InitialValue()为参数,创建一个Thread类的实例对象thread,并且InitialValue类实现了Runnable接口; + * -#step2: 调用thread的start()方法启动该线程; + * -#step3: 调用thread的join()方法; + * -#step4: InitialValue类内部的run()方法的逻辑是,创建一个MyLocal类的实例对象myLocal,并且MyLocal类继承自ThreadLocal类; + * 调用myLocal的get()方法,并将其返回值赋值给string1;定义一个ThreadLocal类的变量other,调用其get()方法并将其返 + * 回值赋值给string2,当且仅当string2不等于null并且string2与字符串"Other"相同时,令boolean类型的静态全局变量 + * passed等于true; + * -#step5: 确认程序执行成功并且正常终止; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: InitialValue.java + *- @ExecuteClass: InitialValue + *- @ExecuteArgs: + */ +/* + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 5025230 + * @summary Tests to see that a set nested in initialValue works OK + * @author Pete Soper + */ +public class InitialValue implements Runnable { + static ThreadLocal other; + static boolean passed; + + public static void main(String[] args) { + // Starting with Mustang the main thread already has an initialized + // ThreadLocal map at this point, so test with a second thread. + Thread thread = new Thread(new InitialValue()); + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + throw new RuntimeException("Test Interrupted: failed"); + } + if (!passed) { + throw new RuntimeException("Test Failed"); + } + System.out.println("pass"); + } + + public void run() { + MyLocal myLocal = new MyLocal(); + // This should pick up the initial value + String string1 = myLocal.get(); + // And this should pick up the other local in this thread's locals map + String string2 = other.get(); + if ((string2 != null) && string2.equals("Other")) { + // JMM guarantees this will be visible to + // another thread joining with this thread's + // termination: no need for this to be volatile. + passed = true; + } + } + + public class MyLocal extends ThreadLocal { + protected String initialValue() { + other = new ThreadLocal(); + // This should reuse the map that the containing get() created + // or visa versa (i.e. instead of a second map being created). + other.set("Other"); + return "Initial"; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan pass \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0122-rt-thread-ThreadTest22/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0122-rt-thread-ThreadTest22/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..e20d5c9bae65bc65b1227edcbe46800e4ae33a3a --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0122-rt-thread-ThreadTest22/ThreadTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test for interrupt() -- Interrupt a newly created thread, Interrupting a thread that is not + * alive need not have any effect. + *- @Brief: see below + * -#step1: 创建一个Thread类的实例对象thread,并调用其interrupt()方法中断此线程; + * -#step2: 调用doSleep()方法,参数为600,返回boolean类型的值并赋值给expired; + * -#step3: 调用thread的isInterrupted()方法,返回值记为result; + * -#step4: 确认线程的状态是新建态,并且调用线程的isInterrupted()返回false,表明此时线程并未中断; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +class ThreadTest { + private static final long waitDuration = 3000; + private static long waitTime = 0; + + private static boolean doSleep(int interval) { + try { + Thread.sleep(interval); + } catch (InterruptedException e) { + System.out.println("unexpected InterruptedException while sleeping"); + } + waitTime -= interval; + return waitTime <= 0; + } + + // test for interrupt() -- Interrupt a newly created thread + // Interrupting a thread that is not alive need not have any effect. + /* If this thread is blocked in an invocation + * of the wait(), wait(long), or wait(long, int) methods of the Object class, or + * of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, + * then its interrupt status will be cleared and it will receive an InterruptedException. + */ + public static void main(String[] args) { + boolean expired = false; + boolean result = false; + Thread thread = new Thread(); + thread.interrupt(); + waitTime = waitDuration; + while (!result && !expired) { + expired = doSleep(600); + result = thread.isInterrupted(); + } + System.out.println("thread's state is -- " + thread.getState()); + System.out.println("isInterrupted() finally returns -- " + result); + if (expired) { + System.out.println("interrupt status has not changed to true"); + } else { + System.out.println("*PASS*"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan thread\'s\s*state\s*is\s*\-\-\s*NEW\s*isInterrupted\(\)\s*finally\s*returns\s*\-\-\s*false\s*interrupt\s*status\s*has\s*not\s*changed\s*to\s*true \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0123-rt-thread-ThreadTest7/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0123-rt-thread-ThreadTest7/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..bd70ca5ec702495cc4c3e8c5cb1b6fd3085ed5cc --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0123-rt-thread-ThreadTest7/ThreadTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: the default priority of a thread is in range (MIN_PRIORITY,MAX_PRIORITY). + *- @Brief: see below + * -#step1: 创建一个Thread类的实例对象thread; + * -#step2: 调用thread的getPriority()方法,获取线程的优先级并记为p; + * -#step3: 确认该线程的优先级p介于最小优先级和最大优先级之间; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + //test for getPriority() + public static void main(String[] args) throws Exception { + Thread thread = new Thread(); + int p = thread.getPriority(); + System.out.println(Thread.MIN_PRIORITY + " <= " + p + " <= " + Thread.MAX_PRIORITY); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 1\s*\<\=\s*5\s*\<\=\s*10 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0125-rt-thread-ThreadTest26/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0125-rt-thread-ThreadTest26/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..269bccd67ae6d7ef0c108aac8e88b41584bee35c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0125-rt-thread-ThreadTest26/ThreadTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test setUncaughtExceptionHandler(). + *- @Brief: see below + * -#step1: 以"test thread group"为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 以threadGroup、new ThreadRun("helloworld!")为参数,创建一个Thread类的实例对象thread,并且ThreadRun类实现了 + * Runnable接口; + * -#step3: 创建一个ExceptionHandler类的实例对象exceptionHandler,并以exceptionHandler为参数,调用thread的 + * setUncaughtExceptionHandler()方法; + * -#step4: 经判断得知实例对象exceptionHandler与thread.getUncaughtExceptionHandler()的返回值是相同的; + * -#step5: 以"test thread group2"为参数,创建一个ThreadGroup类的实例对象threadGroup2; + * -#step6: 以threadGroup2、new ThreadRun("helloworld!")为参数,创建一个Thread类的实例对象thread2,并且ThreadRun类实现了 + * Runnable接口; + * -#step7: 以null为参数,调用thread2的setUncaughtExceptionHandler()方法; + * -#step8: 经判断得知实例对象threadGroup2与thread2.getUncaughtExceptionHandler()的返回值是相同的; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + public static void main(String[] args) throws Exception { + //Test for setUncaughtExceptionHandler() + ThreadGroup threadGroup = new ThreadGroup("test thread group"); + Thread thread = new Thread(threadGroup, new ThreadRun("helloworld!")); + ExceptionHandler exceptionHandler = new ExceptionHandler(); + thread.setUncaughtExceptionHandler(exceptionHandler); + System.out.println("should be same -- " + exceptionHandler.equals(thread.getUncaughtExceptionHandler())); + + //Test for setUncaughtExceptionHandler(null) + ThreadGroup threadGroup2 = new ThreadGroup("test thread group2"); + Thread thread2 = new Thread(threadGroup2, new ThreadRun("helloworld!")); + thread2.setUncaughtExceptionHandler(null); + System.out.println("Thread's thread group is expected to be a handler -- " + + threadGroup2.equals(thread2.getUncaughtExceptionHandler())); + System.out.println("PASS"); + } + + private static class ThreadRun implements Runnable { + private final String helloworld; + + public ThreadRun(String str) { + helloworld = str; + } + + public void run() { + System.out.println(helloworld); + } + } + + static class ExceptionHandler implements Thread.UncaughtExceptionHandler { + public boolean wasCalled = false; + + public void uncaughtException(Thread t, Throwable e) { + wasCalled = true; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan should\s*be\s*same\s*\-\-\s*true\s*Thread\'s\s*thread\s*group\s*is\s*expected\s*to\s*be\s*a\s*handler\s*\-\-\s*true\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0126-rt-thread-SetMaxPriority/SetMaxPriority.java b/test/testsuite/ouroboros/thread_test/RT0126-rt-thread-SetMaxPriority/SetMaxPriority.java new file mode 100755 index 0000000000000000000000000000000000000000..6a247d250b5911d2c7036d43500478f2b7e36f5c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0126-rt-thread-SetMaxPriority/SetMaxPriority.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Ouroboros/rt_test/SetMaxPriority + *- @TestCaseName: Thread_SetMaxPriority.java + *- @RequirementName: Java Thread + *- @Title/Destination:test ThreadGroup.setMaxPriority ignores bad argument values + *- @Brief: see below + * -#step1: 以foo为参数,创建一个ThreadGroup类的实例对象threadGroup; + * -#step2: 通过调用threadGroup的getParent()方法,得其返回值并赋值给threadGroupParent; + * -#step3: 将threadGroup.getMaxPriority()的返回值记为currentMaxPriority,将threadGroupParent.getMaxPriority() / 2的返回 + * 值记为halfMaxPriority; + * -#step4: 经判断得知halfMaxPriority与Thread.MIN_PRIORITY的差值大于等于2; + * -#step5: 以(halfMaxPriority - 2)为参数,调用threadGroup的setMaxPriority()方法,而后将threadGroup.getMaxPriority()的 + * 返回值赋值给currentMaxPriority; + * -#step6: 经判断得知currentMaxPriority与(halfMaxPriority - 2)的值相等; + * -#step7: 以(currentMaxPriority + 1)为参数,调用threadGroup的setMaxPriority()方法,而后将 + * threadGroup.getMaxPriority()的返回值记为newMaxPriority; + * -#step8: 经判断得知newMaxPriority与(currentMaxPriority + 1)的值相等; + * -#step9: 以(Thread.MIN_PRIORITY - 1)为参数,调用threadGroup的setMaxPriority()方法; + * -#step10: 经判断得知Thread.MIN_PRIORITY的值与threadGroup.getMaxPriority()的返回值不相等; + * -#step11: 以(Thread.MAX_PRIORITY + 1)为参数,调用threadGroup的setMaxPriority()方法; + * -#step12: 经判断得知Thread.MAX_PRIORITY的值与threadGroup.getMaxPriority()的返回值不相等; + *- @Expect:expected.txt + *- @Priority: High + *- @Source: SetMaxPriority.java + *- @ExecuteClass: SetMaxPriority + *- @ExecuteArgs: + */ +/* + * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4708197 6497629 + * @summary Test for max priority setting that matches spec + * @author Pete Soper + */ + +public class SetMaxPriority { + + public static void main(String[] args) throws Exception { + ThreadGroup tg = new ThreadGroup("foo"); + ThreadGroup ptg = tg.getParent(); + int currentMaxPriority = tg.getMaxPriority(); + int halfMaxPriority = ptg.getMaxPriority() / 2; + if (halfMaxPriority - Thread.MIN_PRIORITY < 2) { + throw new RuntimeException("SetMaxPriority test no longer valid: starting parent max priority too close to Thread.MIN_PRIORITY"); + } + tg.setMaxPriority(halfMaxPriority - 2); + currentMaxPriority = tg.getMaxPriority(); + if (currentMaxPriority != halfMaxPriority - 2) { + throw new RuntimeException("SetMaxPriority failed: max priority not changed"); + } + + // This will fail if bug 6497629 is present because the min tests is + // being made with the (just lowered) max instead of the parent max, + // preventing the priority from being moved back up. + tg.setMaxPriority(currentMaxPriority + 1); + int newMaxPriority = tg.getMaxPriority(); + if (newMaxPriority != currentMaxPriority + 1) { + throw new RuntimeException("SetMaxPriority failed: defect 6497629 present"); + } + + // Confirm that max priorities out of range on both ends have no + // effect. + /* android is not same as openjdk*/ + tg.setMaxPriority(Thread.MIN_PRIORITY - 1); + if (Thread.MIN_PRIORITY != tg.getMaxPriority()) + throw new RuntimeException( + "setMaxPriority bad arg not ignored as specified"); + + tg.setMaxPriority(Thread.MAX_PRIORITY + 1); + if (Thread.MAX_PRIORITY != tg.getMaxPriority()) + throw new RuntimeException( + "setMaxPriority bad arg not ignored as specified"); + + System.out.println("SetMaxPriority passed"); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan SetMaxPriority\s*passed \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0127-rt-thread-ThreadTest18/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0127-rt-thread-ThreadTest18/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2e4e8922419d6f1a06c05bf409fbf274c0841e9a --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0127-rt-thread-ThreadTest18/ThreadTest.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: set a Thread to Daemon and run it. + *- @Brief: see below + * -#step1: 创建一个ThreadRunning类的实例对象threadRunning,并且ThreadRunning类继承自Thread类; + * -#step2: 调用threadRunning的setDaemon()方法,设置其属性为true; + * -#step3: 调用threadRunning的start()方法启动该线程; + * -#step4: 让当前线程休眠1000ms; + * -#step5: 经判断得知,threadRunning.isDaemon()与threadRunning.isAlive()的返回值均为true; + * -#step6: 将类变量threadRunning.stopWork赋值为true; + * -#step7: 让当前线程休眠1000ms; + * -#step8: 在ThreadRunning类内部的run()方法执行完成后,经判断得知,threadRunning.isDaemon()的返回值为true, + * threadRunning.isAlive()的返回值均为false; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + public static void main(String[] args) throws Exception { + //Try to make a running thread daemon, test SetDaemonLiveThread + ThreadRunning threadRunning = new ThreadRunning(); + try { + threadRunning.setDaemon(true); + threadRunning.start(); + } catch (Exception e) { + System.out.println("fail"); + } + try { + Thread.sleep(1000); + } catch (Exception e) { + } + System.out.println(threadRunning.isDaemon()); + System.out.println(threadRunning.isAlive()); + threadRunning.stopWork = true; + try { + Thread.sleep(1000); + } catch (Exception e) { + } + System.out.println(threadRunning.isDaemon()); + System.out.println(threadRunning.isAlive()); + } + + static class ThreadRunning extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + i--; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan true\s*true\s*true\s*false \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0128-rt-thread-ThreadTest16/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0128-rt-thread-ThreadTest16/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..e1dca29b441be32d7bc3040e0975499d2ab1c6e9 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0128-rt-thread-ThreadTest16/ThreadTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: interrupt a running thread. + *- @Brief: see below + * -#step1: 创建一个MyThread类的实例对象thread,并且MyThread类继承自Thread类; + * -#step2: 调用thread的start()方法启动该线程; + * -#step3: 让当前线程休眠1000ms; + * -#step4: 调用thread的interrupt()方法中断线程; + * -#step5: 在thread内部的run()执行完成后(内部逻辑是当isInterrupted()返回为false时,调用yield()方法,并分别打印 + * isInterrupted()、interrupted()、isInterrupted()的值),isInterrupted()、interrupted()、isInterrupted()的值 + * 分别为true、true、false; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +class MyThread extends Thread { + public void run() { + while (!isInterrupted()) { + yield(); + } + System.out.println(isInterrupted()); + System.out.println(interrupted()); + System.out.println(isInterrupted()); + } +} + +public class ThreadTest { + public static void main(String[] args) { + Thread thread = new MyThread(); + thread.start(); + + try { + Thread.sleep(1000); + thread.interrupt(); + } catch (Exception e) { + System.out.println("catch"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan true\s*true\s*false \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0130-rt-thread-ThreadTest20/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0130-rt-thread-ThreadTest20/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f48e1d688b283d770645c37a2526305787db866d --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0130-rt-thread-ThreadTest20/ThreadTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: when there are only daemon thread, JVM exit. + *- @Brief: see below + * -#step1: 创建两个ThreadRunning1类的实例对象threadRunning1、threadRunning3,创建一个ThreadRunning2类的实例对象 + * threadRunning2,并且ThreadRunning1类、ThreadRunning2类都继承自Thread类; + * -#step2: 分别调用threadRunning1、threadRunning3的setDaemon()方法,设置其属性为true; + * -#step3: 分别调用threadRunning1、threadRunning2、threadRunning3的start()方法启动这三个线程; + * -#step4: 让当前线程休眠1000ms; + * -#step5: 将类变量threadRunning2.stopWork赋值为true; + * -#step6: 经判断可知,程序最终只打印了ThreadRunning2; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + public static void main(String[] args) throws Exception { + //Try to make a running thread daemon, test SetDaemonLiveThread + + ThreadRunning1 threadRunning1 = new ThreadRunning1(); + ThreadRunning2 threadRunning2 = new ThreadRunning2(); + ThreadRunning1 threadRunning3 = new ThreadRunning1(); + threadRunning1.setDaemon(true); + threadRunning3.setDaemon(true); + threadRunning1.start(); + threadRunning2.start(); + threadRunning3.start(); + try { + Thread.sleep(1000); + } catch (Exception e) { + } + threadRunning2.stopWork = true; + } + + static class ThreadRunning1 extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning1() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + } + System.out.println("ThreadRunning1"); + } + } + + static class ThreadRunning2 extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning2() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + i--; + } + System.out.println("ThreadRunning2"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan ThreadRunning2 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0131-rt-thread-ThreadTest14/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0131-rt-thread-ThreadTest14/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..6a3ed3673b0b48e3eada6bfcb06b65a171ddef58 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0131-rt-thread-ThreadTest14/ThreadTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test join(long millis) and join(long millis, int nanos) with valid and invalid value. when value + * out of range, throws IllegalArgumentException. + *- @Brief: see below + * -#step1: 创建一个ThreadRunning类的实例对象threadRunning,并且ThreadRunning类继承自Thread类; + * -#step2: 调用threadRunning的start()方法启动该线程; + * -#step3: 尝试以-1为参数,调用threadRunning的join()方法; + * -#step4: step3中会抛出IllegalArgumentException,此时将类变量threadRunning.stopWork赋值为true; + * -#step5: 创建一个ThreadRunning类的实例对象threadRunning2,并且ThreadRunning类继承自Thread类; + * -#step6: 调用threadRunning2的start()方法启动该线程; + * -#step7: 以1000为参数,调用threadRunning2的join()方法; + * -#step8: 程序执行成功并打印相关信息,此时将类变量threadRunning2.stopWork赋值为true; + * -#step9: 创建一个ThreadRunning类的实例对象threadRunning3,并且ThreadRunning类继承自Thread类; + * -#step10: 调用threadRunning3的start()方法启动该线程; + * -#step11: 尝试以1000、1123456为参数,调用threadRunning3的join()方法; + * -#step12: step11中会抛出IllegalArgumentException,此时将类变量threadRunning3.stopWork赋值为true; + * -#step13: 创建一个ThreadRunning类的实例对象threadRunning4,并且ThreadRunning类继承自Thread类; + * -#step14: 调用threadRunning4的start()方法启动该线程; + * -#step15: 尝试以-2、123456为参数,调用threadRunning4的join()方法; + * -#step16: step15中会抛出IllegalArgumentException,此时将类变量threadRunning4.stopWork赋值为true; + * -#step17: 创建一个ThreadRunning类的实例对象threadRunning5,并且ThreadRunning类继承自Thread类; + * -#step18: 调用threadRunning5的start()方法启动该线程; + * -#step19: 以1000、123456为参数,调用threadRunning5的join()方法; + * -#step20: 程序执行成功并打印相关信息,此时将类变量threadRunning5.stopWork赋值为true; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + public static void main(String[] args) throws Exception { + //for join(long millis) + ThreadRunning threadRunning = new ThreadRunning(); + threadRunning.start(); + try { + threadRunning.join(-1); + System.out.println("join(millis) OK"); + threadRunning.stopWork = true; + } catch (IllegalArgumentException e) { + threadRunning.stopWork = true; + System.out.println("in join(millis), millis is negative"); + } + + ThreadRunning threadRunning2 = new ThreadRunning(); + threadRunning2.start(); + try { + threadRunning2.join(1000); + System.out.println("join(millis) OK"); + threadRunning2.stopWork = true; + } catch (IllegalArgumentException e) { + threadRunning2.stopWork = true; + System.out.println("in join(millis), millis is negative"); + } + + //for join(long millis, int nanos) + ThreadRunning threadRunning3 = new ThreadRunning(); + threadRunning3.start(); + try { + threadRunning3.join(1000, 1123456); + System.out.println("join(millis, nanos) OK"); + threadRunning3.stopWork = true; + } catch (IllegalArgumentException e) { + threadRunning3.stopWork = true; + System.out.println("in join(millis, nanos), nanosecond out of range"); + } + + ThreadRunning threadRunning4 = new ThreadRunning(); + threadRunning4.start(); + try { + threadRunning4.join(-2, 123456); + System.out.println("join(millis, nanos) OK"); + threadRunning4.stopWork = true; + } catch (IllegalArgumentException e) { + threadRunning4.stopWork = true; + System.out.println("in join(millis, nanos), millis is negative"); + } + + ThreadRunning threadRunning5 = new ThreadRunning(); + threadRunning5.start(); + try { + threadRunning5.join(1000, 123456); + System.out.println("join(millis, nanos) OK"); + threadRunning5.stopWork = true; + } catch (IllegalArgumentException e) { + threadRunning5.stopWork = true; + System.out.println("in join(millis, nanos), millis is negative or nanosecond out of range"); + } + System.out.println("PASS"); + } + + static class ThreadRunning extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + i--; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan in\s*join\(millis\)\,\s*millis\s*is\s*negative\s*join\(millis\)\s*OK\s*in\s*join\(millis\,\s*nanos\)\,\s*nanosecond\s*out\s*of\s*range\s*in\s*join\(millis\,\s*nanos\)\,\s*millis\s*is\s*negative\s*join\(millis\,\s*nanos\)\s*OK\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0132-rt-thread-ThreadTest17/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0132-rt-thread-ThreadTest17/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5fcae2c7a30d39c2459e01fd9a50e4728556fc4e --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0132-rt-thread-ThreadTest17/ThreadTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: use volatile to control when a thread should stop running. + *- @Brief: see below + * -#step1: 创建一个ThreadRunning类的实例对象threadRunning,且ThreadRunning类继承自Thread类; + * -#step2: 调用threadRunning的start()方法启动该线程; + * -#step3: 调用threadRunning的isAlive()方法得其返回值为true,得知线程threadRunning是活跃着的; + * -#step4: 将类变量threadRunning.stopWork赋值为true; + * -#step5: 调用threadRunning的join()方法; + * -#step6: 调用threadRunning的isAlive()方法得其返回值为false,得知线程threadRunning已经不活跃; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + public static void main(String[] args) throws Exception { + //Try to make a running thread daemon, test SetDaemonLiveThread + + ThreadRunning threadRunning = new ThreadRunning(); + threadRunning.start(); + System.out.println(threadRunning.isAlive()); + threadRunning.stopWork = true; + threadRunning.join(); + System.out.println(threadRunning.isAlive()); + } + + static class ThreadRunning extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + i--; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan true\s*false \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0133-rt-thread-ThreadTest33/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0133-rt-thread-ThreadTest33/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7a2890f3bfdef572453d767b00ea787c4429931c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0133-rt-thread-ThreadTest33/ThreadTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: test yield() in thread. finally all thread finished running. + *- @Brief: see below + * -#step1: 创建两个ThreadYielding类的实例对象threadYielding1、threadYielding2,并且ThreadYielding类继承自Thread类; + * -#step2: 分别调用threadYielding1、threadYielding2的start()方法启动这两个线程; + * -#step3: 分别调用threadYielding1、threadYielding2的join()方法; + * -#step4: 将类变量ThreadYielding.dim的值赋值给threadNum; + * -#step5: 经判断得知,threadYielding1.count、threadYielding2.count的值与(threadNum / 2)的值相等; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + public static void main(String[] args) throws Exception { + /** + * Test for void yield() + */ + ThreadYielding threadYielding1 = new ThreadYielding(); + ThreadYielding threadYielding2 = new ThreadYielding(); + threadYielding1.start(); + threadYielding2.start(); + try { + threadYielding1.join(); + threadYielding2.join(); + } catch (InterruptedException e) { + System.out.println("INTERRUPTED_MESSAGE"); + } + int threadNum = ThreadYielding.dim; + + // We suppose that threads t1 and t2 alternate with each other. + // The might be a case when some another thread (not t2) runs + // while t1 is yelding. In this case the 'list' might start with 1s + // and end with 2s and look like threads does not alternate. + // We cannot treat this as failure nevertheless. + // We just make sure that both threads have finished successfully. + System.out.println("threads have finished successfully --- " + + (threadYielding1.count == threadNum / 2) + " --- " + (threadYielding2.count == threadNum / 2)); + System.out.println("PASS"); + } + + private static class ThreadYielding extends Thread { + public static final int dim = 200; + public int count = 0; + + public synchronized void incCount() { + count++; + } + + public void run() { + for (int i = 0; i < dim / 2; i++) { + incCount(); + Thread.yield(); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan threads\s*have\s*finished\s*successfully\s*\-\-\-\s*true\s*\-\-\-\s*true\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0134-rt-thread-ThreadTest27/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0134-rt-thread-ThreadTest27/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..e7a812b7cede2e0ca6d68a5728657bea4def402e --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0134-rt-thread-ThreadTest27/ThreadTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test set/get DefaultUncaughtExceptionHandler() and set/get DefaultUncaughtExceptionHandler + * (null). + *- @Brief: see below + * -#step1: 创建一个ExceptionHandler类的实例对象exceptionHandler,并且ExceptionHandler类实现了 + * Thread.UncaughtExceptionHandler接口; + * -#step2: 以exceptionHandler为参数,调用Thread的setDefaultUncaughtExceptionHandler()方法; + * -#step3: 经判断得知,exceptionHandler与Thread.getDefaultUncaughtExceptionHandler()的返回值相同; + * -#step4: 以null为参数,调用Thread的setDefaultUncaughtExceptionHandler()方法; + * -#step5: 经判断得知,Thread.getDefaultUncaughtExceptionHandler()的返回值为null; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + public static void main(String[] args) throws Exception { + /** + * Test set/get DefaultUncaughtExceptionHandler() + */ + ExceptionHandler exceptionHandler = new ExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler(exceptionHandler); + System.out.println("The default handler has been set, should print true -- " + + exceptionHandler.equals(Thread.getDefaultUncaughtExceptionHandler())); + + + /** + * Test set/get DefaultUncaughtExceptionHandler(null) + */ + Thread.setDefaultUncaughtExceptionHandler(null); + System.out.println("Default handler should be null, and the test is -- " + + Thread.getDefaultUncaughtExceptionHandler()); + System.out.println("PASS"); + } + + static class ExceptionHandler implements Thread.UncaughtExceptionHandler { + public boolean wasCalled = false; + + public void uncaughtException(Thread t, Throwable e) { + wasCalled = true; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan The\s*default\s*handler\s*has\s*been\s*set\,\s*should\s*print\s*true\s*\-\-\s*true\s*Default\s*handler\s*should\s*be\s*null\,\s*and\s*the\s*test\s*is\s*\-\-\s*null\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0135-rt-thread-StartOOMTest/StartOOMTest.java b/test/testsuite/ouroboros/thread_test/RT0135-rt-thread-StartOOMTest/StartOOMTest.java new file mode 100755 index 0000000000000000000000000000000000000000..1b74d942fb632625d38851b0a6237e94a788516c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0135-rt-thread-StartOOMTest/StartOOMTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: StartOOMTest + *- @TestCaseName: Thread_StartOOMTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: OutOfMemoryError is thrown when there are too many thread created. + *- @Brief: see below + * -#step1: 定义类SleepRunnable实现Runnable接口,定义run()方法,通过sleep()指定休眠时间。 + * -#step2: 通过new得到类SleepRunnable的对象、线程组对象、线程列表对象以及一个为null的failedThread。 + * -#step3: 在for()循环中,new得到100个设置了参数的Thread类对象,当跑到第100个是,throw OutOfMemoryError。 + * -#step4: Thread类对象循环调用interrupt()。启动failedThread线程对象,调用interrupt()。Thread类对象循环调用join(), + * failedThread对象赋值为最后一个新增的Thread类对象。 + * -#step5: 对前100个线程调用interrupt()进行中断,当活跃线程数大于50时,调用Thread.yield()。 + * -#step6: 等待所有线程运行结束,确认激活的线程组对象数量为0。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: StartOOMTest.java + *- @ExecuteClass: StartOOMTest + *- @ExecuteArgs: + */ + +import java.util.ArrayList; +import java.util.List; + +public class StartOOMTest { + public static void main(String[] args) throws Throwable { + Runnable r = new SleepRunnable(); + ThreadGroup tg = new ThreadGroup("buggy"); + List threads = new ArrayList(); + Thread failedThread = null; + int i = 0; + for (i = 0; i < 101; i++) { + Thread t = new Thread(tg, r); + try { + if (i == 100) { + throw new OutOfMemoryError("throw OutOfMemoryError"); + } + t.start(); + threads.add(t); + } catch (Throwable x) { + failedThread = t; + System.out.println(x); + System.out.println(i); + break; + } + } + + int j = 0; + for (Thread t : threads) { + t.interrupt(); + } + + while (tg.activeCount() > i / 2) { + Thread.yield(); + } + failedThread.start(); + failedThread.interrupt(); + + for (Thread t : threads) { + t.join(); + } + failedThread.join(); + + try { + Thread.sleep(1000); + } catch (Throwable ignore) { + System.out.println("Sleep is interrupted"); + } + + int activeCount = tg.activeCount(); + System.out.println("activeCount = " + activeCount); + + if (activeCount > 0) { + throw new RuntimeException("Failed: there should be no active Threads in the group"); + } + } + + static class SleepRunnable implements Runnable { + public void run() { + try { + Thread.sleep(60 * 1000); + } catch (Throwable t) { + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan java\.lang\.OutOfMemoryError\:\s*throw\s*OutOfMemoryError\s*100\s*activeCount\s*\=\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0136-rt-thread-ThreadTest29/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0136-rt-thread-ThreadTest29/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9fba8965af227edb522e1dd45cbb4cc0fddbb8a9 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0136-rt-thread-ThreadTest29/ThreadTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test for interrupt() -- Interrupt a joining thread. + *- @Brief: see below + * -#step1: 定义私有静态类ThreadJoining继承于Thread,创建ThreadJoining的构造方法。定义run()。 + * -#step2: 通过new得到ThreadJoining的对象,启动线程对象,通过sleep()指定线程休眠时间。 + * -#step3: 中断线程,等待3秒,确认抛出InterruptedException,调用isInterrupted()返回false。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +class ThreadTest { + public static void main(String[] args) { + ThreadJoining t = new ThreadJoining(10000, 0); + t.start(); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + System.out.println("main throws InterruptedException"); + } + t.interrupt(); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + System.out.println("main throws InterruptedException"); + } + System.out.println("interrupt status has been cleared, if the output is false -- " + t.isInterrupted()); + } + + /* Test for interrupt() -- Interrupt a joining thread + * If this thread is blocked in an invocation + * of the wait(), wait(long), or wait(long, int) methods of the Object class, or + * of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, + * then its interrupt status will be cleared and it will receive an InterruptedException. + */ + private static class ThreadJoining extends Thread { + private long millis; + private int nanos; + + ThreadJoining(long millis, int nanos) { + this.millis = millis; + this.nanos = nanos; + } + + public void run() { + try { + this.join(millis, nanos); + System.out.println("Fail -- joining thread has not received the InterruptedException"); + } catch (InterruptedException e) { + System.out.println("joining thread has received the InterruptedException"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan joining\s*thread\s*has\s*received\s*the\s*InterruptedException\s*interrupt\s*status\s*has\s*been\s*cleared\,\s*if\s*the\s*output\s*is\s*false\s*\-\-\s*false \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0137-rt-thread-ThreadTest12/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0137-rt-thread-ThreadTest12/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..489269cb05fada551a1346491dea53f0a0c2d9c9 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0137-rt-thread-ThreadTest12/ThreadTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test for setDaemon() and isDaemon(); child thread inherits from parent thread if it is daemon + * or not. + *- @Brief: see below + * -#step1: 定义私有静态类ThreadRunningAnotherThread,继承于类Thread。定义构造方法,调用super()。定义run(),定义了Thread + * 对象,currentThread对象,isDaemon对象。 + * -#step2: 通过new得到ThreadRunningAnotherThread的对象,设置对象的守护进程状态为true。启动线程对象,暂停线程。等待线程结束, + * 调用childIsDaemon(),确认返回true。 + * -#step3: 通过new得到ThreadRunningAnotherThread的对象,设置对象的守护进程状态为false。启动线程对象,暂停线程。等待线程结束, + * 调用childIsDaemon(),确认返回false。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + public static void main(String[] args) throws Exception { + /** + * Verify that a thread created by a daemon thread is daemon + */ + ThreadRunningAnotherThread t = new ThreadRunningAnotherThread(); + t.setDaemon(true); + t.start(); + t.stop = true; + try { + t.join(); + } catch (InterruptedException e) { + System.out.println("INTERRUPTED_MESSAGE --"); + } + System.out.println("the child thread of a daemon thread is daemon --- " + + t.childIsDaemon); + /** + * Verify that a thread created by a non-daemon thread is not daemon + */ + ThreadRunningAnotherThread tt = new ThreadRunningAnotherThread(); + tt.setDaemon(false); + tt.start(); + tt.stop = true; + try { + tt.join(); + } catch (InterruptedException e) { + System.out.println("INTERRUPTED_MESSAGE --"); + } + System.out.println("the child thread of a non-daemon thread is non-daemon --- " + + tt.childIsDaemon); + } + + // Test for setDaemon() and isDaemon() + private static class ThreadRunningAnotherThread extends Thread { + int field = 0; + volatile boolean stop = false; + boolean childIsDaemon = false; + Thread curThread = null; + + public ThreadRunningAnotherThread() { + super(); + } + + public void run() { + Thread child = new Thread(); + curThread = Thread.currentThread(); + childIsDaemon = child.isDaemon(); + while (!stop) { + field++; + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan the\s*child\s*thread\s*of\s*a\s*daemon\s*thread\s*is\s*daemon\s*\-\-\-\s*true\s*the\s*child\s*thread\s*of\s*a\s*non\-daemon\s*thread\s*is\s*non\-daemon\s*\-\-\-\s*false \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0138-rt-thread-ThreadTest32/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0138-rt-thread-ThreadTest32/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2f598dfa5da857d77171eabf7a9268541b7bf8b1 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0138-rt-thread-ThreadTest32/ThreadTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Create a thread with Thread(ThreadGroup, Runnable, String, long), stack size is Long.MAX_VALUE. + *- @Brief: see below + * -#step1: 定义类Square实现Runnable接口,定义run()方法,通过sleep()指定线程休眠时间。 + * -#step2: 创建Square对象。 + * -#step3: 调用Thread(ThreadGroup, Runnable, String, long)创建Thread对象,启动线程对象。确认正常启动,run方法被调用,无异常 + * 抛出。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + /** + * Thread(ThreadGroup, Runnable, String, long) stack size is Long.MAX_VALUE. + */ + public static void main(String[] args) throws Exception { + // Does not work in maple, no exception occurs, run() is not executed. + boolean expired = false; + ThreadGroup tg = new ThreadGroup("newGroup"); + String name = "t1"; + Square s = new Square(); + System.out.println(Long.MAX_VALUE); + try { + Thread t = new Thread(tg, s, name, Long.MAX_VALUE); + System.out.println("Creation_OK"); + t.start(); + } catch (OutOfMemoryError er) { + System.out.println("OutOfMemoryError"); + } + System.out.println("PASS"); + } + + static class Square implements Runnable { + public void run() { + System.out.println("Enter_OK"); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + System.out.println("unexpected InterruptedException while sleeping"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 9223372036854775807\s*Creation_OK\s*OutOfMemoryError\s*PASS \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0139-rt-thread-ThreadTest4/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0139-rt-thread-ThreadTest4/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..cf96639a538ca885ab9aebef20bbb5102ee625ad --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0139-rt-thread-ThreadTest4/ThreadTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test for static int enumerate(Thread[] tarray) . + *- @Brief: see below + * -#step1: 定义类ThreadRunning继承于Thread。定义构造方法,调用super()。定义run()。 + * -#step2: 通过new得到类ThreadRunning的多个线程对象并启动,调用enumerate(Thread[] tarray)复制线程列表。 + * -#step3: 遍历线程,暂停线程。返回线程总数为7。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + // Enumerate() does not work in maple. + public static void main(String[] args) throws Exception { + ThreadRunning t1 = new ThreadRunning(); + t1.start(); + ThreadRunning t2 = new ThreadRunning(); + t2.start(); + ThreadRunning t11 = new ThreadRunning(); + t11.start(); + ThreadRunning t12 = new ThreadRunning(); + t12.start(); + ThreadRunning t121 = new ThreadRunning(); + t121.start(); + ThreadRunning t122 = new ThreadRunning(); + t122.start(); + // Estimate dimension as 6 created threads. + // Plus 10 for some other threads. + int estimateLength = 16; + Thread[] list; + int count; + while (true) { + list = new Thread[estimateLength]; + count = Thread.enumerate(list); + if (count == estimateLength) { + estimateLength *= 2; + } else { + //System.out.println(count); + break; + } + } + t1.stopWork = true; + t2.stopWork = true; + t11.stopWork = true; + t12.stopWork = true; + t121.stopWork = true; + t122.stopWork = true; + System.out.println("thread count : " + count); + } + + // Test for enumerate() + static class ThreadRunning extends Thread { + public volatile int i = 0; + volatile boolean stopWork = false; + + ThreadRunning() { + super(); + } + + public void run() { + while (!stopWork) { + i++; + i--; + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan thread\s*count\s*\:\s*7 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0140-rt-thread-MainThreadTest/MainThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0140-rt-thread-MainThreadTest/MainThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b27be9eb887c5fee9339452e06d99f241bda65eb --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0140-rt-thread-MainThreadTest/MainThreadTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MainThreadTest + *- @TestCaseName: Thread_MainThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test to see if the main thread is in its thread group. + *- @Brief: see below + * -#step1: 通过Thread.currentThread().getThreadGroup()获取当前线程组对象。 + * -#step2: 调用activeCount()获取当前活跃的线程数目n。 + * -#step3: 创建一个n大小的线程组ts,调用enumerate(Thread[] tarray)复制当前的线程组到ts。 + * -#step4: 遍历线程组。main线程确认在遍历的线程组中。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: MainThreadTest.java + *- @ExecuteClass: MainThreadTest + *- @ExecuteArgs: + */ + +public class MainThreadTest { + public static void main(String[] args) { + ThreadGroup tg = Thread.currentThread().getThreadGroup(); + int n = tg.activeCount(); + Thread[] ts = new Thread[n]; + int m = tg.enumerate(ts); + for (int i = 0; i < ts.length; i++) { + if (Thread.currentThread() == ts[i]) { + System.out.println(0); + return; + } + } + throw new RuntimeException("Current thread is not in its own thread group!"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0141-rt-thread-ThreadTest35/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0141-rt-thread-ThreadTest35/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b418216ad2c1ef6aecd534603767f89ebe1c2744 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0141-rt-thread-ThreadTest35/ThreadTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Verify the setName(null) method, and throw NullPointerException. + *- @Brief: see below + * -#step1: 通过new得到Thread的线程对象,通过setName()设置线程名称。输出线程设置的名称。 + * -#step2: 通过new得到Thread的线程对象,通过setName()设置一个空的名称。抛出NullPointerException。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + // Test for setName() + public static void main(String[] args) throws Exception { + Thread thread = new Thread(); + String newName = "maple_thread"; + thread.setName(newName); + System.out.println("set the new name -- " + newName + " ---- " + thread.getName()); + + /** + * Verify the setName(null) method, and throw NullPointerException + */ + Thread t = new Thread(); + try { + t.setName(null); + } catch (NullPointerException e) { + System.out.println("setName() should not accept null names"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan set\s*the\s*new\s*name\s*\-\-\s*maple_thread\s*\-\-\-\-\s*maple_thread\s*setName\(\)\s*should\s*not\s*accept\s*null\s*names \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0142-rt-thread-ThreadTest5/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0142-rt-thread-ThreadTest5/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..43aa6c10008a0798f428d51b9961dc9f4dd174f5 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0142-rt-thread-ThreadTest5/ThreadTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test set/get DefaultUncaughtExceptionHandler and set/get DefaultUncaughtExceptionHandler(null). + *- @Brief: see below + * -#step1: 定义类ExceptionHandler实现Thread.UncaughtExceptionHandler,定义带参的构造方法。 + * -#step2: 通过new得到的类ExceptionHandler对象eh,通过setDefaultUncaughtExceptionHandler()设置类ExceptionHandler对象的处 + * 理程序。通过getDefaultUncaughtExceptionHandler()确认设置成功。 + * -#step3: 通过setDefaultUncaughtExceptionHandler()设置参数为null的处理程序。通过getDefaultUncaughtExceptionHandler() + * 得到Thread.UncaughtExceptionHandler的对象。确认该对象为为null。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +public class ThreadTest { + public static void main(String[] args) throws Exception { + // Test set/get DefaultUncaughtExceptionHandler + ExceptionHandler eh = new ExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler(eh); + Thread.UncaughtExceptionHandler ret1 = Thread.getDefaultUncaughtExceptionHandler(); + + //Test set/get DefaultUncaughtExceptionHandler(null) + Thread.setDefaultUncaughtExceptionHandler(null); + Thread.UncaughtExceptionHandler ret2 = Thread.getDefaultUncaughtExceptionHandler(); + if (ret1 == eh && ret2 == null) + System.out.println(0); + } + + static class ExceptionHandler implements Thread.UncaughtExceptionHandler { + public boolean wasCalled = false; + + public void uncaughtException(Thread t, Throwable e) { + wasCalled = true; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0143-rt-thread-Daemon/Daemon.java b/test/testsuite/ouroboros/thread_test/RT0143-rt-thread-Daemon/Daemon.java new file mode 100755 index 0000000000000000000000000000000000000000..29a1f044e903565d072462c47d3e9b1deb41b3c8 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0143-rt-thread-Daemon/Daemon.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Daemon + *- @TestCaseName: Thread_Daemon.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test for premature destruction of daemon threadgroups + *- @Brief: see below + * -#step1: Create a thread group. + * -#step2: Assign the new thread to thread group + * -#step3: Create a new thread group,its parent thread group is tg. + * -#step4: Change this thread group(tg) to a last backgrounder Thread Group + * -#step5: Destroy the thread group by calling destroy() + * -#step6: Check that child thread group was stop correctly. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: Daemon.java + *- @ExecuteClass: Daemon + *- @ExecuteArgs: + */ + +public class Daemon { + public static void main(String[] args) throws Exception { + ThreadGroup tg = new ThreadGroup("madbot-threads"); + Thread myThread = new MadThread(tg, "mad"); + ThreadGroup aGroup = new ThreadGroup(tg, "ness"); + tg.setDaemon(true); + if (tg.activeCount() != 0) + throw new RuntimeException("activeCount"); + aGroup.destroy(); + if (tg.isDestroyed()) + throw new RuntimeException("destroy"); + try { + Thread anotherThread = new MadThread(aGroup, "bot"); + throw new RuntimeException("illegal"); + } catch (IllegalThreadStateException itse) { + // Correct result + } + System.out.println("Passed"); + } +} + +class MadThread extends Thread { + String name; + + MadThread(ThreadGroup tg, String name) { + super(tg, name); + this.name = name; + } + + public void run() { + System.out.println("me run " + name); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan Passed \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0144-rt-thread-ThreadTest10/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0144-rt-thread-ThreadTest10/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..13acaaf0eecacd045c297d618d00affcb3753f06 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0144-rt-thread-ThreadTest10/ThreadTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test sleep with out interrupt + *- @Brief: see below + * -#step1: Sleep current thread by calling Thread.sleep(). + * -#step2: Check that current thread was slept. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + public static void main(String[] args) throws Exception { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + System.out.println("unexpected InterruptedException while sleeping"); + } + System.out.println("Test sleep(long millis) OK --"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan Test\s*sleep\(long\s*millis\)\s*OK\s*\-\- \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0145-rt-thread-MemoryLeak/MemoryLeak.java b/test/testsuite/ouroboros/thread_test/RT0145-rt-thread-MemoryLeak/MemoryLeak.java new file mode 100755 index 0000000000000000000000000000000000000000..6083a52262fca2719aea349891ce762437a88326 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0145-rt-thread-MemoryLeak/MemoryLeak.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MemoryLeak + *- @TestCaseName: Thread_MemoryLeak.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test to see that memory leak no longer exists. + *- @Brief: see below + * -#step1: Create ThreadLocal instance. + * -#step2: Set the value of the thread local variable for the current thread + * -#step2: Check that memory leak no longer exists. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: MemoryLeak.java + *- @ExecuteClass: MemoryLeak + *- @ExecuteArgs: + */ + +public class MemoryLeak { + public static void main(String[] args) { + + for (int i = 0; i < 1000; i++) { + ThreadLocal t = new ThreadLocal(); + t.set(new Object()); + t.set(null); + } + System.out.println("Passed"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan Passed \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0146-rt-thread-ThreadId/ThreadId.java b/test/testsuite/ouroboros/thread_test/RT0146-rt-thread-ThreadId/ThreadId.java new file mode 100755 index 0000000000000000000000000000000000000000..e8a64d276f6f145b95f709e60c250138b9341d06 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0146-rt-thread-ThreadId/ThreadId.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadId + *- @TestCaseName: Thread_ThreadId.java + *- @RequirementName: Java Thread + *- @Title/Destination: Use ThreadLocal to generate unique id for thread + *- @Brief: see below + * -#step1: Define a test class that to generate unique id for thread. + * -#step2: Atomic integer containing the next thread ID to be assigned. + * -#step3: Override initialValue(). + * -#step4: Check that the current thread's unique ID is correctly. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadId.java + *- @ExecuteClass: ThreadId + *- @ExecuteArgs: + */ + +import java.util.concurrent.atomic.AtomicInteger; + +public class ThreadId { + private static final AtomicInteger nextId = new AtomicInteger(0); + + private static final ThreadLocal threadId = + new ThreadLocal() { + @Override + protected Integer initialValue() { + return nextId.getAndIncrement(); + } + }; + + public static int get() { + return threadId.get(); + } + + public static void main(String[] args) { + System.out.println(get()); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0147-rt-thread-ThreadTest1/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0147-rt-thread-ThreadTest1/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b385e7e20a678d73b83f2bf0fd9f1e798e98ffb0 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0147-rt-thread-ThreadTest1/ThreadTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Interrupt a sleeping thread + *- @Brief: see below + * -#step1: Define a test class inherited from thread. + * -#step2: Create a thread instance. + * -#step3: Sleep the current thread. + * -#step4: Interrupt the sleeping thread. + * -#step5: Check that the sleeping thread was Interrupted. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ + +class MyThread extends Thread { + public void run() { + try { + while (!isInterrupted()) { + Thread.sleep(10000); + } + } catch (Exception e) { + System.out.println("isInterrupted"); + } + } +} + +public class ThreadTest { + public static void main(String[] args) { + Thread t1 = new MyThread(); + t1.start(); + + try { + Thread.sleep(1000); + t1.interrupt(); + } catch (Exception e) { + System.out.println("catch"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan isInterrupted \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0148-rt-thread-ThreadTest37/ThreadTest.java b/test/testsuite/ouroboros/thread_test/RT0148-rt-thread-ThreadTest37/ThreadTest.java new file mode 100755 index 0000000000000000000000000000000000000000..91ae9171df9ecfb2c609c3b7c4941ca498cb1062 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0148-rt-thread-ThreadTest37/ThreadTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadTest + *- @TestCaseName: Thread_ThreadTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test for void sleep(long millis) and sleep(long millis, int nanos) with both valid and + * invalid value + *- @Brief: see below + * case1: + * -#step1: Test void sleep(long millis) with legal or illegal param. + * -#step2: Check that IllegalArgumentException was threw when param is illegal. + * case2: + * -#step1: Test sleep(long millis, int nanos) with legal or illegal param. + * -#step2: Check that IllegalArgumentException was threw when param is illegal. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadTest.java + *- @ExecuteClass: ThreadTest + *- @ExecuteArgs: + */ +public class ThreadTest { + public static void main(String[] args) throws Exception { + long millis = 2000; + + try { + Thread.sleep(millis); + System.out.println("sleep(long millis) OK"); + } catch (IllegalArgumentException e) { + System.out.println("IllegalArgumentException for sleep(long millis) as: millis < 0"); + } + + try { + Thread.sleep(-2); + System.out.println("sleep(long millis) OK"); + } catch (IllegalArgumentException e) { + System.out.println("IllegalArgumentException for sleep(long millis) as: millis < 0"); + } + + int nanos = 123456; + + try { + Thread.sleep(millis, nanos); + System.out.println("sleep(long millis, int nanos) OK"); + } catch (IllegalArgumentException e) { + System.out.println("IllegalArgumentException for sleep(long millis, int nanos) as: millis < 0 or nanos < 0 or nanos > 999999"); + } + + try { + Thread.sleep(millis, -1); + System.out.println("sleep(long millis, int nanos) OK"); + } catch (IllegalArgumentException e) { + System.out.println("IllegalArgumentException for sleep(long millis, int nanos) as: nanos < 0"); + } + + try { + Thread.sleep(millis, 1123456); + System.out.println("sleep(long millis, int nanos) OK"); + } catch (IllegalArgumentException e) { + System.out.println("IllegalArgumentException for sleep(long millis, int nanos) as: nanos > 999999"); + } + + try { + Thread.sleep(-3, nanos); + System.out.println("sleep(long millis, int nanos) OK"); + } catch (IllegalArgumentException e) { + System.out.println("IllegalArgumentException for sleep(long millis, int nanos) as: millis < 0"); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan sleep\(long\s*millis\)\s*OK\s*IllegalArgumentException\s*for\s*sleep\(long\s*millis\)\s*as\:\s*millis\s*\<\s*0\s*sleep\(long\s*millis\,\s*int\s*nanos\)\s*OK\s*IllegalArgumentException\s*for\s*sleep\(long\s*millis\,\s*int\s*nanos\)\s*as\:\s*nanos\s*\<\s*0\s*IllegalArgumentException\s*for\s*sleep\(long\s*millis\,\s*int\s*nanos\)\s*as\:\s*nanos\s*\>\s*999999\s*IllegalArgumentException\s*for\s*sleep\(long\s*millis\,\s*int\s*nanos\)\s*as\:\s*millis\s*\<\s*0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0149-rt-thread-ThreadConstructors13/ThreadConstructors13.java b/test/testsuite/ouroboros/thread_test/RT0149-rt-thread-ThreadConstructors13/ThreadConstructors13.java new file mode 100755 index 0000000000000000000000000000000000000000..6f2b0ca5832b905fc887181dbedc2fc2182ecff5 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0149-rt-thread-ThreadConstructors13/ThreadConstructors13.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors13 + *- @TestCaseName: Thread_ThreadConstructors13.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for Constructors Thread(String name) + *- @Brief: see below + * -#step1: Create thread instances. + * -#step2: Test Constructors Thread(String name) with null and "" params. + * -#step3: Check that Thread(String name) threw NullPointerException when param was null,and when param is "",it will + * be normal. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadConstructors13.java + *- @ExecuteClass: ThreadConstructors13 + *- @ExecuteArgs: + */ + +public class ThreadConstructors13 extends Thread { + static int i = 0; + private static int ecount = 0; + + public ThreadConstructors13(String name) { + super(name); + } + + public static void main(String[] args) { + try { + ThreadConstructors13 test_illegal1 = new ThreadConstructors13(null); + } catch (NullPointerException e) { + ecount++; + } + ThreadConstructors13 test_illegal2 = new ThreadConstructors13(""); + ThreadConstructors13 test_illegal3 = new ThreadConstructors13(""); + + test_illegal2.start(); + try { + test_illegal2.join(); + } catch (InterruptedException e) { + System.out.println("InterruptedException"); + } + + test_illegal3.start(); + try { + test_illegal3.join(); + } catch (InterruptedException e) { + System.out.println("InterruptedException"); + } + + if (i == 2) { + if (ecount == 1) { + System.out.println("0"); + return; + } + } + System.out.println("2"); + return; + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0150-rt-thread-ThreadConstructors14/ThreadConstructors14.java b/test/testsuite/ouroboros/thread_test/RT0150-rt-thread-ThreadConstructors14/ThreadConstructors14.java new file mode 100755 index 0000000000000000000000000000000000000000..7ad0ada9089713d5d3eeb3841c8d5c6acc7b4935 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0150-rt-thread-ThreadConstructors14/ThreadConstructors14.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors14 + *- @TestCaseName: Thread_ThreadConstructors14.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for Constructors Thread(ThreadGroup group, Runnable target) + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Start the thread. + * -#step3: Test Thread(ThreadGroup group, Runnable target) with null params. + * -#step4: Check that no wrong or exception when Thread(ThreadGroup group, Runnable target)'s params are null. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadConstructors14.java + *- @ExecuteClass: ThreadConstructors14 + *- @ExecuteArgs: + */ + +public class ThreadConstructors14 extends Thread { + static int i = 0; + + public ThreadConstructors14(ThreadGroup group, Runnable target) { + super(group, target); + } + + public static void main(String[] args) { + + ThreadConstructors14 test_illegal1 = new ThreadConstructors14(null, null); + + test_illegal1.start(); + try { + test_illegal1.join(); + } catch (InterruptedException e) { + System.out.println("InterruptedException"); + } + + if (i == 1) { + System.out.println("0"); + return; + } + System.out.println("2"); + return; + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0151-rt-thread-ThreadConstructors15/ThreadConstructors15.java b/test/testsuite/ouroboros/thread_test/RT0151-rt-thread-ThreadConstructors15/ThreadConstructors15.java new file mode 100755 index 0000000000000000000000000000000000000000..69eac8ce3c8f9bfdd47894445205c8a7bc132a57 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0151-rt-thread-ThreadConstructors15/ThreadConstructors15.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors15 + *- @TestCaseName: Thread_ThreadConstructors15.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for Constructors Thread(ThreadGroup group, Runnable target, String name) + *- @Brief: see below + * -#step1: Create a thread instance. + * -#step2: Test Thread(ThreadGroup group, Runnable target, String name) with different params. + * -#step3: Check that NullPointerException was threw when the params are null. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadConstructors15.java + *- @ExecuteClass: ThreadConstructors15 + *- @ExecuteArgs: + */ + +public class ThreadConstructors15 extends Thread { + static int i = 0; + static int ecount = 0; + + public ThreadConstructors15(ThreadGroup group, Runnable target, String name) { + super(group, target, name); + } + + public static void main(String[] args) { + try { + ThreadConstructors15 test_illegal1 = new ThreadConstructors15(null, null, null); + } catch (NullPointerException e) { + //System.out.println("NullPointerException"); + ecount++; + } + ThreadConstructors15 test_illegal2 = new ThreadConstructors15(null, null, ""); + ThreadConstructors15 test_illegal3 = new ThreadConstructors15(null, null, ""); + + test_illegal2.start(); + try { + test_illegal2.join(); + } catch (InterruptedException e) { + //System.out.println("NullPointerException"); + } + + test_illegal3.start(); + try { + test_illegal3.join(); + } catch (InterruptedException e) { + //System.out.println("NullPointerException"); + } + + if (i == 2) { + if (ecount == 1) { + System.out.println("0"); + return; + } + } + System.out.println("2"); + return; + } + + public void run() { + i++; + super.run(); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0152-rt-thread-ThreadConstructors16/ThreadConstructors16.java b/test/testsuite/ouroboros/thread_test/RT0152-rt-thread-ThreadConstructors16/ThreadConstructors16.java new file mode 100755 index 0000000000000000000000000000000000000000..635bdda2509e345c892927fad0847dc2e5469695 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0152-rt-thread-ThreadConstructors16/ThreadConstructors16.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors16 + *- @TestCaseName: Thread_ThreadConstructors16.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for Thread(ThreadGroup group, Runnable target, String name, long stackSize) + *- @Brief: see below + * -#step1: Create thread instance. + * -#step2: Test Thread(ThreadGroup group, Runnable target, String name, long stackSize) with different params. + * -#step3: Check that whatever stackSize is any value,there is no exception threw. + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadConstructors16.java + *- @ExecuteClass: ThreadConstructors16 + *- @ExecuteArgs: + */ + +public class ThreadConstructors16 extends Thread { + static int i = 0; + static int ecount = 0; + + public ThreadConstructors16(ThreadGroup group, Runnable target, String name, long stackSize) { + super(group, target, name, stackSize); + } + + public static void main(String[] args) { + try { + ThreadConstructors16 test_illegal1 = new ThreadConstructors16(null, null, null, 0); + } catch (NullPointerException e) { + //System.out.println("NullPointerException"); + ecount++; + } + + try { + ThreadConstructors16 test_illegal2 = new ThreadConstructors16(null, null, "", Long.MAX_VALUE); + } catch (OutOfMemoryError ee) { + System.out.println("OutOfMemoryError"); + ecount += 2; + } + + ThreadConstructors16[] test_illegal = new ThreadConstructors16[3]; + + test_illegal[0] = new ThreadConstructors16(null, null, "", 100); //Long.MIN_VALUE); + test_illegal[1] = new ThreadConstructors16(null, null, "", new Integer("-1")); + test_illegal[2] = new ThreadConstructors16(null, null, "", new Short("00356")); + + for (ThreadConstructors16 thread : test_illegal) { + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + // System.out.println("InterruptedException"); + } + } + + if (i == 3) { + if (ecount == 1) { + System.out.println("0"); + return; + } + } + System.out.println("2"); + return; + } + + public void run() { + i++; + super.run(); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0153-rt-thread-ThreadConstructors17/ThreadConstructors17.java b/test/testsuite/ouroboros/thread_test/RT0153-rt-thread-ThreadConstructors17/ThreadConstructors17.java new file mode 100755 index 0000000000000000000000000000000000000000..defc7ab1cb03d74fcebdddf53c61780ec7e430ec --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0153-rt-thread-ThreadConstructors17/ThreadConstructors17.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors17 + *- @TestCaseName: Thread_ThreadConstructors17.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for Constructors Thread(ThreadGroup group, String name) + *- @Brief: see below + * -#step1: Create thread instance. + * -#step2: Test Constructors Thread(ThreadGroup group, String name) with different params. + * -#step3: Check that NullPointerException was threw when name param was null; + *- @Expect: expected.txt + *- @Priority: High + *- @Source: ThreadConstructors17.java + *- @ExecuteClass: ThreadConstructors17 + *- @ExecuteArgs: + */ + +public class ThreadConstructors17 extends Thread { + static int i = 0; + static int ecount = 0; + + public ThreadConstructors17(ThreadGroup group, String name) { + super(group, name); + } + + public static void main(String[] args) { + try { + ThreadConstructors17 test_illegal1 = new ThreadConstructors17(null, null); + } catch (NullPointerException e) { + //System.out.println("NullPointerException"); + ecount++; + } + + ThreadConstructors17 test_illegal2 = new ThreadConstructors17(null, ""); + ThreadConstructors17 test_illegal3 = new ThreadConstructors17(null, new String()); + + test_illegal2.start(); + try { + test_illegal2.join(); + } catch (InterruptedException e) { + System.out.println("InterruptedException"); + } + + test_illegal3.start(); + try { + test_illegal3.join(); + } catch (InterruptedException e) { + System.out.println("InterruptedException"); + } + + if (i == 2) { + if (ecount == 1) { + System.out.println("0"); + return; + } + } + System.out.println("2"); + return; + } + + public void run() { + i++; + super.run(); + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0154-rt-thread-ThreadEHcountStackFrames/ThreadCountStackFramesTest.java b/test/testsuite/ouroboros/thread_test/RT0154-rt-thread-ThreadEHcountStackFrames/ThreadCountStackFramesTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3c0d186a9ea247868d22606b100593f0abf932f1 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0154-rt-thread-ThreadEHcountStackFrames/ThreadCountStackFramesTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadCountStackFramesTest + *- @TestCaseName: Thread_ThreadCountStackFramesTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Check if countStackFrames throws IllegalThreadStateException when thread not suspended. + *- @Brief: see below + * -#step1: 创建Thread对象实例。 + * -#step2:调用start()启动对象实例。 + * -#step3:调用countStackFrames()确认无异常抛出。 + * -#step4:调用getStackTrace(),获取返回的长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadCountStackFramesTest.java + *- @ExecuteClass: ThreadCountStackFramesTest + *- @ExecuteArgs: + */ + +public class ThreadCountStackFramesTest extends Thread { + static int cnt = 0; + static Object ob = "aa"; + + public static void main(String[] args) { + ThreadCountStackFramesTest thCountStackFramesTest = new ThreadCountStackFramesTest(); + thCountStackFramesTest.start(); + + try { + cnt = thCountStackFramesTest.countStackFrames(); + } catch (IllegalThreadStateException e) { + System.out.println(2); + return; + } + + int j = thCountStackFramesTest.getStackTrace().length; + if (j == cnt) { + System.out.println(0); + return; + } + + System.out.println(2); + } + + public void run() { + synchronized (ob) { + try { + ob.wait(1000); + } catch (InterruptedException e) { + System.out.println("Wait is interrupted"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0155-rt-thread-ThreadEHdestroy/ThreadDestroyUnsupportedOperationExceptionTest.java b/test/testsuite/ouroboros/thread_test/RT0155-rt-thread-ThreadEHdestroy/ThreadDestroyUnsupportedOperationExceptionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d05ebca1c2d734be02f69882a79d29ab9b271ee6 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0155-rt-thread-ThreadEHdestroy/ThreadDestroyUnsupportedOperationExceptionTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadDestroyUnsupportedOperationExceptionTest + *- @TestCaseName: Thread_ThreadDestroyUnsupportedOperationExceptionTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Check if destroy() throws UnsupportedOperationException. + *- @Brief: see below + * -#step1: 创建Thread对象实例。 + * -#step2:调用start()启动对象实例。 + * -#step3: 调用destroy()方法。 + * -#step4:确认抛出UnsupportedOperationException。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadDestroyUnsupportedOperationExceptionTest.java + *- @ExecuteClass: ThreadDestroyUnsupportedOperationExceptionTest + *- @ExecuteArgs: + */ + +public class ThreadDestroyUnsupportedOperationExceptionTest extends Thread { + public static void main(String[] args) { + ThreadDestroyUnsupportedOperationExceptionTest thread = new ThreadDestroyUnsupportedOperationExceptionTest(); + thread.start(); + + try { + thread.destroy(); + } catch (UnsupportedOperationException e) { + System.out.println(0); + return; + } catch (Throwable ee) { + System.out.println(1); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0156-rt-thread-Threadenumerate2/Threadenumerate2.java b/test/testsuite/ouroboros/thread_test/RT0156-rt-thread-Threadenumerate2/Threadenumerate2.java new file mode 100755 index 0000000000000000000000000000000000000000..45a14c2bff02bba48ddfc1e9f9013ecfb2cc02dc --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0156-rt-thread-Threadenumerate2/Threadenumerate2.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: Threadenumerate2 + *- @TestCaseName: Thread_Threadenumerate2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for static int enumerate(Thread[] tarray). + *- @Brief: see below + * -#step1: 创建Thread对象实例。 + * -#step2:调用start()启动对象实例。 + * -#step3: 构造参数tarray为null,调用enumerate(Thread[] tarray)。 + * -#step4:确认NullPointerException抛出。 + * -#step5: 构造参数tarray为new Thread[0],调用enumerate(Thread[] tarray)。 + * -#step6:确认返回为0。 + *- @Expect: expected.txt + *- @Priority: High + *- @Source: Threadenumerate2.java + *- @ExecuteClass: Threadenumerate2 + *- @ExecuteArgs: + */ + +public class Threadenumerate2 extends Thread { + static int num = 0; + static int eCount = 0; + + public static void main(String[] args) { + Threadenumerate2 te = new Threadenumerate2(); + te.start(); + + try { + enumerate(null); + } catch (NullPointerException e) { + eCount++; + } + + num = enumerate(new Thread[0]); + if (num == 0 && eCount == 1) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0 \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0158-rt-thread-ThreadgetStackTrace/ThreadGetStackTraceTest.java_bak b/test/testsuite/ouroboros/thread_test/RT0158-rt-thread-ThreadgetStackTrace/ThreadGetStackTraceTest.java_bak new file mode 100755 index 0000000000000000000000000000000000000000..1bcd2b77dd29b459ad4bf07603f8969ba8428127 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0158-rt-thread-ThreadgetStackTrace/ThreadGetStackTraceTest.java_bak @@ -0,0 +1,41 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetStackTraceTest + *- @TestCaseName: Thread_ThreadGetStackTraceTest.java_bak + *- @RequirementName: Java Thread + *- @Title/Destination: Test getStackTrace(). + *- @Brief: see below + * -#step1: 调用Thread.currentThread()获取Thread 实例。 + * -#step2:调用getStackTrace()获取对应的StackTraceElement数组。 + * -#step3:确认获取的StackTraceElement数组成员内容正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Remark: + *- @Source: ThreadGetStackTraceTest.java + *- @ExecuteClass: ThreadGetStackTraceTest + *- @ExecuteArgs: + */ + +public class ThreadGetStackTraceTest extends Thread { + public static void main(String[] args) { + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + int l = stackTraceElements.length; + if (stackTraceElements[l - 1].toString().contains("main") && stackTraceElements[l - 2].toString().contains("run") + && stackTraceElements[l - 3].toString().contains("ThreadGetStackTraceTest")) { + System.out.println(0); + return; + } + System.out.println(2); + } +} diff --git a/test/testsuite/ouroboros/thread_test/RT0158-rt-thread-ThreadgetStackTrace/ThreadgetStackTrace.java b/test/testsuite/ouroboros/thread_test/RT0158-rt-thread-ThreadgetStackTrace/ThreadgetStackTrace.java new file mode 100755 index 0000000000000000000000000000000000000000..9adc6c4837135654fe6242d09e8a1026c42da33e --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0158-rt-thread-ThreadgetStackTrace/ThreadgetStackTrace.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetStackTraceTest + *- @TestCaseName: Thread_ThreadgetStackTrace.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test getStackTrace(). + *- @Brief: see below + * -#step1: 调用Thread.currentThread()获取Thread 实例。 + * -#step2:调用getStackTrace()获取对应的StackTraceElement数组。 + * -#step3:确认获取的StackTraceElement数组成员内容正确。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadgetStackTrace.java + *- @ExecuteClass: ThreadgetStackTrace + *- @ExecuteArgs: + */ + + +import java.io.PrintStream; + +public class ThreadgetStackTrace extends Thread { + + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + public static int run(String[] args, PrintStream out) { + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + + int l = stackTraceElements.length; + if (stackTraceElements[l - 1].toString().contains("main") && stackTraceElements[l - 2].toString().contains("run") && stackTraceElements[l - 3].toString().contains("getStackTrace")) { + return 0; + } + + return 2; + } +} + +// DEPENDENCE: ThreadGetStackTraceTest.java_bak +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0159-rt-thread-ThreadGroupallowThreadSuspension/ThreadGroupAllowThreadSuspensionTest.java b/test/testsuite/ouroboros/thread_test/RT0159-rt-thread-ThreadGroupallowThreadSuspension/ThreadGroupAllowThreadSuspensionTest.java new file mode 100755 index 0000000000000000000000000000000000000000..0294a3be19409a9b45b75499eee75dcb08cfc43b --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0159-rt-thread-ThreadGroupallowThreadSuspension/ThreadGroupAllowThreadSuspensionTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupAllowThreadSuspensionTest + *- @TestCaseName: Thread_ThreadGroupAllowThreadSuspensionTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test ThreadGroup.allowSuspension(), it changes the value of vmAllowSuspension. + *- @Brief: see below + * -#step1: 通过new ThreadGroup(String name)构造新的实例。 + * -#step2:调用allowThreadSuspension(boolean b),参数b为true。 + * -#step3:通过反射getDeclaredField获取私有域vmAllowSuspension判断值不为true。 + * -#step4:调用allowThreadSuspension(boolean b),参数b为false。 + * -#step5:通过反射getDeclaredField获取私有域vmAllowSuspension判断值不为false。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadGroupAllowThreadSuspensionTest.java + *- @ExecuteClass: ThreadGroupAllowThreadSuspensionTest + *- @ExecuteArgs: + */ + +import java.lang.reflect.Field; + +public class ThreadGroupAllowThreadSuspensionTest { + public static void main(String[] args) { + ThreadGroup tg = new ThreadGroup("group"); + tg.allowThreadSuspension(true); + try { + if (getValue(tg, "vmAllowSuspension").toString() != "true") { + System.out.println(2); + return; + } + } catch (Throwable e) { + System.out.println(2); + return; + } + + tg.allowThreadSuspension(false); + try { + if (getValue(tg, "vmAllowSuspension").toString() != "false") { + System.out.println(2); + return; + } + } catch (Throwable e) { + System.out.println(2); + return; + } + System.out.println(0); + } + + // Use reflect to get the value of private field of ThreadGroup + public static Object getValue(Object instance, String fieldName) throws IllegalAccessException, NoSuchFieldException { + Field field = getField(instance.getClass(), fieldName); + field.setAccessible(true); + return field.get(instance); + } + + public static Field getField(Class thisClass, String fieldName) throws NoSuchFieldException { + if (fieldName == null) { + throw new NoSuchFieldException("Error field !"); + } + Field field = thisClass.getDeclaredField(fieldName); + return field; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0160-rt-thread-ThreadGroupEHdestroy/ThreadGroupEHdestroy.java b/test/testsuite/ouroboros/thread_test/RT0160-rt-thread-ThreadGroupEHdestroy/ThreadGroupEHdestroy.java new file mode 100755 index 0000000000000000000000000000000000000000..583130bf154e15328b40bbcf7c3228c9b7912b36 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0160-rt-thread-ThreadGroupEHdestroy/ThreadGroupEHdestroy.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGroupEHdestroy + *- @TestCaseName: Thread_ThreadGroupEHdestroy.java + *- @RequirementName: Java Thread + *- @Title/Destination: Check if destroy throws IllegalThreadStateException. + *- @Brief: see below + * -#step1: 通过new ThreadGroup(String name)构造新的实例tg。 + * -#step2: 通过Thread(ThreadGroup group, String name)分配新的thread对象。 + * -#step3:调用start()启动线程。 + * -#step4:对ThreadGroup对象tg调用destroy(),预计会抛出IllegalThreadStateException。 + * -#step5:调用join()等待线程运行结束。 + * -#step6:对ThreadGroup对象tg调用destroy(),预计会抛出IllegalThreadStateException。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadGroupEHdestroy.java + *- @ExecuteClass: ThreadGroupEHdestroy + *- @ExecuteArgs: + */ + +public class ThreadGroupEHdestroy { + static int cnt = 0; + + public static void main(String[] args) { + ThreadGroup tg = new ThreadGroup("hi"); + Thread t = new Thread(tg, "hello"); + t.start(); + // Destroy a thread group which is not empty, throws IllegalThreadStateException + try { + tg.destroy(); + } catch (IllegalThreadStateException e) { + cnt++; + } + try { + t.join(); + } catch (InterruptedException ee) { + System.out.println("Join is interrupted"); + } + + tg.destroy(); + // Destroy a thread group which is already destroyed, throws IllegalThreadStateException + try { + tg.destroy(); + } catch (IllegalThreadStateException e) { + cnt += 2; + } + + if (cnt == 3) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0161-rt-thread-ThreadholdsLock4/ThreadholdsLock4.java b/test/testsuite/ouroboros/thread_test/RT0161-rt-thread-ThreadholdsLock4/ThreadholdsLock4.java new file mode 100755 index 0000000000000000000000000000000000000000..6ae1d6e09626313918b11dfb3413c2296a3f502b --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0161-rt-thread-ThreadholdsLock4/ThreadholdsLock4.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadholdsLock4 + *- @TestCaseName: Thread_ThreadholdsLock4.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for boolean holdsLock(Object obj). + *- @Brief: see below + * -#step1: 构造Thread实例。 + * -#step2:调用holdsLock(Object obj), 参数obj为null。 + * -#step3:确认抛出NullPointerException。 + * -#step4: 重复两次调用holdsLock(Object obj), 参数obj为"", 预期每次结果都返回false。 + * -#step5: 调用holdsLock(Object obj), 参数obj为new Object(), 预期结果返回false。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadholdsLock4.java + *- @ExecuteClass: ThreadholdsLock4 + *- @ExecuteArgs: + */ + +public class ThreadholdsLock4 extends Thread { + static int eCount = 0; + static int sCount = 0; + + public static void main(String[] args) { + ThreadholdsLock4 tl = new ThreadholdsLock4(); + try { + holdsLock(null); + } catch (NullPointerException e) { + eCount++; + } + + if (!holdsLock("")) { + if (!holdsLock("")) { + if (!holdsLock(new Object())) { + sCount++; + } + } + } + + if (sCount == 1 && eCount == 1) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0162-rt-thread-ThreadLocalEHwithInitial/ThreadLocalEHwithInitial.java b/test/testsuite/ouroboros/thread_test/RT0162-rt-thread-ThreadLocalEHwithInitial/ThreadLocalEHwithInitial.java new file mode 100755 index 0000000000000000000000000000000000000000..00a2fb779e09207464beb3f56b58e3d855128a47 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0162-rt-thread-ThreadLocalEHwithInitial/ThreadLocalEHwithInitial.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadLocalEHwithInitial + *- @TestCaseName: Thread_ThreadLocalEHwithInitial.java + *- @RequirementName: Java Thread + *- @Title/Destination: Check if ThreadLocal.withInitial(Supplier supplier) throws NullPointerException. + *- @Brief: see below + * -#step1: 创建参数supplier为null。 + * -#step2:调用withInitial(Supplier supplier)。 + * -#step3:确认会抛出NullPointerException异常。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadLocalEHwithInitial.java + *- @ExecuteClass: ThreadLocalEHwithInitial + *- @ExecuteArgs: + */ + +public class ThreadLocalEHwithInitial { + public static void main(String[] args) { + try { + ThreadLocal threadLocal = ThreadLocal.withInitial(null); + } catch (NullPointerException e) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0163-rt-thread-ThreadsetContextClassLoader1/ThreadsetContextClassLoader1.java b/test/testsuite/ouroboros/thread_test/RT0163-rt-thread-ThreadsetContextClassLoader1/ThreadsetContextClassLoader1.java new file mode 100755 index 0000000000000000000000000000000000000000..c740bb8c4c05bf6cdfd92bf629fc0a6390802cc4 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0163-rt-thread-ThreadsetContextClassLoader1/ThreadsetContextClassLoader1.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadsetContextClassLoader1 + *- @TestCaseName: Thread_ThreadsetContextClassLoader1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for setContextClassLoader(ClassLoader cl). + *- @Brief: see below + * -#step1: 创建Thread实例。 + * -#step2:调用setContextClassLoader(ClassLoader cl),参数cl为null。 + * -#step3:调用start()启动线程,等待线程结束。 + * -#step4:确认线程的run函数被正常调用。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadsetContextClassLoader1.java + *- @ExecuteClass: ThreadsetContextClassLoader1 + *- @ExecuteArgs: + */ + +public class ThreadsetContextClassLoader1 extends Thread { + static int i = 0; + + public static void main(String[] args) { + ThreadsetContextClassLoader1 t = new ThreadsetContextClassLoader1(); + t.setContextClassLoader(null); + + t.start(); + try { + t.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + + if (i == 1 && t.getContextClassLoader() == null) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0164-rt-thread-ThreadsetDefaultUncaughtExceptionHandler2/ThreadSetDefaultUncaughtExceptionHandlerTest.java b/test/testsuite/ouroboros/thread_test/RT0164-rt-thread-ThreadsetDefaultUncaughtExceptionHandler2/ThreadSetDefaultUncaughtExceptionHandlerTest.java new file mode 100755 index 0000000000000000000000000000000000000000..26b8b56240bc430967beb1e17e614ef9289ec4b2 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0164-rt-thread-ThreadsetDefaultUncaughtExceptionHandler2/ThreadSetDefaultUncaughtExceptionHandlerTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetDefaultUncaughtExceptionHandlerTest + *- @TestCaseName: Thread_ThreadSetDefaultUncaughtExceptionHandlerTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test negative input for setDefaultUncaughtExceptionHandler(). + *- @Brief: see below + * -#step1: 创建Thread对象实例。 + * -#step2:构造参数eh为实例的getUncaughtExceptionHandler(),调用 + * setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)。 + * -#step3:调用getDefaultUncaughtExceptionHandler()确认返回不为null。 + * -#step4:构造参数eh为实例的null,调用setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)。 + * -#step3:调用getDefaultUncaughtExceptionHandler()确认返回为null。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadSetDefaultUncaughtExceptionHandlerTest.java + *- @ExecuteClass: ThreadSetDefaultUncaughtExceptionHandlerTest + *- @ExecuteArgs: + */ + +public class ThreadSetDefaultUncaughtExceptionHandlerTest extends Thread { + public static void main(String[] args) { + ThreadSetDefaultUncaughtExceptionHandlerTest setEH = new ThreadSetDefaultUncaughtExceptionHandlerTest(); + Thread.setDefaultUncaughtExceptionHandler(setEH.getUncaughtExceptionHandler()); + if (getDefaultUncaughtExceptionHandler() == null) { + System.out.println(1); + return; + } + + Thread.setDefaultUncaughtExceptionHandler(null); + if (getDefaultUncaughtExceptionHandler() == null) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0165-rt-thread-ThreadsetUncaughtExceptionHandler2/ThreadSetUncaughtExceptionHandlerTest.java b/test/testsuite/ouroboros/thread_test/RT0165-rt-thread-ThreadsetUncaughtExceptionHandler2/ThreadSetUncaughtExceptionHandlerTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8f93b989b4b0ca4c4fc82555743c92fb64711cbd --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0165-rt-thread-ThreadsetUncaughtExceptionHandler2/ThreadSetUncaughtExceptionHandlerTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetUncaughtExceptionHandlerTest + *- @TestCaseName: Thread_ThreadSetUncaughtExceptionHandlerTest.java + *- @RequirementName: Java Thread + *- @Title/Destination:test negative input for setUncaughtExceptionHandler() + *- @Brief: see below + * -#step1: 创建Thread对象实例。 + * -#step2: 实例调用getUncaughtExceptionHandler()确认返回不为null。 + * -#step3:构造参数eh为实例的null,调用setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)。 + * -#step4: 启动线程,实例调用getUncaughtExceptionHandler()确认返回不为null。 + * -#step5:等待线程结束,实例调用getUncaughtExceptionHandler()确认返回不为null,run函数被成功调用。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadSetUncaughtExceptionHandlerTest.java + *- @ExecuteClass: ThreadSetUncaughtExceptionHandlerTest + *- @ExecuteArgs: + */ + +public class ThreadSetUncaughtExceptionHandlerTest extends Thread { + static int i = 0; + + public static void main(String[] args) { + ThreadSetUncaughtExceptionHandlerTest setEH = new ThreadSetUncaughtExceptionHandlerTest(); + if (setEH.getUncaughtExceptionHandler() == null) { + System.out.println(1); + return; + } + setEH.setUncaughtExceptionHandler(null); + setEH.start(); + if (setEH.getUncaughtExceptionHandler() == null) { + System.out.println(2); + return; + } + try { + setEH.join(); + } catch (InterruptedException e1) { + System.out.println("Join is interrupted"); + } + + if (i == 1 && setEH.getUncaughtExceptionHandler() != null) { + System.out.println(0); + return; + } + System.out.println(3); + } + + public void run() { + i++; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0166-rt-thread-ThreadStatejoin16/ThreadStatejoin16.java b/test/testsuite/ouroboros/thread_test/RT0166-rt-thread-ThreadStatejoin16/ThreadStatejoin16.java new file mode 100755 index 0000000000000000000000000000000000000000..527641a6816c9b293854f0c79c473e94145ed290 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0166-rt-thread-ThreadStatejoin16/ThreadStatejoin16.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStatejoin16 + *- @TestCaseName: Thread_ThreadStatejoin16.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for join(long millis) + *- @Brief: see below + * -#step1: 调用Thread()来构造对象实例。 + * -#step2:调用start()启动线程。 + * -#step3:构造参数millis为负数,调用join(long millis)等待线程结束,确认抛出IllegalArgumentException异常。 + * -#step4:构造参数millis为0,调用join(long millis)等待线程结束,确认线程能正常运行。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStatejoin16.java + *- @ExecuteClass: ThreadStatejoin16 + *- @ExecuteArgs: + */ + +public class ThreadStatejoin16 extends Thread { + static int i = 0; + static int eCount = 0; + + public static void main(String[] args) { + ThreadStatejoin16 tj = new ThreadStatejoin16(); + tj.start(); + + try { + tj.join(-2); + } catch (InterruptedException e) { + System.out.println(e); + } catch (IllegalArgumentException ee) { + eCount++; + } + + try { + tj.join(0); + } catch (InterruptedException e) { + System.out.println(e); + } catch (IllegalArgumentException ee) { + eCount = eCount + 2; + } + + if (i == 1 && eCount == 1) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0167-rt-thread-ThreadStatejoin17/ThreadStatejoin17.java b/test/testsuite/ouroboros/thread_test/RT0167-rt-thread-ThreadStatejoin17/ThreadStatejoin17.java new file mode 100755 index 0000000000000000000000000000000000000000..5544d965d9b4baa54fc1576fa62959cb65697c4d --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0167-rt-thread-ThreadStatejoin17/ThreadStatejoin17.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStatejoin17 + *- @TestCaseName: Thread_ThreadStatejoin17.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for join(long millis, int nanos). + *- @Brief: see below + * -#step1: 调用Thread()来构造对象实例。 + * -#step2:调用start()启动线程。 + * -#step3:构造参数millis为负数,nanos为正整数,调用join(long millis, int nanos)等待线程结束,确认抛出 + * IllegalArgumentException异常。 + * -#step4:构造参数millis为正整数,nanos为负数,调用join(long millis, int nanos)等待线程结束,确认抛出 + * IllegalArgumentException异常。 + * -#step5:构造参数millis为0,nanos为0,调用join(long millis, int nanos)等待线程结束,确认线程能正常运行。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStatejoin17.java + *- @ExecuteClass: ThreadStatejoin17 + *- @ExecuteArgs: + */ + +public class ThreadStatejoin17 extends Thread { + static int i = 0; + static int eCount = 0; + + public static void main(String[] args) { + ThreadStatejoin17 tj = new ThreadStatejoin17(); + tj.start(); + + long[] invalidMillis = new long[]{-2l, 2l}; + int[] invalidNanos = new int[]{2, -2}; + + for (int j = 0; j < invalidMillis.length; j++) { + try { + tj.join(invalidMillis[j], invalidNanos[j]); + } catch (InterruptedException e) { + System.out.println(e); + } catch (IllegalArgumentException ee) { + eCount++; + } + } + + try { + tj.join(0, 0); + } catch (InterruptedException e) { + System.out.println(e); + } catch (IllegalArgumentException ee) { + eCount = eCount + 10; + } + + if (i == 1 && eCount == invalidMillis.length) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0168-rt-thread-ThreadStatesleep7/ThreadStatesleep7.java b/test/testsuite/ouroboros/thread_test/RT0168-rt-thread-ThreadStatesleep7/ThreadStatesleep7.java new file mode 100755 index 0000000000000000000000000000000000000000..48f77ef0290888edb7629d80c7338699adb5ed6f --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0168-rt-thread-ThreadStatesleep7/ThreadStatesleep7.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStatesleep7 + *- @TestCaseName: Thread_ThreadStatesleep7.java + *- @RequirementName: Java Thread + *- @Title/Destination: Sleep 0 millisecond time or 0 nanos, no exception threw. + *- @Brief: see below + * -#step1: 调用Thread()来构造对象实例。 + * -#step2:调用start()启动线程。 + * -#step3:构造参数millis为0,调用sleep(long millis),确认线程能正常运行,无异常抛出。 + * -#step4:构造参数millis为0,nanos为0,调用sleep(long millis, int nanos),确认确认线程能正常运行,无异常抛出。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStatesleep7.java + *- @ExecuteClass: ThreadStatesleep7 + *- @ExecuteArgs: + */ + +public class ThreadStatesleep7 extends Thread { + public static void main(String[] args) { + ThreadStatesleep7 cls = new ThreadStatesleep7(); + cls.start(); + try { + sleep(0); + sleep(0, 0); + } catch (InterruptedException e) { + System.out.println("sleep is interrupted"); + } catch (IllegalArgumentException e1) { + System.out.println(2); + return; + } + System.out.println(0); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0169-rt-thread-ThreadStatewait9/ThreadStatewait9.java b/test/testsuite/ouroboros/thread_test/RT0169-rt-thread-ThreadStatewait9/ThreadStatewait9.java new file mode 100755 index 0000000000000000000000000000000000000000..7042fe3e099415b83019194025dd14c39a830ac9 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0169-rt-thread-ThreadStatewait9/ThreadStatewait9.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStatewait9 + *- @TestCaseName: Thread_ThreadStatewait9.java + *- @RequirementName: Java Thread + *- @Title/Destination: Invalid input for Object.wait(long timeout). + *- @Brief: see below + * -#step1: 调用Thread()来构造对象实例。 + * -#step2:调用start()启动线程。 + * -#step3: 构造参数timeout为负数,调用wait(long timeout),确认会抛出IllegalArgumentException异常。 + * -#step4:等待线程结束。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStatewait9.java + *- @ExecuteClass: ThreadStatewait9 + *- @ExecuteArgs: + */ + +public class ThreadStatewait9 extends Thread { + static Object ob = "aa"; + static int i = 0; + + public static void main(String[] args) { + ThreadStatewait9 threadWait = new ThreadStatewait9(); + threadWait.start(); + try { + threadWait.join(); + } catch (InterruptedException ee) { + System.out.println(2); + return; + } + + if (i == 1) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (ob) { + try { + ob.wait(-1000); + } catch (IllegalArgumentException ee) { + i++; + } catch (InterruptedException e) { + System.out.println("Wait is interrupted"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0170-rt-thread-ThreadStatewait10/ThreadStatewait10.java b/test/testsuite/ouroboros/thread_test/RT0170-rt-thread-ThreadStatewait10/ThreadStatewait10.java new file mode 100755 index 0000000000000000000000000000000000000000..5744b8f79dc9c97b2160f1fdfbe704aeb568991c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0170-rt-thread-ThreadStatewait10/ThreadStatewait10.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStatewait10 + *- @TestCaseName: Thread_ThreadStatewait10.java + *- @RequirementName: Java Thread + *- @Title/Destination: Invalid input for Object.wait(long timeout, int nanos). + *- @Brief: see below + * -#step1: 调用Thread()来构造对象实例。 + * -#step2:调用start()启动线程。 + * -#step3: 构造参数timeout为正整数,参数nanos为负数,调用wait(long timeout, int nanos),确认会抛出 + * IllegalArgumentException. + * -#step4:等待线程结束。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStatewait10.java + *- @ExecuteClass: ThreadStatewait10 + *- @ExecuteArgs: + */ + +public class ThreadStatewait10 extends Thread { + static Object ob = "aa"; + static int i = 0; + + public static void main(String[] args) { + ThreadStatewait10 threadWait = new ThreadStatewait10(); + threadWait.start(); + try { + threadWait.join(); + } catch (InterruptedException ee) { + System.out.println(2); + return; + } + + if (i == 1) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + synchronized (ob) { + try { + ob.wait(100, -1000); + } catch (IllegalArgumentException ee) { + i++; + } catch (InterruptedException e) { + System.out.println("Wait is interrupted"); + } + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0171-rt-thread-ThreadStatewait11/ThreadStatewait11.java b/test/testsuite/ouroboros/thread_test/RT0171-rt-thread-ThreadStatewait11/ThreadStatewait11.java new file mode 100755 index 0000000000000000000000000000000000000000..e974cc3c8a2978060b72700fbe3eb8642b5a9216 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0171-rt-thread-ThreadStatewait11/ThreadStatewait11.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStatewait11 + *- @TestCaseName: Thread_ThreadStatewait11.java + *- @RequirementName: Java Thread + *- @Title/Destination: Invalid input for Object.wait(long timeout). + *- @Brief: see below + * -#step1: 调用ThreadStatewait11()来构造对象实例。 + * -#step2:调用start()启动线程。 + * -#step3: 构造参数timeout为0,调用wait(long timeout),确认会抛出IllegalMonitorStateException. + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStatewait11.java + *- @ExecuteClass: ThreadStatewait11 + *- @ExecuteArgs: + */ + +public class ThreadStatewait11 extends Thread { + public static void main(String[] args) { + ThreadStatewait11 threadWait = new ThreadStatewait11(); + threadWait.start(); + try { + threadWait.wait(0); + } catch (InterruptedException e) { + System.out.println(2); + return; + } catch (IllegalMonitorStateException e1) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0172-rt-thread-ThreadStatewait12/ThreadStatewait12.java b/test/testsuite/ouroboros/thread_test/RT0172-rt-thread-ThreadStatewait12/ThreadStatewait12.java new file mode 100755 index 0000000000000000000000000000000000000000..577619616e422f890680bd6d91a2ed1c5ebff2cd --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0172-rt-thread-ThreadStatewait12/ThreadStatewait12.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStatewait12 + *- @TestCaseName: Thread_ThreadStatewait12.java + *- @RequirementName: Java Thread + *- @Title/Destination: Invalid input for Object.wait(long timeout, int nanos). + *- @Brief: see below + * -#step1: 调用ThreadStatewait12()来构造对象实例。 + * -#step2:调用start()启动线程。 + * -#step3: 构造参数timeout为0,nanos为0,调用wait(long timeout, int nanos),确认会抛出IllegalMonitorStateException. + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStatewait12.java + *- @ExecuteClass: ThreadStatewait12 + *- @ExecuteArgs: + */ + +public class ThreadStatewait12 extends Thread { + public static void main(String[] args) { + ThreadStatewait12 threadWait = new ThreadStatewait12(); + threadWait.start(); + try { + threadWait.wait(0, 0); + } catch (InterruptedException e) { + System.out.println(2); + return; + } catch (IllegalMonitorStateException e1) { + System.out.println(0); + return; + } + System.out.println(2); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0173-rt-thread-ThreadConstructors11/ThreadConstructors11.java b/test/testsuite/ouroboros/thread_test/RT0173-rt-thread-ThreadConstructors11/ThreadConstructors11.java new file mode 100755 index 0000000000000000000000000000000000000000..af54efa7e92142d7b71fc5b79b5fd7fab61cc601 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0173-rt-thread-ThreadConstructors11/ThreadConstructors11.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors11 + *- @TestCaseName: Thread_ThreadConstructors11.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for Constructors Thread(Runnable target). + *- @Brief: see below + * -#step1: 构造参数target为null,调用Thread(Runnable target)来构造对象实例。 + * -#step2:调用start()启动线程。 + * -#step3:等待线程结束,确认线程能正常运行。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors11.java + *- @ExecuteClass: ThreadConstructors11 + *- @ExecuteArgs: + */ + +public class ThreadConstructors11 extends Thread { + static int i = 0; + + public ThreadConstructors11(Runnable target) { + super(target); + } + + public static void main(String[] args) { + ThreadConstructors11 test_illegal1 = new ThreadConstructors11(null); + + test_illegal1.start(); + try { + test_illegal1.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + + if (i == 1) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + i++; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0174-rt-thread-ThreadConstructors12/ThreadConstructors12.java b/test/testsuite/ouroboros/thread_test/RT0174-rt-thread-ThreadConstructors12/ThreadConstructors12.java new file mode 100755 index 0000000000000000000000000000000000000000..f634f69d0bc46fa5201c56e608301a2856520cbf --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0174-rt-thread-ThreadConstructors12/ThreadConstructors12.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadConstructors12 + *- @TestCaseName: Thread_ThreadConstructors12.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for Constructors Thread(Runnable target, String name). + *- @Brief: see below + * -#step1: 构造参数target为null,name为null,调用Thread(Runnable target, String name)来构造对象实例。 + * -#step2: 确认会抛出NullPointerException异常。 + * -#step3:构造参数target为null,name为"",调用Thread(Runnable target, String name)来构造对象实例test_illegal2。 + * -#step4: 构造参数target为null,name为new String(),调用Thread(Runnable target, String name)来构造对象实例 + * test_illegal3. + * -#step2:调用start()启动线程test_illegal2,test_illegal3。 + * -#step3:等待线程结束,确认两个线程都能正常运行。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadConstructors12.java + *- @ExecuteClass: ThreadConstructors12 + *- @ExecuteArgs: + */ + +public class ThreadConstructors12 extends Thread { + static int i = 0; + static int eCount = 0; + + public ThreadConstructors12(Runnable target, String name) { + super(target, name); + } + + public static void main(String[] args) { + try { + ThreadConstructors12 test_illegal1 = new ThreadConstructors12(null, null); + } catch (NullPointerException e) { + eCount++; + } + + ThreadConstructors12 test_illegal2 = new ThreadConstructors12(null, ""); + ThreadConstructors12 test_illegal3 = new ThreadConstructors12(null, new String()); + + test_illegal2.start(); + try { + test_illegal2.join(); + } catch (InterruptedException e) { + System.out.println("test_illegal2 join is interrupted"); + } + + test_illegal3.start(); + try { + test_illegal3.join(); + } catch (InterruptedException e) { + System.out.println("test_illegal3 join is interrupted"); + } + + if (i == 2 && eCount == 1) { + System.out.println(0); + return; + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0175-rt-thread-MonitorTestCase1/MonitorTestCase1.java b/test/testsuite/ouroboros/thread_test/RT0175-rt-thread-MonitorTestCase1/MonitorTestCase1.java new file mode 100755 index 0000000000000000000000000000000000000000..f44d21c2479abfa2e699937e316f41f361d9aa65 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0175-rt-thread-MonitorTestCase1/MonitorTestCase1.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MonitorTestCase1.java + *- @TestCaseName: Thread_MonitorTestCase1.java + *- @RequirementName: Java Thread + *- @Title/Destination: Added according to stress cases SyscompTestCase/Maple_harness/tools/testapp_MemStressTest/src + * /com/huawei/stress. + *- @Brief: see below + * -#step1: 创建一个static的类StopAbleThread继承Thread,类的构造方法使用了父函数的构造方法。 + * -#step2: 分配INIT_DEFAULT_THREAD_NUM / 2个对象来自于new StopAbleThread类,同时启动监控线程。 + * -#step3: 调用start()启动所有的对象线程。 + * -#step4: 调用join()等待线程运行结束。 + * -#step5: 调用Runtime.getRuntime().gc()回收资源。 + * -#step6: 重复步骤1~4。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: MonitorTestCase1.java + *- @ExecuteClass: MonitorTestCase1 + *- @ExecuteArgs: + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class MonitorTestCase1 { + private static final int INIT_DEFAULT_THREAD_NUM = 100; + private static int DEFAULT_THREAD_NUM_HALF = INIT_DEFAULT_THREAD_NUM / 2; + private static final int THREAD_SLEEP_TIME_DEFAULT = 1; + private static final String MODULE_NAME_MONITOR = "M"; + private static final int THREAD_REPEATS_INFINITE = -1; + private static final int THREAD_REPEATS_DEFAULT = 1; + private static boolean mRunning = true; + private static boolean mRest = false; + private static int mRestTime = 5000; + static List mAllThread = new ArrayList<>(); + + public static void main(String[] args) { + testCase1(); + Runtime.getRuntime().gc(); + testCase1(); + System.out.println(0); + } + + public static void testCase1() { + ArrayList list = new ArrayList<>(); + Thread thread; + Object lockObject = new Object(); + for (int i = 0; i < DEFAULT_THREAD_NUM_HALF; i++) { + thread = new StopAbleThread(new MonitorTest(lockObject, THREAD_SLEEP_TIME_DEFAULT, THREAD_REPEATS_DEFAULT), + MODULE_NAME_MONITOR + "_testCase1_" + i); + list.add(thread); + } + startAllThread(list); + waitAllThreadFinish(list); + } + + public static void waitAllThreadFinish(List list) { + for (Thread s : list) { + try { + s.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + removeDeadThread(s); + } + } + } + + public static void removeDeadThread(Thread t) { + if (t == null) { + return; + } + if (!t.isAlive()) { + synchronized (mAllThread) { + mAllThread.remove(t); + } + } + } + + public static void startAllThread(List list) { + for (Thread s : list) { + s.start(); + trySleep(new Random().nextInt(2)); + } + } + + public static void trySleep(long time) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + static class MonitorTest implements Runnable { + Object lockObject; + int sleepTime; + int repeats; + + public MonitorTest(Object lockObject, int sleepTime, int repeatTimes) { + this.lockObject = lockObject; + this.sleepTime = sleepTime; + repeats = repeatTimes; + } + + @Override + public void run() { + while (THREAD_REPEATS_INFINITE == repeats || repeats > 0) { + if (repeats > 0) { + repeats--; + } + synchronized (lockObject) { + lockObject.toString(); + tryRest(); + trySleep(sleepTime); + if (!mRunning) { + break; + } + } + } + } + } + + private static boolean tryRest() { + if (mRest) { + trySleep(mRestTime); + return true; + } + return false; + } + + static class StopAbleThread extends Thread { + public StopAbleThread(Runnable r, String name) { + super(r, name); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0176-rt-thread-MonitorTestCase2/MonitorTestCase2.java b/test/testsuite/ouroboros/thread_test/RT0176-rt-thread-MonitorTestCase2/MonitorTestCase2.java new file mode 100755 index 0000000000000000000000000000000000000000..2d2e25814bd943b3d6a4ba02b923677ff37ffc34 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0176-rt-thread-MonitorTestCase2/MonitorTestCase2.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MonitorTestCase2.java + *- @TestCaseName: Thread_MonitorTestCase2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Added according to stress cases SyscompTestCase/Maple_harness/tools/testapp_MemStressTest/src + * /com/huawei/stress. + *- @Brief: see below + * -#step1: 创建一个static的类StopAbleThread继承Thread,类的构造方法使用了父函数的构造方法。 + * -#step2: 分配INIT_DEFAULT_THREAD_NUM / 2个对象来自于new StopAbleThread类,同时启动监控线程,监控进程解锁后等待sleepTime时间。 + * -#step3: 调用start()启动所有的对象线程。 + * -#step4: 调用join()等待线程运行结束。 + * -#step5: 调用Runtime.getRuntime().gc()回收资源。 + * -#step6: 重复步骤1~4。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: MonitorTestCase2.java + *- @ExecuteClass: MonitorTestCase2 + *- @ExecuteArgs: + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class MonitorTestCase2 { + private static final int INIT_DEFAULT_THREAD_NUM = 100; + private static int DEFAULT_THREAD_NUM_HALF = INIT_DEFAULT_THREAD_NUM / 2; + private static final int THREAD_SLEEP_TIME_DEFAULT = 1; + private static final String MODULE_NAME_MONITOR = "M"; + private static final int THREAD_REPEATS_INFINITE = -1; + private static final int THREAD_REPEATS_DEFAULT = 1; + private static boolean mRunning = true; + private static boolean mRest = false; + private static int mRestTime = 5000; + static List mAllThread = new ArrayList<>(); + + public static void main(String[] args) { + testCase2(); + Runtime.getRuntime().gc(); + testCase2(); + System.out.println("0"); + } + + public static void testCase2() { + ArrayList list = new ArrayList<>(); + Thread t; + Object lockObject = new Object(); + for (int i = 0; i < DEFAULT_THREAD_NUM_HALF; i++) { + t = new StopAbleThread(new MonitorTestWait(lockObject, THREAD_SLEEP_TIME_DEFAULT, THREAD_REPEATS_DEFAULT), + MODULE_NAME_MONITOR + "_testCase2_" + i); + list.add(t); + } + startAllThread(list); + waitAllThreadFinish(list); + } + + public static void waitAllThreadFinish(List list) { + for (Thread s : list) { + try { + s.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + removeDeadThread(s); + } + } + } + + public static void removeDeadThread(Thread t) { + if (t == null) { + return; + } + if (!t.isAlive()) { + synchronized (mAllThread) { + mAllThread.remove(t); + } + } + } + + public static void startAllThread(List list) { + for (Thread s : list) { + s.start(); + trySleep(new Random().nextInt(2)); + } + } + + public static void trySleep(long time) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + static class MonitorTest implements Runnable { + Object lockObject; + int sleepTime; + int repeats; + + public MonitorTest(Object lockObject, int sleepTime) { + this(lockObject, sleepTime, THREAD_REPEATS_INFINITE); + } + + public MonitorTest(Object lockObject, int sleepTime, int repeatTimes) { + this.lockObject = lockObject; + this.sleepTime = sleepTime; + repeats = repeatTimes; + } + + @Override + public void run() { + while (THREAD_REPEATS_INFINITE == repeats || repeats > 0) { + if (repeats > 0) { + repeats--; + } + synchronized (lockObject) { + lockObject.toString(); + tryRest(); + trySleep(sleepTime); + if (!mRunning) { + break; + } + } + } + } + } + + static class MonitorTestWait extends MonitorTest { + public MonitorTestWait(Object lockObject, int sleepTime, int repeatTimes) { + super(lockObject, sleepTime, repeatTimes); + } + + @Override + public void run() { + while (THREAD_REPEATS_INFINITE == repeats || repeats > 0) { + if (repeats > 0) { + repeats--; + } + if (!mRunning) { + break; + } + synchronized (lockObject) { + lockObject.toString(); + tryRest(); + try { + lockObject.wait(sleepTime); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + } + + private static boolean tryRest() { + if (mRest) { + trySleep(mRestTime); + return true; + } + return false; + } + + static class StopAbleThread extends Thread { + public StopAbleThread(Runnable r, String name) { + super(r, name); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0177-rt-thread-MonitorTestCase4/MonitorTestCase4.java b/test/testsuite/ouroboros/thread_test/RT0177-rt-thread-MonitorTestCase4/MonitorTestCase4.java new file mode 100755 index 0000000000000000000000000000000000000000..e66d13fe4ac89a91451fc50b370976f4d1bcde91 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0177-rt-thread-MonitorTestCase4/MonitorTestCase4.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MonitorTestCase4.java + *- @TestCaseName: Thread_MonitorTestCase4.java + *- @RequirementName: Java Thread + *- @Title/Destination: Added according to stress cases SyscompTestCase/Maple_harness/tools/testapp_MemStressTest/src + * /com/huawei/stress. + *- @Brief: see below + * -#step1: 创建一个static的类StopAbleThread继承Thread,类的构造方法使用了父函数的构造方法。 + * -#step2: 分配INIT_DEFAULT_THREAD_NUM / 2个对象来自于new StopAbleThread类,同时启动mTestVolatileRun线程。 + * -#step3: 调用start()启动所有的对象线程。 + * -#step4: 调用join()等待线程运行结束。 + * -#step5: 调用Runtime.getRuntime().gc()回收资源。 + * -#step6: 重复步骤1~4。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: MonitorTestCase4.java + *- @ExecuteClass: MonitorTestCase4 + *- @ExecuteArgs: + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class MonitorTestCase4 { + private static final int INIT_DEFAULT_THREAD_NUM = 100; + private static int DEFAULT_THREAD_NUM_HALF = INIT_DEFAULT_THREAD_NUM / 2; + private static final int THREAD_SLEEP_TIME_DEFAULT = 1; + private static final int THREAD_REPEATS_INFINITE = -1; + private static final int THREAD_REPEATS_DEFAULT = 1; + private static boolean mRunning = true; + private static boolean mRest = false; + private static int mRestTime = 5000; + + private static final String MODULE_NAME_MONITOR = "M"; + static List mAllThread = new ArrayList<>(); + + public static void main(String[] args) { + testCase4(); + Runtime.getRuntime().gc(); + testCase4(); + System.out.println("0"); + } + + public static void testCase4() { + ArrayList list = new ArrayList<>(); + Thread t1; + for (int i = 0; i < DEFAULT_THREAD_NUM_HALF; i++) { + t1 = new StopAbleThread(new CommonRun(mTestVolatileRun, THREAD_SLEEP_TIME_DEFAULT, THREAD_REPEATS_DEFAULT), + MODULE_NAME_MONITOR + "_testCase4_" + i); + list.add(t1); + } + startAllThread(list); + waitAllThreadFinish(list); + } + + public static void waitAllThreadFinish(List list) { + for (Thread s : list) { + try { + s.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + removeDeadThread(s); + } + } + } + + public static void startAllThread(List list) { + for (Thread s : list) { + s.start(); + trySleep(new Random().nextInt(2)); + } + } + + public static void removeDeadThread(Thread t) { + if (t == null) { + return; + } + if (!t.isAlive()) { + synchronized (mAllThread) { + mAllThread.remove(t); + } + } + } + + public static void trySleep(long time) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private static Runnable mTestVolatileRun = new Runnable() { + @Override + public void run() { + for (int i = 0; i < 100; i++) { + tryRest(); + Object testa = GetTestVolatile(); + // Visit meta + if (testa instanceof Object) { + continue; + } + } + } + }; + + public static volatile Object testVolatile = null; + + private static Object GetTestVolatileImpl() { + if (testVolatile == null) { + testVolatile = new testVolatileClass(); + } + return testVolatile; + } + + static class testVolatileClass { + int a; + } + + private static Object GetTestVolatile() { + return GetTestVolatileImpl(); + } + + private static boolean tryRest() { + if (mRest) { + trySleep(mRestTime); + return true; + } + return false; + } + + static class CommonRun implements Runnable { + int sleepTime; + int repeats; + Runnable cbFun; + + public CommonRun(Runnable cb, int sleepTime, int repeatTimes) { + this.sleepTime = sleepTime; + repeats = repeatTimes; + cbFun = cb; + } + + @Override + public void run() { + while (THREAD_REPEATS_INFINITE == repeats || repeats > 0) { + if (repeats > 0) { + repeats--; + } + tryRest(); + if (cbFun != null) { + cbFun.run(); + } + trySleep(sleepTime); + if (!mRunning) { + break; + } + } + } + } + + static class StopAbleThread extends Thread { + public StopAbleThread(Runnable r, String name) { + super(r, name); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0178-rt-thread-MonitorTestCase5/MonitorTestCase5.java b/test/testsuite/ouroboros/thread_test/RT0178-rt-thread-MonitorTestCase5/MonitorTestCase5.java new file mode 100755 index 0000000000000000000000000000000000000000..ec77b47b7474ee7b021c6990244eb248188a1b3c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0178-rt-thread-MonitorTestCase5/MonitorTestCase5.java @@ -0,0 +1,182 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MonitorTestCase5.java + *- @TestCaseName: Thread_MonitorTestCase5.java + *- @RequirementName: Java Thread + *- @Title/Destination: Added according to stress cases SyscompTestCase/Maple_harness/tools/testapp_MemStressTest/src + * /com/huawei/stress. + *- @Brief: see below + * -#step1: 创建一个static的类StopAbleThread继承Thread,类的构造方法使用了父函数的构造方法。 + * -#step2: 分配INIT_DEFAULT_THREAD_NUM / 2个对象来自于new StopAbleThread类,同时启动mTestVolatileRun线程。 + * -#step3: 调用start()启动所有的对象线程。 + * -#step4: 调用join()等待线程运行结束。 + * -#step5: 调用Runtime.getRuntime().gc()回收资源。 + * -#step6: 重复步骤1~4。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: MonitorTestCase5.java + *- @ExecuteClass: MonitorTestCase5 + *- @ExecuteArgs: + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class MonitorTestCase5 { + private static final int INIT_DEFAULT_THREAD_NUM = 100; + private static int DEFAULT_THREAD_NUM_HALF = INIT_DEFAULT_THREAD_NUM / 2; + private static final int THREAD_SLEEP_TIME_DEFAULT = 1; + private static final int THREAD_REPEATS_INFINITE = -1; + private static final int THREAD_REPEATS_DEFAULT = 1; + private static final String MODULE_NAME_MONITOR = "M"; + private static boolean mRunning = true; + private static boolean mRest = false; + private static int mRestTime = 5000; + static List mAllThread = new ArrayList<>(); + + public static void main(String[] args) { + testCase5(); + Runtime.getRuntime().gc(); + testCase5(); + System.out.println("0"); + } + + public static void testCase5() { + ArrayList list = new ArrayList<>(); + Thread t1; + for (int i = 0; i < DEFAULT_THREAD_NUM_HALF; i++) { + t1 = new StopAbleThread(new CommonRun(mTestVolatileRun, THREAD_SLEEP_TIME_DEFAULT, THREAD_REPEATS_DEFAULT), + MODULE_NAME_MONITOR + "_testCase5_" + i); + list.add(t1); + } + startAllThread(list); + waitAllThreadFinish(list); + } + + public static void waitAllThreadFinish(List list) { + for (Thread s : list) { + try { + s.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + removeDeadThread(s); + } + } + } + + public static void removeDeadThread(Thread t) { + if (t == null) { + return; + } + if (!t.isAlive()) { + synchronized (mAllThread) { + mAllThread.remove(t); + } + } + } + + public static void startAllThread(List list) { + for (Thread s : list) { + s.start(); + trySleep(new Random().nextInt(2)); + } + } + + public static void trySleep(long time) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private static Runnable mTestVolatileRun = new Runnable() { + @Override + public void run() { + for (int i = 0; i < 100; i++) { + tryRest(); + Object testa = GetTestVolatile(); + + if (testa instanceof Object) { + continue; + } + } + } + }; + + public static volatile Object testVolatile = null; + + private static Object GetTestVolatileImpl() { + if (testVolatile == null) { + testVolatile = new testVolatileClass(); + } + return testVolatile; + } + + static class testVolatileClass { + // test class + } + + private static Object GetTestVolatile() { + return GetTestVolatileImpl(); + } + + private static boolean tryRest() { + if (mRest) { + trySleep(mRestTime); + return true; + } + return false; + } + + static class CommonRun implements Runnable { + int sleepTime; + int repeats; + Runnable cbFun; + + public CommonRun(Runnable cb, int sleepTime, int repeatTimes) { + this.sleepTime = sleepTime; + repeats = repeatTimes; + cbFun = cb; + } + + @Override + public void run() { + while (THREAD_REPEATS_INFINITE == repeats || repeats > 0) { + if (repeats > 0) { + repeats--; + } + tryRest(); + if (cbFun != null) { + cbFun.run(); + } + trySleep(sleepTime); + if (!mRunning) { + break; + } + } + } + } + + static class StopAbleThread extends Thread { + public StopAbleThread(Runnable r, String name) { + super(r, name); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0179-rt-thread-MonitorTestCase6/MonitorTestCase6.java b/test/testsuite/ouroboros/thread_test/RT0179-rt-thread-MonitorTestCase6/MonitorTestCase6.java new file mode 100755 index 0000000000000000000000000000000000000000..ff76e274e8b5fd5f1ffdba7234dfa0f0c869f695 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0179-rt-thread-MonitorTestCase6/MonitorTestCase6.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MonitorTestCase6.java + *- @TestCaseName: Thread_MonitorTestCase6.java + *- @RequirementName: Java Thread + *- @Title/Destination: Added according to stress cases SyscompTestCase/Maple_harness/tools/testapp_MemStressTest/src + * /com/huawei/stress. + *- @Brief: see below + * -#step1: 创建一个static的类StopAbleThread继承Thread,类的构造方法使用了父函数的构造方法。 + * -#step2: 分配INIT_DEFAULT_THREAD_NUM个对象来自于new StopAbleThread类,同时启动SyncThread监控线程,该线程带同步锁。 + * -#step3: 调用Runtime.getRuntime().gc()回收资源。 + * -#step4: 重复步骤1~2。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: MonitorTestCase6.java + *- @ExecuteClass: MonitorTestCase6 + *- @ExecuteArgs: + */ + +import java.util.ArrayList; +import java.util.Random; + +public class MonitorTestCase6 { + private static boolean quit = false; + private static final int INIT_DEFAULT_THREAD_NUM = 100; + private static int DEFAULT_THREAD_NUM = INIT_DEFAULT_THREAD_NUM; + private static final String MODULE_NAME_MONITOR = "M"; + private static int monitorLengthForCase6 = DEFAULT_THREAD_NUM / 5; + private static boolean mRest = false; + private static int mRestTime = 5000; + + public static void main(String[] args) { + testCase6(); + Runtime.getRuntime().gc(); + testCase6(); + System.out.println("0"); + } + + public static void testCase6() { + quit = false; + ArrayList mList = createTestObject(); + ArrayList list = new ArrayList<>(); + Thread t; + + for (int i = 0; i < (DEFAULT_THREAD_NUM / 10); i++) { + t = new StopAbleThread(new SyncThread(mList), MODULE_NAME_MONITOR + "_testCase6_A" + i); + list.add(t); + } + } + + public static class SyncThread implements Runnable { + private Random intRandom; + private ArrayList mList; + + public SyncThread(ArrayList list) { + this.intRandom = new Random(); + this.mList = list; + } + + @Override + public void run() { + monitorTestUnit monitor; + int start; + int sleepTime; + for (int j = 0; j < 2000; j++) { + start = this.intRandom.nextInt(monitorLengthForCase6); + for (int k = 0; k < monitorLengthForCase6; k++) { + monitor = mList.get((k + start) % monitorLengthForCase6); + synchronized (monitor) { + tryRest(); + monitor.testCount++; + sleepTime = this.intRandom.nextInt(4) + 1; + trySleep(sleepTime * 3); + } + } + + if (quit) { + break; + } + } + } + } + + public static void trySleep(long time) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private static boolean tryRest() { + if (mRest) { + trySleep(mRestTime); + return true; + } + return false; + } + + public static ArrayList createTestObject() { + ArrayList mList = new ArrayList<>(); + for (int i = 0; i < monitorLengthForCase6; i++) { + mList.add(new monitorTestUnit()); + } + return mList; + } + + static class StopAbleThread extends Thread { + public StopAbleThread(Runnable r, String name) { + super(r, name); + } + } + + static class monitorTestUnit { + int testCount; + boolean isWait; + + monitorTestUnit() { + testCount = 0; + isWait = false; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0180-rt-thread-MonitorTestCase8/MonitorTestCase8.java b/test/testsuite/ouroboros/thread_test/RT0180-rt-thread-MonitorTestCase8/MonitorTestCase8.java new file mode 100755 index 0000000000000000000000000000000000000000..c77e322f0279404a77c90d3ec15ef13bf45f9aaf --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0180-rt-thread-MonitorTestCase8/MonitorTestCase8.java @@ -0,0 +1,305 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: MonitorTestCase8.java + *- @TestCaseName: Thread_MonitorTestCase8.java + *- @RequirementName: Java Thread + *- @Title/Destination: Added according to stress cases SyscompTestCase/Maple_harness/tools/testapp_MemStressTest/src + * /com/huawei/stress. + *- @Brief: see below + * -#step1: 创建一个static的类StopAbleThread继承Thread,类的构造方法使用了父函数的构造方法。 + * -#step2: 分配DEFAULT_THREAD_NUM_HALF / 2个对象来自于new StopAbleThread类,同时在new的参数1里定义new CommonRun监控线程。 + * -#step3: 调用start()启动所有的对象线程。 + * -#step4: 调用join()等待线程运行结束。 + * -#step5: 调用Runtime.getRuntime().gc()回收资源。 + * -#step6: 重复步骤1~4。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: MonitorTestCase8.java + *- @ExecuteClass: MonitorTestCase8 + *- @ExecuteArgs: + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class MonitorTestCase8 { + private static final int INIT_DEFAULT_THREAD_NUM = 10; + private static int DEFAULT_THREAD_NUM_HALF = INIT_DEFAULT_THREAD_NUM / 2; + private static final int THREAD_REPEATS_DEFAULT = 1; + private static final int THREAD_REPEATS_INFINITE = -1; + private static boolean mRunning = true; + private static boolean mRest = false; + private static int mRestTime = 500; + static List mAllThread = new ArrayList<>(); + + public static void main(String[] args) { + testCase8(); + Runtime.getRuntime().gc(); + testCase8(); + System.out.println("0"); + } + + public static void testCase8() { + List list = new ArrayList<>(); + List stringList = new ArrayList<>(); + for (int i = 0; i < (DEFAULT_THREAD_NUM_HALF / 2); i++) { + int index = i; + stringList.add(""); + list.add(new StopAbleThread(new CommonRun(() -> { + ArrayList strings = new ArrayList<>(100); + for (int j = 0; j < 100; j++) { + strings.add(StringMethod.getStringRandom()); + } + for (String str : strings) { + stringList.set(index, stringList.get(index) + str); + } + }, 100, THREAD_REPEATS_DEFAULT), "testCase8_" + (i + 1))); + } + startAllThread(list); + waitAllThreadFinish(list); + } + + public static void startAllThread(List list) { + for (Thread s : list) { + s.start(); + trySleep(new Random().nextInt(2)); + } + } + + public static void trySleep(long time) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public static void waitAllThreadFinish(List list) { + for (Thread s : list) { + try { + s.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + removeDeadThread(s); + } + } + } + + public static void removeDeadThread(Thread t) { + if (t == null) { + return; + } + if (!t.isAlive()) { + synchronized (mAllThread) { + mAllThread.remove(t); + } + } + } + + static class StopAbleThread extends Thread { + public StopAbleThread(Runnable r, String name) { + super(r, name); + } + } + + static class CommonRun implements Runnable { + int sleepTime; + int repeats; + Runnable cbFun; + + public CommonRun(Runnable cb, int sleepTime, int repeatTimes) { + this.sleepTime = sleepTime; + repeats = repeatTimes; + cbFun = cb; + } + + @Override + public void run() { + while (THREAD_REPEATS_INFINITE == repeats || repeats > 0) { + if (repeats > 0) { + repeats--; + } + tryRest(); + if (cbFun != null) { + cbFun.run(); + } + trySleep(sleepTime); + if (!mRunning) { + break; + } + } + } + } + + private static boolean tryRest() { + if (mRest) { + trySleep(mRestTime); + return true; + } + return false; + } + + private enum StringMethod { + METHOD0("DirectString") { + @Override + public String apply() { + return "DirectString"; + } + }, + METHOD1("ReferenceString") { + @Override + public String apply() { + return this.name; + } + }, + METHOD2("FinalString") { + @Override + public String apply() { + return FINAL_STRING; + } + }, + METHOD3("ConcatString") { + @Override + public String apply() { + return "Concat".concat("String"); + } + }, + METHOD4("StringAddition") { + @Override + public String apply() { + return "String" + "Addition" + 1; + } + }, + METHOD5("CopyValueOf") { + @Override + public String apply() { + char[] tmp = {'C', 'o', 'p', 'y', 'V', 'a', 'l', 'u', 'e', 'O', 'f'}; + return String.copyValueOf(tmp); + } + }, + METHOD6("Intern") { + @Override + public String apply() { + return mRandom.toString().intern(); + } + }, + METHOD7("Integer") { + @Override + public String apply() { + return Integer.toString(mRandom.nextInt()); + } + }, + METHOD8("Float") { + @Override + public String apply() { + return Float.toString(mRandom.nextFloat()); + } + }, + METHOD9("Double") { + @Override + public String apply() { + return Double.toString(mRandom.nextDouble()); + } + }, + METHOD10("Boolean") { + @Override + public String apply() { + return Boolean.toString(mRandom.nextBoolean()); + } + }, + METHOD11("ReplaceChar") { + @Override + public String apply() { + return mRandom.toString().replace('R', 'r'); + } + }, + METHOD12("ReplaceString") { + @Override + public String apply() { + return mRandom.toString().replace("Ran", "RED"); + } + }, + METHOD13("Split") { + @Override + public String apply() { + return mRandom.toString().split("@")[0]; + } + }, + METHOD14("SubString") { + @Override + public String apply() { + return mRandom.toString().substring(3, 5); + } + }, + METHOD15("ToLowerCase") { + @Override + public String apply() { + return mRandom.toString().toLowerCase(); + } + }, + METHOD16("ToUpperCase") { + @Override + public String apply() { + return mRandom.toString().toUpperCase(); + } + }, + METHOD17("StringBuffer") { + @Override + public String apply() { + return new StringBuffer("String").append("Buffer").append(1).toString(); + } + }, + METHOD18("StringBuilder") { + @Override + public String apply() { + return new StringBuilder(20).append(mRandom).toString(); + } + }, + METHOD19("subSequence") { + @Override + public String apply() { + return mRandom.toString().subSequence(1, 3).toString(); + } + }; + + public final String name; + private static final String FINAL_STRING = "FinalString"; + private static final Random mRandom = new Random(); + + StringMethod(String name) { + this.name = name; + } + + public String apply() { + return name; + } + + public static String getString(int id) { + if ((id < 0) || (id >= StringMethod.values().length)) { + return ""; + } else { + return StringMethod.values()[id].apply(); + } + } + + public static String getStringRandom() { + return getString(mRandom.nextInt(StringMethod.values().length)); + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0181-rt-thread-ThreadCountStackFrames/ThreadCountStackFrames.java b/test/testsuite/ouroboros/thread_test/RT0181-rt-thread-ThreadCountStackFrames/ThreadCountStackFrames.java new file mode 100755 index 0000000000000000000000000000000000000000..d479056b68816f563d5f4d578e2ab80aca1a388e --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0181-rt-thread-ThreadCountStackFrames/ThreadCountStackFrames.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadCountStackFrames + *- @TestCaseName: Thread_ThreadCountStackFrames.java + *- @RequirementName: Java Thread + *- @Brief: see below + * -#step1: 创建一个线程。 + * -#step2:在线程启动前检查,调用countStackFrames()确认返回0,调用getStackTrace()确认返回的长度为0。 + * -#step3:启动线程,等待线程结束。 + * -#step4:确认线程已经结束,调用countStackFrames()确认返回0,调用getStackTrace()确认返回的长度为0。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadCountStackFrames.java + *- @ExecuteClass: ThreadCountStackFrames + *- @ExecuteArgs: + */ + +public class ThreadCountStackFrames { + static int threadFinish = 0; + + public static void main(String[] args) { + int result = 2; + Thread thread = new Thread("ThreadCountStackFrames") { + public void run() { + try { + sleep(1000); + } catch (Exception e) { + System.out.println(e); + } + ThreadCountStackFrames.threadFinish++; + } + }; + // Before the thread started. + if (thread.countStackFrames() == 0 && thread.getStackTrace().length == 0) { + result--; + } + + thread.start(); + try { + thread.join(); + } catch (Exception e) { + System.out.println(e); + } + // After a thread finished. + if (thread.countStackFrames() == 0 && thread.getStackTrace().length == 0 + && ThreadCountStackFrames.threadFinish == 1) { + result--; + } + System.out.println(result); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n diff --git a/test/testsuite/ouroboros/thread_test/RT0182-rt-thread-ThreadDMdestory2/ThreadDMdestory2.java b/test/testsuite/ouroboros/thread_test/RT0182-rt-thread-ThreadDMdestory2/ThreadDMdestory2.java new file mode 100755 index 0000000000000000000000000000000000000000..48dad6a5cd5d9ceb505dcb56516b2d4729ff3d1a --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0182-rt-thread-ThreadDMdestory2/ThreadDMdestory2.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadDMDestroy2 + *- @TestCaseName: Thread_ThreadDMdestory2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread api: destroy(), added from JCK test case ${MAPLE_ROOT}/clinic/jck/JCK-runtime-8b/tests/ + * api/java_lang/Thread/index.html#destroy destroy001, destroy002, destroy003. + *- @Brief: see below + * -#step1: 直接调用new Thread().destroy(),确认会抛出UnsupportedOperationException。 + * -#step2:创建一个线程thread,调用start()启动,调用join()等待线程结束,调用destroy(),确认会抛出 + * UnsupportedOperationException。 + * -#step3:创建一个线程st,调用start()启动,线程会执行sleep操作,调用destroy(),确认会抛出UnsupportedOperationException。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadDMdestory2.java + *- @ExecuteClass: ThreadDMdestory2 + *- @ExecuteArgs: + */ + +public class ThreadDMdestory2 { + + public static void main(String[] args) { + System.out.println(run()); + } + + private static int run() { + int exceptionCount = 0; + + // destroy001: test destroy() when the thread is not started + try { + new Thread().destroy(); + return 1; + } catch (UnsupportedOperationException ok) { + exceptionCount++; + } + + // destroy002: test destroy() when the thread is finished + Thread thread = new Thread(); + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + System.out.println(e); + } + + try { + thread.destroy(); + return 2; + } catch (UnsupportedOperationException ok) { + exceptionCount++; + } + + // destroy003: test destroy() when a thread is sleeping + SleepingThread st = new SleepingThread(); + st.start(); + + while (! st.started) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // ignore any attempt to interrupt + System.out.println(e); + } + } + + try { + st.destroy(); + return 3; + } catch (UnsupportedOperationException ok) { + exceptionCount++; + } + st.checked=true; + + if (exceptionCount == 3) { + return 0; + }else{ + return 4; + } + } +} + +class SleepingThread extends Thread { + public volatile boolean started = false; + public volatile boolean checked = false; + + public void run() { + started = true; + while (! checked) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // ignore any attempt to interrupt + System.out.println(e); + } + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0183-rt-thread-ThreadGetContextClassLoader/ThreadGetContextClassLoader.java b/test/testsuite/ouroboros/thread_test/RT0183-rt-thread-ThreadGetContextClassLoader/ThreadGetContextClassLoader.java new file mode 100755 index 0000000000000000000000000000000000000000..1fcb73e250048e63cebb0b0e4d97b147e197d910 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0183-rt-thread-ThreadGetContextClassLoader/ThreadGetContextClassLoader.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadGetContextClassLoader.java + *- @TestCaseName: Thread_ThreadGetContextClassLoader.java + *- @RequirementName: Java Thread + *- @Title/Destination: Thread api: getContextClassLoader(), added from JCK test case ${MAPLE_ROOT}/clinic/jck/ + * JCK-runtime-8b/tests/api/java_lang/Thread/index.html#getContextClassLoader(), Thread4404. + *- @Brief: see below + * -#step1: 创建线程,调用getContextClassLoader()确认为父线程的ClassLoader上下文。 + * -#step2:启动线程,等待线程结束。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadGetContextClassLoader.java + *- @ExecuteClass: ThreadGetContextClassLoader + *- @ExecuteArgs: + */ + +public class ThreadGetContextClassLoader { + public static void main(String[] args) { + Thread thr = new Thread(); + try { + // If not set, the default is the ClassLoader context of the parent Thread. + if (thr.getContextClassLoader() != Thread.currentThread().getContextClassLoader()) { + System.out.println(2); + } + } finally { + thr.start(); + try { + thr.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + } + System.out.println(0); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0184-rt-Thread-GenerifyStackTraces2/GenerifyStackTraces.java b/test/testsuite/ouroboros/thread_test/RT0184-rt-Thread-GenerifyStackTraces2/GenerifyStackTraces.java new file mode 100755 index 0000000000000000000000000000000000000000..bcd0b261a0e8a93aa6f538bd4e02a24137dbb644 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0184-rt-Thread-GenerifyStackTraces2/GenerifyStackTraces.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: getStackTrace_RecursiveCall + *- @TestCaseName: GenerifyStackTraces.java + *- @RequirementName: Java Thread + *- @Title/Destination: Generified basic unit test of Thread.getStackTraces() + *- @Brief: see below + * -#step1: 定义ThreadOne类,该类继承Thread类,定义run函数,会调用wait()方法依次调用A,B,C,Done方法,最后获取当前线程的栈信 + * 息,并检查。 + * -#step2: 定义DumpThread类,该类继承Thread类,定义run函数,等待ThreadOne阻塞获取栈信息,通知ThreadOne继续。 + * -#step3: New对象ThreadOne,通过start()方法启动run()。 + * -#step4: New对象DumpThread,通过start()方法启动run()。 + * -#step5: 等待ThreadOne对象运行结束。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: GenerifyStackTraces.java + *- @ExecuteClass: GenerifyStackTraces + *- @ExecuteArgs: + */ + +import java.util.Map; + +public class GenerifyStackTraces { + private static Object go = new Object(); + private static String[] methodNames = {"run", "A", "B", "C", "Done"}; + private static int DONE_DEPTH = 5; + private static boolean testFailed = false; + private static Thread one; + private static boolean trace = false; + + public static void main(String[] args) throws Exception { + if (args.length > 0 && args[0].equals("trace")) { + trace = true; + } + + one = new ThreadOne(); + one.start(); + + DumpThread dt = new DumpThread(); + dt.start(); + + try { + one.join(); + } finally { + dt.shutdown(); + } + + if (testFailed) { + throw new RuntimeException("Test Failed."); + } + System.out.println(0); + } + + static class DumpThread extends Thread { + private volatile boolean finished = false; + + public void run() { + int depth = 2; + while (!finished) { + // At each iterator, wait until ThreadOne blocks to wait for thread dump. + // Then dump stack trace and notify ThreadOne to continue. + try { + sleep(2000); + dumpStacks(depth); + depth++; + finishDump(); + } catch (Exception e) { + e.printStackTrace(); + testFailed = true; + } + } + } + + public void shutdown() throws InterruptedException { + finished = true; + this.join(); + } + } + + static class ThreadOne extends Thread { + public void run() { + System.out.println( ); + A(); + } + + private void A() { + waitForDump(); + B(); + } + + private void B() { + waitForDump(); + C(); + } + + private void C() { + waitForDump(); + Done(); + } + + private void Done() { + waitForDump(); + + // Get stack trace of current thread + StackTraceElement[] stack = getStackTrace(); + try { + checkStack(this, stack, DONE_DEPTH); + } catch (Exception e) { + e.printStackTrace(); + testFailed = true; + } + } + } + + static private void waitForDump() { + synchronized(go) { + try { + go.wait(); + } catch (Exception e) { + throw new RuntimeException("Unexpected exception" + e); + } + } + } + + static private void finishDump() { + synchronized(go) { + try { + go.notifyAll(); + } catch (Exception e) { + throw new RuntimeException("Unexpected exception" + e); + } + } + } + + public static void dumpStacks(int depth) throws Exception { + // Get stack trace of another thread + StackTraceElement[] stack = one.getStackTrace(); + checkStack(one, stack, depth); + + // Get stack traces of all Threads + for (Map.Entry entry : Thread.getAllStackTraces().entrySet()) { + Thread t = entry.getKey(); + stack = entry.getValue(); + if (t == null || stack == null) { + throw new RuntimeException("Null thread or stacktrace returned"); + } + if (t == one) { + checkStack(t, stack, depth); + } + } + } + + private static void checkStack(Thread t, StackTraceElement[] stack, int depth) throws Exception { + if (trace) { + printStack(t, stack); + } + int frame = stack.length - 1; + for (int i = 0; i < depth && frame >= 0; i++) { + if (! stack[frame].getMethodName().equals(methodNames[i])) { + throw new RuntimeException("Expected " + methodNames[i] + " in frame " + frame + " but got " + + stack[frame].getMethodName()); + } + frame--; + } + } + + private static void printStack(Thread t, StackTraceElement[] stack) { + System.out.println(t + " stack: (length = " + stack.length + ")"); + if (t != null) { + for (int j = 0; j < stack.length; j++) { + System.out.println(stack[j]); + } + System.out.println(); + } + } +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0185-rt-Thread-GenerifyAllStackTraces/GenerifyAllStackTraces.java b/test/testsuite/ouroboros/thread_test/RT0185-rt-Thread-GenerifyAllStackTraces/GenerifyAllStackTraces.java new file mode 100755 index 0000000000000000000000000000000000000000..c3ab91acc47cdcc185602a649002f54cc0f56cb7 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0185-rt-Thread-GenerifyAllStackTraces/GenerifyAllStackTraces.java @@ -0,0 +1,241 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: GenerifyAllStackTraces + *- @TestCaseName: GenerifyAllStackTraces.java + *- @RequirementName: Unwind + *- @Title/Destination: Generified basic unit test of Thread.getAllStackTraces() + *- @Brief: see below + * -#step1: 创造两个线程组,每个线程都有相同同步锁,解锁后等待10ms, + * -#step2: 定义ThreadOne和ThreadTwo类,该类均继承Thread类,分别定义run函数,会调用wait()方法依次调用A,B,C方法,最后获取当前线程的栈信 + * 息,并检查。 + * -#step3: 定义DumpThread类,该类继承Thread类,定义run函数,等待ThreadOne和ThreadTwo阻塞获取栈信息,通知ThreadOne继续。 + * -#step4: 等待线程组中的ThreadOne和ThreadTwo对象运行结束。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: GenerifyAllStackTraces.java + *- @ExecuteClass: GenerifyAllStackTraces + *- @ExecuteArgs: + */ + + +import java.util.Map; + +public class GenerifyAllStackTraces { + private static Object go = new Object(); + private static String[] methodNames = {"run", "A", "B", "C", "Done"}; + private static int DONE_DEPTH = 5; + private static boolean testFailed = false; + private static Thread one; + private static Thread two; + private static boolean trace = false; + + public static void main(String[] args) throws Exception { + if (args.length > 0 && args[0].equals("trace")) { + trace = true; + } + + one = new ThreadOne(); + two = new ThreadTwo(); + one.start(); + two.start(); + + DumpThread dt = new DumpThread(); + dt.start(); + + try { + one.join(); + two.join(); + } finally { + dt.shutdown(); + } + + if (testFailed) { + throw new RuntimeException("Test Failed."); + } + System.out.println(0); + } + + static class DumpThread extends Thread { + private volatile boolean finished = false; + + @Override + public void run() { + int depth = 2; + while (!finished) { + // At each iterator, wait until ThreadOne blocks to wait for thread dump. + // Then dump stack trace and notify ThreadOne to continue. + try { + sleep(2000); + dumpStacks(depth); + depth++; + finishDump(); + } catch (Exception e) { + e.printStackTrace(); + testFailed = true; + } + } + } + + public void shutdown() throws InterruptedException { + finished = true; + join(); + } + } + + static class ThreadOne extends Thread { + @Override + public void run() { + System.out.println(); + A(); + } + + private void A() { + waitForDump(); + B(); + } + + private void B() { + waitForDump(); + C(); + } + + private void C() { + waitForDump(); + Done(); + } + + private void Done() { + waitForDump(); + + // Get stack trace of current thread + + StackTraceElement[] stack = getStackTrace(); + try { + checkStack(this, stack, DONE_DEPTH); + } catch (Exception e) { + e.printStackTrace(); + testFailed = true; + } + } + } + + static class ThreadTwo extends Thread { + @Override + public void run() { + System.out.println(); + A(); + } + + private void A() { + waitForDump(); + B(); + } + + private void B() { + waitForDump(); + C(); + } + + private void C() { + waitForDump(); + Done(); + } + + private void Done() { + waitForDump(); + + // Get stack trace of current thread + StackTraceElement[] stack = getStackTrace(); + try { + checkStack(this, stack, DONE_DEPTH); + } catch (Exception e) { + e.printStackTrace(); + testFailed = true; + } + } + } + + static private void waitForDump() { + synchronized (go) { + try { + go.wait(); + } catch (Exception e) { + throw new RuntimeException("Unexpected exception" + e); + } + } + } + + static private void finishDump() { + synchronized (go) { + try { + go.notifyAll(); + } catch (Exception e) { + throw new RuntimeException("Unexpected exception" + e); + } + } + } + + public static void dumpStacks(int depth) throws Exception { + // Get stack trace of another thread + StackTraceElement[] stack = one.getStackTrace(); + StackTraceElement[] stacks = two.getStackTrace(); + checkStack(one, stack, depth); + checkStack(two, stacks, depth); + + // Get stack traces of all Threads + for (Map.Entry entry : Thread.getAllStackTraces().entrySet()) { + Thread t = entry.getKey(); + stack = entry.getValue(); + if (t == null || stack == null) { + throw new RuntimeException("Null thread or stacktrace returned"); + } + if (t == one) { + checkStack(t, stack, depth); + } + if (t == two) { + checkStack(t, stacks, depth); + } + } + } + + private static void checkStack(Thread t, StackTraceElement[] stack, int depth) throws Exception { + if (trace) { + printStack(t, stack); + } + int frame = stack.length - 1; + for (int i = 0; i < depth && frame >= 0; i++) { + if (!stack[frame].getMethodName().equals(methodNames[i])) { + throw new RuntimeException("Expected " + methodNames[i] + " in frame " + frame + " but got " + + stack[frame].getMethodName()); + } + frame--; + } + } + + private static void printStack(Thread t, StackTraceElement[] stack) { + System.out.println(t + " stack: (length = " + stack.length + ")"); + if (t != null) { + for (int j = 0; j < stack.length; j++) { + System.out.println(stack[j]); + } + System.out.println(); + } + } +} + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0186-rt-Thread-getAllStackTraces-RecursiveCall/RecursiveCall.java b/test/testsuite/ouroboros/thread_test/RT0186-rt-Thread-getAllStackTraces-RecursiveCall/RecursiveCall.java new file mode 100755 index 0000000000000000000000000000000000000000..f5857d2a3429ee746d81a0770396af439bab4d76 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0186-rt-Thread-getAllStackTraces-RecursiveCall/RecursiveCall.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: getAllStackTrace_RecursiveCall + *- @TestCaseName: RecursiveCall.java + *- @RequirementName: Unwind + *- @Title/Destination: Generified basic unit test of Thread.getAllStackTraces() + *- @Brief: see below + * -#step1: 创造一个线程组,长度为1000,每个线程都有相同同步锁,解锁后等待10ms, + * -#step2: ThreadOne类,该类均继承Thread类,分别定义run函数,会调用wait()方法依次调用A,B,C方法,并行执行线程组。 + * -#step3: 等待所有线程正常结束 + *- @Expect: 0\n + *- @Priority: High + *- @Source: RecursiveCall.java + *- @ExecuteClass: RecursiveCall + *- @ExecuteArgs: + */ + + +import java.util.Map; + +public class RecursiveCall extends Thread{ + private static String[] methodNames = {"run", "A", "B", "C", "Done"}; + private static Object obj = new Object(); + private static Thread[] tt = new Thread[1000]; + + public static void main(String[] args) throws InterruptedException{ + + for (int i = 0; i < tt.length; i++) { + tt[i] = new ThreadOne(); + } + for (int i = 0; i < tt.length; i++) { + tt[i].start(); + } + + for (int i = 0; i < tt.length; i++) { + try { + tt[i].join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + System.out.println(0); + } + + + static class ThreadOne extends Thread { + @Override + public void run() { + System.out.println( ); + A(); + } + + private void A() { + waitForDump(); + B(); + } + + private void B() { + waitForDump(); + C(); + } + + private void C() { + waitForDump(); + Done(); + } + + private void Done() { + waitForDump(); + } + } + + static private void waitForDump() { + synchronized (obj) { + try { + obj.wait(10); + } catch (InterruptedException e) { + System.out.println("wait is interrupted"); + } + } + } + + +} + + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/RT0188-rt-Thread-getAllStackTraces-NullStackTrace/NullStackTrace.java b/test/testsuite/ouroboros/thread_test/RT0188-rt-Thread-getAllStackTraces-NullStackTrace/NullStackTrace.java new file mode 100755 index 0000000000000000000000000000000000000000..dd44d5d4afc600728422463c1951fcb2e1125019 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/RT0188-rt-Thread-getAllStackTraces-NullStackTrace/NullStackTrace.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: getAllStackTrace_NullStackTrace + *- @TestCaseName: NullStackTrace.java + *- @RequirementName: getAllStackTrace + *- @Title/Destination: Thread.getAllStackTrace() on runnable threads, should not return null + *- @Brief: see below + * -#step1: 创建一个线程实例 + * -#step2: 启动线程 + * -#step3: 用Thread.getAllStackTrace() 打印线程,不能返回为空 + * -#step4: 重复1-3步骤1000次. + *- @Expect: Passed + *- @Priority: High + *- @Source: NullStackTrace.java + *- @ExecuteClass: NullStackTrace + *- @ExecuteArgs: + */ +import java.util.Map; + +public class NullStackTrace extends Thread{ + static final int TIMES = 1000; + + public static void main(String[] args) { + for (int i = 0; i < TIMES; i++) { + Thread t = new Thread(); + t.start(); + + Map m = getAllStackTraces(); + String stFinish = m.keySet().toString(); + if (stFinish == null) + throw new RuntimeException("Failed: Thread.getAllStackTrace should not return null"); + } + System.out.println("Passed"); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan Passed \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/issue-0000-rt-Thread-ThreadOutofmemory/ThreadOutOfMemoryTest.java b/test/testsuite/ouroboros/thread_test/issue-0000-rt-Thread-ThreadOutofmemory/ThreadOutOfMemoryTest.java new file mode 100755 index 0000000000000000000000000000000000000000..18f27641474085f20085431abece6e8f617234a8 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/issue-0000-rt-Thread-ThreadOutofmemory/ThreadOutOfMemoryTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadOutOfMemoryTest + *- @TestCaseName: Thread_ThreadOutOfMemoryTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Check if thread creation reaches memory line will throw OutOfMemory. + *- @Brief: see below + * -#step1: 调用new Thread来创建线程,线程里会创建一个超大整数。 + * -#step2:使用循环反复启动该线程。 + * -#step3:检查线程是否会抛OutOfMemoryError异常并退出。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadOutOfMemoryTest.java + *- @ExecuteClass: ThreadOutOfMemoryTest + *- @ExecuteArgs: + */ +import java.io.PrintStream; + +public class ThreadOutOfMemoryTest { + private static Object s = new Object(); + private static int count = 0; + private static int i = 0; + + public static void main(String[] args) { + System.exit(run(args, System.out)); + System.out.println(2); + } + + public static int run(String[] args, PrintStream out) { + for (; ; ) { + new Thread(new Runnable() { + public void run() { + synchronized (s) { + try { + int[] y; + y = new int[50000 * 1000]; + y[0]++; + } catch (OutOfMemoryError e2) { + i++; + System.err.println(e2); + } + count += 1; +// System.out.println("New thread #" + count); + } + for (; ; ) { + try { + Thread.sleep(1000); + } catch (InterruptedException e1) { + System.err.println(e1); + } catch (OutOfMemoryError e3) { + i++; + System.err.println(e3); + } + } + } + }).start(); + if (i != 0) { +// System.out.println(i); + break; + } + } + System.out.println(0); + return 0; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/issue-RT0392-rt-Thread-Threadperformance1/ThreadPerformance1Test.java b/test/testsuite/ouroboros/thread_test/issue-RT0392-rt-Thread-Threadperformance1/ThreadPerformance1Test.java new file mode 100755 index 0000000000000000000000000000000000000000..2434a338473008eefcba2e40d5b13aa901a31346 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/issue-RT0392-rt-Thread-Threadperformance1/ThreadPerformance1Test.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadPerformance1Test + *- @TestCaseName: Thread_ThreadPerformance1Test.java + *- @RequirementName: Java Thread + *- @Title/Destination: Gets the average time to perform 20 group reentrant locks/unlock 100 times of monitor. + *- @Brief: see below + * -#step1: 创建个100长度的线程组,线程里有6个同步锁,第5和6个解锁后各等待10毫秒,调用notifyAll()进行解锁。 + * -#step2:打点开始时间startTime,并发启动线程组的线程进行解锁和关锁的操作。 + * -#step3:调用join()等待所有线程结束,打点结束时间endTime,endTime - startTime算出每次运行时间。 + * -#step4:重复步骤1~3 20次,计算每次的平均时间。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadPerformance1Test.java + *- @ExecuteClass: ThreadPerformance1Test + *- @ExecuteArgs: + */ + +class LockCls {} + +public class ThreadPerformance1Test extends Thread{ + public static void main(String[] args) { + LockCls lock = new LockCls(); + long startTime; + long endTime; + long[] ThreadPerformance1Test = new long[20]; + long sum = 0; + long ave; + Object obj = "aa"; + Thread[] tt = new Thread[100]; + for (int ii = 0; ii < ThreadPerformance1Test.length; ii++) { + for (int i = 0; i < tt.length; i++) { + tt[i] = new Thread(new Runnable() { + public void run() { + synchronized (lock) { + synchronized (lock) { + synchronized (obj) { + synchronized (this) { + synchronized (obj) { + synchronized (this) { + try { + this.wait(10); + } catch (InterruptedException e1) { + System.err.println(e1); + } + } + try { + obj.wait(10); + } catch (InterruptedException e2) { + System.err.println(e2); + } + } + this.notifyAll(); + } + obj.notify(); + } + try { + lock.wait(10); + } catch (InterruptedException e3) { + System.err.println(e3); + } + } + lock.notifyAll(); + } + } + }); + } + startTime = System.currentTimeMillis(); + for (int i = 0; i < tt.length; i++) { + tt[i].start(); + } + for (int i = 0; i < tt.length; i++) { + try { + tt[i].join(); + } catch (InterruptedException e) { + System.err.println(e); + } + } + endTime = System.currentTimeMillis(); + //System.out.println(startTime); + //System.out.println(endTime); + //System.out.println(endTime - startTime); + ThreadPerformance1Test[ii] = endTime - startTime; + } + for(int ii = 0; ii < ThreadPerformance1Test.length; ii++) { + sum += ThreadPerformance1Test[ii]; + } + ave = sum / ThreadPerformance1Test.length; + //System.out.println("ave=" + ave + "ms"); + System.out.println(0); + return; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/issue-RT0427-rt-Thread-ThreadStatenew/ThreadStateNewTest.java b/test/testsuite/ouroboros/thread_test/issue-RT0427-rt-Thread-ThreadStatenew/ThreadStateNewTest.java new file mode 100755 index 0000000000000000000000000000000000000000..6361dbd2cdf1a06bda7d2b845ccc008ca005409c --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/issue-RT0427-rt-Thread-ThreadStatenew/ThreadStateNewTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadStateNewTest + *- @TestCaseName: Thread_ThreadStateNewTest.java + *- @RequirementName: Java Thread + *- @Title/Destination: Test getState() return NEW when the thread have not start. + *- @Brief: see below + * -#step1: 用用例的类来new一个对象。 + * -#step2: 用对象调用getState()方法。 + * -#step3:确认返回NEW。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadStateNewTest.java + *- @ExecuteClass: ThreadStateNewTest + *- @ExecuteArgs: + */ + +public class ThreadStateNewTest extends Thread { + public static void main(String[] args) { + ThreadStateNewTest cls = new ThreadStateNewTest(); + if (cls.getState().toString().equals("NEW")) { + System.out.println(0); + return; + } + System.out.println(2); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/issue-RT0475-rt-Thread-GenerifyStackTraces/GenerifyStackTraces.java b/test/testsuite/ouroboros/thread_test/issue-RT0475-rt-Thread-GenerifyStackTraces/GenerifyStackTraces.java new file mode 100755 index 0000000000000000000000000000000000000000..af4e66d602708a0e8fbae1877ab1e16bc06118e8 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/issue-RT0475-rt-Thread-GenerifyStackTraces/GenerifyStackTraces.java @@ -0,0 +1,190 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: GenerifyStackTraces + *- @TestCaseName: Thread_GenerifyStackTraces.java + *- @RequirementName: Java Thread + *- @Title/Destination: Generified basic unit test of Thread.getAllStackTraces() + *- @Brief: see below + * -#step1: 定义ThreadOne类,该类继承Thread类,定义run函数,会调用wait()方法依次调用A,B,C方法,最后获取当前线程的栈信 + * 息,并检查。 + * -#step2: 定义DumpThread类,该类继承Thread类,定义run函数,等待ThreadOne阻塞获取栈信息,通知ThreadOne继续。 + * -#step3: New对象ThreadOne,通过start()方法启动run()。 + * -#step4: New对象DumpThread,通过start()方法启动run()。 + * -#step5: 等待ThreadOne对象运行结束。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: GenerifyStackTraces.java + *- @ExecuteClass: GenerifyStackTraces + *- @ExecuteArgs: + */ + +import java.util.*; + +public class GenerifyStackTraces { + private static Object go = new Object(); + private static String[] methodNames = {"run", "A", "B", "C", "Done"}; + private static int DONE_DEPTH = 5; + private static boolean testFailed = false; + private static Thread one; + private static boolean trace = false; + + public static void main(String[] args) throws Exception { + if (args.length > 0 && args[0].equals("trace")) { + trace = true; + } + + one = new ThreadOne(); + one.start(); + + DumpThread dt = new DumpThread(); + dt.start(); + + try { + one.join(); + } finally { + dt.shutdown(); + } + + if (testFailed) { + throw new RuntimeException("Test Failed."); + } + System.out.println(0); + } + + static class DumpThread extends Thread { + private volatile boolean finished = false; + + public void run() { + int depth = 2; + while (!finished) { + // At each iterator, wait until ThreadOne blocks to wait for thread dump. + // Then dump stack trace and notify ThreadOne to continue. + try { + sleep(2000); + dumpStacks(depth); + depth++; + finishDump(); + } catch (Exception e) { + e.printStackTrace(); + testFailed = true; + } + } + } + + public void shutdown() throws InterruptedException { + finished = true; + this.join(); + } + } + + static class ThreadOne extends Thread { + public void run() { + A(); + } + + private void A() { + waitForDump(); + B(); + } + + private void B() { + waitForDump(); + C(); + } + + private void C() { + waitForDump(); + Done(); + } + + private void Done() { + waitForDump(); + + // Get stack trace of current thread + StackTraceElement[] stack = getStackTrace(); + try { + checkStack(this, stack, DONE_DEPTH); + } catch (Exception e) { + e.printStackTrace(); + testFailed = true; + } + } + } + + static private void waitForDump() { + synchronized(go) { + try { + go.wait(); + } catch (Exception e) { + throw new RuntimeException("Unexpected exception" + e); + } + } + } + + static private void finishDump() { + synchronized(go) { + try { + go.notifyAll(); + } catch (Exception e) { + throw new RuntimeException("Unexpected exception" + e); + } + } + } + + public static void dumpStacks(int depth) throws Exception { + // Get stack trace of another thread + StackTraceElement[] stack = one.getStackTrace(); + checkStack(one, stack, depth); + + // Get stack traces of all Threads + for (Map.Entry entry : Thread.getAllStackTraces().entrySet()) { + Thread t = entry.getKey(); + stack = entry.getValue(); + if (t == null || stack == null) { + throw new RuntimeException("Null thread or stacktrace returned"); + } + if (t == one) { + checkStack(t, stack, depth); + } + } + } + + private static void checkStack(Thread t, StackTraceElement[] stack, int depth) throws Exception { + if (trace) { + printStack(t, stack); + } + int frame = stack.length - 1; + for (int i = 0; i < depth && frame >= 0; i++) { + if (! stack[frame].getMethodName().equals(methodNames[i])) { + throw new RuntimeException("Expected " + methodNames[i] + " in frame " + frame + " but got " + + stack[frame].getMethodName()); + } + frame--; + } + } + + private static void printStack(Thread t, StackTraceElement[] stack) { + System.out.println(t + " stack: (length = " + stack.length + ")"); + if (t != null) { + for (int j = 0; j < stack.length; j++) { + System.out.println(stack[j]); + } + System.out.println(); + } + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/issue-RT0508-rt-Thread-JGFSyncBench/JGFSyncBench.java b/test/testsuite/ouroboros/thread_test/issue-RT0508-rt-Thread-JGFSyncBench/JGFSyncBench.java new file mode 100755 index 0000000000000000000000000000000000000000..bac52243926a42ae7dd84d4ba165b346ef05bbb7 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/issue-RT0508-rt-Thread-JGFSyncBench/JGFSyncBench.java @@ -0,0 +1,399 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: JGFSyncBench + *- @TestCaseName: Thread_JGFSyncBench.java + *- @RequirementName: Java Thread + *- @Title/Destination: Get the time of thread sync. + *- @Brief: see below + * -#step1: 调用JGFInstrumentor.printHeader对header进行设置。 + * -#step2: 声明类JGFSyncBench实现自定义接口JGFSection1。 + * -#step3:创建nThreads+1个Runnable数组和Thread数组,线程里有synchronized同步锁。 + * -#step4: 打点开始时间,启动线程组线程,等待线程结束,打点结束时间,存储运行时间。 + * -#step5:重复步骤1~4 100000次。 + * -#step6:重复步骤1~5。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: JGFSyncBench.java + *- @ExecuteClass: JGFSyncBench + *- @ExecuteArgs: + */ + +import java.util.Hashtable; + +public class JGFSyncBench implements JGFSection1 { + public static int nThreads; + private static final int INITSIZE = 1000; + private static final int MAXSIZE = 100000; + private static final double TARGETTIME = 10.0; + + public JGFSyncBench(int nThreads) { + this.nThreads = nThreads; + } + + public void JGFRun() { + int i,size; + double time; + int counter = 0; + int shared_cont = 0; + + size=INITSIZE; + time = 0.0; + + Runnable thoObjects[] = new Runnable[nThreads + 1]; + Thread th[] = new Thread[nThreads + 1]; + CounterClass conTm = new CounterClass(shared_cont); + CounterClass conTo = new CounterClass(shared_cont); + JGFInstrumentor.addTimer("Section1:Sync:Method", "synchronisations"); + + while (size < MAXSIZE) { + JGFInstrumentor.resetTimer("Section1:Sync:Method"); + JGFInstrumentor.startTimer("Section1:Sync:Method"); + + for(i = 1; i < nThreads + 1; i++) { + thoObjects[i] = new SyncMethodRunner(i,conTm,size); + th[i] = new Thread(thoObjects[i]); + th[i].start(); + } + + thoObjects[0] = new SyncMethodRunner(0, conTm, size); + thoObjects[0].run(); + + for(i = 1; i < nThreads + 1; i++) { + try { + th[i].join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + } + + JGFInstrumentor.stopTimer("Section1:Sync:Method"); + time = JGFInstrumentor.readTimer("Section1:Sync:Method"); + JGFInstrumentor.addOpsToTimer("Section1:Sync:Method", (double) size); + size *= 2; + } + + JGFInstrumentor.printPerTimer("Section1:Sync:Method"); + + size = INITSIZE; + time = 0.0; + JGFInstrumentor.addTimer("Section1:Sync:Object", "synchronisations"); + + while (size < MAXSIZE) { + JGFInstrumentor.resetTimer("Section1:Sync:Object"); + JGFInstrumentor.startTimer("Section1:Sync:Object"); + + for(i = 1; i < nThreads + 1; i++) { + thoObjects[i] = new SyncObjectRunner(i, conTo, size); + th[i] = new Thread(thoObjects[i]); + th[i].start(); + } + + thoObjects[0] = new SyncObjectRunner(i, conTo, size); + thoObjects[0].run(); + + for(i = 1; i < nThreads + 1; i++) { + try { + th[i].join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + } + + JGFInstrumentor.stopTimer("Section1:Sync:Object"); + time = JGFInstrumentor.readTimer("Section1:Sync:Object"); + JGFInstrumentor.addOpsToTimer("Section1:Sync:Object",(double) size); + size *= 2; + } + JGFInstrumentor.printPerTimer("Section1:Sync:Object"); + } + + public static void main(String[] argv) { + nThreads = 4; + JGFInstrumentor.printHeader(1, 0, nThreads); + JGFSyncBench sb = new JGFSyncBench(nThreads); + sb.JGFRun(); + System.out.println(0); + } +} + +class CounterClass { + int shared_cont; + + public CounterClass(int shared_cont) { + this.shared_cont = shared_cont; + } + + public synchronized void update() { + shared_cont++; + } +} + +class SyncMethodRunner implements Runnable { + int id; + int size; + CounterClass cont; + + public SyncMethodRunner(int id, CounterClass cont ,int size) { + this.id = id; + this.cont = cont; + this.size = size; + } + + public void run() { + for(int i = 0; i < size; i++) { + cont.update(); + } + } +} + +class SyncObjectRunner implements Runnable { + int id; + int size; + CounterClass cont; + + public SyncObjectRunner(int id, CounterClass cont, int size) { + this.id = id; + this.cont = cont; + this.size = size; + } + + public void run() { + for(int i = 0; i < size; i++) { + synchronized(cont) { + cont.shared_cont++; + } + } + } +} + +class JGFInstrumentor{ + private static Hashtable timers; + private static Hashtable data; + + static { + timers = new Hashtable(); + data = new Hashtable(); + } + + public static synchronized void addTimer (String name) { + if (!timers.containsKey(name)) { + timers.put(name, new JGFTimer(name)); + } + } + + public static synchronized void addTimer (String name, String opname) { + if (!timers.containsKey(name)) { + timers.put(name, new JGFTimer(name,opname)); + } + } + + public static synchronized void addTimer (String name, String opname, int size) { + if (!timers.containsKey(name)) { + timers.put(name, new JGFTimer(name,opname,size)); + } + } + + public static synchronized void startTimer(String name) { + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).start(); + } + } + + public static synchronized void stopTimer(String name) { + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).stop(); + } + } + + public static synchronized void addOpsToTimer(String name, double count) { + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).addOps(count); + } + } + + public static synchronized void addTimeToTimer(String name, double added_time) { + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).addTime(added_time); + } + } + + public static synchronized double readTimer(String name) { + double time; + if (timers.containsKey(name)) { + time = ((JGFTimer) timers.get(name)).time; + } else { + time = 0.0; + } + return time; + } + + public static synchronized void resetTimer(String name) { + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).reset(); + } + } + + public static synchronized void printTimer(String name) { + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).print(); + } + } + + public static synchronized void printPerTimer(String name) { + if (timers.containsKey(name)) { + ((JGFTimer) timers.get(name)).printPer(); + } + } + + public static synchronized void storeData(String name, Object obj) { + data.put(name,obj); + } + + public static synchronized void retrieveData(String name, Object obj) { + obj = data.get(name); + } + + public static synchronized void printHeader(int section, int size,int nThreads) { + String header; + String base; + header = ""; + base = "Java Grande Forum Thread Benchmark Suite - Version 1.0 - Section "; + + switch (section) { + case 1: + header = base + "1"; + break; + case 2: + switch (size) { + case 0: + header = base + "2 - Size A"; + break; + case 1: + header = base + "2 - Size B"; + break; + case 2: + header = base + "2 - Size C"; + break; + } + break; + case 3: + switch (size) { + case 0: + header = base + "3 - Size A"; + break; + case 1: + header = base + "3 - Size B"; + break; + } + break; + } + } +} + +interface JGFSection1 { + public final int INITSIZE = 10000; + public final int MAXSIZE = 1000000000; + public final double TARGETTIME = 1.0; + public void JGFRun(); +} + +class JGFTimer { + public String name; + public String opName; + public double time; + public double opCount; + public long calls; + public int size = -1; + private long start_time; + private boolean on; + + public JGFTimer(String name, String opName) { + this.name = name; + this.opName = opName; + reset(); + } + + public JGFTimer(String name, String opName, int size) { + this.name = name; + this.opName = opName; + this.size = size; + reset(); + } + + public JGFTimer(String name) { + this(name,""); + } + + public void start() { + if (on) { + on = true; + } + start_time = System.currentTimeMillis(); + } + + public void stop() { + time += (double) (System.currentTimeMillis()-start_time) / 1000.; + if (!on) { + calls++; + } + on = false; + } + + public void addOps(double count) { + opCount += count; + } + + public void addTime(double added_time) { + time += added_time; + } + + public void reset() { + time = 0.0; + calls = 0; + opCount = 0; + on = false; + } + + public double per() { + return opCount / time; + } + + public void print() { + if (!opName.equals("")) { + switch(size) { + case 0: + break; + case 1: + break; + case 2: + break; + default: + break; + } + } + } + + public void printPer() { + String name; + name = this.name; + + // pad name to 40 characters + while ( name.length() < 40 ) { + name = name + " "; + } + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/issue-RT0577-rt-Thread-ThreadsetContextClassLoader2/ThreadSetContextClassLoader2.java b/test/testsuite/ouroboros/thread_test/issue-RT0577-rt-Thread-ThreadsetContextClassLoader2/ThreadSetContextClassLoader2.java new file mode 100755 index 0000000000000000000000000000000000000000..077b8352afcc26752c0f2dace5ac771324679905 --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/issue-RT0577-rt-Thread-ThreadsetContextClassLoader2/ThreadSetContextClassLoader2.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetContextClassLoader2 + *- @TestCaseName: Thread_ThreadSetContextClassLoader2.java + *- @RequirementName: Java Thread + *- @Title/Destination: Use setContextClassLoader(ClassLoader cl) to change the class loader of Thread. + *- @Brief: see below + * -#step1: 创建本用例类的对象,通过getContextClassLoader()获取对应的类加载器。 + * -#step2:调用setContextClassLoader(ClassLoader cl)来设置类的ClassLoader。 + * -#step3:调用start()启动对应的实例对象,等待线程运行结束。 + * -#step4:确认对应的加载器成功运行。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadSetContextClassLoader2.java + *- @ExecuteClass: ThreadSetContextClassLoader2 + *- @ExecuteArgs: + */ + +public class ThreadSetContextClassLoader2 extends Thread { + static int i; + + public static void main(String[] args) { + ThreadSetContextClassLoader2 threadSetContextClassLoader2 = new ThreadSetContextClassLoader2(); + ClassLoader cl = threadSetContextClassLoader2.getContextClassLoader(); + threadSetContextClassLoader2.setContextClassLoader(cl.getParent()); + + threadSetContextClassLoader2.start(); + try { + threadSetContextClassLoader2.join(); + } catch (InterruptedException e) { + System.out.println("Join is interrupted"); + } + + if (i == 1) { + if (threadSetContextClassLoader2.getContextClassLoader() != cl) { + System.out.println(0); + return; + } + } + System.out.println(2); + } + + public void run() { + i++; + super.run(); + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/thread_test/issue-RT0579-rt-Thread-ThreadsetName3/ThreadSetName3Test.java b/test/testsuite/ouroboros/thread_test/issue-RT0579-rt-Thread-ThreadsetName3/ThreadSetName3Test.java new file mode 100755 index 0000000000000000000000000000000000000000..80b1afc4fcafc4ab445feb06e0ecf41d220c61ad --- /dev/null +++ b/test/testsuite/ouroboros/thread_test/issue-RT0579-rt-Thread-ThreadsetName3/ThreadSetName3Test.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: ThreadSetName3Test + *- @TestCaseName: Thread_ThreadSetName3Test.java + *- @RequirementName: Java Thread + *- @Title/Destination: Negative input for setName(String name). + *- @Brief: see below + * -#step1: 创建两个线程分别为testName1,testName2。 + * -#step2:调用start()启动两个线程。 + * -#step3:创建参数name为空字符串,两个线程分别都调用setName(String name)。 + * -#step4:通过getName()检查设置成功。 + *- @Expect: 0\n + *- @Priority: High + *- @Source: ThreadSetName3Test.java + *- @ExecuteClass: ThreadSetName3Test + *- @ExecuteArgs: + */ + +public class ThreadSetName3Test extends Thread { + public static void main(String[] args) { + ThreadSetName3Test testName1 = new ThreadSetName3Test(); + ThreadSetName3Test testName2 = new ThreadSetName3Test(); + testName1.start(); + testName1.setName(""); + testName2.start(); + testName2.setName(""); + + if (testName1.getName().equals("")) { + if (testName1.getName().equals("")) { + System.out.println(0); + return; + } + } + System.out.println(2); + return; + } +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0001-rt-unsafe-UnsafegetIntVolatileTest/UnsafegetIntVolatileTest.java b/test/testsuite/ouroboros/unsafe_test/RT0001-rt-unsafe-UnsafegetIntVolatileTest/UnsafegetIntVolatileTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3dd6053985d5d62263692271a888390890eaecac --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0001-rt-unsafe-UnsafegetIntVolatileTest/UnsafegetIntVolatileTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetIntVolatileTest + * -@TestCaseName: Unsafe api: getIntvolatile() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:getobjectFieldOffset + * -#step2:Unsafe.getIntVolatile of step1 + * -#step3:get result as step1 set + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetIntVolatileTest.java + * -@ExecuteClass: UnsafegetIntVolatileTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.TreeSet; + +public class UnsafegetIntVolatileTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetIntVolatileTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetIntVolatileTest.res -= 2; + } + + if (result == 3 && UnsafegetIntVolatileTest.res == 97) { + result =0; + } + return result; + } + + + private static int UnsafegetIntVolatileTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + int result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie6.class.getDeclaredField("age"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie6(); + result = unsafe.getIntVolatile(obj, offset); + if (result == 18) { + UnsafegetIntVolatileTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} +class Billie6 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0002-rt-unsafe-UnsafeallocateMemoryTest/UnsafeallocateMemoryTest.java b/test/testsuite/ouroboros/unsafe_test/RT0002-rt-unsafe-UnsafeallocateMemoryTest/UnsafeallocateMemoryTest.java new file mode 100755 index 0000000000000000000000000000000000000000..cc15b1fd430be37a17e41240db43286d494ef809 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0002-rt-unsafe-UnsafeallocateMemoryTest/UnsafeallocateMemoryTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeallocateMemoryTest + * -@TestCaseName: Unsafe api: allocateMemoary() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief:invoke Unsafe.allocateMemory to get Memory success + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeallocateMemoryTest.java + * -@ExecuteClass: UnsafeallocateMemoryTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeallocateMemoryTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeallocateMemoryTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeallocateMemoryTest.res -= 2; + } + + if (result == 3 && UnsafeallocateMemoryTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeallocateMemoryTest_1() { + Unsafe unsafe; + Field field; + long address; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(4); +// System.out.println(address); + UnsafeallocateMemoryTest.res -= 2; + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0003-rt-unsafe-UnsafearrayBaseOffsetTest/UnsafearrayBaseOffsetTest.java b/test/testsuite/ouroboros/unsafe_test/RT0003-rt-unsafe-UnsafearrayBaseOffsetTest/UnsafearrayBaseOffsetTest.java new file mode 100755 index 0000000000000000000000000000000000000000..eb159adb1a28139765608c5addbe860f0bda973a --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0003-rt-unsafe-UnsafearrayBaseOffsetTest/UnsafearrayBaseOffsetTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafearrayBaseOffsetTest + * -@TestCaseName: Unsafe api: arrayBaseOffset() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare array + * -#step2:get offset of array + * -#step3:check return value by getInt,compare step1 + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafearrayBaseOffsetTest.java + * -@ExecuteClass: UnsafearrayBaseOffsetTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafearrayBaseOffsetTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafearrayFieldOffsetTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafearrayBaseOffsetTest.res = UnsafearrayBaseOffsetTest.res - 10; + } +// System.out.println(result); +// System.out.println(UnsafearrayBaseOffsetTest.res); + if (result == 3 && UnsafearrayBaseOffsetTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafearrayFieldOffsetTest_1() { + Unsafe unsafe; + Field field; + Object obj; + long offset; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe) field.get(null); + obj = new int[]{101, 2, 3}; + offset = unsafe.arrayBaseOffset(obj.getClass()); + int result = unsafe.getInt(obj, offset); + if (result == 101) { + UnsafearrayBaseOffsetTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0004-rt-unsafe-UnsafearrayIndexScaleTest/UnsafearrayIndexScaleTest.java b/test/testsuite/ouroboros/unsafe_test/RT0004-rt-unsafe-UnsafearrayIndexScaleTest/UnsafearrayIndexScaleTest.java new file mode 100755 index 0000000000000000000000000000000000000000..4bad0ffb67e4f8593ca1ad7c8c8ae57444c9430d --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0004-rt-unsafe-UnsafearrayIndexScaleTest/UnsafearrayIndexScaleTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafearrayBaseOffsetTest + * -@TestCaseName: Unsafe api: arrayBaseOffset() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare arrys[N] + * -#step2:use arrayBaseOffset+index*arrayIndexScale to visit arrays + * -#step3:get corrt value + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafearrayIndexScaleTest.java + * -@ExecuteClass: UnsafearrayIndexScaleTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafearrayIndexScaleTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafearrayIndexSacleTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafearrayIndexScaleTest.res = UnsafearrayIndexScaleTest.res - 10; + } +// System.out.println(result); +// System.out.println(UnsafearrayBaseOffsetTest.res); + if (result == 3 && UnsafearrayIndexScaleTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafearrayIndexSacleTest_1() { + Unsafe unsafe; + Field field; + Object obj; + long scale; + long offset; + long result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + obj = new long[]{9, 8, 7, 6}; + scale = unsafe.arrayIndexScale(obj.getClass()); + offset = unsafe.arrayBaseOffset(obj.getClass()); + result = unsafe.getLong(obj, offset + 2*scale); + if (result == 7) { + UnsafearrayIndexScaleTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } + +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0005-rt-unsafe-UnsafecompareAndSwapIntTest/UnsafecompareAndSwapIntTest.java b/test/testsuite/ouroboros/unsafe_test/RT0005-rt-unsafe-UnsafecompareAndSwapIntTest/UnsafecompareAndSwapIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8a1908640e038a9eff0a2afee63a47a4b19c4e47 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0005-rt-unsafe-UnsafecompareAndSwapIntTest/UnsafecompareAndSwapIntTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafecompareAndSwapIntTest + * -@TestCaseName: Unsafe api: compareAndSwapInt() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare Field height = 8(int type) + * -#step2:invoke Unsafe.compareAndSwapInt to swap value of step1 + * -#step3:swap success + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafecompareAndSwapIntTest.java + * -@ExecuteClass: UnsafecompareAndSwapIntTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafecompareAndSwapIntTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafecompareAndSwapIntTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafecompareAndSwapIntTest.res = UnsafecompareAndSwapIntTest.res - 10; + } +// System.out.println(result); +// System.out.println(UnsafearrayBaseOffsetTest.res); + if (result == 3 && UnsafecompareAndSwapIntTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafecompareAndSwapIntTest_1() { + Unsafe unsafe; + Field field; + Field param; + Object obj; + long scale; + long offset; + int result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + obj = new Billie3(); + param = Billie3.class.getDeclaredField("height"); + offset = unsafe.objectFieldOffset(param); + unsafe.compareAndSwapInt(obj, offset, 8, 10); + result = unsafe.getInt(obj, offset); + if (result == 10) { + UnsafecompareAndSwapIntTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie3 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0006-rt-unsafe-UnsafecompareAndSwapLongTest/UnsafecompareAndSwapLongTest.java b/test/testsuite/ouroboros/unsafe_test/RT0006-rt-unsafe-UnsafecompareAndSwapLongTest/UnsafecompareAndSwapLongTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ae75d238949c4361b0b9cbddf29ee4b0c42021e7 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0006-rt-unsafe-UnsafecompareAndSwapLongTest/UnsafecompareAndSwapLongTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafecompareAndSwapLongTest + * -@TestCaseName: Unsafe api: compareAndSwapLong() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare Field weight = 100L(long type) + * -#step2:invoke Unsafe.compareAndSwapLong to swap value of step1 + * -#step3:swap success + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafecompareAndSwapLongTest.java + * -@ExecuteClass: UnsafecompareAndSwapLongTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafecompareAndSwapLongTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafecompareAndSwapLongTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafecompareAndSwapLongTest.res = UnsafecompareAndSwapLongTest.res - 10; + } +// System.out.println(result); +// System.out.println(UnsafearrayBaseOffsetTest.res); + if (result == 3 && UnsafecompareAndSwapLongTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafecompareAndSwapLongTest_1() { + Unsafe unsafe; + Field field; + Field param; + Object obj; + long offset; + long result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + obj = new Billie4(); + param = Billie4.class.getDeclaredField("weight"); + offset = unsafe.objectFieldOffset(param); + unsafe.compareAndSwapLong(obj, offset, 100L, 200L); + result = unsafe.getLong(obj, offset); + if (result == 200L) { + UnsafecompareAndSwapLongTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie4 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0007-rt-unsafe-UnsafecompareAndSwapObjectTest/UnsafecompareAndSwapObjectTest.java b/test/testsuite/ouroboros/unsafe_test/RT0007-rt-unsafe-UnsafecompareAndSwapObjectTest/UnsafecompareAndSwapObjectTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ca4c56486af961412d9d022fe16691f7e65e88e1 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0007-rt-unsafe-UnsafecompareAndSwapObjectTest/UnsafecompareAndSwapObjectTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafecompareAndSwapObjectTest + * -@TestCaseName: Unsafe api: compareAndSwapObject() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare Field owner = "Me"(Object) + * -#step2:invoke Unsafe.compareAndSwapObject to swap value of step1 + * -#step3:swap success + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafecompareAndSwapObjectTest.java + * -@ExecuteClass: UnsafecompareAndSwapObjectTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafecompareAndSwapObjectTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafecompareAndSwapObjectTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafecompareAndSwapObjectTest.res = UnsafecompareAndSwapObjectTest.res - 10; + } +// System.out.println(result); +// System.out.println(UnsafearrayBaseOffsetTest.res); + if (result == 3 && UnsafecompareAndSwapObjectTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafecompareAndSwapObjectTest_1() { + Unsafe unsafe; + Field field; + Field param; + Object obj; + long offset; + Object result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + obj = new Billie5(); + param = Billie5.class.getDeclaredField("owner"); + offset = unsafe.objectFieldOffset(param); + unsafe.compareAndSwapObject(obj, offset, "Me", "billie5"); + result = unsafe.getObject(obj, offset); + if (result.equals("billie5")) { + UnsafecompareAndSwapObjectTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie5 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0008-rt-unsafe-UnsafecopyMemoryTest/UnsafecopyMemoryTest.java b/test/testsuite/ouroboros/unsafe_test/RT0008-rt-unsafe-UnsafecopyMemoryTest/UnsafecopyMemoryTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ceb9ff512df6ffef119b56c90b8243dac92a07c6 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0008-rt-unsafe-UnsafecopyMemoryTest/UnsafecopyMemoryTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafecopyMemoryTest + * -@TestCaseName: Unsafe api: copyMemory(long srcAddr, long dstAddr, long bytes) + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:allocateMemory to put value + * -#step2:copyMemory from step1 + * -#step3:get value from step2,should be same as step1 put + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafecopyMemoryTest.java + * -@ExecuteClass: UnsafecopyMemoryTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +public class UnsafecopyMemoryTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafecopyMemoryTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafecopyMemoryTest.res -= 2; + } + + if (result == 3 && UnsafecopyMemoryTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafecopyMemoryTest_1() { + Unsafe unsafe; + Field field; + long address1; + long address2; + byte result; + Method m; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address1 = unsafe.allocateMemory(5); + byte b = 101; + unsafe.putByte(address1, b); + address2 = unsafe.allocateMemory(5); + unsafe.copyMemory(address1, address2, 5); +// System.out.println(Arrays.toString(bytes)); + result = unsafe.getByte(address2); +// System.out.println(result); + if (result == 101) { + UnsafecopyMemoryTest.res -= 2; + } + + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0009-rt-unsafe-UnsafefreeMemoryTest/UnsafefreeMemoryTest.java b/test/testsuite/ouroboros/unsafe_test/RT0009-rt-unsafe-UnsafefreeMemoryTest/UnsafefreeMemoryTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f1d2c0ff124080075c606a7d8bc44fc817aeaf10 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0009-rt-unsafe-UnsafefreeMemoryTest/UnsafefreeMemoryTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeallocateMemoryTest + * -@TestCaseName: Unsafe api: allocateMemoary() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief:Unsafe.freeMemory sucess + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafefreeMemoryTest.java + * -@ExecuteClass: UnsafefreeMemoryTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafefreeMemoryTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafefreeMemoryTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafefreeMemoryTest.res -= 2; + } + + if (result == 3 && UnsafefreeMemoryTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafefreeMemoryTest_1() { + Unsafe unsafe; + Field field; + long address; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(4); +// System.out.println(address); + unsafe.freeMemory(address); + UnsafefreeMemoryTest.res -= 2; + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0010-rt-unsafe-UnsafegetAndAddIntTest/UnsafegetAndAddIntTest.java b/test/testsuite/ouroboros/unsafe_test/RT0010-rt-unsafe-UnsafegetAndAddIntTest/UnsafegetAndAddIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3111a7b8fcd7007a562b53668b0e6e972ca04b68 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0010-rt-unsafe-UnsafegetAndAddIntTest/UnsafegetAndAddIntTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetAndAddIntTest + * -@TestCaseName: Unsafe api: getAndAddInt() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare Field height = 8(int type) + * -#step2:invoke Unsafe.getAndAddInt to add one value + * -#step3:check the Field,add success + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetAndAddIntTest.java + * -@ExecuteClass: UnsafegetAndAddIntTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetAndAddIntTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetAndAddIntTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetAndAddIntTest.res -= 2; + } + + if (result == 3 && UnsafegetAndAddIntTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetAndAddIntTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + int result; + int result2; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie35.class.getDeclaredField("height"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie35(); + result = unsafe.getAndAddInt(obj, offset, 20); +// System.out.println(result); + result2 = unsafe.getInt(obj, offset); +// System.out.println(result2); + if (result == 8 && result2 == 28) { + UnsafegetAndAddIntTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie35 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0011-rt-unsafe-UnsafegetAndAddLongTest/UnsafegetAndAddLongTest.java b/test/testsuite/ouroboros/unsafe_test/RT0011-rt-unsafe-UnsafegetAndAddLongTest/UnsafegetAndAddLongTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b6fd5749da4130faccbd311aeb010c388f0dd7a6 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0011-rt-unsafe-UnsafegetAndAddLongTest/UnsafegetAndAddLongTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetAndAddIntTest + * -@TestCaseName: Unsafe api: getAndAddInt() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare Field weight = 100L(long type) + * -#step2:invoke Unsafe.getAndAddLong to add one value + * -#step3:check the Field,add success + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetAndAddLongTest.java + * -@ExecuteClass: UnsafegetAndAddLongTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetAndAddLongTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetAndAddLongTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetAndAddLongTest.res -= 2; + } + + if (result == 3 && UnsafegetAndAddLongTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetAndAddLongTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + long result; + long result2; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie37.class.getDeclaredField("weight"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie37(); + result = unsafe.getAndAddLong(obj, offset, 1L); +// System.out.println(result); + result2 = unsafe.getLong(obj, offset); +// System.out.println(result2); + if (result == 100 && result2 == 101) { + UnsafegetAndAddLongTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie37 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0012-rt-unsafe-UnsafegetAndSetIntTest/UnsafegetAndSetIntTest.java b/test/testsuite/ouroboros/unsafe_test/RT0012-rt-unsafe-UnsafegetAndSetIntTest/UnsafegetAndSetIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..548cad92fefa281a2814da212f369aa909fb20c4 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0012-rt-unsafe-UnsafegetAndSetIntTest/UnsafegetAndSetIntTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetAndSetIntTest + * -@TestCaseName: Unsafe api: getAndSetInt() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare Field height = 8(int type) + * -#step2:invoke Unsafe.getAndSetInt to set another value + * -#step3:check the Field,modify success + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetAndSetIntTest.java + * -@ExecuteClass: UnsafegetAndSetIntTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafegetAndSetIntTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetAndSetIntTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetAndSetIntTest.res -= 2; + } + + if (result == 3 && UnsafegetAndSetIntTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetAndSetIntTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + int result; + int result2; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie36.class.getDeclaredField("height"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie36(); + result = unsafe.getAndSetInt(obj, offset, 20); +// System.out.println(result); + result2 = unsafe.getInt(obj, offset); +// System.out.println(result2); + if (result == 8 && result2 == 20) { + UnsafegetAndSetIntTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie36 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0013-rt-unsafe-UnsafegetAndSetLongTest/UnsafegetAndSetLongTest.java b/test/testsuite/ouroboros/unsafe_test/RT0013-rt-unsafe-UnsafegetAndSetLongTest/UnsafegetAndSetLongTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d2fce1836dc499d7a0ec149ba7b4b75382265034 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0013-rt-unsafe-UnsafegetAndSetLongTest/UnsafegetAndSetLongTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetAndSetLongTest + * -@TestCaseName: Unsafe api: getAndSetLong() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare Field weight = 100L(Long type) + * -#step2:invoke Unsafe.getAndSetLong to set another value + * -#step3:check the Field,modify success + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetAndSetLongTest.java + * -@ExecuteClass: UnsafegetAndSetLongTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafegetAndSetLongTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetAndSetLongTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetAndSetLongTest.res -= 2; + } + + if (result == 3 && UnsafegetAndSetLongTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetAndSetLongTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + long result; + long result2; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie38.class.getDeclaredField("weight"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie38(); + result = unsafe.getAndSetLong(obj, offset, 99L); +// System.out.println(result); + result2 = unsafe.getInt(obj, offset); +// System.out.println(result2); + if (result == 100 && result2 == 99) { + UnsafegetAndSetLongTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie38 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0014-rt-unsafe-UnsafegetAndSetObjectTest/UnsafegetAndSetObjectTest.java b/test/testsuite/ouroboros/unsafe_test/RT0014-rt-unsafe-UnsafegetAndSetObjectTest/UnsafegetAndSetObjectTest.java new file mode 100755 index 0000000000000000000000000000000000000000..5dd4a1c2b0fbc8dab7d8ff8cbba34404f9ad0d53 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0014-rt-unsafe-UnsafegetAndSetObjectTest/UnsafegetAndSetObjectTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetAndSetObjectTest + * -@TestCaseName: Unsafe api: getAndSetObject() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare Field private String owner = "Me"(Object type) + * -#step2:invoke Unsafe.getAndSetObject to add another value + * -#step3:check the Field,modify success + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetAndSetObjectTest.java + * -@ExecuteClass: UnsafegetAndSetObjectTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafegetAndSetObjectTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetAndSetObjectTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetAndSetObjectTest.res -= 2; + } + + if (result == 3 && UnsafegetAndSetObjectTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetAndSetObjectTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Object result; + Object result2; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie39.class.getDeclaredField("owner"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie39(); + result = unsafe.getAndSetObject(obj, offset, "she"); +// System.out.println(result); + result2 = unsafe.getObject(obj, offset); +// System.out.println(result2); + if (result.equals("Me") && result2.equals("she")) { + UnsafegetAndSetObjectTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie39 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0015-rt-unsafe-UnsafegetBooleanTest/UnsafegetBooleanTest.java b/test/testsuite/ouroboros/unsafe_test/RT0015-rt-unsafe-UnsafegetBooleanTest/UnsafegetBooleanTest.java new file mode 100755 index 0000000000000000000000000000000000000000..cb219b7765bbe892f785b54a2c5b8b8286430089 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0015-rt-unsafe-UnsafegetBooleanTest/UnsafegetBooleanTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetBooleanTest + * -@TestCaseName: Unsafe api: getBoolean() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Boolean + * -#step2:invoke Unsafe.getBoolean to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetBooleanTest.java + * -@ExecuteClass: UnsafegetBooleanTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetBooleanTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetBooleanTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetBooleanTest.res -= 2; + } + + if (result == 3 && UnsafegetBooleanTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetBooleanTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + boolean result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie21.class.getDeclaredField("gender"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie21(); + result = unsafe.getBoolean(obj, offset); + if (!result) { + UnsafegetBooleanTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie21 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0016-rt-unsafe-UnsafegetCharByAddressTest/UnsafegetCharByAddressTest.java b/test/testsuite/ouroboros/unsafe_test/RT0016-rt-unsafe-UnsafegetCharByAddressTest/UnsafegetCharByAddressTest.java new file mode 100755 index 0000000000000000000000000000000000000000..01beecf81f3855f99edf1284deae55bb781596f6 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0016-rt-unsafe-UnsafegetCharByAddressTest/UnsafegetCharByAddressTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetCharByAddressTest + * -@TestCaseName: Unsafe api: getChar(address) + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:allocateMemory for one Field of Char + * -#step2:set value of Field from step1 + * -#step3:invoke Unsafe.getChar(address) to visit this Field + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetCharByAddressTest.java + * -@ExecuteClass: UnsafegetCharByAddressTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafegetCharByAddressTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetCharByAddressTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetCharByAddressTest.res -= 2; + } + + if (result == 3 && UnsafegetCharByAddressTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetCharByAddressTest_1() { + Unsafe unsafe; + Field field; + long address; + char result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(2); +// System.out.println(address); + char c = 'a'; + unsafe.putChar(address, c); + result = unsafe.getChar(address); +// System.out.println(result); + if (result == c) { + UnsafegetCharByAddressTest.res -= 2; + } + + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0017-rt-unsafe-UnsafegetCharTest/UnsafegetCharTest.java b/test/testsuite/ouroboros/unsafe_test/RT0017-rt-unsafe-UnsafegetCharTest/UnsafegetCharTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d5da44ea297a1611ebffc62d1c02f588c8f63d16 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0017-rt-unsafe-UnsafegetCharTest/UnsafegetCharTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetCharTest + * -@TestCaseName: Unsafe api: getChar() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Char + * -#step2:invoke Unsafe.getChar to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetCharTest.java + * -@ExecuteClass: UnsafegetCharTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetCharTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetCharTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetCharTest.res -= 2; + } + + if (result == 3 && UnsafegetCharTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetCharTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + char result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie25.class.getDeclaredField("favorite"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie25(); + result = unsafe.getChar(obj, offset); + if (result == '7') { + UnsafegetCharTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie25 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; + private char favorite = '7'; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0018-rt-unsafe-UnsafegetDoubleByAddressTest/UnsafegetDoubleByAddressTest.java b/test/testsuite/ouroboros/unsafe_test/RT0018-rt-unsafe-UnsafegetDoubleByAddressTest/UnsafegetDoubleByAddressTest.java new file mode 100755 index 0000000000000000000000000000000000000000..e4b395ebfda4e2e92e9ba1d60cd3e5025db1600e --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0018-rt-unsafe-UnsafegetDoubleByAddressTest/UnsafegetDoubleByAddressTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetDoubleByAddressTest + * -@TestCaseName: Unsafe api: getDouble(address) + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:allocateMemory for one Field of Double + * -#step2:set value of Field from step1 + * -#step3:invoke Unsafe.getDouble(address) to visit this Field + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetDoubleByAddressTest.java + * -@ExecuteClass: UnsafegetDoubleByAddressTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafegetDoubleByAddressTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetDoubleByAddressTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetDoubleByAddressTest.res -= 2; + } + + if (result == 3 && UnsafegetDoubleByAddressTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetDoubleByAddressTest_1() { + Unsafe unsafe; + Field field; + long address; + double result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(2); +// System.out.println(address); + double d = 111; + unsafe.putDouble(address, d); + result = unsafe.getDouble(address); +// System.out.println(result); + if (result == d) { + UnsafegetDoubleByAddressTest.res -= 2; + } + + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0019-rt-unsafe-UnsafegetDoubleTest/UnsafegetDoubleTest.java b/test/testsuite/ouroboros/unsafe_test/RT0019-rt-unsafe-UnsafegetDoubleTest/UnsafegetDoubleTest.java new file mode 100755 index 0000000000000000000000000000000000000000..8167c5166e7965f746c31f27a6fb455094d29b73 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0019-rt-unsafe-UnsafegetDoubleTest/UnsafegetDoubleTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetDoubleTest + * -@TestCaseName: Unsafe api: getDouble() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Double + * -#step2:invoke Unsafe.getDouble to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetDoubleTest.java + * -@ExecuteClass: UnsafegetDoubleTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetDoubleTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetDoubleTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetDoubleTest.res -= 2; + } + + if (result == 3 && UnsafegetDoubleTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetDoubleTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + double result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie29.class.getDeclaredField("grade"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie29(); + result = unsafe.getDouble(obj, offset); + if (result == 99.99) { + UnsafegetDoubleTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie29 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; + private char favorite = '7'; + private short date = 6; + private double grade = 99.99; + private float aFloat = 66.66f; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0020-rt-unsafe-UnsafegetFloatByAddressTest/UnsafegetFloatByAddressTest.java b/test/testsuite/ouroboros/unsafe_test/RT0020-rt-unsafe-UnsafegetFloatByAddressTest/UnsafegetFloatByAddressTest.java new file mode 100755 index 0000000000000000000000000000000000000000..40b27515cb0683e57d6c0ac2544bc99ad6da693a --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0020-rt-unsafe-UnsafegetFloatByAddressTest/UnsafegetFloatByAddressTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetFloatByAddressTest + * -@TestCaseName: Unsafe api: getFloat(Address) + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:allocateMemory for one Field of Float + * -#step2:set value of Field from step1 + * -#step3:invoke Unsafe.getFloat(address) to visit this Field + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetFloatByAddressTest.java + * -@ExecuteClass: UnsafegetFloatByAddressTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafegetFloatByAddressTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetFloatByAddressTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetFloatByAddressTest.res -= 2; + } + + if (result == 3 && UnsafegetFloatByAddressTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetFloatByAddressTest_1() { + Unsafe unsafe; + Field field; + long address; + float result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(2); +// System.out.println(address); + float f = 111f; + unsafe.putFloat(address, f); + result = unsafe.getFloat(address); +// System.out.println(result); + if (result == f) { + UnsafegetFloatByAddressTest.res -= 2; + } + + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0021-rt-unsafe-UnsafegetFloatTest/UnsafegetFloatTest.java b/test/testsuite/ouroboros/unsafe_test/RT0021-rt-unsafe-UnsafegetFloatTest/UnsafegetFloatTest.java new file mode 100755 index 0000000000000000000000000000000000000000..e098ae9b394f069435841ed334e8eda449253927 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0021-rt-unsafe-UnsafegetFloatTest/UnsafegetFloatTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetFloatTest + * -@TestCaseName: Unsafe api: getFloat() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Float + * -#step2:invoke Unsafe.getFloat to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetFloatTest.java + * -@ExecuteClass: UnsafegetFloatTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetFloatTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetFloatTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetFloatTest.res -= 2; + } + + if (result == 3 && UnsafegetFloatTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetFloatTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Float result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie31.class.getDeclaredField("aFloat"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie31(); + result = unsafe.getFloat(obj, offset); + if (result == 66.66f) { + UnsafegetFloatTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie31 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; + private char favorite = '7'; + private short date = 6; + private double grade = 99.99; + private float aFloat = 66.66f; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0022-rt-unsafe-UnsafegetIntByAddressTest/UnsafegetIntByAddressTest.java b/test/testsuite/ouroboros/unsafe_test/RT0022-rt-unsafe-UnsafegetIntByAddressTest/UnsafegetIntByAddressTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ea01a5988b36d8dd17891536a239a8640d46681a --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0022-rt-unsafe-UnsafegetIntByAddressTest/UnsafegetIntByAddressTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetIntByAddressTest + * -@TestCaseName: Unsafe api: getInt(address) + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:allocateMemory for one Int of Char + * -#step2:set value of Field from step1 + * -#step3:invoke Unsafe.getInt(address) to visit this Field + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetIntByAddressTest.java + * -@ExecuteClass: UnsafegetIntByAddressTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafegetIntByAddressTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetIntByAddressTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetIntByAddressTest.res -= 2; + } + + if (result == 3 && UnsafegetIntByAddressTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetIntByAddressTest_1() { + Unsafe unsafe; + Field field; + long address; + int result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(2); +// System.out.println(address); + int i = 111; + unsafe.putInt(address, i); + result = unsafe.getInt(address); +// System.out.println(result); + if (result == i) { + UnsafegetIntByAddressTest.res -= 2; + } + + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0023-rt-unsafe-UnsafegetIntTest/UnsafegetIntTest.java b/test/testsuite/ouroboros/unsafe_test/RT0023-rt-unsafe-UnsafegetIntTest/UnsafegetIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..d30abe2cb81e9363f5e616c2140bf73932738281 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0023-rt-unsafe-UnsafegetIntTest/UnsafegetIntTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetIntTest + * -@TestCaseName: Unsafe api: getInt() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Int + * -#step2:invoke Unsafe.getInt to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetIntTest.java + * -@ExecuteClass: UnsafegetIntTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetIntTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetIntTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetIntTest.res -= 2; + } + + if (result == 3 && UnsafegetIntTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetIntTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + int result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie12.class.getDeclaredField("height"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie12(); + result = unsafe.getInt(obj, offset); + if (result == 8) { + UnsafegetIntTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie12 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0024-rt-unsafe-UnsafegetLongTest/UnsafegetLongTest.java b/test/testsuite/ouroboros/unsafe_test/RT0024-rt-unsafe-UnsafegetLongTest/UnsafegetLongTest.java new file mode 100755 index 0000000000000000000000000000000000000000..a8031f026bd8de265c032dfd74e5edf8cc51e901 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0024-rt-unsafe-UnsafegetLongTest/UnsafegetLongTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetLongTest + * -@TestCaseName: Unsafe api: getLong() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Long + * -#step2:invoke Unsafe.getLong to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetLongTest.java + * -@ExecuteClass: UnsafegetLongTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetLongTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetLongTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetLongTest.res -= 2; + } + + if (result == 3 && UnsafegetLongTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetLongTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Long result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie15.class.getDeclaredField("weight"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie15(); + result = unsafe.getLong(obj, offset); + if (result == 100L) { + UnsafegetLongTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie15 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0025-rt-unsafe-UnsafegetLongVolatileTest/UnsafegetLongVolatileTest.java b/test/testsuite/ouroboros/unsafe_test/RT0025-rt-unsafe-UnsafegetLongVolatileTest/UnsafegetLongVolatileTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2ecf0a12858f3908463c499f1f9873b9aadbc646 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0025-rt-unsafe-UnsafegetLongVolatileTest/UnsafegetLongVolatileTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetLongVolatileTest + * -@TestCaseName: Unsafe api: getLongvolatile() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Volatile&Long + * -#step2:invoke Unsafe.getLong to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetLongVolatileTest.java + * -@ExecuteClass: UnsafegetLongVolatileTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetLongVolatileTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetLongVolatileTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetLongVolatileTest.res -= 2; + } + + if (result == 3 && UnsafegetLongVolatileTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetLongVolatileTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Long result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie8.class.getDeclaredField("birth"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie8(); + result = unsafe.getLongVolatile(obj, offset); + if (result == 20010214L) { + UnsafegetLongVolatileTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie8 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0026-rt-unsafe-UnsafegetObjectTest/UnsafegetObjectTest.java b/test/testsuite/ouroboros/unsafe_test/RT0026-rt-unsafe-UnsafegetObjectTest/UnsafegetObjectTest.java new file mode 100755 index 0000000000000000000000000000000000000000..22da06010e92e5db4f85c7a4d4715bace316caaf --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0026-rt-unsafe-UnsafegetObjectTest/UnsafegetObjectTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetObjectTest + * -@TestCaseName: Unsafe api: getObject() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Object + * -#step2:invoke Unsafe.getObject to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetObjectTest.java + * -@ExecuteClass: UnsafegetObjectTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetObjectTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetObjectTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetObjectTest.res -= 2; + } + + if (result == 3 && UnsafegetObjectTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetObjectTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Object result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie18.class.getDeclaredField("owner"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie18(); + result = unsafe.getObject(obj, offset); + if (result.equals("Me")) { + UnsafegetObjectTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie18 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0027-rt-unsafe-UnsafegetObjectVolatileTest/UnsafegetObjectVolatileTest.java b/test/testsuite/ouroboros/unsafe_test/RT0027-rt-unsafe-UnsafegetObjectVolatileTest/UnsafegetObjectVolatileTest.java new file mode 100755 index 0000000000000000000000000000000000000000..bc25b224f144ae7dd9da39792c2dc0b9992371b9 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0027-rt-unsafe-UnsafegetObjectVolatileTest/UnsafegetObjectVolatileTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetObjectVolatileTest + * -@TestCaseName: Unsafe api: getObjectvolatile() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Volatile&Object + * -#step2:invoke Unsafe.getObject to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetObjectVolatileTest.java + * -@ExecuteClass: UnsafegetObjectVolatileTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetObjectVolatileTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetObjectVolatileTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetObjectVolatileTest.res -= 2; + } + + if (result == 3 && UnsafegetObjectVolatileTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetObjectVolatileTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Object result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie10.class.getDeclaredField("lastname"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie10(); + result = unsafe.getObjectVolatile(obj, offset); + if (result.equals("eilish")) { + UnsafegetObjectVolatileTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie10 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0028-rt-unsafe-UnsafegetShortByAddressTest/UnsafegetShortByAddressTest.java b/test/testsuite/ouroboros/unsafe_test/RT0028-rt-unsafe-UnsafegetShortByAddressTest/UnsafegetShortByAddressTest.java new file mode 100755 index 0000000000000000000000000000000000000000..135e2ff66099f6a7b71823af1cb7fbee0a5756b7 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0028-rt-unsafe-UnsafegetShortByAddressTest/UnsafegetShortByAddressTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetShortByAddressTest + * -@TestCaseName: Unsafe api: getShort(address) + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:allocateMemory for one Field of Short + * -#step2:set value of Field from step1 + * -#step3:invoke Unsafe.getShort(address) to visit this Field + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetShortByAddressTest.java + * -@ExecuteClass: UnsafegetShortByAddressTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafegetShortByAddressTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetShortByAddressTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetShortByAddressTest.res -= 2; + } + + if (result == 3 && UnsafegetShortByAddressTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetShortByAddressTest_1() { + Unsafe unsafe; + Field field; + long address; + short result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(2); +// System.out.println(address); + short s = 1; + unsafe.putShort(address, s); + result = unsafe.getShort(address); +// System.out.println(result); + if (result == s) { + UnsafegetShortByAddressTest.res -= 2; + } + + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0029-rt-unsafe-UnsafegetShortTest/UnsafegetShortTest.java b/test/testsuite/ouroboros/unsafe_test/RT0029-rt-unsafe-UnsafegetShortTest/UnsafegetShortTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b95ab19b81f5204d48c5fea891bb7fa0d38ebd08 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0029-rt-unsafe-UnsafegetShortTest/UnsafegetShortTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetShortTest + * -@TestCaseName: Unsafe api: getShort() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Short + * -#step2:invoke Unsafe.getShort to visit this Field + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetShortTest.java + * -@ExecuteClass: UnsafegetShortTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetShortTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetShortTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetShortTest.res -= 2; + } + + if (result == 3 && UnsafegetShortTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetShortTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + short result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie27.class.getDeclaredField("date"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie27(); + result = unsafe.getShort(obj, offset); + if (result == 6) { + UnsafegetShortTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie27 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; + private char favorite = '7'; + private short date = 6; + private double grade = 99.99; + private float aFloat = 66.66f; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0030-rt-unsafe-UnsafeobjectFieldOffeset/UnsafeobjectFieldOffeset.java b/test/testsuite/ouroboros/unsafe_test/RT0030-rt-unsafe-UnsafeobjectFieldOffeset/UnsafeobjectFieldOffeset.java new file mode 100755 index 0000000000000000000000000000000000000000..1e1a2e261fd2a2e9bc3c5023c08b4c90daf692f9 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0030-rt-unsafe-UnsafeobjectFieldOffeset/UnsafeobjectFieldOffeset.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeobjectFieldOffeset + * -@TestCaseName: Unsafe api: objectFieldOffset() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:Prepare Object + * -#step2:get offset by Unsafe.objectFieldOffset() + * -#step3:check return value from step2,compare step1 + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeobjectFieldOffeset.java + * -@ExecuteClass: UnsafeobjectFieldOffeset + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeobjectFieldOffeset { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeobjectFieldOffsetTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeobjectFieldOffeset.res = UnsafeobjectFieldOffeset.res - 10; + } +// System.out.println(result); +// System.out.println(UnsafeobjectFieldOffeset.res); + if (result == 3 && UnsafeobjectFieldOffeset.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeobjectFieldOffsetTest_1() { + Unsafe unsafe; + Object obj = new Billie(); + Field field; + Field param1; + String result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe) field.get(null); + param1 = obj.getClass().getDeclaredField("owner"); + long offset = unsafe.objectFieldOffset(param1); +// System.out.println(offset); +// System.out.println(unsafe.getObject(obj, offset)); + result = (String)unsafe.getObject(obj, offset); +// System.out.println(result); + if (result.equals("Me")) { + UnsafeobjectFieldOffeset.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } + +} + +class Billie { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; +} +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0032-rt-unsafe-UnsafeputBooleanTest/UnsafeputBooleanTest.java b/test/testsuite/ouroboros/unsafe_test/RT0032-rt-unsafe-UnsafeputBooleanTest/UnsafeputBooleanTest.java new file mode 100755 index 0000000000000000000000000000000000000000..834f51a5fcae0630347fd63afe3d240f986d3163 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0032-rt-unsafe-UnsafeputBooleanTest/UnsafeputBooleanTest.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputBooleanTest + * -@TestCaseName: Unsafe api: putBoolean() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Boolean + * -#step2:invoke Unsafe.getBoolean to visit this Field + * -#step3:set value of step2 by Unsafe.putBoolean + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputBooleanTest.java + * -@ExecuteClass: UnsafeputBooleanTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafeputBooleanTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputBooleanTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputBooleanTest.res -= 2; + } + + if (result == 3 && UnsafeputBooleanTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputBooleanTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + boolean result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie22.class.getDeclaredField("gender"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie22(); + result = unsafe.getBoolean(obj, offset); + unsafe.putBoolean(obj, offset, true); + result = unsafe.getBoolean(obj, offset); + if (result) { + UnsafeputBooleanTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie22 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0033-rt-unsafe-UnsafeputByteByAddressTest/UnsafeputByteByAddressTest.java b/test/testsuite/ouroboros/unsafe_test/RT0033-rt-unsafe-UnsafeputByteByAddressTest/UnsafeputByteByAddressTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fa411abfcc5bbfbffbea9d8d45ab7d6961ff442d --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0033-rt-unsafe-UnsafeputByteByAddressTest/UnsafeputByteByAddressTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputByteByAddressTest + * -@TestCaseName: Unsafe api: putByte(Address) + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:allocateMemory for one Field of Byte + * -#step2:set value of step2 by Unsafe.putByte + * -#step3:check value after step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputByteByAddressTest.java + * -@ExecuteClass: UnsafeputByteByAddressTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeputByteByAddressTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputByteByAddressTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputByteByAddressTest.res -= 2; + } + + if (result == 3 && UnsafeputByteByAddressTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputByteByAddressTest_1() { + Unsafe unsafe; + Field field; + long address; + byte result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(4); +// System.out.println(address); + byte b = 127; + unsafe.putByte(address, b); + result = unsafe.getByte(address); +// System.out.println(result); + if (result == b) { + UnsafeputByteByAddressTest.res -= 2; + } + + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0034-rt-unsafe-UnsafeputByteTest/UnsafeputByteTest.java b/test/testsuite/ouroboros/unsafe_test/RT0034-rt-unsafe-UnsafeputByteTest/UnsafeputByteTest.java new file mode 100755 index 0000000000000000000000000000000000000000..280e6314b8d7922463386bd3f1760c628aea471a --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0034-rt-unsafe-UnsafeputByteTest/UnsafeputByteTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputByteTest + * -@TestCaseName: Unsafe api: putByten() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Byte + * -#step2:invoke Unsafe.getByte to visit this Field + * -#step3:set value of step2 by Unsafe.putByte + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputByteTest.java + * -@ExecuteClass: UnsafeputByteTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafeputByteTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputByteTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputByteTest.res -= 2; + } + + if (result == 3 && UnsafeputByteTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputByteTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + byte result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie24.class.getDeclaredField("length"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie24(); + result = unsafe.getByte(obj, offset); + byte b = 12; + unsafe.putByte(obj, offset, b); + result = unsafe.getByte(obj, offset); + if (result == 12) { + UnsafeputByteTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie24 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0035-rt-unsafe-UnsafeputCharTest/UnsafeputCharTest.java b/test/testsuite/ouroboros/unsafe_test/RT0035-rt-unsafe-UnsafeputCharTest/UnsafeputCharTest.java new file mode 100755 index 0000000000000000000000000000000000000000..941d10c7f30de90d7a0488eadd59adfab25ad3b6 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0035-rt-unsafe-UnsafeputCharTest/UnsafeputCharTest.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputCharTest + * -@TestCaseName: Unsafe api: putChar() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Char + * -#step2:invoke Unsafe.getChar to visit this Field + * -#step3:set value of step2 by Unsafe.putChar + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputCharTest.java + * -@ExecuteClass: UnsafeputCharTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafeputCharTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputCharTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputCharTest.res -= 2; + } + + if (result == 3 && UnsafeputCharTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputCharTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + char result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie26.class.getDeclaredField("favorite"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie26(); + result = unsafe.getChar(obj, offset); + unsafe.putChar(obj, offset, 's'); + result = unsafe.getChar(obj, offset); + if (result == 's') { + UnsafeputCharTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie26 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; + private char favorite = '7'; + private short date = 6; + private double grade = 99.99; + private float aFloat = 66.66f; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0036-rt-unsafe-UnsafeputDoubleTest/UnsafeputDoubleTest.java b/test/testsuite/ouroboros/unsafe_test/RT0036-rt-unsafe-UnsafeputDoubleTest/UnsafeputDoubleTest.java new file mode 100755 index 0000000000000000000000000000000000000000..4816543fcece8b67801b8e42743bff0f96a70b89 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0036-rt-unsafe-UnsafeputDoubleTest/UnsafeputDoubleTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputDoubleTest + * -@TestCaseName: Unsafe api: putDouble() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Double + * -#step2:invoke Unsafe.getDouble to visit this Field + * -#step3:set value of step2 by Unsafe.putDouble + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputDoubleTest.java + * -@ExecuteClass: UnsafeputDoubleTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafeputDoubleTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputDoubleTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputDoubleTest.res -= 2; + } + + if (result == 3 && UnsafeputDoubleTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputDoubleTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + double result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie30.class.getDeclaredField("grade"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie30(); + result = unsafe.getDouble(obj, offset); + double d = 11.11; + unsafe.putDouble(obj, offset, d); + result = unsafe.getDouble(obj, offset); + if (result == d) { + UnsafeputDoubleTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie30 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; + private char favorite = '7'; + private short date = 6; + private double grade = 99.99; + private float aFloat = 66.66f; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0037-rt-unsafe-UnsafeputFloatTest/UnsafeputFloatTest.java b/test/testsuite/ouroboros/unsafe_test/RT0037-rt-unsafe-UnsafeputFloatTest/UnsafeputFloatTest.java new file mode 100755 index 0000000000000000000000000000000000000000..3b7cc7bb1efc708f024f090832a52d5a44e95dae --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0037-rt-unsafe-UnsafeputFloatTest/UnsafeputFloatTest.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputFloatTest + * -@TestCaseName: Unsafe api: putFloat() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Float + * -#step2:invoke Unsafe.getFloat to visit this Field + * -#step3:set value of step2 by Unsafe.putFloat + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputFloatTest.java + * -@ExecuteClass: UnsafeputFloatTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafeputFloatTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputFloatTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputFloatTest.res -= 2; + } + + if (result == 3 && UnsafeputFloatTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputFloatTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Float result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie32.class.getDeclaredField("aFloat"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie32(); + result = unsafe.getFloat(obj, offset); + unsafe.putFloat(obj, offset, 11.11f); + result = unsafe.getFloat(obj, offset); + if (result == 11.11f) { + UnsafeputFloatTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie32 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; + private char favorite = '7'; + private short date = 6; + private double grade = 99.99; + private float aFloat = 66.66f; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0038-rt-unsafe-UnsafeputIntTest/UnsafeputIntTest.java b/test/testsuite/ouroboros/unsafe_test/RT0038-rt-unsafe-UnsafeputIntTest/UnsafeputIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..cc9e89978d4c6fab43a48092cf68e1a4d65b71e4 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0038-rt-unsafe-UnsafeputIntTest/UnsafeputIntTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputIntTest + * -@TestCaseName: Unsafe api: putInt() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Int + * -#step2:invoke Unsafe.getInt to visit this Field + * -#step3:set value of step2 by Unsafe.putInt + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputIntTest.java + * -@ExecuteClass: UnsafeputIntTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeputIntTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputIntTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputIntTest.res -= 2; + } + + if (result == 3 && UnsafeputIntTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputIntTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + int result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie13.class.getDeclaredField("height"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie13(); + result = unsafe.getInt(obj, offset); + unsafe.putInt(obj, offset, 10); + result = unsafe.getInt(obj,offset); + if (result == 10) { + UnsafeputIntTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie13 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0039-rt-unsafe-UnsafeputIntVolatileTest/UnsafeputIntVolatileTest.java b/test/testsuite/ouroboros/unsafe_test/RT0039-rt-unsafe-UnsafeputIntVolatileTest/UnsafeputIntVolatileTest.java new file mode 100755 index 0000000000000000000000000000000000000000..695fed597636be3db05f083f710c6a31fa070326 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0039-rt-unsafe-UnsafeputIntVolatileTest/UnsafeputIntVolatileTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputIntVolatileTest + * -@TestCaseName: Unsafe api: putIntvolatile() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Volatile Int + * -#step2:invoke Unsafe.getIntVolatile to visit this Field + * -#step3:set value of step2 by Unsafe.putIntVolatile + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputIntVolatileTest.java + * -@ExecuteClass: UnsafeputIntVolatileTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.TreeSet; + +public class UnsafeputIntVolatileTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputIntVolatileTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputIntVolatileTest.res -= 2; + } + + if (result == 3 && UnsafeputIntVolatileTest.res == 97) { + result =0; + } + return result; + } + + + private static int UnsafeputIntVolatileTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + int result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie7.class.getDeclaredField("age"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie7(); + result = unsafe.getIntVolatile(obj, offset); + unsafe.putIntVolatile(obj, offset, 20); + result = unsafe.getIntVolatile(obj, offset); + if (result == 20) { + UnsafeputIntVolatileTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} +class Billie7 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0040-rt-unsafe-UnsafeputLongTest/UnsafeputLongTest.java b/test/testsuite/ouroboros/unsafe_test/RT0040-rt-unsafe-UnsafeputLongTest/UnsafeputLongTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9d9b891b16744aa600789b69cf4ba5d3b747c7db --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0040-rt-unsafe-UnsafeputLongTest/UnsafeputLongTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputLongTest + * -@TestCaseName: Unsafe api: putLong() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:allocateMemory for one Field of Long + * -#step2:set value of step2 by Unsafe.putLong + * -#step3:check value after step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputLongTest.java + * -@ExecuteClass: UnsafeputLongTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeputLongTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputLongTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputLongTest.res -= 2; + } + + if (result == 3 && UnsafeputLongTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputLongTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + long result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie16.class.getDeclaredField("weight"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie16(); + result = unsafe.getLong(obj, offset); + unsafe.putLong(obj, offset, 200L); + result = unsafe.getLong(obj,offset); + if (result == 200L) { + UnsafeputLongTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie16 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0041-rt-unsafe-UnsafeputLongVolatileTest/UnsafeputLongVolatileTest.java b/test/testsuite/ouroboros/unsafe_test/RT0041-rt-unsafe-UnsafeputLongVolatileTest/UnsafeputLongVolatileTest.java new file mode 100755 index 0000000000000000000000000000000000000000..fd3a3fba7db4fa6e817a81b648aa4ab986c356a2 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0041-rt-unsafe-UnsafeputLongVolatileTest/UnsafeputLongVolatileTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputLongVolatileTest + * -@TestCaseName: Unsafe api: putLongvolatile() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Long + * -#step2:invoke Unsafe.getVolatileLong to visit this Field + * -#step3:set value of step2 by Unsafe.putVolatileLong + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputLongVolatileTest.java + * -@ExecuteClass: UnsafeputLongVolatileTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafeputLongVolatileTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputLongVolatileTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputLongVolatileTest.res -= 2; + } + + if (result == 3 && UnsafeputLongVolatileTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputLongVolatileTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Long result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie9.class.getDeclaredField("birth"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie9(); + result = unsafe.getLongVolatile(obj, offset); + unsafe.putLongVolatile(obj, offset, 20020214L); + result = unsafe.getLongVolatile(obj, offset); + if (result == 20020214L) { + UnsafeputLongVolatileTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie9 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0042-rt-unsafe-UnsafeputObjectTest/UnsafeputObjectTest.java b/test/testsuite/ouroboros/unsafe_test/RT0042-rt-unsafe-UnsafeputObjectTest/UnsafeputObjectTest.java new file mode 100755 index 0000000000000000000000000000000000000000..731665408e6e0638b7f167791ce24e55ed879b1c --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0042-rt-unsafe-UnsafeputObjectTest/UnsafeputObjectTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputObjectTest + * -@TestCaseName: Unsafe api: putObject() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Object + * -#step2:invoke Unsafe.getObject to visit this Field + * -#step3:set value of step2 by Unsafe.putObject + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputObjectTest.java + * -@ExecuteClass: UnsafeputObjectTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeputObjectTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputObjectTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputObjectTest.res -= 2; + } + + if (result == 3 && UnsafeputObjectTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputObjectTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Object result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie19.class.getDeclaredField("owner"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie19(); + result = unsafe.getObject(obj, offset); + unsafe.putObject(obj, offset, "she"); + result = unsafe.getObject(obj,offset); + if (result.equals("she")) { + UnsafeputObjectTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie19 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0043-rt-unsafe-UnsafeputObjectVolatileTest/UnsafeputObjectVolatileTest.java b/test/testsuite/ouroboros/unsafe_test/RT0043-rt-unsafe-UnsafeputObjectVolatileTest/UnsafeputObjectVolatileTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ec511977b4fcfe3c90159119e0e3effb503b0680 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0043-rt-unsafe-UnsafeputObjectVolatileTest/UnsafeputObjectVolatileTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputObjectVolatileTest + * -@TestCaseName: Unsafe api: putLongvolatile() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Object + * -#step2:invoke Unsafe.getVolatileObject to visit this Field + * -#step3:set value of step2 by Unsafe.putVolatileObject + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputObjectVolatileTest.java + * -@ExecuteClass: UnsafeputObjectVolatileTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeputObjectVolatileTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputObjectVolatileTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputObjectVolatileTest.res -= 2; + } + + if (result == 3 && UnsafeputObjectVolatileTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafeputObjectVolatileTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + Object result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie11.class.getDeclaredField("lastname"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie11(); + result = unsafe.getObjectVolatile(obj, offset); + unsafe.putObjectVolatile(obj, offset, "Eilish"); + result = unsafe.getObjectVolatile(obj, offset); + if (result.equals("Eilish")) { + UnsafeputObjectVolatileTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie11 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0044-rt-unsafe-UnsafeputOrderedIntTest/UnsafeputOrderedIntTest.java b/test/testsuite/ouroboros/unsafe_test/RT0044-rt-unsafe-UnsafeputOrderedIntTest/UnsafeputOrderedIntTest.java new file mode 100755 index 0000000000000000000000000000000000000000..b6a2c1327b74adf86ba4f384b4f0bfd48053dba9 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0044-rt-unsafe-UnsafeputOrderedIntTest/UnsafeputOrderedIntTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputOrderedIntTest + * -@TestCaseName: Unsafe api: putOrderedInt() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Int + * -#step2:invoke Unsafe.getInt to visit this Field + * -#step3:set value of step2 by Unsafe.putOrderedInt + * -#step4:check value of step3 immediately,the value may not be changed as step3 + * -#step5:check value of step3 after seconds,the value should be changed as step3 + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputOrderedIntTest.java + * -@ExecuteClass: UnsafeputOrderedIntTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeputOrderedIntTest { + private static int res = 99; + private static Object obj = new Object(); + private static Long offset =0l; + private static int flag =0; + public static void main(String[] args) throws InterruptedException { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) throws InterruptedException { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputOrderedIntTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputOrderedIntTest.res -= 2; + } +// System.out.println(flag); + if (flag==0) { +// System.out.println("It is true"); + } + Thread.sleep(4000); +// System.out.println(flag); +// System.out.println("result:" +result); +// System.out.println("res: "+ res); + if (result == 3 && UnsafeputOrderedIntTest.flag == 10) { + result = 0; + } + return result; + } + + private static int UnsafeputOrderedIntTest_1() { + int result = 3; + Field field; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + Unsafe unsafe = (Unsafe)field.get(null); + Thread boyThread = new Thread(new Runnable() { + @Override + public void run() { + Field param = null; + try { + param = Billie14.class.getDeclaredField("height"); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + offset = unsafe.objectFieldOffset(param); + obj = new Billie14(); + unsafe.putOrderedInt(obj, offset, 10); + } + }); + + Thread girlThread = new Thread(new Runnable() { + @Override + public void run() { + int result; + flag = unsafe.getInt(obj,offset); +// System.out.println("======================="+flag); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + flag = unsafe.getInt(obj,offset); +// System.out.println("======================="+flag); + } + }); + boyThread.start(); + girlThread.start(); + } catch (Exception e) { + e.printStackTrace(); + return 40; + } + return result; + } +} + +class Billie14 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0045-rt-unsafe-UnsafeputOrderedLongTest/UnsafeputOrderedLongTest.java b/test/testsuite/ouroboros/unsafe_test/RT0045-rt-unsafe-UnsafeputOrderedLongTest/UnsafeputOrderedLongTest.java new file mode 100755 index 0000000000000000000000000000000000000000..386f6b693a79d9166a958a4bf14faab7b23855fd --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0045-rt-unsafe-UnsafeputOrderedLongTest/UnsafeputOrderedLongTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputLongTest + * -@TestCaseName: Unsafe api: putLong() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Long + * -#step2:invoke Unsafe.getLong to visit this Field + * -#step3:set value of step2 by Unsafe.putOrderedLong + * -#step4:check value of step3 immediately,the value may not be changed as step3 + * -#step5:check value of step3 after seconds,the value should be changed as step3 + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputOrderedLongTest.java + * -@ExecuteClass: UnsafeputOrderedLongTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeputOrderedLongTest { + private static int res = 99; + private static Object obj = new Object(); + private static Long offset =0l; + private static long flag =0l; + public static void main(String[] args) throws InterruptedException { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) throws InterruptedException { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputOrderedLongTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputOrderedLongTest.res -= 2; + } +// System.out.println(flag); + if (flag==0) { +// System.out.println("It is true"); + } + Thread.sleep(4000); +// System.out.println(flag); +// System.out.println("result:" +result); +// System.out.println("res: "+ res); + if (result == 3 && UnsafeputOrderedLongTest.flag == 200L) { + result =0; + } + return result; + } + + private static int UnsafeputOrderedLongTest_1() { + int result =3; + Field field; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + Unsafe unsafe = (Unsafe)field.get(null); + Thread boyThread = new Thread(new Runnable() { + @Override + public void run() { + Field param = null; + try { + param = Billie17.class.getDeclaredField("weight"); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + offset = unsafe.objectFieldOffset(param); + obj = new Billie17(); + unsafe.putOrderedLong(obj, offset, 200L); + } + }); + + Thread girlThread = new Thread(new Runnable() { + @Override + public void run() { + int result; + flag = unsafe.getLong(obj,offset); +// System.out.println("======================="+flag); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + flag = unsafe.getLong(obj,offset); +// System.out.println("======================="+flag); + } + }); + boyThread.start(); + girlThread.start(); + } catch (Exception e) { + e.printStackTrace(); + return 40; + } + return 3; + } +} + +class Billie17 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0046-rt-unsafe-UnsafeputOrderedObjectTest/UnsafeputOrderedObjectTest.java b/test/testsuite/ouroboros/unsafe_test/RT0046-rt-unsafe-UnsafeputOrderedObjectTest/UnsafeputOrderedObjectTest.java new file mode 100755 index 0000000000000000000000000000000000000000..9af1555fbe1380bf4c4c4b4e9cf503bd7195a5cc --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0046-rt-unsafe-UnsafeputOrderedObjectTest/UnsafeputOrderedObjectTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputOrderedObjectTest + * -@TestCaseName: Unsafe api: putOrderedObject() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Object + * -#step2:invoke Unsafe.getObject to visit this Field + * -#step3:set value of step2 by Unsafe.putOrderedObject + * -#step4:check value of step3 immediately,the value may not be changed as step3 + * -#step5:check value of step3 after seconds,the value should be changed as step3 + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputOrderedObjectTest.java + * -@ExecuteClass: UnsafeputOrderedObjectTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeputOrderedObjectTest { + private static int res = 99; + private static Object obj = new Object(); + private static Long offset =0l; + private static Object flag = new Object(); + public static void main(String[] args) throws InterruptedException { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) throws InterruptedException { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeputOrderedObjectTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputOrderedObjectTest.res -= 2; + } +// System.out.println(flag.toString()); + if (flag.equals("")) { +// System.out.println("It is true"); + } + Thread.sleep(4000); +// System.out.println(flag.toString()); +// System.out.println("result:" +result); +// System.out.println("res: "+ res); + if (result == 3 && UnsafeputOrderedObjectTest.flag.equals("Yours")) { + result =0; + } + return result; + } + + private static int UnsafeputOrderedObjectTest_1() { + int result =3; + Field field; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + Unsafe unsafe = (Unsafe)field.get(null); + Thread boyThread = new Thread(new Runnable() { + @Override + public void run() { + Field param = null; + try { + param = Billie20.class.getDeclaredField("owner"); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } + offset = unsafe.objectFieldOffset(param); + obj = new Billie20(); + unsafe.putOrderedObject(obj, offset, "Yours"); + } + }); + + Thread girlThread = new Thread(new Runnable() { + @Override + public void run() { + int result; + flag = unsafe.getObject(obj,offset); +// System.out.println("======================="+flag); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + flag = unsafe.getObject(obj,offset); +// System.out.println("======================="+flag); + } + }); + boyThread.start(); + girlThread.start(); + } catch (Exception e) { + e.printStackTrace(); + return 40; + } + return 3; + } +} + +class Billie20 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0047-rt-unsafe-UnsafeputShortTest/UnsafeputShortTest.java b/test/testsuite/ouroboros/unsafe_test/RT0047-rt-unsafe-UnsafeputShortTest/UnsafeputShortTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2bc350eae7d0309a3620d54da77ed07ae438c8a2 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0047-rt-unsafe-UnsafeputShortTest/UnsafeputShortTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeputShortTest + * -@TestCaseName: Unsafe api: putShort() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get Field of Short + * -#step2:invoke Unsafe.getShort to visit this Field + * -#step3:set value of step2 by Unsafe.putShort + * -#step4:check value of step3 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeputShortTest.java + * -@ExecuteClass: UnsafeputShortTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafeputShortTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetShortTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeputShortTest.res -= 2; + } + + if (result == 3 && UnsafeputShortTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetShortTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + short result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie28.class.getDeclaredField("date"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie28(); + result = unsafe.getShort(obj, offset); + short s = 10; + unsafe.putShort(obj, offset, s); + result = unsafe.getShort(obj, offset); + if (result == 10) { + UnsafeputShortTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie28 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; + private char favorite = '7'; + private short date = 6; + private double grade = 99.99; + private float aFloat = 66.66f; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0048-rt-unsafe-UnsafesetMemoryTest/UnsafesetMemoryTest.java b/test/testsuite/ouroboros/unsafe_test/RT0048-rt-unsafe-UnsafesetMemoryTest/UnsafesetMemoryTest.java new file mode 100755 index 0000000000000000000000000000000000000000..935ccfc5b023cc55aceef86a8c870f6408c33cdc --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0048-rt-unsafe-UnsafesetMemoryTest/UnsafesetMemoryTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafesetMemoryTest + * -@TestCaseName: Unsafe api: setMemory() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:allocateMemory for one Field + * -#step2:set value at step1 by Unsafe.setMemory + * -#step3:check value after ste2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafesetMemoryTest.java + * -@ExecuteClass: UnsafesetMemoryTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafesetMemoryTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafesetMemoryTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafesetMemoryTest.res -= 2; + } + + if (result == 3 && UnsafesetMemoryTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafesetMemoryTest_1() { + Unsafe unsafe; + Field field; + long address; + byte result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(4); +// System.out.println(address); + byte b = 127; + unsafe.setMemory(address, 4L, b); + result = unsafe.getByte(address); +// System.out.println(result); + if (result == b) { + UnsafesetMemoryTest.res -= 2; + } + + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0850-rt-unsafe-UnsafegetByteTest/UnsafegetByteTest.java b/test/testsuite/ouroboros/unsafe_test/RT0850-rt-unsafe-UnsafegetByteTest/UnsafegetByteTest.java new file mode 100755 index 0000000000000000000000000000000000000000..4d30a8e19ccda9a45209e4c387d7f4df1ec3837a --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0850-rt-unsafe-UnsafegetByteTest/UnsafegetByteTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetByteTest + * -@TestCaseName: Test Unsafe api: getByte() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare one Class and get this FieldOffset + * -#step2:invoke Unsafe.getByte to get value from FieldOffset + * -#step3:check value of step2 correct + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetByteTest.java + * -@ExecuteClass: UnsafegetByteTest + * -@ExecuteArgs: + */ +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class UnsafegetByteTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetByteTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetByteTest.res -= 2; + } + + if (result == 3 && UnsafegetByteTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetByteTest_1() { + Unsafe unsafe; + Field field; + Long offset; + Field param; + Object obj; + byte result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + param = Billie23.class.getDeclaredField("length"); + offset = unsafe.objectFieldOffset(param); + obj = new Billie23(); + result = unsafe.getByte(obj, offset); + if (result == 7) { + UnsafegetByteTest.res -= 2; + } + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +class Billie23 { + public int height = 8; + private String[] color = {"black","white"}; + private String owner = "Me"; + private byte length = 0x7; + private String[] water = {"day","wet"}; + private long weight = 100L; + private volatile int age = 18; + private volatile long birth = 20010214L; + private volatile String lastname = "eilish"; + private boolean gender = false; +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/RT0909-rt-unsafe-UnsafegetLongByAddressTest/UnsafegetLongByAddressTest.java b/test/testsuite/ouroboros/unsafe_test/RT0909-rt-unsafe-UnsafegetLongByAddressTest/UnsafegetLongByAddressTest.java new file mode 100755 index 0000000000000000000000000000000000000000..f61daa1201a421a87d1e4de4f104e8f4accdaa5c --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/RT0909-rt-unsafe-UnsafegetLongByAddressTest/UnsafegetLongByAddressTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafegetShortByAddressTest + * -@TestCaseName: Unsafe api: getLong(long) + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:prepare address from unsafe.allocateMemory,and put long number + * -#step2:invoke unsafe.getLong(address) + * -#step3:check return from step2 as step1 + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafegetLongByAddressTest.java + * -@ExecuteClass: UnsafegetLongByAddressTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafegetLongByAddressTest { + private static int res = 99; + public static void main(String[] args) { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafegetLongByAddressTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafegetLongByAddressTest.res -= 2; + } + + if (result == 3 && UnsafegetLongByAddressTest.res == 97) { + result =0; + } + return result; + } + + private static int UnsafegetLongByAddressTest_1() { + Unsafe unsafe; + Field field; + long address; + long result; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + unsafe = (Unsafe)field.get(null); + address = unsafe.allocateMemory(2); +// System.out.println(address); + long l = 111L; + unsafe.putLong(address, l); + result = unsafe.getLong(address); +// System.out.println(result); + if (result == l) { + UnsafegetLongByAddressTest.res -= 2; + } + + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 40; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 41; + } + return 3; + } +} + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file diff --git a/test/testsuite/ouroboros/unsafe_test/issue-RT0935-rt-unsafe-UnsafeunparkTest/UnsafeunparkTest.java b/test/testsuite/ouroboros/unsafe_test/issue-RT0935-rt-unsafe-UnsafeunparkTest/UnsafeunparkTest.java new file mode 100755 index 0000000000000000000000000000000000000000..2b0ca7713a43f9d836a19497931d0e0d00f31d68 --- /dev/null +++ b/test/testsuite/ouroboros/unsafe_test/issue-RT0935-rt-unsafe-UnsafeunparkTest/UnsafeunparkTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + * -@TestCaseID: UnsafeunparkTest + * -@TestCaseName: Unsafe api: unpark() + * -@TestCaseType: Function Test + * -@RequirementName: VMRuntime_registerNativeAllocation接口实现 + * -@Brief: + * -#step1:threa1 park + * -#step2:thread2 to unpark thread1 + * -#step3:thread1 go on excute + * -@Expect:0\n + * -@Priority: High + * -@Source: UnsafeunparkTest.java + * -@ExecuteClass: UnsafeunparkTest + * -@ExecuteArgs: + */ + +import sun.misc.Unsafe; + +import java.io.PrintStream; +import java.lang.reflect.Field; + +public class UnsafeunparkTest { + private static int res = 99; + private static int flag = 0; + public static void main(String[] args) throws InterruptedException { + System.out.println(run(args, System.out)); + } + + private static int run(String[] args, PrintStream out) throws InterruptedException { + int result = 2/*STATUS_FAILED*/; + try { + result = UnsafeunparkTest_1(); + } catch (Exception e) { + e.printStackTrace(); + UnsafeunparkTest.res -= 2; + } + Thread.sleep(4000); +// System.out.println("===================="+flag); + if (result == 3 && UnsafeunparkTest.flag == 1214210) { + result =0; + } + return result; + } + + private static int UnsafeunparkTest_1() { + int result = 3; + Field field; + try { + field = Unsafe.class.getDeclaredField("theUnsafe"); + field.setAccessible(true); + Unsafe unsafe = (Unsafe)field.get(null); + Thread boyThread = new Thread(new Runnable() { + @Override + public void run() { +// System.out.println("boy: 我要吃鸡"); + flag += (flag+1)*10; +// System.out.println(flag); + unsafe.park(false,0); +// System.out.println("boy: park1"); + flag += (flag+3)*1000; +// System.out.println(flag); +// unsafe.park(false,0); // 第二次会阻塞住,因为只有一个permit +// System.out.println("boy: park2"); +// System.out.println("boy: 不会再执行了"); + } + }); + + Thread girlThread = new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } +// System.out.println("girl: OK"); + flag += (flag+2)*100; +// System.out.println(flag); + unsafe.unpark(boyThread); // unpark两次,但是permit不会叠加 + unsafe.unpark(boyThread); + } + }); + + boyThread.start(); + girlThread.start(); + } catch (Exception e) { + e.printStackTrace(); + return 40; + } + return result; + } + +} + + +// EXEC:%maple %f %build_option -o %n.so +// EXEC:%run %n.so %n %run_option | compare %f +// ASSERT: scan 0\n \ No newline at end of file