1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstddef>
17 #define private public
18 #define protected public
19 
20 #include <chrono>
21 #include <thread>
22 
23 #include "test.h"
24 #include "test_common.h"
25 #include "gtest/gtest.h"
26 #include "napi/native_api.h"
27 #include "napi/native_node_api.h"
28 #include "napi/native_common.h"
29 #include "securec.h"
30 #include "utils/log.h"
31 #include "native_engine/impl/ark/ark_native_engine.h"
32 #include "napi/native_engine/native_create_env.h"
33 
34 using panda::RuntimeOption;
35 
36 static constexpr int MAX_BUFFER_SIZE = 2;
37 static constexpr int BUFFER_SIZE_FIVE = 5;
38 static constexpr size_t TEST_STR_LENGTH = 30;
39 static int g_hookTagcp = 0;
40 static int g_hookTag = 0;
41 static int g_hookArgOne = 1;
42 static int g_hookArgTwo = 2;
43 static int g_hookArgThree = 3;
44 static constexpr int INT_ZERO = 0;
45 static constexpr int INT_ONE = 1;
46 static constexpr int INT_TWO = 2;
47 static constexpr int INT_THREE = 3;
48 static constexpr int THREAD_SIZE = 5;
49 
50 static constexpr double TEST_DOUBLE = 1.1;
51 static constexpr char TEST_STRING[5] = "test";
52 static constexpr size_t MAX_BYTE_LENGTH = 2097152;
53 static constexpr int32_t TEST_INT32_MINUS_1 = -1;
54 static constexpr int32_t TEST_INT32_500 = 500;
55 static constexpr uint32_t TEST_UINT32_1000 = 1000;
56 static constexpr int64_t TEST_INT64 = 9007199254740991;
57 static constexpr const char TEST_CHAR_STRING[] = "TestString";
58 static constexpr const char16_t TEST_CHAR16_STRING[] = u"TestString";
59 
60 class NapiBasicTest : public NativeEngineTest {
61 public:
SetUpTestCase()62     static void SetUpTestCase()
63     {
64         GTEST_LOG_(INFO) << "NapiBasicTest SetUpTestCase";
65     }
66 
TearDownTestCase()67     static void TearDownTestCase()
68     {
69         GTEST_LOG_(INFO) << "NapiBasicTest TearDownTestCase";
70     }
71 
72     void SetUp() override
73     {
74         napi_env env = reinterpret_cast<napi_env>(engine_);
75         napi_open_handle_scope(env, &scope_);
76     }
77 
78     void TearDown() override
79     {
80         napi_env env = reinterpret_cast<napi_env>(engine_);
81         napi_value exception = nullptr;
82         napi_get_and_clear_last_exception(env, &exception);
83         napi_close_handle_scope(env, scope_);
84     }
85 private:
86     napi_handle_scope scope_ = nullptr;
87 };
88 
89 class NativeEngineProxy {
90 public:
NativeEngineProxy()91     NativeEngineProxy()
92     {
93         // Setup
94         RuntimeOption option;
95         option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC);
96         const int64_t poolSize = 0x1000000;  // 16M
97         option.SetGcPoolSize(poolSize);
98         option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
99         option.SetDebuggerLibraryPath("");
100         vm_ = panda::JSNApi::CreateJSVM(option);
101         if (vm_ == nullptr) {
102             return;
103         }
104 
105         engine_ = new ArkNativeEngine(vm_, nullptr);
106     }
107 
~NativeEngineProxy()108     ~NativeEngineProxy()
109     {
110         delete engine_;
111         panda::JSNApi::DestroyJSVM(vm_);
112     }
113 
operator ->() const114     inline ArkNativeEngine* operator->() const
115     {
116         return engine_;
117     }
118 
operator napi_env() const119     inline operator napi_env() const
120     {
121         return reinterpret_cast<napi_env>(engine_);
122     }
123 
124 private:
125     EcmaVM* vm_ {nullptr};
126     ArkNativeEngine* engine_ {nullptr};
127 };
128 
129 static const napi_type_tag typeTags[5] = { // 5:array element size is 5.
130     {0xdaf987b3cc62481a, 0xb745b0497f299531},
131     {0xbb7936c374084d9b, 0xa9548d0762eeedb9},
132     {0xa5ed9ce2e4c00c38, 0},
133     {0, 0},
134     {0xa5ed9ce2e4c00c34, 0xdaf987b3cc62481a},
135 };
136 
TestDetachCallback(napi_env env, void* nativeObject, void* hint)137 static void* TestDetachCallback(napi_env env, void* nativeObject, void* hint)
138 {
139     HILOG_INFO("this is detach callback");
140     return nativeObject;
141 }
142 
TestAttachCallback(napi_env env, void* nativeObject, void* hint)143 static napi_value TestAttachCallback(napi_env env, void* nativeObject, void* hint)
144 {
145     HILOG_INFO("this is attach callback");
146     napi_value object = nullptr;
147     napi_value number = nullptr;
148     uint32_t data = 0;
149     if (hint != nullptr) {
150         object = reinterpret_cast<napi_value>(nativeObject);
151         data = 2000; // 2000 : test number
152         napi_create_uint32(env, data, &number);
153     } else {
154         napi_create_object(env, &object);
155         data = 1000; // 1000 : test number
156         napi_create_uint32(env, data, &number);
157     }
158     napi_set_named_property(env, object, "number", number);
159     return object;
160 }
161 
162 /**
163  * @tc.name: ToNativeBindingObjectTest001
164  * @tc.desc: Test nativeBinding object type.
165  * @tc.type: FUNC
166  */
HWTEST_F(NapiBasicTest, ToNativeBindingObjectTest001, testing::ext::TestSize.Level1)167 HWTEST_F(NapiBasicTest, ToNativeBindingObjectTest001, testing::ext::TestSize.Level1)
168 {
169     napi_env env = (napi_env)engine_;
170     napi_value object = nullptr;
171     napi_create_object(env, &object);
172     napi_value object1 = nullptr;
173     napi_create_object(env, &object1);
174     napi_status status = napi_coerce_to_native_binding_object(
175         env, object, TestDetachCallback, TestAttachCallback, reinterpret_cast<void*>(object1), nullptr);
176     ASSERT_EQ(status, napi_status::napi_ok);
177 }
178 
179 /**
180  * @tc.name: ToNativeBindingObjectTest002
181  * @tc.desc: Test nativeBinding object type.
182  * @tc.type: FUNC
183  */
HWTEST_F(NapiBasicTest, ToNativeBindingObjectTest002, testing::ext::TestSize.Level1)184 HWTEST_F(NapiBasicTest, ToNativeBindingObjectTest002, testing::ext::TestSize.Level1)
185 {
186     napi_env env = (napi_env)engine_;
187     napi_value object = nullptr;
188     napi_create_object(env, &object);
189     napi_value object1 = nullptr;
190     napi_create_object(env, &object1);
191     napi_coerce_to_native_binding_object(
192         env, object, TestDetachCallback, TestAttachCallback, reinterpret_cast<void*>(object1), nullptr);
193     napi_value undefined = nullptr;
194     napi_get_undefined(env, &undefined);
195     void* data = nullptr;
196     napi_serialize_inner(env, object, undefined, undefined, false, true, &data);
197     ASSERT_NE(data, nullptr);
198     napi_value result = nullptr;
199     napi_deserialize(env, data, &result);
200     ASSERT_CHECK_VALUE_TYPE(env, result, napi_object);
201     napi_delete_serialization_data(env, data);
202     napi_value number = nullptr;
203     napi_get_named_property(env, result, "number", &number);
204     ASSERT_CHECK_VALUE_TYPE(env, number, napi_number);
205     uint32_t numData = 0;
206     napi_get_value_uint32(env, number, &numData);
207     ASSERT_EQ(numData, 1000);
208 }
209 
210 /**
211  * @tc.name: ToNativeBindingObjectTest003
212  * @tc.desc: Test nativeBinding object type.
213  * @tc.type: FUNC
214  */
HWTEST_F(NapiBasicTest, ToNativeBindingObjectTest003, testing::ext::TestSize.Level1)215 HWTEST_F(NapiBasicTest, ToNativeBindingObjectTest003, testing::ext::TestSize.Level1)
216 {
217     napi_env env = (napi_env)engine_;
218     napi_value object = nullptr;
219     napi_create_object(env, &object);
220     napi_status status = napi_coerce_to_native_binding_object(
221         env, object, TestDetachCallback, TestAttachCallback, nullptr, nullptr);
222     ASSERT_EQ(status, napi_status::napi_invalid_arg);
223     napi_value object1 = nullptr;
224     napi_create_object(env, &object1);
225     status = napi_coerce_to_native_binding_object(
226         env, object, nullptr, nullptr, reinterpret_cast<void*>(object1), nullptr);
227     ASSERT_EQ(status, napi_status::napi_invalid_arg);
228 }
229 
230 /**
231  * @tc.name: ToNativeBindingObjectTest004
232  * @tc.desc: Test nativeBinding object type.
233  * @tc.type: FUNC
234  */
HWTEST_F(NapiBasicTest, ToNativeBindingObjectTest004, testing::ext::TestSize.Level1)235 HWTEST_F(NapiBasicTest, ToNativeBindingObjectTest004, testing::ext::TestSize.Level1)
236 {
237     napi_env env = (napi_env)engine_;
238     napi_value object = nullptr;
239     napi_create_object(env, &object);
240     napi_value hint = nullptr;
241     napi_create_object(env, &hint);
242     napi_value object1 = nullptr;
243     napi_create_object(env, &object1);
244     napi_status status = napi_coerce_to_native_binding_object(env, object,
245         TestDetachCallback, TestAttachCallback, reinterpret_cast<void*>(object1), reinterpret_cast<void*>(hint));
246     ASSERT_EQ(status, napi_status::napi_ok);
247     napi_value undefined = nullptr;
248     napi_get_undefined(env, &undefined);
249     void* data = nullptr;
250     napi_serialize_inner(env, object, undefined, undefined, false, true, &data);
251     ASSERT_NE(data, nullptr);
252     napi_value result = nullptr;
253     napi_deserialize(env, data, &result);
254     ASSERT_CHECK_VALUE_TYPE(env, result, napi_object);
255     napi_delete_serialization_data(env, data);
256     napi_value number = nullptr;
257     napi_get_named_property(env, result, "number", &number);
258     ASSERT_CHECK_VALUE_TYPE(env, number, napi_number);
259     uint32_t numData = 0;
260     napi_get_value_uint32(env, number, &numData);
261     ASSERT_EQ(numData, 2000);
262 }
263 
264 /**
265  * @tc.name: UndefinedTest001
266  * @tc.desc: Test undefined type.
267  * @tc.type: FUNC
268  */
HWTEST_F(NapiBasicTest, UndefinedTest001, testing::ext::TestSize.Level1)269 HWTEST_F(NapiBasicTest, UndefinedTest001, testing::ext::TestSize.Level1)
270 {
271     napi_env env = (napi_env)engine_;
272     napi_value result = nullptr;
273     ASSERT_CHECK_CALL(napi_get_undefined(env, &result));
274     ASSERT_CHECK_VALUE_TYPE(env, result, napi_undefined);
275 }
276 
277 /**
278  * @tc.name: NullTest001
279  * @tc.desc: Test null type.
280  * @tc.type: FUNC
281  */
HWTEST_F(NapiBasicTest, NullTest001, testing::ext::TestSize.Level1)282 HWTEST_F(NapiBasicTest, NullTest001, testing::ext::TestSize.Level1)
283 {
284     napi_env env = (napi_env)engine_;
285     napi_value result = nullptr;
286     ASSERT_CHECK_CALL(napi_get_null(env, &result));
287     ASSERT_CHECK_VALUE_TYPE(env, result, napi_null);
288 }
289 
290 /**
291  * @tc.name: BooleanTest001
292  * @tc.desc: Test boolean type.
293  * @tc.type: FUNC
294  */
HWTEST_F(NapiBasicTest, BooleanTest001, testing::ext::TestSize.Level1)295 HWTEST_F(NapiBasicTest, BooleanTest001, testing::ext::TestSize.Level1)
296 {
297     napi_env env = (napi_env)engine_;
298     napi_value result = nullptr;
299     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &result));
300     ASSERT_CHECK_VALUE_TYPE(env, result, napi_boolean);
301 
302     bool resultValue = false;
303     ASSERT_CHECK_CALL(napi_get_value_bool(env, result, &resultValue));
304     ASSERT_TRUE(resultValue);
305 }
306 
307 /**
308  * @tc.name: NumberTest001
309  * @tc.desc: Test number type.
310  * @tc.type: FUNC
311  */
HWTEST_F(NapiBasicTest, NumberTest001, testing::ext::TestSize.Level1)312 HWTEST_F(NapiBasicTest, NumberTest001, testing::ext::TestSize.Level1)
313 {
314     napi_env env = (napi_env)engine_;
315     {
316         int32_t testValue = INT32_MAX;
317         napi_value result = nullptr;
318         ASSERT_CHECK_CALL(napi_create_int32(env, testValue, &result));
319         ASSERT_CHECK_VALUE_TYPE(env, result, napi_number);
320 
321         int32_t resultValue = 0;
322         ASSERT_CHECK_CALL(napi_get_value_int32(env, result, &resultValue));
323         ASSERT_EQ(resultValue, INT32_MAX);
324     }
325     {
326         uint32_t testValue = UINT32_MAX;
327         napi_value result = nullptr;
328         ASSERT_CHECK_CALL(napi_create_uint32(env, testValue, &result));
329         ASSERT_CHECK_VALUE_TYPE(env, result, napi_number);
330 
331         uint32_t resultValue = 0;
332         ASSERT_CHECK_CALL(napi_get_value_uint32(env, result, &resultValue));
333         ASSERT_EQ(resultValue, UINT32_MAX);
334     }
335     {
336         int64_t testValue = 9007199254740991;
337         napi_value result = nullptr;
338         ASSERT_CHECK_CALL(napi_create_int64(env, testValue, &result));
339         ASSERT_CHECK_VALUE_TYPE(env, result, napi_number);
340 
341         int64_t resultValue = 0;
342         ASSERT_CHECK_CALL(napi_get_value_int64(env, result, &resultValue));
343         ASSERT_EQ(resultValue, testValue);
344     }
345     {
346         double testValue = DBL_MAX;
347         napi_value result = nullptr;
348         ASSERT_CHECK_CALL(napi_create_double(env, testValue, &result));
349         ASSERT_CHECK_VALUE_TYPE(env, result, napi_number);
350 
351         double resultValue = 0;
352         ASSERT_CHECK_CALL(napi_get_value_double(env, result, &resultValue));
353         ASSERT_EQ(resultValue, DBL_MAX);
354     }
355 }
356 
357 /**
358  * @tc.name: StringTest001
359  * @tc.desc: Test string type.
360  * @tc.type: FUNC
361  */
HWTEST_F(NapiBasicTest, StringTest001, testing::ext::TestSize.Level1)362 HWTEST_F(NapiBasicTest, StringTest001, testing::ext::TestSize.Level1)
363 {
364     napi_env env = (napi_env)engine_;
365     const char testStr[] = "中文,English,123456,!@#$%$#^%&";
366     size_t testStrLength = strlen(testStr);
367     napi_value result = nullptr;
368     ASSERT_CHECK_CALL(napi_create_string_utf8(env, testStr, testStrLength, &result));
369     ASSERT_CHECK_VALUE_TYPE(env, result, napi_string);
370 
371     char* buffer = nullptr;
372     size_t bufferSize = 0;
373     size_t strLength = 0;
374     ASSERT_CHECK_CALL(napi_get_value_string_utf8(env, result, nullptr, 0, &bufferSize));
375     ASSERT_GT(bufferSize, static_cast<size_t>(0));
376     buffer = new char[bufferSize + 1]{ 0 };
377     ASSERT_CHECK_CALL(napi_get_value_string_utf8(env, result, buffer, bufferSize + 1, &strLength));
378     ASSERT_STREQ(testStr, buffer);
379     ASSERT_EQ(testStrLength, strLength);
380     delete []buffer;
381     buffer = nullptr;
382 }
383 
384 /**
385  * @tc.name: StringTest002
386  * @tc.desc: Test string type.
387  * @tc.type: FUNC
388  */
HWTEST_F(NapiBasicTest, StringTest002, testing::ext::TestSize.Level1)389 HWTEST_F(NapiBasicTest, StringTest002, testing::ext::TestSize.Level1)
390 {
391     napi_env env = (napi_env)engine_;
392     const char testStr[] = "中测";
393     size_t testStrLength = strlen(testStr);
394     napi_value result = nullptr;
395     ASSERT_CHECK_CALL(napi_create_string_utf8(env, testStr, testStrLength, &result));
396     ASSERT_CHECK_VALUE_TYPE(env, result, napi_string);
397 
398     std::string str = "";
399     size_t strSize = 0;
400     napi_get_value_string_latin1(env, result, nullptr, 0, &strSize);
401     str.reserve(strSize + 1);
402     str.resize(strSize);
403     napi_get_value_string_latin1(env, result, str.data(), strSize + 1, &strSize);
404 
405     ASSERT_EQ(str, "-K");
406 }
407 
408 /**
409  * @tc.name: StringTest003
410  * @tc.desc: Test string type.
411  * @tc.type: FUNC
412  */
HWTEST_F(NapiBasicTest, StringTest003, testing::ext::TestSize.Level1)413 HWTEST_F(NapiBasicTest, StringTest003, testing::ext::TestSize.Level1)
414 {
415     napi_env env = (napi_env)engine_;
416     const char16_t testStr[] = u"abc56";
417     size_t testStrLength = std::char_traits<char16_t>::length(testStr);
418     napi_value res = nullptr;
419     ASSERT_CHECK_CALL(napi_create_string_utf16(env, testStr, testStrLength, &res));
420     ASSERT_CHECK_VALUE_TYPE(env, res, napi_string);
421 
422     char16_t* buffer = nullptr;
423     size_t bufSize = 0;
424     size_t copied = 0;
425     ASSERT_CHECK_CALL(napi_get_value_string_utf16(env, res, nullptr, 0, &bufSize));
426     ASSERT_EQ(bufSize, testStrLength);
427     buffer = new char16_t[bufSize + 1]{ 0 };
428     ASSERT_CHECK_CALL(napi_get_value_string_utf16(env, res, buffer, bufSize + 1, &copied));
429     for (size_t i = 0; i < copied; i++) {
430         ASSERT_TRUE(testStr[i] == buffer[i]);
431     }
432     ASSERT_EQ(testStrLength, copied);
433     delete []buffer;
434     buffer = nullptr;
435 }
436 
437 /**
438  * @tc.name: StringTest004
439  * @tc.desc: Test string type.
440  * @tc.type: FUNC
441  */
HWTEST_F(NapiBasicTest, StringTest004, testing::ext::TestSize.Level1)442 HWTEST_F(NapiBasicTest, StringTest004, testing::ext::TestSize.Level1)
443 {
444     napi_env env = (napi_env)engine_;
445     const char16_t testStr[] = u"abc56";
446     size_t testStrLength = std::char_traits<char16_t>::length(testStr);
447     napi_value result = nullptr;
448     ASSERT_CHECK_CALL(napi_create_string_utf16(env, testStr, testStrLength, &result));
449     ASSERT_CHECK_VALUE_TYPE(env, result, napi_string);
450 
451     char16_t buffer[4]; // 4: char16_t type of array size
452     size_t bufferSize = 4; // 4: char16_t type of array size
453     size_t copied;
454 
455     ASSERT_CHECK_CALL(napi_get_value_string_utf16(env, result, buffer, bufferSize, &copied));
456     for (size_t i = 0; i < copied; i++) {
457         ASSERT_TRUE(testStr[i] == buffer[i]);
458     }
459     ASSERT_EQ(copied, 3);
460 }
461 
462 /**
463  * @tc.name: TypetagTest001
464  * @tc.desc: Test typetag type.
465  * @tc.type: FUNC
466  */
HWTEST_F(NapiBasicTest, TypetagTest001, testing::ext::TestSize.Level1)467 HWTEST_F(NapiBasicTest, TypetagTest001, testing::ext::TestSize.Level1)
468 {
469     napi_env env = (napi_env)engine_;
470     napi_value instance = nullptr;
471     bool result;
472     for (size_t i = 0; i < 5; i++) {
473         napi_create_object(env, &instance);
474         napi_type_tag_object(env, instance, &typeTags[i]);
475         napi_check_object_type_tag(env, instance, &typeTags[i], &result);
476         ASSERT_TRUE(result);
477     }
478 }
479 
480 /**
481  * @tc.name: TypetagTest002
482  * @tc.desc: Test typetag type.
483  * @tc.type: FUNC
484  */
HWTEST_F(NapiBasicTest, TypetagTest002, testing::ext::TestSize.Level1)485 HWTEST_F(NapiBasicTest, TypetagTest002, testing::ext::TestSize.Level1)
486 {
487     napi_env env = (napi_env)engine_;
488     uint32_t typeIndex = 0;
489     napi_value instance = nullptr;
490     bool result;
491     napi_create_object(env, &instance);
492 
493     napi_type_tag_object(env, instance, &typeTags[typeIndex]);
494     napi_check_object_type_tag(env, instance, &typeTags[typeIndex + 1], &result);
495 
496     ASSERT_FALSE(result);
497 }
498 
499 /**
500  * @tc.name: SymbolTest001
501  * @tc.desc: Test symbol type.
502  * @tc.type: FUNC
503  */
HWTEST_F(NapiBasicTest, SymbolTest001, testing::ext::TestSize.Level1)504 HWTEST_F(NapiBasicTest, SymbolTest001, testing::ext::TestSize.Level1)
505 {
506     napi_env env = (napi_env)engine_;
507 
508     const char testStr[] = "testSymbol";
509     napi_value result = nullptr;
510 
511     napi_create_string_latin1(env, testStr, strlen(testStr), &result);
512 
513     napi_value symbolVal = nullptr;
514     napi_create_symbol(env, result, &symbolVal);
515 
516     ASSERT_CHECK_VALUE_TYPE(env, symbolVal, napi_symbol);
517 }
518 
519 /**
520  * @tc.name: ExternalTest001
521  * @tc.desc: Test external type.
522  * @tc.type: FUNC
523  */
HWTEST_F(NapiBasicTest, ExternalTest001, testing::ext::TestSize.Level1)524 HWTEST_F(NapiBasicTest, ExternalTest001, testing::ext::TestSize.Level1)
525 {
526     napi_env env = (napi_env)engine_;
527     const char testStr[] = "test";
528     napi_value external = nullptr;
529     napi_create_external(
530         env, (void*)testStr,
531         [](napi_env env, void* data, void* hint) { ASSERT_STREQ((const char*)data, (const char*)hint); },
532         (void*)testStr, &external);
533 
534     ASSERT_CHECK_VALUE_TYPE(env, external, napi_external);
535     void* tmpExternal = nullptr;
536     napi_get_value_external(env, external, &tmpExternal);
537     ASSERT_TRUE(tmpExternal);
538     ASSERT_EQ(tmpExternal, testStr);
539 }
540 
541 /**
542  * @tc.name: ObjectTest001
543  * @tc.desc: Test object type.
544  * @tc.type: FUNC
545  */
HWTEST_F(NapiBasicTest, ObjectTest001, testing::ext::TestSize.Level1)546 HWTEST_F(NapiBasicTest, ObjectTest001, testing::ext::TestSize.Level1)
547 {
548     napi_env env = (napi_env)engine_;
549 
550     napi_value result = nullptr;
551     ASSERT_CHECK_CALL(napi_create_object(env, &result));
552     ASSERT_CHECK_VALUE_TYPE(env, result, napi_object);
553 
554     const char testStr[] = "1234567";
555     napi_value strAttribute = nullptr;
556     ASSERT_CHECK_CALL(napi_create_string_utf8(env, testStr, strlen(testStr), &strAttribute));
557     ASSERT_CHECK_VALUE_TYPE(env, strAttribute, napi_string);
558     ASSERT_CHECK_CALL(napi_set_named_property(env, result, "strAttribute", strAttribute));
559 
560     napi_value retStrAttribute = nullptr;
561     ASSERT_CHECK_CALL(napi_get_named_property(env, result, "strAttribute", &retStrAttribute));
562     ASSERT_CHECK_VALUE_TYPE(env, retStrAttribute, napi_string);
563 
564     int32_t testNumber = 12345;
565     napi_value numberAttribute = nullptr;
566     ASSERT_CHECK_CALL(napi_create_int32(env, testNumber, &numberAttribute));
567     ASSERT_CHECK_VALUE_TYPE(env, numberAttribute, napi_number);
568     ASSERT_CHECK_CALL(napi_set_named_property(env, result, "numberAttribute", numberAttribute));
569 
570     napi_value propNames = nullptr;
571     ASSERT_CHECK_CALL(napi_get_property_names(env, result, &propNames));
572     ASSERT_CHECK_VALUE_TYPE(env, propNames, napi_object);
573     bool isArray = false;
574     ASSERT_CHECK_CALL(napi_is_array(env, propNames, &isArray));
575     ASSERT_TRUE(isArray);
576     uint32_t arrayLength = 0;
577     ASSERT_CHECK_CALL(napi_get_array_length(env, propNames, &arrayLength));
578     ASSERT_EQ(arrayLength, static_cast<uint32_t>(2));
579 
580     for (uint32_t i = 0; i < arrayLength; i++) {
581         bool hasElement = false;
582         ASSERT_CHECK_CALL(napi_has_element(env, propNames, i, &hasElement));
583 
584         napi_value propName = nullptr;
585         ASSERT_CHECK_CALL(napi_get_element(env, propNames, i, &propName));
586         ASSERT_CHECK_VALUE_TYPE(env, propName, napi_string);
587 
588         bool hasProperty = false;
589         napi_has_property(env, result, propName, &hasProperty);
590         ASSERT_TRUE(hasProperty);
591 
592         napi_value propValue = nullptr;
593         napi_get_property(env, result, propName, &propValue);
594         ASSERT_TRUE(propValue != nullptr);
595     }
596 }
597 
598 /**
599  * @tc.name: ObjectTest002
600  * @tc.desc: Test Object Type.
601  * @tc.type: FUNC
602  */
HWTEST_F(NapiBasicTest, ObjectTest002, testing::ext::TestSize.Level1)603 HWTEST_F(NapiBasicTest, ObjectTest002, testing::ext::TestSize.Level1)
604 {
605     napi_env env = reinterpret_cast<napi_env>(engine_);
606 
607     napi_value result = nullptr;
608     napi_create_object(env, &result);
609     napi_value messageKey = nullptr;
610     const char* messageKeyStr = "message";
611     napi_create_string_latin1(env, messageKeyStr, strlen(messageKeyStr), &messageKey);
612     napi_value messageValue = nullptr;
613     const char* messageValueStr = "OK";
614     napi_create_string_latin1(env, messageValueStr, strlen(messageValueStr), &messageValue);
615     napi_set_property(env, result, messageKey, messageValue);
616 
617     napi_value propValue = nullptr;
618     napi_get_property(env, result, messageKey, &propValue);
619     ASSERT_TRUE(propValue != nullptr);
620 
621     napi_delete_property(env, result, messageKey, nullptr);
622     bool resultVal = true;
623     napi_has_property(env, result, messageKey, &resultVal);
624     ASSERT_FALSE(resultVal);
625 
626     napi_value newKey = nullptr;
627     const char* newKeyStr = "new";
628     napi_create_string_latin1(env, newKeyStr, strlen(newKeyStr), &newKey);
629     int32_t testnumber = 12345;
630     napi_value numberValue = nullptr;
631     napi_create_int32(env, testnumber, &numberValue);
632     napi_set_property(env, result, newKey, numberValue);
633 
634     napi_value propNames = nullptr;
635     napi_get_property_names(env, result, &propNames);
636     uint32_t arrayLength = 0;
637     napi_get_array_length(env, propNames, &arrayLength);
638     ASSERT_EQ(arrayLength, static_cast<uint32_t>(1));
639 }
640 
641 /**
642  * @tc.name: ObjectTest003
643  * @tc.desc: Test Object Type.
644  * @tc.type: FUNC
645  */
HWTEST_F(NapiBasicTest, ObjectTest003, testing::ext::TestSize.Level1)646 HWTEST_F(NapiBasicTest, ObjectTest003, testing::ext::TestSize.Level1)
647 {
648     napi_env env = reinterpret_cast<napi_env>(engine_);
649 
650     napi_value result = nullptr;
651     napi_create_object(env, &result);
652 
653     auto func = [](napi_env env, napi_callback_info info) -> napi_value {
654         return nullptr;
655     };
656     napi_value funcAttribute = nullptr;
657     napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH, func, nullptr, &funcAttribute);
658 
659     napi_value funcKey = nullptr;
660     const char* funcKeyStr = "func";
661     napi_create_string_latin1(env, funcKeyStr, strlen(funcKeyStr), &funcKey);
662     napi_status status = napi_set_property(env, result, funcKey, funcAttribute);
663     ASSERT_EQ(status, napi_status::napi_ok);
664 
665     bool isFuncExist = false;
666     ASSERT_CHECK_CALL(napi_has_property(env, result, funcKey, &isFuncExist));
667     ASSERT_TRUE(isFuncExist);
668 
669     napi_value propFuncValue = nullptr;
670     napi_get_property_names(env, result, &propFuncValue);
671     uint32_t arrayLength = 0;
672     napi_get_array_length(env, propFuncValue, &arrayLength);
673     ASSERT_EQ(arrayLength, static_cast<uint32_t>(1));
674 
675     bool isFuncDelete = false;
676     ASSERT_CHECK_CALL(napi_delete_property(env, result, funcKey, &isFuncDelete));
677     ASSERT_TRUE(isFuncDelete);
678 }
679 
680 /**
681  * @tc.name: FunctionTest001
682  * @tc.desc: Test function type.
683  * @tc.type: FUNC
684  */
HWTEST_F(NapiBasicTest, FunctionTest001, testing::ext::TestSize.Level1)685 HWTEST_F(NapiBasicTest, FunctionTest001, testing::ext::TestSize.Level1)
686 {
687     napi_env env = (napi_env)engine_;
688 
689     auto func = [](napi_env env, napi_callback_info info) -> napi_value {
690         napi_value thisVar;
691         napi_value* argv = nullptr;
692         size_t argc = 0;
693         void* data = nullptr;
694 
695         napi_get_cb_info(env, info, &argc, nullptr, nullptr, nullptr);
696         if (argc > 0) {
697             argv = new napi_value[argc];
698         }
699         napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
700 
701         napi_value result = nullptr;
702         napi_create_object(env, &result);
703 
704         napi_value messageKey = nullptr;
705         const char* messageKeyStr = "message";
706         napi_create_string_latin1(env, messageKeyStr, strlen(messageKeyStr), &messageKey);
707         napi_value messageValue = nullptr;
708         const char* messageValueStr = "OK";
709         napi_create_string_latin1(env, messageValueStr, strlen(messageValueStr), &messageValue);
710         napi_set_property(env, result, messageKey, messageValue);
711 
712         if (argv != nullptr) {
713             delete []argv;
714         }
715 
716         return result;
717     };
718 
719     napi_value recv = nullptr;
720     napi_value funcValue = nullptr;
721     napi_get_undefined(env, &recv);
722     ASSERT_NE(recv, nullptr);
723 
724     napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH, func, nullptr, &funcValue);
725     ASSERT_NE(funcValue, nullptr);
726 
727     napi_handle_scope parentScope = nullptr;
728     napi_open_handle_scope(env, &parentScope);
729     ASSERT_NE(parentScope, nullptr);
730 
731     napi_escapable_handle_scope childScope = nullptr;
732     napi_open_escapable_handle_scope(env, &childScope);
733     ASSERT_NE(childScope, nullptr);
734 
735     napi_value funcResultValue = nullptr;
736     napi_value newFuncResultValue = nullptr;
737     napi_call_function(env, recv, funcValue, 0, nullptr, &funcResultValue);
738     ASSERT_NE(funcResultValue, nullptr);
739 
740     napi_escape_handle(env, childScope, funcResultValue, &newFuncResultValue);
741     napi_close_escapable_handle_scope(env, childScope);
742     ASSERT_TRUE(newFuncResultValue != nullptr);
743     ASSERT_CHECK_VALUE_TYPE(env, newFuncResultValue, napi_object);
744     napi_close_handle_scope(env, parentScope);
745 }
746 
747 /**
748  * @tc.name: FunctionTest002
749  * @tc.desc: Test function type.
750  * @tc.type: FUNC
751  */
HWTEST_F(NapiBasicTest, FunctionTest002, testing::ext::TestSize.Level1)752 HWTEST_F(NapiBasicTest, FunctionTest002, testing::ext::TestSize.Level1)
753 {
754     napi_env env = reinterpret_cast<napi_env>(engine_);
755 
756     auto func = [](napi_env env, napi_callback_info info) -> napi_value {
757         return nullptr;
758     };
759     napi_value fn;
760     const char data[] = "data";
761     napi_status status = napi_create_function(nullptr, nullptr, 0, nullptr, nullptr, &fn);
762     ASSERT_EQ(status, napi_invalid_arg);
763     status = napi_create_function(env, nullptr, 0, nullptr, nullptr, &fn);
764     ASSERT_EQ(status, napi_invalid_arg);
765     status = napi_create_function(env, nullptr, 0, func, (void*)data, nullptr);
766     ASSERT_EQ(status, napi_invalid_arg);
767     status = napi_create_function(env, nullptr, 0, func, nullptr, &fn);
768     ASSERT_EQ(status, napi_ok);
769     status = napi_create_function(env, nullptr, 0, func, (void*)data, &fn);
770     ASSERT_EQ(status, napi_ok);
771 }
772 
773 /**
774  * @tc.name: FunctionTest003
775  * @tc.desc: Test function type.
776  * @tc.type: FUNC
777  */
HWTEST_F(NapiBasicTest, FunctionTest003, testing::ext::TestSize.Level1)778 HWTEST_F(NapiBasicTest, FunctionTest003, testing::ext::TestSize.Level1)
779 {
780     napi_env env = reinterpret_cast<napi_env>(engine_);
781     auto func = [](napi_env env, napi_callback_info info) -> napi_value {
782         napi_value thisVar;
783         napi_value* argv = nullptr;
784         size_t argc = 0;
785         void* innerData = nullptr;
786 
787         napi_get_cb_info(env, info, &argc, nullptr, nullptr, nullptr);
788         if (argc > 0) {
789             argv = new napi_value[argc];
790         }
791         napi_get_cb_info(env, info, &argc, argv, &thisVar, &innerData);
792         napi_value result;
793         if (argv) {
794             result = argv[0];
795             delete[] argv;
796         } else {
797             napi_get_undefined(env, &result);
798         }
799         return result;
800     };
801 
802     napi_value fn;
803     napi_value funcResultValue;
804     napi_value recv;
805     napi_value jsNumber;
806     const static char data[] = "data";
807     napi_status status = napi_create_function(env, nullptr, 0, func, (void*)data, &fn);
808     ASSERT_EQ(napi_ok, status);
809 
810     const int32_t testNumber = 1;
811     napi_create_int32(env, testNumber, &jsNumber);
812     napi_value argv[] = { jsNumber };
813     napi_get_undefined(env, &recv);
814     status = napi_call_function(env, recv, fn, 1, argv, &funcResultValue);
815     ASSERT_EQ(status, napi_ok);
816 
817     int32_t cNumber;
818     napi_get_value_int32(env, funcResultValue, &cNumber);
819     ASSERT_EQ(cNumber, testNumber);
820 
821     status = napi_call_function(env, nullptr, fn, 1, argv, &funcResultValue);
822     ASSERT_EQ(status, napi_ok);
823 
824     status = napi_call_function(env, nullptr, nullptr, 1, argv, &funcResultValue);
825     ASSERT_EQ(status, napi_invalid_arg);
826 
827     status = napi_call_function(env, nullptr, nullptr, 0, nullptr, &funcResultValue);
828     ASSERT_EQ(status, napi_invalid_arg);
829 
830     status = napi_call_function(env, nullptr, fn, 1, argv, nullptr);
831     ASSERT_EQ(status, napi_ok);
832 }
833 
TestCreateFunc(napi_env env, napi_callback_info info)834 static napi_value TestCreateFunc(napi_env env, napi_callback_info info)
835 {
836     napi_value result = nullptr;
837     napi_create_object(env, &result);
838     return result;
839 }
840 
841 /**
842  * @tc.name: FunctionTest004
843  * @tc.desc: Test the second parameter as null
844  * @tc.type: FUNC
845  */
HWTEST_F(NapiBasicTest, FunctionTest004, testing::ext::TestSize.Level1)846 HWTEST_F(NapiBasicTest, FunctionTest004, testing::ext::TestSize.Level1)
847 {
848     napi_env env = reinterpret_cast<napi_env>(engine_);
849     napi_value funcValue = nullptr;
850     napi_create_function(env, nullptr, NAPI_AUTO_LENGTH, TestCreateFunc, nullptr, &funcValue);
851     ASSERT_NE(funcValue, nullptr);
852 
853     napi_value recv = nullptr;
854     napi_get_undefined(env, &recv);
855     ASSERT_NE(recv, nullptr);
856     napi_value funcResultValue = nullptr;
857     napi_call_function(env, recv, funcValue, 0, nullptr, &funcResultValue);
858     ASSERT_NE(funcResultValue, nullptr);
859 }
860 
TestCallFunc(napi_env env, napi_callback_info info)861 static napi_value TestCallFunc(napi_env env, napi_callback_info info)
862 {
863     napi_value error = nullptr;
864     napi_throw_error(env, "500", "Common error");
865     return error;
866 }
867 
868 /**
869  * @tc.name: FunctionTest005
870  * @tc.desc: Test callfunction throw error
871  * @tc.type: FUNC
872  */
HWTEST_F(NapiBasicTest, FunctionTest005, testing::ext::TestSize.Level1)873 HWTEST_F(NapiBasicTest, FunctionTest005, testing::ext::TestSize.Level1)
874 {
875     napi_env env = reinterpret_cast<napi_env>(engine_);
876     napi_value funcValue = nullptr;
877     napi_value exception = nullptr;
878     napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH, TestCallFunc, nullptr, &funcValue);
879     ASSERT_NE(funcValue, nullptr);
880 
881     napi_value recv = nullptr;
882     napi_get_undefined(env, &recv);
883     ASSERT_NE(recv, nullptr);
884     napi_value funcResultValue = nullptr;
885     bool isExceptionPending = false;
886     napi_call_function(env, recv, funcValue, 0, nullptr, &funcResultValue);
887     napi_is_exception_pending(env, &isExceptionPending);
888     ASSERT_TRUE(isExceptionPending);
889 
890     napi_get_and_clear_last_exception(env, &exception);
891 }
892 
893 /**
894  * @tc.name: ArrayTest001
895  * @tc.desc: Test array type.
896  * @tc.type: FUNC
897  */
HWTEST_F(NapiBasicTest, ArrayTest001, testing::ext::TestSize.Level1)898 HWTEST_F(NapiBasicTest, ArrayTest001, testing::ext::TestSize.Level1) {
899     napi_env env = (napi_env) engine_;
900 
901     napi_value array = nullptr;
902     napi_create_array(env, &array);
903     ASSERT_NE(array, nullptr);
904     bool isArray = false;
905     napi_is_array(env, array, &isArray);
906     ASSERT_TRUE(isArray);
907 
908     for (size_t i = 0; i < 10; i++) {
909         napi_value num = nullptr;
910         napi_create_uint32(env, i, &num);
911         napi_set_element(env, array, i, num);
912     }
913 
914     uint32_t arrayLength = 0;
915     napi_get_array_length(env, array, &arrayLength);
916 
917     ASSERT_EQ(arrayLength, static_cast<uint32_t>(10));
918 
919     for (size_t i = 0; i < arrayLength; i++) {
920         bool hasIndex = false;
921         napi_has_element(env, array, i, &hasIndex);
922         ASSERT_TRUE(hasIndex);
923     }
924 
925     for (size_t i = 0; i < arrayLength; i++) {
926         bool isDelete = false;
927         napi_delete_element(env, array, i, &isDelete);
928         ASSERT_TRUE(isDelete);
929     }
930 }
931 
932 /**
933  * @tc.name: ArrayBufferTest001
934  * @tc.desc: Test array buffer type.
935  * @tc.type: FUNC
936  */
HWTEST_F(NapiBasicTest, ArrayBufferTest001, testing::ext::TestSize.Level1)937 HWTEST_F(NapiBasicTest, ArrayBufferTest001, testing::ext::TestSize.Level1)
938 {
939     napi_env env = (napi_env)engine_;
940 
941     napi_value arrayBuffer = nullptr;
942     void* arrayBufferPtr = nullptr;
943     size_t arrayBufferSize = 1024;
944     napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer);
945 
946     void* tmpArrayBufferPtr = nullptr;
947     size_t arrayBufferLength = 0;
948     napi_get_arraybuffer_info(env, arrayBuffer, &tmpArrayBufferPtr, &arrayBufferLength);
949 
950     ASSERT_EQ(arrayBufferPtr, tmpArrayBufferPtr);
951     ASSERT_EQ(arrayBufferSize, arrayBufferLength);
952 }
953 
954 /**
955  * @tc.name: TypedArrayTest001
956  * @tc.desc: Test typed array type.
957  * @tc.type: FUNC
958  */
HWTEST_F(NapiBasicTest, TypedArrayTest001, testing::ext::TestSize.Level1)959 HWTEST_F(NapiBasicTest, TypedArrayTest001, testing::ext::TestSize.Level1)
960 {
961     napi_env env = (napi_env)engine_;
962 
963     {
964         napi_value arrayBuffer = nullptr;
965         void* arrayBufferPtr = nullptr;
966         size_t arrayBufferSize = 1024;
967         napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer);
968 
969         void* tmpArrayBufferPtr = nullptr;
970         size_t arrayBufferLength = 0;
971         napi_get_arraybuffer_info(env, arrayBuffer, &tmpArrayBufferPtr, &arrayBufferLength);
972 
973         ASSERT_EQ(arrayBufferPtr, tmpArrayBufferPtr);
974         ASSERT_EQ(arrayBufferSize, arrayBufferLength);
975 
976         napi_value typedarray = nullptr;
977         napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &typedarray);
978         ASSERT_NE(typedarray, nullptr);
979         bool isTypedArray = false;
980         napi_is_typedarray(env, typedarray, &isTypedArray);
981         ASSERT_TRUE(isTypedArray);
982 
983         napi_typedarray_type typedarrayType;
984         size_t typedarrayLength = 0;
985         void* typedarrayBufferPtr = nullptr;
986         napi_value tmpArrayBuffer = nullptr;
987         size_t byteOffset = 0;
988 
989         napi_get_typedarray_info(env, typedarray, &typedarrayType, &typedarrayLength, &typedarrayBufferPtr,
990                                  &tmpArrayBuffer, &byteOffset);
991 
992         ASSERT_EQ(typedarrayBufferPtr, arrayBufferPtr);
993         ASSERT_EQ(arrayBufferSize, typedarrayLength);
994     }
995 }
996 
997 /**
998  * @tc.name: DataViewTest001
999  * @tc.desc: Test data view type.
1000  * @tc.type: FUNC
1001  */
HWTEST_F(NapiBasicTest, DataViewTest001, testing::ext::TestSize.Level1)1002 HWTEST_F(NapiBasicTest, DataViewTest001, testing::ext::TestSize.Level1)
1003 {
1004     napi_env env = (napi_env)engine_;
1005 
1006     napi_value arrayBuffer = nullptr;
1007     void* arrayBufferPtr = nullptr;
1008     size_t arrayBufferSize = 1024;
1009     napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer);
1010     ASSERT_NE(arrayBuffer, nullptr);
1011     ASSERT_NE(arrayBufferPtr, nullptr);
1012     bool isArrayBuffer = false;
1013     napi_is_arraybuffer(env, arrayBuffer, &isArrayBuffer);
1014     ASSERT_TRUE(isArrayBuffer);
1015 
1016     napi_value result = nullptr;
1017     napi_create_dataview(env, arrayBufferSize, arrayBuffer, 0, &result);
1018 
1019     bool isDataView = false;
1020     napi_is_dataview(env, result, &isDataView);
1021 
1022     napi_value retArrayBuffer = nullptr;
1023     void* data = nullptr;
1024     size_t byteLength = 0;
1025     size_t byteOffset = 0;
1026     napi_get_dataview_info(env, result, &byteLength, &data, &retArrayBuffer, &byteOffset);
1027 
1028     bool retIsArrayBuffer = false;
1029     napi_is_arraybuffer(env, arrayBuffer, &retIsArrayBuffer);
1030     ASSERT_TRUE(retIsArrayBuffer);
1031     ASSERT_EQ(arrayBufferPtr, data);
1032     ASSERT_EQ(arrayBufferSize, byteLength);
1033     ASSERT_EQ(static_cast<size_t>(0), byteOffset);
1034 }
1035 
1036 /**
1037  * @tc.name: PromiseTest001
1038  * @tc.desc: Test promise type.
1039  * @tc.type: FUNC
1040  */
HWTEST_F(NapiBasicTest, PromiseTest001, testing::ext::TestSize.Level1)1041 HWTEST_F(NapiBasicTest, PromiseTest001, testing::ext::TestSize.Level1)
1042 {
1043     napi_env env = (napi_env)engine_;
1044     {
1045         napi_deferred deferred = nullptr;
1046         napi_value promise = nullptr;
1047         ASSERT_CHECK_CALL(napi_create_promise(env, &deferred, &promise));
1048         ASSERT_NE(deferred, nullptr);
1049         ASSERT_NE(promise, nullptr);
1050 
1051         bool isPromise = false;
1052         ASSERT_CHECK_CALL(napi_is_promise(env, promise, &isPromise));
1053         ASSERT_TRUE(isPromise);
1054 
1055         napi_value undefined = nullptr;
1056         napi_get_undefined(env, &undefined);
1057         ASSERT_CHECK_CALL(napi_resolve_deferred(env, deferred, undefined));
1058     }
1059     {
1060         napi_deferred deferred = nullptr;
1061         napi_value promise = nullptr;
1062         ASSERT_CHECK_CALL(napi_create_promise(env, &deferred, &promise));
1063         ASSERT_NE(deferred, nullptr);
1064         ASSERT_NE(promise, nullptr);
1065 
1066         bool isPromise = false;
1067         ASSERT_CHECK_CALL(napi_is_promise(env, promise, &isPromise));
1068         ASSERT_TRUE(isPromise);
1069 
1070         napi_value undefined = nullptr;
1071         napi_get_undefined(env, &undefined);
1072         ASSERT_CHECK_CALL(napi_reject_deferred(env, deferred, undefined));
1073     }
1074     {
1075         napi_deferred deferred = nullptr;
1076         napi_value promise = nullptr;
1077         ASSERT_CHECK_CALL(napi_throw_error(env, "500", "common error"));
1078         ASSERT_NE(napi_create_promise(env, &deferred, &promise), napi_ok);
1079         ASSERT_EQ(deferred, nullptr);
1080         ASSERT_EQ(promise, nullptr);
1081         napi_value error = nullptr;
1082         napi_get_and_clear_last_exception(env, &error);
1083     }
1084 }
1085 
1086 /**
1087  * @tc.name: PromiseTest002
1088  * @tc.desc: Test promise type.
1089  * @tc.type: FUNC
1090  */
HWTEST_F(NapiBasicTest, PromiseTest002, testing::ext::TestSize.Level1)1091 HWTEST_F(NapiBasicTest, PromiseTest002, testing::ext::TestSize.Level1)
1092 {
1093     napi_env env = reinterpret_cast<napi_env>(engine_);
1094     {
1095         napi_deferred deferred = nullptr;
1096         napi_value promise = nullptr;
1097         napi_status status = napi_create_promise(nullptr, &deferred, &promise);
1098         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1099         status = napi_create_promise(env, nullptr, &promise);
1100         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1101         status = napi_create_promise(env, &deferred, nullptr);
1102         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1103     }
1104     {
1105         napi_deferred deferred = nullptr;
1106         napi_value promise = nullptr;
1107         ASSERT_CHECK_CALL(napi_create_promise(env, &deferred, &promise));
1108 
1109         bool isPromise = false;
1110         napi_status status = napi_is_promise(nullptr, promise, &isPromise);
1111         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1112         status = napi_is_promise(env, nullptr, &isPromise);
1113         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1114         status = napi_is_promise(env, promise, nullptr);
1115         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1116     }
1117     {
1118         napi_deferred deferred = nullptr;
1119         napi_value promise = nullptr;
1120         ASSERT_CHECK_CALL(napi_create_promise(env, &deferred, &promise));
1121 
1122         napi_value undefined = nullptr;
1123         napi_get_undefined(env, &undefined);
1124         napi_status status = napi_resolve_deferred(nullptr, deferred, undefined);
1125         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1126         status = napi_resolve_deferred(env, nullptr, undefined);
1127         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1128         status = napi_resolve_deferred(env, deferred, nullptr);
1129         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1130     }
1131     {
1132         napi_deferred deferred = nullptr;
1133         napi_value promise = nullptr;
1134         ASSERT_CHECK_CALL(napi_create_promise(env, &deferred, &promise));
1135 
1136         napi_value undefined = nullptr;
1137         napi_get_undefined(env, &undefined);
1138         napi_status status = napi_reject_deferred(nullptr, deferred, undefined);
1139         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1140         status = napi_reject_deferred(env, nullptr, undefined);
1141         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1142         status = napi_reject_deferred(env, deferred, nullptr);
1143         ASSERT_EQ(status, napi_status::napi_invalid_arg);
1144     }
1145 }
1146 
1147 /**
1148  * @tc.name: ErrorTest001
1149  * @tc.desc: Test error type.
1150  * @tc.type: FUNC
1151  */
HWTEST_F(NapiBasicTest, ErrorTest001, testing::ext::TestSize.Level1)1152 HWTEST_F(NapiBasicTest, ErrorTest001, testing::ext::TestSize.Level1)
1153 {
1154     napi_env env = (napi_env)engine_;
1155     bool isExceptionPending = false;
1156     napi_value exception = nullptr;
1157 
1158     {
1159         napi_value code = nullptr;
1160         napi_value message = nullptr;
1161 
1162         napi_create_string_latin1(env, "500", NAPI_AUTO_LENGTH, &code);
1163         napi_create_string_latin1(env, "common error", NAPI_AUTO_LENGTH, &message);
1164 
1165         napi_value error = nullptr;
1166         napi_create_error(env, code, message, &error);
1167         ASSERT_TRUE(error != nullptr);
1168         bool isError = false;
1169         napi_is_error(env, error, &isError);
1170         ASSERT_TRUE(isError);
1171         napi_throw(env, error);
1172         napi_is_exception_pending(env, &isExceptionPending);
1173         ASSERT_TRUE(isExceptionPending);
1174         napi_get_and_clear_last_exception(env, &exception);
1175         napi_is_exception_pending(env, &isExceptionPending);
1176         ASSERT_FALSE(isExceptionPending);
1177     }
1178 
1179     {
1180         napi_value code = nullptr;
1181         napi_value message = nullptr;
1182         napi_create_string_latin1(env, "500", NAPI_AUTO_LENGTH, &code);
1183         napi_create_string_latin1(env, "range error", NAPI_AUTO_LENGTH, &message);
1184         napi_value error = nullptr;
1185         napi_create_range_error(env, code, message, &error);
1186         ASSERT_TRUE(error != nullptr);
1187         bool isError = false;
1188         napi_is_error(env, error, &isError);
1189         ASSERT_TRUE(isError);
1190 
1191         napi_throw_range_error(env, "500", "Range error");
1192         napi_is_exception_pending(env, &isExceptionPending);
1193         ASSERT_TRUE(isExceptionPending);
1194         napi_get_and_clear_last_exception(env, &exception);
1195         napi_is_exception_pending(env, &isExceptionPending);
1196         ASSERT_FALSE(isExceptionPending);
1197     }
1198 
1199     {
1200         napi_value code = nullptr;
1201         napi_value message = nullptr;
1202         napi_create_string_latin1(env, "500", NAPI_AUTO_LENGTH, &code);
1203         napi_create_string_latin1(env, "type error", NAPI_AUTO_LENGTH, &message);
1204         napi_value error = nullptr;
1205         napi_create_type_error(env, code, message, &error);
1206         ASSERT_TRUE(error != nullptr);
1207         bool isError = false;
1208         napi_is_error(env, error, &isError);
1209         ASSERT_TRUE(isError);
1210 
1211         napi_throw_type_error(env, "500", "Type error");
1212         napi_is_exception_pending(env, &isExceptionPending);
1213         ASSERT_TRUE(isExceptionPending);
1214         napi_get_and_clear_last_exception(env, &exception);
1215         napi_is_exception_pending(env, &isExceptionPending);
1216         ASSERT_FALSE(isExceptionPending);
1217     }
1218 
1219     napi_throw_error(env, "500", "Common error");
1220     napi_is_exception_pending(env, &isExceptionPending);
1221     ASSERT_TRUE(isExceptionPending);
1222     napi_get_and_clear_last_exception(env, &exception);
1223     napi_is_exception_pending(env, &isExceptionPending);
1224     ASSERT_FALSE(isExceptionPending);
1225 }
1226 
1227 /**
1228  * @tc.name: ReferenceTest001
1229  * @tc.desc: Test reference type.
1230  * @tc.type: FUNC
1231  */
HWTEST_F(NapiBasicTest, ReferenceTest001, testing::ext::TestSize.Level1)1232 HWTEST_F(NapiBasicTest, ReferenceTest001, testing::ext::TestSize.Level1)
1233 {
1234     napi_env env = (napi_env)engine_;
1235 
1236     napi_value result = nullptr;
1237     napi_ref resultRef = nullptr;
1238 
1239     napi_create_object(env, &result);
1240     napi_create_reference(env, result, 1, &resultRef);
1241 
1242     uint32_t resultRefCount = 0;
1243 
1244     napi_reference_ref(env, resultRef, &resultRefCount);
1245     ASSERT_EQ(resultRefCount, static_cast<uint32_t>(2));
1246 
1247     napi_reference_unref(env, resultRef, &resultRefCount);
1248     ASSERT_EQ(resultRefCount, static_cast<uint32_t>(1));
1249 
1250     napi_value refValue = nullptr;
1251     napi_get_reference_value(env, resultRef, &refValue);
1252 
1253     ASSERT_NE(refValue, nullptr);
1254 
1255     napi_delete_reference(env, resultRef);
1256 }
1257 
1258 /**
1259  * @tc.name: CustomClassTest001
1260  * @tc.desc: Test define class.
1261  * @tc.type: FUNC
1262  */
HWTEST_F(NapiBasicTest, CustomClassTest001, testing::ext::TestSize.Level1)1263 HWTEST_F(NapiBasicTest, CustomClassTest001, testing::ext::TestSize.Level1)
1264 {
1265     napi_env env = (napi_env)engine_;
1266 
1267     auto constructor = [](napi_env env, napi_callback_info info) -> napi_value {
1268         napi_value thisVar = nullptr;
1269         napi_value* argv = nullptr;
1270         size_t argc = 0;
1271         void* data = nullptr;
1272         napi_value constructor = nullptr;
1273         napi_get_cb_info(env, info, &argc, nullptr, nullptr, nullptr);
1274         if (argc > 0) {
1275             argv = new napi_value[argc];
1276         }
1277         napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
1278         napi_get_new_target(env, info, &constructor);
1279         if (constructor == nullptr) {
1280             napi_throw_error(env, nullptr, "is not new instance");
1281         }
1282         if (argv != nullptr) {
1283             delete []argv;
1284         }
1285         return thisVar;
1286     };
1287 
1288     napi_value ln2 = nullptr;
1289     napi_value e = nullptr;
1290 
1291     napi_create_double(env, 2.718281828459045, &e);
1292     napi_create_double(env, 0.6931471805599453, &ln2);
1293 
1294     napi_property_descriptor desc[] = {
1295         DECLARE_NAPI_FUNCTION("add", [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; }),
1296         DECLARE_NAPI_FUNCTION("sub", [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; }),
1297         DECLARE_NAPI_FUNCTION("mul", [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; }),
1298         DECLARE_NAPI_FUNCTION("div", [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; }),
1299         DECLARE_NAPI_STATIC_FUNCTION("getTime",
1300                                      [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; }),
1301         DECLARE_NAPI_GETTER_SETTER(
1302             "pi", [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; },
1303             [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; }),
1304 
1305     };
1306 
1307     napi_value customClass = nullptr;
1308 
1309     ASSERT_CHECK_CALL(napi_define_class(env, "CustomClass", NAPI_AUTO_LENGTH, constructor, nullptr,
1310                                         sizeof(desc) / sizeof(desc[0]), desc, &customClass));
1311     ASSERT_CHECK_VALUE_TYPE(env, customClass, napi_function);
1312     napi_value customClassPrototype = nullptr;
1313     napi_get_prototype(env, customClass, &customClassPrototype);
1314     ASSERT_CHECK_VALUE_TYPE(env, customClassPrototype, napi_function);
1315 
1316     napi_value customInstance = nullptr;
1317     ASSERT_CHECK_CALL(napi_new_instance(env, customClass, 0, nullptr, &customInstance));
1318 
1319     bool isInstanceOf = false;
1320     ASSERT_CHECK_CALL(napi_instanceof(env, customInstance, customClass, &isInstanceOf));
1321     ASSERT_TRUE(isInstanceOf);
1322 }
1323 
1324 /**
1325  * @tc.name: CreateMap001
1326  * @tc.desc: Test napi_create_map.
1327  * @tc.type: FUNC
1328  */
HWTEST_F(NapiBasicTest, CreateMap001, testing::ext::TestSize.Level1)1329 HWTEST_F(NapiBasicTest, CreateMap001, testing::ext::TestSize.Level1)
1330 {
1331     ASSERT_NE(engine_, nullptr);
1332     napi_env env = reinterpret_cast<napi_env>(engine_);
1333     napi_status res = napi_ok;
1334 
1335     res = napi_create_map(env, nullptr);
1336     ASSERT_EQ(res, napi_invalid_arg);
1337 
1338     napi_value result = nullptr;
1339     ASSERT_CHECK_CALL(napi_create_map(env, &result));
1340 
1341     bool isMap = false;
1342     ASSERT_CHECK_CALL(napi_is_map(env, result, &isMap));
1343     ASSERT_EQ(isMap, true);
1344 }
1345 
1346 /**
1347  * @tc.name: CreateMap002
1348  * @tc.desc: Test napi_create_map.
1349  * @tc.type: FUNC
1350  */
HWTEST_F(NapiBasicTest, CreateMap002, testing::ext::TestSize.Level1)1351 HWTEST_F(NapiBasicTest, CreateMap002, testing::ext::TestSize.Level1)
1352 {
1353     ASSERT_NE(engine_, nullptr);
1354     napi_env env = reinterpret_cast<napi_env>(engine_);
1355 
1356     napi_value result = nullptr;
1357     ASSERT_CHECK_CALL(napi_create_map(env, &result));
1358 
1359     uint32_t length = 0;
1360     napi_value value = nullptr;
1361     bool hasKey = false;
1362 
1363     napi_value key = nullptr;
1364     ASSERT_CHECK_CALL(napi_create_string_utf8(env, "null", NAPI_AUTO_LENGTH, &key));
1365     napi_value null = nullptr;
1366     ASSERT_CHECK_CALL(napi_get_null(env, &null));
1367     napi_value undefined = nullptr;
1368     ASSERT_CHECK_CALL(napi_get_undefined(env, &undefined));
1369 
1370     ASSERT_CHECK_CALL(napi_map_set_property(env, result, key, null));
1371     ASSERT_CHECK_CALL(napi_map_get_size(env, result, &length));
1372     ASSERT_EQ(length, 1);
1373     ASSERT_CHECK_CALL(napi_map_has_property(env, result, key, &hasKey));
1374     ASSERT_TRUE(hasKey);
1375     ASSERT_CHECK_CALL(napi_map_get_property(env, result, key, &value));
1376     ASSERT_CHECK_VALUE_TYPE(env, value, napi_null);
1377 
1378     ASSERT_CHECK_CALL(napi_map_delete_property(env, result, key));
1379     ASSERT_CHECK_CALL(napi_map_get_size(env, result, &length));
1380     ASSERT_EQ(length, 0);
1381     ASSERT_CHECK_CALL(napi_map_has_property(env, result, key, &hasKey));
1382     ASSERT_FALSE(hasKey);
1383     ASSERT_CHECK_CALL(napi_map_get_property(env, result, key, &value));
1384     ASSERT_CHECK_VALUE_TYPE(env, value, napi_undefined);
1385 }
1386 
1387 /**
1388  * @tc.name: CreateMap003
1389  * @tc.desc: Test napi_create_map.
1390  * @tc.type: FUNC
1391  */
HWTEST_F(NapiBasicTest, CreateMap003, testing::ext::TestSize.Level1)1392 HWTEST_F(NapiBasicTest, CreateMap003, testing::ext::TestSize.Level1)
1393 {
1394     ASSERT_NE(engine_, nullptr);
1395     napi_env env = reinterpret_cast<napi_env>(engine_);
1396 
1397     napi_value result = nullptr;
1398     ASSERT_CHECK_CALL(napi_create_map(env, &result));
1399 
1400     uint32_t length = 0;
1401     napi_value value = nullptr;
1402     bool hasKey = false;
1403 
1404     const char* key = "null";
1405     napi_value null = nullptr;
1406     ASSERT_CHECK_CALL(napi_get_null(env, &null));
1407     napi_value undefined = nullptr;
1408     ASSERT_CHECK_CALL(napi_get_undefined(env, &undefined));
1409 
1410     ASSERT_CHECK_CALL(napi_map_set_named_property(env, result, key, null));
1411     ASSERT_CHECK_CALL(napi_map_get_size(env, result, &length));
1412     ASSERT_EQ(length, 1);
1413     ASSERT_CHECK_CALL(napi_map_has_named_property(env, result, key, &hasKey));
1414     ASSERT_TRUE(hasKey);
1415     ASSERT_CHECK_CALL(napi_map_get_named_property(env, result, key, &value));
1416     ASSERT_CHECK_VALUE_TYPE(env, value, napi_null);
1417 
1418     ASSERT_CHECK_CALL(napi_map_clear(env, result));
1419     ASSERT_CHECK_CALL(napi_map_get_size(env, result, &length));
1420     ASSERT_EQ(length, 0);
1421     ASSERT_CHECK_CALL(napi_map_has_named_property(env, result, key, &hasKey));
1422     ASSERT_FALSE(hasKey);
1423     ASSERT_CHECK_CALL(napi_map_get_named_property(env, result, key, &value));
1424     ASSERT_CHECK_VALUE_TYPE(env, value, napi_undefined);
1425 
1426     napi_value object = nullptr;
1427     ASSERT_CHECK_CALL(napi_create_object(env, &object));
1428     ASSERT_CHECK_CALL(napi_map_set_named_property(env, result, key, object));
1429     ASSERT_CHECK_CALL(napi_map_get_named_property(env, result, key, &value));
1430     ASSERT_CHECK_VALUE_TYPE(env, value, napi_object);
1431 }
1432 
1433 /**
1434  * @tc.name: CreateMap004
1435  * @tc.desc: Test napi_create_map.
1436  * @tc.type: FUNC
1437  */
HWTEST_F(NapiBasicTest, CreateMap004, testing::ext::TestSize.Level1)1438 HWTEST_F(NapiBasicTest, CreateMap004, testing::ext::TestSize.Level1)
1439 {
1440     ASSERT_NE(engine_, nullptr);
1441     napi_env env = reinterpret_cast<napi_env>(engine_);
1442 
1443     napi_value map = nullptr;
1444     ASSERT_CHECK_CALL(napi_create_map(env, &map));
1445 
1446     napi_value zero = nullptr;
1447     ASSERT_CHECK_CALL(napi_create_int32(env, 0, &zero));
1448     napi_value one = nullptr;
1449     ASSERT_CHECK_CALL(napi_create_int32(env, 1, &one));
1450 
1451     ASSERT_CHECK_CALL(napi_map_set_property(env, map, zero, one));
1452 
1453     napi_value entries;
1454     ASSERT_CHECK_CALL(napi_map_get_entries(env, map, &entries));
1455 
1456     napi_value entries0;
1457     ASSERT_CHECK_CALL(napi_map_iterator_get_next(env, entries, &entries0));
1458     napi_value entries0Value = nullptr;
1459     ASSERT_CHECK_CALL(napi_get_named_property(env, entries0, "value", &entries0Value));
1460     napi_value key = nullptr;
1461     ASSERT_CHECK_CALL(napi_get_element(env, entries0Value, 0, &key));
1462     int32_t nativeKey;
1463     ASSERT_CHECK_CALL(napi_get_value_int32(env, key, &nativeKey));
1464     ASSERT_EQ(nativeKey, 0);
1465     napi_value value = nullptr;
1466     ASSERT_CHECK_CALL(napi_get_element(env, entries0Value, 1, &value));
1467     int32_t nativeValue;
1468     ASSERT_CHECK_CALL(napi_get_value_int32(env, value, &nativeValue));
1469     ASSERT_EQ(nativeValue, 1);
1470 
1471     napi_value end;
1472     ASSERT_CHECK_CALL(napi_map_iterator_get_next(env, entries, &end));
1473     napi_value done = nullptr;
1474     ASSERT_CHECK_CALL(napi_get_named_property(env, end, "done", &done));
1475     bool isDone;
1476     ASSERT_CHECK_CALL(napi_get_value_bool(env, done, &isDone));
1477     ASSERT_TRUE(isDone);
1478 }
1479 
1480 /**
1481  * @tc.name: CreateMap005
1482  * @tc.desc: Test napi_create_map.
1483  * @tc.type: FUNC
1484  */
HWTEST_F(NapiBasicTest, CreateMap005, testing::ext::TestSize.Level1)1485 HWTEST_F(NapiBasicTest, CreateMap005, testing::ext::TestSize.Level1)
1486 {
1487     ASSERT_NE(engine_, nullptr);
1488     napi_env env = reinterpret_cast<napi_env>(engine_);
1489 
1490     napi_value map = nullptr;
1491     ASSERT_CHECK_CALL(napi_create_map(env, &map));
1492 
1493     napi_value zero = nullptr;
1494     ASSERT_CHECK_CALL(napi_create_int32(env, 0, &zero));
1495     napi_value one = nullptr;
1496     ASSERT_CHECK_CALL(napi_create_int32(env, 1, &one));
1497 
1498     ASSERT_CHECK_CALL(napi_map_set_property(env, map, zero, one));
1499 
1500     napi_value keys;
1501     ASSERT_CHECK_CALL(napi_map_get_keys(env, map, &keys));
1502 
1503     napi_value keys0;
1504     ASSERT_CHECK_CALL(napi_map_iterator_get_next(env, keys, &keys0));
1505     napi_value key = nullptr;
1506     ASSERT_CHECK_CALL(napi_get_named_property(env, keys0, "value", &key));
1507     int32_t nativeKey;
1508     ASSERT_CHECK_CALL(napi_get_value_int32(env, key, &nativeKey));
1509     ASSERT_EQ(nativeKey, 0);
1510 
1511     napi_value end;
1512     ASSERT_CHECK_CALL(napi_map_iterator_get_next(env, keys, &end));
1513     napi_value done = nullptr;
1514     ASSERT_CHECK_CALL(napi_get_named_property(env, end, "done", &done));
1515     bool isDone;
1516     ASSERT_CHECK_CALL(napi_get_value_bool(env, done, &isDone));
1517     ASSERT_TRUE(isDone);
1518 }
1519 
1520 /**
1521  * @tc.name: CreateMap006
1522  * @tc.desc: Test napi_create_map.
1523  * @tc.type: FUNC
1524  */
HWTEST_F(NapiBasicTest, CreateMap006, testing::ext::TestSize.Level1)1525 HWTEST_F(NapiBasicTest, CreateMap006, testing::ext::TestSize.Level1)
1526 {
1527     ASSERT_NE(engine_, nullptr);
1528     napi_env env = reinterpret_cast<napi_env>(engine_);
1529 
1530     napi_value map = nullptr;
1531     ASSERT_CHECK_CALL(napi_create_map(env, &map));
1532 
1533     napi_value zero = nullptr;
1534     ASSERT_CHECK_CALL(napi_create_int32(env, 0, &zero));
1535     napi_value one = nullptr;
1536     ASSERT_CHECK_CALL(napi_create_int32(env, 1, &one));
1537 
1538     ASSERT_CHECK_CALL(napi_map_set_property(env, map, zero, one));
1539 
1540     napi_value values;
1541     ASSERT_CHECK_CALL(napi_map_get_values(env, map, &values));
1542 
1543     napi_value values0;
1544     ASSERT_CHECK_CALL(napi_map_iterator_get_next(env, values, &values0));
1545     napi_value value = nullptr;
1546     ASSERT_CHECK_CALL(napi_get_named_property(env, values0, "value", &value));
1547     int32_t nativeValue;
1548     ASSERT_CHECK_CALL(napi_get_value_int32(env, value, &nativeValue));
1549     ASSERT_EQ(nativeValue, 1);
1550 
1551     napi_value end;
1552     ASSERT_CHECK_CALL(napi_map_iterator_get_next(env, values, &end));
1553     napi_value done = nullptr;
1554     ASSERT_CHECK_CALL(napi_get_named_property(env, end, "done", &done));
1555     bool isDone;
1556     ASSERT_CHECK_CALL(napi_get_value_bool(env, done, &isDone));
1557     ASSERT_TRUE(isDone);
1558 }
1559 
1560 /**
1561  * @tc.name: AsyncWorkTest001
1562  * @tc.desc: Test async work.
1563  * @tc.type: FUNC
1564  */
HWTEST_F(NapiBasicTest, AsyncWorkTest001, testing::ext::TestSize.Level1)1565 HWTEST_F(NapiBasicTest, AsyncWorkTest001, testing::ext::TestSize.Level1)
1566 {
1567     struct AsyncWorkContext {
1568         napi_async_work work = nullptr;
1569     };
1570     napi_env env = (napi_env)engine_;
1571     {
1572         auto asyncWorkContext = new AsyncWorkContext();
1573         napi_value resourceName = nullptr;
1574         napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
1575         ASSERT_CHECK_CALL(napi_create_async_work(
1576             env, nullptr, resourceName, [](napi_env value, void* data) {},
1577             [](napi_env env, napi_status status, void* data) {
1578                 AsyncWorkContext* asyncWorkContext = (AsyncWorkContext*)data;
1579                 ASSERT_CHECK_CALL(napi_delete_async_work(env, asyncWorkContext->work));
1580                 delete asyncWorkContext;
1581                 STOP_EVENT_LOOP(env);
1582             },
1583             asyncWorkContext, &asyncWorkContext->work));
1584         ASSERT_CHECK_CALL(napi_queue_async_work(env, asyncWorkContext->work));
1585         RUN_EVENT_LOOP(env);
1586     }
1587     {
1588         auto asyncWorkContext = new AsyncWorkContext();
1589         napi_value resourceName = nullptr;
1590         napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
1591         napi_create_async_work(
1592             env, nullptr, resourceName, [](napi_env value, void* data) {},
1593             [](napi_env env, napi_status status, void* data) {
1594                 AsyncWorkContext* asyncWorkContext = (AsyncWorkContext*)data;
1595                 ASSERT_EQ(status, napi_status::napi_cancelled);
1596                 napi_delete_async_work(env, asyncWorkContext->work);
1597                 delete asyncWorkContext;
1598                 STOP_EVENT_LOOP(env);
1599             },
1600             asyncWorkContext, &asyncWorkContext->work);
1601         napi_queue_async_work(env, asyncWorkContext->work);
1602         ASSERT_CHECK_CALL(napi_cancel_async_work(env, asyncWorkContext->work));
1603         RUN_EVENT_LOOP(env);
1604     }
1605 }
1606 
1607 /**
1608  * @tc.name: AsyncWorkTest003
1609  * @tc.desc: Test async work.
1610  * @tc.type: FUNC
1611  */
HWTEST_F(NapiBasicTest, AsyncWorkTest003, testing::ext::TestSize.Level1)1612 HWTEST_F(NapiBasicTest, AsyncWorkTest003, testing::ext::TestSize.Level1)
1613 {
1614     struct AsyncWorkContext {
1615         napi_async_work work = nullptr;
1616     };
1617     napi_env env = reinterpret_cast<napi_env>(engine_);
1618     std::unique_ptr<AsyncWorkContext> asyncWorkContext = std::make_unique<AsyncWorkContext>();
1619     napi_value resourceName = nullptr;
1620     napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
1621     napi_status status = napi_create_async_work(
1622         env, nullptr, nullptr, [](napi_env env, void* data) {},
1623         [](napi_env env, napi_status status, void* data) {},
1624         asyncWorkContext.get(), &asyncWorkContext->work);
1625     ASSERT_EQ(status, napi_invalid_arg);
1626 
1627     status = napi_create_async_work(
1628         env, nullptr, resourceName, nullptr,
1629         [](napi_env env, napi_status status, void* data) {},
1630         asyncWorkContext.get(), &asyncWorkContext->work);
1631     ASSERT_EQ(status, napi_invalid_arg);
1632 
1633     status = napi_create_async_work(
1634         env, nullptr, resourceName, [](napi_env env, void* data) {},
1635         nullptr,
1636         asyncWorkContext.get(), &asyncWorkContext->work);
1637     ASSERT_EQ(status, napi_invalid_arg);
1638 
1639     status = napi_create_async_work(
1640         env, nullptr, resourceName, [](napi_env env, void* data) {},
1641         [](napi_env env, napi_status status, void* data) {},
1642         nullptr, &asyncWorkContext->work);
1643     ASSERT_EQ(status, napi_ok);
1644 
1645     status = napi_create_async_work(
1646         env, nullptr, resourceName, [](napi_env env, void* data) {},
1647         [](napi_env env, napi_status status, void* data) {},
1648         asyncWorkContext.get(), nullptr);
1649     ASSERT_EQ(status, napi_invalid_arg);
1650 }
1651 
1652 /**
1653  * @tc.name: AsyncWorkTest004
1654  * @tc.desc: Test async work.
1655  * @tc.type: FUNC
1656  */
HWTEST_F(NapiBasicTest, AsyncWorkTest004, testing::ext::TestSize.Level1)1657 HWTEST_F(NapiBasicTest, AsyncWorkTest004, testing::ext::TestSize.Level1)
1658 {
1659     struct AsyncWorkContext {
1660         napi_async_work work = nullptr;
1661     };
1662     napi_env env = reinterpret_cast<napi_env>(engine_);
1663     auto asyncWorkContext = new AsyncWorkContext();
1664     napi_value resourceName = nullptr;
1665     napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
1666     napi_create_async_work(
1667         env, nullptr, resourceName, [](napi_env env, void* data) {},
1668         [](napi_env env, napi_status status, void* data) {
1669             AsyncWorkContext* asyncWorkContext = reinterpret_cast<AsyncWorkContext*>(data);
1670             ASSERT_NE(asyncWorkContext, nullptr);
1671             delete asyncWorkContext;
1672         },
1673         nullptr, &asyncWorkContext->work);
1674     napi_delete_async_work(env, asyncWorkContext->work);
1675 }
1676 
1677 /**
1678  * @tc.name: AsyncWorkTest005
1679  * @tc.desc: Test async work.
1680  * @tc.type: FUNC
1681  */
HWTEST_F(NapiBasicTest, AsyncWorkTest005, testing::ext::TestSize.Level1)1682 HWTEST_F(NapiBasicTest, AsyncWorkTest005, testing::ext::TestSize.Level1)
1683 {
1684     struct AsyncWorkContext {
1685         napi_async_work work = nullptr;
1686     };
1687     napi_env env = reinterpret_cast<napi_env>(engine_);
1688     auto asyncWorkContext = new AsyncWorkContext();
1689     napi_value resourceName = nullptr;
1690     napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
1691     napi_create_async_work(
1692         env, nullptr, resourceName, [](napi_env env, void* data) {},
1693         [](napi_env env, napi_status status, void* data) {
1694             AsyncWorkContext* asyncWorkContext = reinterpret_cast<AsyncWorkContext*>(data);
1695             ASSERT_NE(asyncWorkContext, nullptr);
1696             delete asyncWorkContext;
1697             STOP_EVENT_LOOP(env);
1698         },
1699         asyncWorkContext, &asyncWorkContext->work);
1700     napi_status status = napi_queue_async_work(env, asyncWorkContext->work);
1701     ASSERT_EQ(status, napi_ok);
1702     status = napi_queue_async_work(env, nullptr);
1703     ASSERT_EQ(status, napi_invalid_arg);
1704     RUN_EVENT_LOOP(env);
1705 }
1706 
1707 /**
1708  * @tc.name: ObjectWrapperTest001
1709  * @tc.desc: Test object wrapper.
1710  * @tc.type: FUNC
1711  */
HWTEST_F(NapiBasicTest, ObjectWrapperTest001, testing::ext::TestSize.Level1)1712 HWTEST_F(NapiBasicTest, ObjectWrapperTest001, testing::ext::TestSize.Level1)
1713 {
1714     napi_env env = (napi_env)engine_;
1715 
1716     napi_value testClass = nullptr;
1717     napi_define_class(
1718         env, "TestClass", NAPI_AUTO_LENGTH,
1719         [](napi_env env, napi_callback_info info) -> napi_value {
1720             napi_value thisVar = nullptr;
1721             napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
1722 
1723             return thisVar;
1724         },
1725         nullptr, 0, nullptr, &testClass);
1726 
1727     napi_value instanceValue = nullptr;
1728     napi_new_instance(env, testClass, 0, nullptr, &instanceValue);
1729 
1730     const char* testStr = "test";
1731     napi_wrap(
1732         env, instanceValue, (void*)testStr, [](napi_env env, void* data, void* hint) {}, nullptr, nullptr);
1733 
1734     char* tmpTestStr = nullptr;
1735     napi_unwrap(env, instanceValue, (void**)&tmpTestStr);
1736     ASSERT_STREQ(testStr, tmpTestStr);
1737 
1738     char* tmpTestStr1 = nullptr;
1739     napi_remove_wrap(env, instanceValue, (void**)&tmpTestStr1);
1740     ASSERT_STREQ(testStr, tmpTestStr1);
1741 }
1742 
1743 /**
1744  * @tc.name: StrictEqualsTest001
1745  * @tc.desc: Test date type.
1746  * @tc.type: FUNC
1747  */
HWTEST_F(NapiBasicTest, StrictEqualsTest001, testing::ext::TestSize.Level1)1748 HWTEST_F(NapiBasicTest, StrictEqualsTest001, testing::ext::TestSize.Level1)
1749 {
1750     napi_env env = (napi_env)engine_;
1751 
1752     const char* testStringStr = "test";
1753     napi_value testString = nullptr;
1754     napi_create_string_utf8(env, testStringStr, strlen(testStringStr), &testString);
1755     bool isStrictEquals = false;
1756     napi_strict_equals(env, testString, testString, &isStrictEquals);
1757     ASSERT_TRUE(isStrictEquals);
1758 
1759     napi_value testObject = nullptr;
1760     napi_create_object(env, &testObject);
1761     isStrictEquals = false;
1762     napi_strict_equals(env, testObject, testObject, &isStrictEquals);
1763     ASSERT_TRUE(isStrictEquals);
1764 }
1765 
1766 /**
1767  * @tc.name: CreateRuntimeTest001
1768  * @tc.desc: Test create runtime.
1769  * @tc.type: FUNC
1770  */
HWTEST_F(NapiBasicTest, CreateRuntimeTest001, testing::ext::TestSize.Level1)1771 HWTEST_F(NapiBasicTest, CreateRuntimeTest001, testing::ext::TestSize.Level1)
1772 {
1773     napi_env env = (napi_env)engine_;
1774 
1775     napi_env newEnv = nullptr;
1776     napi_create_runtime(env, &newEnv);
1777 }
1778 
1779 /**
1780  * @tc.name: SerializeDeSerializeTest001
1781  * @tc.desc: Test serialize & deserialize.
1782  * @tc.type: FUNC
1783  */
HWTEST_F(NapiBasicTest, SerializeDeSerializeTest001, testing::ext::TestSize.Level1)1784 HWTEST_F(NapiBasicTest, SerializeDeSerializeTest001, testing::ext::TestSize.Level1)
1785 {
1786     napi_env env = (napi_env)engine_;
1787 
1788     napi_value undefined = nullptr;
1789     napi_get_undefined(env, &undefined);
1790 
1791     napi_value num = nullptr;
1792     uint32_t value = 1000;
1793     napi_create_uint32(env, value, &num);
1794     void* data = nullptr;
1795     napi_serialize_inner(env, num, undefined, undefined, false, true, &data);
1796     ASSERT_NE(data, nullptr);
1797 
1798     napi_value result = nullptr;
1799     napi_deserialize(env, data, &result);
1800     ASSERT_CHECK_VALUE_TYPE(env, result, napi_number);
1801     napi_delete_serialization_data(env, data);
1802     int32_t resultData = 0;
1803     napi_get_value_int32(env, result, &resultData);
1804     ASSERT_EQ(resultData, 1000);
1805 }
1806 
1807 /**
1808  * @tc.name: SerializeDeSerializeTest002
1809  * @tc.desc: Test serialize & deserialize.
1810  * @tc.type: FUNC
1811  */
HWTEST_F(NapiBasicTest, SerializeDeSerializeTest002, testing::ext::TestSize.Level1)1812 HWTEST_F(NapiBasicTest, SerializeDeSerializeTest002, testing::ext::TestSize.Level1)
1813 {
1814     napi_env env = (napi_env)engine_;
1815 
1816     napi_value undefined = nullptr;
1817     napi_get_undefined(env, &undefined);
1818 
1819     napi_value num = nullptr;
1820     uint32_t value = 1000;
1821     napi_create_uint32(env, value, &num);
1822     void* data = nullptr;
1823     napi_serialize_inner(env, num, undefined, undefined, false, true, &data);
1824     ASSERT_NE(data, nullptr);
1825 
1826     napi_value result1 = nullptr;
1827     napi_deserialize(env, data, &result1);
1828     ASSERT_CHECK_VALUE_TYPE(env, result1, napi_number);
1829     int32_t resultData1 = 0;
1830     napi_get_value_int32(env, result1, &resultData1);
1831     ASSERT_EQ(resultData1, 1000);
1832 
1833     napi_value result2 = nullptr;
1834     napi_deserialize(env, data, &result2);
1835     ASSERT_CHECK_VALUE_TYPE(env, result2, napi_number);
1836     int32_t resultData2 = 0;
1837     napi_get_value_int32(env, result2, &resultData2);
1838     ASSERT_EQ(resultData2, 1000);
1839 
1840     napi_delete_serialization_data(env, data);
1841 }
1842 
1843 /**
1844  * @tc.name: SerializeDeSerializeTest003
1845  * @tc.desc: Test nativeBinding object type.
1846  * @tc.type: FUNC
1847  */
HWTEST_F(NapiBasicTest, SerializeDeSerializeTest003, testing::ext::TestSize.Level1)1848 HWTEST_F(NapiBasicTest, SerializeDeSerializeTest003, testing::ext::TestSize.Level1)
1849 {
1850     napi_env env = (napi_env)engine_;
1851     napi_value object = nullptr;
1852     napi_create_object(env, &object);
1853     napi_value hint = nullptr;
1854     napi_create_object(env, &hint);
1855     napi_value object1 = nullptr;
1856     napi_create_object(env, &object1);
1857     napi_status status = napi_coerce_to_native_binding_object(env, object,
1858         TestDetachCallback, TestAttachCallback, reinterpret_cast<void*>(object1), reinterpret_cast<void*>(hint));
1859     ASSERT_EQ(status, napi_status::napi_ok);
1860     napi_value undefined = nullptr;
1861     napi_get_undefined(env, &undefined);
1862     void* data = nullptr;
1863     napi_serialize_inner(env, object, undefined, undefined, false, true, &data);
1864     ASSERT_NE(data, nullptr);
1865 
1866     napi_value result1 = nullptr;
1867     napi_deserialize(env, data, &result1);
1868     ASSERT_CHECK_VALUE_TYPE(env, result1, napi_object);
1869     napi_value number1 = nullptr;
1870     napi_get_named_property(env, result1, "number", &number1);
1871     ASSERT_CHECK_VALUE_TYPE(env, number1, napi_number);
1872     uint32_t numData1 = 0;
1873     napi_get_value_uint32(env, number1, &numData1);
1874     ASSERT_EQ(numData1, 2000);
1875 
1876     napi_value result2 = nullptr;
1877     napi_deserialize(env, data, &result2);
1878     ASSERT_CHECK_VALUE_TYPE(env, result2, napi_object);
1879     napi_value number2 = nullptr;
1880     napi_get_named_property(env, result2, "number", &number2);
1881     ASSERT_CHECK_VALUE_TYPE(env, number2, napi_number);
1882     uint32_t numData2 = 0;
1883     napi_get_value_uint32(env, number2, &numData2);
1884     ASSERT_EQ(numData2, 2000);
1885 
1886     napi_delete_serialization_data(env, data);
1887 }
1888 
1889 /**
1890  * @tc.name: SerializeDeSerializeTest004
1891  * @tc.desc: Test nativeBinding object type.
1892  * @tc.type: FUNC
1893  */
HWTEST_F(NapiBasicTest, SerializeDeSerializeTest004, testing::ext::TestSize.Level1)1894 HWTEST_F(NapiBasicTest, SerializeDeSerializeTest004, testing::ext::TestSize.Level1)
1895 {
1896     napi_env env = (napi_env)engine_;
1897 
1898     napi_value object = nullptr;
1899     napi_create_object(env, &object);
1900     napi_value num = nullptr;
1901     uint32_t value = 1000;
1902     napi_create_uint32(env, value, &num);
1903     napi_set_named_property(env, object, "numKey", num);
1904     napi_value obj = nullptr;
1905     napi_create_object(env, &obj);
1906     napi_set_named_property(env, object, "objKey", obj);
1907 
1908     napi_value undefined = nullptr;
1909     napi_get_undefined(env, &undefined);
1910     void* data = nullptr;
1911     napi_serialize_inner(env, object, undefined, undefined, false, true, &data);
1912     ASSERT_NE(data, nullptr);
1913 
1914     napi_value result1 = nullptr;
1915     napi_deserialize(env, data, &result1);
1916     ASSERT_CHECK_VALUE_TYPE(env, result1, napi_object);
1917     napi_value obj1 = nullptr;
1918     napi_get_named_property(env, result1, "objKey", &obj1);
1919     ASSERT_CHECK_VALUE_TYPE(env, obj1, napi_object);
1920 
1921     napi_value result2 = nullptr;
1922     napi_deserialize(env, data, &result2);
1923     ASSERT_CHECK_VALUE_TYPE(env, result2, napi_object);
1924     napi_value num1 = nullptr;
1925     napi_get_named_property(env, result2, "numKey", &num1);
1926     uint32_t value1 = 0;
1927     napi_get_value_uint32(env, num1, &value1);
1928     ASSERT_EQ(value1, 1000);
1929 
1930     napi_delete_serialization_data(env, data);
1931 }
1932 
1933 /**
1934  * @tc.name: SerializeDeSerializeTest005
1935  * @tc.desc: Test serialize & deserialize.
1936  * @tc.type: FUNC
1937  */
HWTEST_F(NapiBasicTest, SerializeDeSerializeTest005, testing::ext::TestSize.Level1)1938 HWTEST_F(NapiBasicTest, SerializeDeSerializeTest005, testing::ext::TestSize.Level1)
1939 {
1940     napi_env env = (napi_env)engine_;
1941 
1942     napi_value undefined = nullptr;
1943     napi_get_undefined(env, &undefined);
1944 
1945     napi_value num = nullptr;
1946     uint32_t value = 1000;
1947     napi_create_uint32(env, value, &num);
1948     void* data = nullptr;
1949     napi_serialize(env, num, undefined, undefined, &data);
1950     ASSERT_NE(data, nullptr);
1951 
1952     napi_value result = nullptr;
1953     napi_deserialize(env, data, &result);
1954     ASSERT_CHECK_VALUE_TYPE(env, result, napi_number);
1955     napi_delete_serialization_data(env, data);
1956     int32_t resultData = 0;
1957     napi_get_value_int32(env, result, &resultData);
1958     ASSERT_EQ(resultData, 1000);
1959 }
1960 
1961 /**
1962  * @tc.name: SerializeDeSerializeTest006
1963  * @tc.desc: Test serialize & deserialize.
1964  * @tc.type: FUNC
1965  */
HWTEST_F(NapiBasicTest, SerializeDeSerializeTest006, testing::ext::TestSize.Level1)1966 HWTEST_F(NapiBasicTest, SerializeDeSerializeTest006, testing::ext::TestSize.Level1)
1967 {
1968     napi_env env = (napi_env)engine_;
1969 
1970     napi_value undefined = nullptr;
1971     napi_get_undefined(env, &undefined);
1972 
1973     napi_value num = nullptr;
1974     uint32_t value = 1000;
1975     napi_create_uint32(env, value, &num);
1976     void* data = nullptr;
1977     napi_serialize(env, num, undefined, undefined, &data);
1978     ASSERT_NE(data, nullptr);
1979 
1980     napi_value result1 = nullptr;
1981     napi_deserialize(env, data, &result1);
1982     ASSERT_CHECK_VALUE_TYPE(env, result1, napi_number);
1983     int32_t resultData1 = 0;
1984     napi_get_value_int32(env, result1, &resultData1);
1985     ASSERT_EQ(resultData1, 1000);
1986 
1987     napi_value result2 = nullptr;
1988     napi_deserialize(env, data, &result2);
1989     ASSERT_CHECK_VALUE_TYPE(env, result2, napi_number);
1990     int32_t resultData2 = 0;
1991     napi_get_value_int32(env, result2, &resultData2);
1992     ASSERT_EQ(resultData2, 1000);
1993 
1994     napi_delete_serialization_data(env, data);
1995 }
1996 
1997 /**
1998  * @tc.name: SerializeDeSerializeTest007
1999  * @tc.desc: Test nativeBinding object type.
2000  * @tc.type: FUNC
2001  */
HWTEST_F(NapiBasicTest, SerializeDeSerializeTest007, testing::ext::TestSize.Level1)2002 HWTEST_F(NapiBasicTest, SerializeDeSerializeTest007, testing::ext::TestSize.Level1)
2003 {
2004     napi_env env = (napi_env)engine_;
2005     napi_value object = nullptr;
2006     napi_create_object(env, &object);
2007     napi_value hint = nullptr;
2008     napi_create_object(env, &hint);
2009     napi_value object1 = nullptr;
2010     napi_create_object(env, &object1);
2011     napi_status status = napi_coerce_to_native_binding_object(env, object,
2012         TestDetachCallback, TestAttachCallback, reinterpret_cast<void*>(object1), reinterpret_cast<void*>(hint));
2013     ASSERT_EQ(status, napi_status::napi_ok);
2014     napi_value undefined = nullptr;
2015     napi_get_undefined(env, &undefined);
2016     void* data = nullptr;
2017     napi_serialize(env, object, undefined, undefined, &data);
2018     ASSERT_NE(data, nullptr);
2019 
2020     napi_value result1 = nullptr;
2021     napi_deserialize(env, data, &result1);
2022     ASSERT_CHECK_VALUE_TYPE(env, result1, napi_object);
2023     napi_value number1 = nullptr;
2024     napi_get_named_property(env, result1, "number", &number1);
2025     ASSERT_CHECK_VALUE_TYPE(env, number1, napi_number);
2026     uint32_t numData1 = 0;
2027     napi_get_value_uint32(env, number1, &numData1);
2028     ASSERT_EQ(numData1, 2000);
2029 
2030     napi_value result2 = nullptr;
2031     napi_deserialize(env, data, &result2);
2032     ASSERT_CHECK_VALUE_TYPE(env, result2, napi_object);
2033     napi_value number2 = nullptr;
2034     napi_get_named_property(env, result2, "number", &number2);
2035     ASSERT_CHECK_VALUE_TYPE(env, number2, napi_number);
2036     uint32_t numData2 = 0;
2037     napi_get_value_uint32(env, number2, &numData2);
2038     ASSERT_EQ(numData2, 2000);
2039 
2040     napi_delete_serialization_data(env, data);
2041 }
2042 
2043 /**
2044  * @tc.name: SerializeDeSerializeTest008
2045  * @tc.desc: Test nativeBinding object type.
2046  * @tc.type: FUNC
2047  */
HWTEST_F(NapiBasicTest, SerializeDeSerializeTest008, testing::ext::TestSize.Level1)2048 HWTEST_F(NapiBasicTest, SerializeDeSerializeTest008, testing::ext::TestSize.Level1)
2049 {
2050     napi_env env = (napi_env)engine_;
2051 
2052     napi_value object = nullptr;
2053     napi_create_object(env, &object);
2054     napi_value num = nullptr;
2055     uint32_t value = 1000;
2056     napi_create_uint32(env, value, &num);
2057     napi_set_named_property(env, object, "numKey", num);
2058     napi_value obj = nullptr;
2059     napi_create_object(env, &obj);
2060     napi_set_named_property(env, object, "objKey", obj);
2061 
2062     napi_value undefined = nullptr;
2063     napi_get_undefined(env, &undefined);
2064     void* data = nullptr;
2065     napi_serialize(env, object, undefined, undefined, &data);
2066     ASSERT_NE(data, nullptr);
2067 
2068     napi_value result1 = nullptr;
2069     napi_deserialize(env, data, &result1);
2070     ASSERT_CHECK_VALUE_TYPE(env, result1, napi_object);
2071     napi_value obj1 = nullptr;
2072     napi_get_named_property(env, result1, "objKey", &obj1);
2073     ASSERT_CHECK_VALUE_TYPE(env, obj1, napi_object);
2074 
2075     napi_value result2 = nullptr;
2076     napi_deserialize(env, data, &result2);
2077     ASSERT_CHECK_VALUE_TYPE(env, result2, napi_object);
2078     napi_value num1 = nullptr;
2079     napi_get_named_property(env, result2, "numKey", &num1);
2080     uint32_t value1 = 0;
2081     napi_get_value_uint32(env, num1, &value1);
2082     ASSERT_EQ(value1, 1000);
2083 
2084     napi_delete_serialization_data(env, data);
2085 }
2086 
2087 /**
2088  * @tc.name: IsCallableTest001
2089  * @tc.desc: Test is callable.
2090  * @tc.type: FUNC
2091  */
HWTEST_F(NapiBasicTest, IsCallableTest001, testing::ext::TestSize.Level1)2092 HWTEST_F(NapiBasicTest, IsCallableTest001, testing::ext::TestSize.Level1)
2093 {
2094     napi_env env = (napi_env)engine_;
2095 
2096     auto func = [](napi_env env, napi_callback_info info) -> napi_value {
2097         napi_value thisVar;
2098         napi_value* argv = nullptr;
2099         size_t argc = 0;
2100         void* data = nullptr;
2101 
2102         napi_get_cb_info(env, info, &argc, nullptr, nullptr, nullptr);
2103         if (argc > 0) {
2104             argv = new napi_value[argc];
2105         }
2106         napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
2107 
2108         napi_value result = nullptr;
2109         napi_create_object(env, &result);
2110 
2111         napi_value messageKey = nullptr;
2112         const char* messageKeyStr = "message";
2113         napi_create_string_latin1(env, messageKeyStr, strlen(messageKeyStr), &messageKey);
2114         napi_value messageValue = nullptr;
2115         const char* messageValueStr = "OK";
2116         napi_create_string_latin1(env, messageValueStr, strlen(messageValueStr), &messageValue);
2117         napi_set_property(env, result, messageKey, messageValue);
2118 
2119         if (argv != nullptr) {
2120             delete []argv;
2121         }
2122         return result;
2123     };
2124 
2125     napi_value funcValue = nullptr;
2126     napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH, func, nullptr, &funcValue);
2127     ASSERT_NE(funcValue, nullptr);
2128 
2129     bool result = false;
2130     napi_is_callable(env, funcValue, &result);
2131     ASSERT_TRUE(result);
2132 }
2133 
2134 /**
2135  * @tc.name: EncodeToUtf8Test001
2136  * @tc.desc: Test EncodeToUtf8 Func.
2137  * @tc.type: FUNC
2138  */
HWTEST_F(NapiBasicTest, EncodeToUtf8Test001, testing::ext::TestSize.Level1)2139 HWTEST_F(NapiBasicTest, EncodeToUtf8Test001, testing::ext::TestSize.Level1)
2140 {
2141     napi_env env = (napi_env)engine_;
2142     std::string str = "encode";
2143     napi_value testStr = nullptr;
2144     napi_create_string_utf8(env, str.c_str(), str.length(), &testStr);
2145     char* buffer = new char[str.length()];
2146     size_t bufferSize = str.length();
2147     uint32_t written = 0;
2148     int32_t nchars = 0;
2149     ASSERT_EQ(memset_s(buffer, str.length(), 0, str.length()), EOK);
2150     engine_->EncodeToUtf8(testStr, buffer, &written, bufferSize, &nchars);
2151     ASSERT_EQ(written, 6);
2152     ASSERT_EQ(nchars, 6);
2153     delete[] buffer;
2154 
2155     str = "encode\xc2\xab\xe2\x98\x80";
2156     testStr = nullptr;
2157     napi_create_string_utf8(env, str.c_str(), str.length(), &testStr);
2158     buffer = new char[str.length()];
2159     bufferSize = str.length();
2160     ASSERT_EQ(memset_s(buffer, str.length(), 0, str.length()), EOK);
2161     engine_->EncodeToUtf8(testStr, buffer, &written, bufferSize, &nchars);
2162     ASSERT_EQ(written, 11);
2163     ASSERT_EQ(nchars, 8);
2164     delete[] buffer;
2165 
2166     buffer = new char[str.length()];
2167     bufferSize = str.length();
2168     ASSERT_EQ(memset_s(buffer, str.length(), 0, str.length()), EOK);
2169     bufferSize--;
2170     engine_->EncodeToUtf8(testStr, buffer, &written, bufferSize, &nchars);
2171     ASSERT_EQ(written, 8);
2172     ASSERT_EQ(nchars, 7);
2173     delete[] buffer;
2174 
2175     buffer = new char[str.length()];
2176     bufferSize = str.length();
2177     ASSERT_EQ(memset_s(buffer, str.length(), 0, str.length()), EOK);
2178     bufferSize -= 4;
2179     engine_->EncodeToUtf8(testStr, buffer, &written, bufferSize, &nchars);
2180     ASSERT_EQ(written, 6);
2181     ASSERT_EQ(nchars, 6);
2182     delete[] buffer;
2183 
2184     str = "encode\xc2\xab\xe2\x98\x80t";
2185     testStr = nullptr;
2186     napi_create_string_utf8(env, str.c_str(), str.length(), &testStr);
2187     buffer = new char[str.length()];
2188     bufferSize = str.length();
2189     ASSERT_EQ(memset_s(buffer, str.length(), 0, str.length()), EOK);
2190     bufferSize--;
2191     engine_->EncodeToUtf8(testStr, buffer, &written, bufferSize, &nchars);
2192     ASSERT_EQ(written, 11);
2193     ASSERT_EQ(nchars, 8);
2194     delete[] buffer;
2195 
2196     str = "";
2197     testStr = nullptr;
2198     napi_create_string_utf8(env, str.c_str(), str.length(), &testStr);
2199     buffer = new char[str.length() + 1];
2200     bufferSize = str.length() + 1;
2201     ASSERT_EQ(memset_s(buffer, str.length(), 0, str.length()), EOK);
2202     engine_->EncodeToUtf8(testStr, buffer, &written, bufferSize, &nchars);
2203     ASSERT_EQ(written, 0);
2204     ASSERT_EQ(nchars, 0);
2205     delete[] buffer;
2206 }
2207 
2208 /**
2209  * @tc.name: WrapWithSizeTest001
2210  * @tc.desc: Test wrap with size.
2211  * @tc.type: FUNC
2212  */
HWTEST_F(NapiBasicTest, WrapWithSizeTest001, testing::ext::TestSize.Level1)2213 HWTEST_F(NapiBasicTest, WrapWithSizeTest001, testing::ext::TestSize.Level1)
2214 {
2215     napi_env env = (napi_env)engine_;
2216 
2217     napi_value testWrapClass = nullptr;
2218     napi_define_class(
2219         env, "TestWrapClass", NAPI_AUTO_LENGTH,
2220         [](napi_env env, napi_callback_info info) -> napi_value {
2221             napi_value thisVar = nullptr;
2222             napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
2223 
2224             return thisVar;
2225         },
2226         nullptr, 0, nullptr, &testWrapClass);
2227 
2228     napi_value instanceValue = nullptr;
2229     napi_new_instance(env, testWrapClass, 0, nullptr, &instanceValue);
2230 
2231     const char* testWrapStr = "testWrapStr";
2232     size_t size = sizeof(*testWrapStr) / sizeof(char);
2233     napi_wrap_with_size(
2234         env, instanceValue, (void*)testWrapStr, [](napi_env env, void* data, void* hint) {}, nullptr, nullptr, size);
2235 
2236     char* tempTestStr = nullptr;
2237     napi_unwrap(env, instanceValue, (void**)&tempTestStr);
2238     ASSERT_STREQ(testWrapStr, tempTestStr);
2239 
2240     char* tempTestStr1 = nullptr;
2241     napi_remove_wrap(env, instanceValue, (void**)&tempTestStr1);
2242     ASSERT_STREQ(testWrapStr, tempTestStr1);
2243 
2244 }
2245 
2246 /**
2247  * @tc.name: CreateExternalWithSizeTest001
2248  * @tc.desc: Test create external with size.
2249  * @tc.type: FUNC
2250  */
HWTEST_F(NapiBasicTest, CreateExternalWithSizeTest001, testing::ext::TestSize.Level1)2251 HWTEST_F(NapiBasicTest, CreateExternalWithSizeTest001, testing::ext::TestSize.Level1)
2252 {
2253     napi_env env = (napi_env)engine_;
2254     const char testStr[] = "test";
2255     size_t size = sizeof(testStr) / sizeof(char);
2256     napi_value external = nullptr;
2257     napi_create_external_with_size(
2258         env, (void*)testStr,
2259         [](napi_env env, void* data, void* hint) { ASSERT_STREQ((const char*)data, (const char*)hint); },
2260         (void*)testStr, &external, size);
2261 
2262     ASSERT_CHECK_VALUE_TYPE(env, external, napi_external);
2263     void* tempExternal = nullptr;
2264     napi_get_value_external(env, external, &tempExternal);
2265     ASSERT_TRUE(tempExternal);
2266     ASSERT_EQ(tempExternal, testStr);
2267 }
2268 
2269 /**
2270  * @tc.name: BigArrayTest001
2271  * @tc.desc: Test is big int64 array and big uint64 array.
2272  * @tc.type: FUNC
2273  */
HWTEST_F(NapiBasicTest, BigArrayTest001, testing::ext::TestSize.Level1)2274 HWTEST_F(NapiBasicTest, BigArrayTest001, testing::ext::TestSize.Level1) {
2275     napi_env env = (napi_env) engine_;
2276 
2277     napi_value array = nullptr;
2278     napi_create_array(env, &array);
2279     ASSERT_NE(array, nullptr);
2280     bool isArray = false;
2281     napi_is_array(env, array, &isArray);
2282     ASSERT_TRUE(isArray);
2283 
2284     bool isBigInt64Array = true;
2285     napi_is_big_int64_array(env, array, &isBigInt64Array);
2286     ASSERT_EQ(isBigInt64Array, false);
2287 
2288     bool isBigUInt64Array = true;
2289     napi_is_big_uint64_array(env, array, &isBigUInt64Array);
2290     ASSERT_EQ(isBigUInt64Array, false);
2291 }
2292 
2293 /**
2294  * @tc.name: CreateBufferTest001
2295  * @tc.desc: Test is CreateBuffer.
2296  * @tc.type: FUNC
2297  */
HWTEST_F(NapiBasicTest, CreateBufferTest001, testing::ext::TestSize.Level1)2298 HWTEST_F(NapiBasicTest, CreateBufferTest001, testing::ext::TestSize.Level1)
2299 {
2300     napi_env env = (napi_env)engine_;
2301 
2302     napi_value buffer = nullptr;
2303     void* bufferPtr = nullptr;
2304     size_t bufferSize = -1;
2305     napi_status creatresult = napi_create_buffer(env, bufferSize, &bufferPtr, &buffer);
2306 
2307     ASSERT_EQ(creatresult, napi_status::napi_invalid_arg);
2308     ASSERT_EQ(bufferPtr, nullptr);
2309 }
2310 
2311 /**
2312  * @tc.name: CreateBufferTest002
2313  * @tc.desc: Test is CreateBuffer.
2314  * @tc.type: FUNC
2315  */
HWTEST_F(NapiBasicTest, CreateBufferTest002, testing::ext::TestSize.Level1)2316 HWTEST_F(NapiBasicTest, CreateBufferTest002, testing::ext::TestSize.Level1)
2317 {
2318     napi_env env = (napi_env)engine_;
2319 
2320     napi_value buffer = nullptr;
2321     void* bufferPtr = nullptr;
2322     const char* data = nullptr;
2323     size_t bufferSize = -1;
2324     napi_status creatresult = napi_create_buffer_copy(env, bufferSize, data, &bufferPtr, &buffer);
2325 
2326     ASSERT_EQ(creatresult, napi_status::napi_invalid_arg);
2327     ASSERT_EQ(bufferPtr, nullptr);
2328 }
2329 
2330 /**
2331  * @tc.name: CreateBufferTest003
2332  * @tc.desc: Test is CreateBuffer.
2333  * @tc.type: FUNC
2334  */
HWTEST_F(NapiBasicTest, CreateBufferTest003, testing::ext::TestSize.Level1)2335 HWTEST_F(NapiBasicTest, CreateBufferTest003, testing::ext::TestSize.Level1)
2336 {
2337     napi_env env = reinterpret_cast<napi_env>(engine_);
2338     napi_value buffer = nullptr;
2339     void* bufferPtr = nullptr;
2340     size_t bufferSize = 1;
2341     napi_status creatresult = napi_create_buffer(env, bufferSize, &bufferPtr, &buffer);
2342     ASSERT_EQ(creatresult, napi_status::napi_ok);
2343     creatresult = napi_create_buffer(env, bufferSize, nullptr, &buffer);
2344     ASSERT_EQ(creatresult, napi_status::napi_invalid_arg);
2345 }
2346 
2347 /**
2348  * @tc.name: CreateBufferTest004
2349  * @tc.desc: Test is CreateBufferCopy.
2350  * @tc.type: FUNC
2351  */
HWTEST_F(NapiBasicTest, CreateBufferTest004, testing::ext::TestSize.Level1)2352 HWTEST_F(NapiBasicTest, CreateBufferTest004, testing::ext::TestSize.Level1)
2353 {
2354     napi_env env = reinterpret_cast<napi_env>(engine_);
2355 
2356     napi_value buffer = nullptr;
2357     void* bufferPtr = nullptr;
2358     const char* data = nullptr;
2359     size_t bufferSize = 1;
2360     napi_status creatresult = napi_create_buffer_copy(env, bufferSize, nullptr, &bufferPtr, &buffer);
2361     ASSERT_EQ(creatresult, napi_status::napi_invalid_arg);
2362     creatresult = napi_create_buffer_copy(env, bufferSize, data, &bufferPtr, nullptr);
2363     ASSERT_EQ(creatresult, napi_status::napi_invalid_arg);
2364 }
2365 
2366 /**
2367  * @tc.name: IsDetachedArrayBufferTest001
2368  * @tc.desc: Test is DetachedArrayBuffer.
2369  * @tc.type: FUNC
2370  */
HWTEST_F(NapiBasicTest, IsDetachedArrayBufferTest001, testing::ext::TestSize.Level1)2371 HWTEST_F(NapiBasicTest, IsDetachedArrayBufferTest001, testing::ext::TestSize.Level1)
2372 {
2373     static constexpr size_t arrayBufferSize = 1024;
2374     napi_env env = (napi_env)engine_;
2375     napi_value arrayBuffer = nullptr;
2376     void* arrayBufferPtr = nullptr;
2377     napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer);
2378 
2379     bool result = false;
2380     ASSERT_CHECK_CALL(napi_is_detached_arraybuffer(env, arrayBuffer, &result));
2381 
2382     auto out = napi_detach_arraybuffer(env, arrayBuffer);
2383     if (out == napi_ok) {
2384         arrayBufferPtr = nullptr;
2385     }
2386     ASSERT_EQ(out, napi_ok);
2387 
2388     result = false;
2389     ASSERT_CHECK_CALL(napi_is_detached_arraybuffer(env, arrayBuffer, &result));
2390     ASSERT_TRUE(result);
2391 }
2392 
2393 /**
2394  * @tc.name: FreezeObjectTest001
2395  * @tc.desc: Test is FreezeObject.
2396  * @tc.type: FUNC
2397  */
HWTEST_F(NapiBasicTest, FreezeObjectTest001, testing::ext::TestSize.Level1)2398 HWTEST_F(NapiBasicTest, FreezeObjectTest001, testing::ext::TestSize.Level1)
2399 {
2400     constexpr int dataSize = 60;
2401     napi_env env = (napi_env)engine_;
2402     napi_value object = nullptr;
2403     napi_create_object(env, &object);
2404 
2405     const char testStr[] = "1234567";
2406     napi_value strAttribute = nullptr;
2407     napi_create_string_utf8(env, testStr, strlen(testStr), &strAttribute);
2408     napi_set_named_property(env, object, "strAttribute", strAttribute);
2409 
2410     int32_t testNumber = 1;
2411     napi_value numberAttribute = nullptr;
2412     napi_create_int32(env, testNumber, &numberAttribute);
2413     napi_set_named_property(env, object, "numberAttribute", numberAttribute);
2414 
2415     ASSERT_CHECK_CALL(napi_object_freeze(env, object));
2416 
2417     int32_t testNumber2 = 0;
2418     napi_value numberAttribute2 = nullptr;
2419     napi_create_int32(env, testNumber2, &numberAttribute2);
2420     // Set property after freezed will throw 'Cannot add property in prevent extensions'.
2421     napi_status status = napi_set_named_property(env, object, "test", numberAttribute2);
2422     ASSERT_EQ(status, napi_pending_exception);
2423 
2424     napi_value ex;
2425     napi_get_and_clear_last_exception(env, &ex);
2426 
2427     napi_key_collection_mode keyMode = napi_key_own_only;
2428     napi_key_filter keyFilter = napi_key_all_properties;
2429     napi_key_conversion keyConversion = napi_key_keep_numbers;
2430     napi_value propNames = nullptr;
2431     ASSERT_CHECK_CALL(napi_get_all_property_names(env, object, keyMode, keyFilter, keyConversion, &propNames));
2432 
2433     uint32_t arrayLength = 0;
2434     ASSERT_CHECK_CALL(napi_get_array_length(env, propNames, &arrayLength));
2435     ASSERT_EQ(arrayLength, MAX_BUFFER_SIZE);
2436 
2437     char names[2][30];
2438     memset_s(names, dataSize, 0, dataSize);
2439     auto ret = memcpy_s(names[0], strlen("strAttribute"), "strAttribute", strlen("strAttribute"));
2440     ASSERT_EQ(ret, EOK);
2441     ret = memcpy_s(names[1], strlen("numberAttribute"), "numberAttribute", strlen("numberAttribute"));
2442     ASSERT_EQ(ret, EOK);
2443     for (uint32_t i = 0; i < arrayLength; i++) {
2444         bool hasElement = false;
2445         ASSERT_CHECK_CALL(napi_has_element(env, propNames, i, &hasElement));
2446 
2447         napi_value propName = nullptr;
2448         ASSERT_CHECK_CALL(napi_get_element(env, propNames, i, &propName));
2449         ASSERT_CHECK_VALUE_TYPE(env, propName, napi_string);
2450 
2451         size_t testStrLength = TEST_STR_LENGTH;
2452         char testStrInner[TEST_STR_LENGTH + 1];
2453         size_t outStrLength = 0;
2454         memset_s(testStrInner, testStrLength + 1, 0, testStrLength + 1);
2455         ASSERT_CHECK_CALL(napi_get_value_string_utf8(env, propName, testStrInner, testStrLength, &outStrLength));
2456 
2457         int ret = strcmp(testStrInner, names[i]);
2458         ASSERT_EQ(ret, 0);
2459     }
2460 }
2461 
2462 /**
2463  * @tc.name: SealObjectTest001
2464  * @tc.desc: Test is SealObject.
2465  * @tc.type: FUNC
2466  */
HWTEST_F(NapiBasicTest, SealObjectTest001, testing::ext::TestSize.Level1)2467 HWTEST_F(NapiBasicTest, SealObjectTest001, testing::ext::TestSize.Level1)
2468 {
2469     napi_env env = (napi_env)engine_;
2470     napi_value object = nullptr;
2471 
2472     napi_create_object(env, &object);
2473 
2474     const char testStr[] = "1234567";
2475     napi_value strAttribute = nullptr;
2476     napi_create_string_utf8(env, testStr, strlen(testStr), &strAttribute);
2477     napi_set_named_property(env, object, "strAttribute", strAttribute);
2478 
2479     int32_t testNumber = 1;
2480     napi_value numberAttribute = nullptr;
2481     napi_create_int32(env, testNumber, &numberAttribute);
2482     napi_set_named_property(env, object, "numberAttribute", numberAttribute);
2483 
2484     ASSERT_CHECK_CALL(napi_object_seal(env, object));
2485 
2486     bool testDeleted = false;
2487     ASSERT_CHECK_CALL(napi_delete_property(env, object, strAttribute, &testDeleted));
2488     ASSERT_TRUE(testDeleted);
2489 
2490     const char modifiedStr[] = "modified";
2491     napi_value modifiedValue = nullptr;
2492     napi_create_string_utf8(env, modifiedStr, strlen(modifiedStr), &modifiedValue);
2493     ASSERT_CHECK_CALL(napi_set_named_property(env, object, "strAttribute", modifiedValue));
2494 
2495     napi_value strAttribute2 = nullptr;
2496     napi_get_named_property(env, object, "strAttribute", &strAttribute2);
2497     char buffer[TEST_STR_LENGTH] = {0};
2498     size_t length = 0;
2499     napi_status status = napi_get_value_string_utf8(env, strAttribute2, buffer, sizeof(buffer) - 1, &length);
2500     ASSERT_EQ(status, napi_ok);
2501     ASSERT_EQ(length, strlen(modifiedStr));
2502     ASSERT_EQ(strcmp(buffer, modifiedStr), 0);
2503 
2504     napi_key_collection_mode keyMode = napi_key_own_only;
2505     napi_key_filter keyFilter = napi_key_all_properties;
2506     napi_key_conversion keyConversion = napi_key_keep_numbers;
2507     napi_value propNames = nullptr;
2508     ASSERT_CHECK_CALL(napi_get_all_property_names(env, object, keyMode, keyFilter, keyConversion, &propNames));
2509 
2510     uint32_t arrayLength = 0;
2511     ASSERT_CHECK_CALL(napi_get_array_length(env, propNames, &arrayLength));
2512     ASSERT_EQ(arrayLength, MAX_BUFFER_SIZE);
2513 
2514     char names[2][TEST_STR_LENGTH];
2515     // There are 2 elements in the string array,
2516     // so the parameter is set to TEST_STR_LENGTH * 2 to clear the entire array.
2517     memset_s(names, TEST_STR_LENGTH * 2, 0, TEST_STR_LENGTH * 2);
2518     auto ret = memcpy_s(names[0], strlen("strAttribute"), "strAttribute", strlen("strAttribute"));
2519     ASSERT_EQ(ret, EOK);
2520     ret = memcpy_s(names[1], strlen("numberAttribute"), "numberAttribute", strlen("numberAttribute"));
2521     ASSERT_EQ(ret, EOK);
2522 
2523     for (uint32_t i = 0; i < arrayLength; i++) {
2524         bool hasElement = false;
2525         ASSERT_CHECK_CALL(napi_has_element(env, propNames, i, &hasElement));
2526 
2527         napi_value propName = nullptr;
2528         ASSERT_CHECK_CALL(napi_get_element(env, propNames, i, &propName));
2529         ASSERT_CHECK_VALUE_TYPE(env, propName, napi_string);
2530 
2531         size_t testStrLength = TEST_STR_LENGTH;
2532         char testStrInner[TEST_STR_LENGTH + 1];
2533         size_t outStrLength = 0;
2534         memset_s(testStrInner, testStrLength + 1, 0, testStrLength + 1);
2535         ASSERT_CHECK_CALL(napi_get_value_string_utf8(env, propName, testStrInner, testStrLength, &outStrLength));
2536 
2537         int ret = strcmp(testStrInner, names[i]);
2538         ASSERT_EQ(ret, 0);
2539     }
2540 }
2541 
2542 /**
2543  * @tc.name: AllPropertyNamesTest001
2544  * @tc.desc: Test is AllPropertyNames.
2545  * @tc.type: FUNC
2546  */
HWTEST_F(NapiBasicTest, AllPropertyNamesTest001, testing::ext::TestSize.Level1)2547 HWTEST_F(NapiBasicTest, AllPropertyNamesTest001, testing::ext::TestSize.Level1)
2548 {
2549     napi_env env = (napi_env)engine_;
2550     napi_key_collection_mode keyMode = napi_key_own_only;
2551     napi_key_filter keyFilter = napi_key_all_properties;
2552     napi_key_conversion keyConversion = napi_key_keep_numbers;
2553     napi_value result = nullptr;
2554     napi_value propNames = nullptr;
2555 
2556     ASSERT_CHECK_CALL(napi_create_object(env, &result));
2557     ASSERT_CHECK_VALUE_TYPE(env, result, napi_object);
2558 
2559     const char testStr[] = "1234567";
2560     napi_value strAttribute = nullptr;
2561     napi_create_string_utf8(env, testStr, strlen(testStr), &strAttribute);
2562     napi_set_named_property(env, result, "strAttribute", strAttribute);
2563 
2564     int32_t testNumber = 1;
2565     napi_value numberAttribute = nullptr;
2566     napi_create_int32(env, testNumber, &numberAttribute);
2567     napi_set_named_property(env, result, "numberAttribute", numberAttribute);
2568 
2569     ASSERT_CHECK_CALL(napi_get_all_property_names(env, result, keyMode, keyFilter, keyConversion, &propNames));
2570 
2571     ASSERT_CHECK_VALUE_TYPE(env, propNames, napi_object);
2572     bool isArray = false;
2573     ASSERT_CHECK_CALL(napi_is_array(env, propNames, &isArray));
2574     ASSERT_TRUE(isArray);
2575     uint32_t arrayLength = 0;
2576     ASSERT_CHECK_CALL(napi_get_array_length(env, propNames, &arrayLength));
2577     ASSERT_EQ(arrayLength, MAX_BUFFER_SIZE);
2578 
2579     char names[2][TEST_STR_LENGTH];
2580     // There are 2 elements in the string array,
2581     // so the parameter is set to TEST_STR_LENGTH * 2 to clear the entire array.
2582     memset_s(names, TEST_STR_LENGTH * 2, 0, TEST_STR_LENGTH * 2);
2583     auto ret = memcpy_s(names[0], strlen("strAttribute"), "strAttribute", strlen("strAttribute"));
2584     ASSERT_EQ(ret, EOK);
2585     ret = memcpy_s(names[1], strlen("numberAttribute"), "numberAttribute", strlen("numberAttribute"));
2586     ASSERT_EQ(ret, EOK);
2587 
2588     for (uint32_t i = 0; i < arrayLength; i++) {
2589         bool hasElement = false;
2590         ASSERT_CHECK_CALL(napi_has_element(env, propNames, i, &hasElement));
2591 
2592         napi_value propName = nullptr;
2593         ASSERT_CHECK_CALL(napi_get_element(env, propNames, i, &propName));
2594         ASSERT_CHECK_VALUE_TYPE(env, propName, napi_string);
2595 
2596         size_t testStrLength = TEST_STR_LENGTH;
2597         char testStrInner[TEST_STR_LENGTH + 1];
2598         size_t outStrLength = 0;
2599         memset_s(testStrInner, testStrLength + 1, 0, testStrLength + 1);
2600         ASSERT_CHECK_CALL(napi_get_value_string_utf8(env, propName, testStrInner, testStrLength, &outStrLength));
2601 
2602         int ret = strcmp(testStrInner, names[i]);
2603         ASSERT_EQ(ret, 0);
2604     }
2605 }
2606 
2607 /**
2608  * @tc.name: AllPropertyNamesTest002
2609  * @tc.desc: Test is AllPropertyNames.
2610  * @tc.type: FUNC
2611  */
HWTEST_F(NapiBasicTest, AllPropertyNamesTest002, testing::ext::TestSize.Level1)2612 HWTEST_F(NapiBasicTest, AllPropertyNamesTest002, testing::ext::TestSize.Level1)
2613 {
2614     napi_env env = (napi_env)engine_;
2615     napi_key_collection_mode keyMode = napi_key_own_only;
2616     napi_key_filter keyFilter = napi_key_writable;
2617     napi_key_conversion keyConversion = napi_key_keep_numbers;
2618     napi_value result = nullptr;
2619     napi_value propNames = nullptr;
2620     // Create napi_values for 123, 456 and 789
2621     napi_value unenumerAble, writAble, configurAble;
2622     napi_create_int32(env, 123, &unenumerAble);
2623     napi_create_int32(env, 456, &writAble);
2624     napi_create_int32(env, 789, &configurAble);
2625 
2626     napi_property_descriptor descriptors[] = {
2627         {"unenumerable",
2628          nullptr, nullptr, nullptr, nullptr, unenumerAble,
2629          napi_default_method, nullptr},
2630         {"writable",
2631          nullptr, nullptr, nullptr, nullptr, writAble,
2632          static_cast<napi_property_attributes>(napi_enumerable | napi_writable), nullptr},
2633         {"configurable",
2634          nullptr, nullptr, nullptr, nullptr, configurAble,
2635          static_cast<napi_property_attributes>(napi_enumerable | napi_configurable), nullptr}
2636     };
2637 
2638     ASSERT_CHECK_CALL(napi_create_object(env, &result));
2639     ASSERT_CHECK_VALUE_TYPE(env, result, napi_object);
2640     ASSERT_CHECK_CALL(napi_define_properties(env, result, sizeof(descriptors) / sizeof(descriptors[0]), descriptors));
2641 
2642     const char testStr[] = "1234567";
2643     napi_value strAttribute = nullptr;
2644     napi_create_string_utf8(env, testStr, strlen(testStr), &strAttribute);
2645     napi_set_named_property(env, result, "strAttribute", strAttribute);
2646 
2647     int32_t testNumber = 1;
2648     napi_value numberAttribute = nullptr;
2649     napi_create_int32(env, testNumber, &numberAttribute);
2650     napi_set_named_property(env, result, "numberAttribute", numberAttribute);
2651 
2652     ASSERT_CHECK_CALL(napi_get_all_property_names(env, result, keyMode, keyFilter, keyConversion, &propNames));
2653 
2654     ASSERT_CHECK_VALUE_TYPE(env, propNames, napi_object);
2655     bool isArray = false;
2656     ASSERT_CHECK_CALL(napi_is_array(env, propNames, &isArray));
2657     ASSERT_TRUE(isArray);
2658     uint32_t arrayLength = 0;
2659     ASSERT_CHECK_CALL(napi_get_array_length(env, propNames, &arrayLength));
2660     ASSERT_EQ(arrayLength, 4); // 4 means array length.
2661 
2662     char names[4][TEST_STR_LENGTH];
2663     // There are 4 elements in the string array,
2664     // so the parameter is set to TEST_STR_LENGTH * 4 to clear the entire array.
2665     memset_s(names, TEST_STR_LENGTH * 4, 0, TEST_STR_LENGTH * 4);
2666     auto ret = memcpy_s(names[0], strlen("unenumerable"), "unenumerable", strlen("unenumerable"));
2667     ASSERT_EQ(ret, EOK);
2668     ret = memcpy_s(names[1], strlen("writable"), "writable", strlen("writable"));
2669     ASSERT_EQ(ret, EOK);
2670     ret = memcpy_s(names[2], strlen("strAttribute"), "strAttribute", strlen("strAttribute"));
2671     ASSERT_EQ(ret, EOK);
2672     ret = memcpy_s(names[3], strlen("numberAttribute"), "numberAttribute", strlen("numberAttribute"));
2673     ASSERT_EQ(ret, EOK);
2674 
2675     for (uint32_t i = 0; i < arrayLength; i++) {
2676         bool hasElement = false;
2677         ASSERT_CHECK_CALL(napi_has_element(env, propNames, i, &hasElement));
2678 
2679         napi_value propName = nullptr;
2680         ASSERT_CHECK_CALL(napi_get_element(env, propNames, i, &propName));
2681         ASSERT_CHECK_VALUE_TYPE(env, propName, napi_string);
2682 
2683         size_t testStrLength = TEST_STR_LENGTH;
2684         char testStrInner[TEST_STR_LENGTH + 1];
2685         size_t outStrLength = 0;
2686         memset_s(testStrInner, testStrLength + 1, 0, testStrLength + 1);
2687         ASSERT_CHECK_CALL(napi_get_value_string_utf8(env, propName, testStrInner, testStrLength, &outStrLength));
2688 
2689         int ret = strcmp(testStrInner, names[i]);
2690         ASSERT_EQ(ret, 0);
2691     }
2692 }
2693 
2694 /**
2695  * @tc.name: StringUtf16Test001
2696  * @tc.desc: Test is Chinese space character special character truncation.
2697  * @tc.type: FUNC
2698  */
HWTEST_F(NapiBasicTest, StringUtf16Test001, testing::ext::TestSize.Level1)2699 HWTEST_F(NapiBasicTest, StringUtf16Test001, testing::ext::TestSize.Level1)
2700 {
2701     napi_env env = reinterpret_cast<napi_env>(engine_);
2702     const char16_t testStr[] = u"中文,English,123456,!@#$%$#^%&12345     ";
2703     int testStrLength = static_cast<int>(std::char_traits<char16_t>::length(testStr));
2704     napi_value result = nullptr;
2705     ASSERT_CHECK_CALL(napi_create_string_utf16(env, testStr, testStrLength, &result));
2706     ASSERT_CHECK_VALUE_TYPE(env, result, napi_string);
2707 
2708     char16_t* buffer = nullptr;
2709     size_t bufferSize = 0;
2710     size_t strLength = 0;
2711     ASSERT_CHECK_CALL(napi_get_value_string_utf16(env, result, nullptr, 0, &bufferSize));
2712     ASSERT_GT(bufferSize, 0);
2713     buffer = new char16_t[bufferSize + 1] { 0 };
2714     ASSERT_CHECK_CALL(napi_get_value_string_utf16(env, result, buffer, bufferSize + 1, &strLength));
2715     for (int i = 0; i < testStrLength; i++) {
2716         ASSERT_EQ(testStr[i], buffer[i]);
2717     }
2718     ASSERT_EQ(testStrLength, strLength);
2719     delete[] buffer;
2720     buffer = nullptr;
2721 
2722     char16_t* bufferShort = nullptr;
2723     int bufferShortSize = 3;
2724     bufferShort = new char16_t[bufferShortSize] { 0 };
2725     ASSERT_CHECK_CALL(napi_get_value_string_utf16(env, result, bufferShort, bufferShortSize, &strLength));
2726     for (int i = 0; i < bufferShortSize; i++) {
2727         if (i == (bufferShortSize - 1)) {
2728             ASSERT_EQ(0, bufferShort[i]);
2729         } else {
2730             ASSERT_EQ(testStr[i], bufferShort[i]);
2731         }
2732     }
2733     ASSERT_EQ(strLength, MAX_BUFFER_SIZE);
2734     delete[] bufferShort;
2735     bufferShort = nullptr;
2736 }
2737 
2738 /**
2739  * @tc.name: StringUtf16Test002
2740  * @tc.desc: Test string type.
2741  * @tc.type: FUNC
2742  */
HWTEST_F(NapiBasicTest, StringUtf16Test002, testing::ext::TestSize.Level2)2743 HWTEST_F(NapiBasicTest, StringUtf16Test002, testing::ext::TestSize.Level2)
2744 {
2745     napi_env env = reinterpret_cast<napi_env>(engine_);
2746     char16_t testStr[] = u"ut.utf16test.napi.!@#%中^&*()6666";
2747     int testStrLength = static_cast<int>(std::char_traits<char16_t>::length(testStr));
2748     napi_value result = nullptr;
2749     {
2750         napi_status ret = napi_create_string_utf16(env, nullptr, testStrLength, &result);
2751         ASSERT_EQ(ret, napi_status::napi_invalid_arg);
2752     }
2753     {
2754         napi_status ret = napi_create_string_utf16(env, testStr, (size_t)INT_MAX + 1, &result);
2755         ASSERT_EQ(ret, napi_status::napi_invalid_arg);
2756     }
2757 }
2758 
2759 /**
2760  * @tc.name: StringUtf16Test003
2761  * @tc.desc: Test string type.
2762  * @tc.type: FUNC
2763  */
HWTEST_F(NapiBasicTest, StringUtf16Test003, testing::ext::TestSize.Level2)2764 HWTEST_F(NapiBasicTest, StringUtf16Test003, testing::ext::TestSize.Level2)
2765 {
2766     napi_env env = reinterpret_cast<napi_env>(engine_);
2767     char16_t testStr[] = u"ut.utf16test.napi.!@#$%^&*123";
2768     size_t testStrLength = static_cast<size_t>(std::char_traits<char16_t>::length(testStr));
2769     char16_t buffer[] = u"12345";
2770     size_t bufferSize = 0;
2771     size_t copied = 0;
2772     napi_value result = nullptr;
2773 
2774     ASSERT_CHECK_CALL(napi_create_string_utf16(env, testStr, testStrLength, &result));
2775     ASSERT_CHECK_CALL(napi_get_value_string_utf16(env, result, buffer, bufferSize, &copied));
2776 
2777     for (size_t i = 0; i < MAX_BUFFER_SIZE; i++) {
2778         ASSERT_NE(buffer[i], testStr[i]);
2779     }
2780 }
2781 
2782 /**
2783  * @tc.name: StringUtf16Test004
2784  * @tc.desc: Test string type.
2785  * @tc.type: FUNC
2786  */
HWTEST_F(NapiBasicTest, StringUtf16Test004, testing::ext::TestSize.Level2)2787 HWTEST_F(NapiBasicTest, StringUtf16Test004, testing::ext::TestSize.Level2)
2788 {
2789     napi_env env = reinterpret_cast<napi_env>(engine_);
2790     char16_t buffer[BUFFER_SIZE_FIVE];
2791     int testStrLength = static_cast<int>(std::char_traits<char16_t>::length(buffer));
2792     size_t copied;
2793     int64_t testValue = INT64_MAX;
2794     napi_value result = nullptr;
2795 
2796     ASSERT_CHECK_CALL(napi_create_bigint_int64(env, testValue, &result));
2797     ASSERT_CHECK_VALUE_TYPE(env, result, napi_bigint);
2798 
2799     napi_status ret = napi_get_value_string_utf16(env, result, buffer, testStrLength, &copied);
2800     ASSERT_EQ(ret, napi_status::napi_string_expected);
2801 }
2802 
2803 /**
2804  * @tc.name: StringUtf16Test005
2805  * @tc.desc: Test string type.
2806  * @tc.type: FUNC
2807  */
HWTEST_F(NapiBasicTest, StringUtf16Test005, testing::ext::TestSize.Level2)2808 HWTEST_F(NapiBasicTest, StringUtf16Test005, testing::ext::TestSize.Level2)
2809 {
2810     napi_env env = reinterpret_cast<napi_env>(engine_);
2811     char16_t testStr[] = u"ut.utf16test.napi.!@#$%^&*123";
2812     int testStrLength = static_cast<int>(std::char_traits<char16_t>::length(testStr));
2813     char16_t buffer[testStrLength];
2814     size_t copied;
2815     napi_value result = nullptr;
2816 
2817     napi_status ret = napi_get_value_string_utf16(env, result, buffer, testStrLength, &copied);
2818     ASSERT_EQ(ret, napi_status::napi_invalid_arg);
2819 }
2820 
2821 /**
2822  * @tc.name: StringUtf16Test006
2823  * @tc.desc: Test string length.
2824  * @tc.type: FUNC
2825  */
HWTEST_F(NapiBasicTest, StringUtf16Test006, testing::ext::TestSize.Level1)2826 HWTEST_F(NapiBasicTest, StringUtf16Test006, testing::ext::TestSize.Level1)
2827 {
2828     napi_env env = reinterpret_cast<napi_env>(engine_);
2829     char16_t testStr[] = u"ut.utf16test.napi.!@#$%^&*123";
2830     size_t testStrLength = static_cast<size_t>(std::char_traits<char16_t>::length(testStr));
2831     size_t copied = 0;
2832     napi_value result = nullptr;
2833 
2834     ASSERT_CHECK_CALL(napi_create_string_utf16(env, testStr, testStrLength, &result));
2835     ASSERT_CHECK_CALL(napi_get_value_string_utf16(env, result, nullptr, testStrLength, &copied));
2836 
2837     ASSERT_EQ(testStrLength, copied);
2838 }
2839 
2840 /**
2841  * @tc.name: StringUtf8Test001
2842  * @tc.desc: Test string type.
2843  * @tc.type: FUNC
2844  */
HWTEST_F(NapiBasicTest, StringUtf8Test001, testing::ext::TestSize.Level2)2845 HWTEST_F(NapiBasicTest, StringUtf8Test001, testing::ext::TestSize.Level2)
2846 {
2847     napi_env env = reinterpret_cast<napi_env>(engine_);
2848     const char testStr[] = "ut.utf8test.napi.!@#%中^&*()6666";
2849     size_t testStrLength = strlen(testStr);
2850 
2851     napi_status ret = napi_create_string_utf8(env, testStr, testStrLength, nullptr);
2852     ASSERT_EQ(ret, napi_status::napi_invalid_arg);
2853 }
2854 
2855 /**
2856  * @tc.name: StringUtf8Test002
2857  * @tc.desc: Test string type.
2858  * @tc.type: FUNC
2859  */
HWTEST_F(NapiBasicTest, StringUtf8Test002, testing::ext::TestSize.Level2)2860 HWTEST_F(NapiBasicTest, StringUtf8Test002, testing::ext::TestSize.Level2)
2861 {
2862     napi_env env = reinterpret_cast<napi_env>(engine_);
2863     char buffer[BUFFER_SIZE_FIVE] = { 0 };
2864     size_t testStrLength = strlen(buffer);
2865     size_t copied;
2866     napi_value result = nullptr;
2867     napi_get_boolean(env, true, &result);
2868     ASSERT_CHECK_VALUE_TYPE(env, result, napi_boolean);
2869 
2870     napi_status ret = napi_get_value_string_utf8(env, result, buffer, testStrLength, &copied);
2871     ASSERT_EQ(ret, napi_status::napi_string_expected);
2872 }
2873 
2874 /**
2875  * @tc.name: StringUtf8Test003
2876  * @tc.desc: Test string type.
2877  * @tc.type: FUNC
2878  */
HWTEST_F(NapiBasicTest, StringUtf8Test003, testing::ext::TestSize.Level2)2879 HWTEST_F(NapiBasicTest, StringUtf8Test003, testing::ext::TestSize.Level2)
2880 {
2881     napi_env env = reinterpret_cast<napi_env>(engine_);
2882     const char testStr[] = "ut.utf8test.napi.!@#$%^&*123";
2883     size_t testStrLength = strlen(testStr);
2884     char buffer[testStrLength];
2885     size_t copied;
2886     napi_value result = nullptr;
2887 
2888     napi_status ret = napi_get_value_string_utf8(env, result, buffer, testStrLength, &copied);
2889     ASSERT_EQ(ret, napi_status::napi_invalid_arg);
2890 }
2891 
2892 /**
2893  * @tc.name: StringUtf8Test004
2894  * @tc.desc: Test string length.
2895  * @tc.type: FUNC
2896  */
HWTEST_F(NapiBasicTest, StringUtf8Test004, testing::ext::TestSize.Level1)2897 HWTEST_F(NapiBasicTest, StringUtf8Test004, testing::ext::TestSize.Level1)
2898 {
2899     napi_env env = reinterpret_cast<napi_env>(engine_);
2900     const char testStr[] = "ut.utf8test.napi.!@#$%^&*123";
2901     size_t testStrLength = strlen(testStr);
2902     size_t copied = 0;
2903     napi_value result = nullptr;
2904 
2905     ASSERT_CHECK_CALL(napi_create_string_utf8(env, testStr, testStrLength, &result));
2906     ASSERT_CHECK_CALL(napi_get_value_string_utf8(env, result, nullptr, testStrLength, &copied));
2907 
2908     ASSERT_EQ(testStrLength, copied);
2909 }
2910 
2911 /**
2912  * @tc.name: StringLatin1Test001
2913  * @tc.desc: Test string type.
2914  * @tc.type: FUNC
2915  */
HWTEST_F(NapiBasicTest, StringLatin1Test001, testing::ext::TestSize.Level1)2916 HWTEST_F(NapiBasicTest, StringLatin1Test001, testing::ext::TestSize.Level1)
2917 {
2918     napi_env env = reinterpret_cast<napi_env>(engine_);
2919     const char testStr[] = "ut.latin1test.napi.!@#%^&*()6666";
2920     size_t testStrLength = strlen(testStr);
2921     napi_value result = nullptr;
2922     ASSERT_CHECK_CALL(napi_create_string_latin1(env, testStr, testStrLength, &result));
2923     ASSERT_CHECK_VALUE_TYPE(env, result, napi_string);
2924 
2925     char* buffer = nullptr;
2926     size_t bufferSize = 0;
2927     size_t strLength = 0;
2928     ASSERT_CHECK_CALL(napi_get_value_string_latin1(env, result, nullptr, 0, &bufferSize));
2929     ASSERT_GT(bufferSize, 0);
2930     buffer = new char[bufferSize + 1]{ 0 };
2931     ASSERT_CHECK_CALL(napi_get_value_string_latin1(env, result, buffer, bufferSize + 1, &strLength));
2932     ASSERT_STREQ(testStr, buffer);
2933     ASSERT_EQ(testStrLength, strLength);
2934     delete []buffer;
2935     buffer = nullptr;
2936 }
2937 
2938 /**
2939  * @tc.name: StringLatin1Test002
2940  * @tc.desc: Test string type.
2941  * @tc.type: FUNC
2942  */
HWTEST_F(NapiBasicTest, StringLatin1Test002, testing::ext::TestSize.Level1)2943 HWTEST_F(NapiBasicTest, StringLatin1Test002, testing::ext::TestSize.Level1)
2944 {
2945     napi_env env = reinterpret_cast<napi_env>(engine_);
2946     const char testStr[] = "ut.latin1test.中文测试";
2947     size_t testStrLength = strlen(testStr);
2948     napi_value result = nullptr;
2949     ASSERT_CHECK_CALL(napi_create_string_latin1(env, testStr, testStrLength, &result));
2950     ASSERT_CHECK_VALUE_TYPE(env, result, napi_string);
2951 
2952     char* buffer = nullptr;
2953     size_t bufferSize = 0;
2954     size_t strLength = 0;
2955     ASSERT_CHECK_CALL(napi_get_value_string_latin1(env, result, nullptr, 0, &bufferSize));
2956     ASSERT_GT(bufferSize, 0);
2957     buffer = new char[bufferSize + 1]{ 0 };
2958     ASSERT_CHECK_CALL(napi_get_value_string_latin1(env, result, buffer, bufferSize + 1, &strLength));
2959     ASSERT_STRNE(testStr, buffer);
2960     ASSERT_GT(testStrLength, strLength);
2961     delete []buffer;
2962     buffer = nullptr;
2963 }
2964 
2965 /**
2966  * @tc.name: StringLatin1Test003
2967  * @tc.desc: Test string type.
2968  * @tc.type: FUNC
2969  */
HWTEST_F(NapiBasicTest, StringLatin1Test003, testing::ext::TestSize.Level2)2970 HWTEST_F(NapiBasicTest, StringLatin1Test003, testing::ext::TestSize.Level2)
2971 {
2972     napi_env env = reinterpret_cast<napi_env>(engine_);
2973     napi_value result = nullptr;
2974 
2975     const char testStr[] = "ut.latin1test.napi.!@#%^&*()6666";
2976     size_t testStrLength = strlen(testStr);
2977 
2978     napi_status ret = napi_create_string_latin1(env, nullptr, testStrLength, &result);
2979     ASSERT_EQ(ret, napi_status::napi_invalid_arg);
2980 }
2981 
2982 /**
2983  * @tc.name: StringLatin1Test004
2984  * @tc.desc: Test string type.
2985  * @tc.type: FUNC
2986  */
HWTEST_F(NapiBasicTest, StringLatin1Test004, testing::ext::TestSize.Level2)2987 HWTEST_F(NapiBasicTest, StringLatin1Test004, testing::ext::TestSize.Level2)
2988 {
2989     napi_env env = reinterpret_cast<napi_env>(engine_);
2990     napi_value result = nullptr;
2991 
2992     const char testStr[] = "ut.latin1test.napi.!@#%^&*()6666";
2993 
2994     napi_status ret = napi_create_string_latin1(env, testStr, 0, &result);
2995     ASSERT_EQ(ret, napi_status::napi_ok);
2996 
2997     size_t bufferSize = 0;
2998     ASSERT_CHECK_CALL(napi_get_value_string_latin1(env, result, nullptr, 0, &bufferSize));
2999     ASSERT_EQ(bufferSize, 0);
3000 }
3001 
3002 /**
3003  * @tc.name: StringLatin1Test005
3004  * @tc.desc: Test string type.
3005  * @tc.type: FUNC
3006  */
HWTEST_F(NapiBasicTest, StringLatin1Test005, testing::ext::TestSize.Level2)3007 HWTEST_F(NapiBasicTest, StringLatin1Test005, testing::ext::TestSize.Level2)
3008 {
3009     napi_env env = reinterpret_cast<napi_env>(engine_);
3010     char buffer[BUFFER_SIZE_FIVE] = { 0 };
3011     size_t testStrLength = strlen(buffer);
3012     size_t copied;
3013     napi_value result = nullptr;
3014     napi_get_boolean(env, true, &result);
3015     ASSERT_CHECK_VALUE_TYPE(env, result, napi_boolean);
3016 
3017     napi_status ret = napi_get_value_string_latin1(env, result, buffer, testStrLength, &copied);
3018     ASSERT_EQ(ret, napi_status::napi_string_expected);
3019 }
3020 
3021 /**
3022  * @tc.name: StringLatin1Test006
3023  * @tc.desc: Test string type.
3024  * @tc.type: FUNC
3025  */
HWTEST_F(NapiBasicTest, StringLatin1Test006, testing::ext::TestSize.Level2)3026 HWTEST_F(NapiBasicTest, StringLatin1Test006, testing::ext::TestSize.Level2)
3027 {
3028     napi_env env = reinterpret_cast<napi_env>(engine_);
3029     const char testStr[] = "ut.latin1test.napi.!@#$%^&*123";
3030     size_t testStrLength = strlen(testStr);
3031     char buffer[testStrLength];
3032     size_t copied;
3033     napi_value result = nullptr;
3034 
3035     napi_status ret = napi_get_value_string_latin1(env, result, buffer, testStrLength, &copied);
3036     ASSERT_EQ(ret, napi_status::napi_invalid_arg);
3037 }
3038 
3039 /**
3040  * @tc.name: StringLatin1Test007
3041  * @tc.desc: Test string type.
3042  * @tc.type: FUNC
3043  */
HWTEST_F(NapiBasicTest, StringLatin1Test007, testing::ext::TestSize.Level1)3044 HWTEST_F(NapiBasicTest, StringLatin1Test007, testing::ext::TestSize.Level1)
3045 {
3046     napi_env env = reinterpret_cast<napi_env>(engine_);
3047     const char testStr[] = "ut.latin1test.napi.!@#$%^&*123";
3048     size_t testStrLength = strlen(testStr);
3049     size_t copied = 0;
3050     napi_value result = nullptr;
3051 
3052     ASSERT_CHECK_CALL(napi_create_string_latin1(env, testStr, testStrLength, &result));
3053     ASSERT_CHECK_CALL(napi_get_value_string_latin1(env, result, nullptr, testStrLength, &copied));
3054 
3055     ASSERT_EQ(testStrLength, copied);
3056 }
3057 
3058 /**
3059  * @tc.name: ToStringTest001
3060  * @tc.desc: Test string type of str.
3061  * @tc.type: FUNC
3062  */
HWTEST_F(NapiBasicTest, ToStringTest001, testing::ext::TestSize.Level1)3063 HWTEST_F(NapiBasicTest, ToStringTest001, testing::ext::TestSize.Level1)
3064 {
3065     napi_env env = reinterpret_cast<napi_env>(engine_);
3066     const char testStr[] = "中文,English,123456,!@#$%$#^%&";
3067     size_t testStrLength = strlen(testStr);
3068     napi_value str = nullptr;
3069     ASSERT_CHECK_CALL(napi_create_string_utf8(env, testStr, testStrLength, &str));
3070     ASSERT_CHECK_VALUE_TYPE(env, str, napi_string);
3071 
3072     napi_value result = nullptr;
3073     ASSERT_CHECK_CALL(napi_coerce_to_string(env, str, &result));
3074     char* buffer = nullptr;
3075     size_t bufferSize = 0;
3076     size_t strLength = 0;
3077     ASSERT_CHECK_CALL(napi_get_value_string_utf8(env, result, nullptr, 0, &bufferSize));
3078     ASSERT_GT(bufferSize, 0);
3079     buffer = new char[bufferSize + 1]{ 0 };
3080     ASSERT_CHECK_CALL(napi_get_value_string_utf8(env, result, buffer, bufferSize + 1, &strLength));
3081     ASSERT_STREQ(testStr, buffer);
3082     ASSERT_EQ(testStrLength, strLength);
3083     delete []buffer;
3084     buffer = nullptr;
3085 }
3086 
3087 /**
3088  * @tc.name: ToStringTest002
3089  * @tc.desc: Test string type of undefined.
3090  * @tc.type: FUNC
3091  */
HWTEST_F(NapiBasicTest, ToStringTest002, testing::ext::TestSize.Level1)3092 HWTEST_F(NapiBasicTest, ToStringTest002, testing::ext::TestSize.Level1)
3093 {
3094     napi_env env = reinterpret_cast<napi_env>(engine_);
3095     napi_value argument;
3096     napi_get_undefined(env, &argument);
3097     ASSERT_CHECK_VALUE_TYPE(env, argument, napi_undefined);
3098 
3099     napi_value result;
3100     ASSERT_CHECK_CALL(napi_coerce_to_string(env, argument, &result));
3101 
3102     const char expected[] = "undefined";
3103     size_t expectedLength = strlen(expected);
3104     char* buffer = nullptr;
3105     size_t bufferSize = 0;
3106     size_t strLength = 0;
3107     napi_get_value_string_utf8(env, result, nullptr, 0, &bufferSize);
3108     ASSERT_GT(bufferSize, 0);
3109     buffer = new char[bufferSize + 1]{ 0 };
3110     napi_get_value_string_utf8(env, result, buffer, bufferSize + 1, &strLength);
3111     ASSERT_EQ(expectedLength, strLength);
3112     ASSERT_STREQ(expected, buffer);
3113     delete []buffer;
3114     buffer = nullptr;
3115 }
3116 
3117 /**
3118  * @tc.name: ToStringTest003
3119  * @tc.desc: Test string type of null.
3120  * @tc.type: FUNC
3121  */
HWTEST_F(NapiBasicTest, ToStringTest003, testing::ext::TestSize.Level1)3122 HWTEST_F(NapiBasicTest, ToStringTest003, testing::ext::TestSize.Level1)
3123 {
3124     napi_env env = reinterpret_cast<napi_env>(engine_);
3125     napi_value argument;
3126     napi_get_null(env, &argument);
3127     ASSERT_CHECK_VALUE_TYPE(env, argument, napi_null);
3128 
3129     napi_value result;
3130     ASSERT_CHECK_CALL(napi_coerce_to_string(env, argument, &result));
3131 
3132     const char expected[] = "null";
3133     size_t expectedLength = strlen(expected);
3134     char* buffer = nullptr;
3135     size_t bufferSize = 0;
3136     size_t strLength = 0;
3137     napi_get_value_string_utf8(env, result, nullptr, 0, &bufferSize);
3138     ASSERT_GT(bufferSize, 0);
3139     buffer = new char[bufferSize + 1]{ 0 };
3140     napi_get_value_string_utf8(env, result, buffer, bufferSize + 1, &strLength);
3141     ASSERT_EQ(expectedLength, strLength);
3142     ASSERT_STREQ(expected, buffer);
3143     delete []buffer;
3144     buffer = nullptr;
3145 }
3146 
3147 /**
3148  * @tc.name: ToStringTest004
3149  * @tc.desc: Test string type of bool.
3150  * @tc.type: FUNC
3151  */
HWTEST_F(NapiBasicTest, ToStringTest004, testing::ext::TestSize.Level1)3152 HWTEST_F(NapiBasicTest, ToStringTest004, testing::ext::TestSize.Level1)
3153 {
3154     napi_env env = reinterpret_cast<napi_env>(engine_);
3155     napi_value argument;
3156     napi_get_boolean(env, true, &argument);
3157     ASSERT_CHECK_VALUE_TYPE(env, argument, napi_boolean);
3158 
3159     napi_value result;
3160     ASSERT_CHECK_CALL(napi_coerce_to_string(env, argument, &result));
3161 
3162     const char expected[] = "true";
3163     size_t expectedLength = strlen(expected);
3164     char* buffer = nullptr;
3165     size_t bufferSize = 0;
3166     size_t strLength = 0;
3167     napi_get_value_string_utf8(env, result, nullptr, 0, &bufferSize);
3168     ASSERT_GT(bufferSize, 0);
3169     buffer = new char[bufferSize + 1]{ 0 };
3170     napi_get_value_string_utf8(env, result, buffer, bufferSize + 1, &strLength);
3171     ASSERT_EQ(expectedLength, strLength);
3172     ASSERT_STREQ(expected, buffer);
3173     delete []buffer;
3174     buffer = nullptr;
3175 }
3176 
3177 /**
3178  * @tc.name: ToStringTest005
3179  * @tc.desc: Test string type of number.
3180  * @tc.type: FUNC
3181  */
HWTEST_F(NapiBasicTest, ToStringTest005, testing::ext::TestSize.Level1)3182 HWTEST_F(NapiBasicTest, ToStringTest005, testing::ext::TestSize.Level1)
3183 {
3184     napi_env env = reinterpret_cast<napi_env>(engine_);
3185     napi_value argument;
3186     double number = 0.1;
3187     napi_create_double(env, number, &argument);
3188     ASSERT_CHECK_VALUE_TYPE(env, argument, napi_number);
3189 
3190     napi_value result;
3191     ASSERT_CHECK_CALL(napi_coerce_to_string(env, argument, &result));
3192 
3193     double numberValue;
3194     napi_get_value_double(env, argument, &numberValue);
3195     std::string expected = std::to_string(numberValue);
3196     // Remove excess '0' after delimiter
3197     while (!expected.empty() && expected.back() == '0')
3198     {
3199         expected.pop_back();
3200     }
3201 
3202     size_t expectedLength = expected.length();
3203     char* buffer = nullptr;
3204     size_t bufferSize = 0;
3205     size_t strLength = 0;
3206     napi_get_value_string_utf8(env, result, nullptr, 0, &bufferSize);
3207     ASSERT_GT(bufferSize, 0);
3208     buffer = new char[bufferSize + 1]{ 0 };
3209     napi_get_value_string_utf8(env, result, buffer, bufferSize + 1, &strLength);
3210     ASSERT_EQ(expectedLength, strLength);
3211     ASSERT_STREQ(expected.c_str(), buffer);
3212     delete []buffer;
3213     buffer = nullptr;
3214 }
3215 
3216 /**
3217  * @tc.name: ToStringTest006
3218  * @tc.desc: Test string type of bigint.
3219  * @tc.type: FUNC
3220  */
HWTEST_F(NapiBasicTest, ToStringTest006, testing::ext::TestSize.Level1)3221 HWTEST_F(NapiBasicTest, ToStringTest006, testing::ext::TestSize.Level1)
3222 {
3223     napi_env env = reinterpret_cast<napi_env>(engine_);
3224     int64_t testValue = INT64_MAX;
3225     napi_value argument;
3226     bool flag = false;
3227     ASSERT_CHECK_CALL(napi_create_bigint_int64(env, testValue, &argument));
3228     ASSERT_CHECK_VALUE_TYPE(env, argument, napi_bigint);
3229 
3230     napi_value result;
3231     ASSERT_CHECK_CALL(napi_coerce_to_string(env, argument, &result));
3232 
3233     int64_t numberValue = 0;
3234     ASSERT_CHECK_CALL(napi_get_value_bigint_int64(env, argument, &numberValue, &flag));
3235     ASSERT_EQ(numberValue, INT64_MAX);
3236     ASSERT_TRUE(flag);
3237     std::string expected = std::to_string(numberValue);
3238 
3239     size_t expectedLength = expected.length();
3240     char* buffer = nullptr;
3241     size_t bufferSize = 0;
3242     size_t strLength = 0;
3243     napi_get_value_string_utf8(env, result, nullptr, 0, &bufferSize);
3244     ASSERT_GT(bufferSize, 0);
3245     buffer = new char[bufferSize + 1]{ 0 };
3246     napi_get_value_string_utf8(env, result, buffer, bufferSize + 1, &strLength);
3247     ASSERT_EQ(expectedLength, strLength);
3248     ASSERT_STREQ(expected.c_str(), buffer);
3249     delete []buffer;
3250     buffer = nullptr;
3251 }
3252 
3253 /**
3254  * @tc.name: ToStringTest007
3255  * @tc.desc: Test string type of symbol.
3256  * @tc.type: FUNC
3257  */
HWTEST_F(NapiBasicTest, ToStringTest007, testing::ext::TestSize.Level1)3258 HWTEST_F(NapiBasicTest, ToStringTest007, testing::ext::TestSize.Level1)
3259 {
3260     napi_env env = reinterpret_cast<napi_env>(engine_);
3261     const char testStr[] = "testSymbol";
3262     size_t testStrLength = strlen(testStr);
3263     napi_value testSymbol = nullptr;
3264     napi_create_string_utf8(env, testStr, testStrLength, &testSymbol);
3265     napi_value symbolVal = nullptr;
3266     napi_create_symbol(env, testSymbol, &symbolVal);
3267     ASSERT_CHECK_VALUE_TYPE(env, symbolVal, napi_symbol);
3268 
3269     napi_value result = nullptr;
3270     ASSERT_CHECK_CALL(napi_coerce_to_string(env, symbolVal, &result));
3271     ASSERT_CHECK_VALUE_TYPE(env, result, napi_undefined);
3272 }
3273 
3274 /**
3275  * @tc.name: ToStringTest001
3276  * @tc.desc: Test string type.
3277  * @tc.type: FUNC
3278  */
HWTEST_F(NapiBasicTest, ToStringTest008, testing::ext::TestSize.Level1)3279 HWTEST_F(NapiBasicTest, ToStringTest008, testing::ext::TestSize.Level1)
3280 {
3281     napi_env env = reinterpret_cast<napi_env>(engine_);
3282 
3283     napi_value result;
3284     napi_status status = napi_coerce_to_string(env, nullptr, &result);
3285     ASSERT_EQ(status, napi_status::napi_invalid_arg);
3286 }
3287 
3288 /**
3289  * @tc.name: InstanceDataTest_001
3290  * @tc.desc: Test instance type.
3291  * @tc.type: FUNC
3292  */
3293 struct AddonDataTest {
3294     size_t value;
3295     bool print;
3296     napi_ref jsCbRef;
3297 };
3298 
DeleteAddonData(napi_env env, void* rawData, void* hint)3299 static void DeleteAddonData(napi_env env, void* rawData, void* hint)
3300 {
3301     AddonDataTest* data = reinterpret_cast<AddonDataTest*>(rawData);
3302     if (data->print) {
3303         printf("deleting addon data\n");
3304     }
3305     if (data->jsCbRef != nullptr) {
3306         NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, data->jsCbRef));
3307     }
3308     free(data);
3309 }
3310 
SetPrintOnDelete(napi_env env, napi_callback_info info)3311 static napi_value SetPrintOnDelete(napi_env env, napi_callback_info info)
3312 {
3313     AddonDataTest* data;
3314     NAPI_CALL(env, napi_get_instance_data(env, (void**)&data));
3315     data->print = true;
3316     return nullptr;
3317 }
3318 
TestFinalizer(napi_env env, void* rawData, void* hint)3319 static void TestFinalizer(napi_env env, void* rawData, void* hint)
3320 {
3321     (void)rawData;
3322     (void)hint;
3323 
3324     AddonDataTest* data;
3325     napi_value jsResult;
3326     NAPI_CALL_RETURN_VOID(env, napi_get_instance_data(env, (void**)&data));
3327     napi_value jsCb;
3328     napi_value value;
3329     NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, data->jsCbRef, &jsCb));
3330     NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &value));
3331     NAPI_CALL_RETURN_VOID(env, napi_call_function(env, value, jsCb, 0, nullptr, &jsResult));
3332 
3333     NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, data->jsCbRef));
3334     data->jsCbRef = nullptr;
3335 }
3336 
ObjectWithFinalizer(napi_env env, napi_callback_info info)3337 static napi_value ObjectWithFinalizer(napi_env env, napi_callback_info info)
3338 {
3339     AddonDataTest* data;
3340 
3341     napi_value value;
3342     napi_value jsCb;
3343     size_t argc = 1;
3344 
3345     auto func = [](napi_env env, napi_callback_info info) -> napi_value {
3346         return nullptr;
3347     };
3348 
3349     napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH, func, nullptr, &jsCb);
3350 
3351     NAPI_CALL(env, napi_get_instance_data(env, (void**)&data));
3352     NAPI_ASSERT(env, data->jsCbRef == nullptr, "reference must be nullptr");
3353     NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &jsCb, nullptr, nullptr));
3354     NAPI_CALL(env, napi_create_object(env, &value));
3355     NAPI_CALL(env, napi_add_finalizer(env, value, nullptr, TestFinalizer, nullptr, nullptr));
3356     NAPI_CALL(env, napi_create_reference(env, jsCb, 1, &data->jsCbRef));
3357     return nullptr;
3358 }
3359 
HWTEST_F(NapiBasicTest, InstanceDataTest_001, testing::ext::TestSize.Level1)3360 HWTEST_F(NapiBasicTest, InstanceDataTest_001, testing::ext::TestSize.Level1)
3361 {
3362     napi_env env = reinterpret_cast<napi_env>(engine_);
3363     // Set instance data
3364     AddonDataTest* data = new AddonDataTest();
3365     data->value = 41;
3366     data->print = false;
3367     data->jsCbRef = nullptr;
3368     ASSERT_CHECK_CALL(napi_set_instance_data(env, data, DeleteAddonData, nullptr));
3369 
3370     // Test get instance data
3371     AddonDataTest* getData = nullptr;
3372     ASSERT_CHECK_CALL(napi_get_instance_data(env, (void**)&getData));
3373     ++getData->value;
3374     const size_t expectValue = 42;
3375     ASSERT_EQ(getData->value, expectValue);
3376 
3377     // Test finalizer
3378     SetPrintOnDelete(env, nullptr);
3379     ObjectWithFinalizer(env, nullptr);
3380 }
3381 
3382 /**
3383  * @tc.name: AsyncInitTest001.
3384  * @tc.desc: Test napi_async_init, napi_async_destroy.
3385  * @tc.type: FUNC
3386  */
HWTEST_F(NapiBasicTest, AsyncInitTest001, testing::ext::TestSize.Level1)3387 HWTEST_F(NapiBasicTest, AsyncInitTest001, testing::ext::TestSize.Level1)
3388 {
3389     napi_env env = reinterpret_cast<napi_env>(engine_);
3390 
3391     napi_value name;
3392     NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, "ACE_napi_async_init_Test_001",
3393         NAPI_AUTO_LENGTH, &name));
3394 
3395     napi_async_context context = nullptr;
3396     napi_status ret = napi_async_init(env, nullptr, name, &context);
3397     ASSERT_EQ(ret, napi_ok);
3398     EXPECT_NE(context, nullptr);
3399 
3400     ret = napi_async_destroy(env, context);
3401     ASSERT_EQ(ret, napi_ok);
3402 }
3403 
3404 /**
3405  * @tc.name: AsyncInitTest002
3406  * @tc.desc: Test napi_async_init with invalid arguments.
3407  * @tc.type: FUNC
3408  */
HWTEST_F(NapiBasicTest, AsyncInitTest002, testing::ext::TestSize.Level1)3409 HWTEST_F(NapiBasicTest, AsyncInitTest002, testing::ext::TestSize.Level1)
3410 {
3411     napi_env env = reinterpret_cast<napi_env>(engine_);
3412 
3413     napi_value resourceName;
3414     NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, "test", NAPI_AUTO_LENGTH, &resourceName));
3415 
3416     napi_async_context* contextPtr = nullptr;
3417     napi_status status = napi_async_init(env, nullptr, resourceName, contextPtr);
3418     EXPECT_EQ(status, napi_invalid_arg);
3419 }
3420 
3421 /**
3422  * @tc.name: OpenCallbackScopeTest001
3423  * @tc.desc: Test napi_open_callback_scope, napi_close_callback_scope.
3424  * @tc.type: FUNC
3425  */
HWTEST_F(NapiBasicTest, OpenCallbackScopeTest001, testing::ext::TestSize.Level1)3426 HWTEST_F(NapiBasicTest, OpenCallbackScopeTest001, testing::ext::TestSize.Level1)
3427 {
3428     napi_env envOne = reinterpret_cast<napi_env>(engine_);
3429 
3430     auto callbackScopeManager = engine_->GetCallbackScopeManager();
3431     ASSERT_NE(callbackScopeManager, nullptr);
3432 
3433     int openCallbackScopesBefore = callbackScopeManager->GetOpenCallbackScopes();
3434     int asyncCallbackScopeDepthBefore = callbackScopeManager->GetAsyncCallbackScopeDepth();
3435 
3436     napi_value resourceName;
3437     NAPI_CALL_RETURN_VOID(envOne, napi_create_string_utf8(envOne, "test", NAPI_AUTO_LENGTH, &resourceName));
3438 
3439     napi_async_context context;
3440     NAPI_CALL_RETURN_VOID(envOne, napi_async_init(envOne, nullptr, resourceName, &context));
3441 
3442     napi_callback_scope scope = nullptr;
3443     napi_status ret = napi_open_callback_scope(envOne, nullptr, context, &scope);
3444     EXPECT_EQ(ret, napi_ok);
3445     EXPECT_NE(scope, nullptr);
3446 
3447     int openCallbackScopes = callbackScopeManager->GetOpenCallbackScopes();
3448     int asyncCallbackScopeDepth = callbackScopeManager->GetAsyncCallbackScopeDepth();
3449     EXPECT_EQ(openCallbackScopes, (openCallbackScopesBefore + 1));
3450     EXPECT_EQ(asyncCallbackScopeDepth, (asyncCallbackScopeDepthBefore + 1));
3451 
3452     ret = napi_close_callback_scope(envOne, scope);
3453     EXPECT_EQ(ret, napi_ok);
3454 
3455     int openCallbackScopesAfter = callbackScopeManager->GetOpenCallbackScopes();
3456     int asyncCallbackScopeDepthAfter = callbackScopeManager->GetAsyncCallbackScopeDepth();
3457     EXPECT_EQ(openCallbackScopesAfter, openCallbackScopesBefore);
3458     EXPECT_EQ(asyncCallbackScopeDepthAfter, asyncCallbackScopeDepthBefore);
3459 
3460     NAPI_CALL_RETURN_VOID(envOne, napi_async_destroy(envOne, context));
3461 }
3462 
3463 /**
3464  * @tc.name: OpenCallbackScopeTest002
3465  * @tc.desc: Test napi_open_callback_scope, napi_close_callback_scope.
3466  * @tc.type: FUNC
3467  */
HWTEST_F(NapiBasicTest, OpenCallbackScopeTest002, testing::ext::TestSize.Level1)3468 HWTEST_F(NapiBasicTest, OpenCallbackScopeTest002, testing::ext::TestSize.Level1)
3469 {
3470     napi_env envOne = reinterpret_cast<napi_env>(engine_);
3471 
3472     auto callbackScopeManager = engine_->GetCallbackScopeManager();
3473     ASSERT_NE(callbackScopeManager, nullptr);
3474 
3475     int openCallbackScopesBefore = callbackScopeManager->GetOpenCallbackScopes();
3476     int asyncCallbackScopeDepthBefore = callbackScopeManager->GetAsyncCallbackScopeDepth();
3477 
3478     napi_value resourceName;
3479     NAPI_CALL_RETURN_VOID(envOne, napi_create_string_utf8(envOne, "test", NAPI_AUTO_LENGTH, &resourceName));
3480 
3481     napi_async_context context;
3482     NAPI_CALL_RETURN_VOID(envOne, napi_async_init(envOne, nullptr, resourceName, &context));
3483 
3484     napi_callback_scope scope = nullptr;
3485     napi_status res = napi_open_callback_scope(envOne, nullptr, context, &scope);
3486     EXPECT_EQ(res, napi_ok);
3487     EXPECT_NE(scope, nullptr);
3488 
3489     int openCallbackScopesOne = callbackScopeManager->GetOpenCallbackScopes();
3490     int asyncCallbackScopeDepthOne = callbackScopeManager->GetAsyncCallbackScopeDepth();
3491 
3492     // Open a internal callback scope
3493     panda::Local<panda::ObjectRef> obj = panda::ObjectRef::New(engine_->GetEcmaVm());
3494     auto scopeTwo = callbackScopeManager->Open(engine_, obj, {0, 0});
3495     int openCallbackScopesTwo = callbackScopeManager->GetOpenCallbackScopes();
3496     int asyncCallbackScopeDepthTwo = callbackScopeManager->GetAsyncCallbackScopeDepth();
3497 
3498     EXPECT_NE(scopeTwo, nullptr);
3499     EXPECT_EQ(openCallbackScopesTwo, openCallbackScopesOne);
3500     EXPECT_EQ(asyncCallbackScopeDepthTwo, (asyncCallbackScopeDepthOne + 1));
3501 
3502     callbackScopeManager->Close(scopeTwo);
3503     obj->Delete(engine_->GetEcmaVm(), obj);
3504     int openCallbackScopesAfterTwo = callbackScopeManager->GetOpenCallbackScopes();
3505     int asyncCallbackScopeDepthAfterTwo = callbackScopeManager->GetAsyncCallbackScopeDepth();
3506 
3507     EXPECT_EQ(openCallbackScopesAfterTwo, openCallbackScopesOne);
3508     EXPECT_EQ(asyncCallbackScopeDepthAfterTwo, asyncCallbackScopeDepthOne);
3509 
3510     res = napi_close_callback_scope(envOne, scope);
3511     EXPECT_EQ(res, napi_ok);
3512 
3513     int openCallbackScopesAfter = callbackScopeManager->GetOpenCallbackScopes();
3514     int asyncCallbackScopeDepthAfter = callbackScopeManager->GetAsyncCallbackScopeDepth();
3515 
3516     EXPECT_EQ(openCallbackScopesAfter, openCallbackScopesBefore);
3517     EXPECT_EQ(asyncCallbackScopeDepthAfter, asyncCallbackScopeDepthBefore);
3518 
3519     NAPI_CALL_RETURN_VOID(envOne, napi_async_destroy(envOne, context));
3520 }
3521 
ExpectCheckCall(napi_status call)3522 static void ExpectCheckCall(napi_status call)
3523 {
3524     EXPECT_EQ(call, napi_ok);
3525 }
3526 
Cleanup(void* arg)3527 static void Cleanup(void* arg)
3528 {
3529     g_hookTag += INT_ONE;
3530     if (arg != nullptr) {
3531     }
3532 }
3533 
CleanupCopy(void* arg)3534 static void CleanupCopy(void* arg)
3535 {
3536     g_hookTagcp += INT_ONE;
3537     if (arg != nullptr) {
3538     }
3539 }
3540 
3541 /**
3542  * @tc.name: AddEnvCleanupHook001
3543  * @tc.desc: Test napi_add_env_cleanup_hook
3544  * @tc.type: FUNC
3545  */
HWTEST_F(NapiBasicTest, AddEnvCleanupHook001, testing::ext::TestSize.Level1)3546 HWTEST_F(NapiBasicTest, AddEnvCleanupHook001, testing::ext::TestSize.Level1)
3547 {
3548     std::this_thread::sleep_for(std::chrono::seconds(2));
3549     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3550     g_hookTag = INT_ZERO;
3551     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3552     engine_->RunCleanup();
3553     EXPECT_EQ(g_hookTag, INT_ONE);
3554 }
3555 
3556 /**
3557  * @tc.name: AddEnvCleanupHook002
3558  * @tc.desc: Test napi_add_env_cleanup_hook
3559  * @tc.type: FUNC
3560  */
HWTEST_F(NapiBasicTest, AddEnvCleanupHook002, testing::ext::TestSize.Level2)3561 HWTEST_F(NapiBasicTest, AddEnvCleanupHook002, testing::ext::TestSize.Level2)
3562 {
3563     napi_env env = reinterpret_cast<napi_env>(engine_);
3564     napi_status res = napi_invalid_arg;
3565     res = napi_add_env_cleanup_hook(env, Cleanup, nullptr);
3566     engine_->RunCleanup();
3567     EXPECT_EQ(res, napi_ok);
3568 }
3569 
3570 /**
3571  * @tc.name: AddEnvCleanupHook003
3572  * @tc.desc: Test napi_add_env_cleanup_hook
3573  * @tc.type: FUNC
3574  */
HWTEST_F(NapiBasicTest, AddEnvCleanupHook003, testing::ext::TestSize.Level2)3575 HWTEST_F(NapiBasicTest, AddEnvCleanupHook003, testing::ext::TestSize.Level2)
3576 {
3577     napi_env env = reinterpret_cast<napi_env>(engine_);
3578     napi_status res = napi_ok;
3579     res = napi_add_env_cleanup_hook(env, nullptr, &g_hookArgOne);
3580 
3581     EXPECT_EQ(res, napi_invalid_arg);
3582 }
3583 
3584 /**
3585  * @tc.name: AddEnvCleanupHook004
3586  * @tc.desc: Test napi_add_env_cleanup_hook
3587  * @tc.type: FUNC
3588  */
HWTEST_F(NapiBasicTest, AddEnvCleanupHook004, testing::ext::TestSize.Level2)3589 HWTEST_F(NapiBasicTest, AddEnvCleanupHook004, testing::ext::TestSize.Level2)
3590 {
3591     napi_status res = napi_ok;
3592     res = napi_add_env_cleanup_hook(nullptr, Cleanup, &g_hookArgOne);
3593     engine_->RunCleanup();
3594     EXPECT_EQ(res, napi_invalid_arg);
3595 }
3596 
3597 /**
3598  * @tc.name: AddEnvCleanupHook005
3599  * @tc.desc: Test napi_add_env_cleanup_hook
3600  * @tc.type: FUNC
3601  */
HWTEST_F(NapiBasicTest, AddEnvCleanupHook005, testing::ext::TestSize.Level1)3602 HWTEST_F(NapiBasicTest, AddEnvCleanupHook005, testing::ext::TestSize.Level1)
3603 {
3604     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3605     g_hookTag = INT_ZERO;
3606     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3607     ExpectCheckCall(napi_remove_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3608     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3609     engine_->RunCleanup();
3610     EXPECT_EQ(g_hookTag, INT_ONE);
3611 }
3612 
3613 /**
3614  * @tc.name: AddEnvCleanupHook006
3615  * @tc.desc: Test napi_add_env_cleanup_hook
3616  * @tc.type: FUNC
3617  */
HWTEST_F(NapiBasicTest, AddEnvCleanupHook006, testing::ext::TestSize.Level1)3618 HWTEST_F(NapiBasicTest, AddEnvCleanupHook006, testing::ext::TestSize.Level1)
3619 {
3620     g_hookTag = INT_ZERO;
3621     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3622     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3623     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgTwo));
3624     engine_->RunCleanup();
3625     EXPECT_EQ(g_hookTag, INT_TWO);
3626 }
3627 
3628 /**
3629  * @tc.name: AddEnvCleanupHook007
3630  * @tc.desc: Test napi_add_env_cleanup_hook
3631  * @tc.type: FUNC
3632  */
HWTEST_F(NapiBasicTest, AddEnvCleanupHook007, testing::ext::TestSize.Level1)3633 HWTEST_F(NapiBasicTest, AddEnvCleanupHook007, testing::ext::TestSize.Level1)
3634 {
3635     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3636     g_hookTag = INT_ZERO;
3637     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3638     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgTwo));
3639     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgThree));
3640     engine_->RunCleanup();
3641     EXPECT_EQ(g_hookTag, INT_THREE);
3642 }
3643 
3644 /**
3645  * @tc.name: EnvCleanupHook008
3646  * @tc.desc: Test napi_add_env_cleanup_hook napi_remove_env_cleanup_hook
3647  * @tc.type: FUNC
3648  */
HWTEST_F(NapiBasicTest, EnvCleanupHook008, testing::ext::TestSize.Level1)3649 HWTEST_F(NapiBasicTest, EnvCleanupHook008, testing::ext::TestSize.Level1)
3650 {
3651     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3652     g_hookTag = INT_ZERO;
3653     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3654     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgTwo));
3655     ExpectCheckCall(napi_remove_env_cleanup_hook(testEnv, Cleanup, &g_hookArgTwo));
3656     engine_->RunCleanup();
3657     EXPECT_EQ(g_hookTag, INT_ONE);
3658 }
3659 
3660 /**
3661  * @tc.name: EnvCleanupHook0009
3662  * @tc.desc: Test napi_add_env_cleanup_hook napi_remove_env_cleanup_hook
3663  * @tc.type: FUNC
3664  */
HWTEST_F(NapiBasicTest, EnvCleanupHook0009, testing::ext::TestSize.Level2)3665 HWTEST_F(NapiBasicTest, EnvCleanupHook0009, testing::ext::TestSize.Level2)
3666 {
3667     napi_env env = reinterpret_cast<napi_env>(engine_);
3668     g_hookTag = INT_ZERO;
3669     napi_status res = napi_invalid_arg;
3670     ExpectCheckCall(napi_add_env_cleanup_hook(env, Cleanup, &g_hookArgOne));
3671     ExpectCheckCall(napi_add_env_cleanup_hook(env, Cleanup, &g_hookArgTwo));
3672     res = napi_remove_env_cleanup_hook(env, Cleanup, nullptr);
3673     engine_->RunCleanup();
3674     EXPECT_EQ(g_hookTag, INT_TWO);
3675     EXPECT_EQ(res, napi_ok);
3676 }
3677 
3678 /**
3679  * @tc.name: EnvCleanupHook0010
3680  * @tc.desc: Test napi_add_env_cleanup_hook napi_remove_env_cleanup_hook
3681  * @tc.type: FUNC
3682  */
HWTEST_F(NapiBasicTest, EnvCleanupHook0010, testing::ext::TestSize.Level2)3683 HWTEST_F(NapiBasicTest, EnvCleanupHook0010, testing::ext::TestSize.Level2)
3684 {
3685     napi_env env = reinterpret_cast<napi_env>(engine_);
3686     g_hookTag = INT_ZERO;
3687     napi_status res = napi_ok;
3688     ExpectCheckCall(napi_add_env_cleanup_hook(env, Cleanup, &g_hookArgOne));
3689     ExpectCheckCall(napi_add_env_cleanup_hook(env, Cleanup, &g_hookArgTwo));
3690     res = napi_remove_env_cleanup_hook(env, nullptr, &g_hookArgTwo);
3691     engine_->RunCleanup();
3692     EXPECT_EQ(g_hookTag, INT_TWO);
3693     EXPECT_EQ(res, napi_invalid_arg);
3694 }
3695 
3696 /**
3697  * @tc.name: EnvCleanupHook0011
3698  * @tc.desc: Test napi_add_env_cleanup_hook napi_remove_env_cleanup_hook
3699  * @tc.type: FUNC
3700  */
HWTEST_F(NapiBasicTest, EnvCleanupHook0011, testing::ext::TestSize.Level2)3701 HWTEST_F(NapiBasicTest, EnvCleanupHook0011, testing::ext::TestSize.Level2)
3702 {
3703     napi_env env = reinterpret_cast<napi_env>(engine_);
3704     g_hookTag = INT_ZERO;
3705     napi_status res = napi_ok;
3706     ExpectCheckCall(napi_add_env_cleanup_hook(env, Cleanup, &g_hookArgOne));
3707     ExpectCheckCall(napi_add_env_cleanup_hook(env, Cleanup, &g_hookArgTwo));
3708     res = napi_remove_env_cleanup_hook(nullptr, Cleanup, &g_hookArgTwo);
3709     engine_->RunCleanup();
3710     EXPECT_EQ(g_hookTag, INT_TWO);
3711     EXPECT_EQ(res, napi_invalid_arg);
3712 }
3713 
3714 /**
3715  * @tc.name: EnvCleanupHook0012
3716  * @tc.desc: Test napi_add_env_cleanup_hook napi_remove_env_cleanup_hook
3717  * @tc.type: FUNC
3718  */
HWTEST_F(NapiBasicTest, EnvCleanupHook0012, testing::ext::TestSize.Level2)3719 HWTEST_F(NapiBasicTest, EnvCleanupHook0012, testing::ext::TestSize.Level2)
3720 {
3721     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3722     g_hookTag = INT_ZERO;
3723     g_hookTagcp = INT_ZERO;
3724     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3725     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, CleanupCopy, &g_hookArgTwo));
3726     ExpectCheckCall(napi_remove_env_cleanup_hook(testEnv, Cleanup, &g_hookArgTwo));
3727     ExpectCheckCall(napi_remove_env_cleanup_hook(testEnv, CleanupCopy, &g_hookArgOne));
3728     engine_->RunCleanup();
3729     EXPECT_EQ(g_hookTag, INT_ONE);
3730     EXPECT_EQ(g_hookTagcp, INT_ONE);
3731 }
3732 
3733 /**
3734  * @tc.name: EnvCleanupHook0013
3735  * @tc.desc: Test napi_add_env_cleanup_hook napi_remove_env_cleanup_hook
3736  * @tc.type: FUNC
3737  */
HWTEST_F(NapiBasicTest, EnvCleanupHook0013, testing::ext::TestSize.Level1)3738 HWTEST_F(NapiBasicTest, EnvCleanupHook0013, testing::ext::TestSize.Level1)
3739 {
3740     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3741     g_hookTag = INT_ZERO;
3742     g_hookTagcp = INT_ZERO;
3743     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3744     ExpectCheckCall(napi_add_env_cleanup_hook(testEnv, CleanupCopy, &g_hookArgTwo));
3745     ExpectCheckCall(napi_remove_env_cleanup_hook(testEnv, Cleanup, &g_hookArgOne));
3746     ExpectCheckCall(napi_remove_env_cleanup_hook(testEnv, CleanupCopy, &g_hookArgTwo));
3747     engine_->RunCleanup();
3748     EXPECT_EQ(g_hookTag, INT_ZERO);
3749     EXPECT_EQ(g_hookTagcp, INT_ZERO);
3750 }
3751 
3752 struct AsyncData {
3753     uv_async_t async;
3754     napi_env env;
3755     napi_async_cleanup_hook_handle handle;
3756 };
3757 
MustNotCall(napi_async_cleanup_hook_handle hook, void* arg)3758 static void MustNotCall(napi_async_cleanup_hook_handle hook, void* arg)
3759 {
3760     EXPECT_EQ(1, 0);
3761 }
3762 
CreateAsyncData()3763 static struct AsyncData* CreateAsyncData()
3764 {
3765     AsyncData* data = static_cast<AsyncData*>(malloc(sizeof(AsyncData)));
3766     if (data == nullptr) {
3767         return nullptr;
3768     }
3769     data->handle = nullptr;
3770     return data;
3771 }
3772 
AfterCleanupHookTwo(uv_handle_t* handle)3773 static void AfterCleanupHookTwo(uv_handle_t* handle)
3774 {
3775     AsyncData* data = static_cast<AsyncData*>(handle->data);
3776     ExpectCheckCall(napi_remove_async_cleanup_hook(data->handle));
3777     g_hookTag += INT_ONE;
3778     free(data);
3779 }
3780 
AfterCleanupHookOne(uv_async_t* async)3781 static void AfterCleanupHookOne(uv_async_t* async)
3782 {
3783     uv_close((uv_handle_t*)async, AfterCleanupHookTwo);
3784 }
3785 
AsyncCleanupHook(napi_async_cleanup_hook_handle handle, void* arg)3786 static void AsyncCleanupHook(napi_async_cleanup_hook_handle handle, void* arg)
3787 {
3788     AsyncData* data = static_cast<AsyncData*>(arg);
3789     uv_loop_t* loop;
3790     ExpectCheckCall(napi_get_uv_event_loop(data->env, &loop));
3791     int res = uv_async_init(loop, &data->async, AfterCleanupHookOne);
3792     EXPECT_EQ(res, 0);
3793 
3794     data->async.data = data;
3795     data->handle = handle;
3796     uv_async_send(&data->async);
3797 }
3798 
3799 /**
3800  * @tc.name: AsyncCleanupHook001
3801  * @tc.desc: Test napi_add_async_cleanup_hook
3802  * @tc.type: FUNC
3803  */
HWTEST_F(NapiBasicTest, AsyncCleanupHook001, testing::ext::TestSize.Level1)3804 HWTEST_F(NapiBasicTest, AsyncCleanupHook001, testing::ext::TestSize.Level1)
3805 {
3806     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3807     AsyncData* data = CreateAsyncData();
3808     if (data == nullptr) {
3809         return;
3810     }
3811     g_hookTag = INT_ZERO;
3812     data->env = testEnv;
3813     napi_status res = napi_add_async_cleanup_hook(testEnv, AsyncCleanupHook, data, &data->handle);
3814     engine_->RunCleanup();
3815     EXPECT_EQ(res, napi_ok);
3816     EXPECT_EQ(g_hookTag, INT_ONE);
3817 }
3818 
3819 /**
3820  * @tc.name: AsyncCleanupHook002
3821  * @tc.desc: Test napi_add_async_cleanup_hook
3822  * @tc.type: FUNC
3823  */
HWTEST_F(NapiBasicTest, AsyncCleanupHook002, testing::ext::TestSize.Level1)3824 HWTEST_F(NapiBasicTest, AsyncCleanupHook002, testing::ext::TestSize.Level1)
3825 {
3826     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3827     AsyncData* data = CreateAsyncData();
3828     if (data == nullptr) {
3829         return;
3830     }
3831     g_hookTag = INT_ZERO;
3832     data->env = testEnv;
3833     napi_status res = napi_add_async_cleanup_hook(testEnv, AsyncCleanupHook, data, nullptr);
3834     engine_->RunCleanup();
3835     EXPECT_EQ(g_hookTag, INT_ONE);
3836     EXPECT_EQ(res, napi_ok);
3837 }
3838 
3839 /**
3840  * @tc.name: AsyncCleanupHook003
3841  * @tc.desc: Test napi_add_async_cleanup_hook napi_remove_async_cleanup_hook
3842  * @tc.type: FUNC
3843  */
HWTEST_F(NapiBasicTest, ACE_Napi_Add_Async_Cleanup_Hook_0300, testing::ext::TestSize.Level2)3844 HWTEST_F(NapiBasicTest, ACE_Napi_Add_Async_Cleanup_Hook_0300, testing::ext::TestSize.Level2)
3845 {
3846     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
3847     napi_async_cleanup_hook_handle mustNotCallHandle;
3848     g_hookTag = INT_ZERO;
3849     ExpectCheckCall(napi_add_async_cleanup_hook(testEnv, MustNotCall, nullptr, &mustNotCallHandle));
3850     ExpectCheckCall(napi_remove_async_cleanup_hook(mustNotCallHandle));
3851     engine_->RunCleanup();
3852     EXPECT_EQ(g_hookTag, INT_ZERO);
3853 }
3854 
3855 /**
3856  * @tc.name: AsyncCleanupHook004
3857  * @tc.desc: Test napi_add_async_cleanup_hook
3858  * @tc.type: FUNC
3859  */
HWTEST_F(NapiBasicTest, ACE_Napi_Add_Async_Cleanup_Hook_0400, testing::ext::TestSize.Level2)3860 HWTEST_F(NapiBasicTest, ACE_Napi_Add_Async_Cleanup_Hook_0400, testing::ext::TestSize.Level2)
3861 {
3862     napi_status res = napi_ok;
3863     napi_async_cleanup_hook_handle mustNotCallHandle;
3864     g_hookTag = INT_ZERO;
3865     res = napi_add_async_cleanup_hook(nullptr, MustNotCall, nullptr, &mustNotCallHandle);
3866     engine_->RunCleanup();
3867     EXPECT_EQ(res, napi_invalid_arg);
3868 }
3869 
3870 /**
3871  * @tc.name: AsyncCleanupHook005
3872  * @tc.desc: Test napi_add_async_cleanup_hook
3873  * @tc.type: FUNC
3874  */
HWTEST_F(NapiBasicTest, ACE_Napi_Add_Async_Cleanup_Hook_0500, testing::ext::TestSize.Level2)3875 HWTEST_F(NapiBasicTest, ACE_Napi_Add_Async_Cleanup_Hook_0500, testing::ext::TestSize.Level2)
3876 {
3877     napi_env env = reinterpret_cast<napi_env>(engine_);
3878     napi_status res = napi_ok;
3879     napi_async_cleanup_hook_handle mustNotCallHandle;
3880     res = napi_add_async_cleanup_hook(env, nullptr, nullptr, &mustNotCallHandle);
3881     engine_->RunCleanup();
3882     EXPECT_EQ(res, napi_invalid_arg);
3883 }
3884 
3885 /**
3886  * @tc.name: AsyncCleanupHook006
3887  * @tc.desc: Test napi_add_async_cleanup_hook napi_remove_async_cleanup_hook
3888  * @tc.type: FUNC
3889  */
HWTEST_F(NapiBasicTest, ACE_Napi_Add_Async_Cleanup_Hook_0600, testing::ext::TestSize.Level1)3890 HWTEST_F(NapiBasicTest, ACE_Napi_Add_Async_Cleanup_Hook_0600, testing::ext::TestSize.Level1)
3891 {
3892     napi_env env = reinterpret_cast<napi_env>(engine_);
3893     AsyncData* data = CreateAsyncData();
3894     if (data == nullptr) {
3895         return;
3896     }
3897     data->env = env;
3898     g_hookTag = INT_ZERO;
3899     napi_status res = napi_invalid_arg;
3900     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, data, &data->handle);
3901     ASSERT_EQ(res, napi_ok);
3902     res = napi_remove_async_cleanup_hook(data->handle);
3903     ASSERT_EQ(res, napi_ok);
3904     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, data, &data->handle);
3905     ASSERT_EQ(res, napi_ok);
3906     engine_->RunCleanup();
3907     EXPECT_EQ(g_hookTag, INT_ONE);
3908     EXPECT_EQ(res, napi_ok);
3909 }
3910 
3911 /**
3912  * @tc.name: AsyncCleanupHook007
3913  * @tc.desc: Test napi_add_async_cleanup_hook
3914  * @tc.type: FUNC
3915  */
HWTEST_F(NapiBasicTest, AsyncCleanupHook007, testing::ext::TestSize.Level1)3916 HWTEST_F(NapiBasicTest, AsyncCleanupHook007, testing::ext::TestSize.Level1)
3917 {
3918     napi_env env = reinterpret_cast<napi_env>(engine_);
3919     napi_env envTwo = reinterpret_cast<napi_env>(engine_);
3920     g_hookTag = INT_ZERO;
3921     AsyncData* data = CreateAsyncData();
3922     if (data == nullptr) {
3923         return;
3924     }
3925     data->env = env;
3926     napi_status res = napi_invalid_arg;
3927     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, data, &data->handle);
3928     EXPECT_EQ(res, napi_ok);
3929     AsyncData* dataTwo = CreateAsyncData();
3930     if (dataTwo == nullptr) {
3931         return;
3932     }
3933     dataTwo->env = envTwo;
3934     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, dataTwo, &dataTwo->handle);
3935     EXPECT_EQ(res, napi_ok);
3936     engine_->RunCleanup();
3937     EXPECT_EQ(g_hookTag, INT_TWO);
3938 }
3939 
3940 /**
3941  * @tc.name: AsyncCleanupHook008
3942  * @tc.desc: Test napi_add_async_cleanup_hook
3943  * @tc.type: FUNC
3944  */
HWTEST_F(NapiBasicTest, AsyncCleanupHook008, testing::ext::TestSize.Level1)3945 HWTEST_F(NapiBasicTest, AsyncCleanupHook008, testing::ext::TestSize.Level1)
3946 {
3947     napi_env env = reinterpret_cast<napi_env>(engine_);
3948     napi_env envTwo = reinterpret_cast<napi_env>(engine_);
3949     napi_env envThree = reinterpret_cast<napi_env>(engine_);
3950     AsyncData* data = CreateAsyncData();
3951     if (data == nullptr) {
3952         return;
3953     }
3954     g_hookTag = INT_ZERO;
3955     data->env = env;
3956     napi_status res = napi_invalid_arg;
3957     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, data, &data->handle);
3958     EXPECT_EQ(res, napi_ok);
3959 
3960     AsyncData* dataTwo = CreateAsyncData();
3961     if (dataTwo == nullptr) {
3962         return;
3963     }
3964     dataTwo->env = envTwo;
3965     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, dataTwo, &dataTwo->handle);
3966     EXPECT_EQ(res, napi_ok);
3967 
3968     AsyncData* dataThree = CreateAsyncData();
3969     if (dataThree == nullptr) {
3970         return;
3971     }
3972     dataThree->env = envThree;
3973     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, dataThree, &dataThree->handle);
3974     EXPECT_EQ(res, napi_ok);
3975     engine_->RunCleanup();
3976     EXPECT_EQ(g_hookTag, INT_THREE);
3977 }
3978 
3979 /**
3980  * @tc.name: AsyncCleanupHook009
3981  * @tc.desc: Test napi_add_async_cleanup_hook napi_remove_async_cleanup_hook
3982  * @tc.type: FUNC
3983  */
HWTEST_F(NapiBasicTest, AsyncCleanupHook009, testing::ext::TestSize.Level1)3984 HWTEST_F(NapiBasicTest, AsyncCleanupHook009, testing::ext::TestSize.Level1)
3985 {
3986     napi_env env = reinterpret_cast<napi_env>(engine_);
3987     AsyncData* data = CreateAsyncData();
3988     if (data == nullptr) {
3989         return;
3990     }
3991     napi_status res = napi_invalid_arg;
3992     g_hookTag = INT_ZERO;
3993     data->env = env;
3994     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, data, &data->handle);
3995     EXPECT_EQ(res, napi_ok);
3996     res = napi_remove_async_cleanup_hook(data->handle);
3997     EXPECT_EQ(res, napi_ok);
3998     engine_->RunCleanup();
3999     EXPECT_EQ(g_hookTag, INT_ZERO);
4000 }
4001 
4002 /**
4003  * @tc.name: AsyncCleanupHook0010
4004  * @tc.desc: Test napi_remove_async_cleanup_hook
4005  * @tc.type: FUNC
4006  */
HWTEST_F(NapiBasicTest, AsyncCleanupHook0010, testing::ext::TestSize.Level2)4007 HWTEST_F(NapiBasicTest, AsyncCleanupHook0010, testing::ext::TestSize.Level2)
4008 {
4009     napi_status res = napi_ok;
4010     res = napi_remove_async_cleanup_hook(nullptr);
4011     EXPECT_EQ(res, napi_invalid_arg);
4012 }
4013 
4014 /**
4015  * @tc.name: AsyncCleanupHook0011
4016  * @tc.desc: Test napi_add_async_cleanup_hook napi_remove_async_cleanup_hook
4017  * @tc.type: FUNC
4018  */
HWTEST_F(NapiBasicTest, AsyncCleanupHook0011, testing::ext::TestSize.Level2)4019 HWTEST_F(NapiBasicTest, AsyncCleanupHook0011, testing::ext::TestSize.Level2)
4020 {
4021 
4022     napi_env env = reinterpret_cast<napi_env>(engine_);
4023     napi_env envTwo = reinterpret_cast<napi_env>(engine_);
4024     AsyncData* data = CreateAsyncData();
4025     if (data == nullptr) {
4026         return;
4027     }
4028     napi_status res = napi_invalid_arg;
4029     data->env = env;
4030     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, data, nullptr);
4031     EXPECT_EQ(res, napi_ok);
4032     AsyncData* dataTwo = CreateAsyncData();
4033     if (dataTwo == nullptr) {
4034         return;
4035     }
4036     dataTwo->env = envTwo;
4037     res = napi_add_async_cleanup_hook(env, AsyncCleanupHook, dataTwo, &dataTwo->handle);
4038     EXPECT_EQ(res, napi_ok);
4039     res = napi_remove_async_cleanup_hook(dataTwo->handle);
4040     EXPECT_EQ(res, napi_ok);
4041     engine_->RunCleanup();
4042 }
4043 
4044 /**
4045  * @tc.name: nodeApiGetModuleFileName0001
4046  * @tc.desc: Test node_api_get_module_file_name.
4047  * @tc.type: FUNC
4048  */
HWTEST_F(NapiBasicTest, nodeApiGetModuleFileName0001, testing::ext::TestSize.Level1)4049 HWTEST_F(NapiBasicTest, nodeApiGetModuleFileName0001, testing::ext::TestSize.Level1)
4050 {
4051     const char *fileName;
4052     napi_env testEnv = reinterpret_cast<napi_env>(engine_);
4053     napi_value result;
4054     node_api_get_module_file_name(testEnv, &fileName);
4055     napi_create_string_utf8(testEnv, fileName, NAPI_AUTO_LENGTH, &result);
4056     ASSERT_TRUE(strcmp(fileName, "") == 0);
4057 }
4058 
4059 /**
4060  * @tc.name: AsyncWorkTest002
4061  * @tc.desc: Test async work.
4062  * @tc.type: FUNC
4063  */
HWTEST_F(NapiBasicTest, AsyncWorkTest002, testing::ext::TestSize.Level1)4064 HWTEST_F(NapiBasicTest, AsyncWorkTest002, testing::ext::TestSize.Level1)
4065 {
4066     struct AsyncWorkContext {
4067         napi_async_work work = nullptr;
4068         bool executed = false;
4069     };
4070     napi_env env = reinterpret_cast<napi_env>(engine_);
4071     auto asyncWorkContext = new AsyncWorkContext();
4072     napi_value resourceName = nullptr;
4073     napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
4074     napi_create_async_work(
4075         env, nullptr, resourceName, [](napi_env value, void* data) {
4076             AsyncWorkContext* asyncWorkContext = (AsyncWorkContext*)data;
4077             asyncWorkContext->executed = true;
4078         },
4079         [](napi_env env, napi_status status, void* data) {
4080             AsyncWorkContext* asyncWorkContext = (AsyncWorkContext*)data;
4081             ASSERT_EQ(status, napi_status::napi_cancelled);
4082             std::cout << "status of task is: " << status << std::endl;
4083             napi_delete_async_work(env, asyncWorkContext->work);
4084             delete asyncWorkContext;
4085             STOP_EVENT_LOOP(env);
4086         },
4087         asyncWorkContext, &asyncWorkContext->work);
4088     napi_queue_async_work(env, asyncWorkContext->work);
4089     napi_cancel_async_work(env, asyncWorkContext->work);
4090     RUN_EVENT_LOOP(env);
4091 }
4092 
CreateWithPropertiesTestGetter(napi_env env, napi_callback_info info)4093 static napi_value CreateWithPropertiesTestGetter(napi_env env, napi_callback_info info)
4094 {
4095     napi_value res;
4096     napi_get_boolean(env, false, &res);
4097     return res;
4098 }
4099 
CreateWithPropertiesTestSetter(napi_env env, napi_callback_info info)4100 static napi_value CreateWithPropertiesTestSetter(napi_env env, napi_callback_info info)
4101 {
4102     napi_value res;
4103     napi_get_boolean(env, true, &res);
4104     return res;
4105 }
4106 
4107 /**
4108  * @tc.name: CreateObjectWithPropertiesTest001
4109  * @tc.desc: Test napi_create_object_with_properteis.
4110  * @tc.type: FUNC
4111  */
HWTEST_F(NapiBasicTest, CreateObjectWithPropertiesTest001, testing::ext::TestSize.Level1)4112 HWTEST_F(NapiBasicTest, CreateObjectWithPropertiesTest001, testing::ext::TestSize.Level1)
4113 {
4114     napi_env env = (napi_env)engine_;
4115     napi_value excep;
4116     ASSERT_CHECK_CALL(napi_get_and_clear_last_exception(env, &excep));
4117     napi_value val_false;
4118     napi_value val_true;
4119     ASSERT_CHECK_CALL(napi_get_boolean(env, false, &val_false));
4120     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &val_true));
4121     napi_property_descriptor desc1[] = {
4122         DECLARE_NAPI_DEFAULT_PROPERTY("x", val_true),
4123     };
4124     napi_value obj1;
4125     ASSERT_CHECK_CALL(napi_create_object_with_properties(env, &obj1, 1, desc1));
4126     napi_value obj2;
4127     napi_property_descriptor desc2[] = {
4128         DECLARE_NAPI_DEFAULT_PROPERTY("a", val_false),
4129         DECLARE_NAPI_GETTER_SETTER("b", CreateWithPropertiesTestGetter, CreateWithPropertiesTestSetter),
4130         DECLARE_NAPI_DEFAULT_PROPERTY("c", obj1),
4131     };
4132     ASSERT_CHECK_CALL(napi_create_object_with_properties(env, &obj2, 3, desc2));
4133     ASSERT_CHECK_VALUE_TYPE(env, obj1, napi_object);
4134     ASSERT_CHECK_VALUE_TYPE(env, obj2, napi_object);
4135     auto checkPropertyEqualsTo = [env] (napi_value obj, const char *keyStr, napi_value expect) -> bool {
4136         napi_value result;
4137         napi_get_named_property(env, obj, keyStr, &result);
4138         bool equal = false;
4139         napi_strict_equals(env, result, expect, &equal);
4140         return equal;
4141     };
4142     // get obj1.x == true
4143     ASSERT_TRUE(checkPropertyEqualsTo(obj1, "x", val_true));
4144     // set obj1.x = false
4145     ASSERT_CHECK_CALL(napi_set_named_property(env, obj1, "x", val_false));
4146     // get obj1.x == false
4147     ASSERT_TRUE(checkPropertyEqualsTo(obj1, "x", val_false));
4148     // get obj2.a == false
4149     ASSERT_TRUE(checkPropertyEqualsTo(obj2, "a", val_false));
4150     // get obj2.b == false
4151     ASSERT_TRUE(checkPropertyEqualsTo(obj2, "b", val_false));
4152     // set obj2.b = true (useless)
4153     ASSERT_CHECK_CALL(napi_set_named_property(env, obj2, "b", val_true));
4154     // get obj2.b == false
4155     ASSERT_TRUE(checkPropertyEqualsTo(obj2, "b", val_false));
4156     // get obj2.c == obj1
4157     ASSERT_TRUE(checkPropertyEqualsTo(obj2, "c", obj1));
4158     // get obj2.c.x == false
4159     napi_value val_res;
4160     ASSERT_CHECK_CALL(napi_get_named_property(env, obj2, "c", &val_res));
4161     ASSERT_TRUE(checkPropertyEqualsTo(val_res, "x", val_false));
4162 }
4163 
4164 /**
4165  * @tc.name: CreateObjectWithNamedPropertiesTest001
4166  * @tc.desc: Test napi_create_object_with_named_properteis.
4167  * @tc.type: FUNC
4168  */
HWTEST_F(NapiBasicTest, CreateObjectWithNamedPropertiesTest001, testing::ext::TestSize.Level1)4169 HWTEST_F(NapiBasicTest, CreateObjectWithNamedPropertiesTest001, testing::ext::TestSize.Level1)
4170 {
4171     napi_env env = (napi_env)engine_;
4172     napi_value excep;
4173     ASSERT_CHECK_CALL(napi_get_and_clear_last_exception(env, &excep));
4174     napi_value val_false;
4175     napi_value val_true;
4176     ASSERT_CHECK_CALL(napi_get_boolean(env, false, &val_false));
4177     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &val_true));
4178     const char *keys1[] = {
4179         "x",
4180     };
4181     const napi_value values1[] = {
4182         val_true,
4183     };
4184     napi_value obj1;
4185     ASSERT_CHECK_CALL(napi_create_object_with_named_properties(env, &obj1, 1, keys1, values1));
4186     napi_value obj2;
4187     const char *keys2[] = {
4188         "a",
4189         "b",
4190     };
4191     const napi_value values2[] = {
4192         val_false,
4193         obj1,
4194     };
4195     ASSERT_CHECK_CALL(napi_create_object_with_named_properties(env, &obj2, 2, keys2, values2));
4196     ASSERT_CHECK_VALUE_TYPE(env, obj1, napi_object);
4197     ASSERT_CHECK_VALUE_TYPE(env, obj2, napi_object);
4198     auto checkPropertyEqualsTo = [env] (napi_value obj, const char *keyStr, napi_value expect) -> bool {
4199         napi_value result;
4200         napi_get_named_property(env, obj, keyStr, &result);
4201         bool equal = false;
4202         napi_strict_equals(env, result, expect, &equal);
4203         return equal;
4204     };
4205     // get obj1.x == true
4206     ASSERT_TRUE(checkPropertyEqualsTo(obj1, "x", val_true));
4207     // set obj1.x = false
4208     ASSERT_CHECK_CALL(napi_set_named_property(env, obj1, "x", val_false));
4209     // get obj1.x == false
4210     ASSERT_TRUE(checkPropertyEqualsTo(obj1, "x", val_false));
4211     // get obj2.a == false
4212     ASSERT_TRUE(checkPropertyEqualsTo(obj2, "a", val_false));
4213     // get obj2.b == obj1
4214     ASSERT_TRUE(checkPropertyEqualsTo(obj2, "b", obj1));
4215     // get obj2.b.x == false
4216     napi_value val_res;
4217     ASSERT_CHECK_CALL(napi_get_named_property(env, obj2, "b", &val_res));
4218     ASSERT_TRUE(checkPropertyEqualsTo(val_res, "x", val_false));
4219 }
4220 
4221 /**
4222  * @tc.name: loadModuleWithInfo001
4223  * @tc.desc: Test napi_load_module_with_info with nullptr env.
4224  * @tc.type: FUNC
4225  */
HWTEST_F(NapiBasicTest, loadModuleWithInfo001, testing::ext::TestSize.Level1)4226 HWTEST_F(NapiBasicTest, loadModuleWithInfo001, testing::ext::TestSize.Level1)
4227 {
4228     ASSERT_NE(engine_, nullptr);
4229     napi_value result;
4230     napi_status res = napi_load_module_with_info(nullptr, nullptr, nullptr, &result);
4231     ASSERT_EQ(res, napi_invalid_arg);
4232 }
4233 
4234 /**
4235  * @tc.name: loadModuleWithInfo002
4236  * @tc.desc: Test napi_load_module_with_info with nullptr result.
4237  * @tc.type: FUNC
4238  */
HWTEST_F(NapiBasicTest, loadModuleWithInfo002, testing::ext::TestSize.Level1)4239 HWTEST_F(NapiBasicTest, loadModuleWithInfo002, testing::ext::TestSize.Level1)
4240 {
4241     ASSERT_NE(engine_, nullptr);
4242     napi_env env = (napi_env)engine_;
4243     napi_status res = napi_load_module_with_info(env, "@ohos.hilog", nullptr, nullptr);
4244     ASSERT_EQ(res, napi_invalid_arg);
4245 }
4246 
4247 /**
4248  * @tc.name: runEventLoopTest001
4249  * @tc.desc: Test napi_run_event_loop with nullptr env.
4250  * @tc.type: FUNC
4251  */
HWTEST_F(NapiBasicTest, runEventLoopTest001, testing::ext::TestSize.Level1)4252 HWTEST_F(NapiBasicTest, runEventLoopTest001, testing::ext::TestSize.Level1)
4253 {
4254     napi_status res = napi_run_event_loop(nullptr, napi_event_mode_default);
4255     ASSERT_EQ(res, napi_invalid_arg);
4256 }
4257 
4258 /**
4259  * @tc.name: runEventLoopTest002
4260  * @tc.desc: Test napi_run_event_loop with nullptr env.
4261  * @tc.type: FUNC
4262  */
HWTEST_F(NapiBasicTest, runEventLoopTest002, testing::ext::TestSize.Level1)4263 HWTEST_F(NapiBasicTest, runEventLoopTest002, testing::ext::TestSize.Level1)
4264 {
4265     napi_status res = napi_run_event_loop(nullptr, napi_event_mode_nowait);
4266     ASSERT_EQ(res, napi_invalid_arg);
4267 }
4268 
4269 /**
4270  * @tc.name: runEventLoopTest003
4271  * @tc.desc: Test napi_run_event_loop with nullptr loop
4272  * @tc.type: FUNC
4273  */
HWTEST_F(NapiBasicTest, runEventLoopTest003, testing::ext::TestSize.Level1)4274 HWTEST_F(NapiBasicTest, runEventLoopTest003, testing::ext::TestSize.Level1)
4275 {
4276     ASSERT_NE(engine_, nullptr);
4277     NativeEngineProxy engine;
4278     engine->Deinit();
4279     napi_status res = napi_run_event_loop(napi_env(engine), napi_event_mode_nowait);
4280     ASSERT_EQ(res, napi_invalid_arg);
4281     engine->Init();
4282 }
4283 
4284 /**
4285  * @tc.name: runEventLoopTest004
4286  * @tc.desc: Test napi_run_event_loop with nullptr loop
4287  * @tc.type: FUNC
4288  */
HWTEST_F(NapiBasicTest, runEventLoopTest004, testing::ext::TestSize.Level1)4289 HWTEST_F(NapiBasicTest, runEventLoopTest004, testing::ext::TestSize.Level1)
4290 {
4291     ASSERT_NE(engine_, nullptr);
4292     NativeEngineProxy engine;
4293     engine->Deinit();
4294     napi_status res = napi_run_event_loop(napi_env(engine), napi_event_mode_default);
4295     engine->Init();
4296     ASSERT_EQ(res, napi_invalid_arg);
4297 }
4298 
4299 /**
4300  * @tc.name: runEventLoopTest005
4301  * @tc.desc: Test napi_run_event_loop with main thread.
4302  * @tc.type: FUNC
4303  */
HWTEST_F(NapiBasicTest, runEventLoopTest005, testing::ext::TestSize.Level1)4304 HWTEST_F(NapiBasicTest, runEventLoopTest005, testing::ext::TestSize.Level1)
4305 {
4306     ASSERT_NE(engine_, nullptr);
4307     napi_env env = (napi_env)engine_;
4308     // main thread does not support napi_run_event_loop func
4309     napi_status res = napi_run_event_loop(env, napi_event_mode_default);
4310     ASSERT_EQ(res, napi_generic_failure);
4311 }
4312 
4313 /**
4314  * @tc.name: runEventLoopTest006
4315  * @tc.desc: Test napi_run_event_loop with main thread.
4316  * @tc.type: FUNC
4317  */
HWTEST_F(NapiBasicTest, runEventLoopTest006, testing::ext::TestSize.Level1)4318 HWTEST_F(NapiBasicTest, runEventLoopTest006, testing::ext::TestSize.Level1)
4319 {
4320     ASSERT_NE(engine_, nullptr);
4321     napi_env env = (napi_env)engine_;
4322     // main thread does not support napi_run_event_loop func
4323     napi_status res = napi_run_event_loop(env, napi_event_mode_nowait);
4324     ASSERT_EQ(res, napi_generic_failure);
4325 }
4326 
4327 /**
4328  * @tc.name: runEventLoopTest007
4329  * @tc.desc: Test napi_run_event_loop with worker thread.
4330  * @tc.type: FUNC
4331  */
HWTEST_F(NapiBasicTest, runEventLoopTest007, testing::ext::TestSize.Level1)4332 HWTEST_F(NapiBasicTest, runEventLoopTest007, testing::ext::TestSize.Level1)
4333 {
4334     ASSERT_NE(engine_, nullptr);
4335     engine_->MarkWorkerThread();
4336     napi_env env = (napi_env)engine_;
4337     // worker thread does not support napi_run_event_loop func
4338     napi_status res = napi_run_event_loop(env, napi_event_mode_nowait);
4339     ASSERT_EQ(res, napi_generic_failure);
4340     engine_->jsThreadType_ = panda::panda_file::DataProtect(uintptr_t(NativeEngine::JSThreadType::MAIN_THREAD));
4341 }
4342 
4343 /**
4344  * @tc.name: runEventLoopTest008
4345  * @tc.desc: Test napi_run_event_loop with worker thread.
4346  * @tc.type: FUNC
4347  */
HWTEST_F(NapiBasicTest, runEventLoopTest008, testing::ext::TestSize.Level1)4348 HWTEST_F(NapiBasicTest, runEventLoopTest008, testing::ext::TestSize.Level1)
4349 {
4350     ASSERT_NE(engine_, nullptr);
4351     engine_->MarkWorkerThread();
4352     napi_env env = (napi_env)engine_;
4353     // worker thread does not support napi_run_event_loop func
4354     napi_status res = napi_run_event_loop(env, napi_event_mode_default);
4355     ASSERT_EQ(res, napi_generic_failure);
4356     engine_->jsThreadType_ = panda::panda_file::DataProtect(uintptr_t(NativeEngine::JSThreadType::MAIN_THREAD));
4357 }
4358 
4359 /**
4360  * @tc.name: runEventLoopTest009
4361  * @tc.desc: Test napi_run_event_loop with taskpool thread.
4362  * @tc.type: FUNC
4363  */
HWTEST_F(NapiBasicTest, runEventLoopTest009, testing::ext::TestSize.Level1)4364 HWTEST_F(NapiBasicTest, runEventLoopTest009, testing::ext::TestSize.Level1)
4365 {
4366     ASSERT_NE(engine_, nullptr);
4367     engine_->MarkTaskPoolThread();
4368     napi_env env = (napi_env)engine_;
4369     // taskpool thread does not support napi_run_event_loop func
4370     napi_status res = napi_run_event_loop(env, napi_event_mode_nowait);
4371     ASSERT_EQ(res, napi_generic_failure);
4372     engine_->jsThreadType_ = panda::panda_file::DataProtect(uintptr_t(NativeEngine::JSThreadType::MAIN_THREAD));
4373 }
4374 
4375 /**
4376  * @tc.name: runEventLoopTest010
4377  * @tc.desc: Test napi_run_event_loop with taskpool thread.
4378  * @tc.type: FUNC
4379  */
HWTEST_F(NapiBasicTest, runEventLoopTest010, testing::ext::TestSize.Level1)4380 HWTEST_F(NapiBasicTest, runEventLoopTest010, testing::ext::TestSize.Level1)
4381 {
4382     ASSERT_NE(engine_, nullptr);
4383     engine_->MarkTaskPoolThread();
4384     napi_env env = (napi_env)engine_;
4385     // taskpool thread does not support napi_run_event_loop func
4386     napi_status res = napi_run_event_loop(env, napi_event_mode_default);
4387     ASSERT_EQ(res, napi_generic_failure);
4388     engine_->jsThreadType_ = panda::panda_file::DataProtect(uintptr_t(NativeEngine::JSThreadType::MAIN_THREAD));
4389 }
4390 
4391 /**
4392  * @tc.name: stopEventLoopTest001
4393  * @tc.desc: Test napi_stop_event_loop with nullptr env.
4394  * @tc.type: FUNC
4395  */
HWTEST_F(NapiBasicTest, stopEventLoopTest001, testing::ext::TestSize.Level1)4396 HWTEST_F(NapiBasicTest, stopEventLoopTest001, testing::ext::TestSize.Level1)
4397 {
4398     napi_status res = napi_stop_event_loop(nullptr);
4399     ASSERT_EQ(res, napi_invalid_arg);
4400 }
4401 
4402 /**
4403  * @tc.name: stopEventLoopTest002
4404  * @tc.desc: Test napi_stop_event_loop with nullptr loop.
4405  * @tc.type: FUNC
4406  */
HWTEST_F(NapiBasicTest, stopEventLoopTest002, testing::ext::TestSize.Level1)4407 HWTEST_F(NapiBasicTest, stopEventLoopTest002, testing::ext::TestSize.Level1)
4408 {
4409     ASSERT_NE(engine_, nullptr);
4410     NativeEngineProxy engine;
4411     engine->Deinit();
4412     napi_status res = napi_stop_event_loop(napi_env(engine));
4413     engine->Init();
4414     ASSERT_EQ(res, napi_invalid_arg);
4415 }
4416 
4417 /**
4418  * @tc.name: stopEventLoopTest003
4419  * @tc.desc: Test napi_stop_event_loop with main thread.
4420  * @tc.type: FUNC
4421  */
HWTEST_F(NapiBasicTest, stopEventLoopTest003, testing::ext::TestSize.Level1)4422 HWTEST_F(NapiBasicTest, stopEventLoopTest003, testing::ext::TestSize.Level1)
4423 {
4424     ASSERT_NE(engine_, nullptr);
4425     napi_env env = (napi_env)engine_;
4426     // main thread does not support napi_run_event_loop func
4427     napi_status res = napi_stop_event_loop(env);
4428     ASSERT_EQ(res, napi_generic_failure);
4429 }
4430 
4431 /**
4432  * @tc.name: stopEventLoopTest004
4433  * @tc.desc: Test napi_stop_event_loop with worker thread.
4434  * @tc.type: FUNC
4435  */
HWTEST_F(NapiBasicTest, stopEventLoopTest004, testing::ext::TestSize.Level1)4436 HWTEST_F(NapiBasicTest, stopEventLoopTest004, testing::ext::TestSize.Level1)
4437 {
4438     ASSERT_NE(engine_, nullptr);
4439     engine_->MarkWorkerThread();
4440     napi_env env = (napi_env)engine_;
4441     // worker thread does not support napi_run_event_loop func
4442     napi_status res = napi_stop_event_loop(env);
4443     ASSERT_EQ(res, napi_generic_failure);
4444     engine_->jsThreadType_ = panda::panda_file::DataProtect(uintptr_t(NativeEngine::JSThreadType::MAIN_THREAD));
4445 }
4446 
4447 /**
4448  * @tc.name: stopEventLoopTest005
4449  * @tc.desc: Test napi_stop_event_loop with taskpool thread.
4450  * @tc.type: FUNC
4451  */
HWTEST_F(NapiBasicTest, stopEventLoopTest005, testing::ext::TestSize.Level1)4452 HWTEST_F(NapiBasicTest, stopEventLoopTest005, testing::ext::TestSize.Level1)
4453 {
4454     ASSERT_NE(engine_, nullptr);
4455     engine_->MarkTaskPoolThread();
4456     napi_env env = (napi_env)engine_;
4457     // taskpool thread does not support napi_run_event_loop func
4458     napi_status res = napi_stop_event_loop(env);
4459     ASSERT_EQ(res, napi_generic_failure);
4460     engine_->jsThreadType_ = panda::panda_file::DataProtect(uintptr_t(NativeEngine::JSThreadType::MAIN_THREAD));
4461 }
4462 
4463 /**
4464  * @tc.name: stopEventLoopTest006
4465  * @tc.desc: Test napi_stop_event_loop before running the loop.
4466  * @tc.type: FUNC
4467  */
HWTEST_F(NapiBasicTest, stopEventLoopTest006, testing::ext::TestSize.Level1)4468 HWTEST_F(NapiBasicTest, stopEventLoopTest006, testing::ext::TestSize.Level1)
4469 {
4470     ASSERT_NE(engine_, nullptr);
4471     engine_->MarkNativeThread();
4472     napi_env env = (napi_env)engine_;
4473     napi_status res = napi_stop_event_loop(env);
4474     ASSERT_EQ(res, napi_ok);
4475     engine_->jsThreadType_ = panda::panda_file::DataProtect(uintptr_t(NativeEngine::JSThreadType::MAIN_THREAD));
4476 }
4477 
4478 /**
4479  * @tc.name: multipleThreadRunEventLoopTest001
4480  * @tc.desc: Test napi_run_event_loop with multiple threads.
4481  * @tc.type: FUNC
4482  */
HWTEST_F(NapiBasicTest, multipleThreadRunEventLoopTest001, testing::ext::TestSize.Level1)4483 HWTEST_F(NapiBasicTest, multipleThreadRunEventLoopTest001, testing::ext::TestSize.Level1)
4484 {
4485     ASSERT_NE(engine_, nullptr);
4486     engine_->MarkNativeThread();
4487     napi_env env = (napi_env)engine_;
4488 
4489     // 1. create five child threads to call napi_run_event_loop
4490     auto runFunc = [](const napi_env &env, napi_event_mode mode) {
4491         napi_status res = napi_run_event_loop(env, mode);
4492         ASSERT_EQ(res, napi_ok);
4493     };
4494 
4495     for (int32_t index = 0; index < THREAD_SIZE; ++index) {
4496         std::thread runThread = std::thread(runFunc, std::ref(env), napi_event_mode_nowait);
4497         runThread.detach();
4498     }
4499     // 2. create async work to stop the loop
4500     struct AsyncWorkContext {
4501         napi_async_work work = nullptr;
4502     };
4503     auto asyncWorkContext = new AsyncWorkContext();
4504     napi_value resourceName = nullptr;
4505     napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
4506     napi_create_async_work(
4507         env, nullptr, resourceName, [](napi_env env, void* data) { },
4508         [](napi_env env, napi_status status, void* data) {
4509             AsyncWorkContext* asyncWorkContext = (AsyncWorkContext*)data;
4510             napi_delete_async_work(env, asyncWorkContext->work);
4511             delete asyncWorkContext;
4512             // stop the loop after the task is processed
4513             napi_status res = napi_stop_event_loop(env);
4514             ASSERT_EQ(res, napi_ok);
4515         },
4516         asyncWorkContext, &asyncWorkContext->work);
4517     napi_queue_async_work(env, asyncWorkContext->work);
4518     // 3. run the loop
4519     napi_status res = napi_run_event_loop(env, napi_event_mode_default);
4520     ASSERT_EQ(res, napi_ok);
4521     engine_->jsThreadType_ = panda::panda_file::DataProtect(uintptr_t(NativeEngine::JSThreadType::MAIN_THREAD));
4522 }
4523 
4524 /**
4525  * @tc.name: NapiFatalExceptionTest
4526  * @tc.desc: Test interface of napi_fatal_exception
4527  * @tc.type: FUNC
4528  */
HWTEST_F(NapiBasicTest, NapiFatalExceptionTest001, testing::ext::TestSize.Level1)4529 HWTEST_F(NapiBasicTest, NapiFatalExceptionTest001, testing::ext::TestSize.Level1)
4530 {
4531     ASSERT_NE(engine_, nullptr);
4532     napi_env env = reinterpret_cast<napi_env>(engine_);
4533     // create error object
4534     napi_value code = nullptr;
4535     constexpr char codeStr[] = "test code";
4536     napi_status res = napi_create_string_utf8(env, codeStr, NAPI_AUTO_LENGTH, &code);
4537     ASSERT_EQ(res, napi_ok);
4538 
4539     napi_value msg = nullptr;
4540     constexpr char msgStr[] = "test message";
4541     res = napi_create_string_utf8(env, msgStr, NAPI_AUTO_LENGTH, &msg);
4542     ASSERT_EQ(res, napi_ok);
4543 
4544     napi_value error = nullptr;
4545     res = napi_create_error(env, code, msg, &error);
4546     ASSERT_EQ(res, napi_ok);
4547 
4548     // call napi_fatal_exception interface with nullptr env
4549     res = napi_fatal_exception(nullptr, error);
4550     ASSERT_EQ(res, napi_invalid_arg);
4551 }
4552 
4553 /**
4554  * @tc.name: NapiFatalExceptionTest
4555  * @tc.desc: Test interface of napi_fatal_exception
4556  * @tc.type: FUNC
4557  */
HWTEST_F(NapiBasicTest, NapiFatalExceptionTest002, testing::ext::TestSize.Level1)4558 HWTEST_F(NapiBasicTest, NapiFatalExceptionTest002, testing::ext::TestSize.Level1)
4559 {
4560     ASSERT_NE(engine_, nullptr);
4561     napi_env env = reinterpret_cast<napi_env>(engine_);
4562     // create error object
4563     napi_value code = nullptr;
4564     constexpr char codeStr[] = "test code";
4565     napi_status res = napi_create_string_utf8(env, codeStr, NAPI_AUTO_LENGTH, &code);
4566     ASSERT_EQ(res, napi_ok);
4567 
4568     // call napi_fatal_exception interface with non-JSError object
4569     res = napi_fatal_exception(env, code);
4570     ASSERT_EQ(res, napi_invalid_arg);
4571 }
4572 
4573 /**
4574  * @tc.name: NapiFatalExceptionTest
4575  * @tc.desc: Test interface of napi_fatal_exception
4576  * @tc.type: FUNC
4577  */
HWTEST_F(NapiBasicTest, NapiFatalExceptionTest003, testing::ext::TestSize.Level1)4578 HWTEST_F(NapiBasicTest, NapiFatalExceptionTest003, testing::ext::TestSize.Level1)
4579 {
4580     ASSERT_NE(engine_, nullptr);
4581     napi_env env = reinterpret_cast<napi_env>(engine_);
4582 
4583     // call napi_fatal_exception interface with nullptr error
4584     auto res = napi_fatal_exception(env, nullptr);
4585     ASSERT_EQ(res, napi_invalid_arg);
4586 }
4587 
4588 /**
4589  * @tc.name: NapiFatalExceptionTest
4590  * @tc.desc: Test interface of napi_coerce_to_bool
4591  * @tc.type: FUNC
4592  */
HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest001, testing::ext::TestSize.Level1)4593 HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest001, testing::ext::TestSize.Level1)
4594 {
4595     napi_env env = reinterpret_cast<napi_env>(engine_);
4596     napi_value value = nullptr;
4597     napi_value result;
4598     napi_status status = napi_coerce_to_bool(env, value, &result);
4599     ASSERT_EQ(status, napi_invalid_arg);
4600 }
4601 
HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest002, testing::ext::TestSize.Level1)4602 HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest002, testing::ext::TestSize.Level1)
4603 {
4604     napi_env env = reinterpret_cast<napi_env>(engine_);
4605     napi_value value;
4606     napi_value *result = nullptr;
4607     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4608     status = napi_coerce_to_bool(env, value, result);
4609     ASSERT_EQ(status, napi_invalid_arg);
4610 }
4611 
4612 /**
4613  * @tc.name: NapiFatalExceptionTest
4614  * @tc.desc: Test interface of napi_coerce_to_bool
4615  * @tc.type: FUNC
4616  */
HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest003, testing::ext::TestSize.Level1)4617 HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest003, testing::ext::TestSize.Level1)
4618 {
4619     napi_env env = reinterpret_cast<napi_env>(engine_);
4620     napi_value value;
4621     napi_value result;
4622     napi_status status = napi_create_double(env, NAN, &value);
4623     status = napi_coerce_to_bool(env, value, &result);
4624     bool ret = true;
4625     napi_get_value_bool(env, result, &ret);
4626     ASSERT_EQ(ret, false);
4627     ASSERT_EQ(status, napi_ok);
4628 }
4629 /**
4630  * @tc.name: NapiFatalExceptionTest
4631  * @tc.desc: Test interface of napi_coerce_to_bool
4632  * @tc.type: FUNC
4633  */
HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest004, testing::ext::TestSize.Level1)4634 HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest004, testing::ext::TestSize.Level1)
4635 {
4636     napi_env env = reinterpret_cast<napi_env>(engine_);
4637     napi_value value;
4638     napi_value result;
4639     napi_status status = napi_get_undefined(env, &value);
4640     status = napi_coerce_to_bool(env, value, &result);
4641     bool ret = true;
4642     napi_get_value_bool(env, result, &ret);
4643     ASSERT_EQ(ret, false);
4644     ASSERT_EQ(status, napi_ok);
4645 }
4646 
4647 /**
4648  * @tc.name: NapiFatalExceptionTest
4649  * @tc.desc: Test interface of napi_coerce_to_bool
4650  * @tc.type: FUNC
4651  */
HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest005, testing::ext::TestSize.Level1)4652 HWTEST_F(NapiBasicTest, NapiCoerceToBoolTest005, testing::ext::TestSize.Level1)
4653 {
4654     napi_env env = reinterpret_cast<napi_env>(engine_);
4655     napi_value value;
4656     napi_value result;
4657     napi_status status = napi_get_null(env, &value);
4658     status = napi_coerce_to_bool(env, value, &result);
4659     bool ret = true;
4660     napi_get_value_bool(env, result, &ret);
4661     ASSERT_EQ(ret, false);
4662     ASSERT_EQ(status, napi_ok);
4663 }
4664 
HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest001, testing::ext::TestSize.Level1)4665 HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest001, testing::ext::TestSize.Level1)
4666 {
4667     napi_env env = reinterpret_cast<napi_env>(engine_);
4668     napi_value value = nullptr;
4669     napi_value result;
4670     napi_status status = napi_coerce_to_number(env, value, &result);
4671     ASSERT_EQ(status, napi_invalid_arg);
4672 }
4673 
HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest002, testing::ext::TestSize.Level1)4674 HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest002, testing::ext::TestSize.Level1)
4675 {
4676     napi_env env = reinterpret_cast<napi_env>(engine_);
4677     napi_value value;
4678     napi_value *result = nullptr;
4679     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4680     status = napi_coerce_to_number(env, value, result);
4681     ASSERT_EQ(status, napi_invalid_arg);
4682 }
4683 
HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest003, testing::ext::TestSize.Level1)4684 HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest003, testing::ext::TestSize.Level1)
4685 {
4686     napi_env env = reinterpret_cast<napi_env>(engine_);
4687     napi_value value;
4688     napi_value result;
4689     napi_status status = napi_create_string_utf8(env, "", 0, &value);
4690     status = napi_coerce_to_number(env, value, &result);
4691     ASSERT_EQ(status, napi_ok);
4692     int32_t num;
4693     status = napi_get_value_int32(env, result, &num);
4694     ASSERT_EQ(num, 0);
4695 }
4696 
HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest004, testing::ext::TestSize.Level1)4697 HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest004, testing::ext::TestSize.Level1)
4698 {
4699     napi_env env = reinterpret_cast<napi_env>(engine_);
4700     napi_value value;
4701     napi_value result;
4702     napi_status status = napi_create_string_utf8(env, TEST_STRING, 4, &value);
4703     status = napi_coerce_to_number(env, value, &result);
4704     ASSERT_EQ(status, napi_ok);
4705     double db;
4706     status = napi_get_value_double(env, result, &db);
4707     ASSERT_EQ(std::isnan(db), true);
4708 }
4709 
HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest005, testing::ext::TestSize.Level1)4710 HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest005, testing::ext::TestSize.Level1)
4711 {
4712     napi_env env = reinterpret_cast<napi_env>(engine_);
4713     napi_value value;
4714     napi_value result;
4715     napi_status status = napi_get_undefined(env, &value);
4716     status = napi_coerce_to_number(env, value, &result);
4717     ASSERT_EQ(status, napi_ok);
4718     double db;
4719     status = napi_get_value_double(env, result, &db);
4720     ASSERT_EQ(std::isnan(db), true);
4721 }
4722 
HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest006, testing::ext::TestSize.Level1)4723 HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest006, testing::ext::TestSize.Level1)
4724 {
4725     napi_env env = reinterpret_cast<napi_env>(engine_);
4726     napi_value value;
4727     napi_value result;
4728     napi_status status = napi_get_null(env, &value);
4729     status = napi_coerce_to_number(env, value, &result);
4730     ASSERT_EQ(status, napi_ok);
4731     int32_t num;
4732     status = napi_get_value_int32(env, result, &num);
4733     ASSERT_EQ(num, 0);
4734 }
4735 
HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest007, testing::ext::TestSize.Level1)4736 HWTEST_F(NapiBasicTest, NapiCoerceToNumberTest007, testing::ext::TestSize.Level1)
4737 {
4738     napi_env env = reinterpret_cast<napi_env>(engine_);
4739     napi_value value;
4740     napi_value result;
4741     napi_status status = napi_create_object(env, &value);
4742     status = napi_coerce_to_number(env, value, &result);
4743     ASSERT_EQ(status, napi_ok);
4744     double db;
4745     status = napi_get_value_double(env, result, &db);
4746     ASSERT_EQ(std::isnan(db), true);
4747 }
4748 
HWTEST_F(NapiBasicTest, NapiCoerceToObjectTest001, testing::ext::TestSize.Level1)4749 HWTEST_F(NapiBasicTest, NapiCoerceToObjectTest001, testing::ext::TestSize.Level1)
4750 {
4751     napi_env env = reinterpret_cast<napi_env>(engine_);
4752     napi_value value = nullptr;
4753     napi_value result;
4754     napi_status status = napi_coerce_to_object(env, value, &result);
4755     ASSERT_EQ(status, napi_invalid_arg);
4756 }
4757 
HWTEST_F(NapiBasicTest, NapiCoerceToObjectTest002, testing::ext::TestSize.Level1)4758 HWTEST_F(NapiBasicTest, NapiCoerceToObjectTest002, testing::ext::TestSize.Level1)
4759 {
4760     napi_env env = reinterpret_cast<napi_env>(engine_);
4761     napi_value value;
4762     napi_value *result = nullptr;
4763     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4764     status = napi_coerce_to_object(env, value, result);
4765     ASSERT_EQ(status, napi_invalid_arg);
4766 }
4767 
HWTEST_F(NapiBasicTest, NapiCoerceToObjectTest003, testing::ext::TestSize.Level1)4768 HWTEST_F(NapiBasicTest, NapiCoerceToObjectTest003, testing::ext::TestSize.Level1)
4769 {
4770     napi_env env = reinterpret_cast<napi_env>(engine_);
4771     napi_value value;
4772     napi_value result;
4773     napi_status status = napi_get_undefined(env, &value);
4774     status = napi_coerce_to_object(env, value, &result);
4775     ASSERT_EQ(status, napi_ok);
4776     napi_valuetype type = napi_undefined;
4777     status = napi_typeof(env, result, &type);
4778     ASSERT_EQ(status, napi_ok);
4779     ASSERT_EQ(type, napi_undefined);
4780 }
4781 
HWTEST_F(NapiBasicTest, NapiCoerceToObjectTest004, testing::ext::TestSize.Level1)4782 HWTEST_F(NapiBasicTest, NapiCoerceToObjectTest004, testing::ext::TestSize.Level1)
4783 {
4784     napi_env env = reinterpret_cast<napi_env>(engine_);
4785     napi_value value;
4786     napi_value result;
4787     napi_status status = napi_get_null(env, &value);
4788     status = napi_coerce_to_object(env, value, &result);
4789     ASSERT_EQ(status, napi_ok);
4790     napi_valuetype type = napi_undefined;
4791     status = napi_typeof(env, result, &type);
4792     ASSERT_EQ(status, napi_ok);
4793     ASSERT_EQ(type, napi_undefined);
4794 }
4795 
HWTEST_F(NapiBasicTest, NapiCoerceToStringTest001, testing::ext::TestSize.Level1)4796 HWTEST_F(NapiBasicTest, NapiCoerceToStringTest001, testing::ext::TestSize.Level1)
4797 {
4798     napi_env env = reinterpret_cast<napi_env>(engine_);
4799     napi_value value = nullptr;
4800     napi_value result;
4801     napi_status status = napi_coerce_to_string(env, value, &result);
4802     ASSERT_EQ(status, napi_invalid_arg);
4803 }
4804 
HWTEST_F(NapiBasicTest, NapiCoerceToStringTest002, testing::ext::TestSize.Level1)4805 HWTEST_F(NapiBasicTest, NapiCoerceToStringTest002, testing::ext::TestSize.Level1)
4806 {
4807     napi_env env = reinterpret_cast<napi_env>(engine_);
4808     napi_value value;
4809     napi_value *result = nullptr;
4810     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4811     status = napi_coerce_to_string(env, value, result);
4812     ASSERT_EQ(status, napi_invalid_arg);
4813 }
4814 
HWTEST_F(NapiBasicTest, NapiTypeofTest001, testing::ext::TestSize.Level1)4815 HWTEST_F(NapiBasicTest, NapiTypeofTest001, testing::ext::TestSize.Level1)
4816 {
4817     napi_env env = reinterpret_cast<napi_env>(engine_);
4818     napi_value value = nullptr;
4819     napi_valuetype result;
4820     napi_status status = napi_typeof(env, value, &result);
4821     ASSERT_EQ(status, napi_invalid_arg);
4822 }
4823 
HWTEST_F(NapiBasicTest, NapiTypeofTest002, testing::ext::TestSize.Level1)4824 HWTEST_F(NapiBasicTest, NapiTypeofTest002, testing::ext::TestSize.Level1)
4825 {
4826     napi_env env = reinterpret_cast<napi_env>(engine_);
4827     napi_value value;
4828     napi_valuetype *result = nullptr;
4829     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4830     status = napi_typeof(env, value, result);
4831     ASSERT_EQ(status, napi_invalid_arg);
4832 }
4833 
HWTEST_F(NapiBasicTest, NapiInstanceofTest001, testing::ext::TestSize.Level1)4834 HWTEST_F(NapiBasicTest, NapiInstanceofTest001, testing::ext::TestSize.Level1)
4835 {
4836     napi_env env = reinterpret_cast<napi_env>(engine_);
4837     napi_value value = nullptr;
4838     napi_value constructor;
4839     bool result;
4840     napi_status status = napi_create_object(env, &constructor);
4841     status = napi_instanceof(env, value, constructor, &result);
4842     ASSERT_EQ(status, napi_invalid_arg);
4843 }
4844 
HWTEST_F(NapiBasicTest, NapiInstanceofTest002, testing::ext::TestSize.Level1)4845 HWTEST_F(NapiBasicTest, NapiInstanceofTest002, testing::ext::TestSize.Level1)
4846 {
4847     napi_env env = reinterpret_cast<napi_env>(engine_);
4848     napi_value value;
4849     napi_value constructor = nullptr;
4850     bool result;
4851     napi_status status = napi_create_object(env, &value);
4852     status = napi_instanceof(env, value, constructor, &result);
4853     ASSERT_EQ(status, napi_invalid_arg);
4854 }
4855 
HWTEST_F(NapiBasicTest, NapiInstanceofTest003, testing::ext::TestSize.Level1)4856 HWTEST_F(NapiBasicTest, NapiInstanceofTest003, testing::ext::TestSize.Level1)
4857 {
4858     napi_env env = reinterpret_cast<napi_env>(engine_);
4859     napi_value value;
4860     napi_value constructor;
4861     bool *result = nullptr;
4862     napi_status status = napi_create_object(env, &value);
4863     status = napi_create_object(env, &constructor);
4864     status = napi_instanceof(env, value, constructor, result);
4865     ASSERT_EQ(status, napi_invalid_arg);
4866 }
4867 
HWTEST_F(NapiBasicTest, NapiInstanceofTest004, testing::ext::TestSize.Level1)4868 HWTEST_F(NapiBasicTest, NapiInstanceofTest004, testing::ext::TestSize.Level1)
4869 {
4870     napi_env env = reinterpret_cast<napi_env>(engine_);
4871     napi_value value;
4872     napi_value constructor;
4873     bool result;
4874     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4875     status = napi_create_object(env, &constructor);
4876     status = napi_instanceof(env, value, constructor, &result);
4877     ASSERT_EQ(status, napi_object_expected);
4878 }
4879 
HWTEST_F(NapiBasicTest, NapiInstanceofTest005, testing::ext::TestSize.Level1)4880 HWTEST_F(NapiBasicTest, NapiInstanceofTest005, testing::ext::TestSize.Level1)
4881 {
4882     napi_env env = reinterpret_cast<napi_env>(engine_);
4883     napi_value value;
4884     napi_value constructor;
4885     bool result;
4886     napi_status status = napi_create_object(env, &value);
4887     status = napi_create_double(env, TEST_DOUBLE, &constructor);
4888     status = napi_instanceof(env, value, constructor, &result);
4889     ASSERT_EQ(status, napi_function_expected);
4890 }
4891 
HWTEST_F(NapiBasicTest, NapiIsArrayTest001, testing::ext::TestSize.Level1)4892 HWTEST_F(NapiBasicTest, NapiIsArrayTest001, testing::ext::TestSize.Level1)
4893 {
4894     napi_env env = reinterpret_cast<napi_env>(engine_);
4895     napi_value value = nullptr;
4896     bool result;
4897     napi_status status = napi_is_array(env, value, &result);
4898     ASSERT_EQ(status, napi_invalid_arg);
4899 }
4900 
HWTEST_F(NapiBasicTest, NapiIsArrayTest002, testing::ext::TestSize.Level1)4901 HWTEST_F(NapiBasicTest, NapiIsArrayTest002, testing::ext::TestSize.Level1)
4902 {
4903     napi_env env = reinterpret_cast<napi_env>(engine_);
4904     napi_value value;
4905     bool *result = nullptr;
4906     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4907     status = napi_is_array(env, value, result);
4908     ASSERT_EQ(status, napi_invalid_arg);
4909 }
4910 
HWTEST_F(NapiBasicTest, NapiIsArrayBufferTest001, testing::ext::TestSize.Level1)4911 HWTEST_F(NapiBasicTest, NapiIsArrayBufferTest001, testing::ext::TestSize.Level1)
4912 {
4913     napi_env env = reinterpret_cast<napi_env>(engine_);
4914     napi_value value = nullptr;
4915     bool result;
4916     napi_status status = napi_is_arraybuffer(env, value, &result);
4917     ASSERT_EQ(status, napi_invalid_arg);
4918 }
4919 
HWTEST_F(NapiBasicTest, NapiIsArrayBufferTest002, testing::ext::TestSize.Level1)4920 HWTEST_F(NapiBasicTest, NapiIsArrayBufferTest002, testing::ext::TestSize.Level1)
4921 {
4922     napi_env env = reinterpret_cast<napi_env>(engine_);
4923     napi_value value;
4924     bool *result = nullptr;
4925     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4926     status = napi_is_arraybuffer(env, value, result);
4927     ASSERT_EQ(status, napi_invalid_arg);
4928 }
4929 
HWTEST_F(NapiBasicTest, NapiIsTypeBufferTest001, testing::ext::TestSize.Level1)4930 HWTEST_F(NapiBasicTest, NapiIsTypeBufferTest001, testing::ext::TestSize.Level1)
4931 {
4932     napi_env env = reinterpret_cast<napi_env>(engine_);
4933     napi_value value = nullptr;
4934     bool result;
4935     napi_status status = napi_is_typedarray(env, value, &result);
4936     ASSERT_EQ(status, napi_invalid_arg);
4937 }
4938 
HWTEST_F(NapiBasicTest, NapiIsTypeBufferTest002, testing::ext::TestSize.Level1)4939 HWTEST_F(NapiBasicTest, NapiIsTypeBufferTest002, testing::ext::TestSize.Level1)
4940 {
4941     napi_env env = reinterpret_cast<napi_env>(engine_);
4942     napi_value value;
4943     bool *result = nullptr;
4944     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4945     status = napi_is_typedarray(env, value, result);
4946     ASSERT_EQ(status, napi_invalid_arg);
4947 }
4948 
HWTEST_F(NapiBasicTest, NapiIsDataViewTest001, testing::ext::TestSize.Level1)4949 HWTEST_F(NapiBasicTest, NapiIsDataViewTest001, testing::ext::TestSize.Level1)
4950 {
4951     napi_env env = reinterpret_cast<napi_env>(engine_);
4952     napi_value value = nullptr;
4953     bool result;
4954     napi_status status = napi_is_dataview(env, value, &result);
4955     ASSERT_EQ(status, napi_invalid_arg);
4956 }
4957 
HWTEST_F(NapiBasicTest, NapiIsDataViewTest002, testing::ext::TestSize.Level1)4958 HWTEST_F(NapiBasicTest, NapiIsDataViewTest002, testing::ext::TestSize.Level1)
4959 {
4960     napi_env env = reinterpret_cast<napi_env>(engine_);
4961     napi_value value;
4962     bool *result = nullptr;
4963     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4964     status = napi_is_dataview(env, value, result);
4965     ASSERT_EQ(status, napi_invalid_arg);
4966 }
4967 
HWTEST_F(NapiBasicTest, NapiIsDateTest001, testing::ext::TestSize.Level1)4968 HWTEST_F(NapiBasicTest, NapiIsDateTest001, testing::ext::TestSize.Level1)
4969 {
4970     napi_env env = reinterpret_cast<napi_env>(engine_);
4971     napi_value value = nullptr;
4972     bool result;
4973     napi_status status = napi_is_date(env, value, &result);
4974     ASSERT_EQ(status, napi_invalid_arg);
4975 }
4976 
HWTEST_F(NapiBasicTest, NapiIsDateTest002, testing::ext::TestSize.Level1)4977 HWTEST_F(NapiBasicTest, NapiIsDateTest002, testing::ext::TestSize.Level1)
4978 {
4979     napi_env env = reinterpret_cast<napi_env>(engine_);
4980     napi_value value;
4981     bool *result = nullptr;
4982     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
4983     status = napi_is_date(env, value, result);
4984     ASSERT_EQ(status, napi_invalid_arg);
4985 }
4986 
HWTEST_F(NapiBasicTest, NapiStrictEqualsTest001, testing::ext::TestSize.Level1)4987 HWTEST_F(NapiBasicTest, NapiStrictEqualsTest001, testing::ext::TestSize.Level1)
4988 {
4989     napi_env env = reinterpret_cast<napi_env>(engine_);
4990     napi_value lhs = nullptr;
4991     napi_value rhs;
4992     bool result;
4993     napi_status status = napi_create_double(env, TEST_DOUBLE, &rhs);
4994     status = napi_strict_equals(env, lhs, rhs, &result);
4995     ASSERT_EQ(status, napi_invalid_arg);
4996 }
4997 
HWTEST_F(NapiBasicTest, NapiStrictEqualsTest002, testing::ext::TestSize.Level1)4998 HWTEST_F(NapiBasicTest, NapiStrictEqualsTest002, testing::ext::TestSize.Level1)
4999 {
5000     napi_env env = reinterpret_cast<napi_env>(engine_);
5001     napi_value lhs;
5002     napi_value rhs = nullptr;
5003     bool result;
5004     napi_status status = napi_create_double(env, TEST_DOUBLE, &lhs);
5005     status = napi_strict_equals(env, lhs, rhs, &result);
5006     ASSERT_EQ(status, napi_invalid_arg);
5007 }
5008 
HWTEST_F(NapiBasicTest, NapiStrictEqualsTest003, testing::ext::TestSize.Level1)5009 HWTEST_F(NapiBasicTest, NapiStrictEqualsTest003, testing::ext::TestSize.Level1)
5010 {
5011     napi_env env = reinterpret_cast<napi_env>(engine_);
5012     napi_value lhs;
5013     napi_value rhs;
5014     bool *result = nullptr;
5015     napi_status status = napi_create_double(env, TEST_DOUBLE, &lhs);
5016     status = napi_create_double(env, TEST_DOUBLE, &rhs);
5017     status = napi_strict_equals(env, lhs, rhs, result);
5018     ASSERT_EQ(status, napi_invalid_arg);
5019 }
5020 
HWTEST_F(NapiBasicTest, NapiStrictEqualsTest004, testing::ext::TestSize.Level1)5021 HWTEST_F(NapiBasicTest, NapiStrictEqualsTest004, testing::ext::TestSize.Level1)
5022 {
5023     napi_env env = reinterpret_cast<napi_env>(engine_);
5024     napi_value lhs;
5025     napi_value rhs;
5026     bool result;
5027     napi_status status = napi_create_double(env, NAN, &lhs);
5028     status = napi_create_double(env, NAN, &rhs);
5029     status = napi_strict_equals(env, lhs, rhs, &result);
5030     ASSERT_EQ(status, false);
5031 }
5032 
HWTEST_F(NapiBasicTest, NapiGetPropertyNamesTest001, testing::ext::TestSize.Level1)5033 HWTEST_F(NapiBasicTest, NapiGetPropertyNamesTest001, testing::ext::TestSize.Level1)
5034 {
5035     napi_env env = reinterpret_cast<napi_env>(engine_);
5036     napi_value value = nullptr;
5037     napi_value result;
5038     napi_status status = napi_get_property_names(env, value, &result);
5039     ASSERT_EQ(status, napi_invalid_arg);
5040 }
5041 
HWTEST_F(NapiBasicTest, NapiGetPropertyNamesTest002, testing::ext::TestSize.Level1)5042 HWTEST_F(NapiBasicTest, NapiGetPropertyNamesTest002, testing::ext::TestSize.Level1)
5043 {
5044     napi_env env = reinterpret_cast<napi_env>(engine_);
5045     napi_value value;
5046     napi_value *result = nullptr;
5047     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
5048     status = napi_get_property_names(env, value, result);
5049     ASSERT_EQ(status, napi_invalid_arg);
5050 }
5051 
HWTEST_F(NapiBasicTest, NapiGetPropertyNamesTest003, testing::ext::TestSize.Level1)5052 HWTEST_F(NapiBasicTest, NapiGetPropertyNamesTest003, testing::ext::TestSize.Level1)
5053 {
5054     napi_env env = reinterpret_cast<napi_env>(engine_);
5055     napi_value value;
5056     napi_value result;
5057     napi_status status = napi_create_double(env, TEST_DOUBLE, &value);
5058     status = napi_get_property_names(env, value, &result);
5059     ASSERT_EQ(status, napi_object_expected);
5060 }
5061 
HWTEST_F(NapiBasicTest, NapiSetPropertyTest001, testing::ext::TestSize.Level1)5062 HWTEST_F(NapiBasicTest, NapiSetPropertyTest001, testing::ext::TestSize.Level1)
5063 {
5064     napi_env env = reinterpret_cast<napi_env>(engine_);
5065     napi_value obj = nullptr;
5066     napi_value key;
5067     napi_value value;
5068 
5069     napi_create_int32(env, INT_ONE, &key);
5070     napi_create_int32(env, INT_TWO, &value);
5071     napi_status status = napi_set_property(env, obj, key, value);
5072     ASSERT_EQ(status, napi_invalid_arg);
5073 }
5074 
HWTEST_F(NapiBasicTest, NapiSetPropertyTest002, testing::ext::TestSize.Level1)5075 HWTEST_F(NapiBasicTest, NapiSetPropertyTest002, testing::ext::TestSize.Level1)
5076 {
5077     napi_env env = reinterpret_cast<napi_env>(engine_);
5078     napi_value obj;
5079     napi_value key = nullptr;
5080     napi_value value;
5081 
5082     napi_create_object(env, &obj);
5083     napi_create_int32(env, INT_TWO, &value);
5084     napi_status status = napi_set_property(env, obj, key, value);
5085     ASSERT_EQ(status, napi_invalid_arg);
5086 }
5087 
HWTEST_F(NapiBasicTest, NapiSetPropertyTest003, testing::ext::TestSize.Level1)5088 HWTEST_F(NapiBasicTest, NapiSetPropertyTest003, testing::ext::TestSize.Level1)
5089 {
5090     napi_env env = reinterpret_cast<napi_env>(engine_);
5091     napi_value obj;
5092     napi_value key;
5093     napi_value value = nullptr;
5094 
5095     napi_create_object(env, &obj);
5096     napi_create_int32(env, INT_ONE, &key);
5097     napi_status status = napi_set_property(env, obj, key, value);
5098     ASSERT_EQ(status, napi_invalid_arg);
5099 }
5100 
HWTEST_F(NapiBasicTest, NapiSetPropertyTest004, testing::ext::TestSize.Level1)5101 HWTEST_F(NapiBasicTest, NapiSetPropertyTest004, testing::ext::TestSize.Level1)
5102 {
5103     napi_env env = reinterpret_cast<napi_env>(engine_);
5104     napi_value obj;
5105     napi_value key;
5106     napi_value value;
5107 
5108     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5109     napi_create_int32(env, INT_ONE, &key);
5110     napi_create_int32(env, INT_TWO, &value);
5111     status = napi_set_property(env, obj, key, value);
5112     ASSERT_EQ(status, napi_object_expected);
5113 }
5114 
HWTEST_F(NapiBasicTest, NapiGetPropertyTest001, testing::ext::TestSize.Level1)5115 HWTEST_F(NapiBasicTest, NapiGetPropertyTest001, testing::ext::TestSize.Level1)
5116 {
5117     napi_env env = reinterpret_cast<napi_env>(engine_);
5118     napi_value obj = nullptr;
5119     napi_value key;
5120     napi_value result;
5121 
5122     napi_create_int32(env, INT_ONE, &key);
5123     napi_status status = napi_get_property(env, obj, key, &result);
5124     ASSERT_EQ(status, napi_invalid_arg);
5125 }
5126 
HWTEST_F(NapiBasicTest, NapiGetPropertyTest002, testing::ext::TestSize.Level1)5127 HWTEST_F(NapiBasicTest, NapiGetPropertyTest002, testing::ext::TestSize.Level1)
5128 {
5129     napi_env env = reinterpret_cast<napi_env>(engine_);
5130     napi_value obj;
5131     napi_value key = nullptr;
5132     napi_value result;
5133 
5134     napi_create_object(env, &obj);
5135     napi_status status = napi_get_property(env, obj, key, &result);
5136     ASSERT_EQ(status, napi_invalid_arg);
5137 }
5138 
HWTEST_F(NapiBasicTest, NapiGetPropertyTest003, testing::ext::TestSize.Level1)5139 HWTEST_F(NapiBasicTest, NapiGetPropertyTest003, testing::ext::TestSize.Level1)
5140 {
5141     napi_env env = reinterpret_cast<napi_env>(engine_);
5142     napi_value obj;
5143     napi_value key;
5144     napi_value *result = nullptr;
5145 
5146     napi_create_object(env, &obj);
5147     napi_create_int32(env, INT_ONE, &key);
5148     napi_status status = napi_get_property(env, obj, key, result);
5149     ASSERT_EQ(status, napi_invalid_arg);
5150 }
5151 
HWTEST_F(NapiBasicTest, NapiGetPropertyTest004, testing::ext::TestSize.Level1)5152 HWTEST_F(NapiBasicTest, NapiGetPropertyTest004, testing::ext::TestSize.Level1)
5153 {
5154     napi_env env = reinterpret_cast<napi_env>(engine_);
5155     napi_value obj;
5156     napi_value key;
5157     napi_value result;
5158 
5159     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5160     napi_create_int32(env, INT_ONE, &key);
5161     status = napi_get_property(env, obj, key, &result);
5162     ASSERT_EQ(status, napi_object_expected);
5163 }
5164 
HWTEST_F(NapiBasicTest, NapiHasPropertyTest001, testing::ext::TestSize.Level1)5165 HWTEST_F(NapiBasicTest, NapiHasPropertyTest001, testing::ext::TestSize.Level1)
5166 {
5167     napi_env env = reinterpret_cast<napi_env>(engine_);
5168     napi_value obj = nullptr;
5169     napi_value key;
5170     bool result;
5171 
5172     napi_create_int32(env, INT_ONE, &key);
5173     napi_status status = napi_has_property(env, obj, key, &result);
5174     ASSERT_EQ(status, napi_invalid_arg);
5175 }
5176 
HWTEST_F(NapiBasicTest, NapiHasPropertyTest002, testing::ext::TestSize.Level1)5177 HWTEST_F(NapiBasicTest, NapiHasPropertyTest002, testing::ext::TestSize.Level1)
5178 {
5179     napi_env env = reinterpret_cast<napi_env>(engine_);
5180     napi_value obj;
5181     napi_value key = nullptr;
5182     bool result;
5183 
5184     napi_create_object(env, &obj);
5185     napi_status status = napi_has_property(env, obj, key, &result);
5186     ASSERT_EQ(status, napi_invalid_arg);
5187 }
5188 
HWTEST_F(NapiBasicTest, NapiHasPropertyTest003, testing::ext::TestSize.Level1)5189 HWTEST_F(NapiBasicTest, NapiHasPropertyTest003, testing::ext::TestSize.Level1)
5190 {
5191     napi_env env = reinterpret_cast<napi_env>(engine_);
5192     napi_value obj;
5193     napi_value key;
5194     bool *result = nullptr;
5195 
5196     napi_create_object(env, &obj);
5197     napi_create_int32(env, INT_ONE, &key);
5198     napi_status status = napi_has_property(env, obj, key, result);
5199     ASSERT_EQ(status, napi_invalid_arg);
5200 }
5201 
HWTEST_F(NapiBasicTest, NapiHasPropertyTest004, testing::ext::TestSize.Level1)5202 HWTEST_F(NapiBasicTest, NapiHasPropertyTest004, testing::ext::TestSize.Level1)
5203 {
5204     napi_env env = reinterpret_cast<napi_env>(engine_);
5205     napi_value obj;
5206     napi_value key;
5207     bool result;
5208 
5209     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5210     napi_create_int32(env, INT_ONE, &key);
5211     status = napi_has_property(env, obj, key, &result);
5212     ASSERT_EQ(status, napi_object_expected);
5213 }
5214 
HWTEST_F(NapiBasicTest, NapiDeletePropertyTest001, testing::ext::TestSize.Level1)5215 HWTEST_F(NapiBasicTest, NapiDeletePropertyTest001, testing::ext::TestSize.Level1)
5216 {
5217     napi_env env = reinterpret_cast<napi_env>(engine_);
5218     napi_value obj = nullptr;
5219     napi_value key;
5220     bool result;
5221 
5222     napi_create_int32(env, INT_ONE, &key);
5223     napi_status status = napi_delete_property(env, obj, key, &result);
5224     ASSERT_EQ(status, napi_invalid_arg);
5225 }
5226 
HWTEST_F(NapiBasicTest, NapiDeletePropertyTest002, testing::ext::TestSize.Level1)5227 HWTEST_F(NapiBasicTest, NapiDeletePropertyTest002, testing::ext::TestSize.Level1)
5228 {
5229     napi_env env = reinterpret_cast<napi_env>(engine_);
5230     napi_value obj;
5231     napi_value key = nullptr;
5232     bool result;
5233 
5234     napi_create_object(env, &obj);
5235     napi_status status = napi_delete_property(env, obj, key, &result);
5236     ASSERT_EQ(status, napi_invalid_arg);
5237 }
5238 
HWTEST_F(NapiBasicTest, NapiDeletePropertyTest004, testing::ext::TestSize.Level1)5239 HWTEST_F(NapiBasicTest, NapiDeletePropertyTest004, testing::ext::TestSize.Level1)
5240 {
5241     napi_env env = reinterpret_cast<napi_env>(engine_);
5242     napi_value obj;
5243     napi_value key;
5244     bool result;
5245 
5246     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5247     napi_create_int32(env, INT_ONE, &key);
5248     status = napi_delete_property(env, obj, key, &result);
5249     ASSERT_EQ(status, napi_object_expected);
5250 }
5251 
HWTEST_F(NapiBasicTest, NapiHasOwnPropertyTest001, testing::ext::TestSize.Level1)5252 HWTEST_F(NapiBasicTest, NapiHasOwnPropertyTest001, testing::ext::TestSize.Level1)
5253 {
5254     napi_env env = reinterpret_cast<napi_env>(engine_);
5255     napi_value obj = nullptr;
5256     napi_value key;
5257     bool result;
5258 
5259     napi_create_int32(env, INT_ONE, &key);
5260     napi_status status = napi_has_own_property(env, obj, key, &result);
5261     ASSERT_EQ(status, napi_invalid_arg);
5262 }
5263 
HWTEST_F(NapiBasicTest, NapiHasOwnPropertyTest002, testing::ext::TestSize.Level1)5264 HWTEST_F(NapiBasicTest, NapiHasOwnPropertyTest002, testing::ext::TestSize.Level1)
5265 {
5266     napi_env env = reinterpret_cast<napi_env>(engine_);
5267     napi_value obj;
5268     napi_value key = nullptr;
5269     bool result;
5270 
5271     napi_create_object(env, &obj);
5272     napi_status status = napi_has_own_property(env, obj, key, &result);
5273     ASSERT_EQ(status, napi_invalid_arg);
5274 }
5275 
HWTEST_F(NapiBasicTest, NapiHasOwnPropertyTest003, testing::ext::TestSize.Level1)5276 HWTEST_F(NapiBasicTest, NapiHasOwnPropertyTest003, testing::ext::TestSize.Level1)
5277 {
5278     napi_env env = reinterpret_cast<napi_env>(engine_);
5279     napi_value obj;
5280     napi_value key;
5281     bool *result = nullptr;
5282 
5283     napi_create_object(env, &obj);
5284     napi_create_int32(env, INT_ONE, &key);
5285     napi_status status = napi_has_own_property(env, obj, key, result);
5286     ASSERT_EQ(status, napi_invalid_arg);
5287 }
5288 
HWTEST_F(NapiBasicTest, NapiHasOwnPropertyTest004, testing::ext::TestSize.Level1)5289 HWTEST_F(NapiBasicTest, NapiHasOwnPropertyTest004, testing::ext::TestSize.Level1)
5290 {
5291     napi_env env = reinterpret_cast<napi_env>(engine_);
5292     napi_value obj;
5293     napi_value key;
5294     bool result;
5295 
5296     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5297     napi_create_int32(env, INT_ONE, &key);
5298     status = napi_has_own_property(env, obj, key, &result);
5299     ASSERT_EQ(status, napi_object_expected);
5300 }
5301 
HWTEST_F(NapiBasicTest, NapiSetNamedPropertyTest001, testing::ext::TestSize.Level1)5302 HWTEST_F(NapiBasicTest, NapiSetNamedPropertyTest001, testing::ext::TestSize.Level1)
5303 {
5304     napi_env env = reinterpret_cast<napi_env>(engine_);
5305     napi_value obj = nullptr;
5306     napi_value value;
5307 
5308     napi_create_int32(env, INT_TWO, &value);
5309     napi_status status = napi_set_named_property(env, obj, TEST_STRING, value);
5310     ASSERT_EQ(status, napi_invalid_arg);
5311 }
5312 
HWTEST_F(NapiBasicTest, NapiSetNamedPropertyTest002, testing::ext::TestSize.Level1)5313 HWTEST_F(NapiBasicTest, NapiSetNamedPropertyTest002, testing::ext::TestSize.Level1)
5314 {
5315     napi_env env = reinterpret_cast<napi_env>(engine_);
5316     napi_value obj;
5317     char* utf8name = nullptr;
5318     napi_value value;
5319 
5320     napi_create_object(env, &obj);
5321     napi_create_int32(env, INT_TWO, &value);
5322     napi_status status = napi_set_named_property(env, obj, utf8name, value);
5323     ASSERT_EQ(status, napi_invalid_arg);
5324 }
5325 
HWTEST_F(NapiBasicTest, NapiSetNamedPropertyTest003, testing::ext::TestSize.Level1)5326 HWTEST_F(NapiBasicTest, NapiSetNamedPropertyTest003, testing::ext::TestSize.Level1)
5327 {
5328     napi_env env = reinterpret_cast<napi_env>(engine_);
5329     napi_value obj;
5330     napi_value value = nullptr;
5331 
5332     napi_create_object(env, &obj);
5333     napi_status status = napi_set_named_property(env, obj, TEST_STRING, value);
5334     ASSERT_EQ(status, napi_invalid_arg);
5335 }
5336 
HWTEST_F(NapiBasicTest, NapiSetNamedPropertyTest004, testing::ext::TestSize.Level1)5337 HWTEST_F(NapiBasicTest, NapiSetNamedPropertyTest004, testing::ext::TestSize.Level1)
5338 {
5339     napi_env env = reinterpret_cast<napi_env>(engine_);
5340     napi_value obj;
5341     napi_value value;
5342 
5343     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5344     napi_create_int32(env, INT_TWO, &value);
5345     status = napi_set_named_property(env, obj, TEST_STRING, value);
5346     ASSERT_EQ(status, napi_object_expected);
5347 }
5348 
HWTEST_F(NapiBasicTest, NapiGetNamedPropertyTest001, testing::ext::TestSize.Level1)5349 HWTEST_F(NapiBasicTest, NapiGetNamedPropertyTest001, testing::ext::TestSize.Level1)
5350 {
5351     napi_env env = reinterpret_cast<napi_env>(engine_);
5352     napi_value obj = nullptr;
5353     napi_value value;
5354 
5355     napi_status status = napi_get_named_property(env, obj, TEST_STRING, &value);
5356     ASSERT_EQ(status, napi_invalid_arg);
5357 }
5358 
HWTEST_F(NapiBasicTest, NapiGetNamedPropertyTest002, testing::ext::TestSize.Level1)5359 HWTEST_F(NapiBasicTest, NapiGetNamedPropertyTest002, testing::ext::TestSize.Level1)
5360 {
5361     napi_env env = reinterpret_cast<napi_env>(engine_);
5362     napi_value obj;
5363     char* utf8name = nullptr;
5364     napi_value value;
5365 
5366     napi_create_object(env, &obj);
5367     napi_status status = napi_get_named_property(env, obj, utf8name, &value);
5368     ASSERT_EQ(status, napi_invalid_arg);
5369 }
5370 
HWTEST_F(NapiBasicTest, NapiGetNamedPropertyTest003, testing::ext::TestSize.Level1)5371 HWTEST_F(NapiBasicTest, NapiGetNamedPropertyTest003, testing::ext::TestSize.Level1)
5372 {
5373     napi_env env = reinterpret_cast<napi_env>(engine_);
5374     napi_value obj;
5375     napi_value *value = nullptr;
5376 
5377     napi_create_object(env, &obj);
5378     napi_status status = napi_get_named_property(env, obj, TEST_STRING, value);
5379     ASSERT_EQ(status, napi_invalid_arg);
5380 }
5381 
HWTEST_F(NapiBasicTest, NapiGetNamedPropertyTest004, testing::ext::TestSize.Level1)5382 HWTEST_F(NapiBasicTest, NapiGetNamedPropertyTest004, testing::ext::TestSize.Level1)
5383 {
5384     napi_env env = reinterpret_cast<napi_env>(engine_);
5385     napi_value obj;
5386     napi_value value;
5387 
5388     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5389     status = napi_get_named_property(env, obj, TEST_STRING, &value);
5390     ASSERT_EQ(status, napi_object_expected);
5391 }
5392 
HWTEST_F(NapiBasicTest, NapiHasNamedPropertyTest001, testing::ext::TestSize.Level1)5393 HWTEST_F(NapiBasicTest, NapiHasNamedPropertyTest001, testing::ext::TestSize.Level1)
5394 {
5395     napi_env env = reinterpret_cast<napi_env>(engine_);
5396     napi_value obj = nullptr;
5397     bool result;
5398 
5399     napi_status status = napi_has_named_property(env, obj, TEST_STRING, &result);
5400     ASSERT_EQ(status, napi_invalid_arg);
5401 }
5402 
HWTEST_F(NapiBasicTest, NapiHasNamedPropertyTest002, testing::ext::TestSize.Level1)5403 HWTEST_F(NapiBasicTest, NapiHasNamedPropertyTest002, testing::ext::TestSize.Level1)
5404 {
5405     napi_env env = reinterpret_cast<napi_env>(engine_);
5406     napi_value obj;
5407     char* utf8name = nullptr;
5408     bool result;
5409 
5410     napi_create_object(env, &obj);
5411     napi_status status = napi_has_named_property(env, obj, utf8name, &result);
5412     ASSERT_EQ(status, napi_invalid_arg);
5413 }
5414 
HWTEST_F(NapiBasicTest, NapiHasNamedPropertyTest003, testing::ext::TestSize.Level1)5415 HWTEST_F(NapiBasicTest, NapiHasNamedPropertyTest003, testing::ext::TestSize.Level1)
5416 {
5417     napi_env env = reinterpret_cast<napi_env>(engine_);
5418     napi_value obj;
5419     bool *result = nullptr;
5420 
5421     napi_create_object(env, &obj);
5422     napi_status status = napi_has_named_property(env, obj, TEST_STRING, result);
5423     ASSERT_EQ(status, napi_invalid_arg);
5424 }
5425 
HWTEST_F(NapiBasicTest, NapiHasNamedPropertyTest004, testing::ext::TestSize.Level1)5426 HWTEST_F(NapiBasicTest, NapiHasNamedPropertyTest004, testing::ext::TestSize.Level1)
5427 {
5428     napi_env env = reinterpret_cast<napi_env>(engine_);
5429     napi_value obj;
5430     bool result;
5431 
5432     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5433     status = napi_has_named_property(env, obj, TEST_STRING, &result);
5434     ASSERT_EQ(status, napi_object_expected);
5435 }
5436 
HWTEST_F(NapiBasicTest, NapiSetElementTest001, testing::ext::TestSize.Level1)5437 HWTEST_F(NapiBasicTest, NapiSetElementTest001, testing::ext::TestSize.Level1)
5438 {
5439     napi_env env = reinterpret_cast<napi_env>(engine_);
5440     napi_value obj = nullptr;
5441     uint32_t index = 1;
5442     napi_value value;
5443 
5444     napi_create_int32(env, INT_TWO, &value);
5445     napi_status status = napi_set_element(env, obj, index, value);
5446     ASSERT_EQ(status, napi_invalid_arg);
5447 }
5448 
HWTEST_F(NapiBasicTest, NapiSetElementTest002, testing::ext::TestSize.Level1)5449 HWTEST_F(NapiBasicTest, NapiSetElementTest002, testing::ext::TestSize.Level1)
5450 {
5451     napi_env env = reinterpret_cast<napi_env>(engine_);
5452     napi_value obj;
5453     uint32_t index = 1;
5454     napi_value value = nullptr;
5455 
5456     napi_create_object(env, &obj);
5457     napi_status status = napi_set_element(env, obj, index, value);
5458     ASSERT_EQ(status, napi_invalid_arg);
5459 }
5460 
HWTEST_F(NapiBasicTest, NapiSetElementTest003, testing::ext::TestSize.Level1)5461 HWTEST_F(NapiBasicTest, NapiSetElementTest003, testing::ext::TestSize.Level1)
5462 {
5463     napi_env env = reinterpret_cast<napi_env>(engine_);
5464     napi_value obj;
5465     uint32_t index = 1;
5466     napi_value value;
5467 
5468     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5469     napi_create_int32(env, INT_TWO, &value);
5470     status = napi_set_element(env, obj, index, value);
5471     ASSERT_EQ(status, napi_object_expected);
5472 }
5473 
HWTEST_F(NapiBasicTest, NapiGetElementTest001, testing::ext::TestSize.Level1)5474 HWTEST_F(NapiBasicTest, NapiGetElementTest001, testing::ext::TestSize.Level1)
5475 {
5476     napi_env env = reinterpret_cast<napi_env>(engine_);
5477     napi_value obj = nullptr;
5478     uint32_t index = 1;
5479     napi_value value;
5480 
5481     napi_status status = napi_get_element(env, obj, index, &value);
5482     ASSERT_EQ(status, napi_invalid_arg);
5483 }
5484 
HWTEST_F(NapiBasicTest, NapiGetElementTest002, testing::ext::TestSize.Level1)5485 HWTEST_F(NapiBasicTest, NapiGetElementTest002, testing::ext::TestSize.Level1)
5486 {
5487     napi_env env = reinterpret_cast<napi_env>(engine_);
5488     napi_value obj;
5489     uint32_t index = 1;
5490     napi_value *value = nullptr;
5491 
5492     napi_create_object(env, &obj);
5493     napi_status status = napi_get_element(env, obj, index, value);
5494     ASSERT_EQ(status, napi_invalid_arg);
5495 }
5496 
HWTEST_F(NapiBasicTest, NapiGetElementTest003, testing::ext::TestSize.Level1)5497 HWTEST_F(NapiBasicTest, NapiGetElementTest003, testing::ext::TestSize.Level1)
5498 {
5499     napi_env env = reinterpret_cast<napi_env>(engine_);
5500     napi_value obj;
5501     uint32_t index = 1;
5502     napi_value value;
5503 
5504     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5505     status = napi_get_element(env, obj, index, &value);
5506     ASSERT_EQ(status, napi_object_expected);
5507 }
5508 
HWTEST_F(NapiBasicTest, NapiHasElementTest001, testing::ext::TestSize.Level1)5509 HWTEST_F(NapiBasicTest, NapiHasElementTest001, testing::ext::TestSize.Level1)
5510 {
5511     napi_env env = reinterpret_cast<napi_env>(engine_);
5512     napi_value obj = nullptr;
5513     uint32_t index = 1;
5514     bool result;
5515 
5516     napi_status status = napi_has_element(env, obj, index, &result);
5517     ASSERT_EQ(status, napi_invalid_arg);
5518 }
5519 
HWTEST_F(NapiBasicTest, NapiHasElementTest002, testing::ext::TestSize.Level1)5520 HWTEST_F(NapiBasicTest, NapiHasElementTest002, testing::ext::TestSize.Level1)
5521 {
5522     napi_env env = reinterpret_cast<napi_env>(engine_);
5523     napi_value obj;
5524     uint32_t index = 1;
5525     bool *result = nullptr;
5526 
5527     napi_create_object(env, &obj);
5528     napi_status status = napi_has_element(env, obj, index, result);
5529     ASSERT_EQ(status, napi_invalid_arg);
5530 }
5531 
HWTEST_F(NapiBasicTest, NapiHasElementTest003, testing::ext::TestSize.Level1)5532 HWTEST_F(NapiBasicTest, NapiHasElementTest003, testing::ext::TestSize.Level1)
5533 {
5534     napi_env env = reinterpret_cast<napi_env>(engine_);
5535     napi_value obj;
5536     uint32_t index = 1;
5537     bool result;
5538 
5539     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5540     status = napi_has_element(env, obj, index, &result);
5541     ASSERT_EQ(status, napi_object_expected);
5542 }
5543 
HWTEST_F(NapiBasicTest, NapiDeleteElementTest001, testing::ext::TestSize.Level1)5544 HWTEST_F(NapiBasicTest, NapiDeleteElementTest001, testing::ext::TestSize.Level1)
5545 {
5546     napi_env env = reinterpret_cast<napi_env>(engine_);
5547     napi_value obj = nullptr;
5548     uint32_t index = 1;
5549     bool result;
5550 
5551     napi_status status = napi_delete_element(env, obj, index, &result);
5552     ASSERT_EQ(status, napi_invalid_arg);
5553 }
5554 
HWTEST_F(NapiBasicTest, NapiDeleteElementTest002, testing::ext::TestSize.Level1)5555 HWTEST_F(NapiBasicTest, NapiDeleteElementTest002, testing::ext::TestSize.Level1)
5556 {
5557     napi_env env = reinterpret_cast<napi_env>(engine_);
5558     napi_value obj;
5559     uint32_t index = 1;
5560     bool result;
5561 
5562     napi_status status = napi_create_double(env, TEST_DOUBLE, &obj);
5563     status = napi_delete_element(env, obj, index, &result);
5564     ASSERT_EQ(status, napi_object_expected);
5565 }
5566 
HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest001, testing::ext::TestSize.Level1)5567 HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest001, testing::ext::TestSize.Level1)
5568 {
5569     napi_env env = reinterpret_cast<napi_env>(engine_);
5570     napi_property_descriptor desc[] = {
5571         {"testMethod", nullptr, [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; },
5572          nullptr, nullptr, nullptr, napi_default, nullptr},
5573     };
5574     napi_value result = nullptr;
5575 
5576     napi_status status = napi_define_properties(env, result, sizeof(desc)/sizeof(desc[0]), desc);
5577     ASSERT_EQ(status, napi_invalid_arg);
5578 }
5579 
HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest002, testing::ext::TestSize.Level1)5580 HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest002, testing::ext::TestSize.Level1)
5581 {
5582     napi_env env = reinterpret_cast<napi_env>(engine_);
5583     napi_property_descriptor *desc = nullptr;
5584     napi_value result;
5585     napi_create_object(env, &result);
5586 
5587     napi_status status = napi_define_properties(env, result, INT_ONE, desc);
5588     ASSERT_EQ(status, napi_invalid_arg);
5589 }
5590 
HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest003, testing::ext::TestSize.Level1)5591 HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest003, testing::ext::TestSize.Level1)
5592 {
5593     napi_env env = reinterpret_cast<napi_env>(engine_);
5594     napi_property_descriptor desc[] = {
5595         {"testMethod", nullptr, [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; },
5596          nullptr, nullptr, nullptr, napi_default, nullptr},
5597     };
5598     napi_value result;
5599     napi_create_double(env, TEST_DOUBLE, &result);
5600 
5601     napi_status status = napi_define_properties(env, result, INT_ONE, desc);
5602     ASSERT_EQ(status, napi_object_expected);
5603 }
5604 
HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest004, testing::ext::TestSize.Level1)5605 HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest004, testing::ext::TestSize.Level1)
5606 {
5607     napi_env env = reinterpret_cast<napi_env>(engine_);
5608     napi_property_descriptor desc[] = {
5609         {nullptr, nullptr, [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; },
5610          nullptr, nullptr, nullptr, napi_default, nullptr},
5611     };
5612     napi_value result;
5613     napi_create_object(env, &result);
5614 
5615     napi_status status = napi_define_properties(env, result, INT_ONE, desc);
5616     ASSERT_EQ(status, napi_name_expected);
5617 }
5618 
HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest005, testing::ext::TestSize.Level1)5619 HWTEST_F(NapiBasicTest, NapiDefinePropertiesTest005, testing::ext::TestSize.Level1)
5620 {
5621     napi_env env = reinterpret_cast<napi_env>(engine_);
5622     napi_value name;
5623     napi_create_object(env, &name);
5624     napi_property_descriptor desc[] = {
5625         {nullptr, name, [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; },
5626          nullptr, nullptr, nullptr, napi_default, nullptr},
5627     };
5628     napi_value result;
5629     napi_create_object(env, &result);
5630 
5631     napi_status status = napi_define_properties(env, result, INT_ONE, desc);
5632     ASSERT_EQ(status, napi_name_expected);
5633 }
5634 
HWTEST_F(NapiBasicTest, NapiTypeTagObjectTest001, testing::ext::TestSize.Level1)5635 HWTEST_F(NapiBasicTest, NapiTypeTagObjectTest001, testing::ext::TestSize.Level1)
5636 {
5637     napi_env env = reinterpret_cast<napi_env>(engine_);
5638     napi_value obj = nullptr;
5639     napi_type_tag tag;
5640 
5641     napi_status status = napi_type_tag_object(env, obj, &tag);
5642     ASSERT_EQ(status, napi_invalid_arg);
5643 }
5644 
HWTEST_F(NapiBasicTest, NapiTypeTagObjectTest002, testing::ext::TestSize.Level1)5645 HWTEST_F(NapiBasicTest, NapiTypeTagObjectTest002, testing::ext::TestSize.Level1)
5646 {
5647     napi_env env = reinterpret_cast<napi_env>(engine_);
5648     napi_value obj;
5649     napi_type_tag* tag = nullptr;
5650     napi_create_object(env, &obj);
5651 
5652     napi_status status = napi_type_tag_object(env, obj, tag);
5653     ASSERT_EQ(status, napi_invalid_arg);
5654 }
5655 
HWTEST_F(NapiBasicTest, NapiTypeTagObjectTest003, testing::ext::TestSize.Level1)5656 HWTEST_F(NapiBasicTest, NapiTypeTagObjectTest003, testing::ext::TestSize.Level1)
5657 {
5658     napi_env env = reinterpret_cast<napi_env>(engine_);
5659     napi_value obj;
5660     napi_type_tag tag;
5661     napi_create_double(env, TEST_DOUBLE, &obj);
5662 
5663     napi_status status = napi_type_tag_object(env, obj, &tag);
5664     ASSERT_EQ(status, napi_object_expected);
5665 }
5666 
HWTEST_F(NapiBasicTest, NapiCheckObjectTypeTagTest001, testing::ext::TestSize.Level1)5667 HWTEST_F(NapiBasicTest, NapiCheckObjectTypeTagTest001, testing::ext::TestSize.Level1)
5668 {
5669     napi_env env = reinterpret_cast<napi_env>(engine_);
5670     napi_value obj = nullptr;
5671     napi_type_tag tag;
5672     bool result;
5673 
5674     napi_status status = napi_check_object_type_tag(env, obj, &tag, &result);
5675     ASSERT_EQ(status, napi_invalid_arg);
5676 }
5677 
HWTEST_F(NapiBasicTest, NapiCheckObjectTypeTagTest002, testing::ext::TestSize.Level1)5678 HWTEST_F(NapiBasicTest, NapiCheckObjectTypeTagTest002, testing::ext::TestSize.Level1)
5679 {
5680     napi_env env = reinterpret_cast<napi_env>(engine_);
5681     napi_value obj;
5682     napi_type_tag *tag = nullptr;
5683     bool result;
5684     napi_create_object(env, &obj);
5685 
5686     napi_status status = napi_check_object_type_tag(env, obj, tag, &result);
5687     ASSERT_EQ(status, napi_invalid_arg);
5688 }
5689 
HWTEST_F(NapiBasicTest, NapiCheckObjectTypeTagTest003, testing::ext::TestSize.Level1)5690 HWTEST_F(NapiBasicTest, NapiCheckObjectTypeTagTest003, testing::ext::TestSize.Level1)
5691 {
5692     napi_env env = reinterpret_cast<napi_env>(engine_);
5693     napi_value obj;
5694     napi_type_tag tag;
5695     bool *result = nullptr;
5696     napi_create_object(env, &obj);
5697 
5698     napi_status status = napi_check_object_type_tag(env, obj, &tag, result);
5699     ASSERT_EQ(status, napi_invalid_arg);
5700 }
5701 
HWTEST_F(NapiBasicTest, NapiCallFunctionTest001, testing::ext::TestSize.Level1)5702 HWTEST_F(NapiBasicTest, NapiCallFunctionTest001, testing::ext::TestSize.Level1)
5703 {
5704     napi_env env = reinterpret_cast<napi_env>(engine_);
5705     napi_value funcValue = nullptr;
5706     napi_value recv = nullptr;
5707     size_t argc = 1;
5708     napi_value args[1] = {nullptr};
5709     napi_value funcResultValue = nullptr;
5710 
5711     napi_status status = napi_call_function(env, recv, funcValue, argc, args, &funcResultValue);
5712     ASSERT_EQ(status, napi_invalid_arg);
5713 }
5714 
HWTEST_F(NapiBasicTest, NapiCallFunctionTest002, testing::ext::TestSize.Level1)5715 HWTEST_F(NapiBasicTest, NapiCallFunctionTest002, testing::ext::TestSize.Level1)
5716 {
5717     napi_env env = reinterpret_cast<napi_env>(engine_);
5718     napi_value funcValue = nullptr;
5719     napi_value recv = nullptr;
5720     size_t argc = 1;
5721     napi_value* args = nullptr;
5722     napi_value funcResultValue = nullptr;
5723 
5724     napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH,
5725         [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; }, nullptr, &funcValue);
5726     napi_status status = napi_call_function(env, recv, funcValue, argc, args, &funcResultValue);
5727     ASSERT_EQ(status, napi_invalid_arg);
5728 }
5729 
HWTEST_F(NapiBasicTest, NapiCallFunctionTest003, testing::ext::TestSize.Level1)5730 HWTEST_F(NapiBasicTest, NapiCallFunctionTest003, testing::ext::TestSize.Level1)
5731 {
5732     napi_env env = reinterpret_cast<napi_env>(engine_);
5733     napi_value funcValue = nullptr;
5734     napi_value recv = nullptr;
5735     size_t argc = 1;
5736     napi_value args[1] = {nullptr};
5737     napi_value funcResultValue = nullptr;
5738 
5739     napi_create_object(env, &funcValue);
5740     napi_status status = napi_call_function(env, recv, funcValue, argc, args, &funcResultValue);
5741     ASSERT_EQ(status, napi_function_expected);
5742 }
5743 
HWTEST_F(NapiBasicTest, NapiCallFunctionTest004, testing::ext::TestSize.Level1)5744 HWTEST_F(NapiBasicTest, NapiCallFunctionTest004, testing::ext::TestSize.Level1)
5745 {
5746     napi_env env = reinterpret_cast<napi_env>(engine_);
5747     napi_value funcValue = nullptr;
5748     napi_value recv = nullptr;
5749     size_t argc = 1;
5750     napi_value args[1] = {nullptr};
5751     napi_value funcResultValue = nullptr;
5752 
5753     napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH, [](napi_env env, napi_callback_info info) -> napi_value {
5754             napi_throw_error(env, "500", "Common error");
5755             return nullptr;
5756         }, nullptr, &funcValue);
5757     napi_status status = napi_call_function(env, recv, funcValue, argc, args, &funcResultValue);
5758     ASSERT_EQ(status, napi_pending_exception);
5759 }
5760 
HWTEST_F(NapiBasicTest, NapiCreateFunctionTest001, testing::ext::TestSize.Level1)5761 HWTEST_F(NapiBasicTest, NapiCreateFunctionTest001, testing::ext::TestSize.Level1)
5762 {
5763     napi_env env = reinterpret_cast<napi_env>(engine_);
5764     napi_value funcValue = nullptr;
5765 
5766     napi_status status = napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH, nullptr, nullptr, &funcValue);
5767     ASSERT_EQ(status, napi_invalid_arg);
5768 }
5769 
HWTEST_F(NapiBasicTest, NapiCreateFunctionTest002, testing::ext::TestSize.Level1)5770 HWTEST_F(NapiBasicTest, NapiCreateFunctionTest002, testing::ext::TestSize.Level1)
5771 {
5772     napi_env env = reinterpret_cast<napi_env>(engine_);
5773     napi_value *funcValue = nullptr;
5774 
5775     napi_status status = napi_create_function(env, "testFunc", NAPI_AUTO_LENGTH,
5776         [](napi_env env, napi_callback_info info) -> napi_value { return nullptr; }, nullptr, funcValue);
5777     ASSERT_EQ(status, napi_invalid_arg);
5778 }
5779 
HWTEST_F(NapiBasicTest, NapiGetCbInfoTest001, testing::ext::TestSize.Level1)5780 HWTEST_F(NapiBasicTest, NapiGetCbInfoTest001, testing::ext::TestSize.Level1)
5781 {
5782     napi_env env = reinterpret_cast<napi_env>(engine_);
5783     napi_callback_info info = nullptr;
5784     size_t argc = 0;
5785     napi_value* argv = nullptr;
5786     napi_value thisVar;
5787     void* data = nullptr;
5788 
5789     napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
5790     ASSERT_EQ(status, napi_invalid_arg);
5791 }
5792 
HWTEST_F(NapiBasicTest, NapiGetNewTargetTest001, testing::ext::TestSize.Level1)5793 HWTEST_F(NapiBasicTest, NapiGetNewTargetTest001, testing::ext::TestSize.Level1)
5794 {
5795     napi_env env = reinterpret_cast<napi_env>(engine_);
5796     napi_callback_info info = nullptr;
5797     napi_value result;
5798 
5799     napi_status status = napi_get_new_target(env, info, &result);
5800     ASSERT_EQ(status, napi_invalid_arg);
5801 }
5802 
HWTEST_F(NapiBasicTest, NapiGetNewTargetTest002, testing::ext::TestSize.Level1)5803 HWTEST_F(NapiBasicTest, NapiGetNewTargetTest002, testing::ext::TestSize.Level1)
5804 {
5805     napi_env env = reinterpret_cast<napi_env>(engine_);
5806     napi_callback_info info = napi_callback_info(nullptr);;
5807     napi_value* result = nullptr;
5808 
5809     napi_status status = napi_get_new_target(env, info, result);
5810     ASSERT_EQ(status, napi_invalid_arg);
5811 }
5812 
HWTEST_F(NapiBasicTest, NapiNewInstanceTest001, testing::ext::TestSize.Level1)5813 HWTEST_F(NapiBasicTest, NapiNewInstanceTest001, testing::ext::TestSize.Level1)
5814 {
5815     napi_env env = reinterpret_cast<napi_env>(engine_);
5816     napi_value constructor = nullptr;
5817     size_t argc = 0;
5818     napi_value args[1] = {nullptr};
5819     napi_value result;
5820 
5821     napi_status status = napi_new_instance(env, constructor, argc, args, &result);
5822     ASSERT_EQ(status, napi_invalid_arg);
5823 }
5824 
HWTEST_F(NapiBasicTest, NapiNewInstanceTest002, testing::ext::TestSize.Level1)5825 HWTEST_F(NapiBasicTest, NapiNewInstanceTest002, testing::ext::TestSize.Level1)
5826 {
5827     napi_env env = reinterpret_cast<napi_env>(engine_);
5828     napi_value constructor;
5829     size_t argc = 1;
5830     napi_value* args = nullptr;
5831     napi_value result;
5832 
5833     napi_create_object(env, &constructor);
5834     napi_status status = napi_new_instance(env, constructor, argc, args, &result);
5835     ASSERT_EQ(status, napi_invalid_arg);
5836 }
5837 
HWTEST_F(NapiBasicTest, NapiNewInstanceTest003, testing::ext::TestSize.Level1)5838 HWTEST_F(NapiBasicTest, NapiNewInstanceTest003, testing::ext::TestSize.Level1)
5839 {
5840     napi_env env = reinterpret_cast<napi_env>(engine_);
5841     napi_value constructor;
5842     size_t argc = 1;
5843     napi_value args[1] = {nullptr};
5844     napi_value* result = nullptr;
5845 
5846     napi_create_object(env, &constructor);
5847     napi_status status = napi_new_instance(env, constructor, argc, args, result);
5848     ASSERT_EQ(status, napi_invalid_arg);
5849 }
5850 
HWTEST_F(NapiBasicTest, NapiNewInstanceTest004, testing::ext::TestSize.Level1)5851 HWTEST_F(NapiBasicTest, NapiNewInstanceTest004, testing::ext::TestSize.Level1)
5852 {
5853     napi_env env = reinterpret_cast<napi_env>(engine_);
5854     napi_value constructor;
5855     size_t argc = 1;
5856     napi_value args[1] = {nullptr};
5857     napi_value result;
5858 
5859     napi_create_object(env, &constructor);
5860     napi_status status = napi_new_instance(env, constructor, argc, args, &result);
5861     ASSERT_EQ(status, napi_function_expected);
5862 }
5863 
HWTEST_F(NapiBasicTest, NapiDefineClassTest001, testing::ext::TestSize.Level1)5864 HWTEST_F(NapiBasicTest, NapiDefineClassTest001, testing::ext::TestSize.Level1)
5865 {
5866     napi_env env = reinterpret_cast<napi_env>(engine_);
5867     napi_value result;
5868     napi_status status = napi_define_class(
5869         env, nullptr, NAPI_AUTO_LENGTH,
5870         [](napi_env env, napi_callback_info info) -> napi_value {
5871             napi_value thisVar = nullptr;
5872             napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
5873 
5874             return thisVar;
5875         },
5876         nullptr, 0, nullptr, &result);
5877     ASSERT_EQ(status, napi_invalid_arg);
5878 }
5879 
5880 
HWTEST_F(NapiBasicTest, NapiDefineClassTest002, testing::ext::TestSize.Level1)5881 HWTEST_F(NapiBasicTest, NapiDefineClassTest002, testing::ext::TestSize.Level1)
5882 {
5883     napi_env env = reinterpret_cast<napi_env>(engine_);
5884     napi_value result;
5885     napi_status status = napi_define_class(
5886         env, "TestClass", NAPI_AUTO_LENGTH,
5887         nullptr, nullptr, 0, nullptr, &result);
5888     ASSERT_EQ(status, napi_invalid_arg);
5889 }
5890 
HWTEST_F(NapiBasicTest, NapiDefineClassTest003, testing::ext::TestSize.Level1)5891 HWTEST_F(NapiBasicTest, NapiDefineClassTest003, testing::ext::TestSize.Level1)
5892 {
5893     napi_env env = reinterpret_cast<napi_env>(engine_);
5894     napi_value* result = nullptr;
5895     napi_status status = napi_define_class(
5896         env, "TestClass", NAPI_AUTO_LENGTH,
5897         [](napi_env env, napi_callback_info info) -> napi_value {
5898             napi_value thisVar = nullptr;
5899             napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
5900 
5901             return thisVar;
5902         },
5903         nullptr, 0, nullptr, result);
5904     ASSERT_EQ(status, napi_invalid_arg);
5905 }
5906 
HWTEST_F(NapiBasicTest, NapiDefineClassTest004, testing::ext::TestSize.Level1)5907 HWTEST_F(NapiBasicTest, NapiDefineClassTest004, testing::ext::TestSize.Level1)
5908 {
5909     napi_env env = reinterpret_cast<napi_env>(engine_);
5910     napi_value result;
5911     napi_status status = napi_define_class(
5912         env, "TestClass", NAPI_AUTO_LENGTH,
5913         [](napi_env env, napi_callback_info info) -> napi_value {
5914             napi_value thisVar = nullptr;
5915             napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
5916 
5917             return thisVar;
5918         },
5919         nullptr, 1, nullptr, &result);
5920     ASSERT_EQ(status, napi_invalid_arg);
5921 }
5922 
HWTEST_F(NapiBasicTest, NapiWrapTest001, testing::ext::TestSize.Level1)5923 HWTEST_F(NapiBasicTest, NapiWrapTest001, testing::ext::TestSize.Level1)
5924 {
5925     napi_env env = reinterpret_cast<napi_env>(engine_);
5926     napi_value obj = nullptr;
5927     napi_ref result;
5928 
5929     napi_status status = napi_wrap(env, obj, (void *)TEST_STRING,
5930         [](napi_env, void* data, void* hint) {}, nullptr, &result);
5931     ASSERT_EQ(status, napi_invalid_arg);
5932 }
5933 
HWTEST_F(NapiBasicTest, NapiWrapTest002, testing::ext::TestSize.Level1)5934 HWTEST_F(NapiBasicTest, NapiWrapTest002, testing::ext::TestSize.Level1)
5935 {
5936     napi_env env = reinterpret_cast<napi_env>(engine_);
5937     napi_value obj;
5938     napi_ref result;
5939 
5940     napi_create_object(env, &obj);
5941     napi_status status = napi_wrap(env, obj, nullptr, [](napi_env, void* data, void* hint) {}, nullptr, &result);
5942     ASSERT_EQ(status, napi_invalid_arg);
5943 }
5944 
HWTEST_F(NapiBasicTest, NapiWrapTest003, testing::ext::TestSize.Level1)5945 HWTEST_F(NapiBasicTest, NapiWrapTest003, testing::ext::TestSize.Level1)
5946 {
5947     napi_env env = reinterpret_cast<napi_env>(engine_);
5948     napi_value obj;
5949     napi_ref result;
5950 
5951     napi_create_object(env, &obj);
5952     napi_status status = napi_wrap(env, obj, (void *)TEST_STRING, nullptr, nullptr, &result);
5953     ASSERT_EQ(status, napi_invalid_arg);
5954 }
5955 
HWTEST_F(NapiBasicTest, NapiWrapTest004, testing::ext::TestSize.Level1)5956 HWTEST_F(NapiBasicTest, NapiWrapTest004, testing::ext::TestSize.Level1)
5957 {
5958     napi_env env = reinterpret_cast<napi_env>(engine_);
5959     napi_value obj;
5960     napi_ref result;
5961 
5962     napi_create_double(env, TEST_DOUBLE, &obj);
5963     napi_status status = napi_wrap(env, obj, (void *)TEST_STRING,
5964         [](napi_env, void* data, void* hint) {}, nullptr, &result);
5965     ASSERT_EQ(status, napi_object_expected);
5966 }
5967 
HWTEST_F(NapiBasicTest, NapiUnwrapTest001, testing::ext::TestSize.Level1)5968 HWTEST_F(NapiBasicTest, NapiUnwrapTest001, testing::ext::TestSize.Level1)
5969 {
5970     napi_env env = reinterpret_cast<napi_env>(engine_);
5971     napi_value obj = nullptr;
5972     char *testStr = nullptr;
5973 
5974     napi_status status = napi_unwrap(env, obj, (void **)&testStr);
5975     ASSERT_EQ(status, napi_invalid_arg);
5976 }
5977 
HWTEST_F(NapiBasicTest, NapiUnwrapTest002, testing::ext::TestSize.Level1)5978 HWTEST_F(NapiBasicTest, NapiUnwrapTest002, testing::ext::TestSize.Level1)
5979 {
5980     napi_env env = reinterpret_cast<napi_env>(engine_);
5981     napi_value obj;
5982     char **testStr = nullptr;
5983 
5984     napi_create_object(env, &obj);
5985     napi_status status = napi_unwrap(env, obj, (void **)testStr);
5986     ASSERT_EQ(status, napi_invalid_arg);
5987 }
5988 
HWTEST_F(NapiBasicTest, NapiUnwrapTest003, testing::ext::TestSize.Level1)5989 HWTEST_F(NapiBasicTest, NapiUnwrapTest003, testing::ext::TestSize.Level1)
5990 {
5991     napi_env env = reinterpret_cast<napi_env>(engine_);
5992     napi_value obj = nullptr;
5993     char *testStr = nullptr;
5994 
5995     napi_create_double(env, TEST_DOUBLE, &obj);
5996     napi_status status = napi_unwrap(env, obj, (void **)&testStr);
5997     ASSERT_EQ(status, napi_object_expected);
5998 }
5999 
HWTEST_F(NapiBasicTest, NapiRemoveWrapTest001, testing::ext::TestSize.Level1)6000 HWTEST_F(NapiBasicTest, NapiRemoveWrapTest001, testing::ext::TestSize.Level1)
6001 {
6002     napi_env env = reinterpret_cast<napi_env>(engine_);
6003     napi_value obj = nullptr;
6004     char *testStr = nullptr;
6005 
6006     napi_status status = napi_remove_wrap(env, obj, (void **)&testStr);
6007     ASSERT_EQ(status, napi_invalid_arg);
6008 }
6009 
HWTEST_F(NapiBasicTest, NapiRemoveWrapTest002, testing::ext::TestSize.Level1)6010 HWTEST_F(NapiBasicTest, NapiRemoveWrapTest002, testing::ext::TestSize.Level1)
6011 {
6012     napi_env env = reinterpret_cast<napi_env>(engine_);
6013     napi_value obj;
6014     char **testStr = nullptr;
6015 
6016     napi_create_object(env, &obj);
6017     napi_status status = napi_remove_wrap(env, obj, (void **)testStr);
6018     ASSERT_EQ(status, napi_invalid_arg);
6019 }
6020 
HWTEST_F(NapiBasicTest, NapiRemoveWrapTest003, testing::ext::TestSize.Level1)6021 HWTEST_F(NapiBasicTest, NapiRemoveWrapTest003, testing::ext::TestSize.Level1)
6022 {
6023     napi_env env = reinterpret_cast<napi_env>(engine_);
6024     napi_value obj = nullptr;
6025     char *testStr = nullptr;
6026 
6027     napi_create_double(env, TEST_DOUBLE, &obj);
6028     napi_status status = napi_remove_wrap(env, obj, (void **)&testStr);
6029     ASSERT_EQ(status, napi_object_expected);
6030 }
6031 
HWTEST_F(NapiBasicTest, NapiCreateAsyncWorkTest001, testing::ext::TestSize.Level1)6032 HWTEST_F(NapiBasicTest, NapiCreateAsyncWorkTest001, testing::ext::TestSize.Level1)
6033 {
6034     napi_env env = reinterpret_cast<napi_env>(engine_);
6035     napi_async_work work = nullptr;
6036     napi_value resourceName = nullptr;
6037 
6038     napi_status status = napi_create_async_work(env, nullptr, resourceName, [](napi_env value, void* data) {},
6039                            [](napi_env env, napi_status status, void* data) {}, nullptr, &work);
6040     ASSERT_EQ(status, napi_invalid_arg);
6041 }
6042 
HWTEST_F(NapiBasicTest, NapiCreateAsyncWorkTest002, testing::ext::TestSize.Level1)6043 HWTEST_F(NapiBasicTest, NapiCreateAsyncWorkTest002, testing::ext::TestSize.Level1)
6044 {
6045     napi_env env = reinterpret_cast<napi_env>(engine_);
6046     napi_async_work work = nullptr;
6047     napi_value resourceName = nullptr;
6048     napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
6049     napi_status status = napi_create_async_work(env, nullptr, resourceName, nullptr,
6050                            [](napi_env env, napi_status status, void* data) {}, nullptr, &work);
6051     ASSERT_EQ(status, napi_invalid_arg);
6052 }
6053 
HWTEST_F(NapiBasicTest, NapiCreateAsyncWorkTest003, testing::ext::TestSize.Level1)6054 HWTEST_F(NapiBasicTest, NapiCreateAsyncWorkTest003, testing::ext::TestSize.Level1)
6055 {
6056     napi_env env = reinterpret_cast<napi_env>(engine_);
6057     napi_async_work work = nullptr;
6058     napi_value resourceName = nullptr;
6059     napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
6060     napi_status status = napi_create_async_work(env, nullptr, resourceName, [](napi_env value, void* data) {},
6061                            nullptr, nullptr, &work);
6062     ASSERT_EQ(status, napi_invalid_arg);
6063 }
6064 
HWTEST_F(NapiBasicTest, NapiCreateAsyncWorkTest004, testing::ext::TestSize.Level1)6065 HWTEST_F(NapiBasicTest, NapiCreateAsyncWorkTest004, testing::ext::TestSize.Level1)
6066 {
6067     napi_env env = reinterpret_cast<napi_env>(engine_);
6068     napi_async_work* work = nullptr;
6069     napi_value resourceName = nullptr;
6070     napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName);
6071     napi_status status = napi_create_async_work(env, nullptr, resourceName, [](napi_env value, void* data) {},
6072                            nullptr, nullptr, work);
6073     ASSERT_EQ(status, napi_invalid_arg);
6074 }
6075 
HWTEST_F(NapiBasicTest, NapiDeleteAsyncWorkTest001, testing::ext::TestSize.Level1)6076 HWTEST_F(NapiBasicTest, NapiDeleteAsyncWorkTest001, testing::ext::TestSize.Level1)
6077 {
6078     napi_env env = reinterpret_cast<napi_env>(engine_);
6079     napi_async_work work = nullptr;
6080 
6081     napi_status status = napi_delete_async_work(env, work);
6082     ASSERT_EQ(status, napi_invalid_arg);
6083 }
6084 
HWTEST_F(NapiBasicTest, NapiQueueAsyncWorkTest001, testing::ext::TestSize.Level1)6085 HWTEST_F(NapiBasicTest, NapiQueueAsyncWorkTest001, testing::ext::TestSize.Level1)
6086 {
6087     napi_env env = reinterpret_cast<napi_env>(engine_);
6088     napi_async_work work = nullptr;
6089 
6090     napi_status status = napi_queue_async_work(env, work);
6091     ASSERT_EQ(status, napi_invalid_arg);
6092 }
6093 
HWTEST_F(NapiBasicTest, NapiCancelAsyncWorkTest001, testing::ext::TestSize.Level1)6094 HWTEST_F(NapiBasicTest, NapiCancelAsyncWorkTest001, testing::ext::TestSize.Level1)
6095 {
6096     napi_env env = reinterpret_cast<napi_env>(engine_);
6097     napi_async_work work = nullptr;
6098 
6099     napi_status status = napi_cancel_async_work(env, work);
6100     ASSERT_EQ(status, napi_invalid_arg);
6101 }
6102 
HWTEST_F(NapiBasicTest, NapiAsyncInitTest001, testing::ext::TestSize.Level1)6103 HWTEST_F(NapiBasicTest, NapiAsyncInitTest001, testing::ext::TestSize.Level1)
6104 {
6105     napi_env env = reinterpret_cast<napi_env>(engine_);
6106     napi_value resourceName = nullptr;
6107     napi_async_context context;
6108 
6109     napi_status status = napi_async_init(env, nullptr, resourceName, &context);
6110     ASSERT_EQ(status, napi_invalid_arg);
6111 }
6112 
HWTEST_F(NapiBasicTest, NapiAsyncInitTest002, testing::ext::TestSize.Level1)6113 HWTEST_F(NapiBasicTest, NapiAsyncInitTest002, testing::ext::TestSize.Level1)
6114 {
6115     napi_env env = reinterpret_cast<napi_env>(engine_);
6116     napi_value resourceName;
6117     napi_async_context* context = nullptr;
6118 
6119     napi_create_string_utf8(env, "test", NAPI_AUTO_LENGTH, &resourceName);
6120     napi_status status = napi_async_init(env, nullptr, resourceName, context);
6121     ASSERT_EQ(status, napi_invalid_arg);
6122 }
6123 
HWTEST_F(NapiBasicTest, NapiMakeCallbackTest001, testing::ext::TestSize.Level1)6124 HWTEST_F(NapiBasicTest, NapiMakeCallbackTest001, testing::ext::TestSize.Level1)
6125 {
6126     napi_env env = reinterpret_cast<napi_env>(engine_);
6127     napi_async_context context = nullptr;
6128     napi_value recv = nullptr;
6129     napi_value func;
6130     size_t argc = 1;
6131     napi_value args[1] = {nullptr};
6132     napi_value result = nullptr;
6133 
6134     napi_create_double(env, TEST_DOUBLE, &func);
6135     napi_status status = napi_make_callback(env, context, recv, func, argc, args, &result);
6136     ASSERT_EQ(status, napi_invalid_arg);
6137 }
6138 
HWTEST_F(NapiBasicTest, NapiMakeCallbackTest002, testing::ext::TestSize.Level1)6139 HWTEST_F(NapiBasicTest, NapiMakeCallbackTest002, testing::ext::TestSize.Level1)
6140 {
6141     napi_env env = reinterpret_cast<napi_env>(engine_);
6142     napi_async_context context = nullptr;
6143     napi_value recv;
6144     napi_value func = nullptr;
6145     size_t argc = 1;
6146     napi_value args[1] = {nullptr};
6147     napi_value result = nullptr;
6148 
6149     napi_create_double(env, TEST_DOUBLE, &recv);
6150     napi_status status = napi_make_callback(env, context, recv, func, argc, args, &result);
6151     ASSERT_EQ(status, napi_invalid_arg);
6152 }
6153 
HWTEST_F(NapiBasicTest, NapiAsyncDestroyTest001, testing::ext::TestSize.Level1)6154 HWTEST_F(NapiBasicTest, NapiAsyncDestroyTest001, testing::ext::TestSize.Level1)
6155 {
6156     napi_env env = reinterpret_cast<napi_env>(engine_);
6157     napi_async_context context = nullptr;
6158 
6159     napi_status status = napi_async_destroy(env, context);
6160     ASSERT_EQ(status, napi_invalid_arg);
6161 }
6162 
HWTEST_F(NapiBasicTest, NapiOpenCallbackScopeTest001, testing::ext::TestSize.Level1)6163 HWTEST_F(NapiBasicTest, NapiOpenCallbackScopeTest001, testing::ext::TestSize.Level1)
6164 {
6165     napi_env env = reinterpret_cast<napi_env>(engine_);
6166     napi_value obj = nullptr;
6167     napi_async_context context = nullptr;
6168     napi_callback_scope* result = nullptr;
6169 
6170     napi_status status = napi_open_callback_scope(env, obj, context, result);
6171     ASSERT_EQ(status, napi_invalid_arg);
6172 }
6173 
HWTEST_F(NapiBasicTest, NapiCloseCallbackScopeTest001, testing::ext::TestSize.Level1)6174 HWTEST_F(NapiBasicTest, NapiCloseCallbackScopeTest001, testing::ext::TestSize.Level1)
6175 {
6176     napi_env env = reinterpret_cast<napi_env>(engine_);
6177     napi_callback_scope result = nullptr;
6178 
6179     napi_status status = napi_close_callback_scope(env, result);
6180     ASSERT_EQ(status, napi_invalid_arg);
6181 }
6182 
HWTEST_F(NapiBasicTest, NapiGetVersionTest001, testing::ext::TestSize.Level1)6183 HWTEST_F(NapiBasicTest, NapiGetVersionTest001, testing::ext::TestSize.Level1)
6184 {
6185     napi_env env = reinterpret_cast<napi_env>(engine_);
6186     uint32_t* result = nullptr;
6187 
6188     napi_status status = napi_get_version(env, result);
6189     ASSERT_EQ(status, napi_invalid_arg);
6190 }
6191 
HWTEST_F(NapiBasicTest, NapiCreatePromiseTest001, testing::ext::TestSize.Level1)6192 HWTEST_F(NapiBasicTest, NapiCreatePromiseTest001, testing::ext::TestSize.Level1)
6193 {
6194     napi_env env = reinterpret_cast<napi_env>(engine_);
6195     napi_value* promise = nullptr;
6196     napi_deferred deferred = nullptr;
6197 
6198     napi_status status = napi_create_promise(env, &deferred, promise);
6199     ASSERT_EQ(status, napi_invalid_arg);
6200 }
6201 
HWTEST_F(NapiBasicTest, NapiCreatePromiseTest002, testing::ext::TestSize.Level1)6202 HWTEST_F(NapiBasicTest, NapiCreatePromiseTest002, testing::ext::TestSize.Level1)
6203 {
6204     napi_env env = reinterpret_cast<napi_env>(engine_);
6205     napi_value promise = nullptr;
6206     napi_deferred* deferred = nullptr;
6207 
6208     napi_status status = napi_create_promise(env, deferred, &promise);
6209     ASSERT_EQ(status, napi_invalid_arg);
6210 }
6211 
HWTEST_F(NapiBasicTest, NapiResolveDeferredTest001, testing::ext::TestSize.Level1)6212 HWTEST_F(NapiBasicTest, NapiResolveDeferredTest001, testing::ext::TestSize.Level1)
6213 {
6214     napi_env env = reinterpret_cast<napi_env>(engine_);
6215     napi_deferred deferred = nullptr;
6216 
6217     napi_value resolution = nullptr;
6218     napi_create_double(env, TEST_DOUBLE, &resolution);
6219     napi_status status = napi_resolve_deferred(env, deferred, resolution);
6220     ASSERT_EQ(status, napi_invalid_arg);
6221 }
6222 
HWTEST_F(NapiBasicTest, NapiResolveDeferredTest002, testing::ext::TestSize.Level1)6223 HWTEST_F(NapiBasicTest, NapiResolveDeferredTest002, testing::ext::TestSize.Level1)
6224 {
6225     napi_env env = reinterpret_cast<napi_env>(engine_);
6226     napi_deferred deferred = nullptr;
6227     napi_value promise = nullptr;
6228     napi_create_promise(env, &deferred, &promise);
6229 
6230     napi_value resolution = nullptr;
6231     napi_status status = napi_resolve_deferred(env, deferred, resolution);
6232     ASSERT_EQ(status, napi_invalid_arg);
6233 }
6234 
HWTEST_F(NapiBasicTest, NapiRejectDeferredTest001, testing::ext::TestSize.Level1)6235 HWTEST_F(NapiBasicTest, NapiRejectDeferredTest001, testing::ext::TestSize.Level1)
6236 {
6237     napi_env env = reinterpret_cast<napi_env>(engine_);
6238     napi_deferred deferred = nullptr;
6239 
6240     napi_value resolution = nullptr;
6241     napi_create_double(env, TEST_DOUBLE, &resolution);
6242     napi_status status = napi_reject_deferred(env, deferred, resolution);
6243     ASSERT_EQ(status, napi_invalid_arg);
6244 }
6245 
HWTEST_F(NapiBasicTest, NapiRejectDeferredTest002, testing::ext::TestSize.Level1)6246 HWTEST_F(NapiBasicTest, NapiRejectDeferredTest002, testing::ext::TestSize.Level1)
6247 {
6248     napi_env env = reinterpret_cast<napi_env>(engine_);
6249     napi_deferred deferred = nullptr;
6250     napi_value promise = nullptr;
6251     napi_create_promise(env, &deferred, &promise);
6252 
6253     napi_value resolution = nullptr;
6254     napi_status status = napi_reject_deferred(env, deferred, resolution);
6255     ASSERT_EQ(status, napi_invalid_arg);
6256 }
6257 
HWTEST_F(NapiBasicTest, NapiIsPromiseTest001, testing::ext::TestSize.Level1)6258 HWTEST_F(NapiBasicTest, NapiIsPromiseTest001, testing::ext::TestSize.Level1)
6259 {
6260     napi_env env = reinterpret_cast<napi_env>(engine_);
6261     napi_value promise = nullptr;
6262     bool result;
6263 
6264     napi_status status = napi_is_promise(env, promise, &result);
6265     ASSERT_EQ(status, napi_invalid_arg);
6266 }
6267 
HWTEST_F(NapiBasicTest, NapiIsPromiseTest002, testing::ext::TestSize.Level1)6268 HWTEST_F(NapiBasicTest, NapiIsPromiseTest002, testing::ext::TestSize.Level1)
6269 {
6270     napi_env env = reinterpret_cast<napi_env>(engine_);
6271     napi_deferred deferred = nullptr;
6272     napi_value promise = nullptr;
6273     napi_create_promise(env, &deferred, &promise);
6274     bool* result = nullptr;
6275 
6276     napi_status status = napi_is_promise(env, promise, result);
6277     ASSERT_EQ(status, napi_invalid_arg);
6278 }
6279 
HWTEST_F(NapiBasicTest, NapiGetUvEventLoopTest001, testing::ext::TestSize.Level1)6280 HWTEST_F(NapiBasicTest, NapiGetUvEventLoopTest001, testing::ext::TestSize.Level1)
6281 {
6282     napi_env env = reinterpret_cast<napi_env>(engine_);
6283     struct uv_loop_s** loop = nullptr;
6284 
6285     napi_status status = napi_get_uv_event_loop(env, loop);
6286     ASSERT_EQ(status, napi_invalid_arg);
6287 }
6288 
HWTEST_F(NapiBasicTest, NapiCreateThreadsafeFunctionTest001, testing::ext::TestSize.Level1)6289 HWTEST_F(NapiBasicTest, NapiCreateThreadsafeFunctionTest001, testing::ext::TestSize.Level1)
6290 {
6291     napi_env env = reinterpret_cast<napi_env>(engine_);
6292     napi_value jsCb = 0;
6293     napi_create_object(env, &jsCb);
6294     napi_threadsafe_function tsFunc = nullptr;
6295     napi_value resourceName = nullptr;
6296     int32_t callJsCbDataTestId = 101;
6297     int32_t finalCbDataTestId = 1001;
6298     napi_status status = napi_create_threadsafe_function(env, jsCb, nullptr, resourceName,
6299                                                          0, 1, &callJsCbDataTestId,
6300                                                          nullptr, &finalCbDataTestId, nullptr, &tsFunc);
6301     ASSERT_EQ(status, napi_invalid_arg);
6302 }
6303 
HWTEST_F(NapiBasicTest, NapiCreateThreadsafeFunctionTest002, testing::ext::TestSize.Level1)6304 HWTEST_F(NapiBasicTest, NapiCreateThreadsafeFunctionTest002, testing::ext::TestSize.Level1)
6305 {
6306     napi_env env = reinterpret_cast<napi_env>(engine_);
6307     napi_value jsCb = 0;
6308     napi_create_object(env, &jsCb);
6309     napi_threadsafe_function tsFunc = nullptr;
6310     napi_value resourceName = nullptr;
6311     napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName);
6312     int32_t callJsCbDataTestId = 101;
6313     int32_t finalCbDataTestId = 1001;
6314     napi_status status = napi_create_threadsafe_function(env, jsCb, nullptr, resourceName,
6315                                                          0, 129, &callJsCbDataTestId,
6316                                                          nullptr, &finalCbDataTestId, nullptr, &tsFunc);
6317     ASSERT_EQ(status, napi_invalid_arg);
6318 }
6319 
HWTEST_F(NapiBasicTest, NapiGetThreadsafeFunctionContextTest001, testing::ext::TestSize.Level1)6320 HWTEST_F(NapiBasicTest, NapiGetThreadsafeFunctionContextTest001, testing::ext::TestSize.Level1)
6321 {
6322     napi_threadsafe_function tsFunc = nullptr;
6323     void** result = nullptr;
6324     napi_status status = napi_get_threadsafe_function_context(tsFunc, result);
6325     ASSERT_EQ(status, napi_invalid_arg);
6326 }
6327 
HWTEST_F(NapiBasicTest, NapiCallThreadsafeFunctionTest001, testing::ext::TestSize.Level1)6328 HWTEST_F(NapiBasicTest, NapiCallThreadsafeFunctionTest001, testing::ext::TestSize.Level1)
6329 {
6330     napi_threadsafe_function tsFunc = nullptr;
6331     void* result = nullptr;
6332     napi_status status = napi_call_threadsafe_function(tsFunc, result, napi_tsfn_blocking);
6333     ASSERT_EQ(status, napi_invalid_arg);
6334 }
6335 
HWTEST_F(NapiBasicTest, NapiAcquireThreadsafeFunctionTest001, testing::ext::TestSize.Level1)6336 HWTEST_F(NapiBasicTest, NapiAcquireThreadsafeFunctionTest001, testing::ext::TestSize.Level1)
6337 {
6338     napi_threadsafe_function tsFunc = nullptr;
6339     napi_status status = napi_acquire_threadsafe_function(tsFunc);
6340     ASSERT_EQ(status, napi_invalid_arg);
6341 }
6342 
HWTEST_F(NapiBasicTest, NapiReleaseThreadsafeFunctionTest001, testing::ext::TestSize.Level1)6343 HWTEST_F(NapiBasicTest, NapiReleaseThreadsafeFunctionTest001, testing::ext::TestSize.Level1)
6344 {
6345     napi_threadsafe_function tsFunc = nullptr;
6346     napi_status status = napi_release_threadsafe_function(tsFunc, napi_tsfn_release);
6347     ASSERT_EQ(status, napi_invalid_arg);
6348 }
6349 
HWTEST_F(NapiBasicTest, NapiRefThreadsafeFunctionTest001, testing::ext::TestSize.Level1)6350 HWTEST_F(NapiBasicTest, NapiRefThreadsafeFunctionTest001, testing::ext::TestSize.Level1)
6351 {
6352     napi_env env = reinterpret_cast<napi_env>(engine_);
6353     napi_threadsafe_function tsFunc = nullptr;
6354     napi_status status = napi_ref_threadsafe_function(env, tsFunc);
6355     ASSERT_EQ(status, napi_invalid_arg);
6356 }
6357 
HWTEST_F(NapiBasicTest, NapiUnrefThreadsafeFunctionTest001, testing::ext::TestSize.Level1)6358 HWTEST_F(NapiBasicTest, NapiUnrefThreadsafeFunctionTest001, testing::ext::TestSize.Level1)
6359 {
6360     napi_env env = reinterpret_cast<napi_env>(engine_);
6361     napi_threadsafe_function tsFunc = nullptr;
6362     napi_status status = napi_unref_threadsafe_function(env, tsFunc);
6363     ASSERT_EQ(status, napi_invalid_arg);
6364 }
6365 
HWTEST_F(NapiBasicTest, NapiCreateDateTest001, testing::ext::TestSize.Level1)6366 HWTEST_F(NapiBasicTest, NapiCreateDateTest001, testing::ext::TestSize.Level1)
6367 {
6368     napi_env env = reinterpret_cast<napi_env>(engine_);
6369     napi_value* result = nullptr;
6370 
6371     napi_status status = napi_create_date(env, TEST_DOUBLE, result);
6372     ASSERT_EQ(status, napi_invalid_arg);
6373 }
6374 
HWTEST_F(NapiBasicTest, NapiGetDateValueTest001, testing::ext::TestSize.Level1)6375 HWTEST_F(NapiBasicTest, NapiGetDateValueTest001, testing::ext::TestSize.Level1)
6376 {
6377     napi_env env = reinterpret_cast<napi_env>(engine_);
6378     napi_value date = nullptr;
6379     double result;
6380 
6381     napi_status status = napi_get_date_value(env, date, &result);
6382     ASSERT_EQ(status, napi_invalid_arg);
6383 }
6384 
HWTEST_F(NapiBasicTest, NapiGetDateValueTest002, testing::ext::TestSize.Level1)6385 HWTEST_F(NapiBasicTest, NapiGetDateValueTest002, testing::ext::TestSize.Level1)
6386 {
6387     napi_env env = reinterpret_cast<napi_env>(engine_);
6388     double time = 202110181203150;
6389     napi_value date;
6390     double* result = nullptr;
6391 
6392     napi_status status = napi_create_date(env, time, &date);
6393     status = napi_get_date_value(env, date, result);
6394     ASSERT_EQ(status, napi_invalid_arg);
6395 }
6396 
HWTEST_F(NapiBasicTest, NapiGetDateValueTest003, testing::ext::TestSize.Level1)6397 HWTEST_F(NapiBasicTest, NapiGetDateValueTest003, testing::ext::TestSize.Level1)
6398 {
6399     napi_env env = reinterpret_cast<napi_env>(engine_);
6400     napi_value date;
6401     double result;
6402 
6403     napi_status status = napi_create_object(env, &date);
6404     status = napi_get_date_value(env, date, &result);
6405     ASSERT_EQ(status, napi_date_expected);
6406 }
6407 
HWTEST_F(NapiBasicTest, NapiCreateBigintInt64Test001, testing::ext::TestSize.Level1)6408 HWTEST_F(NapiBasicTest, NapiCreateBigintInt64Test001, testing::ext::TestSize.Level1)
6409 {
6410     napi_env env = reinterpret_cast<napi_env>(engine_);
6411     int64_t value = INT_ONE;
6412     napi_value* result = nullptr;
6413 
6414     napi_status status = napi_create_bigint_int64(env, value, result);
6415     ASSERT_EQ(status, napi_invalid_arg);
6416 }
6417 
HWTEST_F(NapiBasicTest, NapiCreateBigintUint64Test001, testing::ext::TestSize.Level1)6418 HWTEST_F(NapiBasicTest, NapiCreateBigintUint64Test001, testing::ext::TestSize.Level1)
6419 {
6420     napi_env env = reinterpret_cast<napi_env>(engine_);
6421     int64_t value = INT_ONE;
6422     napi_value* result = nullptr;
6423 
6424     napi_status status = napi_create_bigint_uint64(env, value, result);
6425     ASSERT_EQ(status, napi_invalid_arg);
6426 }
6427 
HWTEST_F(NapiBasicTest, NapiCreateBigintWordsTest001, testing::ext::TestSize.Level1)6428 HWTEST_F(NapiBasicTest, NapiCreateBigintWordsTest001, testing::ext::TestSize.Level1)
6429 {
6430     napi_env env = reinterpret_cast<napi_env>(engine_);
6431     int signBit = 0;
6432     size_t wordCount = 4;
6433     uint64_t* words = nullptr;
6434     napi_value result = nullptr;
6435 
6436     napi_status status = napi_create_bigint_words(env, signBit, wordCount, words, &result);
6437     ASSERT_EQ(status, napi_invalid_arg);
6438 }
6439 
HWTEST_F(NapiBasicTest, NapiCreateBigintWordsTest002, testing::ext::TestSize.Level1)6440 HWTEST_F(NapiBasicTest, NapiCreateBigintWordsTest002, testing::ext::TestSize.Level1)
6441 {
6442     napi_env env = reinterpret_cast<napi_env>(engine_);
6443     int signBit = 0;
6444     size_t wordCount = 4;
6445     uint64_t words[] = {0ULL, 34ULL, 56ULL, 2ULL};
6446     napi_value* result = nullptr;
6447 
6448     napi_status status = napi_create_bigint_words(env, signBit, wordCount, words, result);
6449     ASSERT_EQ(status, napi_invalid_arg);
6450 }
6451 
HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test001, testing::ext::TestSize.Level1)6452 HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test001, testing::ext::TestSize.Level1)
6453 {
6454     napi_env env = reinterpret_cast<napi_env>(engine_);
6455     napi_value value = nullptr;
6456     int64_t result = 0;
6457     bool lossless = false;
6458 
6459     napi_status status = napi_get_value_bigint_int64(env, value, &result, &lossless);
6460     ASSERT_EQ(status, napi_invalid_arg);
6461 }
6462 
HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test002, testing::ext::TestSize.Level1)6463 HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test002, testing::ext::TestSize.Level1)
6464 {
6465     napi_env env = reinterpret_cast<napi_env>(engine_);
6466     int64_t testValue = INT64_MAX;
6467     napi_value value = nullptr;
6468     napi_create_bigint_int64(env, testValue, &value);
6469     int64_t* result = nullptr;
6470     bool lossless = false;
6471 
6472     napi_status status = napi_get_value_bigint_int64(env, value, result, &lossless);
6473     ASSERT_EQ(status, napi_invalid_arg);
6474 }
6475 
HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test003, testing::ext::TestSize.Level1)6476 HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test003, testing::ext::TestSize.Level1)
6477 {
6478     napi_env env = reinterpret_cast<napi_env>(engine_);
6479     int64_t testValue = INT64_MAX;
6480     napi_value value = nullptr;
6481     napi_create_bigint_int64(env, testValue, &value);
6482     int64_t result = 0;
6483     bool* lossless = nullptr;
6484 
6485     napi_status status = napi_get_value_bigint_int64(env, value, &result, lossless);
6486     ASSERT_EQ(status, napi_invalid_arg);
6487 }
6488 
HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test004, testing::ext::TestSize.Level1)6489 HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test004, testing::ext::TestSize.Level1)
6490 {
6491     napi_env env = reinterpret_cast<napi_env>(engine_);
6492     napi_value value = nullptr;
6493     napi_create_object(env, &value);
6494     int64_t result = 0;
6495     bool lossless = false;
6496 
6497     napi_status status = napi_get_value_bigint_int64(env, value, &result, &lossless);
6498     ASSERT_EQ(status, napi_bigint_expected);
6499 }
6500 
HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test005, testing::ext::TestSize.Level1)6501 HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test005, testing::ext::TestSize.Level1)
6502 {
6503     napi_env env = reinterpret_cast<napi_env>(engine_);
6504     uint64_t testValue = UINT64_MAX;
6505     napi_value value = nullptr;
6506     napi_create_bigint_uint64(env, testValue, &value);
6507     int64_t result = 0;
6508     bool lossless = false;
6509 
6510     napi_status status = napi_get_value_bigint_int64(env, value, &result, &lossless);
6511     ASSERT_EQ(status, napi_ok);
6512     ASSERT_EQ(lossless, false);
6513 }
6514 
HWTEST_F(NapiBasicTest, NapiGetValueBigintUint64Test001, testing::ext::TestSize.Level1)6515 HWTEST_F(NapiBasicTest, NapiGetValueBigintUint64Test001, testing::ext::TestSize.Level1)
6516 {
6517     napi_env env = reinterpret_cast<napi_env>(engine_);
6518     napi_value value = nullptr;
6519     uint64_t result = 0;
6520     bool lossless = false;
6521 
6522     napi_status status = napi_get_value_bigint_uint64(env, value, &result, &lossless);
6523     ASSERT_EQ(status, napi_invalid_arg);
6524 }
6525 
HWTEST_F(NapiBasicTest, NapiGetValueBigintUint64Test002, testing::ext::TestSize.Level1)6526 HWTEST_F(NapiBasicTest, NapiGetValueBigintUint64Test002, testing::ext::TestSize.Level1)
6527 {
6528     napi_env env = reinterpret_cast<napi_env>(engine_);
6529     uint64_t testValue = UINT64_MAX;
6530     napi_value value = nullptr;
6531     napi_create_bigint_uint64(env, testValue, &value);
6532     uint64_t* result = nullptr;
6533     bool lossless = false;
6534 
6535     napi_status status = napi_get_value_bigint_uint64(env, value, result, &lossless);
6536     ASSERT_EQ(status, napi_invalid_arg);
6537 }
6538 
HWTEST_F(NapiBasicTest, NapiGetValueBigintUint64Test003, testing::ext::TestSize.Level1)6539 HWTEST_F(NapiBasicTest, NapiGetValueBigintUint64Test003, testing::ext::TestSize.Level1)
6540 {
6541     napi_env env = reinterpret_cast<napi_env>(engine_);
6542     uint64_t testValue = UINT64_MAX;
6543     napi_value value = nullptr;
6544     napi_create_bigint_uint64(env, testValue, &value);
6545     uint64_t result = 0;
6546     bool* lossless = nullptr;
6547 
6548     napi_status status = napi_get_value_bigint_uint64(env, value, &result, lossless);
6549     ASSERT_EQ(status, napi_invalid_arg);
6550 }
6551 
HWTEST_F(NapiBasicTest, NapiGetValueBigintUint64Test004, testing::ext::TestSize.Level1)6552 HWTEST_F(NapiBasicTest, NapiGetValueBigintUint64Test004, testing::ext::TestSize.Level1)
6553 {
6554     napi_env env = reinterpret_cast<napi_env>(engine_);
6555     napi_value value = nullptr;
6556     napi_create_object(env, &value);
6557     uint64_t result = 0;
6558     bool lossless = false;
6559 
6560     napi_status status = napi_get_value_bigint_uint64(env, value, &result, &lossless);
6561     ASSERT_EQ(status, napi_bigint_expected);
6562 }
6563 
HWTEST_F(NapiBasicTest, NapiGetValueBigintWordsTest001, testing::ext::TestSize.Level1)6564 HWTEST_F(NapiBasicTest, NapiGetValueBigintWordsTest001, testing::ext::TestSize.Level1)
6565 {
6566     uint64_t wordsOut[] = {0ULL, 0ULL, 0ULL, 0ULL};
6567     napi_env env = reinterpret_cast<napi_env>(engine_);
6568     napi_value value = nullptr;
6569 
6570     int retSignBit = -1;
6571     size_t retWordCount = 4;
6572     napi_status status = napi_get_value_bigint_words(env, value, &retSignBit, &retWordCount, wordsOut);
6573     ASSERT_EQ(status, napi_invalid_arg);
6574 }
6575 
HWTEST_F(NapiBasicTest, NapiGetValueBigintWordsTest002, testing::ext::TestSize.Level1)6576 HWTEST_F(NapiBasicTest, NapiGetValueBigintWordsTest002, testing::ext::TestSize.Level1)
6577 {
6578     int signBit = 0;
6579     size_t wordCount = 4;
6580     uint64_t words[] = {0ULL, 34ULL, 56ULL, 2ULL};
6581     uint64_t wordsOut[] = {0ULL, 0ULL, 0ULL, 0ULL};
6582     napi_env env = reinterpret_cast<napi_env>(engine_);
6583     napi_value value = nullptr;
6584     napi_status status = napi_create_bigint_words(env, signBit, wordCount, words, &value);
6585     ASSERT_EQ(status, napi_ok);
6586 
6587     int retSignBit = -1;
6588     size_t* retWordCount = nullptr;
6589     status = napi_get_value_bigint_words(env, value, &retSignBit, retWordCount, wordsOut);
6590     ASSERT_EQ(status, napi_invalid_arg);
6591 }
6592 
HWTEST_F(NapiBasicTest, NapiCreateBufferTest001, testing::ext::TestSize.Level1)6593 HWTEST_F(NapiBasicTest, NapiCreateBufferTest001, testing::ext::TestSize.Level1)
6594 {
6595     napi_env env = reinterpret_cast<napi_env>(engine_);
6596     const unsigned int bufferSize = sizeof(TEST_STRING);
6597     char** data = nullptr;
6598     napi_value result;
6599     napi_status status = napi_create_buffer(env, bufferSize, (void**)(data), &result);
6600     ASSERT_EQ(status, napi_invalid_arg);
6601 }
6602 
HWTEST_F(NapiBasicTest, NapiCreateBufferTest002, testing::ext::TestSize.Level1)6603 HWTEST_F(NapiBasicTest, NapiCreateBufferTest002, testing::ext::TestSize.Level1)
6604 {
6605     napi_env env = reinterpret_cast<napi_env>(engine_);
6606     const unsigned int bufferSize = sizeof(TEST_STRING);
6607     char* data;
6608     napi_value* result = nullptr;
6609     napi_status status = napi_create_buffer(env, bufferSize, (void**)(&data), result);
6610     ASSERT_EQ(status, napi_invalid_arg);
6611 }
6612 
HWTEST_F(NapiBasicTest, NapiCreateBufferTest003, testing::ext::TestSize.Level1)6613 HWTEST_F(NapiBasicTest, NapiCreateBufferTest003, testing::ext::TestSize.Level1)
6614 {
6615     napi_env env = reinterpret_cast<napi_env>(engine_);
6616     const unsigned int bufferSize = 0;
6617     char* data;
6618     napi_value result;
6619     napi_status status = napi_create_buffer(env, bufferSize, (void**)(&data), &result);
6620     ASSERT_EQ(status, napi_invalid_arg);
6621 }
6622 
HWTEST_F(NapiBasicTest, NapiCreateBufferTest004, testing::ext::TestSize.Level1)6623 HWTEST_F(NapiBasicTest, NapiCreateBufferTest004, testing::ext::TestSize.Level1)
6624 {
6625     napi_env env = reinterpret_cast<napi_env>(engine_);
6626     const unsigned int bufferSize = MAX_BYTE_LENGTH + 1;
6627     char* data;
6628     napi_value result;
6629     napi_status status = napi_create_buffer(env, bufferSize, (void**)(&data), &result);
6630     ASSERT_EQ(status, napi_invalid_arg);
6631 }
6632 
HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest001, testing::ext::TestSize.Level1)6633 HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest001, testing::ext::TestSize.Level1)
6634 {
6635     napi_env env = reinterpret_cast<napi_env>(engine_);
6636     const unsigned int bufferSize = 0;
6637     char* data;
6638     napi_value result;
6639     napi_status status = napi_create_buffer_copy(env, bufferSize, TEST_STRING, (void**)(&data), &result);
6640     ASSERT_EQ(status, napi_invalid_arg);
6641 }
6642 
HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest002, testing::ext::TestSize.Level1)6643 HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest002, testing::ext::TestSize.Level1)
6644 {
6645     napi_env env = reinterpret_cast<napi_env>(engine_);
6646     const unsigned int bufferSize = MAX_BYTE_LENGTH + 1;
6647     char* data;
6648     napi_value result;
6649     napi_status status = napi_create_buffer_copy(env, bufferSize, TEST_STRING, (void**)(&data), &result);
6650     ASSERT_EQ(status, napi_invalid_arg);
6651 }
6652 
HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest003, testing::ext::TestSize.Level1)6653 HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest003, testing::ext::TestSize.Level1)
6654 {
6655     napi_env env = reinterpret_cast<napi_env>(engine_);
6656     const unsigned int bufferSize = sizeof(TEST_STRING);
6657     char* data;
6658     napi_value result;
6659     napi_status status = napi_create_buffer_copy(env, bufferSize, nullptr, (void**)(&data), &result);
6660     ASSERT_EQ(status, napi_invalid_arg);
6661 }
6662 
HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest004, testing::ext::TestSize.Level1)6663 HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest004, testing::ext::TestSize.Level1)
6664 {
6665     napi_env env = reinterpret_cast<napi_env>(engine_);
6666     const unsigned int bufferSize = sizeof(TEST_STRING);
6667     char** data = nullptr;
6668     napi_value result;
6669     napi_status status = napi_create_buffer_copy(env, bufferSize, TEST_STRING, (void**)(data), &result);
6670     ASSERT_EQ(status, napi_invalid_arg);
6671 }
6672 
HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest005, testing::ext::TestSize.Level1)6673 HWTEST_F(NapiBasicTest, NapiCreateBufferCopyTest005, testing::ext::TestSize.Level1)
6674 {
6675     napi_env env = reinterpret_cast<napi_env>(engine_);
6676     const unsigned int bufferSize = sizeof(TEST_STRING);
6677     char* data;
6678     napi_value* result = nullptr;
6679     napi_status status = napi_create_buffer_copy(env, bufferSize, TEST_STRING, (void**)(&data), result);
6680     ASSERT_EQ(status, napi_invalid_arg);
6681 }
6682 
HWTEST_F(NapiBasicTest, NapiCreateExternalBufferTest001, testing::ext::TestSize.Level1)6683 HWTEST_F(NapiBasicTest, NapiCreateExternalBufferTest001, testing::ext::TestSize.Level1)
6684 {
6685     napi_env env = reinterpret_cast<napi_env>(engine_);
6686     const unsigned int bufferSize = 0;
6687     char* copyPtr = strdup(TEST_STRING);
6688     napi_value result;
6689     napi_status status = napi_create_external_buffer(env, bufferSize, copyPtr,
6690         [](napi_env env, void* data, void* hint) { return; },
6691         nullptr, &result);
6692     ASSERT_EQ(status, napi_invalid_arg);
6693 }
6694 
HWTEST_F(NapiBasicTest, NapiCreateExternalBufferTest002, testing::ext::TestSize.Level1)6695 HWTEST_F(NapiBasicTest, NapiCreateExternalBufferTest002, testing::ext::TestSize.Level1)
6696 {
6697     napi_env env = reinterpret_cast<napi_env>(engine_);
6698     const unsigned int bufferSize = MAX_BYTE_LENGTH + 1;
6699     char* copyPtr = strdup(TEST_STRING);
6700     napi_value result;
6701     napi_status status = napi_create_external_buffer(env, bufferSize, copyPtr,
6702         [](napi_env env, void* data, void* hint) { return; },
6703         nullptr, &result);
6704     ASSERT_EQ(status, napi_invalid_arg);
6705 }
6706 
HWTEST_F(NapiBasicTest, NapiCreateExternalBufferTest003, testing::ext::TestSize.Level1)6707 HWTEST_F(NapiBasicTest, NapiCreateExternalBufferTest003, testing::ext::TestSize.Level1)
6708 {
6709     napi_env env = reinterpret_cast<napi_env>(engine_);
6710     const unsigned int bufferSize = sizeof(TEST_STRING);
6711     char* copyPtr = nullptr;
6712     napi_value result;
6713     napi_status status = napi_create_external_buffer(env, bufferSize, copyPtr,
6714         [](napi_env env, void* data, void* hint) { return; },
6715         nullptr, &result);
6716     ASSERT_EQ(status, napi_invalid_arg);
6717 }
6718 
HWTEST_F(NapiBasicTest, NapiCreateExternalBufferTest004, testing::ext::TestSize.Level1)6719 HWTEST_F(NapiBasicTest, NapiCreateExternalBufferTest004, testing::ext::TestSize.Level1)
6720 {
6721     napi_env env = reinterpret_cast<napi_env>(engine_);
6722     const unsigned int bufferSize = sizeof(TEST_STRING);
6723     char* copyPtr = strdup(TEST_STRING);
6724     napi_value* result = nullptr;
6725     napi_status status = napi_create_external_buffer(env, bufferSize, copyPtr,
6726         [](napi_env env, void* data, void* hint) { return; },
6727         nullptr, result);
6728     ASSERT_EQ(status, napi_invalid_arg);
6729 }
6730 
HWTEST_F(NapiBasicTest, NapiGetBufferInfoTest001, testing::ext::TestSize.Level1)6731 HWTEST_F(NapiBasicTest, NapiGetBufferInfoTest001, testing::ext::TestSize.Level1)
6732 {
6733     napi_env env = reinterpret_cast<napi_env>(engine_);
6734     napi_value value = nullptr;
6735     char *data;
6736     size_t length;
6737 
6738     napi_status status = napi_get_buffer_info(env, value, (void**)&data, &length);
6739     ASSERT_EQ(status, napi_invalid_arg);
6740 }
6741 
HWTEST_F(NapiBasicTest, NapiGetBufferInfoTest002, testing::ext::TestSize.Level1)6742 HWTEST_F(NapiBasicTest, NapiGetBufferInfoTest002, testing::ext::TestSize.Level1)
6743 {
6744     napi_env env = reinterpret_cast<napi_env>(engine_);
6745     napi_value value = nullptr;
6746     char *data;
6747     size_t length;
6748 
6749     napi_create_double(env, TEST_DOUBLE, &value);
6750     napi_status status = napi_get_buffer_info(env, value, (void**)&data, &length);
6751     ASSERT_EQ(status, napi_arraybuffer_expected);
6752 }
6753 
HWTEST_F(NapiBasicTest, NapiIsBufferTest001, testing::ext::TestSize.Level1)6754 HWTEST_F(NapiBasicTest, NapiIsBufferTest001, testing::ext::TestSize.Level1)
6755 {
6756     napi_env env = reinterpret_cast<napi_env>(engine_);
6757     napi_value value = nullptr;
6758     bool result;
6759 
6760     napi_status status = napi_is_buffer(env, value, &result);
6761     ASSERT_EQ(status, napi_invalid_arg);
6762 }
6763 
HWTEST_F(NapiBasicTest, NapiIsBufferTest002, testing::ext::TestSize.Level1)6764 HWTEST_F(NapiBasicTest, NapiIsBufferTest002, testing::ext::TestSize.Level1)
6765 {
6766     napi_env env = reinterpret_cast<napi_env>(engine_);
6767     napi_value value;
6768     bool* result = nullptr;
6769 
6770     napi_create_object(env, &value);
6771     napi_status status = napi_is_buffer(env, value, result);
6772     ASSERT_EQ(status, napi_invalid_arg);
6773 }
6774 
HWTEST_F(NapiBasicTest, NapiDeserializeTest001, testing::ext::TestSize.Level1)6775 HWTEST_F(NapiBasicTest, NapiDeserializeTest001, testing::ext::TestSize.Level1)
6776 {
6777     napi_env env = reinterpret_cast<napi_env>(engine_);
6778     void* buffer = nullptr;
6779     napi_value result = nullptr;
6780 
6781     napi_status status = napi_deserialize(env, buffer, &result);
6782     ASSERT_EQ(status, napi_invalid_arg);
6783 }
6784 
HWTEST_F(NapiBasicTest, NapiDeserializeTest002, testing::ext::TestSize.Level1)6785 HWTEST_F(NapiBasicTest, NapiDeserializeTest002, testing::ext::TestSize.Level1)
6786 {
6787     napi_env env = reinterpret_cast<napi_env>(engine_);
6788     int buffer = 0;
6789     napi_value* result = nullptr;
6790 
6791     napi_status status = napi_deserialize(env, (void*)&buffer, result);
6792     ASSERT_EQ(status, napi_invalid_arg);
6793 }
6794 
HWTEST_F(NapiBasicTest, NapiDeleteSerializationDataTest001, testing::ext::TestSize.Level1)6795 HWTEST_F(NapiBasicTest, NapiDeleteSerializationDataTest001, testing::ext::TestSize.Level1)
6796 {
6797     napi_env env = reinterpret_cast<napi_env>(engine_);
6798     void* buffer = nullptr;
6799 
6800     napi_status status = napi_delete_serialization_data(env, buffer);
6801     ASSERT_EQ(status, napi_invalid_arg);
6802 }
6803 
HWTEST_F(NapiBasicTest, NapiCallThreadsafeFunctionWithPriorityTest001, testing::ext::TestSize.Level1)6804 HWTEST_F(NapiBasicTest, NapiCallThreadsafeFunctionWithPriorityTest001, testing::ext::TestSize.Level1)
6805 {
6806     napi_threadsafe_function func = nullptr;
6807 
6808     napi_status status = napi_call_threadsafe_function_with_priority(func, nullptr, napi_priority_idle, true);
6809     ASSERT_EQ(status, napi_invalid_arg);
6810 }
6811 
HWTEST_F(NapiBasicTest, NapiIsSendableTest001, testing::ext::TestSize.Level1)6812 HWTEST_F(NapiBasicTest, NapiIsSendableTest001, testing::ext::TestSize.Level1)
6813 {
6814     napi_env env = reinterpret_cast<napi_env>(engine_);
6815     napi_value value = nullptr;
6816     bool result;
6817 
6818     napi_status status = napi_is_sendable(env, value, &result);
6819     ASSERT_EQ(status, napi_invalid_arg);
6820 }
6821 
HWTEST_F(NapiBasicTest, NapiIsSendableTest002, testing::ext::TestSize.Level1)6822 HWTEST_F(NapiBasicTest, NapiIsSendableTest002, testing::ext::TestSize.Level1)
6823 {
6824     napi_env env = reinterpret_cast<napi_env>(engine_);
6825     napi_value value;
6826     bool* result = nullptr;
6827 
6828     napi_create_object(env, &value);
6829     napi_status status = napi_is_sendable(env, value, result);
6830     ASSERT_EQ(status, napi_invalid_arg);
6831 }
6832 
HWTEST_F(NapiBasicTest, NapiDefineSendableClassTest001, testing::ext::TestSize.Level1)6833 HWTEST_F(NapiBasicTest, NapiDefineSendableClassTest001, testing::ext::TestSize.Level1)
6834 {
6835     napi_env env = reinterpret_cast<napi_env>(engine_);
6836     napi_value testClass = nullptr;
6837     napi_status status = napi_define_sendable_class(
6838         env, nullptr, NAPI_AUTO_LENGTH,
6839         [](napi_env env, napi_callback_info info) -> napi_value {
6840             napi_value thisVar = nullptr;
6841             napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
6842 
6843             return thisVar;
6844         },
6845         nullptr, 0, nullptr, nullptr, &testClass);
6846     ASSERT_EQ(status, napi_invalid_arg);
6847 }
6848 
HWTEST_F(NapiBasicTest, NapiDefineSendableClassTest002, testing::ext::TestSize.Level1)6849 HWTEST_F(NapiBasicTest, NapiDefineSendableClassTest002, testing::ext::TestSize.Level1)
6850 {
6851     napi_env env = reinterpret_cast<napi_env>(engine_);
6852     napi_value testClass = nullptr;
6853     napi_status status = napi_define_sendable_class(
6854         env, "TestClass", NAPI_AUTO_LENGTH,
6855         nullptr, nullptr, 0, nullptr, nullptr, &testClass);
6856     ASSERT_EQ(status, napi_invalid_arg);
6857 }
6858 
HWTEST_F(NapiBasicTest, NapiDefineSendableClassTest003, testing::ext::TestSize.Level1)6859 HWTEST_F(NapiBasicTest, NapiDefineSendableClassTest003, testing::ext::TestSize.Level1)
6860 {
6861     napi_env env = reinterpret_cast<napi_env>(engine_);
6862     napi_value testClass = nullptr;
6863     napi_status status = napi_define_sendable_class(
6864         env, "TestClass", NAPI_AUTO_LENGTH,
6865         [](napi_env env, napi_callback_info info) -> napi_value {
6866             napi_value thisVar = nullptr;
6867             napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
6868 
6869             return thisVar;
6870         },
6871         nullptr, 1, nullptr, nullptr, &testClass);
6872     ASSERT_EQ(status, napi_invalid_arg);
6873 }
6874 
HWTEST_F(NapiBasicTest, NapiDefineSendableClassTest004, testing::ext::TestSize.Level1)6875 HWTEST_F(NapiBasicTest, NapiDefineSendableClassTest004, testing::ext::TestSize.Level1)
6876 {
6877     napi_env env = reinterpret_cast<napi_env>(engine_);
6878     napi_value* testClass = nullptr;
6879     napi_status status = napi_define_sendable_class(
6880         env, "TestClass", NAPI_AUTO_LENGTH,
6881         [](napi_env env, napi_callback_info info) -> napi_value {
6882             napi_value thisVar = nullptr;
6883             napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
6884 
6885             return thisVar;
6886         },
6887         nullptr, 0, nullptr, nullptr, testClass);
6888     ASSERT_EQ(status, napi_invalid_arg);
6889 }
6890 
HWTEST_F(NapiBasicTest, NapiCreateSendableObjectWithPropertiesTest001, testing::ext::TestSize.Level1)6891 HWTEST_F(NapiBasicTest, NapiCreateSendableObjectWithPropertiesTest001, testing::ext::TestSize.Level1)
6892 {
6893     napi_env env = reinterpret_cast<napi_env>(engine_);
6894     napi_value val_true;
6895     napi_get_boolean(env, true, &val_true);
6896     napi_property_descriptor desc[] = {
6897         DECLARE_NAPI_DEFAULT_PROPERTY("x", val_true),
6898     };
6899     napi_value* result = nullptr;
6900 
6901     napi_status status = napi_create_sendable_object_with_properties(env, 1, desc, result);
6902     ASSERT_EQ(status, napi_invalid_arg);
6903 }
6904 
HWTEST_F(NapiBasicTest, NapiCreateSendableArrayTest001, testing::ext::TestSize.Level1)6905 HWTEST_F(NapiBasicTest, NapiCreateSendableArrayTest001, testing::ext::TestSize.Level1)
6906 {
6907     napi_env env = reinterpret_cast<napi_env>(engine_);
6908     napi_value* result = nullptr;
6909 
6910     napi_status status = napi_create_sendable_array(env, result);
6911     ASSERT_EQ(status, napi_invalid_arg);
6912 }
6913 
HWTEST_F(NapiBasicTest, NapiCreateSendableArrayWithLengthTest001, testing::ext::TestSize.Level1)6914 HWTEST_F(NapiBasicTest, NapiCreateSendableArrayWithLengthTest001, testing::ext::TestSize.Level1)
6915 {
6916     napi_env env = reinterpret_cast<napi_env>(engine_);
6917     size_t length = INT_ONE;
6918     napi_value* result = nullptr;
6919 
6920     napi_status status = napi_create_sendable_array_with_length(env, length, result);
6921     ASSERT_EQ(status, napi_invalid_arg);
6922 }
6923 
HWTEST_F(NapiBasicTest, NapiCreateSendableArraybufferTest001, testing::ext::TestSize.Level1)6924 HWTEST_F(NapiBasicTest, NapiCreateSendableArraybufferTest001, testing::ext::TestSize.Level1)
6925 {
6926     napi_env env = reinterpret_cast<napi_env>(engine_);
6927     size_t length = INT_ONE;
6928     void** data = nullptr;
6929     napi_value result;
6930 
6931     napi_status status = napi_create_sendable_arraybuffer(env, length, data, &result);
6932     ASSERT_EQ(status, napi_invalid_arg);
6933 }
6934 
HWTEST_F(NapiBasicTest, NapiCreateSendableArraybufferTest002, testing::ext::TestSize.Level1)6935 HWTEST_F(NapiBasicTest, NapiCreateSendableArraybufferTest002, testing::ext::TestSize.Level1)
6936 {
6937     napi_env env = reinterpret_cast<napi_env>(engine_);
6938     size_t length = INT_ONE;
6939     void* data;
6940     napi_value* result = nullptr;
6941 
6942     napi_status status = napi_create_sendable_arraybuffer(env, length, &data, result);
6943     ASSERT_EQ(status, napi_invalid_arg);
6944 }
6945 
HWTEST_F(NapiBasicTest, NapiCreateSendableTypedarrayTest001, testing::ext::TestSize.Level1)6946 HWTEST_F(NapiBasicTest, NapiCreateSendableTypedarrayTest001, testing::ext::TestSize.Level1)
6947 {
6948     napi_env env = reinterpret_cast<napi_env>(engine_);
6949     napi_value arraybuffer = nullptr;
6950     void* arrayBufferPtr = nullptr;
6951     size_t arrayBufferSize = 16;
6952     size_t typedArrayLength = 4;
6953     napi_status status = napi_create_sendable_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arraybuffer);
6954     ASSERT_EQ(status, napi_ok);
6955 
6956     napi_value* result = nullptr;
6957     status = napi_create_sendable_typedarray(env, napi_int32_array, typedArrayLength, arraybuffer, 0, result);
6958     ASSERT_EQ(status, napi_invalid_arg);
6959 }
6960 
HWTEST_F(NapiBasicTest, NapiCreateSendableTypedarrayTest002, testing::ext::TestSize.Level1)6961 HWTEST_F(NapiBasicTest, NapiCreateSendableTypedarrayTest002, testing::ext::TestSize.Level1)
6962 {
6963     napi_env env = reinterpret_cast<napi_env>(engine_);
6964     napi_value arraybuffer = nullptr;
6965     size_t typedArrayLength = 4;
6966 
6967     napi_value result;
6968     napi_status status = napi_create_sendable_typedarray(env, napi_int32_array, typedArrayLength,
6969         arraybuffer, 0, &result);
6970     ASSERT_EQ(status, napi_invalid_arg);
6971 }
6972 
HWTEST_F(NapiBasicTest, NapiWrapSendableTest001, testing::ext::TestSize.Level1)6973 HWTEST_F(NapiBasicTest, NapiWrapSendableTest001, testing::ext::TestSize.Level1)
6974 {
6975     napi_env env = reinterpret_cast<napi_env>(engine_);
6976     napi_value js_obj = nullptr;
6977 
6978     napi_status status = napi_wrap_sendable(
6979         env, js_obj, (void*)TEST_STRING, [](napi_env env, void* data, void* hint) {}, nullptr);
6980     ASSERT_EQ(status, napi_invalid_arg);
6981 }
6982 
HWTEST_F(NapiBasicTest, NapiWrapSendableTest002, testing::ext::TestSize.Level1)6983 HWTEST_F(NapiBasicTest, NapiWrapSendableTest002, testing::ext::TestSize.Level1)
6984 {
6985     napi_env env = reinterpret_cast<napi_env>(engine_);
6986     napi_value js_obj = nullptr;
6987 
6988     napi_status status = napi_create_object(env, &js_obj);
6989     status = napi_wrap_sendable(
6990         env, js_obj, nullptr, [](napi_env env, void* data, void* hint) {}, nullptr);
6991     ASSERT_EQ(status, napi_invalid_arg);
6992 }
6993 
HWTEST_F(NapiBasicTest, NapiWrapSendableWithSizeTest001, testing::ext::TestSize.Level1)6994 HWTEST_F(NapiBasicTest, NapiWrapSendableWithSizeTest001, testing::ext::TestSize.Level1)
6995 {
6996     napi_env env = reinterpret_cast<napi_env>(engine_);
6997     napi_value js_obj = nullptr;
6998 
6999     napi_status status = napi_wrap_sendable_with_size(
7000         env, js_obj, (void*)TEST_STRING, [](napi_env env, void* data, void* hint) {}, nullptr, INT_ONE);
7001     ASSERT_EQ(status, napi_invalid_arg);
7002 }
7003 
HWTEST_F(NapiBasicTest, NapiWrapSendableWithSizeTest002, testing::ext::TestSize.Level1)7004 HWTEST_F(NapiBasicTest, NapiWrapSendableWithSizeTest002, testing::ext::TestSize.Level1)
7005 {
7006     napi_env env = reinterpret_cast<napi_env>(engine_);
7007     napi_value js_obj = nullptr;
7008 
7009     napi_status status = napi_create_object(env, &js_obj);
7010     status = napi_wrap_sendable_with_size(
7011         env, js_obj, nullptr, [](napi_env env, void* data, void* hint) {}, nullptr, INT_ONE);
7012     ASSERT_EQ(status, napi_invalid_arg);
7013 }
7014 
HWTEST_F(NapiBasicTest, NapiUnwrapSendableTest001, testing::ext::TestSize.Level1)7015 HWTEST_F(NapiBasicTest, NapiUnwrapSendableTest001, testing::ext::TestSize.Level1)
7016 {
7017     napi_env env = reinterpret_cast<napi_env>(engine_);
7018     napi_value js_obj = nullptr;
7019     void* result;
7020 
7021     napi_status status = napi_unwrap_sendable(env, js_obj, &result);
7022     ASSERT_EQ(status, napi_invalid_arg);
7023 }
7024 
HWTEST_F(NapiBasicTest, NapiUnwrapSendableTest002, testing::ext::TestSize.Level1)7025 HWTEST_F(NapiBasicTest, NapiUnwrapSendableTest002, testing::ext::TestSize.Level1)
7026 {
7027     napi_env env = reinterpret_cast<napi_env>(engine_);
7028     napi_value js_obj;
7029     void** result = nullptr;
7030 
7031     napi_status status = napi_create_object(env, &js_obj);
7032     status = napi_unwrap_sendable(env, js_obj, result);
7033     ASSERT_EQ(status, napi_invalid_arg);
7034 }
7035 
HWTEST_F(NapiBasicTest, NapiRemoveWrapSendableTest001, testing::ext::TestSize.Level1)7036 HWTEST_F(NapiBasicTest, NapiRemoveWrapSendableTest001, testing::ext::TestSize.Level1)
7037 {
7038     napi_env env = reinterpret_cast<napi_env>(engine_);
7039     napi_value js_obj = nullptr;
7040     void* result;
7041 
7042     napi_status status = napi_remove_wrap_sendable(env, js_obj, &result);
7043     ASSERT_EQ(status, napi_invalid_arg);
7044 }
7045 
HWTEST_F(NapiBasicTest, NapiRemoveWrapSendableTest002, testing::ext::TestSize.Level1)7046 HWTEST_F(NapiBasicTest, NapiRemoveWrapSendableTest002, testing::ext::TestSize.Level1)
7047 {
7048     napi_env env = reinterpret_cast<napi_env>(engine_);
7049     napi_value js_obj;
7050     void** result = nullptr;
7051 
7052     napi_status status = napi_create_object(env, &js_obj);
7053     status = napi_remove_wrap_sendable(env, js_obj, result);
7054     ASSERT_EQ(status, napi_invalid_arg);
7055 }
7056 
7057 /**
7058  * @tc.name: NapiModuleRegisterTest
7059  * @tc.desc: Test interface of napi_module_register
7060  * @tc.type: FUNC
7061  */
HWTEST_F(NapiBasicTest, NapiModuleRegisterTest001, testing::ext::TestSize.Level1)7062 HWTEST_F(NapiBasicTest, NapiModuleRegisterTest001, testing::ext::TestSize.Level1)
7063 {
7064     // call napi_module_register interface with nullptr error
7065     napi_module_register(nullptr);
7066 }
7067 
7068 /**
7069  * @tc.name: NapiGetLastErrorInfoTest
7070  * @tc.desc: Test interface of napi_get_last_error_info
7071  * @tc.type: FUNC
7072  */
HWTEST_F(NapiBasicTest, NapiGetLastErrorInfoTest001, testing::ext::TestSize.Level1)7073 HWTEST_F(NapiBasicTest, NapiGetLastErrorInfoTest001, testing::ext::TestSize.Level1)
7074 {
7075     ASSERT_NE(engine_, nullptr);
7076     napi_env env = reinterpret_cast<napi_env>(engine_);
7077 
7078     // call napi_get_last_error_info interface with nullptr error
7079     auto res = napi_get_last_error_info(env, nullptr);
7080     ASSERT_EQ(res, napi_invalid_arg);
7081 }
7082 
7083 /**
7084  * @tc.name: NapiThrowTest
7085  * @tc.desc: Test interface of napi_throw
7086  * @tc.type: FUNC
7087  */
HWTEST_F(NapiBasicTest, NapiThrowTest001, testing::ext::TestSize.Level1)7088 HWTEST_F(NapiBasicTest, NapiThrowTest001, testing::ext::TestSize.Level1)
7089 {
7090     ASSERT_NE(engine_, nullptr);
7091     napi_env env = reinterpret_cast<napi_env>(engine_);
7092 
7093     // call napi_throw interface with nullptr error
7094     auto res = napi_throw(env, nullptr);
7095     ASSERT_EQ(res, napi_invalid_arg);
7096 }
7097 
7098 /**
7099  * @tc.name: NapiThrowErrorTest
7100  * @tc.desc: Test interface of napi_throw_error
7101  * @tc.type: FUNC
7102  */
HWTEST_F(NapiBasicTest, NapiThrowErrorTest001, testing::ext::TestSize.Level1)7103 HWTEST_F(NapiBasicTest, NapiThrowErrorTest001, testing::ext::TestSize.Level1)
7104 {
7105     ASSERT_NE(engine_, nullptr);
7106     napi_env env = reinterpret_cast<napi_env>(engine_);
7107 
7108     // call napi_throw_error interface with nullptr msg
7109     auto res = napi_throw_error(env, nullptr, nullptr);
7110     ASSERT_EQ(res, napi_invalid_arg);
7111 }
7112 
7113 /**
7114  * @tc.name: NapiThrowTypeErrorTest
7115  * @tc.desc: Test interface of napi_throw_type_error
7116  * @tc.type: FUNC
7117  */
HWTEST_F(NapiBasicTest, NapiThrowTypeErrorTest001, testing::ext::TestSize.Level1)7118 HWTEST_F(NapiBasicTest, NapiThrowTypeErrorTest001, testing::ext::TestSize.Level1)
7119 {
7120     ASSERT_NE(engine_, nullptr);
7121     napi_env env = reinterpret_cast<napi_env>(engine_);
7122 
7123     // call napi_throw_type_error interface with nullptr msg
7124     auto res = napi_throw_type_error(env, nullptr, nullptr);
7125     ASSERT_EQ(res, napi_invalid_arg);
7126 }
7127 
7128 /**
7129  * @tc.name: NapiThrowRangeErrorTest
7130  * @tc.desc: Test interface of napi_throw_range_error
7131  * @tc.type: FUNC
7132  */
HWTEST_F(NapiBasicTest, NapiThrowRangeErrorTest001, testing::ext::TestSize.Level1)7133 HWTEST_F(NapiBasicTest, NapiThrowRangeErrorTest001, testing::ext::TestSize.Level1)
7134 {
7135     ASSERT_NE(engine_, nullptr);
7136     napi_env env = reinterpret_cast<napi_env>(engine_);
7137 
7138     // call napi_throw_range_error interface with nullptr msg
7139     auto res = napi_throw_range_error(env, nullptr, nullptr);
7140     ASSERT_EQ(res, napi_invalid_arg);
7141 }
7142 
7143 /**
7144  * @tc.name: NapiIsErrorTest
7145  * @tc.desc: Test interface of napi_is_error
7146  * @tc.type: FUNC
7147  */
HWTEST_F(NapiBasicTest, NapiIsErrorTest001, testing::ext::TestSize.Level1)7148 HWTEST_F(NapiBasicTest, NapiIsErrorTest001, testing::ext::TestSize.Level1)
7149 {
7150     ASSERT_NE(engine_, nullptr);
7151     napi_env env = reinterpret_cast<napi_env>(engine_);
7152 
7153     napi_value code = nullptr;
7154     napi_value message = nullptr;
7155     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &code));
7156     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &message));
7157 
7158     napi_value error = nullptr;
7159     ASSERT_CHECK_CALL(napi_create_error(env, code, message, &error));
7160     ASSERT_TRUE(error != nullptr);
7161 
7162     bool isError = false;
7163     // call napi_is_error interface with correct input
7164     auto res = napi_is_error(env, error, &isError);
7165     ASSERT_EQ(res, napi_ok);
7166 }
7167 
7168 /**
7169  * @tc.name: NapiIsErrorTest
7170  * @tc.desc: Test interface of napi_is_error
7171  * @tc.type: FUNC
7172  */
HWTEST_F(NapiBasicTest, NapiIsErrorTest002, testing::ext::TestSize.Level1)7173 HWTEST_F(NapiBasicTest, NapiIsErrorTest002, testing::ext::TestSize.Level1)
7174 {
7175     ASSERT_NE(engine_, nullptr);
7176     napi_env env = reinterpret_cast<napi_env>(engine_);
7177 
7178     // call napi_is_error interface with nullptr value and nullptr result
7179     auto res = napi_is_error(env, nullptr, nullptr);
7180     ASSERT_EQ(res, napi_invalid_arg);
7181 }
7182 
7183 /**
7184  * @tc.name: NapiIsErrorTest
7185  * @tc.desc: Test interface of napi_is_error
7186  * @tc.type: FUNC
7187  */
HWTEST_F(NapiBasicTest, NapiIsErrorTest003, testing::ext::TestSize.Level1)7188 HWTEST_F(NapiBasicTest, NapiIsErrorTest003, testing::ext::TestSize.Level1)
7189 {
7190     ASSERT_NE(engine_, nullptr);
7191     napi_env env = reinterpret_cast<napi_env>(engine_);
7192 
7193     bool isError = false;
7194     // call napi_is_error interface with nullptr value
7195     auto res = napi_is_error(env, nullptr, &isError);
7196     ASSERT_EQ(res, napi_invalid_arg);
7197 }
7198 
7199 /**
7200  * @tc.name: NapiIsErrorTest
7201  * @tc.desc: Test interface of napi_is_error
7202  * @tc.type: FUNC
7203  */
HWTEST_F(NapiBasicTest, NapiIsErrorTest004, testing::ext::TestSize.Level1)7204 HWTEST_F(NapiBasicTest, NapiIsErrorTest004, testing::ext::TestSize.Level1)
7205 {
7206     ASSERT_NE(engine_, nullptr);
7207     napi_env env = reinterpret_cast<napi_env>(engine_);
7208 
7209     napi_value code = nullptr;
7210     napi_value message = nullptr;
7211     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &code));
7212     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &message));
7213 
7214     napi_value error = nullptr;
7215     ASSERT_CHECK_CALL(napi_create_error(env, code, message, &error));
7216     ASSERT_TRUE(error != nullptr);
7217 
7218     // call napi_is_error interface with nullptr result
7219     auto res = napi_is_error(env, error, nullptr);
7220     ASSERT_EQ(res, napi_invalid_arg);
7221 }
7222 
7223 /**
7224  * @tc.name: NapiCreateErrorTest
7225  * @tc.desc: Test interface of napi_create_error
7226  * @tc.type: FUNC
7227  */
HWTEST_F(NapiBasicTest, NapiCreateErrorTest001, testing::ext::TestSize.Level1)7228 HWTEST_F(NapiBasicTest, NapiCreateErrorTest001, testing::ext::TestSize.Level1)
7229 {
7230     ASSERT_NE(engine_, nullptr);
7231     napi_env env = reinterpret_cast<napi_env>(engine_);
7232 
7233     napi_value code = nullptr;
7234     napi_value message = nullptr;
7235     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &code));
7236     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &message));
7237 
7238     napi_value error = nullptr;
7239     auto res = napi_create_error(env, code, message, &error);
7240     ASSERT_EQ(res, napi_ok);
7241 }
7242 
7243 /**
7244  * @tc.name: NapiCreateErrorTest
7245  * @tc.desc: Test interface of napi_create_error
7246  * @tc.type: FUNC
7247  */
HWTEST_F(NapiBasicTest, NapiCreateErrorTest002, testing::ext::TestSize.Level1)7248 HWTEST_F(NapiBasicTest, NapiCreateErrorTest002, testing::ext::TestSize.Level1)
7249 {
7250     ASSERT_NE(engine_, nullptr);
7251     napi_env env = reinterpret_cast<napi_env>(engine_);
7252 
7253     napi_value message = nullptr;
7254     ASSERT_CHECK_CALL(napi_create_int32(env, TEST_INT32_500, &message));
7255 
7256     napi_value error = nullptr;
7257     auto res = napi_create_error(env, nullptr, message, &error);
7258     ASSERT_EQ(res, napi_invalid_arg);
7259 }
7260 
7261 /**
7262  * @tc.name: NapiCreateErrorTest
7263  * @tc.desc: Test interface of napi_create_error
7264  * @tc.type: FUNC
7265  */
HWTEST_F(NapiBasicTest, NapiCreateErrorTest003, testing::ext::TestSize.Level1)7266 HWTEST_F(NapiBasicTest, NapiCreateErrorTest003, testing::ext::TestSize.Level1)
7267 {
7268     ASSERT_NE(engine_, nullptr);
7269     napi_env env = reinterpret_cast<napi_env>(engine_);
7270 
7271     napi_value code = nullptr;
7272     napi_value message = nullptr;
7273     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &code));
7274     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &message));
7275 
7276     napi_value error = nullptr;
7277     auto res = napi_create_error(env, code, message, &error);
7278     ASSERT_EQ(res, napi_invalid_arg);
7279 }
7280 
7281 /**
7282  * @tc.name: NapiCreateErrorTest
7283  * @tc.desc: Test interface of napi_create_error
7284  * @tc.type: FUNC
7285  */
HWTEST_F(NapiBasicTest, NapiCreateErrorTest004, testing::ext::TestSize.Level1)7286 HWTEST_F(NapiBasicTest, NapiCreateErrorTest004, testing::ext::TestSize.Level1)
7287 {
7288     ASSERT_NE(engine_, nullptr);
7289     napi_env env = reinterpret_cast<napi_env>(engine_);
7290 
7291     auto res = napi_create_error(env, nullptr, nullptr, nullptr);
7292     ASSERT_EQ(res, napi_invalid_arg);
7293 }
7294 
7295 /**
7296  * @tc.name: NapiCreateTypeErrorTest
7297  * @tc.desc: Test interface of napi_create_type_error
7298  * @tc.type: FUNC
7299  */
HWTEST_F(NapiBasicTest, NapiCreateTypeErrorTest001, testing::ext::TestSize.Level1)7300 HWTEST_F(NapiBasicTest, NapiCreateTypeErrorTest001, testing::ext::TestSize.Level1)
7301 {
7302     ASSERT_NE(engine_, nullptr);
7303     napi_env env = reinterpret_cast<napi_env>(engine_);
7304 
7305     napi_value code = nullptr;
7306     napi_value message = nullptr;
7307     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &code));
7308     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &message));
7309 
7310     napi_value error = nullptr;
7311     auto res = napi_create_type_error(env, code, message, &error);
7312     ASSERT_EQ(res, napi_ok);
7313 }
7314 
7315 /**
7316  * @tc.name: NapiCreateTypeErrorTest
7317  * @tc.desc: Test interface of napi_create_type_error
7318  * @tc.type: FUNC
7319  */
HWTEST_F(NapiBasicTest, NapiCreateTypeErrorTest002, testing::ext::TestSize.Level1)7320 HWTEST_F(NapiBasicTest, NapiCreateTypeErrorTest002, testing::ext::TestSize.Level1)
7321 {
7322     ASSERT_NE(engine_, nullptr);
7323     napi_env env = reinterpret_cast<napi_env>(engine_);
7324 
7325     napi_value message = nullptr;
7326     ASSERT_CHECK_CALL(napi_create_int32(env, TEST_INT32_500, &message));
7327 
7328     napi_value error = nullptr;
7329     auto res = napi_create_type_error(env, nullptr, message, &error);
7330     ASSERT_EQ(res, napi_invalid_arg);
7331 }
7332 
7333 /**
7334  * @tc.name: NapiCreateTypeErrorTest
7335  * @tc.desc: Test interface of napi_create_type_error
7336  * @tc.type: FUNC
7337  */
HWTEST_F(NapiBasicTest, NapiCreateTypeErrorTest003, testing::ext::TestSize.Level1)7338 HWTEST_F(NapiBasicTest, NapiCreateTypeErrorTest003, testing::ext::TestSize.Level1)
7339 {
7340     ASSERT_NE(engine_, nullptr);
7341     napi_env env = reinterpret_cast<napi_env>(engine_);
7342 
7343     napi_value code = nullptr;
7344     napi_value message = nullptr;
7345     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &code));
7346     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &message));
7347 
7348     napi_value error = nullptr;
7349     auto res = napi_create_type_error(env, code, message, &error);
7350     ASSERT_EQ(res, napi_invalid_arg);
7351 }
7352 
7353 /**
7354  * @tc.name: NapiCreateTypeErrorTest
7355  * @tc.desc: Test interface of napi_create_type_error
7356  * @tc.type: FUNC
7357  */
HWTEST_F(NapiBasicTest, NapiCreateTypeErrorTest004, testing::ext::TestSize.Level1)7358 HWTEST_F(NapiBasicTest, NapiCreateTypeErrorTest004, testing::ext::TestSize.Level1)
7359 {
7360     ASSERT_NE(engine_, nullptr);
7361     napi_env env = reinterpret_cast<napi_env>(engine_);
7362 
7363     auto res = napi_create_type_error(env, nullptr, nullptr, nullptr);
7364     ASSERT_EQ(res, napi_invalid_arg);
7365 }
7366 
7367 /**
7368  * @tc.name: NapiCreateRangeErrorTest
7369  * @tc.desc: Test interface of napi_create_range_error
7370  * @tc.type: FUNC
7371  */
HWTEST_F(NapiBasicTest, NapiCreateRangeErrorTest001, testing::ext::TestSize.Level1)7372 HWTEST_F(NapiBasicTest, NapiCreateRangeErrorTest001, testing::ext::TestSize.Level1)
7373 {
7374     ASSERT_NE(engine_, nullptr);
7375     napi_env env = reinterpret_cast<napi_env>(engine_);
7376 
7377     napi_value code = nullptr;
7378     napi_value message = nullptr;
7379     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &code));
7380     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &message));
7381 
7382     napi_value error = nullptr;
7383     auto res = napi_create_range_error(env, code, message, &error);
7384     ASSERT_EQ(res, napi_ok);
7385 }
7386 
7387 /**
7388  * @tc.name: NapiCreateRangeErrorTest
7389  * @tc.desc: Test interface of napi_create_range_error
7390  * @tc.type: FUNC
7391  */
HWTEST_F(NapiBasicTest, NapiCreateRangeErrorTest002, testing::ext::TestSize.Level1)7392 HWTEST_F(NapiBasicTest, NapiCreateRangeErrorTest002, testing::ext::TestSize.Level1)
7393 {
7394     ASSERT_NE(engine_, nullptr);
7395     napi_env env = reinterpret_cast<napi_env>(engine_);
7396 
7397     napi_value message = nullptr;
7398     ASSERT_CHECK_CALL(napi_create_int32(env, TEST_INT32_500, &message));
7399 
7400     napi_value error = nullptr;
7401     auto res = napi_create_range_error(env, nullptr, message, &error);
7402     ASSERT_EQ(res, napi_invalid_arg);
7403 }
7404 
7405 /**
7406  * @tc.name: NapiCreateRangeErrorTest
7407  * @tc.desc: Test interface of napi_create_range_error
7408  * @tc.type: FUNC
7409  */
HWTEST_F(NapiBasicTest, NapiCreateRangeErrorTest003, testing::ext::TestSize.Level1)7410 HWTEST_F(NapiBasicTest, NapiCreateRangeErrorTest003, testing::ext::TestSize.Level1)
7411 {
7412     ASSERT_NE(engine_, nullptr);
7413     napi_env env = reinterpret_cast<napi_env>(engine_);
7414 
7415     napi_value code = nullptr;
7416     napi_value message = nullptr;
7417     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &code));
7418     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &message));
7419 
7420     napi_value error = nullptr;
7421     auto res = napi_create_range_error(env, code, message, &error);
7422     ASSERT_EQ(res, napi_invalid_arg);
7423 }
7424 
7425 /**
7426  * @tc.name: NapiCreateRangeErrorTest
7427  * @tc.desc: Test interface of napi_create_range_error
7428  * @tc.type: FUNC
7429  */
HWTEST_F(NapiBasicTest, NapiCreateRangeErrorTest004, testing::ext::TestSize.Level1)7430 HWTEST_F(NapiBasicTest, NapiCreateRangeErrorTest004, testing::ext::TestSize.Level1)
7431 {
7432     ASSERT_NE(engine_, nullptr);
7433     napi_env env = reinterpret_cast<napi_env>(engine_);
7434 
7435     auto res = napi_create_range_error(env, nullptr, nullptr, nullptr);
7436     ASSERT_EQ(res, napi_invalid_arg);
7437 }
7438 
7439 /**
7440  * @tc.name: NapiGetAndClearLastExceptionTest
7441  * @tc.desc: Test interface of napi_get_and_clear_last_exception
7442  * @tc.type: FUNC
7443  */
HWTEST_F(NapiBasicTest, NapiGetAndClearLastExceptionTest001, testing::ext::TestSize.Level1)7444 HWTEST_F(NapiBasicTest, NapiGetAndClearLastExceptionTest001, testing::ext::TestSize.Level1)
7445 {
7446     ASSERT_NE(engine_, nullptr);
7447     napi_env env = reinterpret_cast<napi_env>(engine_);
7448     auto res = napi_get_and_clear_last_exception(env, nullptr);
7449     ASSERT_EQ(res, napi_invalid_arg);
7450 }
7451 
7452 /**
7453  * @tc.name: NapiIsExceptionPendingTest
7454  * @tc.desc: Test interface of napi_is_exception_pending
7455  * @tc.type: FUNC
7456  */
HWTEST_F(NapiBasicTest, NapiIsExceptionPendingTest001, testing::ext::TestSize.Level1)7457 HWTEST_F(NapiBasicTest, NapiIsExceptionPendingTest001, testing::ext::TestSize.Level1)
7458 {
7459     ASSERT_NE(engine_, nullptr);
7460     napi_env env = reinterpret_cast<napi_env>(engine_);
7461 
7462     auto res = napi_is_exception_pending(env, nullptr);
7463     ASSERT_EQ(res, napi_invalid_arg);
7464 }
7465 
7466 /**
7467  * @tc.name: NapiOpenHandleScopeTest
7468  * @tc.desc: Test interface of napi_open_handle_scope
7469  * @tc.type: FUNC
7470  */
HWTEST_F(NapiBasicTest, NapiOpenHandleScopeTest001, testing::ext::TestSize.Level1)7471 HWTEST_F(NapiBasicTest, NapiOpenHandleScopeTest001, testing::ext::TestSize.Level1)
7472 {
7473     ASSERT_NE(engine_, nullptr);
7474     napi_env env = reinterpret_cast<napi_env>(engine_);
7475 
7476     auto res = napi_open_handle_scope(env, nullptr);
7477     ASSERT_EQ(res, napi_invalid_arg);
7478 }
7479 
7480 /**
7481  * @tc.name: NapiCloseHandleScopeTest
7482  * @tc.desc: Test interface of napi_close_handle_scope
7483  * @tc.type: FUNC
7484  */
HWTEST_F(NapiBasicTest, NapiCloseHandleScopeTest001, testing::ext::TestSize.Level1)7485 HWTEST_F(NapiBasicTest, NapiCloseHandleScopeTest001, testing::ext::TestSize.Level1)
7486 {
7487     ASSERT_NE(engine_, nullptr);
7488     napi_env env = reinterpret_cast<napi_env>(engine_);
7489 
7490     auto res = napi_close_handle_scope(env, nullptr);
7491     ASSERT_EQ(res, napi_invalid_arg);
7492 }
7493 
7494 /**
7495  * @tc.name: NapiCloseHandleScopeTest
7496  * @tc.desc: Test interface of napi_close_handle_scope
7497  * @tc.type: FUNC
7498  */
HWTEST_F(NapiBasicTest, NapiCloseHandleScopeTest002, testing::ext::TestSize.Level1)7499 HWTEST_F(NapiBasicTest, NapiCloseHandleScopeTest002, testing::ext::TestSize.Level1)
7500 {
7501     ASSERT_NE(engine_, nullptr);
7502     napi_env env = reinterpret_cast<napi_env>(engine_);
7503 
7504     napi_handle_scope scope = nullptr;
7505     ASSERT_CHECK_CALL(napi_open_handle_scope(env, &scope));
7506     auto res = napi_close_handle_scope(env, scope);
7507     ASSERT_EQ(res, napi_ok);
7508 }
7509 
7510 /**
7511  * @tc.name: NapiCloseHandleScopeTest
7512  * @tc.desc: Test interface of napi_close_handle_scope
7513  * @tc.type: FUNC
7514  */
HWTEST_F(NapiBasicTest, NapiCloseHandleScopeTest003, testing::ext::TestSize.Level1)7515 HWTEST_F(NapiBasicTest, NapiCloseHandleScopeTest003, testing::ext::TestSize.Level1)
7516 {
7517     ASSERT_NE(engine_, nullptr);
7518     napi_env env = reinterpret_cast<napi_env>(engine_);
7519     napi_handle_scope scope = reinterpret_cast<napi_handle_scope>(scope_);
7520 
7521     auto tempScope = engine_->openHandleScopes_;
7522     engine_->openHandleScopes_ = 0;
7523     auto res = napi_close_handle_scope(env, scope);
7524     engine_->openHandleScopes_ = tempScope;
7525     ASSERT_EQ(res, napi_handle_scope_mismatch);
7526 }
7527 
7528 /**
7529  * @tc.name: NapiOpenEscapableHandleScopeTest
7530  * @tc.desc: Test interface of napi_open_escapable_handle_scope
7531  * @tc.type: FUNC
7532  */
HWTEST_F(NapiBasicTest, NapiOpenEscapableHandleScopeTest001, testing::ext::TestSize.Level1)7533 HWTEST_F(NapiBasicTest, NapiOpenEscapableHandleScopeTest001, testing::ext::TestSize.Level1)
7534 {
7535     ASSERT_NE(engine_, nullptr);
7536     napi_env env = reinterpret_cast<napi_env>(engine_);
7537 
7538     auto res = napi_open_escapable_handle_scope(env, nullptr);
7539     ASSERT_EQ(res, napi_invalid_arg);
7540 }
7541 
7542 /**
7543  * @tc.name: NapiCloseEscapableHandleScopeTest
7544  * @tc.desc: Test interface of napi_close_escapable_handle_scope
7545  * @tc.type: FUNC
7546  */
HWTEST_F(NapiBasicTest, NapiCloseEscapableHandleScopeTest001, testing::ext::TestSize.Level1)7547 HWTEST_F(NapiBasicTest, NapiCloseEscapableHandleScopeTest001, testing::ext::TestSize.Level1)
7548 {
7549     ASSERT_NE(engine_, nullptr);
7550     napi_env env = reinterpret_cast<napi_env>(engine_);
7551 
7552     auto res = napi_close_escapable_handle_scope(env, nullptr);
7553     ASSERT_EQ(res, napi_invalid_arg);
7554 }
7555 
7556 /**
7557  * @tc.name: NapiCloseEscapableHandleScopeTest
7558  * @tc.desc: Test interface of napi_close_escapable_handle_scope
7559  * @tc.type: FUNC
7560  */
HWTEST_F(NapiBasicTest, NapiCloseEscapableHandleScopeTest002, testing::ext::TestSize.Level1)7561 HWTEST_F(NapiBasicTest, NapiCloseEscapableHandleScopeTest002, testing::ext::TestSize.Level1)
7562 {
7563     ASSERT_NE(engine_, nullptr);
7564     napi_env env = reinterpret_cast<napi_env>(engine_);
7565 
7566     napi_escapable_handle_scope scope = nullptr;
7567     ASSERT_CHECK_CALL(napi_open_escapable_handle_scope(env, &scope));
7568 
7569     auto res = napi_close_escapable_handle_scope(env, scope);
7570     ASSERT_EQ(res, napi_ok);
7571 }
7572 
7573 /**
7574  * @tc.name: NapiCloseEscapableHandleScopeTest
7575  * @tc.desc: Test interface of napi_close_escapable_handle_scope
7576  * @tc.type: FUNC
7577  */
HWTEST_F(NapiBasicTest, NapiCloseEscapableHandleScopeTest003, testing::ext::TestSize.Level1)7578 HWTEST_F(NapiBasicTest, NapiCloseEscapableHandleScopeTest003, testing::ext::TestSize.Level1)
7579 {
7580     ASSERT_NE(engine_, nullptr);
7581     napi_env env = reinterpret_cast<napi_env>(engine_);
7582     napi_handle_scope scope = reinterpret_cast<napi_handle_scope>(scope_);
7583 
7584     auto tempScope = engine_->openHandleScopes_;
7585     engine_->openHandleScopes_ = 0;
7586     auto res = napi_close_escapable_handle_scope(env, (napi_escapable_handle_scope)scope);
7587     engine_->openHandleScopes_ = tempScope;
7588     ASSERT_EQ(res, napi_handle_scope_mismatch);
7589 }
7590 
7591 /**
7592  * @tc.name: NapiEscapeHandleTest
7593  * @tc.desc: Test interface of napi_escape_handle
7594  * @tc.type: FUNC
7595  */
HWTEST_F(NapiBasicTest, NapiEscapeHandleTest001, testing::ext::TestSize.Level1)7596 HWTEST_F(NapiBasicTest, NapiEscapeHandleTest001, testing::ext::TestSize.Level1)
7597 {
7598     ASSERT_NE(engine_, nullptr);
7599     napi_env env = reinterpret_cast<napi_env>(engine_);
7600 
7601     napi_escapable_handle_scope escapableScope = nullptr;
7602     ASSERT_CHECK_CALL(napi_open_escapable_handle_scope(env, &escapableScope));
7603     napi_value boolean, booleanNew = nullptr;
7604     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
7605 
7606     auto res = napi_escape_handle(env, escapableScope, boolean, &booleanNew);
7607     ASSERT_EQ(res, napi_ok);
7608 
7609     ASSERT_CHECK_CALL(napi_close_escapable_handle_scope(env, escapableScope));
7610 }
7611 
7612 /**
7613  * @tc.name: NapiEscapeHandleTest
7614  * @tc.desc: Test interface of napi_escape_handle
7615  * @tc.type: FUNC
7616  */
HWTEST_F(NapiBasicTest, NapiEscapeHandleTest002, testing::ext::TestSize.Level1)7617 HWTEST_F(NapiBasicTest, NapiEscapeHandleTest002, testing::ext::TestSize.Level1)
7618 {
7619     ASSERT_NE(engine_, nullptr);
7620     napi_env env = reinterpret_cast<napi_env>(engine_);
7621 
7622     napi_escapable_handle_scope escapableScope = nullptr;
7623     ASSERT_CHECK_CALL(napi_open_escapable_handle_scope(env, &escapableScope));
7624     napi_value boolean, booleanNew = nullptr;
7625     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
7626     ASSERT_CHECK_CALL(napi_escape_handle(env, escapableScope, boolean, &booleanNew));
7627 
7628     auto res = napi_escape_handle(env, escapableScope, boolean, &booleanNew);
7629     ASSERT_EQ(res, napi_escape_called_twice);
7630 
7631     ASSERT_CHECK_CALL(napi_close_escapable_handle_scope(env, escapableScope));
7632 }
7633 
7634 /**
7635  * @tc.name: NapiEscapeHandleTest
7636  * @tc.desc: Test interface of napi_escape_handle
7637  * @tc.type: FUNC
7638  */
HWTEST_F(NapiBasicTest, NapiEscapeHandleTest003, testing::ext::TestSize.Level1)7639 HWTEST_F(NapiBasicTest, NapiEscapeHandleTest003, testing::ext::TestSize.Level1)
7640 {
7641     ASSERT_NE(engine_, nullptr);
7642     napi_env env = reinterpret_cast<napi_env>(engine_);
7643 
7644     napi_escapable_handle_scope escapableScope = nullptr;
7645     ASSERT_CHECK_CALL(napi_open_escapable_handle_scope(env, &escapableScope));
7646     napi_value boolean = nullptr;
7647     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
7648 
7649     auto res = napi_escape_handle(env, escapableScope, boolean, nullptr);
7650     ASSERT_EQ(res, napi_invalid_arg);
7651 
7652     ASSERT_CHECK_CALL(napi_close_escapable_handle_scope(env, escapableScope));
7653 }
7654 
7655 /**
7656  * @tc.name: NapiEscapeHandleTest
7657  * @tc.desc: Test interface of napi_escape_handle
7658  * @tc.type: FUNC
7659  */
HWTEST_F(NapiBasicTest, NapiEscapeHandleTest004, testing::ext::TestSize.Level1)7660 HWTEST_F(NapiBasicTest, NapiEscapeHandleTest004, testing::ext::TestSize.Level1)
7661 {
7662     ASSERT_NE(engine_, nullptr);
7663     napi_env env = reinterpret_cast<napi_env>(engine_);
7664 
7665     napi_escapable_handle_scope escapableScope = nullptr;
7666     ASSERT_CHECK_CALL(napi_open_escapable_handle_scope(env, &escapableScope));
7667 
7668     auto res = napi_escape_handle(env, escapableScope, nullptr, nullptr);
7669     ASSERT_EQ(res, napi_invalid_arg);
7670 
7671     ASSERT_CHECK_CALL(napi_close_escapable_handle_scope(env, escapableScope));
7672 }
7673 
7674 /**
7675  * @tc.name: NapiEscapeHandleTest
7676  * @tc.desc: Test interface of napi_escape_handle
7677  * @tc.type: FUNC
7678  */
HWTEST_F(NapiBasicTest, NapiEscapeHandleTest005, testing::ext::TestSize.Level1)7679 HWTEST_F(NapiBasicTest, NapiEscapeHandleTest005, testing::ext::TestSize.Level1)
7680 {
7681     ASSERT_NE(engine_, nullptr);
7682     napi_env env = reinterpret_cast<napi_env>(engine_);
7683 
7684     auto res = napi_escape_handle(env, nullptr, nullptr, nullptr);
7685     ASSERT_EQ(res, napi_invalid_arg);
7686 }
7687 
7688 /**
7689  * @tc.name: NapiCreateReferenceTest
7690  * @tc.desc: Test interface of napi_create_reference
7691  * @tc.type: FUNC
7692  */
HWTEST_F(NapiBasicTest, NapiCreateReferenceTest001, testing::ext::TestSize.Level1)7693 HWTEST_F(NapiBasicTest, NapiCreateReferenceTest001, testing::ext::TestSize.Level1)
7694 {
7695     ASSERT_NE(engine_, nullptr);
7696     napi_env env = reinterpret_cast<napi_env>(engine_);
7697 
7698     napi_value boolean = nullptr;
7699     napi_ref booleanRef = nullptr;
7700     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
7701 
7702     auto res = napi_create_reference(env, boolean, 1, &booleanRef);
7703     ASSERT_EQ(res, napi_ok);
7704     ASSERT_CHECK_CALL(napi_delete_reference(env, booleanRef));
7705 }
7706 
7707 /**
7708  * @tc.name: NapiCreateReferenceTest
7709  * @tc.desc: Test interface of napi_create_reference
7710  * @tc.type: FUNC
7711  */
HWTEST_F(NapiBasicTest, NapiCreateReferenceTest002, testing::ext::TestSize.Level1)7712 HWTEST_F(NapiBasicTest, NapiCreateReferenceTest002, testing::ext::TestSize.Level1)
7713 {
7714     ASSERT_NE(engine_, nullptr);
7715     napi_env env = reinterpret_cast<napi_env>(engine_);
7716 
7717     napi_value boolean = nullptr;
7718     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
7719 
7720     auto res = napi_create_reference(env, boolean, 1, nullptr);
7721     ASSERT_EQ(res, napi_invalid_arg);
7722 }
7723 
7724 /**
7725  * @tc.name: NapiCreateReferenceTest
7726  * @tc.desc: Test interface of napi_create_reference
7727  * @tc.type: FUNC
7728  */
HWTEST_F(NapiBasicTest, NapiCreateReferenceTest003, testing::ext::TestSize.Level1)7729 HWTEST_F(NapiBasicTest, NapiCreateReferenceTest003, testing::ext::TestSize.Level1)
7730 {
7731     ASSERT_NE(engine_, nullptr);
7732     napi_env env = reinterpret_cast<napi_env>(engine_);
7733 
7734     auto res = napi_create_reference(env, nullptr, 1, nullptr);
7735     ASSERT_EQ(res, napi_invalid_arg);
7736 }
7737 
7738 /**
7739  * @tc.name: NapiDeleteReferenceTest
7740  * @tc.desc: Test interface of napi_delete_reference
7741  * @tc.type: FUNC
7742  */
HWTEST_F(NapiBasicTest, NapiDeleteReferenceTest001, testing::ext::TestSize.Level1)7743 HWTEST_F(NapiBasicTest, NapiDeleteReferenceTest001, testing::ext::TestSize.Level1)
7744 {
7745     ASSERT_NE(engine_, nullptr);
7746     napi_env env = reinterpret_cast<napi_env>(engine_);
7747 
7748     auto res = napi_delete_reference(env, nullptr);
7749     ASSERT_EQ(res, napi_invalid_arg);
7750 }
7751 
7752 /**
7753  * @tc.name: NapiDeleteReferenceTest
7754  * @tc.desc: Test interface of napi_delete_reference
7755  * @tc.type: FUNC
7756  */
HWTEST_F(NapiBasicTest, NapiDeleteReferenceTest002, testing::ext::TestSize.Level1)7757 HWTEST_F(NapiBasicTest, NapiDeleteReferenceTest002, testing::ext::TestSize.Level1)
7758 {
7759     ASSERT_NE(engine_, nullptr);
7760     napi_env env = reinterpret_cast<napi_env>(engine_);
7761 
7762     napi_value boolean = nullptr;
7763     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
7764 
7765     napi_ref booleanRef = nullptr;
7766     ASSERT_CHECK_CALL(napi_create_reference(env, boolean, 1, &booleanRef));
7767     auto res = napi_delete_reference(env, booleanRef);
7768     ASSERT_EQ(res, napi_ok);
7769 }
7770 
7771 /**
7772  * @tc.name: NapiReferenceRefTest
7773  * @tc.desc: Test interface of napi_reference_ref
7774  * @tc.type: FUNC
7775  */
HWTEST_F(NapiBasicTest, NapiReferenceRefTest001, testing::ext::TestSize.Level1)7776 HWTEST_F(NapiBasicTest, NapiReferenceRefTest001, testing::ext::TestSize.Level1)
7777 {
7778     ASSERT_NE(engine_, nullptr);
7779     napi_env env = reinterpret_cast<napi_env>(engine_);
7780 
7781     auto res = napi_reference_ref(env, nullptr, nullptr);
7782     ASSERT_EQ(res, napi_invalid_arg);
7783 }
7784 
7785 /**
7786  * @tc.name: NapiReferenceUnrefTest
7787  * @tc.desc: Test interface of napi_reference_unref
7788  * @tc.type: FUNC
7789  */
HWTEST_F(NapiBasicTest, NapiReferenceUnrefTest001, testing::ext::TestSize.Level1)7790 HWTEST_F(NapiBasicTest, NapiReferenceUnrefTest001, testing::ext::TestSize.Level1)
7791 {
7792     ASSERT_NE(engine_, nullptr);
7793     napi_env env = reinterpret_cast<napi_env>(engine_);
7794 
7795     auto res = napi_reference_unref(env, nullptr, nullptr);
7796     ASSERT_EQ(res, napi_invalid_arg);
7797 }
7798 
7799 /**
7800  * @tc.name: NapiGetReferenceValueTest
7801  * @tc.desc: Test interface of napi_get_reference_value
7802  * @tc.type: FUNC
7803  */
HWTEST_F(NapiBasicTest, NapiGetReferenceValueTest001, testing::ext::TestSize.Level1)7804 HWTEST_F(NapiBasicTest, NapiGetReferenceValueTest001, testing::ext::TestSize.Level1)
7805 {
7806     ASSERT_NE(engine_, nullptr);
7807     napi_env env = reinterpret_cast<napi_env>(engine_);
7808 
7809     auto res = napi_get_reference_value(env, nullptr, nullptr);
7810     ASSERT_EQ(res, napi_invalid_arg);
7811 }
7812 
7813 /**
7814  * @tc.name: NapiGetReferenceValueTest
7815  * @tc.desc: Test interface of napi_get_reference_value
7816  * @tc.type: FUNC
7817  */
HWTEST_F(NapiBasicTest, NapiGetReferenceValueTest002, testing::ext::TestSize.Level1)7818 HWTEST_F(NapiBasicTest, NapiGetReferenceValueTest002, testing::ext::TestSize.Level1)
7819 {
7820     ASSERT_NE(engine_, nullptr);
7821     napi_env env = reinterpret_cast<napi_env>(engine_);
7822 
7823     napi_value boolean = nullptr;
7824     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
7825 
7826     napi_ref booleanRef = nullptr;
7827     ASSERT_CHECK_CALL(napi_create_reference(env, boolean, 1, &booleanRef));
7828 
7829     auto res = napi_get_reference_value(env, booleanRef, nullptr);
7830     ASSERT_EQ(res, napi_invalid_arg);
7831 }
7832 
7833 /**
7834  * @tc.name: NapiGetReferenceValueTest
7835  * @tc.desc: Test interface of napi_get_reference_value
7836  * @tc.type: FUNC
7837  */
HWTEST_F(NapiBasicTest, NapiGetReferenceValueTest003, testing::ext::TestSize.Level1)7838 HWTEST_F(NapiBasicTest, NapiGetReferenceValueTest003, testing::ext::TestSize.Level1)
7839 {
7840     ASSERT_NE(engine_, nullptr);
7841     napi_env env = reinterpret_cast<napi_env>(engine_);
7842 
7843     napi_value boolean = nullptr;
7844     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
7845 
7846     napi_ref booleanRef = nullptr;
7847     ASSERT_CHECK_CALL(napi_create_reference(env, boolean, 1, &booleanRef));
7848 
7849     napi_value refValue = nullptr;
7850     auto res = napi_get_reference_value(env, booleanRef, &refValue);
7851     ASSERT_EQ(res, napi_ok);
7852     ASSERT_NE(refValue, nullptr);
7853 }
7854 
7855 /**
7856  * @tc.name: NapiCreateArrayTest
7857  * @tc.desc: Test interface of napi_create_array
7858  * @tc.type: FUNC
7859  */
HWTEST_F(NapiBasicTest, NapiCreateArrayTest001, testing::ext::TestSize.Level1)7860 HWTEST_F(NapiBasicTest, NapiCreateArrayTest001, testing::ext::TestSize.Level1)
7861 {
7862     ASSERT_NE(engine_, nullptr);
7863     napi_env env = reinterpret_cast<napi_env>(engine_);
7864     napi_value array = nullptr;
7865     auto res = napi_create_array(env, &array);
7866     ASSERT_EQ(res, napi_ok);
7867 }
7868 
7869 /**
7870  * @tc.name: NapiCreateArrayTest
7871  * @tc.desc: Test interface of napi_create_array
7872  * @tc.type: FUNC
7873  */
HWTEST_F(NapiBasicTest, NapiCreateArrayTest002, testing::ext::TestSize.Level1)7874 HWTEST_F(NapiBasicTest, NapiCreateArrayTest002, testing::ext::TestSize.Level1)
7875 {
7876     ASSERT_NE(engine_, nullptr);
7877     napi_env env = reinterpret_cast<napi_env>(engine_);
7878 
7879     auto res = napi_create_array(env, nullptr);
7880     ASSERT_EQ(res, napi_invalid_arg);
7881 }
7882 
7883 /**
7884  * @tc.name: NapiCreateArrayWithLengthTest
7885  * @tc.desc: Test interface of napi_create_array_with_length
7886  * @tc.type: FUNC
7887  */
HWTEST_F(NapiBasicTest, NapiCreateArrayWithLengthTest001, testing::ext::TestSize.Level1)7888 HWTEST_F(NapiBasicTest, NapiCreateArrayWithLengthTest001, testing::ext::TestSize.Level1)
7889 {
7890     ASSERT_NE(engine_, nullptr);
7891     napi_env env = reinterpret_cast<napi_env>(engine_);
7892 
7893     napi_value array = nullptr;
7894     auto res = napi_create_array_with_length(env, 0, &array);
7895     ASSERT_EQ(res, napi_ok);
7896 }
7897 
7898 /**
7899  * @tc.name: NapiCreateArrayWithLengthTest
7900  * @tc.desc: Test interface of napi_create_array_with_length
7901  * @tc.type: FUNC
7902  */
HWTEST_F(NapiBasicTest, NapiCreateArrayWithLengthTest002, testing::ext::TestSize.Level1)7903 HWTEST_F(NapiBasicTest, NapiCreateArrayWithLengthTest002, testing::ext::TestSize.Level1)
7904 {
7905     ASSERT_NE(engine_, nullptr);
7906     napi_env env = reinterpret_cast<napi_env>(engine_);
7907 
7908     auto res = napi_create_array_with_length(env, 0, nullptr);
7909     ASSERT_EQ(res, napi_invalid_arg);
7910 }
7911 
7912 /**
7913  * @tc.name: NapiCreateArraybufferTest
7914  * @tc.desc: Test interface of napi_create_arraybuffer
7915  * @tc.type: FUNC
7916  */
HWTEST_F(NapiBasicTest, NapiCreateArraybufferTest001, testing::ext::TestSize.Level1)7917 HWTEST_F(NapiBasicTest, NapiCreateArraybufferTest001, testing::ext::TestSize.Level1)
7918 {
7919     ASSERT_NE(engine_, nullptr);
7920     napi_env env = reinterpret_cast<napi_env>(engine_);
7921 
7922     napi_value arrayBuffer = nullptr;
7923     void* arrayBufferPtr = nullptr;
7924     size_t arrayBufferSize = 0;
7925     auto res = napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer);
7926     ASSERT_EQ(res, napi_ok);
7927 }
7928 
7929 /**
7930  * @tc.name: NapiCreateArraybufferTest
7931  * @tc.desc: Test interface of napi_create_arraybuffer
7932  * @tc.type: FUNC
7933  */
HWTEST_F(NapiBasicTest, NapiCreateArraybufferTest002, testing::ext::TestSize.Level1)7934 HWTEST_F(NapiBasicTest, NapiCreateArraybufferTest002, testing::ext::TestSize.Level1)
7935 {
7936     ASSERT_NE(engine_, nullptr);
7937     napi_env env = reinterpret_cast<napi_env>(engine_);
7938 
7939     size_t arrayBufferSize = 0;
7940     auto res = napi_create_arraybuffer(env, arrayBufferSize, nullptr, nullptr);
7941     ASSERT_EQ(res, napi_invalid_arg);
7942 }
7943 
7944 /**
7945  * @tc.name: NapiCreateArraybufferTest
7946  * @tc.desc: Test interface of napi_create_arraybuffer
7947  * @tc.type: FUNC
7948  */
HWTEST_F(NapiBasicTest, NapiCreateArraybufferTest003, testing::ext::TestSize.Level1)7949 HWTEST_F(NapiBasicTest, NapiCreateArraybufferTest003, testing::ext::TestSize.Level1)
7950 {
7951     ASSERT_NE(engine_, nullptr);
7952     napi_env env = reinterpret_cast<napi_env>(engine_);
7953 
7954     void* arrayBufferPtr = nullptr;
7955     size_t arrayBufferSize = 0;
7956     auto res = napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, nullptr);
7957     ASSERT_EQ(res, napi_invalid_arg);
7958 }
7959 
7960 /**
7961  * @tc.name: NapiCreateExternalTest
7962  * @tc.desc: Test interface of napi_create_external
7963  * @tc.type: FUNC
7964  */
HWTEST_F(NapiBasicTest, NapiCreateExternalTest001, testing::ext::TestSize.Level1)7965 HWTEST_F(NapiBasicTest, NapiCreateExternalTest001, testing::ext::TestSize.Level1)
7966 {
7967     ASSERT_NE(engine_, nullptr);
7968     napi_env env = reinterpret_cast<napi_env>(engine_);
7969 
7970     auto res = napi_create_external(
7971         env, (void*)TEST_CHAR_STRING,
7972         [](napi_env env, void* data, void* hint) { ASSERT_STREQ((const char*)data, (const char*)hint); },
7973         (void*)TEST_CHAR_STRING, nullptr);
7974     ASSERT_EQ(res, napi_invalid_arg);
7975 }
7976 
7977 /**
7978  * @tc.name: NapiCreateExternalTest
7979  * @tc.desc: Test interface of napi_create_external
7980  * @tc.type: FUNC
7981  */
HWTEST_F(NapiBasicTest, NapiCreateExternalTest002, testing::ext::TestSize.Level1)7982 HWTEST_F(NapiBasicTest, NapiCreateExternalTest002, testing::ext::TestSize.Level1)
7983 {
7984     ASSERT_NE(engine_, nullptr);
7985     napi_env env = reinterpret_cast<napi_env>(engine_);
7986 
7987     napi_value external = nullptr;
7988     auto res = napi_create_external(
7989         env, (void*)TEST_CHAR_STRING,
7990         [](napi_env env, void* data, void* hint) { ASSERT_STREQ((const char*)data, (const char*)hint); },
7991         (void*)TEST_CHAR_STRING, &external);
7992     ASSERT_EQ(res, napi_ok);
7993 }
7994 
7995 /**
7996  * @tc.name: NapiCreateExternalArraybufferTest
7997  * @tc.desc: Test interface of napi_create_external_arraybuffer
7998  * @tc.type: FUNC
7999  */
HWTEST_F(NapiBasicTest, NapiCreateExternalArraybufferTest001, testing::ext::TestSize.Level1)8000 HWTEST_F(NapiBasicTest, NapiCreateExternalArraybufferTest001, testing::ext::TestSize.Level1)
8001 {
8002     ASSERT_NE(engine_, nullptr);
8003     napi_env env = reinterpret_cast<napi_env>(engine_);
8004 
8005     auto res = napi_create_external_arraybuffer(
8006         env, nullptr, strlen(TEST_CHAR_STRING),
8007         nullptr,
8008         (void*)TEST_CHAR_STRING, nullptr);
8009     ASSERT_EQ(res, napi_invalid_arg);
8010 }
8011 
8012 /**
8013  * @tc.name: NapiCreateExternalArraybufferTest
8014  * @tc.desc: Test interface of napi_create_external_arraybuffer
8015  * @tc.type: FUNC
8016  */
HWTEST_F(NapiBasicTest, NapiCreateExternalArraybufferTest002, testing::ext::TestSize.Level1)8017 HWTEST_F(NapiBasicTest, NapiCreateExternalArraybufferTest002, testing::ext::TestSize.Level1)
8018 {
8019     ASSERT_NE(engine_, nullptr);
8020     napi_env env = reinterpret_cast<napi_env>(engine_);
8021 
8022     auto res = napi_create_external_arraybuffer(
8023         env, (void*)TEST_CHAR_STRING, strlen(TEST_CHAR_STRING),
8024         nullptr,
8025         (void*)TEST_CHAR_STRING, nullptr);
8026     ASSERT_EQ(res, napi_invalid_arg);
8027 }
8028 
8029 /**
8030  * @tc.name: NapiCreateExternalArraybufferTest
8031  * @tc.desc: Test interface of napi_create_external_arraybuffer
8032  * @tc.type: FUNC
8033  */
HWTEST_F(NapiBasicTest, NapiCreateExternalArraybufferTest003, testing::ext::TestSize.Level1)8034 HWTEST_F(NapiBasicTest, NapiCreateExternalArraybufferTest003, testing::ext::TestSize.Level1)
8035 {
8036     ASSERT_NE(engine_, nullptr);
8037     napi_env env = reinterpret_cast<napi_env>(engine_);
8038 
8039     auto res = napi_create_external_arraybuffer(
8040         env, (void*)TEST_CHAR_STRING, strlen(TEST_CHAR_STRING),
8041         [](napi_env env, void* data, void* hint) { ASSERT_STREQ((const char*)data, (const char*)hint); },
8042         (void*)TEST_CHAR_STRING, nullptr);
8043     ASSERT_EQ(res, napi_invalid_arg);
8044 }
8045 
8046 /**
8047  * @tc.name: NapiCreateExternalArraybufferTest
8048  * @tc.desc: Test interface of napi_create_external_arraybuffer
8049  * @tc.type: FUNC
8050  */
HWTEST_F(NapiBasicTest, NapiCreateExternalArraybufferTest004, testing::ext::TestSize.Level1)8051 HWTEST_F(NapiBasicTest, NapiCreateExternalArraybufferTest004, testing::ext::TestSize.Level1)
8052 {
8053     ASSERT_NE(engine_, nullptr);
8054     napi_env env = reinterpret_cast<napi_env>(engine_);
8055 
8056     napi_value external = nullptr;
8057     auto res = napi_create_external_arraybuffer(
8058         env, (void*)TEST_CHAR_STRING, strlen(TEST_CHAR_STRING),
8059         [](napi_env env, void* data, void* hint) { ASSERT_STREQ((const char*)data, (const char*)hint); },
8060         (void*)TEST_CHAR_STRING, &external);
8061     ASSERT_EQ(res, napi_ok);
8062 }
8063 
8064 /**
8065  * @tc.name: NapiCreateObjectTest
8066  * @tc.desc: Test interface of napi_create_object
8067  * @tc.type: FUNC
8068  */
HWTEST_F(NapiBasicTest, NapiCreateObjectTest001, testing::ext::TestSize.Level1)8069 HWTEST_F(NapiBasicTest, NapiCreateObjectTest001, testing::ext::TestSize.Level1)
8070 {
8071     ASSERT_NE(engine_, nullptr);
8072     napi_env env = reinterpret_cast<napi_env>(engine_);
8073 
8074     auto res = napi_create_object(env, nullptr);
8075     ASSERT_EQ(res, napi_invalid_arg);
8076 
8077     napi_value result = nullptr;
8078     ASSERT_CHECK_CALL(napi_create_object(env, &result));
8079 }
8080 
8081 /**
8082  * @tc.name: NapiCreateSymbolTest
8083  * @tc.desc: Test interface of napi_create_symbol
8084  * @tc.type: FUNC
8085  */
HWTEST_F(NapiBasicTest, NapiCreateSymbolTest001, testing::ext::TestSize.Level1)8086 HWTEST_F(NapiBasicTest, NapiCreateSymbolTest001, testing::ext::TestSize.Level1)
8087 {
8088     ASSERT_NE(engine_, nullptr);
8089     napi_env env = reinterpret_cast<napi_env>(engine_);
8090 
8091     auto res = napi_create_symbol(env, nullptr, nullptr);
8092     ASSERT_EQ(res, napi_invalid_arg);
8093 }
8094 
8095 /**
8096  * @tc.name: NapiCreateSymbolTest
8097  * @tc.desc: Test interface of napi_create_symbol
8098  * @tc.type: FUNC
8099  */
HWTEST_F(NapiBasicTest, NapiCreateSymbolTest002, testing::ext::TestSize.Level1)8100 HWTEST_F(NapiBasicTest, NapiCreateSymbolTest002, testing::ext::TestSize.Level1)
8101 {
8102     ASSERT_NE(engine_, nullptr);
8103     napi_env env = reinterpret_cast<napi_env>(engine_);
8104 
8105     napi_value boolean = nullptr;
8106     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8107 
8108     napi_value result = nullptr;
8109     auto res = napi_create_symbol(env, boolean, &result);
8110     ASSERT_EQ(res, napi_invalid_arg);
8111 }
8112 
8113 /**
8114  * @tc.name: NapiCreateTypedarrayTest
8115  * @tc.desc: Test interface of napi_create_typedarray
8116  * @tc.type: FUNC
8117  */
HWTEST_F(NapiBasicTest, NapiCreateTypedarrayTest001, testing::ext::TestSize.Level1)8118 HWTEST_F(NapiBasicTest, NapiCreateTypedarrayTest001, testing::ext::TestSize.Level1)
8119 {
8120     ASSERT_NE(engine_, nullptr);
8121     napi_env env = reinterpret_cast<napi_env>(engine_);
8122 
8123     auto res = napi_create_typedarray(env, napi_int8_array, 0, nullptr, 0, nullptr);
8124     ASSERT_EQ(res, napi_invalid_arg);
8125 
8126     napi_value arraybuffer = nullptr;
8127     res = napi_create_typedarray(env, napi_int8_array, 0, arraybuffer, 0, nullptr);
8128     ASSERT_EQ(res, napi_invalid_arg);
8129 }
8130 
8131 /**
8132  * @tc.name: NapiCreateTypedarrayTest
8133  * @tc.desc: Test interface of napi_create_typedarray
8134  * @tc.type: FUNC
8135  */
HWTEST_F(NapiBasicTest, NapiCreateTypedarrayTest002, testing::ext::TestSize.Level1)8136 HWTEST_F(NapiBasicTest, NapiCreateTypedarrayTest002, testing::ext::TestSize.Level1)
8137 {
8138     ASSERT_NE(engine_, nullptr);
8139     napi_env env = reinterpret_cast<napi_env>(engine_);
8140 
8141     napi_value boolean = nullptr;
8142     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8143     napi_value typedarray = nullptr;
8144     auto res = napi_create_typedarray(env, napi_int8_array, 0, boolean, 0, &typedarray);
8145     ASSERT_EQ(res, napi_arraybuffer_expected);
8146 }
8147 
8148 /**
8149  * @tc.name: NapiCreateTypedarrayTest
8150  * @tc.desc: Test interface of napi_create_typedarray
8151  * @tc.type: FUNC
8152  */
HWTEST_F(NapiBasicTest, NapiCreateTypedarrayTest003, testing::ext::TestSize.Level1)8153 HWTEST_F(NapiBasicTest, NapiCreateTypedarrayTest003, testing::ext::TestSize.Level1)
8154 {
8155     ASSERT_NE(engine_, nullptr);
8156     napi_env env = reinterpret_cast<napi_env>(engine_);
8157 
8158     napi_value arrayBuffer = nullptr;
8159     void* arrayBufferPtr = nullptr;
8160     size_t arrayBufferSize = 1024;
8161     ASSERT_CHECK_CALL(napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer));
8162 
8163     napi_value typedarray = nullptr;
8164     auto res = napi_create_typedarray(env, (napi_typedarray_type)(napi_int8_array - 1), arrayBufferSize,
8165         arrayBuffer, 0, &typedarray);
8166     ASSERT_EQ(res, napi_invalid_arg);
8167 }
8168 
8169 /**
8170  * @tc.name: NapiCreateDataviewTest
8171  * @tc.desc: Test interface of napi_create_dataview
8172  * @tc.type: FUNC
8173  */
HWTEST_F(NapiBasicTest, NapiCreateDataviewTest001, testing::ext::TestSize.Level1)8174 HWTEST_F(NapiBasicTest, NapiCreateDataviewTest001, testing::ext::TestSize.Level1)
8175 {
8176     ASSERT_NE(engine_, nullptr);
8177     napi_env env = reinterpret_cast<napi_env>(engine_);
8178 
8179     auto res = napi_create_dataview(env, 0, nullptr, 0, nullptr);
8180     ASSERT_EQ(res, napi_invalid_arg);
8181 
8182     napi_value arraybuffer = nullptr;
8183     res = napi_create_dataview(env, 0, arraybuffer, 0, nullptr);
8184     ASSERT_EQ(res, napi_invalid_arg);
8185 }
8186 
8187 /**
8188  * @tc.name: NapiCreateDataviewTest
8189  * @tc.desc: Test interface of napi_create_dataview
8190  * @tc.type: FUNC
8191  */
HWTEST_F(NapiBasicTest, NapiCreateDataviewTest002, testing::ext::TestSize.Level1)8192 HWTEST_F(NapiBasicTest, NapiCreateDataviewTest002, testing::ext::TestSize.Level1)
8193 {
8194     ASSERT_NE(engine_, nullptr);
8195     napi_env env = reinterpret_cast<napi_env>(engine_);
8196 
8197     napi_value boolean = nullptr;
8198     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8199     napi_value result = nullptr;
8200     auto res = napi_create_dataview(env, 0, boolean, 0, &result);
8201     ASSERT_EQ(res, napi_arraybuffer_expected);
8202 }
8203 
8204 /**
8205  * @tc.name: NapiCreateDataviewTest
8206  * @tc.desc: Test interface of napi_create_dataview
8207  * @tc.type: FUNC
8208  */
HWTEST_F(NapiBasicTest, NapiCreateDataviewTest003, testing::ext::TestSize.Level1)8209 HWTEST_F(NapiBasicTest, NapiCreateDataviewTest003, testing::ext::TestSize.Level1)
8210 {
8211     ASSERT_NE(engine_, nullptr);
8212     napi_env env = reinterpret_cast<napi_env>(engine_);
8213 
8214     napi_value arrayBuffer = nullptr;
8215     void* arrayBufferPtr = nullptr;
8216     size_t arrayBufferSize = 1024;
8217     napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer);
8218     ASSERT_NE(arrayBuffer, nullptr);
8219     ASSERT_NE(arrayBufferPtr, nullptr);
8220     bool isArrayBuffer = false;
8221     napi_is_arraybuffer(env, arrayBuffer, &isArrayBuffer);
8222     ASSERT_TRUE(isArrayBuffer);
8223 
8224     napi_value result = nullptr;
8225     auto res = napi_create_dataview(env, arrayBufferSize, arrayBuffer, arrayBufferSize + 1, &result);
8226     ASSERT_EQ(res, napi_pending_exception);
8227 }
8228 
8229 /**
8230  * @tc.name: NapiCreateInt32Test
8231  * @tc.desc: Test interface of napi_create_int32
8232  * @tc.type: FUNC
8233  */
HWTEST_F(NapiBasicTest, NapiCreateInt32Test001, testing::ext::TestSize.Level1)8234 HWTEST_F(NapiBasicTest, NapiCreateInt32Test001, testing::ext::TestSize.Level1)
8235 {
8236     ASSERT_NE(engine_, nullptr);
8237     napi_env env = reinterpret_cast<napi_env>(engine_);
8238 
8239     auto res = napi_create_int32(env, TEST_INT32_MINUS_1, nullptr);
8240     ASSERT_EQ(res, napi_invalid_arg);
8241 }
8242 
8243 /**
8244  * @tc.name: NapiCreateInt32Test
8245  * @tc.desc: Test interface of napi_create_int32
8246  * @tc.type: FUNC
8247  */
HWTEST_F(NapiBasicTest, NapiCreateInt32Test002, testing::ext::TestSize.Level1)8248 HWTEST_F(NapiBasicTest, NapiCreateInt32Test002, testing::ext::TestSize.Level1)
8249 {
8250     ASSERT_NE(engine_, nullptr);
8251     napi_env env = reinterpret_cast<napi_env>(engine_);
8252 
8253     napi_value numberValue = nullptr;
8254     auto res = napi_create_int32(env, TEST_INT32_MINUS_1, &numberValue);
8255     ASSERT_EQ(res, napi_ok);
8256 }
8257 
8258 /**
8259  * @tc.name: NapiCreateUint32Test
8260  * @tc.desc: Test interface of napi_create_uint32
8261  * @tc.type: FUNC
8262  */
HWTEST_F(NapiBasicTest, NapiCreateUint32Test001, testing::ext::TestSize.Level1)8263 HWTEST_F(NapiBasicTest, NapiCreateUint32Test001, testing::ext::TestSize.Level1)
8264 {
8265     ASSERT_NE(engine_, nullptr);
8266     napi_env env = reinterpret_cast<napi_env>(engine_);
8267 
8268     auto res = napi_create_uint32(env, TEST_UINT32_1000, nullptr);
8269     ASSERT_EQ(res, napi_invalid_arg);
8270 }
8271 
8272 /**
8273  * @tc.name: NapiCreateUint32Test
8274  * @tc.desc: Test interface of napi_create_uint32
8275  * @tc.type: FUNC
8276  */
HWTEST_F(NapiBasicTest, NapiCreateUint32Test002, testing::ext::TestSize.Level1)8277 HWTEST_F(NapiBasicTest, NapiCreateUint32Test002, testing::ext::TestSize.Level1)
8278 {
8279     ASSERT_NE(engine_, nullptr);
8280     napi_env env = reinterpret_cast<napi_env>(engine_);
8281 
8282     napi_value numberValue = nullptr;
8283     auto res = napi_create_uint32(env, TEST_UINT32_1000, &numberValue);
8284     ASSERT_EQ(res, napi_ok);
8285 }
8286 
8287 /**
8288  * @tc.name: NapiCreateInt64Test
8289  * @tc.desc: Test interface of napi_create_int64
8290  * @tc.type: FUNC
8291  */
HWTEST_F(NapiBasicTest, NapiCreateInt64Test001, testing::ext::TestSize.Level1)8292 HWTEST_F(NapiBasicTest, NapiCreateInt64Test001, testing::ext::TestSize.Level1)
8293 {
8294     ASSERT_NE(engine_, nullptr);
8295     napi_env env = reinterpret_cast<napi_env>(engine_);
8296 
8297     auto res = napi_create_int64(env, TEST_INT64, nullptr);
8298     ASSERT_EQ(res, napi_invalid_arg);
8299 }
8300 
8301 /**
8302  * @tc.name: NapiCreateInt64Test
8303  * @tc.desc: Test interface of napi_create_int64
8304  * @tc.type: FUNC
8305  */
HWTEST_F(NapiBasicTest, NapiCreateInt64Test002, testing::ext::TestSize.Level1)8306 HWTEST_F(NapiBasicTest, NapiCreateInt64Test002, testing::ext::TestSize.Level1)
8307 {
8308     ASSERT_NE(engine_, nullptr);
8309     napi_env env = reinterpret_cast<napi_env>(engine_);
8310 
8311     napi_value numberValue = nullptr;
8312     auto res = napi_create_int64(env, TEST_INT64, &numberValue);
8313     ASSERT_EQ(res, napi_ok);
8314 }
8315 
8316 /**
8317  * @tc.name: NapiCreateDoubleTest
8318  * @tc.desc: Test interface of napi_create_double
8319  * @tc.type: FUNC
8320  */
HWTEST_F(NapiBasicTest, NapiCreateDoubleTest001, testing::ext::TestSize.Level1)8321 HWTEST_F(NapiBasicTest, NapiCreateDoubleTest001, testing::ext::TestSize.Level1)
8322 {
8323     ASSERT_NE(engine_, nullptr);
8324     napi_env env = reinterpret_cast<napi_env>(engine_);
8325 
8326     auto res = napi_create_double(env, TEST_DOUBLE, nullptr);
8327     ASSERT_EQ(res, napi_invalid_arg);
8328 }
8329 
8330 /**
8331  * @tc.name: NapiCreateDoubleTest
8332  * @tc.desc: Test interface of napi_create_double
8333  * @tc.type: FUNC
8334  */
HWTEST_F(NapiBasicTest, NapiCreateDoubleTest002, testing::ext::TestSize.Level1)8335 HWTEST_F(NapiBasicTest, NapiCreateDoubleTest002, testing::ext::TestSize.Level1)
8336 {
8337     ASSERT_NE(engine_, nullptr);
8338     napi_env env = reinterpret_cast<napi_env>(engine_);
8339 
8340     napi_value numberValue = nullptr;
8341     auto res = napi_create_double(env, TEST_DOUBLE, &numberValue);
8342     ASSERT_EQ(res, napi_ok);
8343 }
8344 
8345 /**
8346  * @tc.name: NapiCreateStringLatin1Test
8347  * @tc.desc: Test interface of napi_create_string_latin1
8348  * @tc.type: FUNC
8349  */
HWTEST_F(NapiBasicTest, NapiCreateStringLatin1Test001, testing::ext::TestSize.Level1)8350 HWTEST_F(NapiBasicTest, NapiCreateStringLatin1Test001, testing::ext::TestSize.Level1)
8351 {
8352     ASSERT_NE(engine_, nullptr);
8353     napi_env env = reinterpret_cast<napi_env>(engine_);
8354 
8355     auto res = napi_create_string_latin1(env, nullptr, NAPI_AUTO_LENGTH, nullptr);
8356     ASSERT_EQ(res, napi_invalid_arg);
8357 }
8358 
8359 /**
8360  * @tc.name: NapiCreateStringLatin1Test
8361  * @tc.desc: Test interface of napi_create_string_latin1
8362  * @tc.type: FUNC
8363  */
HWTEST_F(NapiBasicTest, NapiCreateStringLatin1Test002, testing::ext::TestSize.Level1)8364 HWTEST_F(NapiBasicTest, NapiCreateStringLatin1Test002, testing::ext::TestSize.Level1)
8365 {
8366     ASSERT_NE(engine_, nullptr);
8367     napi_env env = reinterpret_cast<napi_env>(engine_);
8368 
8369     auto res = napi_create_string_latin1(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, nullptr);
8370     ASSERT_EQ(res, napi_invalid_arg);
8371 }
8372 
8373 /**
8374  * @tc.name: NapiCreateStringUtf8Test
8375  * @tc.desc: Test interface of napi_create_string_utf8
8376  * @tc.type: FUNC
8377  */
HWTEST_F(NapiBasicTest, NapiCreateStringUtf8Test001, testing::ext::TestSize.Level1)8378 HWTEST_F(NapiBasicTest, NapiCreateStringUtf8Test001, testing::ext::TestSize.Level1)
8379 {
8380     ASSERT_NE(engine_, nullptr);
8381     napi_env env = reinterpret_cast<napi_env>(engine_);
8382 
8383     auto res = napi_create_string_utf8(env, nullptr, NAPI_AUTO_LENGTH, nullptr);
8384     ASSERT_EQ(res, napi_invalid_arg);
8385 }
8386 
8387 /**
8388  * @tc.name: NapiCreateStringUtf8Test
8389  * @tc.desc: Test interface of napi_create_string_utf8
8390  * @tc.type: FUNC
8391  */
HWTEST_F(NapiBasicTest, NapiCreateStringUtf8Test002, testing::ext::TestSize.Level1)8392 HWTEST_F(NapiBasicTest, NapiCreateStringUtf8Test002, testing::ext::TestSize.Level1)
8393 {
8394     ASSERT_NE(engine_, nullptr);
8395     napi_env env = reinterpret_cast<napi_env>(engine_);
8396 
8397     auto res = napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, nullptr);
8398     ASSERT_EQ(res, napi_invalid_arg);
8399 }
8400 
8401 /**
8402  * @tc.name: NapiCreateStringUtf16Test
8403  * @tc.desc: Test interface of napi_create_string_utf16
8404  * @tc.type: FUNC
8405  */
HWTEST_F(NapiBasicTest, NapiCreateStringUtf16Test001, testing::ext::TestSize.Level1)8406 HWTEST_F(NapiBasicTest, NapiCreateStringUtf16Test001, testing::ext::TestSize.Level1)
8407 {
8408     ASSERT_NE(engine_, nullptr);
8409     napi_env env = reinterpret_cast<napi_env>(engine_);
8410 
8411     auto res = napi_create_string_utf16(env, nullptr, NAPI_AUTO_LENGTH, nullptr);
8412     ASSERT_EQ(res, napi_invalid_arg);
8413 }
8414 
8415 /**
8416  * @tc.name: NapiCreateStringUtf16Test
8417  * @tc.desc: Test interface of napi_create_string_utf16
8418  * @tc.type: FUNC
8419  */
HWTEST_F(NapiBasicTest, NapiCreateStringUtf16Test002, testing::ext::TestSize.Level1)8420 HWTEST_F(NapiBasicTest, NapiCreateStringUtf16Test002, testing::ext::TestSize.Level1)
8421 {
8422     ASSERT_NE(engine_, nullptr);
8423     napi_env env = reinterpret_cast<napi_env>(engine_);
8424 
8425     auto res = napi_create_string_utf16(env, TEST_CHAR16_STRING, NAPI_AUTO_LENGTH, nullptr);
8426     ASSERT_EQ(res, napi_invalid_arg);
8427 }
8428 
8429 /**
8430  * @tc.name: NapiCreateStringUtf16Test
8431  * @tc.desc: Test interface of napi_create_string_utf16
8432  * @tc.type: FUNC
8433  */
HWTEST_F(NapiBasicTest, NapiCreateStringUtf16Test003, testing::ext::TestSize.Level1)8434 HWTEST_F(NapiBasicTest, NapiCreateStringUtf16Test003, testing::ext::TestSize.Level1)
8435 {
8436     ASSERT_NE(engine_, nullptr);
8437     napi_env env = reinterpret_cast<napi_env>(engine_);
8438 
8439     napi_value stringValue = nullptr;
8440     auto res = napi_create_string_utf16(env, TEST_CHAR16_STRING, (NAPI_AUTO_LENGTH - 1), &stringValue);
8441     ASSERT_EQ(res, napi_invalid_arg);
8442 }
8443 
8444 /**
8445  * @tc.name: NapiGetArrayLengthTest
8446  * @tc.desc: Test interface of napi_get_array_length
8447  * @tc.type: FUNC
8448  */
HWTEST_F(NapiBasicTest, NapiGetArrayLengthTest001, testing::ext::TestSize.Level1)8449 HWTEST_F(NapiBasicTest, NapiGetArrayLengthTest001, testing::ext::TestSize.Level1)
8450 {
8451     ASSERT_NE(engine_, nullptr);
8452     napi_env env = reinterpret_cast<napi_env>(engine_);
8453 
8454     auto res = napi_get_array_length(env, nullptr, nullptr);
8455     ASSERT_EQ(res, napi_invalid_arg);
8456 }
8457 
8458 /**
8459  * @tc.name: NapiGetArrayLengthTest
8460  * @tc.desc: Test interface of napi_get_array_length
8461  * @tc.type: FUNC
8462  */
HWTEST_F(NapiBasicTest, NapiGetArrayLengthTest002, testing::ext::TestSize.Level1)8463 HWTEST_F(NapiBasicTest, NapiGetArrayLengthTest002, testing::ext::TestSize.Level1)
8464 {
8465     ASSERT_NE(engine_, nullptr);
8466     napi_env env = reinterpret_cast<napi_env>(engine_);
8467 
8468     napi_value boolean = nullptr;
8469     uint32_t arrayLength = 0;
8470     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8471     auto res = napi_get_array_length(env, boolean, &arrayLength);
8472     ASSERT_EQ(res, napi_array_expected);
8473 }
8474 
8475 /**
8476  * @tc.name: NapiGetArraybufferInfoTest
8477  * @tc.desc: Test interface of napi_get_arraybuffer_info
8478  * @tc.type: FUNC
8479  */
HWTEST_F(NapiBasicTest, NapiGetArraybufferInfoTest001, testing::ext::TestSize.Level1)8480 HWTEST_F(NapiBasicTest, NapiGetArraybufferInfoTest001, testing::ext::TestSize.Level1)
8481 {
8482     ASSERT_NE(engine_, nullptr);
8483     napi_env env = reinterpret_cast<napi_env>(engine_);
8484 
8485     auto res = napi_get_arraybuffer_info(env, nullptr, nullptr, nullptr);
8486     ASSERT_EQ(res, napi_invalid_arg);
8487 }
8488 
8489 /**
8490  * @tc.name: NapiGetArraybufferInfoTest
8491  * @tc.desc: Test interface of napi_get_arraybuffer_info
8492  * @tc.type: FUNC
8493  */
HWTEST_F(NapiBasicTest, NapiGetArraybufferInfoTest002, testing::ext::TestSize.Level1)8494 HWTEST_F(NapiBasicTest, NapiGetArraybufferInfoTest002, testing::ext::TestSize.Level1)
8495 {
8496     ASSERT_NE(engine_, nullptr);
8497     napi_env env = reinterpret_cast<napi_env>(engine_);
8498 
8499     napi_value boolean = nullptr;
8500     size_t arrayBufferLength = 0;
8501     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8502     auto res = napi_get_arraybuffer_info(env, boolean, nullptr, &arrayBufferLength);
8503     ASSERT_EQ(res, napi_arraybuffer_expected);
8504 }
8505 
8506 /**
8507  * @tc.name: NapiGetPrototypeTest
8508  * @tc.desc: Test interface of napi_get_prototype
8509  * @tc.type: FUNC
8510  */
HWTEST_F(NapiBasicTest, NapiGetPrototypeTest001, testing::ext::TestSize.Level1)8511 HWTEST_F(NapiBasicTest, NapiGetPrototypeTest001, testing::ext::TestSize.Level1)
8512 {
8513     ASSERT_NE(engine_, nullptr);
8514     napi_env env = reinterpret_cast<napi_env>(engine_);
8515 
8516     auto res = napi_get_prototype(env, nullptr, nullptr);
8517     ASSERT_EQ(res, napi_invalid_arg);
8518 }
8519 
8520 /**
8521  * @tc.name: NapiGetPrototypeTest
8522  * @tc.desc: Test interface of napi_get_prototype
8523  * @tc.type: FUNC
8524  */
HWTEST_F(NapiBasicTest, NapiGetPrototypeTest002, testing::ext::TestSize.Level1)8525 HWTEST_F(NapiBasicTest, NapiGetPrototypeTest002, testing::ext::TestSize.Level1)
8526 {
8527     ASSERT_NE(engine_, nullptr);
8528     napi_env env = reinterpret_cast<napi_env>(engine_);
8529 
8530     napi_value result = nullptr;
8531     napi_value boolean = nullptr;
8532     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8533     auto res = napi_get_prototype(env, boolean, &result);
8534     ASSERT_EQ(res, napi_object_expected);
8535 }
8536 
8537 /**
8538  * @tc.name: NapiGetTypedarrayInfoTest
8539  * @tc.desc: Test interface of napi_get_typedarray_info
8540  * @tc.type: FUNC
8541  */
HWTEST_F(NapiBasicTest, NapiGetTypedarrayInfoTest001, testing::ext::TestSize.Level1)8542 HWTEST_F(NapiBasicTest, NapiGetTypedarrayInfoTest001, testing::ext::TestSize.Level1)
8543 {
8544     ASSERT_NE(engine_, nullptr);
8545     napi_env env = reinterpret_cast<napi_env>(engine_);
8546 
8547     auto res = napi_get_typedarray_info(env, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
8548     ASSERT_EQ(res, napi_invalid_arg);
8549 }
8550 
8551 /**
8552  * @tc.name: NapiGetTypedarrayInfoTest
8553  * @tc.desc: Test interface of napi_get_typedarray_info
8554  * @tc.type: FUNC
8555  */
HWTEST_F(NapiBasicTest, NapiGetTypedarrayInfoTest002, testing::ext::TestSize.Level1)8556 HWTEST_F(NapiBasicTest, NapiGetTypedarrayInfoTest002, testing::ext::TestSize.Level1)
8557 {
8558     ASSERT_NE(engine_, nullptr);
8559     napi_env env = reinterpret_cast<napi_env>(engine_);
8560 
8561     napi_value boolean = nullptr;
8562     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8563     auto res = napi_get_typedarray_info(env, boolean, nullptr, nullptr, nullptr, nullptr, nullptr);
8564     ASSERT_EQ(res, napi_invalid_arg);
8565 }
8566 
8567 /**
8568  * @tc.name: NapiGetDataviewInfoTest
8569  * @tc.desc: Test interface of napi_get_dataview_info
8570  * @tc.type: FUNC
8571  */
HWTEST_F(NapiBasicTest, NapiGetDataviewInfoTest001, testing::ext::TestSize.Level1)8572 HWTEST_F(NapiBasicTest, NapiGetDataviewInfoTest001, testing::ext::TestSize.Level1)
8573 {
8574     ASSERT_NE(engine_, nullptr);
8575     napi_env env = reinterpret_cast<napi_env>(engine_);
8576 
8577     auto res = napi_get_dataview_info(env, nullptr, nullptr, nullptr, nullptr, nullptr);
8578     ASSERT_EQ(res, napi_invalid_arg);
8579 }
8580 
8581 /**
8582  * @tc.name: NapiGetDataviewInfoTest
8583  * @tc.desc: Test interface of napi_get_dataview_info
8584  * @tc.type: FUNC
8585  */
HWTEST_F(NapiBasicTest, NapiGetDataviewInfoTest002, testing::ext::TestSize.Level1)8586 HWTEST_F(NapiBasicTest, NapiGetDataviewInfoTest002, testing::ext::TestSize.Level1)
8587 {
8588     ASSERT_NE(engine_, nullptr);
8589     napi_env env = reinterpret_cast<napi_env>(engine_);
8590 
8591     napi_value boolean = nullptr;
8592     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8593     auto res = napi_get_dataview_info(env, boolean, nullptr, nullptr, nullptr, nullptr);
8594     ASSERT_EQ(res, napi_invalid_arg);
8595 }
8596 
8597 /**
8598  * @tc.name: NapiGetValueBoolTest
8599  * @tc.desc: Test interface of napi_get_value_bool
8600  * @tc.type: FUNC
8601  */
HWTEST_F(NapiBasicTest, NapiGetValueBoolTest001, testing::ext::TestSize.Level1)8602 HWTEST_F(NapiBasicTest, NapiGetValueBoolTest001, testing::ext::TestSize.Level1)
8603 {
8604     ASSERT_NE(engine_, nullptr);
8605     napi_env env = reinterpret_cast<napi_env>(engine_);
8606 
8607     auto res = napi_get_value_bool(env, nullptr, nullptr);
8608     ASSERT_EQ(res, napi_invalid_arg);
8609 }
8610 
8611 /**
8612  * @tc.name: NapiGetValueBoolTest
8613  * @tc.desc: Test interface of napi_get_value_bool
8614  * @tc.type: FUNC
8615  */
HWTEST_F(NapiBasicTest, NapiGetValueBoolTest002, testing::ext::TestSize.Level1)8616 HWTEST_F(NapiBasicTest, NapiGetValueBoolTest002, testing::ext::TestSize.Level1)
8617 {
8618     ASSERT_NE(engine_, nullptr);
8619     napi_env env = reinterpret_cast<napi_env>(engine_);
8620 
8621     napi_value stringUtf8 = nullptr;
8622     const char testStr[] = "errorType";
8623     ASSERT_CHECK_CALL(napi_create_string_utf8(env, testStr, NAPI_AUTO_LENGTH, &stringUtf8));
8624     bool boolean;
8625     auto res = napi_get_value_bool(env, stringUtf8, &boolean);
8626     ASSERT_EQ(res, napi_boolean_expected);
8627 }
8628 
8629 /**
8630  * @tc.name: NapiGetValueDoubleTest
8631  * @tc.desc: Test interface of napi_get_value_double
8632  * @tc.type: FUNC
8633  */
HWTEST_F(NapiBasicTest, NapiGetValueDoubleTest001, testing::ext::TestSize.Level1)8634 HWTEST_F(NapiBasicTest, NapiGetValueDoubleTest001, testing::ext::TestSize.Level1)
8635 {
8636     ASSERT_NE(engine_, nullptr);
8637     napi_env env = reinterpret_cast<napi_env>(engine_);
8638 
8639     auto res = napi_get_value_double(env, nullptr, nullptr);
8640     ASSERT_EQ(res, napi_invalid_arg);
8641 }
8642 
8643 /**
8644  * @tc.name: NapiGetValueDoubleTest
8645  * @tc.desc: Test interface of napi_get_value_double
8646  * @tc.type: FUNC
8647  */
HWTEST_F(NapiBasicTest, NapiGetValueDoubleTest002, testing::ext::TestSize.Level1)8648 HWTEST_F(NapiBasicTest, NapiGetValueDoubleTest002, testing::ext::TestSize.Level1)
8649 {
8650     ASSERT_NE(engine_, nullptr);
8651     napi_env env = reinterpret_cast<napi_env>(engine_);
8652 
8653     napi_value boolean = nullptr;
8654     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8655     double number;
8656     auto res = napi_get_value_double(env, boolean, &number);
8657     ASSERT_EQ(res, napi_number_expected);
8658 }
8659 
8660 /**
8661  * @tc.name: NapiGetValueExternalTest
8662  * @tc.desc: Test interface of napi_get_value_external
8663  * @tc.type: FUNC
8664  */
HWTEST_F(NapiBasicTest, NapiGetValueExternalTest001, testing::ext::TestSize.Level1)8665 HWTEST_F(NapiBasicTest, NapiGetValueExternalTest001, testing::ext::TestSize.Level1)
8666 {
8667     ASSERT_NE(engine_, nullptr);
8668     napi_env env = reinterpret_cast<napi_env>(engine_);
8669 
8670     auto res = napi_get_value_external(env, nullptr, nullptr);
8671     ASSERT_EQ(res, napi_invalid_arg);
8672 }
8673 
8674 /**
8675  * @tc.name: NapiGetValueExternalTest
8676  * @tc.desc: Test interface of napi_get_value_external
8677  * @tc.type: FUNC
8678  */
HWTEST_F(NapiBasicTest, NapiGetValueExternalTest002, testing::ext::TestSize.Level1)8679 HWTEST_F(NapiBasicTest, NapiGetValueExternalTest002, testing::ext::TestSize.Level1)
8680 {
8681     ASSERT_NE(engine_, nullptr);
8682     napi_env env = reinterpret_cast<napi_env>(engine_);
8683 
8684     napi_value boolean = nullptr;
8685     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8686     void* external;
8687     auto res = napi_get_value_external(env, boolean, &external);
8688     ASSERT_EQ(res, napi_object_expected);
8689 }
8690 
8691 /**
8692  * @tc.name: NapiGetValueInt32Test
8693  * @tc.desc: Test interface of napi_get_value_int32
8694  * @tc.type: FUNC
8695  */
HWTEST_F(NapiBasicTest, NapiGetValueInt32Test001, testing::ext::TestSize.Level1)8696 HWTEST_F(NapiBasicTest, NapiGetValueInt32Test001, testing::ext::TestSize.Level1)
8697 {
8698     ASSERT_NE(engine_, nullptr);
8699     napi_env env = reinterpret_cast<napi_env>(engine_);
8700 
8701     auto res = napi_get_value_int32(env, nullptr, nullptr);
8702     ASSERT_EQ(res, napi_invalid_arg);
8703 }
8704 
8705 /**
8706  * @tc.name: NapiGetValueInt32Test
8707  * @tc.desc: Test interface of napi_get_value_int32
8708  * @tc.type: FUNC
8709  */
HWTEST_F(NapiBasicTest, NapiGetValueInt32Test002, testing::ext::TestSize.Level1)8710 HWTEST_F(NapiBasicTest, NapiGetValueInt32Test002, testing::ext::TestSize.Level1)
8711 {
8712     ASSERT_NE(engine_, nullptr);
8713     napi_env env = reinterpret_cast<napi_env>(engine_);
8714 
8715     napi_value boolean = nullptr;
8716     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8717     int32_t number;
8718     auto res = napi_get_value_int32(env, boolean, &number);
8719     ASSERT_EQ(res, napi_number_expected);
8720 }
8721 
8722 /**
8723  * @tc.name: NapiGetValueInt64Test
8724  * @tc.desc: Test interface of napi_get_value_int64
8725  * @tc.type: FUNC
8726  */
HWTEST_F(NapiBasicTest, NapiGetValueInt64Test001, testing::ext::TestSize.Level1)8727 HWTEST_F(NapiBasicTest, NapiGetValueInt64Test001, testing::ext::TestSize.Level1)
8728 {
8729     ASSERT_NE(engine_, nullptr);
8730     napi_env env = reinterpret_cast<napi_env>(engine_);
8731 
8732     auto res = napi_get_value_int64(env, nullptr, nullptr);
8733     ASSERT_EQ(res, napi_invalid_arg);
8734 }
8735 
8736 /**
8737  * @tc.name: NapiGetValueInt64Test
8738  * @tc.desc: Test interface of napi_get_value_int64
8739  * @tc.type: FUNC
8740  */
HWTEST_F(NapiBasicTest, NapiGetValueInt64Test002, testing::ext::TestSize.Level1)8741 HWTEST_F(NapiBasicTest, NapiGetValueInt64Test002, testing::ext::TestSize.Level1)
8742 {
8743     ASSERT_NE(engine_, nullptr);
8744     napi_env env = reinterpret_cast<napi_env>(engine_);
8745 
8746     napi_value boolean = nullptr;
8747     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8748     int64_t number;
8749     auto res = napi_get_value_int64(env, boolean, &number);
8750     ASSERT_EQ(res, napi_number_expected);
8751 }
8752 
8753 /**
8754  * @tc.name: NapiGetValueStringLatin1Test
8755  * @tc.desc: Test interface of napi_get_value_string_latin1
8756  * @tc.type: FUNC
8757  */
HWTEST_F(NapiBasicTest, NapiGetValueStringLatin1Test001, testing::ext::TestSize.Level1)8758 HWTEST_F(NapiBasicTest, NapiGetValueStringLatin1Test001, testing::ext::TestSize.Level1)
8759 {
8760     ASSERT_NE(engine_, nullptr);
8761     napi_env env = reinterpret_cast<napi_env>(engine_);
8762 
8763     auto res = napi_get_value_string_latin1(env, nullptr, nullptr, 0, nullptr);
8764     ASSERT_EQ(res, napi_invalid_arg);
8765 }
8766 
8767 /**
8768  * @tc.name: NapiGetValueStringLatin1Test
8769  * @tc.desc: Test interface of napi_get_value_string_latin1
8770  * @tc.type: FUNC
8771  */
HWTEST_F(NapiBasicTest, NapiGetValueStringLatin1Test002, testing::ext::TestSize.Level1)8772 HWTEST_F(NapiBasicTest, NapiGetValueStringLatin1Test002, testing::ext::TestSize.Level1)
8773 {
8774     ASSERT_NE(engine_, nullptr);
8775     napi_env env = reinterpret_cast<napi_env>(engine_);
8776 
8777     napi_value boolean = nullptr;
8778     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8779     auto res = napi_get_value_string_latin1(env, boolean, nullptr, 0, nullptr);
8780     ASSERT_EQ(res, napi_string_expected);
8781 }
8782 
8783 /**
8784  * @tc.name: NapiGetValueStringLatin1Test
8785  * @tc.desc: Test interface of napi_get_value_string_latin1
8786  * @tc.type: FUNC
8787  */
HWTEST_F(NapiBasicTest, NapiGetValueStringLatin1Test003, testing::ext::TestSize.Level1)8788 HWTEST_F(NapiBasicTest, NapiGetValueStringLatin1Test003, testing::ext::TestSize.Level1)
8789 {
8790     ASSERT_NE(engine_, nullptr);
8791     napi_env env = reinterpret_cast<napi_env>(engine_);
8792 
8793     napi_value stringValue = nullptr;
8794     ASSERT_CHECK_CALL(napi_create_string_latin1(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &stringValue));
8795     auto res = napi_get_value_string_latin1(env, stringValue, nullptr, 0, nullptr);
8796     ASSERT_EQ(res, napi_invalid_arg);
8797 
8798     size_t strSize = 0;
8799     res = napi_get_value_string_latin1(env, stringValue, nullptr, 0, &strSize);
8800     ASSERT_EQ(res, napi_ok);
8801 }
8802 
8803 /**
8804  * @tc.name: NapiGetValueStringUtf8Test
8805  * @tc.desc: Test interface of napi_get_value_string_utf8
8806  * @tc.type: FUNC
8807  */
HWTEST_F(NapiBasicTest, NapiGetValueStringUtf8Test001, testing::ext::TestSize.Level1)8808 HWTEST_F(NapiBasicTest, NapiGetValueStringUtf8Test001, testing::ext::TestSize.Level1)
8809 {
8810     ASSERT_NE(engine_, nullptr);
8811     napi_env env = reinterpret_cast<napi_env>(engine_);
8812 
8813     auto res = napi_get_value_string_utf8(env, nullptr, nullptr, 0, nullptr);
8814     ASSERT_EQ(res, napi_invalid_arg);
8815 }
8816 
8817 /**
8818  * @tc.name: NapiGetValueStringUtf8Test
8819  * @tc.desc: Test interface of napi_get_value_string_utf8
8820  * @tc.type: FUNC
8821  */
HWTEST_F(NapiBasicTest, NapiGetValueStringUtf8Test002, testing::ext::TestSize.Level1)8822 HWTEST_F(NapiBasicTest, NapiGetValueStringUtf8Test002, testing::ext::TestSize.Level1)
8823 {
8824     ASSERT_NE(engine_, nullptr);
8825     napi_env env = reinterpret_cast<napi_env>(engine_);
8826 
8827     napi_value boolean = nullptr;
8828     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8829     auto res = napi_get_value_string_utf8(env, boolean, nullptr, 0, nullptr);
8830     ASSERT_EQ(res, napi_string_expected);
8831 }
8832 
8833 /**
8834  * @tc.name: NapiGetValueStringUtf8Test
8835  * @tc.desc: Test interface of napi_get_value_string_utf8
8836  * @tc.type: FUNC
8837  */
HWTEST_F(NapiBasicTest, NapiGetValueStringUtf8Test003, testing::ext::TestSize.Level1)8838 HWTEST_F(NapiBasicTest, NapiGetValueStringUtf8Test003, testing::ext::TestSize.Level1)
8839 {
8840     ASSERT_NE(engine_, nullptr);
8841     napi_env env = reinterpret_cast<napi_env>(engine_);
8842 
8843     napi_value stringValue = nullptr;
8844     ASSERT_CHECK_CALL(napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &stringValue));
8845     auto res = napi_get_value_string_utf8(env, stringValue, nullptr, 0, nullptr);
8846     ASSERT_EQ(res, napi_invalid_arg);
8847 
8848     size_t strSize = 0;
8849     res = napi_get_value_string_utf8(env, stringValue, nullptr, 0, &strSize);
8850     ASSERT_EQ(res, napi_ok);
8851 }
8852 
8853 /**
8854  * @tc.name: NapiGetValueStringUtf16Test
8855  * @tc.desc: Test interface of napi_get_value_string_utf16
8856  * @tc.type: FUNC
8857  */
HWTEST_F(NapiBasicTest, NapiGetValueStringUtf16Test001, testing::ext::TestSize.Level1)8858 HWTEST_F(NapiBasicTest, NapiGetValueStringUtf16Test001, testing::ext::TestSize.Level1)
8859 {
8860     ASSERT_NE(engine_, nullptr);
8861     napi_env env = reinterpret_cast<napi_env>(engine_);
8862 
8863     auto res = napi_get_value_string_utf16(env, nullptr, nullptr, 0, nullptr);
8864     ASSERT_EQ(res, napi_invalid_arg);
8865 }
8866 
8867 /**
8868  * @tc.name: NapiGetValueStringUtf16Test
8869  * @tc.desc: Test interface of napi_get_value_string_utf16
8870  * @tc.type: FUNC
8871  */
HWTEST_F(NapiBasicTest, NapiGetValueStringUtf16Test002, testing::ext::TestSize.Level1)8872 HWTEST_F(NapiBasicTest, NapiGetValueStringUtf16Test002, testing::ext::TestSize.Level1)
8873 {
8874     ASSERT_NE(engine_, nullptr);
8875     napi_env env = reinterpret_cast<napi_env>(engine_);
8876 
8877     napi_value boolean = nullptr;
8878     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8879     auto res = napi_get_value_string_utf16(env, boolean, nullptr, 0, nullptr);
8880     ASSERT_EQ(res, napi_string_expected);
8881 }
8882 
8883 /**
8884  * @tc.name: NapiGetValueStringUtf16Test
8885  * @tc.desc: Test interface of napi_get_value_string_utf16
8886  * @tc.type: FUNC
8887  */
HWTEST_F(NapiBasicTest, NapiGetValueStringUtf16Test003, testing::ext::TestSize.Level1)8888 HWTEST_F(NapiBasicTest, NapiGetValueStringUtf16Test003, testing::ext::TestSize.Level1)
8889 {
8890     ASSERT_NE(engine_, nullptr);
8891     napi_env env = reinterpret_cast<napi_env>(engine_);
8892 
8893     napi_value stringValue = nullptr;
8894     ASSERT_CHECK_CALL(napi_create_string_utf16(env, TEST_CHAR16_STRING, NAPI_AUTO_LENGTH, &stringValue));
8895     auto res = napi_get_value_string_utf16(env, stringValue, nullptr, 0, nullptr);
8896     ASSERT_EQ(res, napi_invalid_arg);
8897 
8898     size_t strSize = 0;
8899     res = napi_get_value_string_utf16(env, stringValue, nullptr, 0, &strSize);
8900     ASSERT_EQ(res, napi_ok);
8901 }
8902 
8903 /**
8904  * @tc.name: NapiGetValueUint32Test
8905  * @tc.desc: Test interface of napi_get_value_uint32
8906  * @tc.type: FUNC
8907  */
HWTEST_F(NapiBasicTest, NapiGetValueUint32Test001, testing::ext::TestSize.Level1)8908 HWTEST_F(NapiBasicTest, NapiGetValueUint32Test001, testing::ext::TestSize.Level1)
8909 {
8910     ASSERT_NE(engine_, nullptr);
8911     napi_env env = reinterpret_cast<napi_env>(engine_);
8912 
8913         auto res = napi_get_value_uint32(env, nullptr, nullptr);
8914     ASSERT_EQ(res, napi_invalid_arg);
8915 }
8916 
8917 /**
8918  * @tc.name: NapiGetValueUint32Test
8919  * @tc.desc: Test interface of napi_get_value_uint32
8920  * @tc.type: FUNC
8921  */
HWTEST_F(NapiBasicTest, NapiGetValueUint32Test002, testing::ext::TestSize.Level1)8922 HWTEST_F(NapiBasicTest, NapiGetValueUint32Test002, testing::ext::TestSize.Level1)
8923 {
8924     ASSERT_NE(engine_, nullptr);
8925     napi_env env = reinterpret_cast<napi_env>(engine_);
8926 
8927     napi_value boolean = nullptr;
8928     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
8929     uint32_t number;
8930     auto res = napi_get_value_uint32(env, boolean, &number);
8931     ASSERT_EQ(res, napi_number_expected);
8932 }
8933 
8934 /**
8935  * @tc.name: NapiGetBooleanTest
8936  * @tc.desc: Test interface of napi_get_boolean
8937  * @tc.type: FUNC
8938  */
HWTEST_F(NapiBasicTest, NapiGetBooleanTest001, testing::ext::TestSize.Level1)8939 HWTEST_F(NapiBasicTest, NapiGetBooleanTest001, testing::ext::TestSize.Level1)
8940 {
8941     ASSERT_NE(engine_, nullptr);
8942     napi_env env = reinterpret_cast<napi_env>(engine_);
8943 
8944     auto res = napi_get_boolean(env, true, nullptr);
8945     ASSERT_EQ(res, napi_invalid_arg);
8946 
8947     napi_value result = nullptr;
8948     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &result));
8949     ASSERT_CHECK_CALL(napi_get_boolean(env, false, &result));
8950 }
8951 
8952 /**
8953  * @tc.name: NapiGetGlobalTest
8954  * @tc.desc: Test interface of napi_get_global
8955  * @tc.type: FUNC
8956  */
HWTEST_F(NapiBasicTest, NapiGetGlobalTest001, testing::ext::TestSize.Level1)8957 HWTEST_F(NapiBasicTest, NapiGetGlobalTest001, testing::ext::TestSize.Level1)
8958 {
8959     ASSERT_NE(engine_, nullptr);
8960     napi_env env = reinterpret_cast<napi_env>(engine_);
8961 
8962     auto res = napi_get_global(env, nullptr);
8963     ASSERT_EQ(res, napi_invalid_arg);
8964 }
8965 
8966 /**
8967  * @tc.name: NapiGetNullTest
8968  * @tc.desc: Test interface of napi_get_null
8969  * @tc.type: FUNC
8970  */
HWTEST_F(NapiBasicTest, NapiGetNullTest001, testing::ext::TestSize.Level1)8971 HWTEST_F(NapiBasicTest, NapiGetNullTest001, testing::ext::TestSize.Level1)
8972 {
8973     ASSERT_NE(engine_, nullptr);
8974     napi_env env = reinterpret_cast<napi_env>(engine_);
8975 
8976     auto res = napi_get_null(env, nullptr);
8977     ASSERT_EQ(res, napi_invalid_arg);
8978 }
8979 
8980 /**
8981  * @tc.name: NapiGetUndefinedTest
8982  * @tc.desc: Test interface of napi_get_undefined
8983  * @tc.type: FUNC
8984  */
HWTEST_F(NapiBasicTest, NapiGetUndefinedTest001, testing::ext::TestSize.Level1)8985 HWTEST_F(NapiBasicTest, NapiGetUndefinedTest001, testing::ext::TestSize.Level1)
8986 {
8987     ASSERT_NE(engine_, nullptr);
8988     napi_env env = reinterpret_cast<napi_env>(engine_);
8989 
8990     auto res = napi_get_undefined(env, nullptr);
8991     ASSERT_EQ(res, napi_invalid_arg);
8992 }
8993 
8994 /**
8995  * @tc.name: NapiObjectFreezeTest
8996  * @tc.desc: Test interface of napi_object_freeze
8997  * @tc.type: FUNC
8998  */
HWTEST_F(NapiBasicTest, NapiObjectFreezeTest001, testing::ext::TestSize.Level1)8999 HWTEST_F(NapiBasicTest, NapiObjectFreezeTest001, testing::ext::TestSize.Level1)
9000 {
9001     ASSERT_NE(engine_, nullptr);
9002     napi_env env = reinterpret_cast<napi_env>(engine_);
9003 
9004     auto res = napi_object_freeze(env, nullptr);
9005     ASSERT_EQ(res, napi_invalid_arg);
9006 }
9007 
9008 /**
9009  * @tc.name: NapiObjectFreezeTest
9010  * @tc.desc: Test interface of napi_object_freeze
9011  * @tc.type: FUNC
9012  */
HWTEST_F(NapiBasicTest, NapiObjectFreezeTest002, testing::ext::TestSize.Level1)9013 HWTEST_F(NapiBasicTest, NapiObjectFreezeTest002, testing::ext::TestSize.Level1)
9014 {
9015     ASSERT_NE(engine_, nullptr);
9016     napi_env env = reinterpret_cast<napi_env>(engine_);
9017 
9018     napi_value boolean = nullptr;
9019     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
9020     auto res = napi_object_freeze(env, boolean);
9021     ASSERT_EQ(res, napi_object_expected);
9022 }
9023 
9024 /**
9025  * @tc.name: NapiObjectSealTest
9026  * @tc.desc: Test interface of napi_object_seal
9027  * @tc.type: FUNC
9028  */
HWTEST_F(NapiBasicTest, NapiObjectSealTest001, testing::ext::TestSize.Level1)9029 HWTEST_F(NapiBasicTest, NapiObjectSealTest001, testing::ext::TestSize.Level1)
9030 {
9031     ASSERT_NE(engine_, nullptr);
9032     napi_env env = reinterpret_cast<napi_env>(engine_);
9033 
9034     auto res = napi_object_seal(env, nullptr);
9035     ASSERT_EQ(res, napi_invalid_arg);
9036 }
9037 
9038 /**
9039  * @tc.name: NapiObjectSealTest
9040  * @tc.desc: Test interface of napi_object_seal
9041  * @tc.type: FUNC
9042  */
HWTEST_F(NapiBasicTest, NapiObjectSealTest002, testing::ext::TestSize.Level1)9043 HWTEST_F(NapiBasicTest, NapiObjectSealTest002, testing::ext::TestSize.Level1)
9044 {
9045     ASSERT_NE(engine_, nullptr);
9046     napi_env env = reinterpret_cast<napi_env>(engine_);
9047 
9048     napi_value boolean = nullptr;
9049     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
9050     auto res = napi_object_seal(env, boolean);
9051     ASSERT_EQ(res, napi_object_expected);
9052 }
9053 
9054 /**
9055  * @tc.name: NapiGetAllPropertyNamesTest
9056  * @tc.desc: Test interface of napi_get_all_property_names
9057  * @tc.type: FUNC
9058  */
HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest001, testing::ext::TestSize.Level1)9059 HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest001, testing::ext::TestSize.Level1)
9060 {
9061     ASSERT_NE(engine_, nullptr);
9062     napi_env env = reinterpret_cast<napi_env>(engine_);
9063 
9064     auto res = napi_get_all_property_names(env, nullptr, napi_key_include_prototypes, napi_key_all_properties,
9065         napi_key_keep_numbers, nullptr);
9066     ASSERT_EQ(res, napi_invalid_arg);
9067 }
9068 
9069 /**
9070  * @tc.name: NapiGetAllPropertyNamesTest
9071  * @tc.desc: Test interface of napi_get_all_property_names
9072  * @tc.type: FUNC
9073  */
HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest002, testing::ext::TestSize.Level1)9074 HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest002, testing::ext::TestSize.Level1)
9075 {
9076     ASSERT_NE(engine_, nullptr);
9077     napi_env env = reinterpret_cast<napi_env>(engine_);
9078 
9079     napi_value object = nullptr;
9080     ASSERT_CHECK_CALL(napi_create_object(env, &object));
9081     auto res = napi_get_all_property_names(env, object, napi_key_include_prototypes, napi_key_all_properties,
9082         napi_key_keep_numbers, nullptr);
9083     ASSERT_EQ(res, napi_invalid_arg);
9084 }
9085 
9086 /**
9087  * @tc.name: NapiGetAllPropertyNamesTest
9088  * @tc.desc: Test interface of napi_get_all_property_names
9089  * @tc.type: FUNC
9090  */
HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest003, testing::ext::TestSize.Level1)9091 HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest003, testing::ext::TestSize.Level1)
9092 {
9093     ASSERT_NE(engine_, nullptr);
9094     napi_env env = reinterpret_cast<napi_env>(engine_);
9095 
9096     napi_value result = nullptr;
9097     napi_value boolean = nullptr;
9098     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
9099     auto res = napi_get_all_property_names(env, boolean, napi_key_include_prototypes, napi_key_all_properties,
9100         napi_key_keep_numbers, &result);
9101     ASSERT_EQ(res, napi_object_expected);
9102 }
9103 
9104 /**
9105  * @tc.name: NapiGetAllPropertyNamesTest
9106  * @tc.desc: Test interface of napi_get_all_property_names
9107  * @tc.type: FUNC
9108  */
HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest004, testing::ext::TestSize.Level1)9109 HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest004, testing::ext::TestSize.Level1)
9110 {
9111     ASSERT_NE(engine_, nullptr);
9112     napi_env env = reinterpret_cast<napi_env>(engine_);
9113 
9114     napi_value result = nullptr;
9115     napi_value object = nullptr;
9116     ASSERT_CHECK_CALL(napi_create_object(env, &object));
9117     auto res = napi_get_all_property_names(env, object, (napi_key_collection_mode)(napi_key_include_prototypes - 1),
9118         napi_key_all_properties, napi_key_keep_numbers, &result);
9119     ASSERT_EQ(res, napi_invalid_arg);
9120 }
9121 
9122 /**
9123  * @tc.name: NapiGetAllPropertyNamesTest
9124  * @tc.desc: Test interface of napi_get_all_property_names
9125  * @tc.type: FUNC
9126  */
HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest005, testing::ext::TestSize.Level1)9127 HWTEST_F(NapiBasicTest, NapiGetAllPropertyNamesTest005, testing::ext::TestSize.Level1)
9128 {
9129     ASSERT_NE(engine_, nullptr);
9130     napi_env env = reinterpret_cast<napi_env>(engine_);
9131 
9132     napi_value result = nullptr;
9133     napi_value object = nullptr;
9134     ASSERT_CHECK_CALL(napi_create_object(env, &object));
9135     auto res = napi_get_all_property_names(env, object, napi_key_include_prototypes, napi_key_all_properties,
9136         (napi_key_conversion)(napi_key_keep_numbers - 1), &result);
9137     ASSERT_EQ(res, napi_invalid_arg);
9138 }
9139 
9140 /**
9141  * @tc.name: NapiDetachArraybufferTest
9142  * @tc.desc: Test interface of napi_detach_arraybuffer
9143  * @tc.type: FUNC
9144  */
HWTEST_F(NapiBasicTest, NapiDetachArraybufferTest001, testing::ext::TestSize.Level1)9145 HWTEST_F(NapiBasicTest, NapiDetachArraybufferTest001, testing::ext::TestSize.Level1)
9146 {
9147     ASSERT_NE(engine_, nullptr);
9148     napi_env env = reinterpret_cast<napi_env>(engine_);
9149 
9150     auto res = napi_detach_arraybuffer(env, nullptr);
9151     ASSERT_EQ(res, napi_invalid_arg);
9152 }
9153 
9154 /**
9155  * @tc.name: NapiDetachArraybufferTest
9156  * @tc.desc: Test interface of napi_detach_arraybuffer
9157  * @tc.type: FUNC
9158  */
HWTEST_F(NapiBasicTest, NapiDetachArraybufferTest002, testing::ext::TestSize.Level1)9159 HWTEST_F(NapiBasicTest, NapiDetachArraybufferTest002, testing::ext::TestSize.Level1)
9160 {
9161     ASSERT_NE(engine_, nullptr);
9162     napi_env env = reinterpret_cast<napi_env>(engine_);
9163 
9164     napi_value boolean = nullptr;
9165     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
9166     auto res = napi_detach_arraybuffer(env, boolean);
9167     ASSERT_EQ(res, napi_object_expected);
9168 }
9169 
9170 /**
9171  * @tc.name: NapiDetachArraybufferTest
9172  * @tc.desc: Test interface of napi_detach_arraybuffer
9173  * @tc.type: FUNC
9174  */
HWTEST_F(NapiBasicTest, NapiDetachArraybufferTest003, testing::ext::TestSize.Level1)9175 HWTEST_F(NapiBasicTest, NapiDetachArraybufferTest003, testing::ext::TestSize.Level1)
9176 {
9177     ASSERT_NE(engine_, nullptr);
9178     napi_env env = reinterpret_cast<napi_env>(engine_);
9179 
9180     napi_value object = nullptr;
9181     ASSERT_CHECK_CALL(napi_create_object(env, &object));
9182     auto res = napi_detach_arraybuffer(env, object);
9183     ASSERT_EQ(res, napi_invalid_arg);
9184 }
9185 
9186 /**
9187  * @tc.name: NapiIsDetachedArraybufferTest
9188  * @tc.desc: Test interface of napi_is_detached_arraybuffer
9189  * @tc.type: FUNC
9190  */
HWTEST_F(NapiBasicTest, NapiIsDetachedArraybufferTest001, testing::ext::TestSize.Level1)9191 HWTEST_F(NapiBasicTest, NapiIsDetachedArraybufferTest001, testing::ext::TestSize.Level1)
9192 {
9193     ASSERT_NE(engine_, nullptr);
9194     napi_env env = reinterpret_cast<napi_env>(engine_);
9195 
9196     auto res = napi_is_detached_arraybuffer(env, nullptr, nullptr);
9197     ASSERT_EQ(res, napi_invalid_arg);
9198 }
9199 
9200 /**
9201  * @tc.name: NapiIsDetachedArraybufferTest
9202  * @tc.desc: Test interface of napi_is_detached_arraybuffer
9203  * @tc.type: FUNC
9204  */
HWTEST_F(NapiBasicTest, NapiIsDetachedArraybufferTest002, testing::ext::TestSize.Level1)9205 HWTEST_F(NapiBasicTest, NapiIsDetachedArraybufferTest002, testing::ext::TestSize.Level1)
9206 {
9207     ASSERT_NE(engine_, nullptr);
9208     napi_env env = reinterpret_cast<napi_env>(engine_);
9209 
9210     static constexpr size_t arrayBufferSize = 1024;
9211     napi_value arrayBuffer = nullptr;
9212     void* arrayBufferPtr = nullptr;
9213     ASSERT_CHECK_CALL(napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer));
9214 
9215     auto res = napi_is_detached_arraybuffer(env, arrayBuffer, nullptr);
9216     ASSERT_EQ(res, napi_invalid_arg);
9217 }
9218 
9219 /**
9220  * @tc.name: NapiSetInstanceDataTest
9221  * @tc.desc: Test interface of napi_set_instance_data
9222  * @tc.type: FUNC
9223  */
HWTEST_F(NapiBasicTest, NapiSetInstanceDataTest001, testing::ext::TestSize.Level1)9224 HWTEST_F(NapiBasicTest, NapiSetInstanceDataTest001, testing::ext::TestSize.Level1)
9225 {
9226     auto res = napi_set_instance_data(nullptr, nullptr, nullptr, nullptr);
9227     ASSERT_EQ(res, napi_invalid_arg);
9228 }
9229 
9230 /**
9231  * @tc.name: NapiGetInstanceDataTest
9232  * @tc.desc: Test interface of napi_get_instance_data
9233  * @tc.type: FUNC
9234  */
HWTEST_F(NapiBasicTest, NapiGetInstanceDataTest001, testing::ext::TestSize.Level1)9235 HWTEST_F(NapiBasicTest, NapiGetInstanceDataTest001, testing::ext::TestSize.Level1)
9236 {
9237     ASSERT_NE(engine_, nullptr);
9238     napi_env env = reinterpret_cast<napi_env>(engine_);
9239 
9240     auto res = napi_get_instance_data(env, nullptr);
9241     ASSERT_EQ(res, napi_invalid_arg);
9242 }
9243 
9244 /**
9245  * @tc.name: NapiAddEnvCleanupHookTest
9246  * @tc.desc: Test interface of napi_add_env_cleanup_hook
9247  * @tc.type: FUNC
9248  */
HWTEST_F(NapiBasicTest, NapiAddEnvCleanupHookTest001, testing::ext::TestSize.Level1)9249 HWTEST_F(NapiBasicTest, NapiAddEnvCleanupHookTest001, testing::ext::TestSize.Level1)
9250 {
9251     auto res = napi_add_env_cleanup_hook(nullptr, nullptr, nullptr);
9252     ASSERT_EQ(res, napi_invalid_arg);
9253 }
9254 
9255 /**
9256  * @tc.name: NapiAddEnvCleanupHookTest
9257  * @tc.desc: Test interface of napi_add_env_cleanup_hook
9258  * @tc.type: FUNC
9259  */
HWTEST_F(NapiBasicTest, NapiAddEnvCleanupHookTest002, testing::ext::TestSize.Level1)9260 HWTEST_F(NapiBasicTest, NapiAddEnvCleanupHookTest002, testing::ext::TestSize.Level1)
9261 {
9262     ASSERT_NE(engine_, nullptr);
9263     napi_env env = reinterpret_cast<napi_env>(engine_);
9264 
9265     auto res = napi_add_env_cleanup_hook(env, nullptr, nullptr);
9266     ASSERT_EQ(res, napi_invalid_arg);
9267 }
9268 
9269 /**
9270  * @tc.name: NapiRemoveEnvCleanupHookTest
9271  * @tc.desc: Test interface of napi_remove_env_cleanup_hook
9272  * @tc.type: FUNC
9273  */
HWTEST_F(NapiBasicTest, NapiRemoveEnvCleanupHookTest001, testing::ext::TestSize.Level1)9274 HWTEST_F(NapiBasicTest, NapiRemoveEnvCleanupHookTest001, testing::ext::TestSize.Level1)
9275 {
9276     auto res = napi_remove_env_cleanup_hook(nullptr, nullptr, nullptr);
9277     ASSERT_EQ(res, napi_invalid_arg);
9278 }
9279 
9280 /**
9281  * @tc.name: NapiRemoveEnvCleanupHookTest
9282  * @tc.desc: Test interface of napi_remove_env_cleanup_hook
9283  * @tc.type: FUNC
9284  */
HWTEST_F(NapiBasicTest, NapiRemoveEnvCleanupHookTest002, testing::ext::TestSize.Level1)9285 HWTEST_F(NapiBasicTest, NapiRemoveEnvCleanupHookTest002, testing::ext::TestSize.Level1)
9286 {
9287     ASSERT_NE(engine_, nullptr);
9288     napi_env env = reinterpret_cast<napi_env>(engine_);
9289 
9290     auto res = napi_remove_env_cleanup_hook(env, nullptr, nullptr);
9291     ASSERT_EQ(res, napi_invalid_arg);
9292 }
9293 
9294 /**
9295  * @tc.name: NapiAddAsyncCleanupHookTest
9296  * @tc.desc: Test interface of napi_add_async_cleanup_hook
9297  * @tc.type: FUNC
9298  */
HWTEST_F(NapiBasicTest, NapiAddAsyncCleanupHookTest001, testing::ext::TestSize.Level1)9299 HWTEST_F(NapiBasicTest, NapiAddAsyncCleanupHookTest001, testing::ext::TestSize.Level1)
9300 {
9301     auto res = napi_add_async_cleanup_hook(nullptr, nullptr, nullptr, nullptr);
9302     ASSERT_EQ(res, napi_invalid_arg);
9303 }
9304 
9305 /**
9306  * @tc.name: NapiAddAsyncCleanupHookTest
9307  * @tc.desc: Test interface of napi_add_async_cleanup_hook
9308  * @tc.type: FUNC
9309  */
HWTEST_F(NapiBasicTest, NapiAddAsyncCleanupHookTest002, testing::ext::TestSize.Level1)9310 HWTEST_F(NapiBasicTest, NapiAddAsyncCleanupHookTest002, testing::ext::TestSize.Level1)
9311 {
9312     ASSERT_NE(engine_, nullptr);
9313     napi_env env = reinterpret_cast<napi_env>(engine_);
9314 
9315     auto res = napi_add_async_cleanup_hook(env, nullptr, nullptr, nullptr);
9316     ASSERT_EQ(res, napi_invalid_arg);
9317 }
9318 
9319 /**
9320  * @tc.name: NapiRemoveAsyncCleanupHookTest
9321  * @tc.desc: Test interface of napi_remove_async_cleanup_hook
9322  * @tc.type: FUNC
9323  */
HWTEST_F(NapiBasicTest, NapiRemoveAsyncCleanupHookTest001, testing::ext::TestSize.Level1)9324 HWTEST_F(NapiBasicTest, NapiRemoveAsyncCleanupHookTest001, testing::ext::TestSize.Level1)
9325 {
9326     auto res = napi_remove_async_cleanup_hook(nullptr);
9327     ASSERT_EQ(res, napi_invalid_arg);
9328 }
9329 
9330 /**
9331  * @tc.name: NodeApiGetModuleFileNameTest
9332  * @tc.desc: Test interface of node_api_get_module_file_name
9333  * @tc.type: FUNC
9334  */
HWTEST_F(NapiBasicTest, NodeApiGetModuleFileNameTest001, testing::ext::TestSize.Level1)9335 HWTEST_F(NapiBasicTest, NodeApiGetModuleFileNameTest001, testing::ext::TestSize.Level1)
9336 {
9337     auto res = node_api_get_module_file_name(nullptr, nullptr);
9338     ASSERT_EQ(res, napi_invalid_arg);
9339 }
9340 
9341 /**
9342  * @tc.name: NodeApiGetModuleFileNameTest
9343  * @tc.desc: Test interface of node_api_get_module_file_name
9344  * @tc.type: FUNC
9345  */
HWTEST_F(NapiBasicTest, NodeApiGetModuleFileNameTest002, testing::ext::TestSize.Level1)9346 HWTEST_F(NapiBasicTest, NodeApiGetModuleFileNameTest002, testing::ext::TestSize.Level1)
9347 {
9348     ASSERT_NE(engine_, nullptr);
9349     napi_env env = reinterpret_cast<napi_env>(engine_);
9350 
9351     auto res = node_api_get_module_file_name(env, nullptr);
9352     ASSERT_EQ(res, napi_invalid_arg);
9353 }
9354 
9355 /**
9356  * @tc.name: NapiAddFinalizerTest
9357  * @tc.desc: Test interface of napi_add_finalizer
9358  * @tc.type: FUNC
9359  */
HWTEST_F(NapiBasicTest, NapiAddFinalizerTest001, testing::ext::TestSize.Level1)9360 HWTEST_F(NapiBasicTest, NapiAddFinalizerTest001, testing::ext::TestSize.Level1)
9361 {
9362     auto res = napi_add_finalizer(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
9363     ASSERT_EQ(res, napi_invalid_arg);
9364 }
9365 
9366 /**
9367  * @tc.name: NapiAddFinalizerTest
9368  * @tc.desc: Test interface of napi_add_finalizer
9369  * @tc.type: FUNC
9370  */
HWTEST_F(NapiBasicTest, NapiAddFinalizerTest002, testing::ext::TestSize.Level1)9371 HWTEST_F(NapiBasicTest, NapiAddFinalizerTest002, testing::ext::TestSize.Level1)
9372 {
9373     ASSERT_NE(engine_, nullptr);
9374     napi_env env = reinterpret_cast<napi_env>(engine_);
9375 
9376     auto res = napi_add_finalizer(env, nullptr, nullptr, nullptr, nullptr, nullptr);
9377     ASSERT_EQ(res, napi_invalid_arg);
9378 }
9379 
9380 /**
9381  * @tc.name: NapiAddFinalizerTest
9382  * @tc.desc: Test interface of napi_add_finalizer
9383  * @tc.type: FUNC
9384  */
HWTEST_F(NapiBasicTest, NapiAddFinalizerTest003, testing::ext::TestSize.Level1)9385 HWTEST_F(NapiBasicTest, NapiAddFinalizerTest003, testing::ext::TestSize.Level1)
9386 {
9387     ASSERT_NE(engine_, nullptr);
9388     napi_env env = reinterpret_cast<napi_env>(engine_);
9389 
9390     napi_value boolean = nullptr;
9391     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
9392     auto res = napi_add_finalizer(env, boolean, nullptr, nullptr, nullptr, nullptr);
9393     ASSERT_EQ(res, napi_invalid_arg);
9394 }
9395 
9396 /**
9397  * @tc.name: NapiAddFinalizerTest
9398  * @tc.desc: Test interface of napi_add_finalizer
9399  * @tc.type: FUNC
9400  */
HWTEST_F(NapiBasicTest, NapiAddFinalizerTest004, testing::ext::TestSize.Level1)9401 HWTEST_F(NapiBasicTest, NapiAddFinalizerTest004, testing::ext::TestSize.Level1)
9402 {
9403     ASSERT_NE(engine_, nullptr);
9404     napi_env env = reinterpret_cast<napi_env>(engine_);
9405 
9406     napi_value boolean = nullptr;
9407     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
9408     auto res = napi_add_finalizer(env, boolean, nullptr, TestFinalizer, nullptr, nullptr);
9409     ASSERT_EQ(res, napi_object_expected);
9410 }
9411 
9412 /**
9413  * @tc.name: NapiQueueAsyncWorkWithQosTest
9414  * @tc.desc: Test interface of napi_queue_async_work_with_qos
9415  * @tc.type: FUNC
9416  */
HWTEST_F(NapiBasicTest, NapiQueueAsyncWorkWithQosTest001, testing::ext::TestSize.Level1)9417 HWTEST_F(NapiBasicTest, NapiQueueAsyncWorkWithQosTest001, testing::ext::TestSize.Level1)
9418 {
9419     auto res = napi_queue_async_work_with_qos(nullptr, nullptr, napi_qos_default);
9420     ASSERT_EQ(res, napi_invalid_arg);
9421 }
9422 
9423 /**
9424  * @tc.name: NapiQueueAsyncWorkWithQosTest
9425  * @tc.desc: Test interface of napi_queue_async_work_with_qos
9426  * @tc.type: FUNC
9427  */
HWTEST_F(NapiBasicTest, NapiQueueAsyncWorkWithQosTest002, testing::ext::TestSize.Level1)9428 HWTEST_F(NapiBasicTest, NapiQueueAsyncWorkWithQosTest002, testing::ext::TestSize.Level1)
9429 {
9430     ASSERT_NE(engine_, nullptr);
9431     napi_env env = reinterpret_cast<napi_env>(engine_);
9432 
9433     auto res = napi_queue_async_work_with_qos(env, nullptr, napi_qos_default);
9434     ASSERT_EQ(res, napi_invalid_arg);
9435 }
9436 
9437 /**
9438  * @tc.name: NapiQueueAsyncWorkWithQosTest
9439  * @tc.desc: Test interface of napi_queue_async_work_with_qos
9440  * @tc.type: FUNC
9441  */
HWTEST_F(NapiBasicTest, NapiQueueAsyncWorkWithQosTest003, testing::ext::TestSize.Level1)9442 HWTEST_F(NapiBasicTest, NapiQueueAsyncWorkWithQosTest003, testing::ext::TestSize.Level1)
9443 {
9444     ASSERT_NE(engine_, nullptr);
9445     napi_env env = reinterpret_cast<napi_env>(engine_);
9446 
9447     struct AsyncWorkContext {
9448         napi_async_work work = nullptr;
9449     };
9450     auto asyncWorkContext = new AsyncWorkContext();
9451     napi_value resourceName = nullptr;
9452     napi_create_string_utf8(env, TEST_CHAR_STRING, NAPI_AUTO_LENGTH, &resourceName);
9453     ASSERT_CHECK_CALL(napi_create_async_work(
9454         env, nullptr, resourceName, [](napi_env value, void* data) {},
9455         [](napi_env env, napi_status status, void* data) {
9456             AsyncWorkContext* asyncWorkContext = (AsyncWorkContext*)data;
9457             ASSERT_CHECK_CALL(napi_delete_async_work(env, asyncWorkContext->work));
9458             delete asyncWorkContext;
9459             STOP_EVENT_LOOP(env);
9460         },
9461         asyncWorkContext, &asyncWorkContext->work));
9462 
9463     auto res = napi_queue_async_work_with_qos(env, asyncWorkContext->work, napi_qos_default);
9464     ASSERT_EQ(res, napi_ok);
9465     RUN_EVENT_LOOP(env);
9466 }
9467 
9468 /**
9469  * @tc.name: NapiRunScriptPathTest
9470  * @tc.desc: Test interface of napi_run_script_path
9471  * @tc.type: FUNC
9472  */
HWTEST_F(NapiBasicTest, NapiRunScriptPathTest001, testing::ext::TestSize.Level1)9473 HWTEST_F(NapiBasicTest, NapiRunScriptPathTest001, testing::ext::TestSize.Level1)
9474 {
9475     auto res = napi_run_script_path(nullptr, nullptr, nullptr);
9476     ASSERT_EQ(res, napi_invalid_arg);
9477 }
9478 
9479 /**
9480  * @tc.name: NapiRunScriptPathTest
9481  * @tc.desc: Test interface of napi_run_script_path
9482  * @tc.type: FUNC
9483  */
HWTEST_F(NapiBasicTest, NapiRunScriptPathTest002, testing::ext::TestSize.Level1)9484 HWTEST_F(NapiBasicTest, NapiRunScriptPathTest002, testing::ext::TestSize.Level1)
9485 {
9486     ASSERT_NE(engine_, nullptr);
9487     napi_env env = reinterpret_cast<napi_env>(engine_);
9488 
9489     auto res = napi_run_script_path(env, nullptr, nullptr);
9490     ASSERT_EQ(res, napi_invalid_arg);
9491 }
9492 
9493 /**
9494  * @tc.name: NapiRunScriptPathTest
9495  * @tc.desc: Test interface of napi_run_script_path
9496  * @tc.type: FUNC
9497  */
HWTEST_F(NapiBasicTest, NapiRunScriptPathTest003, testing::ext::TestSize.Level1)9498 HWTEST_F(NapiBasicTest, NapiRunScriptPathTest003, testing::ext::TestSize.Level1)
9499 {
9500     ASSERT_NE(engine_, nullptr);
9501     napi_env env = reinterpret_cast<napi_env>(engine_);
9502 
9503     napi_value result = nullptr;
9504     auto res = napi_run_script_path(env, TEST_CHAR_STRING, &result);
9505     ASSERT_EQ(res, napi_ok);
9506 }
9507 
9508 /**
9509  * @tc.name: NapiLoadModuleTest
9510  * @tc.desc: Test interface of napi_load_module
9511  * @tc.type: FUNC
9512  */
HWTEST_F(NapiBasicTest, NapiLoadModuleTest001, testing::ext::TestSize.Level1)9513 HWTEST_F(NapiBasicTest, NapiLoadModuleTest001, testing::ext::TestSize.Level1)
9514 {
9515     auto res = napi_load_module(nullptr, nullptr, nullptr);
9516     ASSERT_EQ(res, napi_invalid_arg);
9517 }
9518 
9519 /**
9520  * @tc.name: NapiLoadModuleTest
9521  * @tc.desc: Test interface of napi_load_module
9522  * @tc.type: FUNC
9523  */
HWTEST_F(NapiBasicTest, NapiLoadModuleTest002, testing::ext::TestSize.Level1)9524 HWTEST_F(NapiBasicTest, NapiLoadModuleTest002, testing::ext::TestSize.Level1)
9525 {
9526     ASSERT_NE(engine_, nullptr);
9527     napi_env env = reinterpret_cast<napi_env>(engine_);
9528 
9529     auto res = napi_load_module(env, nullptr, nullptr);
9530     ASSERT_EQ(res, napi_invalid_arg);
9531 }
9532 
9533 /**
9534  * @tc.name: NapiLoadModuleTest
9535  * @tc.desc: Test interface of napi_load_module
9536  * @tc.type: FUNC
9537  */
HWTEST_F(NapiBasicTest, NapiLoadModuleTest003, testing::ext::TestSize.Level1)9538 HWTEST_F(NapiBasicTest, NapiLoadModuleTest003, testing::ext::TestSize.Level1)
9539 {
9540     ASSERT_NE(engine_, nullptr);
9541     napi_env env = reinterpret_cast<napi_env>(engine_);
9542 
9543     napi_value result = nullptr;
9544     auto res = napi_load_module(env, nullptr, &result);
9545     ASSERT_EQ(res, napi_ok);
9546 }
9547 
9548 /**
9549  * @tc.name: NapiCreateObjectWithPropertiesTest
9550  * @tc.desc: Test interface of napi_create_object_with_properties
9551  * @tc.type: FUNC
9552  */
HWTEST_F(NapiBasicTest, NapiCreateObjectWithPropertiesTest001, testing::ext::TestSize.Level1)9553 HWTEST_F(NapiBasicTest, NapiCreateObjectWithPropertiesTest001, testing::ext::TestSize.Level1)
9554 {
9555     auto res = napi_create_object_with_properties(nullptr, nullptr, 0, nullptr);
9556     ASSERT_EQ(res, napi_invalid_arg);
9557 }
9558 
9559 /**
9560  * @tc.name: NapiCreateObjectWithPropertiesTest
9561  * @tc.desc: Test interface of napi_create_object_with_properties
9562  * @tc.type: FUNC
9563  */
HWTEST_F(NapiBasicTest, NapiCreateObjectWithPropertiesTest002, testing::ext::TestSize.Level1)9564 HWTEST_F(NapiBasicTest, NapiCreateObjectWithPropertiesTest002, testing::ext::TestSize.Level1)
9565 {
9566     ASSERT_NE(engine_, nullptr);
9567     napi_env env = reinterpret_cast<napi_env>(engine_);
9568 
9569     auto res = napi_create_object_with_properties(env, nullptr, 0, nullptr);
9570     ASSERT_EQ(res, napi_invalid_arg);
9571 }
9572 
9573 /**
9574  * @tc.name: NapiCreateObjectWithNamedPropertiesTest
9575  * @tc.desc: Test interface of napi_create_object_with_named_properties
9576  * @tc.type: FUNC
9577  */
HWTEST_F(NapiBasicTest, NapiCreateObjectWithNamedPropertiesTest001, testing::ext::TestSize.Level1)9578 HWTEST_F(NapiBasicTest, NapiCreateObjectWithNamedPropertiesTest001, testing::ext::TestSize.Level1)
9579 {
9580     auto res = napi_create_object_with_named_properties(nullptr, nullptr, 0, nullptr, nullptr);
9581     ASSERT_EQ(res, napi_invalid_arg);
9582 }
9583 
9584 /**
9585  * @tc.name: NapiCreateObjectWithNamedPropertiesTest
9586  * @tc.desc: Test interface of napi_create_object_with_named_properties
9587  * @tc.type: FUNC
9588  */
HWTEST_F(NapiBasicTest, NapiCreateObjectWithNamedPropertiesTest002, testing::ext::TestSize.Level1)9589 HWTEST_F(NapiBasicTest, NapiCreateObjectWithNamedPropertiesTest002, testing::ext::TestSize.Level1)
9590 {
9591     ASSERT_NE(engine_, nullptr);
9592     napi_env env = reinterpret_cast<napi_env>(engine_);
9593 
9594     auto res = napi_create_object_with_named_properties(env, nullptr, 0, nullptr, nullptr);
9595     ASSERT_EQ(res, napi_invalid_arg);
9596 }
9597 
9598 /**
9599  * @tc.name: NapiCoerceToNativeBindingObjectTest
9600  * @tc.desc: Test interface of napi_coerce_to_native_binding_object
9601  * @tc.type: FUNC
9602  */
HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest001, testing::ext::TestSize.Level1)9603 HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest001, testing::ext::TestSize.Level1)
9604 {
9605     auto res = napi_coerce_to_native_binding_object(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
9606     ASSERT_EQ(res, napi_invalid_arg);
9607 }
9608 
9609 /**
9610  * @tc.name: NapiCoerceToNativeBindingObjectTest
9611  * @tc.desc: Test interface of napi_coerce_to_native_binding_object
9612  * @tc.type: FUNC
9613  */
HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest002, testing::ext::TestSize.Level1)9614 HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest002, testing::ext::TestSize.Level1)
9615 {
9616     ASSERT_NE(engine_, nullptr);
9617     napi_env env = reinterpret_cast<napi_env>(engine_);
9618 
9619     auto res = napi_coerce_to_native_binding_object(env, nullptr, nullptr, nullptr, nullptr, nullptr);
9620     ASSERT_EQ(res, napi_invalid_arg);
9621 }
9622 
9623 /**
9624  * @tc.name: NapiCoerceToNativeBindingObjectTest
9625  * @tc.desc: Test interface of napi_coerce_to_native_binding_object
9626  * @tc.type: FUNC
9627  */
HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest003, testing::ext::TestSize.Level1)9628 HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest003, testing::ext::TestSize.Level1)
9629 {
9630     ASSERT_NE(engine_, nullptr);
9631     napi_env env = reinterpret_cast<napi_env>(engine_);
9632 
9633     napi_value object = nullptr;
9634     ASSERT_CHECK_CALL(napi_create_object(env, &object));
9635     auto res = napi_coerce_to_native_binding_object(env, object, nullptr, nullptr, nullptr, nullptr);
9636     ASSERT_EQ(res, napi_invalid_arg);
9637 }
9638 
9639 /**
9640  * @tc.name: NapiCoerceToNativeBindingObjectTest
9641  * @tc.desc: Test interface of napi_coerce_to_native_binding_object
9642  * @tc.type: FUNC
9643  */
HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest004, testing::ext::TestSize.Level1)9644 HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest004, testing::ext::TestSize.Level1)
9645 {
9646     ASSERT_NE(engine_, nullptr);
9647     napi_env env = reinterpret_cast<napi_env>(engine_);
9648 
9649     napi_value object = nullptr;
9650     ASSERT_CHECK_CALL(napi_create_object(env, &object));
9651     auto res = napi_coerce_to_native_binding_object(env, object, TestDetachCallback, nullptr, nullptr, nullptr);
9652     ASSERT_EQ(res, napi_invalid_arg);
9653 }
9654 
9655 /**
9656  * @tc.name: NapiCoerceToNativeBindingObjectTest
9657  * @tc.desc: Test interface of napi_coerce_to_native_binding_object
9658  * @tc.type: FUNC
9659  */
HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest005, testing::ext::TestSize.Level1)9660 HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest005, testing::ext::TestSize.Level1)
9661 {
9662     ASSERT_NE(engine_, nullptr);
9663     napi_env env = reinterpret_cast<napi_env>(engine_);
9664 
9665     napi_value object = nullptr;
9666     ASSERT_CHECK_CALL(napi_create_object(env, &object));
9667     auto res = napi_coerce_to_native_binding_object(env, object, TestDetachCallback, TestAttachCallback,
9668         nullptr, nullptr);
9669     ASSERT_EQ(res, napi_invalid_arg);
9670 }
9671 
9672 /**
9673  * @tc.name: NapiCoerceToNativeBindingObjectTest
9674  * @tc.desc: Test interface of napi_coerce_to_native_binding_object
9675  * @tc.type: FUNC
9676  */
HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest006, testing::ext::TestSize.Level1)9677 HWTEST_F(NapiBasicTest, NapiCoerceToNativeBindingObjectTest006, testing::ext::TestSize.Level1)
9678 {
9679     ASSERT_NE(engine_, nullptr);
9680     napi_env env = reinterpret_cast<napi_env>(engine_);
9681 
9682     napi_value object = nullptr;
9683     ASSERT_CHECK_CALL(napi_create_object(env, &object));
9684     auto res = napi_coerce_to_native_binding_object(env, object, TestDetachCallback, TestAttachCallback,
9685         reinterpret_cast<void*>(object), nullptr);
9686     ASSERT_EQ(res, napi_ok);
9687 }
9688 
9689 /**
9690  * @tc.name: NapiCreateArkRuntimeTest
9691  * @tc.desc: Test interface of napi_create_ark_runtime
9692  * @tc.type: FUNC
9693  */
HWTEST_F(NapiBasicTest, NapiCreateArkRuntimeTest001, testing::ext::TestSize.Level1)9694 HWTEST_F(NapiBasicTest, NapiCreateArkRuntimeTest001, testing::ext::TestSize.Level1)
9695 {
9696     auto res = napi_create_ark_runtime(nullptr);
9697     ASSERT_EQ(res, napi_invalid_arg);
9698 }
9699 
9700 /**
9701  * @tc.name: NapiCreateArkRuntimeTest
9702  * @tc.desc: Test interface of napi_create_ark_runtime
9703  * @tc.type: FUNC
9704  */
HWTEST_F(NapiBasicTest, NapiCreateArkRuntimeTest002, testing::ext::TestSize.Level1)9705 HWTEST_F(NapiBasicTest, NapiCreateArkRuntimeTest002, testing::ext::TestSize.Level1)
9706 {
9707     auto temp = NativeCreateEnv::g_createNapiEnvCallback;
9708     NativeCreateEnv::g_createNapiEnvCallback = nullptr;
9709     auto res = napi_create_ark_runtime(nullptr);
9710     NativeCreateEnv::g_createNapiEnvCallback = temp;
9711     ASSERT_EQ(res, napi_invalid_arg);
9712 }
9713 
9714 /**
9715  * @tc.name: NapiDestroyArkRuntimeTest
9716  * @tc.desc: Test interface of napi_destroy_ark_runtime
9717  * @tc.type: FUNC
9718  */
HWTEST_F(NapiBasicTest, NapiDestroyArkRuntimeTest001, testing::ext::TestSize.Level1)9719 HWTEST_F(NapiBasicTest, NapiDestroyArkRuntimeTest001, testing::ext::TestSize.Level1)
9720 {
9721     auto res = napi_destroy_ark_runtime(nullptr);
9722     ASSERT_EQ(res, napi_invalid_arg);
9723 }
9724 
9725 /**
9726  * @tc.name: NapiDestroyArkRuntimeTest
9727  * @tc.desc: Test interface of napi_destroy_ark_runtime
9728  * @tc.type: FUNC
9729  */
HWTEST_F(NapiBasicTest, NapiDestroyArkRuntimeTest002, testing::ext::TestSize.Level1)9730 HWTEST_F(NapiBasicTest, NapiDestroyArkRuntimeTest002, testing::ext::TestSize.Level1)
9731 {
9732     auto temp = NativeCreateEnv::g_destroyNapiEnvCallback;
9733     NativeCreateEnv::g_destroyNapiEnvCallback = nullptr;
9734     auto res = napi_destroy_ark_runtime(nullptr);
9735     NativeCreateEnv::g_destroyNapiEnvCallback = temp;
9736     ASSERT_EQ(res, napi_invalid_arg);
9737 }
9738 
9739 /**
9740  * @tc.name: NapiRunEventLoopTest
9741  * @tc.desc: Test interface of napi_run_event_loop
9742  * @tc.type: FUNC
9743  */
HWTEST_F(NapiBasicTest, NapiRunEventLoopTest001, testing::ext::TestSize.Level1)9744 HWTEST_F(NapiBasicTest, NapiRunEventLoopTest001, testing::ext::TestSize.Level1)
9745 {
9746     auto res = napi_run_event_loop(nullptr, napi_event_mode_default);
9747     ASSERT_EQ(res, napi_invalid_arg);
9748 }
9749 
9750 /**
9751  * @tc.name: NapiRunEventLoopTest
9752  * @tc.desc: Test interface of napi_run_event_loop
9753  * @tc.type: FUNC
9754  */
HWTEST_F(NapiBasicTest, NapiRunEventLoopTest002, testing::ext::TestSize.Level1)9755 HWTEST_F(NapiBasicTest, NapiRunEventLoopTest002, testing::ext::TestSize.Level1)
9756 {
9757     ASSERT_NE(engine_, nullptr);
9758     napi_env env = reinterpret_cast<napi_env>(engine_);
9759 
9760     auto res = napi_run_event_loop(env, (napi_event_mode)(napi_event_mode_default - 1));
9761     ASSERT_EQ(res, napi_invalid_arg);
9762 }
9763 
9764 /**
9765  * @tc.name: NapiStopEventLoopTest
9766  * @tc.desc: Test interface of napi_stop_event_loop
9767  * @tc.type: FUNC
9768  */
HWTEST_F(NapiBasicTest, NapiStopEventLoopTest001, testing::ext::TestSize.Level1)9769 HWTEST_F(NapiBasicTest, NapiStopEventLoopTest001, testing::ext::TestSize.Level1)
9770 {
9771     auto res = napi_stop_event_loop(nullptr);
9772     ASSERT_EQ(res, napi_invalid_arg);
9773 }
9774 
9775 /**
9776  * @tc.name: NapiLoadModuleWithInfoTest
9777  * @tc.desc: Test interface of napi_load_module_with_info
9778  * @tc.type: FUNC
9779  */
HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoTest001, testing::ext::TestSize.Level1)9780 HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoTest001, testing::ext::TestSize.Level1)
9781 {
9782     auto res = napi_load_module_with_info(nullptr, nullptr, nullptr, nullptr);
9783     ASSERT_EQ(res, napi_invalid_arg);
9784 }
9785 
9786 /**
9787  * @tc.name: NapiLoadModuleWithInfoTest
9788  * @tc.desc: Test interface of napi_load_module_with_info
9789  * @tc.type: FUNC
9790  */
HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoTest002, testing::ext::TestSize.Level1)9791 HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoTest002, testing::ext::TestSize.Level1)
9792 {
9793     ASSERT_NE(engine_, nullptr);
9794     napi_env env = reinterpret_cast<napi_env>(engine_);
9795 
9796     auto res = napi_load_module_with_info(env, nullptr, nullptr, nullptr);
9797     ASSERT_EQ(res, napi_invalid_arg);
9798 }
9799 
9800 /**
9801  * @tc.name: NapiLoadModuleWithInfoTest
9802  * @tc.desc: Test interface of napi_load_module_with_info
9803  * @tc.type: FUNC
9804  */
HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoTest003, testing::ext::TestSize.Level1)9805 HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoTest003, testing::ext::TestSize.Level1)
9806 {
9807     ASSERT_NE(engine_, nullptr);
9808     napi_env env = reinterpret_cast<napi_env>(engine_);
9809 
9810     napi_value result = nullptr;
9811     auto res = napi_load_module_with_info(env, nullptr, nullptr, &result);
9812     ASSERT_EQ(res, napi_ok);
9813 }
9814 
9815 /**
9816  * @tc.name: NapiSerializeTest
9817  * @tc.desc: Test interface of napi_serialize
9818  * @tc.type: FUNC
9819  */
HWTEST_F(NapiBasicTest, NapiSerializeTest001, testing::ext::TestSize.Level1)9820 HWTEST_F(NapiBasicTest, NapiSerializeTest001, testing::ext::TestSize.Level1)
9821 {
9822     auto res = napi_serialize(nullptr, nullptr, nullptr, nullptr, nullptr);
9823     ASSERT_EQ(res, napi_invalid_arg);
9824 }
9825 
9826 /**
9827  * @tc.name: NapiSerializeTest
9828  * @tc.desc: Test interface of napi_serialize
9829  * @tc.type: FUNC
9830  */
HWTEST_F(NapiBasicTest, NapiSerializeTest002, testing::ext::TestSize.Level1)9831 HWTEST_F(NapiBasicTest, NapiSerializeTest002, testing::ext::TestSize.Level1)
9832 {
9833     ASSERT_NE(engine_, nullptr);
9834     napi_env env = reinterpret_cast<napi_env>(engine_);
9835 
9836     auto res = napi_serialize(env, nullptr, nullptr, nullptr, nullptr);
9837     ASSERT_EQ(res, napi_invalid_arg);
9838 }
9839 
9840 /**
9841  * @tc.name: NapiSerializeTest
9842  * @tc.desc: Test interface of napi_serialize
9843  * @tc.type: FUNC
9844  */
HWTEST_F(NapiBasicTest, NapiSerializeTest003, testing::ext::TestSize.Level1)9845 HWTEST_F(NapiBasicTest, NapiSerializeTest003, testing::ext::TestSize.Level1)
9846 {
9847     ASSERT_NE(engine_, nullptr);
9848     napi_env env = reinterpret_cast<napi_env>(engine_);
9849 
9850     napi_value num = nullptr;
9851     ASSERT_CHECK_CALL(napi_create_uint32(env, TEST_UINT32_1000, &num));
9852     auto res = napi_serialize(env, num, nullptr, nullptr, nullptr);
9853     ASSERT_EQ(res, napi_invalid_arg);
9854 }
9855 
9856 /**
9857  * @tc.name: NapiSerializeTest
9858  * @tc.desc: Test interface of napi_serialize
9859  * @tc.type: FUNC
9860  */
HWTEST_F(NapiBasicTest, NapiSerializeTest004, testing::ext::TestSize.Level1)9861 HWTEST_F(NapiBasicTest, NapiSerializeTest004, testing::ext::TestSize.Level1)
9862 {
9863     ASSERT_NE(engine_, nullptr);
9864     napi_env env = reinterpret_cast<napi_env>(engine_);
9865 
9866     napi_value num = nullptr;
9867     ASSERT_CHECK_CALL(napi_create_uint32(env, TEST_UINT32_1000, &num));
9868     napi_value undefined = nullptr;
9869     ASSERT_CHECK_CALL(napi_get_undefined(env, &undefined));
9870     auto res = napi_serialize(env, num, undefined, nullptr, nullptr);
9871     ASSERT_EQ(res, napi_invalid_arg);
9872 }
9873 
9874 /**
9875  * @tc.name: NapiSerializeTest
9876  * @tc.desc: Test interface of napi_serialize
9877  * @tc.type: FUNC
9878  */
HWTEST_F(NapiBasicTest, NapiSerializeTest005, testing::ext::TestSize.Level1)9879 HWTEST_F(NapiBasicTest, NapiSerializeTest005, testing::ext::TestSize.Level1)
9880 {
9881     ASSERT_NE(engine_, nullptr);
9882     napi_env env = reinterpret_cast<napi_env>(engine_);
9883 
9884     napi_value num = nullptr;
9885     ASSERT_CHECK_CALL(napi_create_uint32(env, TEST_UINT32_1000, &num));
9886     napi_value undefined = nullptr;
9887     ASSERT_CHECK_CALL(napi_get_undefined(env, &undefined));
9888     auto res = napi_serialize(env, num, undefined, undefined, nullptr);
9889     ASSERT_EQ(res, napi_invalid_arg);
9890 }
9891 
9892 /**
9893  * @tc.name: NapiSerializeTest
9894  * @tc.desc: Test interface of napi_serialize
9895  * @tc.type: FUNC
9896  */
HWTEST_F(NapiBasicTest, NapiSerializeTest006, testing::ext::TestSize.Level1)9897 HWTEST_F(NapiBasicTest, NapiSerializeTest006, testing::ext::TestSize.Level1)
9898 {
9899     ASSERT_NE(engine_, nullptr);
9900     napi_env env = reinterpret_cast<napi_env>(engine_);
9901 
9902     napi_value num = nullptr;
9903     ASSERT_CHECK_CALL(napi_create_uint32(env, TEST_UINT32_1000, &num));
9904     napi_value boolean = nullptr;
9905     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
9906     void* data = nullptr;
9907     auto res = napi_serialize(env, num, boolean, boolean, &data);
9908     ASSERT_EQ(res, napi_invalid_arg);
9909 }
9910 
9911 /**
9912  * @tc.name: NapiSerializeTest
9913  * @tc.desc: Test interface of napi_serialize
9914  * @tc.type: FUNC
9915  */
HWTEST_F(NapiBasicTest, NapiSerializeTest007, testing::ext::TestSize.Level1)9916 HWTEST_F(NapiBasicTest, NapiSerializeTest007, testing::ext::TestSize.Level1)
9917 {
9918     ASSERT_NE(engine_, nullptr);
9919     napi_env env = reinterpret_cast<napi_env>(engine_);
9920 
9921     napi_value num = nullptr;
9922     ASSERT_CHECK_CALL(napi_create_uint32(env, TEST_UINT32_1000, &num));
9923     napi_value undefined = nullptr;
9924     ASSERT_CHECK_CALL(napi_get_undefined(env, &undefined));
9925     napi_value boolean = nullptr;
9926     ASSERT_CHECK_CALL(napi_get_boolean(env, true, &boolean));
9927     void* data = nullptr;
9928     auto res = napi_serialize(env, num, undefined, boolean, &data);
9929     ASSERT_EQ(res, napi_invalid_arg);
9930 }
9931 
9932 /**
9933  * @tc.name: NapiSerializeTest
9934  * @tc.desc: Test interface of napi_serialize
9935  * @tc.type: FUNC
9936  */
HWTEST_F(NapiBasicTest, NapiSerializeTest008, testing::ext::TestSize.Level1)9937 HWTEST_F(NapiBasicTest, NapiSerializeTest008, testing::ext::TestSize.Level1)
9938 {
9939     ASSERT_NE(engine_, nullptr);
9940     napi_env env = reinterpret_cast<napi_env>(engine_);
9941 
9942     napi_value num = nullptr;
9943     ASSERT_CHECK_CALL(napi_create_uint32(env, TEST_UINT32_1000, &num));
9944     napi_value undefined = nullptr;
9945     ASSERT_CHECK_CALL(napi_get_undefined(env, &undefined));
9946     void* data = nullptr;
9947     auto res = napi_serialize(env, num, undefined, undefined, &data);
9948     ASSERT_EQ(res, napi_ok);
9949 }
9950 
9951 /**
9952  * @tc.name: NapiEncodeTest
9953  * @tc.desc: Test interface of napi_encode
9954  * @tc.type: FUNC
9955  */
HWTEST_F(NapiBasicTest, NapiEncodeTest001, testing::ext::TestSize.Level1)9956 HWTEST_F(NapiBasicTest, NapiEncodeTest001, testing::ext::TestSize.Level1)
9957 {
9958     ASSERT_NE(engine_, nullptr);
9959     napi_env env = reinterpret_cast<napi_env>(engine_);
9960     const char testStr[] = "中测_Eng_123";
9961     size_t testStrLength = strlen(testStr);
9962     napi_value src = nullptr;
9963     ASSERT_CHECK_CALL(napi_create_string_utf8(env, testStr, testStrLength, &src));
9964 
9965     napi_value result = nullptr;
9966     ASSERT_CHECK_CALL(napi_encode(env, src, &result));
9967     char expected[15] = {0xe4, 0xb8, 0xad, 0xe6, 0xb5, 0x8b, 0x5f, 0x45, 0x6e, 0x67, 0x5f, 0x31, 0x32, 0x33, 0};
9968 
9969     napi_typedarray_type type;
9970     size_t srcLength = 0;
9971     void* srcData = nullptr;
9972     napi_value srcBuffer = nullptr;
9973     size_t byteOffset = 0;
9974 
9975     napi_get_typedarray_info(env, result, &type, &srcLength, &srcData, &srcBuffer, &byteOffset);
9976 
9977     ASSERT_EQ(srcLength, 14); // 14:string length
9978     char* res = reinterpret_cast<char*>(srcData);
9979 
9980     res[srcLength] = 0;
9981     ASSERT_STREQ(res, expected);
9982 }
9983 
9984 /**
9985  * @tc.name: NapiEncodeTest
9986  * @tc.desc: Test interface of napi_encode
9987  * @tc.type: FUNC
9988  */
HWTEST_F(NapiBasicTest, NapiEncodeTest002, testing::ext::TestSize.Level1)9989 HWTEST_F(NapiBasicTest, NapiEncodeTest002, testing::ext::TestSize.Level1)
9990 {
9991     ASSERT_NE(engine_, nullptr);
9992     napi_env env = reinterpret_cast<napi_env>(engine_);
9993 
9994     napi_value undefined = nullptr;
9995     ASSERT_CHECK_CALL(napi_get_undefined(env, &undefined));
9996 
9997     napi_value result = nullptr;
9998     auto ret = napi_encode(env, undefined, &result);
9999     ASSERT_EQ(ret, napi_string_expected);
10000 }
10001