From e5d0b8218b098f832e6617075e214f8ff2794f04 Mon Sep 17 00:00:00 2001 From: ypigunova Date: Fri, 11 Jul 2025 13:28:19 +0300 Subject: [PATCH] Add Fixed Array Methods in verify mode Issue: ICLRLO Signed-off-by: ypigunova --- .../ets/runtime/ani/verify/env_ani_verifier.h | 16 ++ .../ets/runtime/ani/verify/types/vref.h | 89 +++++++++- .../runtime/ani/verify/verify_ani_cast_api.h | 55 ++++++ .../runtime/ani/verify/verify_ani_checker.cpp | 161 ++++++++++++------ .../runtime/ani/verify/verify_ani_checker.h | 76 ++++++++- .../ani/verify/verify_ani_interaction_api.cpp | 144 +++++++++++++--- .../tests/ani/tests/verifyani/CMakeLists.txt | 1 + .../tests/verifyani/array_ops/CMakeLists.txt | 44 +++++ .../verify_fixed_array_new_boolean_test.cpp | 82 +++++++++ .../verify_fixed_array_new_byte_test.cpp | 82 +++++++++ .../verify_fixed_array_new_char_test.cpp | 82 +++++++++ .../verify_fixed_array_new_double_test.cpp | 82 +++++++++ .../verify_fixed_array_new_float_test.cpp | 82 +++++++++ .../verify_fixed_array_new_int_test.cpp | 82 +++++++++ .../verify_fixed_array_new_long_test.cpp | 82 +++++++++ .../verify_fixed_array_new_short_test.cpp | 82 +++++++++ 16 files changed, 1166 insertions(+), 76 deletions(-) create mode 100644 static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/CMakeLists.txt create mode 100644 static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_boolean_test.cpp create mode 100644 static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_byte_test.cpp create mode 100644 static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_char_test.cpp create mode 100644 static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_double_test.cpp create mode 100644 static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_float_test.cpp create mode 100644 static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_int_test.cpp create mode 100644 static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_long_test.cpp create mode 100644 static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_short_test.cpp diff --git a/static_core/plugins/ets/runtime/ani/verify/env_ani_verifier.h b/static_core/plugins/ets/runtime/ani/verify/env_ani_verifier.h index 00d043a60b..34636c7405 100644 --- a/static_core/plugins/ets/runtime/ani/verify/env_ani_verifier.h +++ b/static_core/plugins/ets/runtime/ani/verify/env_ani_verifier.h @@ -60,6 +60,22 @@ public: return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::MODULE)); } else if constexpr (std::is_same_v) { return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::STRING)); + } else if constexpr (std::is_same_v) { + return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::FIXED_ARRAY_BOOLEAN)); + } else if constexpr (std::is_same_v) { + return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::FIXED_ARRAY_CHAR)); + } else if constexpr (std::is_same_v) { + return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::FIXED_ARRAY_BYTE)); + } else if constexpr (std::is_same_v) { + return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::FIXED_ARRAY_SHORT)); + } else if constexpr (std::is_same_v) { + return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::FIXED_ARRAY_INT)); + } else if constexpr (std::is_same_v) { + return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::FIXED_ARRAY_LONG)); + } else if constexpr (std::is_same_v) { + return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::FIXED_ARRAY_FLOAT)); + } else if constexpr (std::is_same_v) { + return static_cast(DoAddLocalVerifiedRef(ref, ANIRefType::FIXED_ARRAY_DOUBLE)); } else { UNREACHABLE_CONSTEXPR(); } diff --git a/static_core/plugins/ets/runtime/ani/verify/types/vref.h b/static_core/plugins/ets/runtime/ani/verify/types/vref.h index c7ebe17629..870e9df169 100644 --- a/static_core/plugins/ets/runtime/ani/verify/types/vref.h +++ b/static_core/plugins/ets/runtime/ani/verify/types/vref.h @@ -32,7 +32,14 @@ enum class ANIRefType { ERROR, ARRAYBUFFER, STRING, - ARRAY, + FIXED_ARRAY_BOOLEAN, + FIXED_ARRAY_CHAR, + FIXED_ARRAY_BYTE, + FIXED_ARRAY_SHORT, + FIXED_ARRAY_INT, + FIXED_ARRAY_LONG, + FIXED_ARRAY_FLOAT, + FIXED_ARRAY_DOUBLE, TYPE, CLASS, ENUM, @@ -93,6 +100,86 @@ public: } }; +class VFixedArray : public VObject { +public: + ani_fixedarray GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + +class VFixedArrayBoolean : public VFixedArray { +public: + ani_fixedarray_boolean GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + +class VFixedArrayChar : public VFixedArray { +public: + ani_fixedarray_char GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + +class VFixedArrayByte : public VFixedArray { +public: + ani_fixedarray_byte GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + +class VFixedArrayShort : public VFixedArray { +public: + ani_fixedarray_short GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + +class VFixedArrayInt : public VFixedArray { +public: + ani_fixedarray_int GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + +class VFixedArrayLong : public VFixedArray { +public: + ani_fixedarray_long GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + +class VFixedArrayFloat : public VFixedArray { +public: + ani_fixedarray_float GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + +class VFixedArrayDouble : public VFixedArray { +public: + ani_fixedarray_double GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + +class VFixedArrayRef : public VFixedArray { +public: + ani_fixedarray_ref GetRef() + { + return static_cast(VRef::GetRef()); + } +}; + } // namespace ark::ets::ani::verify #endif // PANDA_PLUGINS_ETS_RUNTIME_ANI_VERIFY_TYPES_VREF_H diff --git a/static_core/plugins/ets/runtime/ani/verify/verify_ani_cast_api.h b/static_core/plugins/ets/runtime/ani/verify/verify_ani_cast_api.h index d72d0d3db9..3c356db47f 100644 --- a/static_core/plugins/ets/runtime/ani/verify/verify_ani_cast_api.h +++ b/static_core/plugins/ets/runtime/ani/verify/verify_ani_cast_api.h @@ -28,6 +28,16 @@ class VObject; class VClass; class VString; class VMethod; +class VFixedArray; +class VFixedArrayBoolean; +class VFixedArrayChar; +class VFixedArrayByte; +class VFixedArrayShort; +class VFixedArrayInt; +class VFixedArrayLong; +class VFixedArrayFloat; +class VFixedArrayDouble; +class VFixedArrayRef; namespace internal { @@ -97,6 +107,51 @@ struct TypeMapping { using Type = ani_method; }; +template <> +struct TypeMapping { + using Type = ani_fixedarray_boolean *; +}; + +template <> +struct TypeMapping { + using Type = ani_fixedarray_char *; +}; + +template <> +struct TypeMapping { + using Type = ani_fixedarray_byte *; +}; + +template <> +struct TypeMapping { + using Type = ani_fixedarray_short *; +}; + +template <> +struct TypeMapping { + using Type = ani_fixedarray_int *; +}; + +template <> +struct TypeMapping { + using Type = ani_fixedarray_long *; +}; + +template <> +struct TypeMapping { + using Type = ani_fixedarray_float *; +}; + +template <> +struct TypeMapping { + using Type = ani_fixedarray_double *; +}; + +template <> +struct TypeMapping { + using Type = ani_fixedarray_ref *; +}; + template using ConvertToANIType = typename TypeMapping::Type; diff --git a/static_core/plugins/ets/runtime/ani/verify/verify_ani_checker.cpp b/static_core/plugins/ets/runtime/ani/verify/verify_ani_checker.cpp index c68213317a..488aef5c45 100644 --- a/static_core/plugins/ets/runtime/ani/verify/verify_ani_checker.cpp +++ b/static_core/plugins/ets/runtime/ani/verify/verify_ani_checker.cpp @@ -72,7 +72,14 @@ std::string_view ANIRefTypeToString(ANIRefType refType) case ANIRefType::ERROR: return "ani_error"; case ANIRefType::ARRAYBUFFER: return "ani_arraybuffer"; case ANIRefType::STRING: return "ani_string"; - case ANIRefType::ARRAY: return "ani_array"; + case ANIRefType::FIXED_ARRAY_BOOLEAN: return "ani_fixedarray_boolean"; + case ANIRefType::FIXED_ARRAY_BYTE: return "ani_fixedarray_byte"; + case ANIRefType::FIXED_ARRAY_SHORT: return "ani_fixedarray_short"; + case ANIRefType::FIXED_ARRAY_LONG: return "ani_fixedarray_long"; + case ANIRefType::FIXED_ARRAY_FLOAT: return "ani_fixedarray_float"; + case ANIRefType::FIXED_ARRAY_DOUBLE: return "ani_fixedarray_double"; + case ANIRefType::FIXED_ARRAY_INT: return "ani_fixedarray_int"; + case ANIRefType::FIXED_ARRAY_CHAR: return "ani_fixedarray_char"; case ANIRefType::TYPE: return "ani_type"; case ANIRefType::CLASS: return "ani_class"; case ANIRefType::ENUM: return "ani_enum"; @@ -99,6 +106,30 @@ PandaString ANIArg::GetStringValue() const case ValueType::ANI_SIZE: ss << GetValueSize(); break; + case ValueType::ANI_FIXED_ARRAY_BOOLEAN_STORAGE: + ss << GetValueFixedArrayBooleanStorage(); + break; + case ValueType::ANI_FIXED_ARRAY_BYTE_STORAGE: + ss << GetValueFixedArrayByteStorage(); + break; + case ValueType::ANI_FIXED_ARRAY_CHAR_STORAGE: + ss << GetValueFixedArrayCharStorage(); + break; + case ValueType::ANI_FIXED_ARRAY_DOUBLE_STORAGE: + ss << GetValueFixedArrayDoubleStorage(); + break; + case ValueType::ANI_FIXED_ARRAY_FLOAT_STORAGE: + ss << GetValueFixedArrayFloatStorage(); + break; + case ValueType::ANI_FIXED_ARRAY_INT_STORAGE: + ss << GetValueFixedArrayIntStorage(); + break; + case ValueType::ANI_FIXED_ARRAY_LONG_STORAGE: + ss << GetValueFixedArrayLongStorage(); + break; + case ValueType::ANI_FIXED_ARRAY_SHORT_STORAGE: + ss << GetValueFixedArrayShortStorage(); + break; case ValueType::UINT32: ss << "0x" << std::setfill('0') << std::setw(2U * sizeof(uint32_t)) << std::hex << GetValueU32(); break; @@ -137,6 +168,14 @@ PandaString ANIArg::GetStringType() const case ValueType::ANI_REF_STORAGE: return "ani_ref *"; case ValueType::ANI_OBJECT_STORAGE: return "ani_object *"; case ValueType::UINT32: return "uint32_t"; + case ValueType::ANI_FIXED_ARRAY_BOOLEAN_STORAGE: return "ani_fixedarray_boolean *"; + case ValueType::ANI_FIXED_ARRAY_CHAR_STORAGE: return "ani_fixedarray_char *"; + case ValueType::ANI_FIXED_ARRAY_BYTE_STORAGE: return "ani_fixedarray_byte *"; + case ValueType::ANI_FIXED_ARRAY_SHORT_STORAGE: return "ani_fixedarray_short *"; + case ValueType::ANI_FIXED_ARRAY_INT_STORAGE: return "ani_fixedarray_int *"; + case ValueType::ANI_FIXED_ARRAY_LONG_STORAGE: return "ani_fixedarray_long *"; + case ValueType::ANI_FIXED_ARRAY_FLOAT_STORAGE: return "ani_fixedarray_float *"; + case ValueType::ANI_FIXED_ARRAY_DOUBLE_STORAGE: return "ani_fixedarray_double *"; default: UNREACHABLE(); return ""; case ValueType::METHOD_ARGS: if (action_ == Action::VERIFY_METHOD_A_ARGS) { @@ -164,7 +203,7 @@ static bool IsValidRawAniValue(EnvANIVerifier *envANIVerifier, ani_value v, pand using I32Limits = std::numeric_limits; switch (typeId) { - // clang-format off + // clang-format off case panda_file::Type::TypeId::U1: return 0 == (v.l & BOOLEAN_MASK); // NOLINT(hicpp-signed-bitwise) case panda_file::Type::TypeId::U16: return 0 == (v.l & CHAR_MASK); // NOLINT(hicpp-signed-bitwise) case panda_file::Type::TypeId::I8: return v.i >= I8Limits::min() && v.i <= I8Limits::max(); @@ -181,7 +220,7 @@ static bool IsValidRawAniValue(EnvANIVerifier *envANIVerifier, ani_value v, pand } } else { switch (typeId) { - // clang-format off + // clang-format off case panda_file::Type::TypeId::U1: return v.b == ANI_FALSE || v.b == ANI_TRUE; case panda_file::Type::TypeId::U16: return true; case panda_file::Type::TypeId::I8: return true; @@ -266,6 +305,17 @@ public: return {}; } + template + std::optional VerifyTypeStorage(Type value, std::string_view TypeName) + { + if (value == nullptr) { + PandaStringStream ss; + ss << "wrong pointer for storing '" << TypeName << "'"; + return ss.str(); + } + return {}; + } + std::optional VerifyEnvVersion(uint32_t version) { if (!IsVersionSupported(version)) { @@ -371,47 +421,6 @@ public: return err; } - std::optional VerifyVmStorage(ani_vm **vmStorage) - { - if (vmStorage == nullptr) { - return "wrong pointer for storing 'ani_vm *'"; - } - return {}; - } - - std::optional VerifyEnvStorage(VEnv **envStorage) - { - if (envStorage == nullptr) { - return "wrong pointer for storing 'ani_env *'"; - } - return {}; - } - - // NOLINTNEXTLINE(readability-non-const-parameter) - std::optional VerifyBooleanStorage(ani_boolean *result) - { - if (result == nullptr) { - return "wrong pointer for storing 'ani_boolean'"; - } - return {}; - } - - std::optional VerifyRefStorage(VRef **result) - { - if (result == nullptr) { - return "wrong pointer for storing 'ani_ref'"; - } - return {}; - } - - std::optional VerifyObjectStorage(VObject **result) - { - if (result == nullptr) { - return "wrong pointer for storing 'ani_object'"; - } - return {}; - } - private: EnvANIVerifier *GetEnvANIVerifier() { @@ -506,31 +515,85 @@ static std::optional VerifyMethodVArgs(Verifier &v, const ANIArg &a static std::optional VerifyVmStorage(Verifier &v, const ANIArg &arg) { ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_VM_STORAGE); - return v.VerifyVmStorage(arg.GetValueVmStorage()); + return v.VerifyTypeStorage(arg.GetValueVmStorage(), "ani_vm *"); } static std::optional VerifyEnvStorage(Verifier &v, const ANIArg &arg) { ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_ENV_STORAGE); - return v.VerifyEnvStorage(arg.GetValueEnvStorage()); + return v.VerifyTypeStorage(arg.GetValueEnvStorage(), "ani_env *"); } static std::optional VerifyBooleanStorage(Verifier &v, const ANIArg &arg) { ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_BOOLEAN_STORAGE); - return v.VerifyBooleanStorage(arg.GetValueBooleanStorage()); + return v.VerifyTypeStorage(arg.GetValueBooleanStorage(), "ani_boolean"); } static std::optional VerifyRefStorage(Verifier &v, const ANIArg &arg) { ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_REF_STORAGE); - return v.VerifyRefStorage(arg.GetValueRefStorage()); + return v.VerifyTypeStorage(arg.GetValueRefStorage(), "ani_ref"); } static std::optional VerifyObjectStorage(Verifier &v, const ANIArg &arg) { ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_OBJECT_STORAGE); - return v.VerifyObjectStorage(arg.GetValueObjectStorage()); + return v.VerifyTypeStorage(arg.GetValueObjectStorage(), "ani_object"); +} + +static std::optional VerifyFixedArrayBooleanStorage(Verifier &v, const ANIArg &arg) +{ + ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_FIXED_ARRAY_BOOLEAN_STORAGE); + return v.VerifyTypeStorage(arg.GetValueFixedArrayBooleanStorage(), "ani_fixedarray_boolean"); +} + +static std::optional VerifyFixedArrayByteStorage(Verifier &v, const ANIArg &arg) +{ + ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_FIXED_ARRAY_BYTE_STORAGE); + return v.VerifyTypeStorage(arg.GetValueFixedArrayByteStorage(), "ani_fixedarray_byte"); +} + +static std::optional VerifyFixedArrayCharStorage(Verifier &v, const ANIArg &arg) +{ + ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_FIXED_ARRAY_CHAR_STORAGE); + return v.VerifyTypeStorage(arg.GetValueFixedArrayCharStorage(), "ani_fixedarray_char"); +} + +static std::optional VerifyFixedArrayDoubleStorage(Verifier &v, const ANIArg &arg) +{ + ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_FIXED_ARRAY_DOUBLE_STORAGE); + return v.VerifyTypeStorage(arg.GetValueFixedArrayDoubleStorage(), "ani_fixedarray_double"); +} + +static std::optional VerifyFixedArrayFloatStorage(Verifier &v, const ANIArg &arg) +{ + ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_FIXED_ARRAY_FLOAT_STORAGE); + return v.VerifyTypeStorage(arg.GetValueFixedArrayFloatStorage(), "ani_fixedarray_float"); +} + +static std::optional VerifyFixedArrayIntStorage(Verifier &v, const ANIArg &arg) +{ + ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_FIXED_ARRAY_INT_STORAGE); + return v.VerifyTypeStorage(arg.GetValueFixedArrayIntStorage(), "ani_fixedarray_int"); +} + +static std::optional VerifyFixedArrayLongStorage(Verifier &v, const ANIArg &arg) +{ + ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_FIXED_ARRAY_LONG_STORAGE); + return v.VerifyTypeStorage(arg.GetValueFixedArrayLongStorage(), "ani_fixedarray_long"); +} + +static std::optional VerifyFixedArrayShortStorage(Verifier &v, const ANIArg &arg) +{ + ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_FIXED_ARRAY_SHORT_STORAGE); + return v.VerifyTypeStorage(arg.GetValueFixedArrayShortStorage(), "ani_fixedarray_short"); +} + +static std::optional VerifyEmpty([[maybe_unused]] Verifier &v, [[maybe_unused]] const ANIArg &arg) +{ + ASSERT(arg.GetAction() == ANIArg::Action::VERIFY_EMPTY); + return {}; } // NOLINTBEGIN(cppcoreguidelines-macro-usage) diff --git a/static_core/plugins/ets/runtime/ani/verify/verify_ani_checker.h b/static_core/plugins/ets/runtime/ani/verify/verify_ani_checker.h index 83740661c2..f19d2b125b 100644 --- a/static_core/plugins/ets/runtime/ani/verify/verify_ani_checker.h +++ b/static_core/plugins/ets/runtime/ani/verify/verify_ani_checker.h @@ -41,7 +41,16 @@ X(VERIFY_ENV_STORAGE, VerifyEnvStorage) \ X(VERIFY_BOOLEAN_STORAGE, VerifyBooleanStorage) \ X(VERIFY_REF_STORAGE, VerifyRefStorage) \ - X(VERIFY_OBJECT_STORAGE, VerifyObjectStorage) + X(VERIFY_OBJECT_STORAGE, VerifyObjectStorage) \ + X(VERIFY_FIXED_ARRAY_BOOLEAN_STORAGE, VerifyFixedArrayBooleanStorage) \ + X(VERIFY_FIXED_ARRAY_BYTE_STORAGE, VerifyFixedArrayByteStorage) \ + X(VERIFY_FIXED_ARRAY_CHAR_STORAGE, VerifyFixedArrayCharStorage) \ + X(VERIFY_FIXED_ARRAY_DOUBLE_STORAGE, VerifyFixedArrayDoubleStorage) \ + X(VERIFY_FIXED_ARRAY_FLOAT_STORAGE, VerifyFixedArrayFloatStorage) \ + X(VERIFY_FIXED_ARRAY_INT_STORAGE, VerifyFixedArrayIntStorage) \ + X(VERIFY_FIXED_ARRAY_LONG_STORAGE, VerifyFixedArrayLongStorage) \ + X(VERIFY_FIXED_ARRAY_SHORT_STORAGE, VerifyFixedArrayShortStorage) \ + X(VERIFY_EMPTY, VerifyEmpty) \ // CC-OFFNXT(G.PRE.02-CPP, G.PRE.06) solid logic #define ANI_ARG_TYPES_MAP \ @@ -75,7 +84,16 @@ X(ANI_OBJECT_STORAGE, ObjectStorage, VObject **) \ X(UINT32, U32, uint32_t) \ X(UINT32x, U32x, uint32_t) \ - X(METHOD_ARGS, MethodArgs, AniMethodArgs *) + X(ANI_FIXED_ARRAY_BOOLEAN_STORAGE, FixedArrayBooleanStorage, VFixedArrayBoolean **) \ + X(ANI_FIXED_ARRAY_BYTE_STORAGE, FixedArrayByteStorage, VFixedArrayByte **) \ + X(ANI_FIXED_ARRAY_CHAR_STORAGE, FixedArrayCharStorage, VFixedArrayChar **) \ + X(ANI_FIXED_ARRAY_DOUBLE_STORAGE, FixedArrayDoubleStorage, VFixedArrayDouble **) \ + X(ANI_FIXED_ARRAY_FLOAT_STORAGE, FixedArrayFloatStorage, VFixedArrayFloat **) \ + X(ANI_FIXED_ARRAY_INT_STORAGE, FixedArrayIntStorage, VFixedArrayInt **) \ + X(ANI_FIXED_ARRAY_LONG_STORAGE, FixedArrayLongStorage, VFixedArrayLong **) \ + X(ANI_FIXED_ARRAY_SHORT_STORAGE, FixedArrayShortStorage, VFixedArrayShort **) \ + X(METHOD_ARGS, MethodArgs, AniMethodArgs *) + // NOLINTEND(cppcoreguidelines-macro-usage) // clang-format on @@ -91,6 +109,15 @@ class VEnv; class VRef; class VObject; class VClass; +class VFixedArrayBoolean; +class VFixedArrayChar; +class VFixedArrayByte; +class VFixedArrayShort; +class VFixedArrayInt; +class VFixedArrayLong; +class VFixedArrayFloat; +class VFixedArrayDouble; +class VFixedArrayRef; class ANIArg { public: @@ -195,6 +222,51 @@ public: return ANIArg(ArgValueByObjectStorage(valueStorage), name, Action::VERIFY_OBJECT_STORAGE); } + static ANIArg MakeForArrayBooleanStorage(VFixedArrayBoolean **arrStorage, std::string_view name) + { + return ANIArg(ArgValueByFixedArrayBooleanStorage(arrStorage), name, Action::VERIFY_FIXED_ARRAY_BOOLEAN_STORAGE); + } + + static ANIArg MakeForArrayByteStorage(VFixedArrayByte **arrStorage, std::string_view name) + { + return ANIArg(ArgValueByFixedArrayByteStorage(arrStorage), name, Action::VERIFY_FIXED_ARRAY_BYTE_STORAGE); + } + + static ANIArg MakeForArrayCharStorage(VFixedArrayChar **arrStorage, std::string_view name) + { + return ANIArg(ArgValueByFixedArrayCharStorage(arrStorage), name, Action::VERIFY_FIXED_ARRAY_CHAR_STORAGE); + } + + static ANIArg MakeForArrayDoubleStorage(VFixedArrayDouble **arrStorage, std::string_view name) + { + return ANIArg(ArgValueByFixedArrayDoubleStorage(arrStorage), name, Action::VERIFY_FIXED_ARRAY_DOUBLE_STORAGE); + } + + static ANIArg MakeForArrayFloatStorage(VFixedArrayFloat **arrStorage, std::string_view name) + { + return ANIArg(ArgValueByFixedArrayFloatStorage(arrStorage), name, Action::VERIFY_FIXED_ARRAY_FLOAT_STORAGE); + } + + static ANIArg MakeForArrayIntStorage(VFixedArrayInt **arrStorage, std::string_view name) + { + return ANIArg(ArgValueByFixedArrayIntStorage(arrStorage), name, Action::VERIFY_FIXED_ARRAY_INT_STORAGE); + } + + static ANIArg MakeForArrayLongStorage(VFixedArrayLong **arrStorage, std::string_view name) + { + return ANIArg(ArgValueByFixedArrayLongStorage(arrStorage), name, Action::VERIFY_FIXED_ARRAY_LONG_STORAGE); + } + + static ANIArg MakeForArrayShortStorage(VFixedArrayShort **arrStorage, std::string_view name) + { + return ANIArg(ArgValueByFixedArrayShortStorage(arrStorage), name, Action::VERIFY_FIXED_ARRAY_SHORT_STORAGE); + } + + static ANIArg MakeForSize(ani_size size, std::string_view name) + { + return ANIArg(ArgValueBySize(size), name, Action::VERIFY_EMPTY); + } + Action GetAction() const { return action_; diff --git a/static_core/plugins/ets/runtime/ani/verify/verify_ani_interaction_api.cpp b/static_core/plugins/ets/runtime/ani/verify/verify_ani_interaction_api.cpp index 9f30d24fed..4d6f779b3c 100644 --- a/static_core/plugins/ets/runtime/ani/verify/verify_ani_interaction_api.cpp +++ b/static_core/plugins/ets/runtime/ani/verify/verify_ani_interaction_api.cpp @@ -888,59 +888,155 @@ NO_UB_SANITIZE static ani_status FixedArray_GetLength(VEnv *venv, ani_fixedarray } // NOLINTNEXTLINE(readability-identifier-naming) -NO_UB_SANITIZE static ani_status FixedArray_New_Boolean(VEnv *venv, ani_size length, ani_fixedarray_boolean *result) +NO_UB_SANITIZE static ani_status FixedArray_New_Boolean(VEnv *venv, ani_size length, VFixedArrayBoolean **vresult) { - VERIFY_ANI_ARGS(ANIArg::MakeForEnv(venv, "env"), /* NOTE: Add checkers */); - return GetInteractionAPI(venv)->FixedArray_New_Boolean(venv->GetEnv(), length, result); + // clang-format off + VERIFY_ANI_ARGS( + ANIArg::MakeForEnv(venv, "env"), + ANIArg::MakeForSize(length, "length"), + ANIArg::MakeForArrayBooleanStorage(vresult, "result") + ); + // clang-format on + ani_fixedarray_boolean realResult {}; + ani_status status = GetInteractionAPI(venv)->FixedArray_New_Boolean(venv->GetEnv(), length, &realResult); + + if (LIKELY(status == ANI_OK)) { + *vresult = venv->AddLocalVerifiedRef(realResult); + } + return status; } // NOLINTNEXTLINE(readability-identifier-naming) -NO_UB_SANITIZE static ani_status FixedArray_New_Char(VEnv *venv, ani_size length, ani_fixedarray_char *result) +NO_UB_SANITIZE static ani_status FixedArray_New_Char(VEnv *venv, ani_size length, VFixedArrayChar **vresult) { - VERIFY_ANI_ARGS(ANIArg::MakeForEnv(venv, "env"), /* NOTE: Add checkers */); - return GetInteractionAPI(venv)->FixedArray_New_Char(venv->GetEnv(), length, result); + // clang-format off + VERIFY_ANI_ARGS( + ANIArg::MakeForEnv(venv, "env"), + ANIArg::MakeForSize(length, "length"), + ANIArg::MakeForArrayCharStorage(vresult, "result") + ); + // clang-format on + ani_fixedarray_char realResult {}; + ani_status status = GetInteractionAPI(venv)->FixedArray_New_Char(venv->GetEnv(), length, &realResult); + + if (LIKELY(status == ANI_OK)) { + *vresult = venv->AddLocalVerifiedRef(realResult); + } + return status; } // NOLINTNEXTLINE(readability-identifier-naming) -NO_UB_SANITIZE static ani_status FixedArray_New_Byte(VEnv *venv, ani_size length, ani_fixedarray_byte *result) +NO_UB_SANITIZE static ani_status FixedArray_New_Byte(VEnv *venv, ani_size length, VFixedArrayByte **vresult) { - VERIFY_ANI_ARGS(ANIArg::MakeForEnv(venv, "env"), /* NOTE: Add checkers */); - return GetInteractionAPI(venv)->FixedArray_New_Byte(venv->GetEnv(), length, result); + // clang-format off + VERIFY_ANI_ARGS( + ANIArg::MakeForEnv(venv, "env"), + ANIArg::MakeForSize(length, "length"), + ANIArg::MakeForArrayByteStorage(vresult, "result") + ); + // clang-format on + ani_fixedarray_byte realResult {}; + ani_status status = GetInteractionAPI(venv)->FixedArray_New_Byte(venv->GetEnv(), length, &realResult); + + if (LIKELY(status == ANI_OK)) { + *vresult = venv->AddLocalVerifiedRef(realResult); + } + return status; } // NOLINTNEXTLINE(readability-identifier-naming) -NO_UB_SANITIZE static ani_status FixedArray_New_Short(VEnv *venv, ani_size length, ani_fixedarray_short *result) +NO_UB_SANITIZE static ani_status FixedArray_New_Short(VEnv *venv, ani_size length, VFixedArrayShort **vresult) { - VERIFY_ANI_ARGS(ANIArg::MakeForEnv(venv, "env"), /* NOTE: Add checkers */); - return GetInteractionAPI(venv)->FixedArray_New_Short(venv->GetEnv(), length, result); + // clang-format off + VERIFY_ANI_ARGS( + ANIArg::MakeForEnv(venv, "env"), + ANIArg::MakeForSize(length, "length"), + ANIArg::MakeForArrayShortStorage(vresult, "result") + ); + // clang-format on + ani_fixedarray_short realResult {}; + ani_status status = GetInteractionAPI(venv)->FixedArray_New_Short(venv->GetEnv(), length, &realResult); + + if (LIKELY(status == ANI_OK)) { + *vresult = venv->AddLocalVerifiedRef(realResult); + } + return status; } // NOLINTNEXTLINE(readability-identifier-naming) -NO_UB_SANITIZE static ani_status FixedArray_New_Int(VEnv *venv, ani_size length, ani_fixedarray_int *result) +NO_UB_SANITIZE static ani_status FixedArray_New_Int(VEnv *venv, ani_size length, VFixedArrayInt **vresult) { - VERIFY_ANI_ARGS(ANIArg::MakeForEnv(venv, "env"), /* NOTE: Add checkers */); - return GetInteractionAPI(venv)->FixedArray_New_Int(venv->GetEnv(), length, result); + // clang-format off + VERIFY_ANI_ARGS( + ANIArg::MakeForEnv(venv, "env"), + ANIArg::MakeForSize(length, "length"), + ANIArg::MakeForArrayIntStorage(vresult, "result") + ); + // clang-format on + ani_fixedarray_int realResult {}; + ani_status status = GetInteractionAPI(venv)->FixedArray_New_Int(venv->GetEnv(), length, &realResult); + + if (LIKELY(status == ANI_OK)) { + *vresult = venv->AddLocalVerifiedRef(realResult); + } + return status; } // NOLINTNEXTLINE(readability-identifier-naming) -NO_UB_SANITIZE static ani_status FixedArray_New_Long(VEnv *venv, ani_size length, ani_fixedarray_long *result) +NO_UB_SANITIZE static ani_status FixedArray_New_Long(VEnv *venv, ani_size length, VFixedArrayLong **vresult) { - VERIFY_ANI_ARGS(ANIArg::MakeForEnv(venv, "env"), /* NOTE: Add checkers */); - return GetInteractionAPI(venv)->FixedArray_New_Long(venv->GetEnv(), length, result); + // clang-format off + VERIFY_ANI_ARGS( + ANIArg::MakeForEnv(venv, "env"), + ANIArg::MakeForSize(length, "length"), + ANIArg::MakeForArrayLongStorage(vresult, "result") + ); + // clang-format on + ani_fixedarray_long realResult {}; + ani_status status = GetInteractionAPI(venv)->FixedArray_New_Long(venv->GetEnv(), length, &realResult); + + if (LIKELY(status == ANI_OK)) { + *vresult = venv->AddLocalVerifiedRef(realResult); + } + return status; } // NOLINTNEXTLINE(readability-identifier-naming) -NO_UB_SANITIZE static ani_status FixedArray_New_Float(VEnv *venv, ani_size length, ani_fixedarray_float *result) +NO_UB_SANITIZE static ani_status FixedArray_New_Float(VEnv *venv, ani_size length, VFixedArrayFloat **vresult) { - VERIFY_ANI_ARGS(ANIArg::MakeForEnv(venv, "env"), /* NOTE: Add checkers */); - return GetInteractionAPI(venv)->FixedArray_New_Float(venv->GetEnv(), length, result); + // clang-format off + VERIFY_ANI_ARGS( + ANIArg::MakeForEnv(venv, "env"), + ANIArg::MakeForSize(length, "length"), + ANIArg::MakeForArrayFloatStorage(vresult, "result") + ); + // clang-format on + ani_fixedarray_float realResult {}; + ani_status status = GetInteractionAPI(venv)->FixedArray_New_Float(venv->GetEnv(), length, &realResult); + + if (LIKELY(status == ANI_OK)) { + *vresult = venv->AddLocalVerifiedRef(realResult); + } + return status; } // NOLINTNEXTLINE(readability-identifier-naming) -NO_UB_SANITIZE static ani_status FixedArray_New_Double(VEnv *venv, ani_size length, ani_fixedarray_double *result) +NO_UB_SANITIZE static ani_status FixedArray_New_Double(VEnv *venv, ani_size length, VFixedArrayDouble **vresult) { - VERIFY_ANI_ARGS(ANIArg::MakeForEnv(venv, "env"), /* NOTE: Add checkers */); - return GetInteractionAPI(venv)->FixedArray_New_Double(venv->GetEnv(), length, result); + // clang-format off + VERIFY_ANI_ARGS( + ANIArg::MakeForEnv(venv, "env"), + ANIArg::MakeForSize(length, "length"), + ANIArg::MakeForArrayDoubleStorage(vresult, "result") + ); + // clang-format on + ani_fixedarray_double realResult {}; + ani_status status = GetInteractionAPI(venv)->FixedArray_New_Double(venv->GetEnv(), length, &realResult); + + if (LIKELY(status == ANI_OK)) { + *vresult = venv->AddLocalVerifiedRef(realResult); + } + return status; } // NOLINTNEXTLINE(readability-identifier-naming) diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/CMakeLists.txt b/static_core/plugins/ets/tests/ani/tests/verifyani/CMakeLists.txt index ba09fc489c..9c3072ceec 100644 --- a/static_core/plugins/ets/tests/ani/tests/verifyani/CMakeLists.txt +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/CMakeLists.txt @@ -13,6 +13,7 @@ include(cmake/ani_verify_tests.cmake) +add_subdirectory(array_ops) add_subdirectory(object_ops) add_subdirectory(ref_ops) add_subdirectory(scope_ops) diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/CMakeLists.txt b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/CMakeLists.txt new file mode 100644 index 0000000000..99b8f9f0fb --- /dev/null +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/CMakeLists.txt @@ -0,0 +1,44 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ani_verify_add_gtest(ani_verify_test_fixed_array_new_boolean + CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/verify_fixed_array_new_boolean_test.cpp +) + +ani_verify_add_gtest(ani_verify_test_fixed_array_new_char + CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/verify_fixed_array_new_char_test.cpp +) + +ani_verify_add_gtest(ani_verify_test_fixed_array_new_byte + CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/verify_fixed_array_new_byte_test.cpp +) + +ani_verify_add_gtest(ani_verify_test_fixed_array_new_short + CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/verify_fixed_array_new_short_test.cpp +) + +ani_verify_add_gtest(ani_verify_test_fixed_array_new_int + CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/verify_fixed_array_new_int_test.cpp +) + +ani_verify_add_gtest(ani_verify_test_fixed_array_new_long + CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/verify_fixed_array_new_long_test.cpp +) + +ani_verify_add_gtest(ani_verify_test_fixed_array_new_float + CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/verify_fixed_array_new_float_test.cpp +) + +ani_verify_add_gtest(ani_verify_test_fixed_array_new_double + CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/verify_fixed_array_new_double_test.cpp +) diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_boolean_test.cpp b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_boolean_test.cpp new file mode 100644 index 0000000000..494c6c6142 --- /dev/null +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_boolean_test.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2025 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "verify_ani_gtest.h" + +namespace ark::ets::ani::verify::testing { + +class FixedArrayNewBooleanTest : public VerifyAniTest { +protected: + ani_size length = 3U; +}; + +TEST_F(FixedArrayNewBooleanTest, wrong_env) +{ + ani_fixedarray_boolean res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Boolean(nullptr, length, &res), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_boolean *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Boolean", testLines); +} + +TEST_F(FixedArrayNewBooleanTest, wrong_res) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Boolean(env_, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_boolean *", "wrong pointer for storing 'ani_fixedarray_boolean'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Boolean", testLines); +} + +TEST_F(FixedArrayNewBooleanTest, wrong_all_args) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Boolean(nullptr, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_boolean *", "wrong pointer for storing 'ani_fixedarray_boolean'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Boolean", testLines); +} + +TEST_F(FixedArrayNewBooleanTest, throw_error) +{ + ThrowError(); + + ani_fixedarray_boolean res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Boolean(env_, length, &res), ANI_ERROR); + ASSERT_EQ(env_->ResetError(), ANI_OK); + + std::vector testLines { + {"env", "ani_env *", "has unhandled an error"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_boolean *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Boolean", testLines); +} + +TEST_F(FixedArrayNewBooleanTest, success) +{ + ani_fixedarray_boolean res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Boolean(env_, length, &res), ANI_OK); + ASSERT_NE(res, nullptr); +} + +} // namespace ark::ets::ani::verify::testing diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_byte_test.cpp b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_byte_test.cpp new file mode 100644 index 0000000000..e356b71674 --- /dev/null +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_byte_test.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2025 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "verify_ani_gtest.h" + +namespace ark::ets::ani::verify::testing { + +class FixedArrayNewByteTest : public VerifyAniTest { +protected: + ani_size length = 3U; +}; + +TEST_F(FixedArrayNewByteTest, wrong_env) +{ + ani_fixedarray_byte res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Byte(nullptr, length, &res), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_byte *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Byte", testLines); +} + +TEST_F(FixedArrayNewByteTest, wrong_res) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Byte(env_, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_byte *", "wrong pointer for storing 'ani_fixedarray_byte'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Byte", testLines); +} + +TEST_F(FixedArrayNewByteTest, wrong_all_args) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Byte(nullptr, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_byte *", "wrong pointer for storing 'ani_fixedarray_byte'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Byte", testLines); +} + +TEST_F(FixedArrayNewByteTest, throw_error) +{ + ThrowError(); + + ani_fixedarray_byte res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Byte(env_, length, &res), ANI_ERROR); + ASSERT_EQ(env_->ResetError(), ANI_OK); + + std::vector testLines { + {"env", "ani_env *", "has unhandled an error"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_byte *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Byte", testLines); +} + +TEST_F(FixedArrayNewByteTest, success) +{ + ani_fixedarray_byte res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Byte(env_, length, &res), ANI_OK); + ASSERT_NE(res, nullptr); +} + +} // namespace ark::ets::ani::verify::testing diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_char_test.cpp b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_char_test.cpp new file mode 100644 index 0000000000..e22c461527 --- /dev/null +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_char_test.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2025 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "verify_ani_gtest.h" + +namespace ark::ets::ani::verify::testing { + +class FixedArrayNewCharTest : public VerifyAniTest { +protected: + ani_size length = 3U; +}; + +TEST_F(FixedArrayNewCharTest, wrong_env) +{ + ani_fixedarray_char res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Char(nullptr, length, &res), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_char *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Char", testLines); +} + +TEST_F(FixedArrayNewCharTest, wrong_res) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Char(env_, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_char *", "wrong pointer for storing 'ani_fixedarray_char'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Char", testLines); +} + +TEST_F(FixedArrayNewCharTest, wrong_all_args) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Char(nullptr, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_char *", "wrong pointer for storing 'ani_fixedarray_char'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Char", testLines); +} + +TEST_F(FixedArrayNewCharTest, throw_error) +{ + ThrowError(); + + ani_fixedarray_char res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Char(env_, length, &res), ANI_ERROR); + ASSERT_EQ(env_->ResetError(), ANI_OK); + + std::vector testLines { + {"env", "ani_env *", "has unhandled an error"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_char *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Char", testLines); +} + +TEST_F(FixedArrayNewCharTest, success) +{ + ani_fixedarray_char res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Char(env_, length, &res), ANI_OK); + ASSERT_NE(res, nullptr); +} + +} // namespace ark::ets::ani::verify::testing diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_double_test.cpp b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_double_test.cpp new file mode 100644 index 0000000000..a46e4fd29c --- /dev/null +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_double_test.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2025 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "verify_ani_gtest.h" + +namespace ark::ets::ani::verify::testing { + +class FixedArrayNewDoubleTest : public VerifyAniTest { +protected: + ani_size length = 3U; +}; + +TEST_F(FixedArrayNewDoubleTest, wrong_env) +{ + ani_fixedarray_double res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Double(nullptr, length, &res), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_double *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Double", testLines); +} + +TEST_F(FixedArrayNewDoubleTest, wrong_res) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Double(env_, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_double *", "wrong pointer for storing 'ani_fixedarray_double'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Double", testLines); +} + +TEST_F(FixedArrayNewDoubleTest, wrong_all_args) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Double(nullptr, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_double *", "wrong pointer for storing 'ani_fixedarray_double'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Double", testLines); +} + +TEST_F(FixedArrayNewDoubleTest, throw_error) +{ + ThrowError(); + + ani_fixedarray_double res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Double(env_, length, &res), ANI_ERROR); + ASSERT_EQ(env_->ResetError(), ANI_OK); + + std::vector testLines { + {"env", "ani_env *", "has unhandled an error"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_double *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Double", testLines); +} + +TEST_F(FixedArrayNewDoubleTest, success) +{ + ani_fixedarray_double res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Double(env_, length, &res), ANI_OK); + ASSERT_NE(res, nullptr); +} + +} // namespace ark::ets::ani::verify::testing diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_float_test.cpp b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_float_test.cpp new file mode 100644 index 0000000000..5d14ed4119 --- /dev/null +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_float_test.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2025 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "verify_ani_gtest.h" + +namespace ark::ets::ani::verify::testing { + +class FixedArrayNewFloatTest : public VerifyAniTest { +protected: + ani_size length = 3U; +}; + +TEST_F(FixedArrayNewFloatTest, wrong_env) +{ + ani_fixedarray_float res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Float(nullptr, length, &res), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_float *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Float", testLines); +} + +TEST_F(FixedArrayNewFloatTest, wrong_res) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Float(env_, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_float *", "wrong pointer for storing 'ani_fixedarray_float'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Float", testLines); +} + +TEST_F(FixedArrayNewFloatTest, wrong_all_args) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Float(nullptr, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_float *", "wrong pointer for storing 'ani_fixedarray_float'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Float", testLines); +} + +TEST_F(FixedArrayNewFloatTest, throw_error) +{ + ThrowError(); + + ani_fixedarray_float res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Float(env_, length, &res), ANI_ERROR); + ASSERT_EQ(env_->ResetError(), ANI_OK); + + std::vector testLines { + {"env", "ani_env *", "has unhandled an error"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_float *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Float", testLines); +} + +TEST_F(FixedArrayNewFloatTest, success) +{ + ani_fixedarray_float res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Float(env_, length, &res), ANI_OK); + ASSERT_NE(res, nullptr); +} + +} // namespace ark::ets::ani::verify::testing diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_int_test.cpp b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_int_test.cpp new file mode 100644 index 0000000000..8ccb31d0d0 --- /dev/null +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_int_test.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2025 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "verify_ani_gtest.h" + +namespace ark::ets::ani::verify::testing { + +class FixedArrayNewIntTest : public VerifyAniTest { +protected: + ani_size length = 3U; +}; + +TEST_F(FixedArrayNewIntTest, wrong_env) +{ + ani_fixedarray_int res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Int(nullptr, length, &res), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_int *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Int", testLines); +} + +TEST_F(FixedArrayNewIntTest, wrong_res) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Int(env_, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_int *", "wrong pointer for storing 'ani_fixedarray_int'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Int", testLines); +} + +TEST_F(FixedArrayNewIntTest, wrong_all_args) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Int(nullptr, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_int *", "wrong pointer for storing 'ani_fixedarray_int'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Int", testLines); +} + +TEST_F(FixedArrayNewIntTest, throw_error) +{ + ThrowError(); + + ani_fixedarray_int res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Int(env_, length, &res), ANI_ERROR); + ASSERT_EQ(env_->ResetError(), ANI_OK); + + std::vector testLines { + {"env", "ani_env *", "has unhandled an error"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_int *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Int", testLines); +} + +TEST_F(FixedArrayNewIntTest, success) +{ + ani_fixedarray_int res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Int(env_, length, &res), ANI_OK); + ASSERT_NE(res, nullptr); +} + +} // namespace ark::ets::ani::verify::testing diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_long_test.cpp b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_long_test.cpp new file mode 100644 index 0000000000..37e54666d2 --- /dev/null +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_long_test.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2025 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "verify_ani_gtest.h" + +namespace ark::ets::ani::verify::testing { + +class FixedArrayNewLongTest : public VerifyAniTest { +protected: + ani_size length = 3U; +}; + +TEST_F(FixedArrayNewLongTest, wrong_env) +{ + ani_fixedarray_long res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Long(nullptr, length, &res), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_long *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Long", testLines); +} + +TEST_F(FixedArrayNewLongTest, wrong_res) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Long(env_, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_long *", "wrong pointer for storing 'ani_fixedarray_long'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Long", testLines); +} + +TEST_F(FixedArrayNewLongTest, wrong_all_args) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Long(nullptr, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_long *", "wrong pointer for storing 'ani_fixedarray_long'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Long", testLines); +} + +TEST_F(FixedArrayNewLongTest, throw_error) +{ + ThrowError(); + + ani_fixedarray_long res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Long(env_, length, &res), ANI_ERROR); + ASSERT_EQ(env_->ResetError(), ANI_OK); + + std::vector testLines { + {"env", "ani_env *", "has unhandled an error"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_long *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Long", testLines); +} + +TEST_F(FixedArrayNewLongTest, success) +{ + ani_fixedarray_long res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Long(env_, length, &res), ANI_OK); + ASSERT_NE(res, nullptr); +} + +} // namespace ark::ets::ani::verify::testing diff --git a/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_short_test.cpp b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_short_test.cpp new file mode 100644 index 0000000000..35dab1118a --- /dev/null +++ b/static_core/plugins/ets/tests/ani/tests/verifyani/array_ops/verify_fixed_array_new_short_test.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2025 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "verify_ani_gtest.h" + +namespace ark::ets::ani::verify::testing { + +class FixedArrayNewShortTest : public VerifyAniTest { +protected: + ani_size length = 3U; +}; + +TEST_F(FixedArrayNewShortTest, wrong_env) +{ + ani_fixedarray_short res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Short(nullptr, length, &res), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_short *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Short", testLines); +} + +TEST_F(FixedArrayNewShortTest, wrong_res) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Short(env_, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_short *", "wrong pointer for storing 'ani_fixedarray_short'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Short", testLines); +} + +TEST_F(FixedArrayNewShortTest, wrong_all_args) +{ + ASSERT_EQ(env_->c_api->FixedArray_New_Short(nullptr, length, nullptr), ANI_ERROR); + std::vector testLines { + {"env", "ani_env *", "called from incorrect the native scope"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_short *", "wrong pointer for storing 'ani_fixedarray_short'"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Short", testLines); +} + +TEST_F(FixedArrayNewShortTest, throw_error) +{ + ThrowError(); + + ani_fixedarray_short res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Short(env_, length, &res), ANI_ERROR); + ASSERT_EQ(env_->ResetError(), ANI_OK); + + std::vector testLines { + {"env", "ani_env *", "has unhandled an error"}, + {"length", "ani_size"}, + {"result", "ani_fixedarray_short *"}, + }; + ASSERT_ERROR_ANI_ARGS_MSG("FixedArray_New_Short", testLines); +} + +TEST_F(FixedArrayNewShortTest, success) +{ + ani_fixedarray_short res {}; + ASSERT_EQ(env_->c_api->FixedArray_New_Short(env_, length, &res), ANI_OK); + ASSERT_NE(res, nullptr); +} + +} // namespace ark::ets::ani::verify::testing -- Gitee