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