1 /*
2 * Copyright (c) 2021 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 <cstdlib>
17 #include <cstring>
18 #include <iostream>
19 #include "client_stub.h"
20 #include "gtest/gtest.h"
21 #include "log.h"
22 #include "napi/native_api.h"
23 #include "napi/native_node_api.h"
24 #include "node_api.h"
25 #include "node_api_types.h"
26 #include "securec.h"
27 #include "update_client.h"
28 #include "update_helper.h"
29 #include "update_session.h"
30
31 using namespace updateClient;
32 using namespace std;
33 using namespace OHOS::update_engine;
34 static constexpr int NUMBER_2 = 2;
35
36 TestNApiValue g_callback(napi_function, nullptr);
37
38 uint32_t g_testSessionId = 0;
39 UpdateClient* g_testClient = nullptr;
40 static int32_t g_undefined = 100;
41 bool g_callbackFuncationCalled = false;
42
43 static UpdatePolicy g_updatePolicy = {
44 true,
45 true,
46 INSTALLMODE_AUTO,
47 AUTOUPGRADECONDITION_IDLE,
48 {1000, 1000}
49 };
50
51 TestNApiEnv g_testEnv;
52
CreateNapiValue(int type,const void * value)53 static napi_value CreateNapiValue(int type, const void *value)
54 {
55 auto testValue = new TestNApiValue(type, value);
56 g_testEnv.testValueList.push_back(testValue);
57 return (napi_value)testValue;
58 }
59
FreeAllNapiValues()60 void FreeAllNapiValues()
61 {
62 auto iter = g_testEnv.testValueList.begin();
63 while (iter != g_testEnv.testValueList.end()) {
64 auto value = *iter;
65 g_testEnv.testValueList.erase(iter);
66 delete value;
67 iter = g_testEnv.testValueList.begin();
68 }
69 }
70
TestNApiValue(int type,const void * value)71 TestNApiValue::TestNApiValue(int type, const void *value)
72 {
73 if (value == nullptr) {
74 return;
75 }
76 type_ = type;
77 switch (type) {
78 case napi_boolean:
79 bValue = *static_cast<bool*>(const_cast<void*>(value));
80 break;
81 case napi_number:
82 intValue = *static_cast<int*>(const_cast<void*>(value));
83 break;
84 case napi_string:
85 strValue = std::string(static_cast<char*>(const_cast<void*>(value)));
86 break;
87 case napi_bigint:
88 int64Value = *static_cast<int64_t*>(const_cast<void*>(value));
89 break;
90 default:
91 break;
92 }
93 }
94
TestGetUpdateSession()95 UpdateSession *TestGetUpdateSession()
96 {
97 printf(" TestGetUpdateSession g_testSessionId %u\n", g_testSessionId);
98 if (g_testClient != nullptr) {
99 return g_testClient->GetUpdateSession(g_testSessionId);
100 }
101 return nullptr;
102 }
103
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107
napi_create_string_utf8(napi_env env,const char * str,size_t length,napi_value * result)108 napi_status napi_create_string_utf8(napi_env env, const char *str, size_t length, napi_value *result)
109 {
110 if (result != nullptr) {
111 *result = CreateNapiValue(napi_string, str);
112 }
113 return napi_status::napi_ok;
114 }
115
napi_typeof(napi_env env,napi_value value,napi_valuetype * result)116 napi_status napi_typeof(napi_env env, napi_value value, napi_valuetype *result)
117 {
118 if ((reinterpret_cast<TestNApiValue*>(value)) == nullptr) {
119 return napi_status::napi_invalid_arg;
120 }
121 if ((reinterpret_cast<TestNApiValue*>(value))->GetType() == TEST_NVALUE_TYPE_CONTEXT) {
122 *result = napi_object;
123 } else if ((reinterpret_cast<TestNApiValue*>(value))->GetType() == TEST_NVALUE_TYPE_UPGRADE) {
124 *result = napi_object;
125 } else if ((reinterpret_cast<TestNApiValue*>(value))->GetType() == TEST_NVALUE_TYPE_UPDATE_POLICY) {
126 *result = napi_object;
127 } else {
128 *result = (napi_valuetype)(reinterpret_cast<TestNApiValue*>(value))->GetType();
129 }
130 return napi_status::napi_ok;
131 }
132
napi_create_reference(napi_env env,napi_value value,uint32_t initial_refcount,napi_ref * result)133 napi_status napi_create_reference(napi_env env, napi_value value, uint32_t initial_refcount,
134 napi_ref* result)
135 {
136 return napi_status::napi_ok;
137 }
138
napi_get_reference_value(napi_env env,napi_ref ref,napi_value * result)139 napi_status napi_get_reference_value(napi_env env, napi_ref ref, napi_value* result)
140 {
141 return napi_status::napi_ok;
142 }
143
napi_delete_reference(napi_env env,napi_ref ref)144 napi_status napi_delete_reference(napi_env env, napi_ref ref)
145 {
146 return napi_status::napi_ok;
147 }
148
napi_call_function(napi_env env,napi_value recv,napi_value func,size_t argc,const napi_value * argv,napi_value * result)149 napi_status napi_call_function(napi_env env, napi_value recv,
150 napi_value func, size_t argc, const napi_value *argv, napi_value *result)
151 {
152 g_callbackFuncationCalled = true;
153 return napi_status::napi_ok;
154 }
155
napi_delete_async_work(napi_env env,napi_async_work work)156 napi_status napi_delete_async_work(napi_env env, napi_async_work work)
157 {
158 return napi_status::napi_ok;
159 }
160
napi_queue_async_work(napi_env env,napi_async_work work)161 napi_status napi_queue_async_work(napi_env env, napi_async_work work)
162 {
163 return napi_status::napi_ok;
164 }
165
napi_cancel_async_work(napi_env env,napi_async_work work)166 napi_status napi_cancel_async_work(napi_env env, napi_async_work work)
167 {
168 return napi_status::napi_ok;
169 }
170
napi_create_object(napi_env env,napi_value * result)171 napi_status napi_create_object(napi_env env, napi_value* result)
172 {
173 *result = CreateNapiValue(napi_object, nullptr);
174 return napi_status::napi_ok;
175 }
176
napi_set_element(napi_env env,napi_value object,uint32_t index,napi_value value)177 napi_status napi_set_element(napi_env env, napi_value object, uint32_t index, napi_value value)
178 {
179 return napi_status::napi_ok;
180 }
181
napi_create_array_with_length(napi_env env,size_t length,napi_value * result)182 napi_status napi_create_array_with_length(napi_env env, size_t length, napi_value* result)
183 {
184 *result = CreateNapiValue(napi_object, nullptr);
185 return napi_status::napi_ok;
186 }
187
napi_create_int32(napi_env env,int32_t value,napi_value * result)188 napi_status napi_create_int32(napi_env env, int32_t value, napi_value* result)
189 {
190 *result = CreateNapiValue(napi_number, &value);
191 return napi_status::napi_ok;
192 }
193
napi_create_uint32(napi_env env,uint32_t value,napi_value * result)194 napi_status napi_create_uint32(napi_env env, uint32_t value, napi_value* result)
195 {
196 *result = CreateNapiValue(napi_number, &value);
197 return napi_status::napi_ok;
198 }
199
napi_get_undefined(napi_env env,napi_value * result)200 napi_status napi_get_undefined(napi_env env, napi_value* result)
201 {
202 *result = (napi_value)&g_undefined;
203 return napi_status::napi_ok;
204 }
205
napi_create_int64(napi_env env,int64_t value,napi_value * result)206 napi_status napi_create_int64(napi_env env, int64_t value, napi_value* result)
207 {
208 *result = CreateNapiValue(napi_bigint, &value);
209 return napi_status::napi_ok;
210 }
211
napi_throw_error(napi_env env,const char * code,const char * msg)212 napi_status napi_throw_error(napi_env env, const char* code, const char* msg)
213 {
214 return napi_status::napi_ok;
215 }
napi_is_exception_pending(napi_env env,bool * result)216 napi_status napi_is_exception_pending(napi_env env, bool* result)
217 {
218 return napi_status::napi_ok;
219 }
220
napi_get_last_error_info(napi_env env,const napi_extended_error_info ** result)221 napi_status napi_get_last_error_info(napi_env env, const napi_extended_error_info** result)
222 {
223 return napi_status::napi_ok;
224 }
225
napi_define_properties(napi_env env,napi_value object,size_t property_count,const napi_property_descriptor * properties)226 napi_status napi_define_properties(napi_env env, napi_value object,
227 size_t property_count, const napi_property_descriptor *properties)
228 {
229 return napi_status::napi_ok;
230 }
231
napi_module_register(napi_module * mod)232 void napi_module_register(napi_module* mod) {}
233
napi_has_named_property(napi_env env,napi_value object,const char * utf8name,bool * result)234 napi_status napi_has_named_property(napi_env env, napi_value object, const char *utf8name,
235 bool *result)
236 {
237 *result = false;
238 TestNApiValue* testValue = reinterpret_cast<TestNApiValue*>(object);
239 if (testValue == nullptr) {
240 return napi_status::napi_invalid_arg;
241 }
242 if (testValue->GetType() == TEST_NVALUE_TYPE_CONTEXT) {
243 *result = true;
244 } else if (testValue->GetType() == TEST_NVALUE_TYPE_UPGRADE ||
245 testValue->GetType() == TEST_NVALUE_TYPE_UPDATE_POLICY) {
246 *result = true;
247 }
248 return napi_status::napi_ok;
249 }
250
napi_get_named_property(napi_env env,napi_value object,const char * utf8name,napi_value * result)251 napi_status napi_get_named_property(napi_env env, napi_value object, const char* utf8name,
252 napi_value* result)
253 {
254 TestNApiEnv* testEnv = reinterpret_cast<TestNApiEnv*>(env);
255 TestNApiValue* testValue = reinterpret_cast<TestNApiValue*>(object);
256 if (testEnv == nullptr || testValue == nullptr) {
257 return napi_status::napi_invalid_arg;
258 }
259
260 if (testValue->GetType() == TEST_NVALUE_TYPE_CONTEXT) {
261 if (strcmp(utf8name, "serverAddr") == 0) {
262 *result = CreateNapiValue(napi_string, "10.50.40.92");
263 } else if (strcmp(utf8name, "upgradeDevId") == 0) {
264 *result = CreateNapiValue(napi_string, testEnv->clientContext.upgradeDevId.c_str());
265 } else if (strcmp(utf8name, "controlDevId") == 0) {
266 *result = CreateNapiValue(napi_string, testEnv->clientContext.controlDevId.c_str());
267 } else if (strcmp(utf8name, "upgradeApp") == 0) {
268 *result = CreateNapiValue(napi_string, testEnv->clientContext.upgradeApp.c_str());
269 } else if (strcmp(utf8name, "type") == 0) {
270 *result = CreateNapiValue(napi_number, &testEnv->clientContext.type);
271 }
272 } else if (testValue->GetType() == TEST_NVALUE_TYPE_UPGRADE) {
273 if (strcmp(utf8name, "versionName") == 0) {
274 *result = CreateNapiValue(napi_string, testEnv->pakcageInfo.result[0].versionName.c_str());
275 } else if (strcmp(utf8name, "versionCode") == 0) {
276 *result = CreateNapiValue(napi_string, testEnv->pakcageInfo.result[0].versionCode.c_str());
277 } else if (strcmp(utf8name, "verifyInfo") == 0) {
278 *result = CreateNapiValue(napi_string, testEnv->pakcageInfo.result[0].verifyInfo.c_str());
279 } else if (strcmp(utf8name, "descriptPackageId") == 0) {
280 *result = CreateNapiValue(napi_string, testEnv->pakcageInfo.result[0].descriptPackageId.c_str());
281 } else if (strcmp(utf8name, "packageType") == 0) {
282 *result = CreateNapiValue(napi_number, &testEnv->pakcageInfo.result[0].packageType);
283 } else if (strcmp(utf8name, "size") == 0) {
284 *result = CreateNapiValue(napi_bigint, &testEnv->pakcageInfo.result[0].size);
285 }
286 } else if (testValue->GetType() == TEST_NVALUE_TYPE_UPDATE_POLICY) {
287 if (strcmp(utf8name, "autoDownload") == 0) {
288 *result = CreateNapiValue(napi_number, reinterpret_cast<void*>(&g_updatePolicy.autoDownload));
289 } else if (strcmp(utf8name, "autoDownloadNet") == 0) {
290 *result = CreateNapiValue(napi_string, reinterpret_cast<void*>(&g_updatePolicy.autoDownloadNet));
291 } else if (strcmp(utf8name, "mode") == 0) {
292 *result = CreateNapiValue(napi_string, reinterpret_cast<void*>(&g_updatePolicy.mode));
293 } else if (strcmp(utf8name, "autoUpgradeCondition") == 0) {
294 *result = CreateNapiValue(napi_string, reinterpret_cast<void*>(&g_updatePolicy.autoUpgradeCondition));
295 }
296 }
297 return napi_status::napi_ok;
298 }
299
napi_get_value_string_utf8(napi_env env,napi_value value,char * buf,size_t bufsize,size_t * result)300 napi_status napi_get_value_string_utf8(napi_env env, napi_value value, char* buf,
301 size_t bufsize, size_t* result)
302 {
303 TestNApiValue* testValue = reinterpret_cast<TestNApiValue*>(value);
304 if (testValue == nullptr) {
305 return napi_status::napi_invalid_arg;
306 }
307 if (buf != nullptr) {
308 (void)memcpy_s(buf, bufsize, testValue->strValue.data(), testValue->strValue.size());
309 }
310 printf("napi_get_value_string_utf8 %s bufsize %zu %zu \n",
311 testValue->strValue.c_str(), bufsize, testValue->strValue.size());
312 *result = testValue->strValue.size();
313 return napi_status::napi_ok;
314 }
315
napi_get_value_int32(napi_env env,napi_value value,int32_t * result)316 napi_status napi_get_value_int32(napi_env env, napi_value value, int32_t* result)
317 {
318 TestNApiValue* testValue = reinterpret_cast<TestNApiValue*>(value);
319 if (testValue == nullptr) {
320 return napi_status::napi_invalid_arg;
321 }
322 *result = testValue->intValue;
323 return napi_status::napi_ok;
324 }
325
napi_get_value_uint32(napi_env env,napi_value value,uint32_t * result)326 napi_status napi_get_value_uint32(napi_env env, napi_value value, uint32_t* result)
327 {
328 TestNApiValue* testValue = reinterpret_cast<TestNApiValue*>(value);
329 if (testValue == nullptr) {
330 return napi_status::napi_invalid_arg;
331 }
332 *result = static_cast<uint32_t>(testValue->intValue);
333 return napi_status::napi_ok;
334 }
335
napi_get_value_int64(napi_env env,napi_value value,int64_t * result)336 napi_status napi_get_value_int64(napi_env env, napi_value value, int64_t* result)
337 {
338 TestNApiValue* testValue = reinterpret_cast<TestNApiValue*>(value);
339 if (testValue == nullptr) {
340 return napi_status::napi_invalid_arg;
341 }
342 *result = testValue->int64Value;
343 return napi_status::napi_ok;
344 }
345
napi_set_named_property(napi_env env,napi_value object,const char * utf8name,napi_value value)346 napi_status napi_set_named_property(napi_env env, napi_value object, const char *utf8name,
347 napi_value value)
348 {
349 TestNApiEnv* testEnv = reinterpret_cast<TestNApiEnv*>(env);
350 TestNApiValue* testValue = reinterpret_cast<TestNApiValue*>(value);
351 if (testValue == nullptr) {
352 return napi_status::napi_ok;
353 }
354 if (testValue->GetType() == napi_string) {
355 if (testValue->strValue.empty()) {
356 return napi_status::napi_ok;
357 }
358 if (strcmp(utf8name, "versionName") == 0) {
359 testEnv->pakcageInfo.result[0].versionName = testValue->strValue;
360 } else if (strcmp(utf8name, "versionCode") == 0) {
361 testEnv->pakcageInfo.result[0].versionCode = testValue->strValue;
362 } else if (strcmp(utf8name, "verifyInfo") == 0) {
363 testEnv->pakcageInfo.result[0].verifyInfo = testValue->strValue;
364 } else if (strcmp(utf8name, "descriptPackageId") == 0) {
365 if (testValue->strValue.size() > 0) {
366 testEnv->pakcageInfo.result[0].descriptPackageId = testValue->strValue;
367 }
368 } else if (strcmp(utf8name, "errMsg") == 0) {
369 testEnv->errorMsg = testValue->strValue;
370 }
371 } else if (testValue->GetType() == napi_number) {
372 if (strcmp(utf8name, "packageType") == 0) {
373 testEnv->pakcageInfo.result[0].packageType = (PackageType)testValue->intValue;
374 } else if (strcmp(utf8name, "status") == 0) {
375 testEnv->progress.status = (UpgradeStatus)testValue->intValue;
376 } else if (strcmp(utf8name, "percent") == 0) {
377 testEnv->progress.percent = testValue->intValue;
378 }
379 } else if (testValue->GetType() == napi_bigint) {
380 if (strcmp(utf8name, "size") == 0 && testValue->int64Value != 0) {
381 testEnv->pakcageInfo.result[0].size = (size_t)testValue->int64Value;
382 }
383 }
384 return napi_status::napi_ok;
385 }
386
387 // Asynchronous execution
napi_create_async_work(napi_env env,napi_value async_resource,napi_value async_resource_name,napi_async_execute_callback execute,napi_async_complete_callback complete,void * data,napi_async_work * result)388 napi_status napi_create_async_work(napi_env env, napi_value async_resource,
389 napi_value async_resource_name, napi_async_execute_callback execute,
390 napi_async_complete_callback complete, void *data, napi_async_work *result)
391 {
392 UpdateSession *sess = static_cast<UpdateSession *>(data);
393 g_testSessionId = sess->GetSessionId();
394 printf(" g_testSessionId %u\n", g_testSessionId);
395 *result = (napi_async_work)CreateNapiValue(0, nullptr);
396 return napi_status::napi_ok;
397 }
398
napi_get_cb_info(napi_env env,napi_callback_info cbinfo,size_t * argc,napi_value * argv,napi_value * this_arg,void ** data)399 napi_status napi_get_cb_info(
400 napi_env env, // [in] NAPI environment handle
401 napi_callback_info cbinfo, // [in] Opaque callback-info handle
402 size_t *argc, // [in-out] Specifies the size of the provided argv array
403 // and receives the actual count of args.
404 napi_value *argv, // [out] Array of values
405 napi_value *this_arg, // [out] Receives the JS 'this' arg for the call
406 void **data) // [out] Receives the data pointer for the callback.
407 {
408 TestNApiEnv* testEnv = reinterpret_cast<TestNApiEnv*>(env);
409 if (testEnv == nullptr) {
410 return napi_status::napi_invalid_arg;
411 }
412 printf("++++++++++++++ napi_get_cb_info argc %zu testStage %d \n", *argc, testEnv->testStage);
413 switch (testEnv->testStage) {
414 case static_cast<int32_t>(SessionType::SESSION_GET_UPDATER): {
415 if (*argc > 1) {
416 *argc = (testEnv->engineType != 0) ? NUMBER_2 : 1;
417 argv[0] = CreateNapiValue(napi_string, testEnv->eventType.c_str());
418 argv[1] = CreateNapiValue(napi_string, "OTA");
419 } else {
420 argv[0] = CreateNapiValue(napi_string, "OTA");
421 *argc = 1;
422 }
423 break;
424 }
425 case static_cast<int32_t>(SessionType::SESSION_VERIFY_PACKAGE): {
426 if (*argc > 1) {
427 argv[0] = CreateNapiValue(napi_string, "/data/ota_package/updater_success.zip");
428 argv[1] = CreateNapiValue(napi_string, "/data/ota_package/signing_cert.crt");
429 }
430 *argc = NUMBER_2;
431 break;
432 }
433 case static_cast<int32_t>(SessionType::SESSION_SET_POLICY): {
434 argv[0] = CreateNapiValue(TEST_NVALUE_TYPE_UPDATE_POLICY, nullptr);
435 if (*argc > 1) {
436 argv[1] = CreateNapiValue(napi_function, nullptr);
437 }
438 *argc = testEnv->testAsyncorPermose ? 1 : NUMBER_2;
439 break;
440 }
441 case static_cast<int32_t>(SessionType::SESSION_SUBSCRIBE):
442 case static_cast<int32_t>(SessionType::SESSION_UNSUBSCRIBE): {
443 argv[0] = CreateNapiValue(napi_string, testEnv->eventType.c_str());
444 if (*argc > 1) {
445 argv[1] = CreateNapiValue(napi_function, nullptr);
446 }
447 *argc = testEnv->testAsyncorPermose ? 1 : NUMBER_2;
448 break;
449 }
450 default: {
451 *argc = testEnv->testAsyncorPermose ? 0 : 1;
452 *argv = CreateNapiValue(napi_function, nullptr);
453 break;
454 }
455 }
456 return napi_status::napi_ok;
457 }
458
napi_is_array(napi_env env,napi_value value,bool * result)459 napi_status napi_is_array(napi_env env, napi_value value, bool *result)
460 {
461 if (result != nullptr) {
462 *result = true;
463 }
464 return napi_status::napi_ok;
465 }
466
napi_get_array_length(napi_env env,napi_value value,uint32_t * result)467 napi_status napi_get_array_length(napi_env env, napi_value value, uint32_t *result)
468 {
469 *result = sizeof(g_updatePolicy.autoUpgradeInterval) / sizeof(g_updatePolicy.autoUpgradeInterval[0]);
470 return napi_status::napi_ok;
471 }
472
napi_get_element(napi_env env,napi_value object,uint32_t index,napi_value * result)473 napi_status napi_get_element(napi_env env, napi_value object, uint32_t index, napi_value *result)
474 {
475 if (index >= sizeof(g_updatePolicy.autoUpgradeInterval) / sizeof(g_updatePolicy.autoUpgradeInterval[0])) {
476 *result = nullptr;
477 return napi_status::napi_ok;
478 }
479 *result = CreateNapiValue(napi_number, &g_updatePolicy.autoUpgradeInterval[index]);
480 return napi_status::napi_ok;
481 }
482
napi_open_handle_scope(napi_env env,napi_handle_scope * result)483 napi_status napi_open_handle_scope(napi_env env, napi_handle_scope* result)
484 {
485 return napi_status::napi_ok;
486 }
487
napi_close_handle_scope(napi_env env,napi_handle_scope scope)488 napi_status napi_close_handle_scope(napi_env env, napi_handle_scope scope)
489 {
490 UNUSED(env);
491 return napi_status::napi_ok;
492 }
493
napi_get_value_bool(napi_env env,napi_value value,bool * result)494 napi_status napi_get_value_bool(napi_env env, napi_value value, bool* result)
495 {
496 *result = true;
497 return napi_status::napi_ok;
498 }
499
napi_strict_equals(napi_env env,napi_value lhs,napi_value rhs,bool * result)500 napi_status napi_strict_equals(napi_env env, napi_value lhs, napi_value rhs, bool* result)
501 {
502 *result = true;
503 return napi_status::napi_ok;
504 }
505
napi_create_promise(napi_env env,napi_deferred * deferred,napi_value * promise)506 napi_status napi_create_promise(napi_env env, napi_deferred* deferred, napi_value* promise)
507 {
508 *promise = CreateNapiValue(napi_object, nullptr);
509 return napi_status::napi_ok;
510 }
511
napi_resolve_deferred(napi_env env,napi_deferred deferred,napi_value resolution)512 napi_status napi_resolve_deferred(napi_env env, napi_deferred deferred, napi_value resolution)
513 {
514 return napi_status::napi_ok;
515 }
516
napi_reject_deferred(napi_env env,napi_deferred deferred,napi_value rejection)517 napi_status napi_reject_deferred(napi_env env, napi_deferred deferred, napi_value rejection)
518 {
519 return napi_status::napi_ok;
520 }
521
522 // Methods to work with external data objects
napi_wrap(napi_env env,napi_value jsObject,void * native_object,napi_finalize finalize_cb,void * finalize_hint,napi_ref * result)523 napi_status napi_wrap(napi_env env, napi_value jsObject,
524 void* native_object, napi_finalize finalize_cb, void* finalize_hint, napi_ref* result)
525 {
526 return napi_status::napi_ok;
527 }
528
napi_unwrap(napi_env env,napi_value jsObject,void ** result)529 napi_status napi_unwrap(napi_env env, napi_value jsObject, void** result)
530 {
531 TestNApiEnv* testEnv = reinterpret_cast<TestNApiEnv*>(env);
532 if (testEnv == nullptr) {
533 return napi_status::napi_invalid_arg;
534 }
535 if (testEnv->testStage && testEnv->noneClient) {
536 *result = nullptr;
537 testEnv->noneClient = false;
538 return napi_status::napi_ok;
539 }
540 if (g_testClient == nullptr) {
541 g_testClient = new UpdateClient(env, jsObject);
542 }
543 *result = g_testClient;
544 return napi_status::napi_ok;
545 }
546
napi_define_class(napi_env env,const char * utf8name,size_t length,napi_callback constructor,void * data,size_t property_count,const napi_property_descriptor * properties,napi_value * result)547 napi_status napi_define_class(napi_env env, const char* utf8name, size_t length, napi_callback constructor,
548 void* data, size_t property_count, const napi_property_descriptor* properties, napi_value* result)
549 {
550 std::function<napi_value(napi_env env, napi_callback_info info)> func = constructor;
551 func(env, nullptr);
552 return napi_status::napi_ok;
553 }
554
napi_new_instance(napi_env env,napi_value constructor,size_t argc,const napi_value * argv,napi_value * result)555 napi_status napi_new_instance(napi_env env, napi_value constructor, size_t argc, const napi_value* argv,
556 napi_value* result)
557 {
558 UNUSED(argv);
559 return napi_status::napi_ok;
560 }
561
napi_remove_wrap(napi_env env,napi_value js_object,void ** result)562 napi_status napi_remove_wrap(napi_env env, napi_value js_object, void** result)
563 {
564 UNUSED(result);
565 return napi_status::napi_ok;
566 }
567
568 #ifdef __cplusplus
569 }
570 #endif
571