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