From a1e4f516a411be7e082dcce7609192389f52230e Mon Sep 17 00:00:00 2001 From: lifansheng Date: Mon, 13 Dec 2021 16:50:00 +0800 Subject: [PATCH 1/3] Signed-off-by: lifansheng On branch master Your branch is up to date with 'origin/master'. --- test/unittest/test_util.cpp | 2413 +++++++++++++++++++++++++++++++++++ 1 file changed, 2413 insertions(+) diff --git a/test/unittest/test_util.cpp b/test/unittest/test_util.cpp index af2dbbf..b6d5334 100755 --- a/test/unittest/test_util.cpp +++ b/test/unittest/test_util.cpp @@ -23,6 +23,8 @@ #include "utils/log.h" #include "js_textdecoder.h" #include "js_textencoder.h" +#include "js_base64.h" +#include "js_types.h" #define ASSERT_CHECK_CALL(call) \ { \ @@ -677,3 +679,2414 @@ HWTEST_F(NativeEngineTest, decoderUtf16be003, testing::ext::TestSize.Level0) ch = nullptr; } } + +/* @tc.name: encodeTest001 + * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[3] = {0x73, 0x31, 0x33}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.Encode(src); + char excepted[4] = {0x63, 0x7A, 0x45, 0x7A}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + ASSERT_EQ(res[0], excepted[0]); + ASSERT_EQ(res[1], excepted[1]); + ASSERT_EQ(res[2], excepted[2]); + ASSERT_EQ(res[3], excepted[3]); +} + +/* @tc.name: encodeTest002 + * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[14] = {66, 97, 115, 101, 54, 52, 32, 78, 111, 100, 101, 46, 106, 115}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 14; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.Encode(src); + char excepted[20] = {81, 109, 70, 122, 90, 84, 89, 48, 73, 69, 53, 118, 90, 71, 85, 117, 97, 110, 77, 61}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + for (size_t i = 0; i < 20; i++) { + ASSERT_EQ(res[i], excepted[i]); + } +} + +/* @tc.name: encodeTest003 + * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[26] = {66, 97, 115, 101, 54, 52, 32, 69, 110, + 99, 111, 100, 105, 110, 103, 32, 105, 110, 32, 78, 111, 100, 101, 46, 106, 115}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 26; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.Encode(src); + char excepted[36] = {81, 109, 70, 122, 90, 84, 89, 48, 73, 69, 86, 117, 89, 50, 57, 107, 97, 87, 53, + 110, 73, 71, 108, 117, 73, 69, 53, 118, 90, 71, 85, 117, 97, 110, 77, 61}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + for (size_t i = 0; i < 36; i++) { + ASSERT_EQ(res[i], excepted[i]); + } +} + +/* @tc.name: encodeTest004 + * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[4] = {168, 174, 155, 255}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 4; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.Encode(src); + char excepted[8] = {113, 75, 54, 98, 47, 119, 61, 61}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + for (size_t i = 0; i < 8; i++) { + ASSERT_EQ(res[i], excepted[i]); + } +} + +/* @tc.name: encodeTest005 + * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[6] = {66, 97, 115, 101, 54, 52}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 6; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.Encode(src); + char excepted[8] = {81, 109, 70, 122, 90, 84, 89, 48}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + for (size_t i = 0; i < 8; i++) { + ASSERT_EQ(res[i], excepted[i]); + } +} + +/* @tc.name: encodeToStringTest001 + * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 3; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.EncodeToString(src); + size_t prolen = 0; + char* inputString = nullptr; + napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); + if (prolen > 0) { + inputString = new char[prolen + 1]; + if (memset_s(inputString, prolen + 1, '\0', prolen + 1) != 0) { + napi_throw_error(env, "-1", "decode inputString memset_s failed"); + } + } else { + napi_throw_error(env, "-2", "prolen is error !"); + } + napi_get_value_string_utf8(env, result, inputString, prolen + 1, &prolen); + ASSERT_STREQ("czEz", inputString); + if (inputString != nullptr) { + delete []inputString; + inputString = nullptr; + } +} + +/* @tc.name: encodeToStringTest002 + * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[14] = {66, 97, 115, 101, 54, 52, 32, 78, 111, 100, 101, 46, 106, 115}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 14; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.EncodeToString(src); + size_t prolen = 0; + char* inputString = nullptr; + napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); + if (prolen > 0) { + inputString = new char[prolen + 1]; + if (memset_s(inputString, prolen + 1, '\0', prolen + 1) != 0) { + napi_throw_error(env, "-1", "decode inputString memset_s failed"); + } + } else { + napi_throw_error(env, "-2", "prolen is error !"); + } + napi_get_value_string_utf8(env, result, inputString, prolen + 1, &prolen); + ASSERT_STREQ("QmFzZTY0IE5vZGUuanM=", inputString); + if (inputString != nullptr) { + delete []inputString; + inputString = nullptr; + } +} + +/* @tc.name: encodeToStringTest003 + * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[26] = {66, 97, 115, 101, 54, 52, 32, 69, 110, + 99, 111, 100, 105, 110, 103, 32, 105, 110, 32, 78, 111, 100, 101, 46, 106, 115}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 26; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.EncodeToString(src); + size_t prolen = 0; + char* inputString = nullptr; + napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); + if (prolen > 0) { + inputString = new char[prolen + 1]; + if (memset_s(inputString, prolen + 1, '\0', prolen + 1) != 0) { + napi_throw_error(env, "-1", "decode inputString memset_s failed"); + } + } else { + napi_throw_error(env, "-2", "prolen is error !"); + } + napi_get_value_string_utf8(env, result, inputString, prolen + 1, &prolen); + ASSERT_STREQ("QmFzZTY0IEVuY29kaW5nIGluIE5vZGUuanM=", inputString); + if (inputString != nullptr) { + delete []inputString; + inputString = nullptr; + } +} + +/* @tc.name: encodeToStringTest004 + * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[4] = {168, 174, 155, 255}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 4; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.EncodeToString(src); + size_t prolen = 0; + char* inputString = nullptr; + napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); + if (prolen > 0) { + inputString = new char[prolen + 1]; + if (memset_s(inputString, prolen + 1, '\0', prolen + 1) != 0) { + napi_throw_error(env, "-1", "decode inputString memset_s failed"); + } + } else { + napi_throw_error(env, "-2", "prolen is error !"); + } + napi_get_value_string_utf8(env, result, inputString, prolen + 1, &prolen); + ASSERT_STREQ("qK6b/w==", inputString); + if (inputString != nullptr) { + delete []inputString; + inputString = nullptr; + } +} + +/* @tc.name: encodeToStringTest005 + * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[6] = {66, 97, 115, 101, 54, 52}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 6; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.EncodeToString(src); + size_t prolen = 0; + char* inputString = nullptr; + napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); + if (prolen > 0) { + inputString = new char[prolen + 1]; + if (memset_s(inputString, prolen + 1, '\0', prolen + 1) != 0) { + napi_throw_error(env, "-1", "decode inputString memset_s failed"); + } + } else { + napi_throw_error(env, "-2", "prolen is error !"); + } + napi_get_value_string_utf8(env, result, inputString, prolen + 1, &prolen); + ASSERT_STREQ("QmFzZTY0", inputString); + if (inputString != nullptr) { + delete []inputString; + inputString = nullptr; + } +} + +/* @tc.name: decodeTest001 + * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[4] = {99, 122, 69, 122}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 4; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.Decode(src); + char excepted[3] = {115, 49, 51}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + + ASSERT_EQ(res[0], excepted[0]); + ASSERT_EQ(res[1], excepted[1]); + ASSERT_EQ(res[2], excepted[2]); +} + +/* @tc.name: decodeTest002 + * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[20] = {81, 109, 70, 122, 90, 84, 89, 48, 73, 69, 53, 118, 90, 71, 85, 117, 97, 110, 77, 61}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 20; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.Decode(src); + char excepted[14] = {66, 97, 115, 101, 54, 52, 32, 78, 111, 100, 101, 46, 106, 115}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + + for (size_t i = 0; i < 14; i++) { + ASSERT_EQ(res[i], excepted[i]); + } +} + +/* @tc.name: decodeTest003 + * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + std::string input = "czEz"; + napi_value src = nullptr; + napi_create_string_utf8(env, input.c_str(), input.size(), &src); + napi_value result = Base64.Decode(src); + char excepted[3] = {115, 49, 51}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + + ASSERT_EQ(res[0], excepted[0]); + ASSERT_EQ(res[1], excepted[1]); + ASSERT_EQ(res[2], excepted[2]); +} + +/* @tc.name: decodeTest004 + * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + std::string input = "qK6b/w=="; + napi_value src = nullptr; + napi_create_string_utf8(env, input.c_str(), input.size(), &src); + napi_value result = Base64.Decode(src); + char excepted[4] = {168, 174, 155, 255}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + for (size_t i = 0; i < 4; i++) { + ASSERT_EQ(res[i], excepted[i]); + } +} + +/* @tc.name: decodeTest005 + * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + std::string input = "QmFzZTY0"; + napi_value src = nullptr; + napi_create_string_utf8(env, input.c_str(), input.size(), &src); + napi_value result = Base64.Decode(src); + char excepted[6] = {66, 97, 115, 101, 54, 52}; + napi_typedarray_type type; + size_t srcLength = 0; + void* srcData = nullptr; + napi_value srcBuffer = nullptr; + size_t byteOffset = 0; + napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset); + char* res = (char*)srcData; + for (size_t i = 0; i < 6; i++) { + ASSERT_EQ(res[i], excepted[i]); + } +} + +/* @tc.name: encodeAsyncTest001 + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeAsyncTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeAsyncTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[3] = {0x73, 0x31, 0x33}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.EncodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: encodeAsyncTest002 + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeAsyncTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeAsyncTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[14] = {66, 97, 115, 101, 54, 52, 32, 78, 111, 100, 101, 46, 106, 115}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 14; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.EncodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: encodeAsyncTest003 + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeAsyncTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeAsyncTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[26] = {66, 97, 115, 101, 54, 52, 32, 69, 110, + 99, 111, 100, 105, 110, 103, 32, 105, 110, 32, 78, 111, 100, 101, 46, 106, 115};; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 26; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.EncodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: encodeAsyncTest004 + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeAsyncTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeAsyncTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[4] = {168, 174, 155, 255}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 4; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.EncodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: encodeAsyncTest005 + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeAsyncTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeAsyncTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[6] = {66, 97, 115, 101, 54, 52}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 6; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.EncodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: encodeToStringAsyncTest001 + * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringAsyncTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringAsyncTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 3; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.EncodeToStringAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: encodeToStringAsyncTest002 + * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringAsyncTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringAsyncTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[14] = {66, 97, 115, 101, 54, 52, 32, 78, 111, 100, 101, 46, 106, 115}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 14; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.EncodeToStringAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: encodeToStringAsyncTest003 + * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringAsyncTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringAsyncTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[26] = {66, 97, 115, 101, 54, 52, 32, 69, 110, + 99, 111, 100, 105, 110, 103, 32, 105, 110, 32, 78, 111, 100, 101, 46, 106, 115}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 26; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.EncodeToStringAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: encodeToStringAsyncTest004 + * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringAsyncTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringAsyncTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[4] = {168, 174, 155, 255}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 4; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.EncodeToStringAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: encodeToStringAsyncTest005 + * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, encodeToStringAsyncTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("encodeToStringAsyncTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + unsigned char input[6] = {66, 97, 115, 101, 54, 52}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 6; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value result = Base64.EncodeToStringAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + + + + +/* @tc.name: decodeAsyncTest001 + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeAsyncTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeAsyncTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[4] = {99, 122, 69, 122}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 4; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.DecodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: decodeAsyncTest002 + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeAsyncTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeAsyncTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + unsigned char input[8] = {113, 75, 54, 98, 47, 119, 61, 61}; + napi_value arrayBuffer = nullptr; + size_t arrayBufferSize = 8; + void* data = nullptr; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + napi_value result = Base64.DecodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: decodeAsyncTest003 + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeAsyncTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeAsyncTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + std::string input = "czEz"; + napi_value src = nullptr; + napi_create_string_utf8(env, input.c_str(), input.size(), &src); + napi_value result = Base64.DecodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: decodeAsyncTest004 + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeAsyncTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeAsyncTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + std::string input = "QmFzZTY0IEVuY29kaW5nIGluIE5vZGUuanM="; + napi_value src = nullptr; + napi_create_string_utf8(env, input.c_str(), input.size(), &src); + napi_value result = Base64.DecodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: decodeAsyncTest005 + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, decodeAsyncTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("decodeAsyncTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Base64 Base64(env); + + std::string input = "qK6b/w=="; + napi_value src = nullptr; + napi_create_string_utf8(env, input.c_str(), input.size(), &src); + napi_value result = Base64.DecodeAsync(src); + bool res = false; + napi_is_promise(env, result, &res); + ASSERT_TRUE(res); +} + +/* @tc.name: isAnyArrayBufferTest001 + * @tc.desc: Check whether the entered value is of arraybuffer or sharedarraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isAnyArrayBufferTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isAnyArrayBufferTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + + napi_value flag = Types.IsAnyArrayBuffer(arrayBuffer); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isAnyArrayBufferTest002 + * @tc.desc: Check whether the entered value is of arraybuffer or sharedarraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isAnyArrayBufferTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isAnyArrayBufferTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + bool value = false; + napi_value src = nullptr; + napi_get_boolean(env, value, &src); + + napi_value flag = Types.IsAnyArrayBuffer(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isAnyArrayBufferTest003 + * @tc.desc: Check whether the entered value is of arraybuffer or sharedarraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isAnyArrayBufferTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isAnyArrayBufferTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + bool value = true; + napi_value src = nullptr; + napi_get_boolean(env, value, &src); + + napi_value flag = Types.IsAnyArrayBuffer(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isAnyArrayBufferTest004 + * @tc.desc: Check whether the entered value is of arraybuffer or sharedarraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isAnyArrayBufferTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isAnyArrayBufferTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsAnyArrayBuffer(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isAnyArrayBufferTest005 + * @tc.desc: Check whether the entered value is of arraybuffer or sharedarraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isAnyArrayBufferTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isAnyArrayBufferTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsAnyArrayBuffer(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isArrayBufferViewTest001 + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferViewTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferViewTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsArrayBufferView(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isArrayBufferViewTest002 + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferViewTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferViewTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsArrayBufferView(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isArrayBufferViewTest003 + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferViewTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferViewTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsArrayBufferView(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isArrayBufferViewTest004 + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferViewTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferViewTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsArrayBufferView(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isArrayBufferViewTest005 + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferViewTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferViewTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsArrayBufferView(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isArrayBufferTest001 + * @tc.desc: Check whether the entered value is of arraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + + napi_value flag = Types.IsArrayBuffer(arrayBuffer); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isArrayBufferTest002 + * @tc.desc: Check whether the entered value is of arraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsArrayBuffer(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isArrayBufferTest003 + * @tc.desc: Check whether the entered value is of arraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsArrayBuffer(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isArrayBufferTest004 + * @tc.desc: Check whether the entered value is of arraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + bool value = true; + napi_value src = nullptr; + napi_get_boolean(env, value, &src); + + napi_value flag = Types.IsArrayBuffer(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isArrayBufferTest005 + * @tc.desc: Check whether the entered value is of arraybuffer type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isArrayBufferTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isArrayBufferTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + bool value = false; + napi_value src = nullptr; + napi_get_boolean(env, value, &src); + + napi_value flag = Types.IsArrayBuffer(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isDataViewTest001 + * @tc.desc: Check whether the entered value is of DataView type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isDataViewTest001, testing::ext::TestSize.Level0) //new ArrayBuffer([]) +{ + HILOG_INFO("isDataViewTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_dataview(env, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsDataView(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + + +/* @tc.name: isInt8ArrayTest001 + * @tc.desc: Check whether the entered value is of int8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt8ArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt8ArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isInt8ArrayTest002 + * @tc.desc: Check whether the entered value is of int8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt8ArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt8ArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt8ArrayTest003 + * @tc.desc: Check whether the entered value is of int8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt8ArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt8ArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt8ArrayTest004 + * @tc.desc: Check whether the entered value is of int8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt8ArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt8ArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt8ArrayTest005 + * @tc.desc: Check whether the entered value is of int8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt8ArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt8ArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt16ArrayTest001 + * @tc.desc: Check whether the entered value is the int16array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt16ArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt16ArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isInt16ArrayTest002 + * @tc.desc: Check whether the entered value is the int16array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt16ArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt16ArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt16ArrayTest003 + * @tc.desc: Check whether the entered value is the int16array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt16ArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt16ArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt16ArrayTest004 + * @tc.desc: Check whether the entered value is the int16array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt16ArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt16ArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt16ArrayTest005 + * @tc.desc: Check whether the entered value is the int16array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt16ArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt16ArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt32ArrayTest001 + * @tc.desc: Check whether the entered value is the int32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt32ArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt32ArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isInt32ArrayTest002 + * @tc.desc: Check whether the entered value is the int32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt32ArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt32ArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt32ArrayTest003 + * @tc.desc: Check whether the entered value is the int32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt32ArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt32ArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt32ArrayTest004 + * @tc.desc: Check whether the entered value is the int32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt32ArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt32ArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isInt32ArrayTest005 + * @tc.desc: Check whether the entered value is the int32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isInt32ArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isInt32ArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsInt32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint8ArrayTest001 + * @tc.desc: Check whether the entered value is the uint8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isUint8ArrayTest002 + * @tc.desc: Check whether the entered value is the uint8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint8ArrayTest003 + * @tc.desc: Check whether the entered value is the uint8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint8ArrayTest004 + * @tc.desc: Check whether the entered value is the uint8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint8ArrayTest005 + * @tc.desc: Check whether the entered value is the uint8array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isTypedArrayTest001 + * @tc.desc: Check whether the entered value is a type contained in typedarray. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isTypedArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isTypedArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsTypedArray(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isTypedArrayTest002 + * @tc.desc: Check whether the entered value is a type contained in typedarray. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isTypedArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isTypedArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_float32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsTypedArray(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isTypedArrayTest003 + * @tc.desc: Check whether the entered value is a type contained in typedarray. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isTypedArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isTypedArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsTypedArray(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isTypedArrayTest004 + * @tc.desc: Check whether the entered value is a type contained in typedarray. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isTypedArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isTypedArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsTypedArray(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isTypedArrayTest005 + * @tc.desc: Check whether the entered value is a type contained in typedarray. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isTypedArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isTypedArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + + napi_value flag = Types.IsTypedArray(arrayBuffer); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint8ClampedArrayTest001 + * @tc.desc: Check whether the entered value is the uint8clapedarray array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ClampedArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_clamped_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8ClampedArray(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isUint8ClampedArrayTest002 + * @tc.desc: Check whether the entered value is the uint8clapedarray array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ClampedArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_float32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8ClampedArray(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint8ClampedArrayTest003 + * @tc.desc: Check whether the entered value is the uint8clapedarray array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ClampedArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8ClampedArray(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint8ClampedArrayTest004 + * @tc.desc: Check whether the entered value is the uint8clapedarray array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ClampedArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8ClampedArray(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint8ClampedArrayTest005 + * @tc.desc: Check whether the entered value is the uint8clapedarray array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint8ClampedArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint8ClampedArray(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint16ArrayTest001 + * @tc.desc: Check whether the entered value is the uint16array array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint16ArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint16ArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isUint16ArrayTest002 + * @tc.desc: Check whether the entered value is the uint16array array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint16ArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint16ArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint16ArrayTest003 + * @tc.desc: Check whether the entered value is the uint16array array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint16ArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint16ArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint16ArrayTest004 + * @tc.desc: Check whether the entered value is the uint16array array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint16ArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint16ArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint16ArrayTest005 + * @tc.desc: Check whether the entered value is the uint16array array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint16ArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint16ArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint16Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint32ArrayTest001 + * @tc.desc: Check whether the entered value is the uint32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint32ArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint32ArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isUint32ArrayTest002 + * @tc.desc: Check whether the entered value is the uint32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint32ArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint32ArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint32ArrayTest003 + * @tc.desc: Check whether the entered value is the uint32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint32ArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint32ArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint32ArrayTest004 + * @tc.desc: Check whether the entered value is the uint32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint32ArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint32ArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isUint32ArrayTest005 + * @tc.desc: Check whether the entered value is the uint32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isUint32ArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isUint32ArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsUint32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isFloat32ArrayTest001 + * @tc.desc: Check whether the entered value is of float32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat32ArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat32ArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_float32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isFloat32ArrayTest002 + * @tc.desc: Check whether the entered value is of float32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat32ArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat32ArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isFloat32ArrayTest003 + * @tc.desc: Check whether the entered value is of float32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat32ArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat32ArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isFloat32ArrayTest004 + * @tc.desc: Check whether the entered value is of float32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat32ArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat32ArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isFloat32ArrayTest005 + * @tc.desc: Check whether the entered value is of float32array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat32ArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat32ArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat32Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isFloat64ArrayTest001 + * @tc.desc: Check whether the entered value is of float64array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat64ArrayTest001, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat64ArrayTest001 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_float64_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat64Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_TRUE(result); +} + +/* @tc.name: isFloat64ArrayTest002 + * @tc.desc: Check whether the entered value is of float64array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat64ArrayTest002, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat64ArrayTest002 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat64Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isFloat64ArrayTest003 + * @tc.desc: Check whether the entered value is of float64array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat64ArrayTest003, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat64ArrayTest003 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat64Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isFloat64ArrayTest004 + * @tc.desc: Check whether the entered value is of float64array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat64ArrayTest004, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat64ArrayTest004 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat64Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} + +/* @tc.name: isFloat64ArrayTest005 + * @tc.desc: Check whether the entered value is of float64array array type. + * @tc.type: FUNC + */ +HWTEST_F(NativeEngineTest, isFloat64ArrayTest005, testing::ext::TestSize.Level0) +{ + HILOG_INFO("isFloat64ArrayTest005 start"); + napi_env env = (napi_env)engine_; + OHOS::Util::Types Types(env); + unsigned char input[3] = {115, 49, 51}; + napi_value arrayBuffer = nullptr; + void* data = nullptr; + size_t arrayBufferSize = 3; + napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); + memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + napi_value src = nullptr; + napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); + + napi_value flag = Types.IsFloat64Array(src); + bool result = false; + napi_get_value_bool(env, flag, &result); + ASSERT_FALSE(result); +} \ No newline at end of file -- Gitee From f060162e7a68658062404c984c34e3e24aa43935 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Mon, 13 Dec 2021 17:28:45 +0800 Subject: [PATCH 2/3] Signed-off-by: lifansheng On branch master Your branch is up to date with 'origin/master'. --- test/unittest/test_util.cpp | 111 ++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 42 deletions(-) diff --git a/test/unittest/test_util.cpp b/test/unittest/test_util.cpp index b6d5334..fea14ed 100755 --- a/test/unittest/test_util.cpp +++ b/test/unittest/test_util.cpp @@ -681,7 +681,8 @@ HWTEST_F(NativeEngineTest, decoderUtf16be003, testing::ext::TestSize.Level0) } /* @tc.name: encodeTest001 - * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Encodes all bytes in the specified u8 array into + the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeTest001, testing::ext::TestSize.Level0) @@ -714,7 +715,8 @@ HWTEST_F(NativeEngineTest, encodeTest001, testing::ext::TestSize.Level0) } /* @tc.name: encodeTest002 - * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Encodes all bytes in the specified u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeTest002, testing::ext::TestSize.Level0) @@ -746,7 +748,8 @@ HWTEST_F(NativeEngineTest, encodeTest002, testing::ext::TestSize.Level0) } /* @tc.name: encodeTest003 - * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Encodes all bytes in the specified u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeTest003, testing::ext::TestSize.Level0) @@ -780,7 +783,8 @@ HWTEST_F(NativeEngineTest, encodeTest003, testing::ext::TestSize.Level0) } /* @tc.name: encodeTest004 - * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Encodes all bytes in the specified u8 array into the + newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeTest004, testing::ext::TestSize.Level0) @@ -812,7 +816,8 @@ HWTEST_F(NativeEngineTest, encodeTest004, testing::ext::TestSize.Level0) } /* @tc.name: encodeTest005 - * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Encodes all bytes in the specified u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeTest005, testing::ext::TestSize.Level0) @@ -840,7 +845,7 @@ HWTEST_F(NativeEngineTest, encodeTest005, testing::ext::TestSize.Level0) char* res = (char*)srcData; for (size_t i = 0; i < 8; i++) { ASSERT_EQ(res[i], excepted[i]); - } + } } /* @tc.name: encodeToStringTest001 @@ -878,7 +883,7 @@ HWTEST_F(NativeEngineTest, encodeToStringTest001, testing::ext::TestSize.Level0) if (inputString != nullptr) { delete []inputString; inputString = nullptr; - } + } } /* @tc.name: encodeToStringTest002 @@ -916,7 +921,7 @@ HWTEST_F(NativeEngineTest, encodeToStringTest002, testing::ext::TestSize.Level0) if (inputString != nullptr) { delete []inputString; inputString = nullptr; - } + } } /* @tc.name: encodeToStringTest003 @@ -955,7 +960,7 @@ HWTEST_F(NativeEngineTest, encodeToStringTest003, testing::ext::TestSize.Level0) if (inputString != nullptr) { delete []inputString; inputString = nullptr; - } + } } /* @tc.name: encodeToStringTest004 @@ -993,7 +998,7 @@ HWTEST_F(NativeEngineTest, encodeToStringTest004, testing::ext::TestSize.Level0) if (inputString != nullptr) { delete []inputString; inputString = nullptr; - } + } } /* @tc.name: encodeToStringTest005 @@ -1031,11 +1036,12 @@ HWTEST_F(NativeEngineTest, encodeToStringTest005, testing::ext::TestSize.Level0) if (inputString != nullptr) { delete []inputString; inputString = nullptr; - } + } } /* @tc.name: decodeTest001 - * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Decodes the Base64-encoded string or input u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeTest001, testing::ext::TestSize.Level0) @@ -1068,7 +1074,8 @@ HWTEST_F(NativeEngineTest, decodeTest001, testing::ext::TestSize.Level0) } /* @tc.name: decodeTest002 - * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Decodes the Base64-encoded string or input u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeTest002, testing::ext::TestSize.Level0) @@ -1101,7 +1108,8 @@ HWTEST_F(NativeEngineTest, decodeTest002, testing::ext::TestSize.Level0) } /* @tc.name: decodeTest003 - * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Decodes the Base64-encoded string or input u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeTest003, testing::ext::TestSize.Level0) @@ -1129,7 +1137,8 @@ HWTEST_F(NativeEngineTest, decodeTest003, testing::ext::TestSize.Level0) } /* @tc.name: decodeTest004 - * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Decodes the Base64-encoded string or input u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeTest004, testing::ext::TestSize.Level0) @@ -1156,7 +1165,8 @@ HWTEST_F(NativeEngineTest, decodeTest004, testing::ext::TestSize.Level0) } /* @tc.name: decodeTest005 - * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Decodes the Base64-encoded string or input u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeTest005, testing::ext::TestSize.Level0) @@ -1183,7 +1193,8 @@ HWTEST_F(NativeEngineTest, decodeTest005, testing::ext::TestSize.Level0) } /* @tc.name: encodeAsyncTest001 - * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeAsyncTest001, testing::ext::TestSize.Level0) @@ -1207,7 +1218,8 @@ HWTEST_F(NativeEngineTest, encodeAsyncTest001, testing::ext::TestSize.Level0) } /* @tc.name: encodeAsyncTest002 - * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeAsyncTest002, testing::ext::TestSize.Level0) @@ -1231,7 +1243,8 @@ HWTEST_F(NativeEngineTest, encodeAsyncTest002, testing::ext::TestSize.Level0) } /* @tc.name: encodeAsyncTest003 - * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeAsyncTest003, testing::ext::TestSize.Level0) @@ -1256,7 +1269,8 @@ HWTEST_F(NativeEngineTest, encodeAsyncTest003, testing::ext::TestSize.Level0) } /* @tc.name: encodeAsyncTest004 - * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeAsyncTest004, testing::ext::TestSize.Level0) @@ -1280,7 +1294,8 @@ HWTEST_F(NativeEngineTest, encodeAsyncTest004, testing::ext::TestSize.Level0) } /* @tc.name: encodeAsyncTest005 - * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. + * @tc.desc: Asynchronously encodes all bytes in the specified u8 array + into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, encodeAsyncTest005, testing::ext::TestSize.Level0) @@ -1324,7 +1339,7 @@ HWTEST_F(NativeEngineTest, encodeToStringAsyncTest001, testing::ext::TestSize.Le napi_value result = Base64.EncodeToStringAsync(src); bool res = false; napi_is_promise(env, result, &res); - ASSERT_TRUE(res); + ASSERT_TRUE(res); } /* @tc.name: encodeToStringAsyncTest002 @@ -1361,7 +1376,7 @@ HWTEST_F(NativeEngineTest, encodeToStringAsyncTest003, testing::ext::TestSize.Le napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[26] = {66, 97, 115, 101, 54, 52, 32, 69, 110, - 99, 111, 100, 105, 110, 103, 32, 105, 110, 32, 78, 111, 100, 101, 46, 106, 115}; + 99, 111, 100, 105, 110, 103, 32, 105, 110, 32, 78, 111, 100, 101, 46, 106, 115}; napi_value arrayBuffer = nullptr; void* data = nullptr; size_t arrayBufferSize = 26; @@ -1424,11 +1439,9 @@ HWTEST_F(NativeEngineTest, encodeToStringAsyncTest005, testing::ext::TestSize.Le ASSERT_TRUE(res); } - - - /* @tc.name: decodeAsyncTest001 - * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a + Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeAsyncTest001, testing::ext::TestSize.Level0) @@ -1448,11 +1461,12 @@ HWTEST_F(NativeEngineTest, decodeAsyncTest001, testing::ext::TestSize.Level0) napi_value result = Base64.DecodeAsync(src); bool res = false; napi_is_promise(env, result, &res); - ASSERT_TRUE(res); + ASSERT_TRUE(res); } /* @tc.name: decodeAsyncTest002 - * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a + Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeAsyncTest002, testing::ext::TestSize.Level0) @@ -1472,11 +1486,12 @@ HWTEST_F(NativeEngineTest, decodeAsyncTest002, testing::ext::TestSize.Level0) napi_value result = Base64.DecodeAsync(src); bool res = false; napi_is_promise(env, result, &res); - ASSERT_TRUE(res); + ASSERT_TRUE(res); } /* @tc.name: decodeAsyncTest003 - * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a + Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeAsyncTest003, testing::ext::TestSize.Level0) @@ -1491,11 +1506,12 @@ HWTEST_F(NativeEngineTest, decodeAsyncTest003, testing::ext::TestSize.Level0) napi_value result = Base64.DecodeAsync(src); bool res = false; napi_is_promise(env, result, &res); - ASSERT_TRUE(res); + ASSERT_TRUE(res); } /* @tc.name: decodeAsyncTest004 - * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a + Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeAsyncTest004, testing::ext::TestSize.Level0) @@ -1510,11 +1526,12 @@ HWTEST_F(NativeEngineTest, decodeAsyncTest004, testing::ext::TestSize.Level0) napi_value result = Base64.DecodeAsync(src); bool res = false; napi_is_promise(env, result, &res); - ASSERT_TRUE(res); + ASSERT_TRUE(res); } /* @tc.name: decodeAsyncTest005 - * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. + * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a + Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, decodeAsyncTest005, testing::ext::TestSize.Level0) @@ -1529,7 +1546,7 @@ HWTEST_F(NativeEngineTest, decodeAsyncTest005, testing::ext::TestSize.Level0) napi_value result = Base64.DecodeAsync(src); bool res = false; napi_is_promise(env, result, &res); - ASSERT_TRUE(res); + ASSERT_TRUE(res); } /* @tc.name: isAnyArrayBufferTest001 @@ -1641,7 +1658,9 @@ HWTEST_F(NativeEngineTest, isAnyArrayBufferTest005, testing::ext::TestSize.Level } /* @tc.name: isArrayBufferViewTest001 - * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array + or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or + napi_ float32_ array or napi_ float64_ array array or DataView type. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, isArrayBufferViewTest001, testing::ext::TestSize.Level0) @@ -1665,7 +1684,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferViewTest001, testing::ext::TestSize.Leve } /* @tc.name: isArrayBufferViewTest002 - * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array + or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or + napi_ float32_ array or napi_ float64_ array array or DataView type. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, isArrayBufferViewTest002, testing::ext::TestSize.Level0) @@ -1689,7 +1710,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferViewTest002, testing::ext::TestSize.Leve } /* @tc.name: isArrayBufferViewTest003 - * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array + or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or + napi_ float32_ array or napi_ float64_ array array or DataView type. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, isArrayBufferViewTest003, testing::ext::TestSize.Level0) @@ -1713,7 +1736,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferViewTest003, testing::ext::TestSize.Leve } /* @tc.name: isArrayBufferViewTest004 - * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array + or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or + napi_ float32_ array or napi_ float64_ array array or DataView type. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, isArrayBufferViewTest004, testing::ext::TestSize.Level0) @@ -1737,7 +1762,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferViewTest004, testing::ext::TestSize.Leve } /* @tc.name: isArrayBufferViewTest005 - * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. + * @tc.desc: Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array + or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or + napi_ float32_ array or napi_ float64_ array array or DataView type. * @tc.type: FUNC */ HWTEST_F(NativeEngineTest, isArrayBufferViewTest005, testing::ext::TestSize.Level0) @@ -1872,7 +1899,7 @@ HWTEST_F(NativeEngineTest, isArrayBufferTest005, testing::ext::TestSize.Level0) * @tc.desc: Check whether the entered value is of DataView type. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, isDataViewTest001, testing::ext::TestSize.Level0) //new ArrayBuffer([]) +HWTEST_F(NativeEngineTest, isDataViewTest001, testing::ext::TestSize.Level0) { HILOG_INFO("isDataViewTest001 start"); napi_env env = (napi_env)engine_; -- Gitee From 6ab9a54a67d9398d43315ffa81eb7fbcebfe1ea1 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Tue, 21 Dec 2021 16:44:51 +0800 Subject: [PATCH 3/3] Signed-off-by: lifansheng On branch master Your branch is up to date with 'origin/master'. --- README.md | 188 +++--- README_zh.md | 192 +++--- util/build_ts_js.py => build_ts_js.py | 27 +- mgit.info | 1 + mozilla_docs.txt | 29 - ohos.build | 1 - test/unittest/BUILD.gn | 14 +- test/unittest/test.h | 2 +- .../{test_ark.cpp => test_quickjs.cpp} | 38 +- test/unittest/test_util.cpp | 591 +++++++++++------- util/BUILD.gn | 8 +- util/js_base64.cpp | 70 ++- util/js_base64.h | 24 +- util/js_types.cpp | 277 ++++---- util/js_types.h | 83 ++- util/native_module_util.cpp | 58 +- util/src/util_js.ts | 48 +- util/tsconfig.json | 6 +- 18 files changed, 881 insertions(+), 776 deletions(-) rename util/build_ts_js.py => build_ts_js.py (71%) mode change 100755 => 100644 create mode 100644 mgit.info delete mode 100644 mozilla_docs.txt rename test/unittest/{test_ark.cpp => test_quickjs.cpp} (56%) diff --git a/README.md b/README.md index 1b261e2..6639085 100755 --- a/README.md +++ b/README.md @@ -24,26 +24,26 @@ base/compileruntime/js_util_module/ │ ├── new TextDecoder() # create TextDecoder object │ ├── decode() # decode method │ ├── encoding # encoding property -│ ├── fatal # fatal property -│ └── ignoreBOM # ignoreBOM property +│ ├── fatal # fatal property +│ └── ignoreBOM # ignoreBOM property ├── printf() # printf method ├── getErrorString() # getErrorString method ├── callbackWrapper() # callbackWrapper method ├── promiseWrapper() # promiseWrapper method ├── Class:Base64 # Base64 class │ ├── new Base64() # create Base64 object +│ ├── encodeSync() # encodeSync method +│ ├── encodeToStringSync() # encodeToStringSync method +│ ├── decodeSync() # decodeSync method │ ├── encode() # encode method │ ├── encodeToString() # encodeToString method -│ ├── decode() # decode method -│ ├── encodeAsync() # encodeAsync method -│ ├── encodeToStringAsync() # encodeToStringAsync method -│ └── decodeAsync() # decodeAsync method +│ └── decode() # decode method ├── Class:RationalNumber # RationalNumber class │ ├── new RationalNumber() # create RationalNumber object │ ├── createRationalFromString() # creatRationalFromString method │ ├── compareTo() # compareTo method │ ├── equals() # equals method -│ ├── value() # value method +│ ├── valueOf() # valueOf method │ ├── getCommonDivisor() # getCommonDivisor method │ ├── getDenominator() # getDenominator method │ ├── getNumerator() # getNumerator method @@ -56,8 +56,8 @@ base/compileruntime/js_util_module/ │ ├── updateCapacity() # updateCapacity method │ ├── toString() # toString method │ ├── values() # values method -│ ├── size() # size method -│ ├── capacity() # capacity method +│ ├── length # attribute of length +│ ├── getCapacity() # getCapacity method │ ├── clear() # clear method │ ├── getCreateCount # getCreateCount method │ ├── getMissCount() # getMissCount method @@ -81,9 +81,9 @@ base/compileruntime/js_util_module/ | ├── intersect() # intersect method | ├── getUpper() # getUpper method | ├── getLower() # getLower method -| ├── expand() # expand method | ├── expand() # expand method -| ├── expand() # expand method +| ├── expand() # expand method +| ├── expand() # expand method | ├── contains() # contains method | ├── contains() # contains method | └── clamp() # clamp method @@ -97,7 +97,6 @@ base/compileruntime/js_util_module/ ├── isBigUint64Array() # isBigUint64Array method ├── isBooleanObject() # isBooleanObject method ├── isBoxedPrimitive() # isBoxedPrimitive method - ├── isCryptoKey() # isCryptoKey method ├── isDataView() # isDataView method ├── isDate() # isDate method ├── isExternal() # isExternal method @@ -108,7 +107,6 @@ base/compileruntime/js_util_module/ ├── isInt8Array() # isInt8Array method ├── isInt16Array() # isInt16Array method ├── isInt32Array() # isInt32Array method - ├── isKeyObject() # isKeyObject method ├── isMap() # isMap method ├── isMapIterator() # isMapIterator method ├── isModuleNamespaceObject() # isModuleNamespaceObject method @@ -144,16 +142,16 @@ base/compileruntime/js_util_module/ | readonly fatal : boolean | Get the setting that throws the exception. | | readonly ignoreBOM : boolean | Get whether to ignore the setting of the bom flag. | | decode(input : Uint8Array, options?: { stream?: false }) : string | Input the data to be decoded, and solve the corresponding string character string.The first parameter input represents the data to be decoded, and the second parameter options represents a bool flag, which means that additional data will be followed. The default is false. | -| encode(src: Uint8Array): Uint8Array; | Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. | -| encodeToString(src: Uint8Array): string; | Encodes the specified byte array as a String using the Base64 encoding scheme. | -| decode(src: Uint8Array \| string): Uint8Array; | Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. | -| encodeAsync(src: Uint8Array): Promise\; | Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. | -| encodeToStringAsync(src: Uint8Array): Promise\; | Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. | -| decodeAsync(src: Uint8Array \| string): Promise\; | Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. | +| encodeSync(src: Uint8Array): Uint8Array; | Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. | +| encodeToStringSync(src: Uint8Array): string; | Encodes the specified byte array as a String using the Base64 encoding scheme. | +| decodeSync(src: Uint8Array \| string): Uint8Array; | Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. | +| encode(src: Uint8Array): Promise\; | Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. | +| encodeToString(src: Uint8Array): Promise\; | Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. | +| decode(src: Uint8Array \| string): Promise\; | Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. | | static createRationalFromString(rationalString: string): RationalNumber | Create a RationalNumber object based on the given string. | | compareTo(another: RationalNumber): number | Compare the current RationalNumber object with the given object. | | equals(obj: object): number | Check if the given object is the same as the current RationalNumber object.| -| value(): number | Take the current RationalNumber object to an integer value or a floating point value. | +| valueOf(): number | Take the current RationalNumber object to an integer value or a floating point value. | | static getCommonDivisor(number1: number, number2: number,): number | Obtain the greatest common divisor of two specified numbers. | | getDenominator(): number | Get the denominator of the current RationalNumber object. | | getNumerator(): number | Get the numerator of the current RationalNumber object. | @@ -165,8 +163,8 @@ base/compileruntime/js_util_module/ | updateCapacity(newCapacity: number): void | Updates the buffer capacity to the specified capacity. This exception is thrown if newCapacity is less than or equal to 0. | | toString(): string | Returns the string representation of the object and outputs the string representation of the object. | | values(): V[ ] | Gets a list of all values in the current buffer, and the output returns a list of all values in the current buffer in ascending order, from most recently accessed to least recently accessed. | -| size(): number | Gets the total number of values in the current buffer. The output returns the total number of values in the current buffer. | -| capacity(): number | Gets the capacity of the current buffer. The output returns the capacity of the current buffer. | +| length: number | represents the total number of values in the current buffer. The output returns the total number of values in the current buffer. | +| getCapacity(): number | Gets the capacity of the current buffer. The output returns the capacity of the current buffer. | | clear(): void | The key value pairs are cleared from the current buffer, after the key value is cleared, the afterRemoval () method is invoked to perform subsequent operations in turn. | | getCreateCount(): number | Get the number of times the returned value of createdefault(), and output the number of times the returned value of createdefault(). | | getMissCount(): number | Get the number of times the query value does not match, and output the number of times the query value does not match. | @@ -208,7 +206,6 @@ base/compileruntime/js_util_module/ | isBigUint64Array(value: Object): boolean | Check whether the entered value is of biguint64array array array type. | | isBooleanObject(value: Object): boolean | Check whether the entered value is a Boolean object type. | | isBoxedPrimitive(value: Object): boolean | Check whether the entered value is a Boolean or number or string or symbol object type. | -| isCryptoKey(value: Object): boolean | Check whether the entered value is the cryptokey object type. | | isDataView(value: Object): boolean | Check whether the entered value is of DataView type. | | isDate(value: Object): boolean | Check whether the entered value is of type date. | | isExternal(value: Object): boolean | Check whether the entered value is a native external value type. | @@ -219,7 +216,6 @@ base/compileruntime/js_util_module/ | isInt8Array(value: Object): boolean | Check whether the entered value is of int8array array type. | | isInt16Array(value: Object): boolean | Check whether the entered value is the int16array type. | | isInt32Array(value: Object): boolean | Check whether the entered value is the int32array array type. | -| isKeyObject(value: Object): boolean | Check whether the entered value is the keyobject object type. | | isMap(value: Object): boolean | Check whether the entered value is of map type. | | isMapIterator(value: Object): boolean | Check whether the entered value is the iterator type of map. | | isModuleNamespaceObject(value: Object): boolean | Check whether the entered value is the module namespace object object type. | @@ -349,51 +345,51 @@ newPromiseObj.then(res => { expect(res).strictEqual('HelloWorld'); }) ``` -13.encode() +13.encodeSync() ``` import util from '@ohos.util' var that = new util.Base64(); var array = new Uint8Array([115,49,51]); -var result = that.encode(array); +var result = that.encodeSync(array); ``` -14.encodeToString() +14.encodeToStringSync() ``` import util from '@ohos.util' var that = new util.Base64(); var array = new Uint8Array([115,49,51]); -var result = that.encodeToString(array); +var result = that.encodeToStringSync(array); ``` -15.decode() +15.decodeSync() ``` import util from '@ohos.util' var that = new util.Base64() var buff = 'czEz'; -var result = that.decode(buff); +var result = that.decodeSync(buff); ``` -16.encodeAsync() +16.encode() ``` import util from '@ohos.util' var that = new util.Base64() var array = new Uint8Array([115,49,51]); -await that.encodeAsync(array).then(val=>{ +await that.encode(array).then(val=>{ }) done() ``` -17.encodeToStringAsync() +17.encodeToString() ``` import util from '@ohos.util' var that = new util.Base64() var array = new Uint8Array([115,49,51]); -await that.encodeToStringAsync(array).then(val=>{ +await that.encodeToString(array).then(val=>{ }) done() ``` -18.decodeAsync() +18.decode() ``` import util from '@ohos.util' var that = new util.Base64() var buff = 'czEz'; -await that.decodeAsync(buff).then(val=>{ +await that.decode(buff).then(val=>{ }) done() ``` @@ -418,7 +414,7 @@ var pro = new util.RationalNumber(2, 1); var proc = new util.RationalNumber(3, 4); var res = pro.equals(proc); ``` -22.value() +22.valueOf() ``` import util from '@ohos.util' var pro = new util.RationalNumber(2, 1); @@ -468,7 +464,7 @@ var pro = new util.RationalNumber(-2, 1); var res = pro.toString(); ``` -30.updateCapacity() +30.updateCapacity() ``` import util from '@ohos.util' var pro = new util.LruBuffer(); @@ -492,21 +488,21 @@ pro.put(2,"anhu"); pro.put("afaf","grfb"); var result = pro.values(); ``` -33.size() +33.length ``` import util from '@ohos.util' var pro = new util.LruBuffer(); pro.put(2,10); pro.put(1,8); -var result = pro.size(); +var result = pro.length; ``` -34.capacity() +34.getCapacity() ``` import util from '@ohos.util' var pro = new util.LruBuffer(); -var result = pro.capacity(); +var result = pro.getCapacity(); ``` -35.clear() +35.clear() ``` import util from '@ohos.util' var pro = new util.LruBuffer(); @@ -576,7 +572,7 @@ var result = pro.put(2,10); ``` import util from '@ohos.util' var pro = new util.LruBuffer(); -pro.put(2,10); + pro.put(2,10); var result = pro.keys(); ``` 45.remove() @@ -613,7 +609,7 @@ var pro = new util.LruBuffer(); pro.put(2,10); var result = pro[symbol.iterator](); ``` -50.afterRemoval() +50.afterRemoval() ``` import util from '@ohos.util' var arr = []; @@ -659,20 +655,26 @@ class Temperature { } } ``` + 51.constructor() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); var range = new Scope(tempLower, tempUpper); ``` + 52.toString() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); var range = new Scope(tempLower, tempUpper); var result = range.toString() // => [30,40] ``` + 53.intersect() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -682,7 +684,9 @@ var tempMidS = new Temperature(39); var rangeFir = new Scope(tempMiDF, tempMidS); var result = range.intersect(rangeFir) // => [35,39] ``` + 54.intersect() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -691,21 +695,27 @@ var tempMidS = new Temperature(39); var range = new Scope(tempLower, tempUpper); var result = range.intersect(tempMiDF, tempMidS) // => [35,39] ``` + 55.getUpper() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); var range = new Scope(tempLower, tempUpper); var result = range.getUpper() // => 40 ``` + 56.getLower() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); var range = new Scope(tempLower, tempUpper); var result = range.getLower() // => 30 ``` + 57.expand() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -714,7 +724,9 @@ var tempMidS = new Temperature(39); var range = new Scope(tempLower, tempUpper); var result = range.expand(tempMiDF, tempMidS) // => [30,40] ``` + 58.expand() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -724,7 +736,9 @@ var range = new Scope(tempLower, tempUpper); var rangeFir = new Scope(tempMiDF, tempMidS); var result = range.expand(rangeFir) // => [30,40] ``` + 59.expand() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -732,7 +746,9 @@ var tempMiDF = new Temperature(35); var range = new Scope(tempLower, tempUpper); var result = range.expand(tempMiDF) // => [30,40] ``` + 60.contains() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -740,7 +756,9 @@ var tempMiDF = new Temperature(35); var range = new Scope(tempLower, tempUpper); var result = range.contains(tempMiDF) // => true ``` + 61.contains() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -750,7 +768,9 @@ var tempMore = new Temperature(45); var rangeSec = new Scope(tempLess, tempMore); var result = range.contains(rangeSec) // => true ``` + 62.clamp() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -814,50 +834,44 @@ import util from '@ohos.util' var proc = new util.Types(); var result = proc.isBoxedPrimitive(new Boolean(false)); ``` -72.isCryptoKey() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isCryptoKey(false); -``` -73.isDataView() +72.isDataView() ``` import util from '@ohos.util' var proc = new util.Types(); const ab = new ArrayBuffer(20); var result = proc.isDataView(new DataView(ab)); ``` -74.isDate() +73.isDate() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isDate(new Date()); ``` -75.isExternal() +74.isExternal() ``` import util from '@ohos.util' const data = util.createExternalType(); var reult13 = proc.isExternal(data); ``` -76.isFloat32Array() +75.isFloat32Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isFloat32Array(new Float32Array([])); ``` -77.isFloat64Array() +76.isFloat64Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isFloat64Array(new Float64Array([])); ``` -78.isGeneratorFunction() +77.isGeneratorFunction() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isGeneratorFunction(function* foo() {}); ``` -79.isGeneratorObject() +78.isGeneratorObject() ``` import util from '@ohos.util' var proc = new util.Types(); @@ -865,67 +879,61 @@ function* foo() {} const generator = foo(); var result = proc.isGeneratorObject(generator); ``` -80.isInt8Array() +79.isInt8Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isInt8Array(new Int8Array([])); ``` -81.isInt16Array() +80.isInt16Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isInt16Array(new Int16Array([])); ``` -82.isInt32Array() +81.isInt32Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isInt32Array(new Int32Array([])); ``` -83.isKeyObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isKeyObject(0); -``` -84.isMap() +82.isMap() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isMap(new Map()); ``` -85.isMapIterator() +83.isMapIterator() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isMapIterator(map.keys()); ``` -86.isModuleNamespaceObject() +84.isModuleNamespaceObject() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isModuleNamespaceObject(util); ``` -87.isNativeError() +85.isNativeError() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isNativeError(new TypeError()); ``` -88.isNumberObject() +86.isNumberObject() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isNumberObject(new Number(0)); ``` -89.isPromise() +87.isPromise() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isPromise(Promise.resolve(42)); ``` -90.isProxy() +88.isProxy() ``` import util from '@ohos.util' var proc = new util.Types(); @@ -933,81 +941,81 @@ const target = {}; const proxy = new Proxy(target, {}); var result = proc.isProxy(proxy); ``` -91.isRegExp() +89.isRegExp() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isRegExp(new RegExp('abc')); ``` -92.isSet() +90.isSet() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isSet(new Set()); ``` -93.isSetIterator() +91.isSetIterator() ``` import util from '@ohos.util' var proc = new util.Types(); const set = new Set(); var result = proc.isSetIterator(set.keys()); ``` -94.isSharedArrayBuffer() +92.isSharedArrayBuffer() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isSharedArrayBuffer(new ArrayBuffer([])); ``` -95.isStringObject() +93.isStringObject() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isStringObject(new String('foo')); ``` -96.isSymbolObject() +94.isSymbolObject() ``` import util from '@ohos.util' var proc = new util.Types(); const symbols = Symbol('foo'); var result = proc.isSymbolObject(Object(symbols)); ``` -97.isTypedArray() +95.isTypedArray() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isTypedArray(new Float64Array([])); ``` -98.isUint8Array() +96.isUint8Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isUint8Array(new Uint8Array([])); ``` -99.isUint8ClampedArray() +97.isUint8ClampedArray() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isUint8ClampedArray(new Uint8ClampedArray([])); ``` -100.isUint16Array() +98.isUint16Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isUint16Array(new Uint16Array([])); ``` -101.isUint32Array() +99.isUint32Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isUint32Array(new Uint32Array([])); ``` -102.isWeakMap() +100.isWeakMap() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isWeakMap(new WeakMap()); ``` -103.isWeakSet() +101.isWeakSet() ``` import util from '@ohos.util' var proc = new util.Types(); @@ -1015,10 +1023,8 @@ var result = proc.isWeakSet(new WeakSet()); ``` ## Related warehouse -[js_util_module subsystem](https://gitee.com/OHOS_STD/js_util_module) -[base/compileruntime/js_util_module/](base/compileruntime/js_util_module-readme.md) -## License +[js_util_module subsystem](https://gitee.com/OHOS_STD/js_util_module) -Util is available under [Mozilla license](https://www.mozilla.org/en-US/MPL/), and the documentation is detailed in [documentation](https://gitee.com/openharmony/js_util_module/blob/master/mozilla_docs.txt). See [LICENSE](https://gitee.com/openharmony/js_util_module/blob/master/LICENSE) for the full license text. \ No newline at end of file +[base/compileruntime/js_util_module/](base/compileruntime/js_util_module-readme.md) diff --git a/README_zh.md b/README_zh.md index 9f3838a..c9f17ac 100644 --- a/README_zh.md +++ b/README_zh.md @@ -32,18 +32,18 @@ base/compileruntime/js_util_module/ ├── promiseWrapper() # promiseWrapper方法 ├── Class:Base64 # Base64类 │ ├── new Base64() # 创建Base64对象 +│ ├── encodeSync() # encodeSync方法 +│ ├── encodeToStringSync() # encodeToStringSync方法 +│ ├── decodeSync() # decodeSync方法 │ ├── encode() # encode方法 │ ├── encodeToString() # encodeToString方法 -│ ├── decode() # decode方法 -│ ├── encodeAsync() # encodeAsync方法 -│ ├── encodeToStringAsync() # encodeToStringAsync方法 -│ └── decodeAsync() # decodeAsync方法 +│ └── decode() # decode方法 ├── Class:RationalNumber # RationalNumber类 │ ├── new RationalNumber() # 创建RationalNumber对象 │ ├── createRationalFromString() # createRationalFromString方法 │ ├── compareTo() # compareTo方法 │ ├── equals() # equals方法 -│ ├── value() # value方法 +│ ├── valueOf() # valueOf方法 │ ├── getCommonDivisor() # getCommonDivisor方法 │ ├── getDenominator() # getDenominator方法 │ ├── getNumerator() # getNumerator方法 @@ -56,8 +56,8 @@ base/compileruntime/js_util_module/ │ ├── updateCapacity() # updateCapacity方法 │ ├── toString() # toString方法 │ ├── values() # values方法 -│ ├── size() # size方法 -│ ├── capacity() # capacity方法 +│ ├── length # length属性 +│ ├── getCapacity() # getCapacity方法 │ ├── clear() # clear方法 │ ├── getCreateCount() # getCreateCount方法 │ ├── getMissCount() # getMissCount方法 @@ -81,7 +81,7 @@ base/compileruntime/js_util_module/ | ├── intersect() # intersect方法 | ├── getUpper() # getUpper方法 | ├── getLower() # getLower方法 -| ├── expand() # expand方法 +| ├── expand() # expand方法 | ├── expand() # expand方法 | ├── expand() # expand法 | ├── contains() # contains方法 @@ -97,7 +97,6 @@ base/compileruntime/js_util_module/ ├── isBigUint64Array() # isBigUint64Array方法 ├── isBooleanObject() # isBooleanObject方法 ├── isBoxedPrimitive() # isBoxedPrimitive方法 - ├── isCryptoKey() # isCryptoKey方法 ├── isDataView() # isDataView方法 ├── isDate() # isDate方法 ├── isExternal() # isExternal方法 @@ -108,7 +107,6 @@ base/compileruntime/js_util_module/ ├── isInt8Array() # isInt8Array方法 ├── isInt16Array() # isInt16Array方法 ├── isInt32Array() # isInt32Array方法 - ├── isKeyObject() # isKeyObject方法 ├── isMap() # isMap方法 ├── isMapIterator() # isMapIterator方法 ├── isModuleNamespaceObject() # isModuleNamespaceObject方法 @@ -145,16 +143,16 @@ base/compileruntime/js_util_module/ | readonly fatal : boolean | 获取抛出异常的设置。 | | readonly ignoreBOM : boolean | 获取是否忽略bom标志的设置。 | | decode(input : Uint8Array, options?: { stream?: false }) : string | 输入要解码的数据,解出对应的string字符串。第一个参数input表示要解码的数据,第二个参数options表示一个bool标志,表示将跟随附加数据,默认为false。 | -| encode(src: Uint8Array): Uint8Array; | 使用Base64编码方案将指定u8数组中的所有字节编码到新分配的u8数组中。 | -| encodeToString(src: Uint8Array): string; | 使用Base64编码方案将指定的字节数组编码为String。 | -| decode(src: Uint8Array \| string): Uint8Array; | 使用Base64编码方案将Base64编码的字符串或输入u8数组解码为新分配的u8数组。 | -| encodeAsync(src: Uint8Array): Promise\; | 使用Base64编码方案将指定u8数组中的所有字节异步编码到新分配的u8数组中。 | -| encodeToStringAsync(src: Uint8Array): Promise\; | 使用Base64编码方案将指定的字节数组异步编码为String。 | -| decodeAsync(src: Uint8Array \| string): Promise\; | 使用Base64编码方案将Base64编码的字符串或输入u8数组异步解码为新分配的u8数组。 | +| encodeSync(src: Uint8Array): Uint8Array; | 使用Base64编码方案将指定u8数组中的所有字节编码到新分配的u8数组中。 | +| encodeToStringSync(src: Uint8Array): string; | 使用Base64编码方案将指定的字节数组编码为String。 | +| decodeSync(src: Uint8Array \| string): Uint8Array; | 使用Base64编码方案将Base64编码的字符串或输入u8数组解码为新分配的u8数组。 | +| encode(src: Uint8Array): Promise\; | 使用Base64编码方案将指定u8数组中的所有字节异步编码到新分配的u8数组中。 | +| encodeToString(src: Uint8Array): Promise\; | 使用Base64编码方案将指定的字节数组异步编码为String。 | +| decode(src: Uint8Array \| string): Promise\; | 使用Base64编码方案将Base64编码的字符串或输入u8数组异步解码为新分配的u8数组。 | | static createRationalFromString(rationalString: string): RationalNumber | 基于给定的字符串创建一个RationalNumber对象。 | | compareTo(another: RationalNumber): number | 将当前的RationalNumber对象与给定的对象进行比较。 | | equals(obj: object): number | 检查给定对象是否与当前 RationalNumber 对象相同。 | -| value(): number | 将当前的RationalNumber对象进行取整数值或者浮点数值。 | +| valueOf(): number | 将当前的RationalNumber对象进行取整数值或者浮点数值。 | | static getCommonDivisor(number1: number, number2: number,): number | 获得两个指定数的最大公约数。 | | getDenominator(): number | 获取当前的RationalNumber对象的分母。 | | getNumerator(): number | 获取当前的RationalNumber对象的分子。 | @@ -166,8 +164,8 @@ base/compileruntime/js_util_module/ | updateCapacity(newCapacity: number): void | 将缓冲区容量更新为指定容量,如果 newCapacity 小于或等于 0,则抛出此异常。 | | toString(): string | 返回对象的字符串表示形式,输出对象的字符串表示 | | values(): V[] | 获取当前缓冲区中所有值的列表,输出按升序返回当前缓冲区中所有值的列表,从最近访问到最近最少访问。 | -| size(): number | 获取当前缓冲区中值的总数,输出返回当前缓冲区中值的总数。 | -| capacity(): number | 获取当前缓冲区的容量,输出返回当前缓冲区的容量。 | +| length: number | 代表当前缓冲区中值的总数,输出返回当前缓冲区中值的总数。 | +| getCapacity(): number | 获取当前缓冲区的容量,输出返回当前缓冲区的容量。 | | clear(): void | 从当前缓冲区清除键值对,清除键值对后,调用afterRemoval()方法依次对其执行后续操作。 | | getCreateCount(): number | 获取createDefault()返回值的次数,输出返回createDefault()返回值的次数。 | | getMissCount(): number | 获取查询值不匹配的次数,输出返回查询值不匹配的次数。 | @@ -209,7 +207,6 @@ base/compileruntime/js_util_module/ | isBigUint64Array(value: Object): boolean | 检查输入的value是否是BigUint64Array数组类型。 | | isBooleanObject(value: Object): boolean | 检查输入的value是否是一个布尔对象类型。 | | isBoxedPrimitive(value: Object): boolean | 检查输入的value是否是Boolean或Number或String或Symbol对象类型。 | -| isCryptoKey(value: Object): boolean | 检查输入的value是否是CryptoKey对象类型。 | | isDataView(value: Object): boolean | 检查输入的value是否是DataView类型。 | | isDate(value: Object): boolean | 检查输入的value是否是Date类型。 | | isExternal(value: Object): boolean | 检查输入的value是否是一个native External值类型。 | @@ -220,7 +217,6 @@ base/compileruntime/js_util_module/ | isInt8Array(value: Object): boolean | 检查输入的value是否是Int8Array数组类型。 | | isInt16Array(value: Object): boolean | 检查输入的value是否是Int16Array数组类型。 | | isInt32Array(value: Object): boolean | 检查输入的value是否是Int32Array数组类型。 | -| isKeyObject(value: Object): boolean | 检查输入的value是否是KeyObject对象类型。 | | isMap(value: Object): boolean | 检查输入的value是否是Map类型。 | | isMapIterator(value: Object): boolean | 检查输入的value是否是Map的iterator类型。 | | isModuleNamespaceObject(value: Object): boolean | 检查输入的value是否是Module Namespace Object对象类型。 | @@ -348,52 +344,52 @@ newPromiseObj.then(res => { expect(res).strictEqual('HelloWorld'); }) ``` -13.encode() +13.encodeSync() ``` import util from '@ohos.util' var that = new util.Base64(); var array = new Uint8Array([115,49,51]); -var result = that.encode(array); +var result = that.encodeSync(array); ``` -14.encodeToString() +14.encodeToStringSync() ``` import util from '@ohos.util' var that = new util.Base64(); var array = new Uint8Array([115,49,51]); -var result = that.encodeToString(array); +var result = that.encodeToStringSync(array); ``` -15.decode() +15.decodeSync() ``` import util from '@ohos.util' var that = new util.Base64() var buff = 'czEz'; -var result = that.decode(buff); +var result = that.decodeSync(buff); ``` -16.encodeAsync() +16.encode() ``` import util from '@ohos.util' var that = new util.Base64() var array = new Uint8Array([115,49,51]); -await that.encodeAsync(array).then(val=>{ +await that.encode(array).then(val=>{ }) done() ``` -17.encodeToStringAsync() +17.encodeToString() ``` import util from '@ohos.util' var that = new util.Base64() var array = new Uint8Array([115,49,51]); -await that.encodeToStringAsync(array).then(val=>{ +await that.encodeToString(array).then(val=>{ }) done() ``` -18.decodeAsync() +18.decode() ``` import util from '@ohos.util' var that = new util.Base64() var buff = 'czEz'; -await that.decodeAsync(buff).then(val=>{ +await that.decode(buff).then(val=>{ }) done() ``` @@ -402,7 +398,7 @@ done() import util from '@ohos.util' var pro = new util.RationalNumber(0, 0); var res = pro.createRationalFromString("-1:2"); -var result1 = res.value(); +var result1 = res.valueOf(); ``` 20.compareTo() ``` @@ -418,11 +414,11 @@ var pro = new util.RationalNumber(2, 1); var proc = new util.RationalNumber(3, 4); var res = pro.equals(proc); ``` -22.value() +22.valueOf() ``` import util from '@ohos.util' var pro = new util.RationalNumber(2, 1); -var res = pro.value(); +var res = pro.valueOf(); ``` 23.getCommonDivisor() ``` @@ -459,16 +455,14 @@ var res = pro.isNaN(); import util from '@ohos.util' var pro = new util.RationalNumber(-2, 1); var res = pro.isZero(); - ``` 29.toString() ``` import util from '@ohos.util' var pro = new util.RationalNumber(-2, 1); var res = pro.toString(); - ``` -30.updateCapacity() +30.updateCapacity() ``` import util from '@ohos.util' var pro = new util.LruBuffer(); @@ -492,21 +486,21 @@ pro.put(2,"anhu"); pro.put("afaf","grfb"); var result = pro.values(); ``` -33.size() +33.length ``` import util from '@ohos.util' var pro = new util.LruBuffer(); pro.put(2,10); pro.put(1,8); -var result = pro.size(); +var result = pro.length; ``` -34.capacity() +34.getCapacity() ``` import util from '@ohos.util' var pro = new util.LruBuffer(); -var result = pro.capacity(); +var result = pro.getCapacity(); ``` -35.clear() +35.clear() ``` import util from '@ohos.util' var pro = new util.LruBuffer(); @@ -530,12 +524,14 @@ var result = pro.getMissCount(); ``` 38.getRemovalCount() ``` + import util from '@ohos.util' var pro = new util.LruBuffer(); pro.put(2,10); pro.updateCapacity(2); pro.put(50,22); var result = pro.getRemovalCount(); + ``` 39.getMatchCount() ``` @@ -560,6 +556,7 @@ pro.put(2,10); var result = pro.isEmpty(); ``` 42.get() + ``` import util from '@ohos.util' var pro = new util.LruBuffer(); @@ -607,14 +604,13 @@ pro.put(2,10); var result = pro.entries(); ``` 49.\[Symbol.iterator\]() - ``` import util from '@ohos.util' var pro = new util.LruBuffer(); -pro.put(2,10); +pro .put(2,10); var result = pro[symbol.iterator](); ``` -50.afterRemoval() +50.afterRemoval() ``` import util from '@ohos.util' var arr = [ ]; @@ -660,20 +656,26 @@ class Temperature { } } ``` + 51.constructor() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); var range = new Scope(tempLower, tempUpper); ``` + 52.toString() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); var range = new Scope(tempLower, tempUpper); var result = range.toString() // => [30,40] ``` + 53.intersect() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -683,7 +685,9 @@ var tempMidS = new Temperature(39); var rangeFir = new Scope(tempMiDF, tempMidS); var result = range.intersect(rangeFir) // => [35,39] ``` + 54.intersect() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -692,21 +696,27 @@ var tempMidS = new Temperature(39); var range = new Scope(tempLower, tempUpper); var result = range.intersect(tempMiDF, tempMidS) // => [35,39] ``` + 55.getUpper() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); var range = new Scope(tempLower, tempUpper); var result = range.getUpper() // => 40 ``` + 56.getLower() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); var range = new Scope(tempLower, tempUpper); var result = range.getLower() // => 30 ``` + 57.expand() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -715,7 +725,9 @@ var tempMidS = new Temperature(39); var range = new Scope(tempLower, tempUpper); var result = range.expand(tempMiDF, tempMidS) // => [30,40] ``` + 58.expand() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -725,7 +737,9 @@ var range = new Scope(tempLower, tempUpper); var rangeFir = new Scope(tempMiDF, tempMidS); var result = range.expand(rangeFir) // => [30,40] ``` + 59.expand() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -733,7 +747,9 @@ var tempMiDF = new Temperature(35); var range = new Scope(tempLower, tempUpper); var result = range.expand(tempMiDF) // => [30,40] ``` + 60.contains() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -741,7 +757,9 @@ var tempMiDF = new Temperature(35); var range = new Scope(tempLower, tempUpper); var result = range.contains(tempMiDF) // => true ``` + 61.contains() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -751,7 +769,9 @@ var tempMore = new Temperature(45); var rangeSec = new Scope(tempLess, tempMore); var result = range.contains(rangeSec) // => true ``` + 62.clamp() + ``` var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -815,50 +835,44 @@ import util from '@ohos.util' var proc = new util.Types(); var result = proc.isBoxedPrimitive(new Boolean(false)); ``` -72.isCryptoKey() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isCryptoKey(false); -``` -73.isDataView() +72.isDataView() ``` import util from '@ohos.util' var proc = new util.Types(); const ab = new ArrayBuffer(20); var result = proc.isDataView(new DataView(ab)); ``` -74.isDate() +73.isDate() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isDate(new Date()); ``` -75.isExternal() +74.isExternal() ``` import util from '@ohos.util' const data = util.createExternalType(); var reult13 = proc.isExternal(data); ``` -76.isFloat32Array() +75.isFloat32Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isFloat32Array(new Float32Array([])); ``` -77.isFloat64Array() +76.isFloat64Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isFloat64Array(new Float64Array([])); ``` -78.isGeneratorFunction() +77.isGeneratorFunction() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isGeneratorFunction(function* foo() {}); ``` -79.isGeneratorObject() +78.isGeneratorObject() ``` import util from '@ohos.util' var proc = new util.Types(); @@ -866,67 +880,61 @@ function* foo() {} const generator = foo(); var result = proc.isGeneratorObject(generator); ``` -80.isInt8Array() +79.isInt8Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isInt8Array(new Int8Array([])); ``` -81.isInt16Array() +80.isInt16Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isInt16Array(new Int16Array([])); ``` -82.isInt32Array() +81.isInt32Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isInt32Array(new Int32Array([])); ``` -83.isKeyObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isKeyObject(0); -``` -84.isMap() +82.isMap() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isMap(new Map()); ``` -85.isMapIterator() +83.isMapIterator() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isMapIterator(map.keys()); ``` -86.isModuleNamespaceObject() +84.isModuleNamespaceObject() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isModuleNamespaceObject(util); ``` -87.isNativeError() +85.isNativeError() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isNativeError(new TypeError()); ``` -88.isNumberObject() +86.isNumberObject() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isNumberObject(new Number(0)); ``` -89.isPromise() +87.isPromise() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isPromise(Promise.resolve(42)); ``` -90.isProxy() +88.isProxy() ``` import util from '@ohos.util' var proc = new util.Types(); @@ -934,81 +942,81 @@ const target = {}; const proxy = new Proxy(target, {}); var result = proc.isProxy(proxy); ``` -91.isRegExp() +89.isRegExp() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isRegExp(new RegExp('abc')); ``` -92.isSet() +90.isSet() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isSet(new Set()); ``` -93.isSetIterator() +91.isSetIterator() ``` import util from '@ohos.util' var proc = new util.Types(); const set = new Set(); var result = proc.isSetIterator(set.keys()); ``` -94.isSharedArrayBuffer() +92.isSharedArrayBuffer() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isSharedArrayBuffer(new ArrayBuffer([])); ``` -95.isStringObject() +93.isStringObject() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isStringObject(new String('foo')); ``` -96.isSymbolObject() +94.isSymbolObject() ``` import util from '@ohos.util' var proc = new util.Types(); const symbols = Symbol('foo'); var result = proc.isSymbolObject(Object(symbols)); ``` -97.isTypedArray() +95.isTypedArray() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isTypedArray(new Float64Array([])); ``` -98.isUint8Array() +96.isUint8Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isUint8Array(new Uint8Array([])); ``` -99.isUint8ClampedArray() +97.isUint8ClampedArray() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isUint8ClampedArray(new Uint8ClampedArray([])); ``` -100.isUint16Array() +98.isUint16Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isUint16Array(new Uint16Array([])); ``` -101.isUint32Array() +99.isUint32Array() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isUint32Array(new Uint32Array([])); ``` -102.isWeakMap() +100.isWeakMap() ``` import util from '@ohos.util' var proc = new util.Types(); var result = proc.isWeakMap(new WeakMap()); ``` -103.isWeakSet() +101.isWeakSet() ``` import util from '@ohos.util' var proc = new util.Types(); @@ -1016,10 +1024,8 @@ var result = proc.isWeakSet(new WeakSet()); ``` ## 相关仓 -[js_util_module子系统](https://gitee.com/OHOS_STD/js_util_module) -[base/compileruntime/js_util_module/](base/compileruntime/js_util_module-readme.md) -## 许可证 +[js_util_module子系统](https://gitee.com/OHOS_STD/js_util_module) -Util在[Mozilla许可证](https://www.mozilla.org/en-US/MPL/)下可用,说明文档详见[说明文档](https://gitee.com/openharmony/js_util_module/blob/master/mozilla_docs.txt)。有关完整的许可证文本,有关完整的许可证文本,请参见[许可证](https://gitee.com/openharmony/js_util_module/blob/master/LICENSE) \ No newline at end of file +[base/compileruntime/js_util_module/](base/compileruntime/js_util_module-readme.md) diff --git a/util/build_ts_js.py b/build_ts_js.py old mode 100755 new mode 100644 similarity index 71% rename from util/build_ts_js.py rename to build_ts_js.py index cb4d8eb..93af118 --- a/util/build_ts_js.py +++ b/build_ts_js.py @@ -13,10 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. import os +import shutil import platform import argparse import subprocess + def run_command(in_cmd): print(" ".join(in_cmd)) proc = subprocess.Popen(in_cmd, stdout=subprocess.PIPE, @@ -25,31 +27,34 @@ def run_command(in_cmd): shell=False) stdout, stderr = proc.communicate() if stdout != "": - print(stdout) - exit(1) - + raise Exception(stdout) if __name__ == '__main__': - BUILD_PATH = os.path.abspath(os.path.join(os.getcwd(), "../..")) - os.chdir("%s/base/compileruntime/js_util_module/util" % BUILD_PATH) PARSER_INST = argparse.ArgumentParser() PARSER_INST.add_argument('--dst-file', help='the converted target file') + PARSER_INST.add_argument('--module-path', + help='the module path') + PARSER_INST.add_argument('--out-file', + help='js output file') INPUT_ARGUMENTS = PARSER_INST.parse_args() - + BUILD_PATH = os.path.abspath(os.path.join(os.getcwd(), "../..")) + os.chdir(("%s" + INPUT_ARGUMENTS.module_path) % BUILD_PATH) NODE_PATH = '../../../../prebuilts/build-tools/common/nodejs/\ node-v12.18.4-linux-x64/bin/node' + if not os.path.exists(NODE_PATH): + raise Exception('NO souch file or directory') TSC_PATH = '../../../../ark/ts2abc/ts2panda/node_modules/\ typescript/bin/tsc' CMD_INST = [NODE_PATH, TSC_PATH] run_command(CMD_INST) + if not os.path.exists(INPUT_ARGUMENTS.out_file): + raise Exception('error:NO souch file or directory') + CMD_INST = shutil.copy(INPUT_ARGUMENTS.out_file, INPUT_ARGUMENTS.dst_file) - CMD_INST = ['cp', "-r", './out/util_js.js', INPUT_ARGUMENTS.dst_file] - run_command(CMD_INST) + CMD_INST = shutil.rmtree('./out') - CMD_INST = ['rm', "-rf", './out'] - run_command(CMD_INST) - exit(0) + exit(0) \ No newline at end of file diff --git a/mgit.info b/mgit.info new file mode 100644 index 0000000..05e243f --- /dev/null +++ b/mgit.info @@ -0,0 +1 @@ +hmf/js_util_module diff --git a/mozilla_docs.txt b/mozilla_docs.txt deleted file mode 100644 index d1fa0fb..0000000 --- a/mozilla_docs.txt +++ /dev/null @@ -1,29 +0,0 @@ - -The definitions of some interfaces implemented in jsapi/api/js_url.cpp are released under Mozilla license. - -The definitions and functions of these interfaces are consistent with the standard interfaces under mozila license, -but the implementation of specific functions is independent and self-developed. - -All interfaces are described in d.ts, the following is the interface written in d.ts under to Mozilla license - -class TextDecoder { - readonly encoding: string; - readonly fatal: boolean; - readonly ignoreBOM = false; - constructor( - encoding?: string, - options?: { fatal?: boolean; ignoreBOM?: boolean }, - ); - decode(input: Uint8Array, options?: { stream?: false }): string; -} - -class TextEncoder { - - readonly encoding = "utf-8"; - constructor(); - encode(input?: string): Uint8Array; - encodeInto( - input: string, - dest: Uint8Array, - ): { read: number; written: number }; -} \ No newline at end of file diff --git a/ohos.build b/ohos.build index e5737bd..b85022b 100755 --- a/ohos.build +++ b/ohos.build @@ -12,7 +12,6 @@ "inner_kits": [ ], "test_list": [ - "//base/compileruntime/js_util_module/test/unittest:unittest" ] } } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 6e24ec6..e7277ab 100755 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -10,6 +10,7 @@ # 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. + import("//build/test.gni") if (is_standard_system) { @@ -19,15 +20,12 @@ if (is_standard_system) { ohos_unittest("test_util_unittest") { module_out_path = module_output_path - configs = [ "//ark/js_runtime:ark_jsruntime_public_config" ] - include_dirs = [ "//base/compileruntime/js_util_module/util", - "//ark/js_runtime", "//foundation/ace/napi", "//foundation/ace/napi/interfaces/kits", "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/native_engine/impl/ark", + "//foundation/ace/napi/native_engine/impl/quickjs", "//third_party/icu/icu4c/source/common", "//third_party/googletest/include", "//third_party/node/src", @@ -37,27 +35,25 @@ ohos_unittest("test_util_unittest") { cflags = [ "-g3" ] sources = [ - "test_ark.cpp", + "test_quickjs.cpp", "test_util.cpp", ] deps = [ - "//ark/js_runtime:libark_jsruntime", "//base/compileruntime/js_util_module/util:util_packages", "//foundation/ace/napi/:ace_napi", - "//foundation/ace/napi/:ace_napi_ark", + "//foundation/ace/napi/:ace_napi_quickjs", "//third_party/googletest:gtest", "//third_party/googletest:gtest_main", "//third_party/icu/icu4c:static_icuuc", "//third_party/libuv:uv_static", + "//third_party/quickjs:qjs", "//utils/native/base:utils", "//utils/native/base:utilsecurec", ] if (is_standard_system) { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - } else { - external_deps = [ "hilog:libhilog" ] } } diff --git a/test/unittest/test.h b/test/unittest/test.h index 753199c..af07722 100755 --- a/test/unittest/test.h +++ b/test/unittest/test.h @@ -27,7 +27,7 @@ public: void SetUp() override {} void TearDown() override {} protected: - NativeEngine *engine_; + NativeEngine* engine_; }; #endif /* FOUNDATION_ACE_NAPI_TEST_UNITTEST_TEST_H */ \ No newline at end of file diff --git a/test/unittest/test_ark.cpp b/test/unittest/test_quickjs.cpp similarity index 56% rename from test/unittest/test_ark.cpp rename to test/unittest/test_quickjs.cpp index f7e90b8..d5d4c0b 100644 --- a/test/unittest/test_ark.cpp +++ b/test/unittest/test_quickjs.cpp @@ -15,11 +15,9 @@ #include "test.h" -#include "utils/log.h" -#include "ark_native_engine.h" +#include "quickjs_native_engine.h" -using panda::RuntimeOption; -static NativeEngine *g_nativeEngine = nullptr; +static NativeEngine* g_nativeEngine = nullptr; NativeEngineTest::NativeEngineTest() { @@ -28,35 +26,35 @@ NativeEngineTest::NativeEngineTest() NativeEngineTest::~NativeEngineTest() {} -int main(int argc, char **argv) +int main(int argc, char** argv) { testing::GTEST_FLAG(output) = "xml:./"; testing::InitGoogleTest(&argc, argv); - // Setup - RuntimeOption option; - option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC); - - const int64_t poolSize = 0x1000000; // 16M - option.SetGcPoolSize(poolSize); + JSRuntime* rt = JS_NewRuntime(); + if (rt == nullptr) { + return 0; + } - option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); - option.SetDebuggerLibraryPath(""); - EcmaVM *vm = panda::JSNApi::CreateJSVM(option); - if (vm == nullptr) { + JSContext* ctx = JS_NewContext(rt); + if (ctx == nullptr) { return 0; } - g_nativeEngine = new ArkNativeEngine(vm, nullptr); + js_std_add_helpers(ctx, 0, nullptr); - int ret = testing::UnitTest::GetInstance()->Run(); + g_nativeEngine = new QuickJSNativeEngine(rt, ctx, nullptr); - g_nativeEngine->Loop(LOOP_NOWAIT); + int ret = RUN_ALL_TESTS(); + + g_nativeEngine->Loop(LOOP_DEFAULT); delete g_nativeEngine; g_nativeEngine = nullptr; - panda::JSNApi::DestoryJSVM(vm); - vm = nullptr; + + js_std_free_handlers(rt); + JS_FreeContext(ctx); + JS_FreeRuntime(rt); return ret; } diff --git a/test/unittest/test_util.cpp b/test/unittest/test_util.cpp index fea14ed..43d25a1 100755 --- a/test/unittest/test_util.cpp +++ b/test/unittest/test_util.cpp @@ -21,9 +21,9 @@ #include "securec.h" #include "utils/log.h" +#include "js_base64.h" #include "js_textdecoder.h" #include "js_textencoder.h" -#include "js_base64.h" #include "js_types.h" #define ASSERT_CHECK_CALL(call) \ @@ -39,7 +39,6 @@ ASSERT_EQ(valueType, type); \ } - /* @tc.name: getEncodingTest001 * @tc.desc: Test acquire encoding mode. * @tc.type: FUNC @@ -680,14 +679,14 @@ HWTEST_F(NativeEngineTest, decoderUtf16be003, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeTest001 +/* @tc.name: encodeSyncTest001 * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeTest001, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeSyncTest001, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeTest001 start"); + HILOG_INFO("encodeSyncTest001 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[3] = {0x73, 0x31, 0x33}; @@ -695,11 +694,13 @@ HWTEST_F(NativeEngineTest, encodeTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.Encode(src); + napi_value result = Base64.EncodeSync(src); char excepted[4] = {0x63, 0x7A, 0x45, 0x7A}; napi_typedarray_type type; size_t srcLength = 0; @@ -714,14 +715,14 @@ HWTEST_F(NativeEngineTest, encodeTest001, testing::ext::TestSize.Level0) ASSERT_EQ(res[3], excepted[3]); } -/* @tc.name: encodeTest002 +/* @tc.name: encodeSyncTest002 * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeTest002, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeSyncTest002, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeTest002 start"); + HILOG_INFO("encodeSyncTest002 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[14] = {66, 97, 115, 101, 54, 52, 32, 78, 111, 100, 101, 46, 106, 115}; @@ -729,11 +730,13 @@ HWTEST_F(NativeEngineTest, encodeTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 14; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.Encode(src); + napi_value result = Base64.EncodeSync(src); char excepted[20] = {81, 109, 70, 122, 90, 84, 89, 48, 73, 69, 53, 118, 90, 71, 85, 117, 97, 110, 77, 61}; napi_typedarray_type type; size_t srcLength = 0; @@ -747,14 +750,14 @@ HWTEST_F(NativeEngineTest, encodeTest002, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeTest003 +/* @tc.name: encodeSyncTest003 * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeTest003, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeSyncTest003, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeTest003 start"); + HILOG_INFO("encodeSyncTest003 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[26] = {66, 97, 115, 101, 54, 52, 32, 69, 110, @@ -763,11 +766,13 @@ HWTEST_F(NativeEngineTest, encodeTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 26; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.Encode(src); + napi_value result = Base64.EncodeSync(src); char excepted[36] = {81, 109, 70, 122, 90, 84, 89, 48, 73, 69, 86, 117, 89, 50, 57, 107, 97, 87, 53, 110, 73, 71, 108, 117, 73, 69, 53, 118, 90, 71, 85, 117, 97, 110, 77, 61}; napi_typedarray_type type; @@ -782,14 +787,14 @@ HWTEST_F(NativeEngineTest, encodeTest003, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeTest004 +/* @tc.name: encodeSyncTest004 * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeTest004, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeSyncTest004, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeTest004 start"); + HILOG_INFO("encodeSyncTest004 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[4] = {168, 174, 155, 255}; @@ -797,11 +802,13 @@ HWTEST_F(NativeEngineTest, encodeTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 4; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.Encode(src); + napi_value result = Base64.EncodeSync(src); char excepted[8] = {113, 75, 54, 98, 47, 119, 61, 61}; napi_typedarray_type type; size_t srcLength = 0; @@ -815,14 +822,14 @@ HWTEST_F(NativeEngineTest, encodeTest004, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeTest005 +/* @tc.name: encodeSyncTest005 * @tc.desc: Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeTest005, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeSyncTest005, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeTest005 start"); + HILOG_INFO("encodeSyncTest005 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[6] = {66, 97, 115, 101, 54, 52}; @@ -830,11 +837,13 @@ HWTEST_F(NativeEngineTest, encodeTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 6; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.Encode(src); + napi_value result = Base64.EncodeSync(src); char excepted[8] = {81, 109, 70, 122, 90, 84, 89, 48}; napi_typedarray_type type; size_t srcLength = 0; @@ -848,13 +857,13 @@ HWTEST_F(NativeEngineTest, encodeTest005, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeToStringTest001 +/* @tc.name: encodeToStringSyncTest001 * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringTest001, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringSyncTest001, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringTest001 start"); + HILOG_INFO("encodeToStringSyncTest001 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -863,10 +872,12 @@ HWTEST_F(NativeEngineTest, encodeToStringTest001, testing::ext::TestSize.Level0) size_t arrayBufferSize = 3; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToString(src); + napi_value result = Base64.EncodeToStringSync(src); size_t prolen = 0; char* inputString = nullptr; napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); @@ -886,13 +897,13 @@ HWTEST_F(NativeEngineTest, encodeToStringTest001, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeToStringTest002 +/* @tc.name: encodeToStringSyncTest002 * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringTest002, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringSyncTest002, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringTest002 start"); + HILOG_INFO("encodeToStringSyncTest002 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -901,10 +912,12 @@ HWTEST_F(NativeEngineTest, encodeToStringTest002, testing::ext::TestSize.Level0) size_t arrayBufferSize = 14; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToString(src); + napi_value result = Base64.EncodeToStringSync(src); size_t prolen = 0; char* inputString = nullptr; napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); @@ -924,13 +937,13 @@ HWTEST_F(NativeEngineTest, encodeToStringTest002, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeToStringTest003 +/* @tc.name: encodeToStringSyncTest003 * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringTest003, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringSyncTest003, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringTest003 start"); + HILOG_INFO("encodeToStringSyncTest003 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -940,10 +953,12 @@ HWTEST_F(NativeEngineTest, encodeToStringTest003, testing::ext::TestSize.Level0) size_t arrayBufferSize = 26; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToString(src); + napi_value result = Base64.EncodeToStringSync(src); size_t prolen = 0; char* inputString = nullptr; napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); @@ -963,13 +978,13 @@ HWTEST_F(NativeEngineTest, encodeToStringTest003, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeToStringTest004 +/* @tc.name: encodeToStringSyncTest004 * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringTest004, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringSyncTest004, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringTest004 start"); + HILOG_INFO("encodeToStringSyncTest004 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -978,10 +993,12 @@ HWTEST_F(NativeEngineTest, encodeToStringTest004, testing::ext::TestSize.Level0) size_t arrayBufferSize = 4; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToString(src); + napi_value result = Base64.EncodeToStringSync(src); size_t prolen = 0; char* inputString = nullptr; napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); @@ -1001,13 +1018,13 @@ HWTEST_F(NativeEngineTest, encodeToStringTest004, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeToStringTest005 +/* @tc.name: encodeToStringSyncTest005 * @tc.desc: Encodes the specified byte array as a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringTest005, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringSyncTest005, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringTest005 start"); + HILOG_INFO("encodeToStringSyncTest005 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -1016,10 +1033,12 @@ HWTEST_F(NativeEngineTest, encodeToStringTest005, testing::ext::TestSize.Level0) size_t arrayBufferSize = 6; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToString(src); + napi_value result = Base64.EncodeToStringSync(src); size_t prolen = 0; char* inputString = nullptr; napi_get_value_string_utf8(env, result, nullptr, 0, &prolen); @@ -1039,14 +1058,14 @@ HWTEST_F(NativeEngineTest, encodeToStringTest005, testing::ext::TestSize.Level0) } } -/* @tc.name: decodeTest001 +/* @tc.name: decodeSyncTest001 * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeTest001, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeSyncTest001, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeTest001 start"); + HILOG_INFO("decodeSyncTest001 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -1055,10 +1074,12 @@ HWTEST_F(NativeEngineTest, decodeTest001, testing::ext::TestSize.Level0) size_t arrayBufferSize = 4; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.Decode(src); + napi_value result = Base64.DecodeSync(src); char excepted[3] = {115, 49, 51}; napi_typedarray_type type; size_t srcLength = 0; @@ -1073,14 +1094,14 @@ HWTEST_F(NativeEngineTest, decodeTest001, testing::ext::TestSize.Level0) ASSERT_EQ(res[2], excepted[2]); } -/* @tc.name: decodeTest002 +/* @tc.name: decodeSyncTest002 * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeTest002, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeSyncTest002, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeTest002 start"); + HILOG_INFO("decodeSyncTest002 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -1089,10 +1110,12 @@ HWTEST_F(NativeEngineTest, decodeTest002, testing::ext::TestSize.Level0) size_t arrayBufferSize = 20; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.Decode(src); + napi_value result = Base64.DecodeSync(src); char excepted[14] = {66, 97, 115, 101, 54, 52, 32, 78, 111, 100, 101, 46, 106, 115}; napi_typedarray_type type; size_t srcLength = 0; @@ -1107,21 +1130,21 @@ HWTEST_F(NativeEngineTest, decodeTest002, testing::ext::TestSize.Level0) } } -/* @tc.name: decodeTest003 +/* @tc.name: decodeSyncTest003 * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeTest003, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeSyncTest003, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeTest003 start"); + HILOG_INFO("decodeSyncTest003 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); std::string input = "czEz"; napi_value src = nullptr; napi_create_string_utf8(env, input.c_str(), input.size(), &src); - napi_value result = Base64.Decode(src); + napi_value result = Base64.DecodeSync(src); char excepted[3] = {115, 49, 51}; napi_typedarray_type type; size_t srcLength = 0; @@ -1136,21 +1159,21 @@ HWTEST_F(NativeEngineTest, decodeTest003, testing::ext::TestSize.Level0) ASSERT_EQ(res[2], excepted[2]); } -/* @tc.name: decodeTest004 +/* @tc.name: decodeSyncTest004 * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeTest004, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeSyncTest004, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeTest004 start"); + HILOG_INFO("decodeSyncTest004 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); std::string input = "qK6b/w=="; napi_value src = nullptr; napi_create_string_utf8(env, input.c_str(), input.size(), &src); - napi_value result = Base64.Decode(src); + napi_value result = Base64.DecodeSync(src); char excepted[4] = {168, 174, 155, 255}; napi_typedarray_type type; size_t srcLength = 0; @@ -1164,21 +1187,21 @@ HWTEST_F(NativeEngineTest, decodeTest004, testing::ext::TestSize.Level0) } } -/* @tc.name: decodeTest005 +/* @tc.name: decodeSyncTest005 * @tc.desc: Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeTest005, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeSyncTest005, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeTest005 start"); + HILOG_INFO("decodeSyncTest005 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); std::string input = "QmFzZTY0"; napi_value src = nullptr; napi_create_string_utf8(env, input.c_str(), input.size(), &src); - napi_value result = Base64.Decode(src); + napi_value result = Base64.DecodeSync(src); char excepted[6] = {66, 97, 115, 101, 54, 52}; napi_typedarray_type type; size_t srcLength = 0; @@ -1192,14 +1215,14 @@ HWTEST_F(NativeEngineTest, decodeTest005, testing::ext::TestSize.Level0) } } -/* @tc.name: encodeAsyncTest001 +/* @tc.name: encodeTest001 * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeAsyncTest001, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeTest001, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeAsyncTest001 start"); + HILOG_INFO("encodeTest001 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[3] = {0x73, 0x31, 0x33}; @@ -1207,24 +1230,26 @@ HWTEST_F(NativeEngineTest, encodeAsyncTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeAsync(src); + napi_value result = Base64.Encode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: encodeAsyncTest002 +/* @tc.name: encodeTest002 * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeAsyncTest002, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeTest002, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeAsyncTest002 start"); + HILOG_INFO("encodeTest002 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[14] = {66, 97, 115, 101, 54, 52, 32, 78, 111, 100, 101, 46, 106, 115}; @@ -1232,50 +1257,54 @@ HWTEST_F(NativeEngineTest, encodeAsyncTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 14; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeAsync(src); + napi_value result = Base64.Encode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: encodeAsyncTest003 +/* @tc.name: encodeTest003 * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeAsyncTest003, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeTest003, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeAsyncTest003 start"); + HILOG_INFO("encodeTest003 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[26] = {66, 97, 115, 101, 54, 52, 32, 69, 110, - 99, 111, 100, 105, 110, 103, 32, 105, 110, 32, 78, 111, 100, 101, 46, 106, 115};; + 99, 111, 100, 105, 110, 103, 32, 105, 110, 32, 78, 111, 100, 101, 46, 106, 115}; napi_value arrayBuffer = nullptr; void* data = nullptr; size_t arrayBufferSize = 26; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeAsync(src); + napi_value result = Base64.Encode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: encodeAsyncTest004 +/* @tc.name: encodeTest004 * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeAsyncTest004, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeTest004, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeAsyncTest004 start"); + HILOG_INFO("encodeTest004 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[4] = {168, 174, 155, 255}; @@ -1283,24 +1312,26 @@ HWTEST_F(NativeEngineTest, encodeAsyncTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 4; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeAsync(src); + napi_value result = Base64.Encode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: encodeAsyncTest005 +/* @tc.name: encodeTest005 * @tc.desc: Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeAsyncTest005, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeTest005, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeAsyncTest005 start"); + HILOG_INFO("encodeTest005 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[6] = {66, 97, 115, 101, 54, 52}; @@ -1308,23 +1339,25 @@ HWTEST_F(NativeEngineTest, encodeAsyncTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 6; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeAsync(src); + napi_value result = Base64.Encode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: encodeToStringAsyncTest001 +/* @tc.name: encodeToStringTest001 * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringAsyncTest001, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringTest001, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringAsyncTest001 start"); + HILOG_INFO("encodeToStringTest001 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -1333,22 +1366,24 @@ HWTEST_F(NativeEngineTest, encodeToStringAsyncTest001, testing::ext::TestSize.Le size_t arrayBufferSize = 3; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToStringAsync(src); + napi_value result = Base64.EncodeToString(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: encodeToStringAsyncTest002 +/* @tc.name: encodeToStringTest002 * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringAsyncTest002, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringTest002, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringAsyncTest002 start"); + HILOG_INFO("encodeToStringTest002 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[14] = {66, 97, 115, 101, 54, 52, 32, 78, 111, 100, 101, 46, 106, 115}; @@ -1356,23 +1391,25 @@ HWTEST_F(NativeEngineTest, encodeToStringAsyncTest002, testing::ext::TestSize.Le void* data = nullptr; size_t arrayBufferSize = 14; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToStringAsync(src); + napi_value result = Base64.EncodeToString(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: encodeToStringAsyncTest003 +/* @tc.name: encodeToStringTest003 * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringAsyncTest003, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringTest003, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringAsyncTest003 start"); + HILOG_INFO("encodeToStringTest003 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[26] = {66, 97, 115, 101, 54, 52, 32, 69, 110, @@ -1381,23 +1418,25 @@ HWTEST_F(NativeEngineTest, encodeToStringAsyncTest003, testing::ext::TestSize.Le void* data = nullptr; size_t arrayBufferSize = 26; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToStringAsync(src); + napi_value result = Base64.EncodeToString(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: encodeToStringAsyncTest004 +/* @tc.name: encodeToStringTest004 * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringAsyncTest004, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringTest004, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringAsyncTest004 start"); + HILOG_INFO("encodeToStringTest004 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[4] = {168, 174, 155, 255}; @@ -1405,23 +1444,25 @@ HWTEST_F(NativeEngineTest, encodeToStringAsyncTest004, testing::ext::TestSize.Le void* data = nullptr; size_t arrayBufferSize = 4; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToStringAsync(src); + napi_value result = Base64.EncodeToString(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: encodeToStringAsyncTest005 +/* @tc.name: encodeToStringTest005 * @tc.desc: Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, encodeToStringAsyncTest005, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, encodeToStringTest005, testing::ext::TestSize.Level0) { - HILOG_INFO("encodeToStringAsyncTest005 start"); + HILOG_INFO("encodeToStringTest005 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); unsigned char input[6] = {66, 97, 115, 101, 54, 52}; @@ -1429,24 +1470,26 @@ HWTEST_F(NativeEngineTest, encodeToStringAsyncTest005, testing::ext::TestSize.Le void* data = nullptr; size_t arrayBufferSize = 6; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.EncodeToStringAsync(src); + napi_value result = Base64.EncodeToString(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: decodeAsyncTest001 +/* @tc.name: decodeTest001 * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeAsyncTest001, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeTest001, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeAsyncTest001 start"); + HILOG_INFO("decodeTest001 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -1455,23 +1498,25 @@ HWTEST_F(NativeEngineTest, decodeAsyncTest001, testing::ext::TestSize.Level0) size_t arrayBufferSize = 4; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.DecodeAsync(src); + napi_value result = Base64.Decode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: decodeAsyncTest002 +/* @tc.name: decodeTest002 * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeAsyncTest002, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeTest002, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeAsyncTest002 start"); + HILOG_INFO("decodeTest002 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); @@ -1480,70 +1525,72 @@ HWTEST_F(NativeEngineTest, decodeAsyncTest002, testing::ext::TestSize.Level0) size_t arrayBufferSize = 8; void* data = nullptr; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); - napi_value result = Base64.DecodeAsync(src); + napi_value result = Base64.Decode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: decodeAsyncTest003 +/* @tc.name: decodeTest003 * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeAsyncTest003, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeTest003, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeAsyncTest003 start"); + HILOG_INFO("decodeTest003 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); std::string input = "czEz"; napi_value src = nullptr; napi_create_string_utf8(env, input.c_str(), input.size(), &src); - napi_value result = Base64.DecodeAsync(src); + napi_value result = Base64.Decode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: decodeAsyncTest004 +/* @tc.name: decodeTest004 * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeAsyncTest004, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeTest004, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeAsyncTest004 start"); + HILOG_INFO("decodeTest004 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); std::string input = "QmFzZTY0IEVuY29kaW5nIGluIE5vZGUuanM="; napi_value src = nullptr; napi_create_string_utf8(env, input.c_str(), input.size(), &src); - napi_value result = Base64.DecodeAsync(src); + napi_value result = Base64.Decode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); } -/* @tc.name: decodeAsyncTest005 +/* @tc.name: decodeTest005 * @tc.desc: Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. * @tc.type: FUNC */ -HWTEST_F(NativeEngineTest, decodeAsyncTest005, testing::ext::TestSize.Level0) +HWTEST_F(NativeEngineTest, decodeTest005, testing::ext::TestSize.Level0) { - HILOG_INFO("decodeAsyncTest005 start"); + HILOG_INFO("decodeTest005 start"); napi_env env = (napi_env)engine_; OHOS::Util::Base64 Base64(env); std::string input = "qK6b/w=="; napi_value src = nullptr; napi_create_string_utf8(env, input.c_str(), input.size(), &src); - napi_value result = Base64.DecodeAsync(src); + napi_value result = Base64.Decode(src); bool res = false; napi_is_promise(env, result, &res); ASSERT_TRUE(res); @@ -1563,7 +1610,9 @@ HWTEST_F(NativeEngineTest, isAnyArrayBufferTest001, testing::ext::TestSize.Level void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value flag = Types.IsAnyArrayBuffer(arrayBuffer); bool result = false; @@ -1623,7 +1672,9 @@ HWTEST_F(NativeEngineTest, isAnyArrayBufferTest004, testing::ext::TestSize.Level void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1647,7 +1698,9 @@ HWTEST_F(NativeEngineTest, isAnyArrayBufferTest005, testing::ext::TestSize.Level void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1673,7 +1726,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferViewTest001, testing::ext::TestSize.Leve void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1699,7 +1754,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferViewTest002, testing::ext::TestSize.Leve void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1725,7 +1782,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferViewTest003, testing::ext::TestSize.Leve void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1751,7 +1810,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferViewTest004, testing::ext::TestSize.Leve void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1777,7 +1838,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferViewTest005, testing::ext::TestSize.Leve void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1801,7 +1864,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value flag = Types.IsArrayBuffer(arrayBuffer); bool result = false; @@ -1823,7 +1888,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1847,7 +1914,9 @@ HWTEST_F(NativeEngineTest, isArrayBufferTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1909,14 +1978,16 @@ HWTEST_F(NativeEngineTest, isDataViewTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_dataview(env, arrayBufferSize, arrayBuffer, 0, &src); napi_value flag = Types.IsDataView(src); bool result = false; napi_get_value_bool(env, flag, &result); - ASSERT_FALSE(result); + ASSERT_TRUE(result); } @@ -1934,7 +2005,9 @@ HWTEST_F(NativeEngineTest, isInt8ArrayTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1958,7 +2031,9 @@ HWTEST_F(NativeEngineTest, isInt8ArrayTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -1982,7 +2057,9 @@ HWTEST_F(NativeEngineTest, isInt8ArrayTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2006,7 +2083,9 @@ HWTEST_F(NativeEngineTest, isInt8ArrayTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2030,7 +2109,9 @@ HWTEST_F(NativeEngineTest, isInt8ArrayTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2054,7 +2135,9 @@ HWTEST_F(NativeEngineTest, isInt16ArrayTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2078,7 +2161,9 @@ HWTEST_F(NativeEngineTest, isInt16ArrayTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2102,7 +2187,9 @@ HWTEST_F(NativeEngineTest, isInt16ArrayTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2126,7 +2213,9 @@ HWTEST_F(NativeEngineTest, isInt16ArrayTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2150,7 +2239,9 @@ HWTEST_F(NativeEngineTest, isInt16ArrayTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2174,7 +2265,9 @@ HWTEST_F(NativeEngineTest, isInt32ArrayTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2198,7 +2291,9 @@ HWTEST_F(NativeEngineTest, isInt32ArrayTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2222,7 +2317,9 @@ HWTEST_F(NativeEngineTest, isInt32ArrayTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2246,7 +2343,9 @@ HWTEST_F(NativeEngineTest, isInt32ArrayTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2270,7 +2369,9 @@ HWTEST_F(NativeEngineTest, isInt32ArrayTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2294,7 +2395,9 @@ HWTEST_F(NativeEngineTest, isUint8ArrayTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2318,7 +2421,9 @@ HWTEST_F(NativeEngineTest, isUint8ArrayTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2342,7 +2447,9 @@ HWTEST_F(NativeEngineTest, isUint8ArrayTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2366,7 +2473,9 @@ HWTEST_F(NativeEngineTest, isUint8ArrayTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2390,7 +2499,9 @@ HWTEST_F(NativeEngineTest, isUint8ArrayTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2414,7 +2525,9 @@ HWTEST_F(NativeEngineTest, isTypedArrayTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2438,7 +2551,9 @@ HWTEST_F(NativeEngineTest, isTypedArrayTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_float32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2462,7 +2577,9 @@ HWTEST_F(NativeEngineTest, isTypedArrayTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2486,7 +2603,9 @@ HWTEST_F(NativeEngineTest, isTypedArrayTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2510,7 +2629,9 @@ HWTEST_F(NativeEngineTest, isTypedArrayTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value flag = Types.IsTypedArray(arrayBuffer); bool result = false; @@ -2532,7 +2653,9 @@ HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest001, testing::ext::TestSize.Le void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_clamped_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2556,7 +2679,9 @@ HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest002, testing::ext::TestSize.Le void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_float32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2580,7 +2705,9 @@ HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest003, testing::ext::TestSize.Le void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2604,7 +2731,9 @@ HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest004, testing::ext::TestSize.Le void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2628,7 +2757,9 @@ HWTEST_F(NativeEngineTest, isUint8ClampedArrayTest005, testing::ext::TestSize.Le void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2652,7 +2783,9 @@ HWTEST_F(NativeEngineTest, isUint16ArrayTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2676,7 +2809,9 @@ HWTEST_F(NativeEngineTest, isUint16ArrayTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2700,7 +2835,9 @@ HWTEST_F(NativeEngineTest, isUint16ArrayTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2724,7 +2861,9 @@ HWTEST_F(NativeEngineTest, isUint16ArrayTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2748,7 +2887,9 @@ HWTEST_F(NativeEngineTest, isUint16ArrayTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2772,7 +2913,9 @@ HWTEST_F(NativeEngineTest, isUint32ArrayTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2796,7 +2939,9 @@ HWTEST_F(NativeEngineTest, isUint32ArrayTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2820,7 +2965,9 @@ HWTEST_F(NativeEngineTest, isUint32ArrayTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2844,7 +2991,9 @@ HWTEST_F(NativeEngineTest, isUint32ArrayTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2868,7 +3017,9 @@ HWTEST_F(NativeEngineTest, isUint32ArrayTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2892,7 +3043,9 @@ HWTEST_F(NativeEngineTest, isFloat32ArrayTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_float32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2916,7 +3069,9 @@ HWTEST_F(NativeEngineTest, isFloat32ArrayTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2940,7 +3095,9 @@ HWTEST_F(NativeEngineTest, isFloat32ArrayTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2964,7 +3121,9 @@ HWTEST_F(NativeEngineTest, isFloat32ArrayTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -2988,7 +3147,9 @@ HWTEST_F(NativeEngineTest, isFloat32ArrayTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -3012,7 +3173,9 @@ HWTEST_F(NativeEngineTest, isFloat64ArrayTest001, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_float64_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -3036,7 +3199,9 @@ HWTEST_F(NativeEngineTest, isFloat64ArrayTest002, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint32_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -3060,7 +3225,9 @@ HWTEST_F(NativeEngineTest, isFloat64ArrayTest003, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint16_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -3084,7 +3251,9 @@ HWTEST_F(NativeEngineTest, isFloat64ArrayTest004, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_uint8_array, arrayBufferSize, arrayBuffer, 0, &src); @@ -3108,7 +3277,9 @@ HWTEST_F(NativeEngineTest, isFloat64ArrayTest005, testing::ext::TestSize.Level0) void* data = nullptr; size_t arrayBufferSize = 3; napi_create_arraybuffer(env, arrayBufferSize, &data, &arrayBuffer); - memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)); + if (memcpy_s(data, sizeof(input), reinterpret_cast(input), sizeof(input)) != 0) { + HILOG_ERROR("copy failed"); + } napi_value src = nullptr; napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &src); diff --git a/util/BUILD.gn b/util/BUILD.gn index 1b57306..a4f09df 100755 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -18,18 +18,20 @@ import("//foundation/ace/ace_engine/ace_config.gni") # compile .ts to .js. action("build_ts_js") { - script = "//base/compileruntime/js_util_module/util/build_ts_js.py" - + script = "//base/compileruntime/js_util_module/build_ts_js.py" args = [ "--dst-file", rebase_path(target_out_dir + "/util_js.js"), + "--module-path", + rebase_path("/base/compileruntime/js_util_module/util"), + "--out-file", + rebase_path("./out/util_js.js"), ] depfile = "$target_gen_dir/$target_name.d" outputs = [ target_out_dir + "/util_js.js" ] } base_output_path = get_label_info(":util_js", "target_out_dir") util_js_obj_path = base_output_path + "/util.o" - gen_js_obj("util_js") { input = "$target_out_dir/util_js.js" output = util_js_obj_path diff --git a/util/js_base64.cpp b/util/js_base64.cpp index 4581bb4..c613ff6 100755 --- a/util/js_base64.cpp +++ b/util/js_base64.cpp @@ -39,7 +39,7 @@ namespace OHOS::Util { Base64::Base64(napi_env env_) : env(env_) {} /* base64 encode */ - napi_value Base64::Encode(napi_value src) + napi_value Base64::EncodeSync(napi_value src) { napi_typedarray_type type; size_t byteOffset = 0; @@ -48,7 +48,10 @@ namespace OHOS::Util { napi_value resultBuffer = nullptr; NAPI_CALL(env, napi_get_typedarray_info(env, src, &type, &length, &resultData, &resultBuffer, &byteOffset)); inputEncode_ = static_cast(resultData) + byteOffset; - const unsigned char *rets = EncodeAchieve(inputEncode_, length); + unsigned char *rets = EncodeAchieve(inputEncode_, length); + if (rets == nullptr) { + napi_throw_error(env, "-1", "encode input is null"); + } void *data = nullptr; napi_value arrayBuffer = nullptr; size_t bufferSize = outputLen; @@ -65,7 +68,7 @@ namespace OHOS::Util { } /* base64 encodeToString */ - napi_value Base64::EncodeToString(napi_value src) + napi_value Base64::EncodeToStringSync(napi_value src) { napi_typedarray_type type; size_t byteOffset = 0; @@ -75,6 +78,9 @@ namespace OHOS::Util { NAPI_CALL(env, napi_get_typedarray_info(env, src, &type, &length, &resultData, &resultBuffer, &byteOffset)); inputEncode_ = static_cast(resultData) + byteOffset; unsigned char *ret = EncodeAchieve(inputEncode_, length); + if (ret == nullptr) { + napi_throw_error(env, "-1", "encodeToString input is null"); + } const char *encString = reinterpret_cast(ret); napi_value resultStr = nullptr; NAPI_CALL(env, napi_create_string_utf8(env, encString, strlen(encString), &resultStr)); @@ -96,11 +102,16 @@ namespace OHOS::Util { if (outputLen > 0) { ret = new unsigned char[outputLen + 1]; if (memset_s(ret, outputLen + 1, '\0', outputLen + 1) != 0) { + HILOG_ERROR("encode ret memset_s failed"); FreeMemory(ret); - napi_throw_error(env, "-1", "ret path memset_s failed"); + return nullptr; } } else { - napi_throw_error(env, "-2", "outputLen is error !"); + HILOG_ERROR("outputLen is error"); + return nullptr; + } + if (ret == nullptr) { + return ret; } while (inp < inputLen) { temp = 0; @@ -127,7 +138,7 @@ namespace OHOS::Util { } /* base64 decode */ - napi_value Base64::Decode(napi_value src) + napi_value Base64::DecodeSync(napi_value src) { napi_valuetype valuetype = napi_undefined; napi_typeof(env, src, &valuetype); @@ -152,8 +163,10 @@ namespace OHOS::Util { } else { napi_throw_error(env, "-2", "prolen is error !"); } - napi_get_value_string_utf8(env, src, inputString, prolen + 1, &prolen); - pret = DecodeAchieve(inputString, prolen); + if (inputString != nullptr) { + napi_get_value_string_utf8(env, src, inputString, prolen + 1, &prolen); + pret = DecodeAchieve(inputString, prolen); + } } else if (type == napi_typedarray_type::napi_uint8_array) { inputDecode_ = static_cast(resultData) + byteOffset; pret = DecodeAchieve(inputDecode_, length); @@ -203,6 +216,9 @@ namespace OHOS::Util { } else { napi_throw_error(env, "-2", "retLen is error !"); } + if (retDecode == nullptr) { + return retDecode; + } while (inp < (inputLen - equalCount)) { temp = 0; bitWise = 0; @@ -266,24 +282,23 @@ namespace OHOS::Util { } /* Memory cleanup function */ - void Base64::FreeMemory(const unsigned char *address) + void Base64::FreeMemory(unsigned char *address) { - const unsigned char *temp = address; + unsigned char *temp = address; if (temp != nullptr) { delete[] temp; temp = nullptr; } } - void Base64::FreeMemory(const char *address) + void Base64::FreeMemory(char *address) { - const char *temp = address; + char *temp = address; if (temp != nullptr) { delete[] temp; temp = nullptr; } } - - napi_value Base64::EncodeAsync(napi_value src) + napi_value Base64::Encode(napi_value src) { napi_typedarray_type type; size_t byteOffset = 0; @@ -296,8 +311,7 @@ namespace OHOS::Util { CreateEncodePromise(inputEncode, length); return stdEncodeInfo_->promise; } - - napi_value Base64::EncodeToStringAsync(napi_value src) + napi_value Base64::EncodeToString(napi_value src) { napi_typedarray_type type; size_t byteOffset = 0; @@ -310,7 +324,6 @@ namespace OHOS::Util { CreateEncodeToStringPromise(inputEncode, length); return stdEncodeInfo_->promise; } - void Base64::CreateEncodePromise(unsigned char *inputDecode, size_t length) { napi_value resourceName = nullptr; @@ -324,7 +337,6 @@ namespace OHOS::Util { reinterpret_cast(stdEncodeInfo_), &stdEncodeInfo_->worker); napi_queue_async_work(env, stdEncodeInfo_->worker); } - void Base64::CreateEncodeToStringPromise(unsigned char *inputDecode, size_t length) { napi_value resourceName = nullptr; @@ -337,7 +349,6 @@ namespace OHOS::Util { reinterpret_cast(stdEncodeInfo_), &stdEncodeInfo_->worker); napi_queue_async_work(env, stdEncodeInfo_->worker); } - unsigned char *EncodeAchieves(EncodeInfo *encodeInfo) { const unsigned char *input = encodeInfo->sinputEncode; @@ -361,6 +372,9 @@ namespace OHOS::Util { } else { napi_throw_error(encodeInfo->env, "-2", "outputLen is error !"); } + if (ret == nullptr) { + return ret; + } while (inp < inputLen) { temp = 0; bitWise = 0; @@ -384,14 +398,12 @@ namespace OHOS::Util { ret[index] = 0; return ret; } - void Base64::ReadStdEncode(napi_env env, void *data) { auto stdEncodeInfo = reinterpret_cast(data); unsigned char *rets = EncodeAchieves(stdEncodeInfo); stdEncodeInfo->sinputEncoding = rets; } - void Base64::EndStdEncode(napi_env env, napi_status status, void *buffer) { auto stdEncodeInfo = reinterpret_cast(buffer); @@ -411,14 +423,12 @@ namespace OHOS::Util { delete[] stdEncodeInfo->sinputEncoding; delete stdEncodeInfo; } - void Base64::ReadStdEncodeToString(napi_env env, void *data) { auto stdEncodeInfo = reinterpret_cast(data); unsigned char *rets = EncodeAchieves(stdEncodeInfo); stdEncodeInfo->sinputEncoding = rets; } - void Base64::EndStdEncodeToString(napi_env env, napi_status status, void *buffer) { auto stdEncodeInfo = reinterpret_cast(buffer); @@ -430,8 +440,7 @@ namespace OHOS::Util { delete[] stdEncodeInfo->sinputEncoding; delete stdEncodeInfo; } - - napi_value Base64::DecodeAsync(napi_value src) + napi_value Base64::Decode(napi_value src) { napi_valuetype valuetype = napi_undefined; napi_typeof(env, src, &valuetype); @@ -456,7 +465,7 @@ namespace OHOS::Util { } else { napi_throw_error(env, "-2", "prolen is error !"); } - napi_get_value_string_utf8(env, src, inputString, prolen+1, &prolen); + napi_get_value_string_utf8(env, src, inputString, prolen + 1, &prolen); CreateDecodePromise(inputString, prolen); } else if (type == napi_typedarray_type::napi_uint8_array) { inputDecode = static_cast(resultData) + byteOffset; @@ -465,7 +474,6 @@ namespace OHOS::Util { delete[] inputString; return stdDecodeInfo_->promise; } - void Base64::CreateDecodePromise(char *inputDecode, size_t length) { napi_value resourceName = nullptr; @@ -479,8 +487,6 @@ namespace OHOS::Util { reinterpret_cast(stdDecodeInfo_), &stdDecodeInfo_->worker); napi_queue_async_work(env, stdDecodeInfo_->worker); } - - /* Decoding lookup function */ size_t Finds(char ch) { size_t couts = 0; @@ -491,7 +497,6 @@ namespace OHOS::Util { } return couts; } - size_t DecodeOut(size_t equalCount, size_t retLen, DecodeInfo *decodeInfo) { if (equalCount == 1) { @@ -516,7 +521,6 @@ namespace OHOS::Util { } return retLen; } - unsigned char *DecodeAchieves(DecodeInfo *decodeInfo) { const char *input = decodeInfo->sinputDecode; @@ -567,14 +571,12 @@ namespace OHOS::Util { retDecode[index] = 0; return retDecode; } - void Base64::ReadStdDecode(napi_env env, void *data) { auto stdDecodeInfo = reinterpret_cast(data); unsigned char *rets = DecodeAchieves(stdDecodeInfo); stdDecodeInfo->sinputDecoding = rets; } - void Base64::EndStdDecode(napi_env env, napi_status status, void *buffer) { auto stdDecodeInfo = reinterpret_cast(buffer); @@ -594,4 +596,4 @@ namespace OHOS::Util { delete[] stdDecodeInfo->sinputDecoding; delete stdDecodeInfo; } -} +} \ No newline at end of file diff --git a/util/js_base64.h b/util/js_base64.h index e85e775..20d9705 100755 --- a/util/js_base64.h +++ b/util/js_base64.h @@ -46,34 +46,31 @@ namespace OHOS::Util { napi_env env; }; - enum ConverterFlags { - BIT_FLG = 0x40, - SIXTEEN_FLG = 0x3F, - XFF_FLG = 0xFF, - }; - + enum ConverterFlags { + BIT_FLG = 0x40, + SIXTEEN_FLG = 0x3F, + XFF_FLG = 0xFF, + }; unsigned char *EncodeAchieves(EncodeInfo *encodeInfo); unsigned char *DecodeAchieves(DecodeInfo *decodeInfo); - class Base64 { public: explicit Base64(napi_env env); virtual ~Base64() {} + napi_value EncodeSync(napi_value src); + napi_value EncodeToStringSync(napi_value src); + napi_value DecodeSync(napi_value src); napi_value Encode(napi_value src); napi_value EncodeToString(napi_value src); napi_value Decode(napi_value src); - - napi_value EncodeAsync(napi_value src); - napi_value EncodeToStringAsync(napi_value src); - napi_value DecodeAsync(napi_value src); private: napi_env env; unsigned char *DecodeAchieve(const char *input, size_t inputLen); unsigned char *EncodeAchieve(const unsigned char *input, size_t inputLen); size_t Finds(char ch); size_t DecodeOut(size_t equalCount, size_t retLen); - void FreeMemory(const unsigned char *address); - void FreeMemory(const char *address); + void FreeMemory(unsigned char *address); + void FreeMemory(char *address); size_t retLen = 0; size_t decodeOutLen = 0; size_t outputLen = 0; @@ -81,7 +78,6 @@ namespace OHOS::Util { const unsigned char *inputEncode_ = nullptr; const char *inputDecode_ = nullptr; unsigned char *retDecode = nullptr; - void CreateEncodePromise(unsigned char *inputDecode, size_t length); void CreateEncodeToStringPromise(unsigned char *inputDecode, size_t length); void CreateDecodePromise(char *inputDecode, size_t length); diff --git a/util/js_types.cpp b/util/js_types.cpp index bd1db15..57e9f7f 100644 --- a/util/js_types.cpp +++ b/util/js_types.cpp @@ -16,15 +16,13 @@ #include "js_types.h" #include #include -#include "utils/log.h" #include "securec.h" -#include "napi/native_api.h" -#include "napi/native_node_api.h" +#include "utils/log.h" namespace OHOS::Util { - Types::Types(napi_env env_) : env_(env_) {} + Types::Types(napi_env env) : env_(env) {} - napi_value Types::IsAnyArrayBuffer(napi_value src) + napi_value Types::IsAnyArrayBuffer(napi_value src) const { bool flag = false; bool rstFlag = false; @@ -37,13 +35,13 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsArrayBufferView(napi_value src) + napi_value Types::IsArrayBufferView(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; napi_value rst = nullptr; bool flag = false; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); - if (valuetype != napi_valuetype::napi_object) { + napi_status rstStatus = napi_typeof(env_, src, &valuetype); + if ((valuetype != napi_valuetype::napi_object) || (rstStatus != napi_ok)) { napi_get_boolean(env_, flag, &rst); return rst; } @@ -53,37 +51,40 @@ namespace OHOS::Util { napi_get_boolean(env_, rstFlag, &rst); return rst; } - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset)); - switch (type) { - case napi_typedarray_type::napi_int8_array: - case napi_typedarray_type::napi_uint8_array: - case napi_typedarray_type::napi_uint8_clamped_array: - case napi_typedarray_type::napi_int16_array: - case napi_typedarray_type::napi_uint16_array: - case napi_typedarray_type::napi_int32_array: - case napi_typedarray_type::napi_uint32_array: - case napi_typedarray_type::napi_float32_array: - case napi_typedarray_type::napi_float64_array: - flag = true; - break; - default : - flag = false; - break; + napi_status rstSta = napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); + if (rstSta == napi_ok) { + switch (type) { + case napi_typedarray_type::napi_int8_array: + case napi_typedarray_type::napi_uint8_array: + case napi_typedarray_type::napi_uint8_clamped_array: + case napi_typedarray_type::napi_int16_array: + case napi_typedarray_type::napi_uint16_array: + case napi_typedarray_type::napi_int32_array: + case napi_typedarray_type::napi_uint32_array: + case napi_typedarray_type::napi_float32_array: + case napi_typedarray_type::napi_float64_array: + flag = true; + break; + default: + flag = false; + break; + } } napi_get_boolean(env_, flag, &rst); return rst; } - napi_value Types::IsArgumentsObject(napi_value src) + napi_value Types::IsArgumentsObject(napi_value src) const { - napi_valuetype result; - NAPI_CALL(env_, napi_typeof(env_, src, &result)); + napi_valuetype result = napi_undefined; bool flag = false; + napi_typeof(env_, src, &result); if (result == napi_object) { NAPI_CALL(env_, napi_is_arguments_object(env_, src, &flag)); } @@ -92,7 +93,7 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsArrayBuffer(napi_value src) + napi_value Types::IsArrayBuffer(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_arraybuffer(env_, src, &flag)); @@ -101,11 +102,11 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsAsyncFunction(napi_value src) + napi_value Types::IsAsyncFunction(napi_value src) const { - napi_valuetype result; - NAPI_CALL(env_, napi_typeof(env_, src, &result)); + napi_valuetype result = napi_undefined; bool flag = false; + napi_typeof(env_, src, &result); if (result == napi_function) { NAPI_CALL(env_, napi_is_async_function(env_, src, &flag)); } @@ -114,15 +115,15 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsBigInt64Array(napi_value src) + napi_value Types::IsBigInt64Array(napi_value src) const { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset)); bool flag = false; + napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_bigint64_array) { flag = true; } @@ -132,15 +133,15 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsBigUint64Array(napi_value src) + napi_value Types::IsBigUint64Array(napi_value src) const { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset)); bool flag = false; + napi_get_typedarray_info(env_, src, &type, &length, &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_biguint64_array) { flag = true; } @@ -150,10 +151,10 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsBooleanObject(napi_value src) + napi_value Types::IsBooleanObject(napi_value src) const { - napi_valuetype result; - NAPI_CALL(env_, napi_typeof(env_, src, &result)); + napi_valuetype result = napi_undefined; + napi_typeof(env_, src, &result); bool flag = false; if (result == napi_object) { NAPI_CALL(env_, napi_is_boolean_object(env_, src, &flag)); @@ -163,7 +164,7 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsBoxedPrimitive(napi_value src) + napi_value Types::IsBoxedPrimitive(napi_value src) const { bool flag = false; bool rstNum = false; @@ -182,16 +183,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsCryptoKey(napi_value src) - { - bool flag = false; - napi_value rst = nullptr; - napi_get_boolean(env_, flag, &rst); - HILOG_INFO("The type is not supported!"); - return rst; - } - - napi_value Types::IsDataView(napi_value src) + napi_value Types::IsDataView(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_dataview(env_, src, &flag)); @@ -200,7 +192,7 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsDate(napi_value src) + napi_value Types::IsDate(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_date(env_, src, &flag)); @@ -209,11 +201,11 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsExternal(napi_value src) + napi_value Types::IsExternal(napi_value src) const { - napi_valuetype type; + napi_valuetype type = napi_undefined; bool flag = false; - NAPI_CALL(env_, napi_typeof(env_, src, &type)); + napi_typeof(env_, src, &type); if (type == napi_valuetype::napi_external) { flag = true; } @@ -222,20 +214,20 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsFloat32Array(napi_value src) + napi_value Types::IsFloat32Array(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; bool flag = false; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, - &resultData, &resultBuffer, &byteOffset)); + napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_float32_array) { flag = true; } @@ -244,20 +236,20 @@ namespace OHOS::Util { return result; } - napi_value Types::IsFloat64Array(napi_value src) + napi_value Types::IsFloat64Array(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; bool flag = false; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, - &resultData, &resultBuffer, &byteOffset)); + napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_float64_array) { flag = true; } @@ -266,10 +258,10 @@ namespace OHOS::Util { return result; } - napi_value Types::IsGeneratorFunction(napi_value src) + napi_value Types::IsGeneratorFunction(napi_value src) const { - napi_valuetype result; - NAPI_CALL(env_, napi_typeof(env_, src, &result)); + napi_valuetype result = napi_undefined; + napi_typeof(env_, src, &result); bool flag = false; if (result == napi_function) { NAPI_CALL(env_, napi_is_generator_function(env_, src, &flag)); @@ -279,7 +271,7 @@ namespace OHOS::Util { return rst; } - napi_value Types::IsGeneratorObject(napi_value src) + napi_value Types::IsGeneratorObject(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_generator_object(env_, src, &flag)); @@ -288,21 +280,21 @@ namespace OHOS::Util { return result; } - napi_value Types::IsInt8Array(napi_value src) + napi_value Types::IsInt8Array(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; bool flag = false; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, - &resultData, &resultBuffer, &byteOffset)); - if (type == napi_typedarray_type::napi_int8_array) { + napi_status rstSta = napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); + if ((rstSta == napi_ok) && (type == napi_typedarray_type::napi_int8_array)) { flag = true; } } @@ -310,20 +302,20 @@ namespace OHOS::Util { return result; } - napi_value Types::IsInt16Array(napi_value src) + napi_value Types::IsInt16Array(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; bool flag = false; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, - &resultData, &resultBuffer, &byteOffset)); + napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_int16_array) { flag = true; } @@ -332,20 +324,20 @@ namespace OHOS::Util { return result; } - napi_value Types::IsInt32Array(napi_value src) + napi_value Types::IsInt32Array(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; bool flag = false; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, - &resultData, &resultBuffer, &byteOffset)); + napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_int32_array) { flag = true; } @@ -354,16 +346,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsKeyObject(napi_value src) - { - bool flag = false; - napi_value result = nullptr; - napi_get_boolean(env_, flag, &result); - HILOG_INFO("The type is not supported!"); - return result; - } - - napi_value Types::IsMap(napi_value src) + napi_value Types::IsMap(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_map(env_, src, &flag)); @@ -372,7 +355,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsMapIterator(napi_value src) + napi_value Types::IsMapIterator(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_map_iterator(env_, src, &flag)); @@ -381,7 +364,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsModuleNamespaceObject(napi_value src) + napi_value Types::IsModuleNamespaceObject(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_module_namespace_object(env_, src, &flag)); @@ -391,7 +374,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsNativeError(napi_value src) + napi_value Types::IsNativeError(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_error(env_, src, &flag)); @@ -400,12 +383,12 @@ namespace OHOS::Util { return result; } - napi_value Types::IsNumberObject(napi_value src) + napi_value Types::IsNumberObject(napi_value src) const { bool flag = false; - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { NAPI_CALL(env_, napi_is_number_object(env_, src, &flag)); } @@ -413,7 +396,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsPromise(napi_value src) + napi_value Types::IsPromise(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_promise(env_, src, &flag)); @@ -422,7 +405,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsProxy(napi_value src) + napi_value Types::IsProxy(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_proxy(env_, src, &flag)); @@ -431,7 +414,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsRegExp(napi_value src) + napi_value Types::IsRegExp(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_reg_exp(env_, src, &flag)); @@ -440,7 +423,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsSet(napi_value src) + napi_value Types::IsSet(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_set(env_, src, &flag)); @@ -449,7 +432,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsSetIterator(napi_value src) + napi_value Types::IsSetIterator(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_set_iterator(env_, src, &flag)); @@ -458,7 +441,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsSharedArrayBuffer(napi_value src) + napi_value Types::IsSharedArrayBuffer(napi_value src) const { bool flag = false; napi_value result = nullptr; @@ -467,11 +450,11 @@ namespace OHOS::Util { return result; } - napi_value Types::IsStringObject(napi_value src) + napi_value Types::IsStringObject(napi_value src) const { bool flag = false; - napi_valuetype valuetype; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_valuetype valuetype = napi_undefined; + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { NAPI_CALL(env_, napi_is_string_object(env_, src, &flag)); } @@ -480,12 +463,12 @@ namespace OHOS::Util { return result; } - napi_value Types::IsSymbolObject(napi_value src) + napi_value Types::IsSymbolObject(napi_value src) const { bool flag = false; napi_value result = nullptr; - napi_valuetype valuetype; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_valuetype valuetype = napi_undefined; + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { NAPI_CALL(env_, napi_is_symbol_object(env_, src, &flag)); } @@ -493,7 +476,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsTypedArray(napi_value src) + napi_value Types::IsTypedArray(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_typedarray(env_, src, &flag)); @@ -502,20 +485,20 @@ namespace OHOS::Util { return result; } - napi_value Types::IsUint8Array(napi_value src) + napi_value Types::IsUint8Array(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; bool flag = false; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, - &resultData, &resultBuffer, &byteOffset)); + napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_uint8_array) { flag = true; } @@ -524,20 +507,20 @@ namespace OHOS::Util { return result; } - napi_value Types::IsUint8ClampedArray(napi_value src) + napi_value Types::IsUint8ClampedArray(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; bool flag = false; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, - &resultData, &resultBuffer, &byteOffset)); + napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_uint8_clamped_array) { flag = true; } @@ -546,20 +529,20 @@ namespace OHOS::Util { return result; } - napi_value Types::IsUint16Array(napi_value src) + napi_value Types::IsUint16Array(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; bool flag = false; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, - &resultData, &resultBuffer, &byteOffset)); + napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_uint16_array) { flag = true; } @@ -568,20 +551,20 @@ namespace OHOS::Util { return result; } - napi_value Types::IsUint32Array(napi_value src) + napi_value Types::IsUint32Array(napi_value src) const { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_undefined; bool flag = false; napi_value result = nullptr; - NAPI_CALL(env_, napi_typeof(env_, src, &valuetype)); + napi_typeof(env_, src, &valuetype); if (valuetype == napi_valuetype::napi_object) { - napi_typedarray_type type; + napi_typedarray_type type = napi_int8_array; size_t byteOffset = 0; size_t length = 0; void* resultData = nullptr; napi_value resultBuffer = nullptr; - NAPI_CALL(env_, napi_get_typedarray_info(env_, src, &type, &length, - &resultData, &resultBuffer, &byteOffset)); + napi_get_typedarray_info(env_, src, &type, &length, + &resultData, &resultBuffer, &byteOffset); if (type == napi_typedarray_type::napi_uint32_array) { flag = true; } @@ -590,7 +573,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsWeakMap(napi_value src) + napi_value Types::IsWeakMap(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_weak_map(env_, src, &flag)); @@ -599,7 +582,7 @@ namespace OHOS::Util { return result; } - napi_value Types::IsWeakSet(napi_value src) + napi_value Types::IsWeakSet(napi_value src) const { bool flag = false; NAPI_CALL(env_, napi_is_weak_set(env_, src, &flag)); diff --git a/util/js_types.h b/util/js_types.h index fadbcd3..26858e6 100644 --- a/util/js_types.h +++ b/util/js_types.h @@ -16,10 +16,9 @@ #include #include -#include "napi/native_node_api.h" -#include "native_engine/native_engine.h" #include "napi/native_api.h" #include "napi/native_node_api.h" +#include "native_engine/native_engine.h" #ifndef BASE_COMPILERUNTIME_JS_UTIL_MODULE_TYPES_CLASS_H #define BASE_COMPILERUNTIME_JS_UTIL_MODULE_TYPES_CLASS_H @@ -29,47 +28,45 @@ namespace OHOS::Util { public: explicit Types(napi_env env); virtual ~Types() {} - napi_value IsAnyArrayBuffer(napi_value src); - napi_value IsArrayBufferView(napi_value src); - napi_value IsArgumentsObject(napi_value src); - napi_value IsArrayBuffer(napi_value src); - napi_value IsAsyncFunction(napi_value src); - napi_value IsBigInt64Array(napi_value src); - napi_value IsBigUint64Array(napi_value src); - napi_value IsBooleanObject(napi_value src); - napi_value IsBoxedPrimitive(napi_value src); - napi_value IsCryptoKey(napi_value src); - napi_value IsDataView(napi_value src); - napi_value IsDate(napi_value src); - napi_value IsExternal(napi_value src); - napi_value IsFloat32Array(napi_value src); - napi_value IsFloat64Array(napi_value src); - napi_value IsGeneratorFunction(napi_value src); - napi_value IsGeneratorObject(napi_value src); - napi_value IsInt8Array(napi_value src); - napi_value IsInt16Array(napi_value src); - napi_value IsInt32Array(napi_value src); - napi_value IsKeyObject(napi_value src); - napi_value IsMap(napi_value src); - napi_value IsMapIterator(napi_value src); - napi_value IsModuleNamespaceObject(napi_value src); - napi_value IsNativeError(napi_value src); - napi_value IsNumberObject(napi_value src); - napi_value IsPromise(napi_value src); - napi_value IsProxy(napi_value src); - napi_value IsRegExp(napi_value src); - napi_value IsSet(napi_value src); - napi_value IsSetIterator(napi_value src); - napi_value IsSharedArrayBuffer(napi_value src); - napi_value IsStringObject(napi_value src); - napi_value IsSymbolObject(napi_value src); - napi_value IsTypedArray(napi_value src); - napi_value IsUint8Array(napi_value src); - napi_value IsUint8ClampedArray(napi_value src); - napi_value IsUint16Array(napi_value src); - napi_value IsUint32Array(napi_value src); - napi_value IsWeakMap(napi_value src); - napi_value IsWeakSet(napi_value src); + napi_value IsAnyArrayBuffer(napi_value src) const; + napi_value IsArrayBufferView(napi_value src) const; + napi_value IsArgumentsObject(napi_value src) const; + napi_value IsArrayBuffer(napi_value src) const; + napi_value IsAsyncFunction(napi_value src) const; + napi_value IsBigInt64Array(napi_value src) const; + napi_value IsBigUint64Array(napi_value src) const; + napi_value IsBooleanObject(napi_value src) const; + napi_value IsBoxedPrimitive(napi_value src) const; + napi_value IsDataView(napi_value src) const; + napi_value IsDate(napi_value src) const; + napi_value IsExternal(napi_value src) const; + napi_value IsFloat32Array(napi_value src) const; + napi_value IsFloat64Array(napi_value src) const; + napi_value IsGeneratorFunction(napi_value src) const; + napi_value IsGeneratorObject(napi_value src) const; + napi_value IsInt8Array(napi_value src) const; + napi_value IsInt16Array(napi_value src) const; + napi_value IsInt32Array(napi_value src) const; + napi_value IsMap(napi_value src) const; + napi_value IsMapIterator(napi_value src) const; + napi_value IsModuleNamespaceObject(napi_value src) const; + napi_value IsNativeError(napi_value src) const; + napi_value IsNumberObject(napi_value src) const; + napi_value IsPromise(napi_value src) const; + napi_value IsProxy(napi_value src) const; + napi_value IsRegExp(napi_value src) const; + napi_value IsSet(napi_value src) const; + napi_value IsSetIterator(napi_value src) const; + napi_value IsSharedArrayBuffer(napi_value src) const; + napi_value IsStringObject(napi_value src) const; + napi_value IsSymbolObject(napi_value src) const; + napi_value IsTypedArray(napi_value src) const; + napi_value IsUint8Array(napi_value src) const; + napi_value IsUint8ClampedArray(napi_value src) const; + napi_value IsUint16Array(napi_value src) const; + napi_value IsUint32Array(napi_value src) const; + napi_value IsWeakMap(napi_value src) const; + napi_value IsWeakSet(napi_value src) const; private: napi_env env_; }; diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index 67faef9..d932b28 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -451,7 +451,6 @@ namespace OHOS::Util { return result; } - static napi_value TextcoderInit(napi_env env, napi_value exports) { const char *textEncoderClassName = "TextEncoder"; @@ -523,7 +522,7 @@ namespace OHOS::Util { NAPI_ASSERT(env, valuetype0 == napi_uint8_array, "Wrong argument type. napi_uint8_array expected."); Base64 *object = nullptr; NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); - napi_value result = object->Encode(args[0]); + napi_value result = object->EncodeSync(args[0]); return result; } @@ -544,7 +543,7 @@ namespace OHOS::Util { NAPI_ASSERT(env, valuetype0 == napi_uint8_array, "Wrong argument type. napi_uint8_array expected."); Base64 *object = nullptr; NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); - napi_value result = object->EncodeToString(args[0]); + napi_value result = object->EncodeToStringSync(args[0]); return result; } @@ -572,10 +571,9 @@ namespace OHOS::Util { } Base64 *object = nullptr; NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); - napi_value result = object->Decode(args[0]); + napi_value result = object->DecodeSync(args[0]); return result; } - static napi_value EncodeAsync(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -593,10 +591,9 @@ namespace OHOS::Util { NAPI_ASSERT(env, valuetype0 == napi_uint8_array, "Wrong argument type. napi_uint8_array expected."); Base64 *object = nullptr; NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); - napi_value result = object->EncodeAsync(args[0]); + napi_value result = object->Encode(args[0]); return result; } - static napi_value EncodeToStringAsync(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -614,10 +611,9 @@ namespace OHOS::Util { NAPI_ASSERT(env, valuetype0 == napi_uint8_array, "Wrong argument type. napi_uint8_array expected."); Base64 *object = nullptr; NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); - napi_value result = object->EncodeToStringAsync(args[0]); + napi_value result = object->EncodeToString(args[0]); return result; } - static napi_value DecodeAsync(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -642,7 +638,7 @@ namespace OHOS::Util { } Base64 *object = nullptr; NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); - napi_value result = object->DecodeAsync(args[0]); + napi_value result = object->Decode(args[0]); return result; } @@ -787,18 +783,6 @@ namespace OHOS::Util { return rst; } - static napi_value IsCryptoKey(napi_env env, napi_callback_info info) - { - napi_value thisVar = nullptr; - size_t argc = 1; - napi_value args = nullptr; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); - Types* object = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); - napi_value rst = object->IsCryptoKey(args); - return rst; - } - static napi_value IsDataView(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -927,20 +911,6 @@ namespace OHOS::Util { return result; } - static napi_value IsKeyObject(napi_env env, napi_callback_info info) - { - napi_value thisVar = nullptr; - size_t requireArgc = 1; - size_t argc = 1; - napi_value args = nullptr; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &args, &thisVar, nullptr)); - NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments"); - Types* object = nullptr; - NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&object)); - napi_value result = object->IsKeyObject(args); - return result; - } - static napi_value IsMap(napi_env env, napi_callback_info info) { napi_value thisVar = nullptr; @@ -1220,7 +1190,7 @@ namespace OHOS::Util { napi_value result = object->IsWeakSet(args); return result; } - + static napi_value TypeofInit(napi_env env, napi_value exports) { const char* typeofClassName = "Types"; @@ -1234,7 +1204,6 @@ namespace OHOS::Util { DECLARE_NAPI_FUNCTION("isArrayBufferView", IsArrayBufferView), DECLARE_NAPI_FUNCTION("isArgumentsObject", IsArgumentsObject), DECLARE_NAPI_FUNCTION("isArrayBuffer", IsArrayBuffer), - DECLARE_NAPI_FUNCTION("isCryptoKey", IsCryptoKey), DECLARE_NAPI_FUNCTION("isDataView", IsDataView), DECLARE_NAPI_FUNCTION("isDate", IsDate), DECLARE_NAPI_FUNCTION("isExternal", IsExternal), @@ -1245,7 +1214,6 @@ namespace OHOS::Util { DECLARE_NAPI_FUNCTION("isInt8Array", IsInt8Array), DECLARE_NAPI_FUNCTION("isInt16Array", IsInt16Array), DECLARE_NAPI_FUNCTION("isInt32Array", IsInt32Array), - DECLARE_NAPI_FUNCTION("isKeyObject", IsKeyObject), DECLARE_NAPI_FUNCTION("isMap", IsMap), DECLARE_NAPI_FUNCTION("isMapIterator", IsMapIterator), DECLARE_NAPI_FUNCTION("isModuleNamespaceObject", IsModuleNamespaceObject), @@ -1281,12 +1249,12 @@ namespace OHOS::Util { const char *base64ClassName = "Base64"; napi_value base64Class = nullptr; static napi_property_descriptor base64Desc[] = { - DECLARE_NAPI_FUNCTION("encode", EncodeBase64), - DECLARE_NAPI_FUNCTION("encodeToString", EncodeToString), - DECLARE_NAPI_FUNCTION("decode", DecodeBase64), - DECLARE_NAPI_FUNCTION("encodeAsync", EncodeAsync), - DECLARE_NAPI_FUNCTION("encodeToStringAsync", EncodeToStringAsync), - DECLARE_NAPI_FUNCTION("decodeAsync", DecodeAsync), + DECLARE_NAPI_FUNCTION("encodeSync", EncodeBase64), + DECLARE_NAPI_FUNCTION("encodeToStringSync", EncodeToString), + DECLARE_NAPI_FUNCTION("decodeSync", DecodeBase64), + DECLARE_NAPI_FUNCTION("encode", EncodeAsync), + DECLARE_NAPI_FUNCTION("encodeToString", EncodeToStringAsync), + DECLARE_NAPI_FUNCTION("decode", DecodeAsync), }; NAPI_CALL(env, napi_define_class(env, base64ClassName, strlen(base64ClassName), Base64Constructor, nullptr, sizeof(base64Desc) / sizeof(base64Desc[0]), base64Desc, diff --git a/util/src/util_js.ts b/util/src/util_js.ts index 818c069..e7966ae 100644 --- a/util/src/util_js.ts +++ b/util/src/util_js.ts @@ -441,18 +441,20 @@ function promiseWrapper(func : any) { class LruBuffer { - private cache: Map; + private cache: Map; private maxSize : number = 64; + private maxNumber : number = 2147483647; private putCount : number = 0; private createCount : number = 0; private evictionCount : number = 0; private hitCount : number = 0; private missCount : number = 0; + public length : number = 0; public constructor(capacity?: number) { if(capacity !== undefined) { - if (capacity <= 0) { + if (capacity <= 0 || capacity%1 !== 0 || capacity > this.maxNumber) { throw new Error('data error'); } this.maxSize = capacity; @@ -461,14 +463,15 @@ class LruBuffer } public updateCapacity(newCapacity : number) { - if (newCapacity <= 0) { + if (newCapacity <= 0 || newCapacity%1 !== 0 || newCapacity > this.maxNumber) { throw new Error('data error'); } else if (this.cache.size >newCapacity) { this.changeCapacity(newCapacity); } + this.length = this.cache.size; this.maxSize = newCapacity; } - public get(key : any) + public get(key : any) { if (key === null) { throw new Error('key not be null'); @@ -496,7 +499,7 @@ class LruBuffer return createValue; } } - public put(key : any, value : any) + public put(key : any, value : any) { if (key === null || value === null) { throw new Error('key or value not be null'); @@ -510,42 +513,40 @@ class LruBuffer } else if (this.cache.size >= this.maxSize) { this.cache.delete(this.cache.keys().next().value); this.evictionCount++; - } + } this.cache.set(key, value); + this.length = this.cache.size; return former; } public getCreateCount() - { + { return this.createCount; } public getMissCount() { return this.missCount; } - public getRemovalCount() + public getRemovalCount() { return this.evictionCount; } - public getMatchCount() + public getMatchCount() { return this.hitCount; } - public getPutCount() + public getPutCount() { return this.putCount; } - public capacity() + public getCapacity() { return this.maxSize; } - public size() - { - return this.cache.size; - } public clear() { this.cache.clear(); this.afterRemoval(false, this.cache.keys(), this.cache.values(), null); + this.length = this.cache.size; } public isEmpty() { @@ -565,11 +566,12 @@ class LruBuffer value = this.cache.get(key); this.cache.delete(key); this.cache.set(key, value); + this.length = this.cache.size; return flag; } this.missCount++; return flag; - } + } public remove(key : any) { if (key === null) { @@ -580,9 +582,11 @@ class LruBuffer this.cache.delete(key); if (former !== null) { this.afterRemoval(false, key, former, null); + this.length = this.cache.size; return former; } - } + } + this.length = this.cache.size; return undefined; } public toString() @@ -618,13 +622,13 @@ class LruBuffer } protected afterRemoval(isEvict : boolean, key : any, value : any, newValue : any) { - + } protected createDefault(key : any) { return undefined; } - public entries() + public entries() { let arr = []; for (let entry of this.cache.entries()) { @@ -632,7 +636,7 @@ class LruBuffer } return arr; } - public [Symbol.iterator] () + public [Symbol.iterator]() { let arr = []; for (let [key, value] of this.cache) { @@ -749,7 +753,7 @@ class RationalNumber } } - public value() + public valueOf() { if (this.mnum > 0 && this.mden == 0) { return Number.POSITIVE_INFINITY; @@ -953,7 +957,7 @@ class Scope { let mUpper = reUpper ? this._upperLimit : y; return new Scope(mLower, mUpper); } - } + } public toString(): string { let strLower = this._lowerLimit.toString(); diff --git a/util/tsconfig.json b/util/tsconfig.json index 66ad148..eff2af4 100644 --- a/util/tsconfig.json +++ b/util/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "target": "es6", - "module": "es6", - "rootDir": "./src", + "module": "es6", + "rootDir": "./src", //"outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ "outDir": "./out", /* Specify an output folder for all emitted files. */ "esModuleInterop": true, @@ -10,5 +10,5 @@ "strict": true, "skipLibCheck": true, "noImplicitThis": false, - } + } } -- Gitee