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