1 /*
2 * Copyright (c) 2024 SwanLink (Jiangsu) Technology Development 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 "napi/native_api.h"
17 #include "napi_basicdatatypes_test.h"
18
19 //OH_JSVM_CreateInt32:value int32_max + result not null
TestCreateInt32Case01(JSVM_Env env,JSVM_CallbackInfo info)20 [[maybe_unused]] JSVM_Value TestCreateInt32Case01(JSVM_Env env, JSVM_CallbackInfo info)
21 {
22 int32_t srcNum = INT32_MAX;
23 JSVM_Value desNum = nullptr;
24 JSVM_Status status = OH_JSVM_CreateInt32(env, srcNum, &desNum);
25 if (status != JSVM_OK || desNum == nullptr) {
26 OH_JSVM_ThrowError(env, nullptr, "TestCreateInt32Case01:OH_JSVM_CreateInt32 Failed.");
27 return nullptr;
28 }
29
30 bool setValue = true;
31 JSVM_Value retValue = nullptr;
32 OH_JSVM_GetBoolean(env, setValue, &retValue);
33 return retValue;
34 }
35 //value int32_min + result not null
TestCreateInt32Case02(JSVM_Env env,JSVM_CallbackInfo info)36 [[maybe_unused]] JSVM_Value TestCreateInt32Case02(JSVM_Env env, JSVM_CallbackInfo info)
37 {
38 int32_t srcNum = INT32_MIN;
39 JSVM_Value desNum = nullptr;
40 JSVM_Status status = OH_JSVM_CreateInt32(env, srcNum, &desNum);
41 if (status != JSVM_OK || desNum == nullptr) {
42 OH_JSVM_ThrowError(env, nullptr, "TestCreateInt32Case02:OH_JSVM_CreateInt32 Failed.");
43 return nullptr;
44 }
45
46 bool setValue = true;
47 JSVM_Value retValue = nullptr;
48 OH_JSVM_GetBoolean(env, setValue, &retValue);
49 return retValue;
50 }
51 //value 0 + result not null
TestCreateInt32Case03(JSVM_Env env,JSVM_CallbackInfo info)52 [[maybe_unused]] JSVM_Value TestCreateInt32Case03(JSVM_Env env, JSVM_CallbackInfo info)
53 {
54 JSVM_Value desNum = nullptr;
55 JSVM_Status status = OH_JSVM_CreateInt32(env, 0, &desNum);
56 if (status != JSVM_OK || desNum == nullptr) {
57 OH_JSVM_ThrowError(env, nullptr, "TestCreateInt32Case03:OH_JSVM_CreateInt32 Failed.");
58 return nullptr;
59 }
60
61 bool setValue = true;
62 JSVM_Value retValue = nullptr;
63 OH_JSVM_GetBoolean(env, setValue, &retValue);
64 return retValue;
65 }
66 //value 0 + result NULL
TestCreateInt32Case04(JSVM_Env env,JSVM_CallbackInfo info)67 [[maybe_unused]] JSVM_Value TestCreateInt32Case04(JSVM_Env env, JSVM_CallbackInfo info)
68 {
69 JSVM_Status status = OH_JSVM_CreateInt32(env, 0, nullptr);
70 if (status == JSVM_OK) {
71 OH_JSVM_ThrowError(env, nullptr, "TestCreateInt32Case04:OH_JSVM_CreateInt32 Execution abnormal.");
72 return nullptr;
73 }
74
75 bool setValue = true;
76 JSVM_Value retValue = nullptr;
77 OH_JSVM_GetBoolean(env, setValue, &retValue);
78 return retValue;
79 }
80 //OH_JSVM_CreateUint32:value uint32_max + result not null
TestCreateUint32Case01(JSVM_Env env,JSVM_CallbackInfo info)81 [[maybe_unused]] JSVM_Value TestCreateUint32Case01(JSVM_Env env, JSVM_CallbackInfo info)
82 {
83 uint32_t srcNum = UINT32_MAX;
84 JSVM_Value desNum = nullptr;
85 JSVM_Status status = OH_JSVM_CreateUint32(env, srcNum, &desNum);
86 if (status != JSVM_OK || desNum == nullptr) {
87 OH_JSVM_ThrowError(env, nullptr, "TestCreateUint32Case01:OH_JSVM_CreateUint32 Failed.");
88 return nullptr;
89 }
90
91 bool setValue = true;
92 JSVM_Value retValue = nullptr;
93 OH_JSVM_GetBoolean(env, setValue, &retValue);
94 return retValue;
95 }
96 //value 1 + result not null
TestCreateUint32Case02(JSVM_Env env,JSVM_CallbackInfo info)97 [[maybe_unused]] JSVM_Value TestCreateUint32Case02(JSVM_Env env, JSVM_CallbackInfo info)
98 {
99 JSVM_Value desNum = nullptr;
100 JSVM_Status status = OH_JSVM_CreateUint32(env, 1, &desNum);
101 if (status != JSVM_OK || desNum == nullptr) {
102 OH_JSVM_ThrowError(env, nullptr, "TestCreateUint32Case02:OH_JSVM_CreateUint32 Failed.");
103 return nullptr;
104 }
105
106 bool setValue = true;
107 JSVM_Value retValue = nullptr;
108 OH_JSVM_GetBoolean(env, setValue, &retValue);
109 return retValue;
110 }
111 //value 0 + result not null
TestCreateUint32Case03(JSVM_Env env,JSVM_CallbackInfo info)112 [[maybe_unused]] JSVM_Value TestCreateUint32Case03(JSVM_Env env, JSVM_CallbackInfo info)
113 {
114 JSVM_Value desNum = nullptr;
115 JSVM_Status status = OH_JSVM_CreateUint32(env, 0, &desNum);
116 if (status != JSVM_OK || desNum == nullptr) {
117 OH_JSVM_ThrowError(env, nullptr, "TestCreateUint32Case03:OH_JSVM_CreateUint32 Failed.");
118 return nullptr;
119 }
120
121 bool setValue = true;
122 JSVM_Value retValue = nullptr;
123 OH_JSVM_GetBoolean(env, setValue, &retValue);
124 return retValue;
125 }
126 //value 0 + result NULL
TestCreateUint32Case04(JSVM_Env env,JSVM_CallbackInfo info)127 [[maybe_unused]] JSVM_Value TestCreateUint32Case04(JSVM_Env env, JSVM_CallbackInfo info)
128 {
129 JSVM_Status status = OH_JSVM_CreateUint32(env, 0, nullptr);
130 if (status == JSVM_OK) {
131 OH_JSVM_ThrowError(env, nullptr, "TestCreateUint32Case04:OH_JSVM_CreateUint32 Execution abnormal.");
132 return nullptr;
133 }
134
135 bool setValue = true;
136 JSVM_Value retValue = nullptr;
137 OH_JSVM_GetBoolean(env, setValue, &retValue);
138 return retValue;
139 }
140 //OH_JSVM_CreateInt64:value int64_max + result not null
TestCreateInt64Case01(JSVM_Env env,JSVM_CallbackInfo info)141 [[maybe_unused]] JSVM_Value TestCreateInt64Case01(JSVM_Env env, JSVM_CallbackInfo info)
142 {
143 int64_t srcNum = INT64_MAX;
144 JSVM_Value desNum = nullptr;
145 JSVM_Status status = OH_JSVM_CreateInt64(env, srcNum, &desNum);
146 if (status != JSVM_OK || desNum == nullptr) {
147 OH_JSVM_ThrowError(env, nullptr, "TestCreateInt64Case01:OH_JSVM_CreateInt64 Failed.");
148 return nullptr;
149 }
150
151 bool setValue = true;
152 JSVM_Value retValue = nullptr;
153 OH_JSVM_GetBoolean(env, setValue, &retValue);
154 return retValue;
155 }
156 //value int64_min + result not null
TestCreateInt64Case02(JSVM_Env env,JSVM_CallbackInfo info)157 [[maybe_unused]] JSVM_Value TestCreateInt64Case02(JSVM_Env env, JSVM_CallbackInfo info)
158 {
159 int64_t srcNum = INT64_MIN;
160 JSVM_Value desNum = nullptr;
161 JSVM_Status status = OH_JSVM_CreateInt64(env, srcNum, &desNum);
162 if (status != JSVM_OK || desNum == nullptr) {
163 OH_JSVM_ThrowError(env, nullptr, "TestCreateInt64Case02:OH_JSVM_CreateInt64 Failed.");
164 return nullptr;
165 }
166
167 bool setValue = true;
168 JSVM_Value retValue = nullptr;
169 OH_JSVM_GetBoolean(env, setValue, &retValue);
170 return retValue;
171 }
172 //value 0 + result not null
TestCreateInt64Case03(JSVM_Env env,JSVM_CallbackInfo info)173 [[maybe_unused]] JSVM_Value TestCreateInt64Case03(JSVM_Env env, JSVM_CallbackInfo info)
174 {
175 JSVM_Value desNum = nullptr;
176 JSVM_Status status = OH_JSVM_CreateInt64(env, 0, &desNum);
177 if (status != JSVM_OK || desNum == nullptr) {
178 OH_JSVM_ThrowError(env, nullptr, "TestCreateInt64Case03:OH_JSVM_CreateInt64 Failed.");
179 return nullptr;
180 }
181
182 bool setValue = true;
183 JSVM_Value retValue = nullptr;
184 OH_JSVM_GetBoolean(env, setValue, &retValue);
185 return retValue;
186 }
187 //value 0 + result NULL
TestCreateInt64Case04(JSVM_Env env,JSVM_CallbackInfo info)188 [[maybe_unused]] JSVM_Value TestCreateInt64Case04(JSVM_Env env, JSVM_CallbackInfo info)
189 {
190 JSVM_Status status = OH_JSVM_CreateInt64(env, 0, nullptr);
191 if (status == JSVM_OK) {
192 OH_JSVM_ThrowError(env, nullptr, "TestCreateInt64Case04:OH_JSVM_CreateInt64 Execution abnormal.");
193 return nullptr;
194 }
195
196 bool setValue = true;
197 JSVM_Value retValue = nullptr;
198 OH_JSVM_GetBoolean(env, setValue, &retValue);
199 return retValue;
200 }
201 //OH_JSVM_CreateDouble:value double_max + result not null
202 #define DBL_MAX 1.7976931348623158e+308 /* max value */
203 #define DBL_MIN 2.2250738585072014e-308 /* min positive value */
TestCreateDoubleCase01(JSVM_Env env,JSVM_CallbackInfo info)204 [[maybe_unused]] JSVM_Value TestCreateDoubleCase01(JSVM_Env env, JSVM_CallbackInfo info)
205 {
206 double srcNum = DBL_MAX;
207 JSVM_Value desNum = nullptr;
208 JSVM_Status status = OH_JSVM_CreateDouble(env, srcNum, &desNum);
209 if (status != JSVM_OK || desNum == nullptr) {
210 OH_JSVM_ThrowError(env, nullptr, "TestCreateDoubleCase01:OH_JSVM_CreateDouble Failed.");
211 return nullptr;
212 }
213
214 bool setValue = true;
215 JSVM_Value retValue = nullptr;
216 OH_JSVM_GetBoolean(env, setValue, &retValue);
217 return retValue;
218 }
219 //value double_min + result not null
TestCreateDoubleCase02(JSVM_Env env,JSVM_CallbackInfo info)220 [[maybe_unused]] JSVM_Value TestCreateDoubleCase02(JSVM_Env env, JSVM_CallbackInfo info)
221 {
222 double srcNum = DBL_MIN;
223 JSVM_Value desNum = nullptr;
224 JSVM_Status status = OH_JSVM_CreateDouble(env, srcNum, &desNum);
225 if (status != JSVM_OK || desNum == nullptr) {
226 OH_JSVM_ThrowError(env, nullptr, "TestCreateDoubleCase02:OH_JSVM_CreateDouble Failed.");
227 return nullptr;
228 }
229
230 bool setValue = true;
231 JSVM_Value retValue = nullptr;
232 OH_JSVM_GetBoolean(env, setValue, &retValue);
233 return retValue;
234 }
235 //value 0 + result not null
TestCreateDoubleCase03(JSVM_Env env,JSVM_CallbackInfo info)236 [[maybe_unused]] JSVM_Value TestCreateDoubleCase03(JSVM_Env env, JSVM_CallbackInfo info)
237 {
238 JSVM_Value desNum = nullptr;
239 JSVM_Status status = OH_JSVM_CreateDouble(env, 0.0, &desNum);
240 if (status != JSVM_OK || desNum == nullptr) {
241 OH_JSVM_ThrowError(env, nullptr, "TestCreateDoubleCase03:OH_JSVM_CreateDouble Failed.");
242 return nullptr;
243 }
244
245 bool setValue = true;
246 JSVM_Value retValue = nullptr;
247 OH_JSVM_GetBoolean(env, setValue, &retValue);
248 return retValue;
249 }
250 //value 0 + result NULL
TestCreateDoubleCase04(JSVM_Env env,JSVM_CallbackInfo info)251 [[maybe_unused]] JSVM_Value TestCreateDoubleCase04(JSVM_Env env, JSVM_CallbackInfo info)
252 {
253 JSVM_Status status = OH_JSVM_CreateDouble(env, 0.0, nullptr);
254 if (status == JSVM_OK) {
255 OH_JSVM_ThrowError(env, nullptr, "TestCreateDoubleCase04:OH_JSVM_CreateDouble Execution abnormal.");
256 return nullptr;
257 }
258
259 bool setValue = true;
260 JSVM_Value retValue = nullptr;
261 OH_JSVM_GetBoolean(env, setValue, &retValue);
262 return retValue;
263 }
264 //OH_JSVM_GetValueUint32:not uint32 value
TestGetValueUint32Case01(JSVM_Env env,JSVM_CallbackInfo info)265 [[maybe_unused]] JSVM_Value TestGetValueUint32Case01(JSVM_Env env, JSVM_CallbackInfo info)
266 {
267 JSVM_Value value;
268 JSVM_Status status = OH_JSVM_CreateInt32(env, -1, &value);
269 if (status != JSVM_OK) {
270 OH_JSVM_ThrowError(env, nullptr, "TestGetValueUint32Case01:OH_JSVM_CreateInt32 Failed.");
271 return nullptr;
272 }
273
274 uint32_t rstVal;
275 status = OH_JSVM_GetValueUint32(env, value, &rstVal);
276 if (status != JSVM_OK) {
277 OH_JSVM_ThrowError(env, nullptr, "TestGetValueUint32Case01:OH_JSVM_GetValueUint32 Failed.");
278 return nullptr;
279 }
280
281 bool setValue = true;
282 JSVM_Value retValue = nullptr;
283 OH_JSVM_GetBoolean(env, setValue, &retValue);
284 return retValue;
285 }
286 //OH_JSVM_GetValueInt32:not int32 value
TestGetValueInt32Case01(JSVM_Env env,JSVM_CallbackInfo info)287 [[maybe_unused]] JSVM_Value TestGetValueInt32Case01(JSVM_Env env, JSVM_CallbackInfo info)
288 {
289 JSVM_Value desNum = nullptr;
290 JSVM_Status status = OH_JSVM_CreateDouble(env, 1.1, &desNum);
291 if (status != JSVM_OK) {
292 OH_JSVM_ThrowError(env, nullptr, "TestGetValueInt32Case01:OH_JSVM_CreateDouble Failed.");
293 return nullptr;
294 }
295
296 int32_t rstVal = 0;
297 status = OH_JSVM_GetValueInt32(env, desNum, &rstVal);
298 if (status != JSVM_OK) {
299 OH_JSVM_ThrowError(env, nullptr, "TestGetValueInt32Case01:OH_JSVM_GetValueint32 Failed.");
300 return nullptr;
301 }
302
303 JSVM_Value description;
304 size_t strLen = 7;
305 status = OH_JSVM_CreateStringUtf8(env, "teststr", strLen, &description);
306 if (status != JSVM_OK) {
307 OH_JSVM_ThrowError(env, nullptr, "TestGetValueInt32Case01:OH_JSVM_CreateStringUtf8 Failed.");
308 return nullptr;
309 }
310
311 int32_t rstVal1 = 0;
312 status = OH_JSVM_GetValueInt32(env, description, &rstVal1);
313 if (status != JSVM_NUMBER_EXPECTED) {
314 OH_JSVM_ThrowError(env, nullptr, "TestGetValueInt32Case01:OH_JSVM_GetValueint32 Execution abnormal.");
315 return nullptr;
316 }
317
318 bool setValue = true;
319 JSVM_Value retValue = nullptr;
320 OH_JSVM_GetBoolean(env, setValue, &retValue);
321 return retValue;
322 }
323 //OH_JSVM_GetValueInt64:not int64 value
TestGetValueInt64Case01(JSVM_Env env,JSVM_CallbackInfo info)324 [[maybe_unused]] JSVM_Value TestGetValueInt64Case01(JSVM_Env env, JSVM_CallbackInfo info)
325 {
326 JSVM_Value desNum = nullptr;
327 JSVM_Status status = OH_JSVM_CreateDouble(env, 0.0, &desNum);
328 if (status != JSVM_OK) {
329 OH_JSVM_ThrowError(env, nullptr, "TestGetValueInt64Case01:OH_JSVM_CreateDouble Failed.");
330 return nullptr;
331 }
332
333 int64_t rstVal;
334 status = OH_JSVM_GetValueInt64(env, desNum, &rstVal);
335 if (status != JSVM_OK) {
336 OH_JSVM_ThrowError(env, nullptr, "TestGetValueInt64Case01:OH_JSVM_GetValueInt64 Execution abnormal.");
337 return nullptr;
338 }
339
340 JSVM_Value description;
341 size_t testLen = 4;
342 status = OH_JSVM_CreateStringUtf8(env, "test", testLen, &description);
343 if (status != JSVM_OK) {
344 OH_JSVM_ThrowError(env, nullptr, "TestGetValueInt64Case01:OH_JSVM_CreateStringUtf8 Failed.");
345 return nullptr;
346 }
347
348 int64_t rstVal1 = 0;
349 status = OH_JSVM_GetValueInt64(env, description, &rstVal1);
350 if (status != JSVM_NUMBER_EXPECTED) {
351 OH_JSVM_ThrowError(env, nullptr, "TestGetValueInt64Case01:OH_JSVM_GetValueint32 Execution abnormal.");
352 return nullptr;
353 }
354
355 bool setValue = true;
356 JSVM_Value retValue = nullptr;
357 OH_JSVM_GetBoolean(env, setValue, &retValue);
358 return retValue;
359 }
360 //OH_JSVM_GetValueDouble:not double value
TestGetValueDoubleCase01(JSVM_Env env,JSVM_CallbackInfo info)361 [[maybe_unused]] JSVM_Value TestGetValueDoubleCase01(JSVM_Env env, JSVM_CallbackInfo info)
362 {
363 JSVM_Value value;
364 JSVM_Status status = OH_JSVM_CreateInt32(env, -1, &value);
365 if (status != JSVM_OK) {
366 OH_JSVM_ThrowError(env, nullptr, "TestGetValueDoubleCase01:OH_JSVM_CreateInt32 Failed.");
367 return nullptr;
368 }
369
370 double height;
371 status = OH_JSVM_GetValueDouble(env, value, &height);
372 if (status != JSVM_OK) {
373 OH_JSVM_ThrowError(env, nullptr, "TestGetValueDoubleCase01:OH_JSVM_GetValueDouble Execution abnormal.");
374 return nullptr;
375 }
376
377 JSVM_Value description;
378 size_t strLen = 4;
379 status = OH_JSVM_CreateStringUtf8(env, "test", strLen, &description);
380 if (status != JSVM_OK) {
381 OH_JSVM_ThrowError(env, nullptr, "TestGetValueDoubleCase01:OH_JSVM_CreateStringUtf8 Failed.");
382 return nullptr;
383 }
384
385 double rstVal1 = 0;
386 status = OH_JSVM_GetValueDouble(env, description, &rstVal1);
387 if (status != JSVM_NUMBER_EXPECTED) {
388 OH_JSVM_ThrowError(env, nullptr, "TestGetValueDoubleCase01:OH_JSVM_GetValueDouble Execution abnormal.");
389 return nullptr;
390 }
391
392 bool setValue = true;
393 JSVM_Value retValue = nullptr;
394 OH_JSVM_GetBoolean(env, setValue, &retValue);
395 return retValue;
396 }
397 //CreateInt32 value -> GetValueUint32 int32 convert uint32 ->GetValueInt32 -> GetValueInt64 int32 convert int64 ->
398 //GetValueDouble int32 convert double
TestBasicDataTypesCase01(JSVM_Env env,JSVM_CallbackInfo info)399 [[maybe_unused]] JSVM_Value TestBasicDataTypesCase01(JSVM_Env env, JSVM_CallbackInfo info)
400 {
401 int32_t srcNum = -1;
402 JSVM_Value numVal = nullptr;
403 JSVM_Status status = OH_JSVM_CreateInt32(env, srcNum, &numVal);
404 if (status != JSVM_OK) {
405 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase01:OH_JSVM_CreateInt32 Failed.");
406 return nullptr;
407 }
408
409 uint32_t dataValue;
410 OH_JSVM_GetValueUint32(env, numVal, &dataValue);
411 uint32_t numMax = 4294967295;
412 if (dataValue != numMax) {
413 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase01:OH_JSVM_GetValueUint32 val Failed.");
414 return nullptr;
415 }
416
417 int32_t retVal;
418 status = OH_JSVM_GetValueInt32(env, numVal, &retVal);
419 if (status != JSVM_OK) {
420 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase01:OH_JSVM_GetValueInt32 Failed.");
421 return nullptr;
422 }
423 if (retVal != -1) {
424 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase01:OH_JSVM_GetValueInt32 val Failed.");
425 return nullptr;
426 }
427
428 int64_t retVal2;
429 status = OH_JSVM_GetValueInt64(env, numVal, &retVal2);
430 if (status != JSVM_OK) {
431 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase01:OH_JSVM_GetValueInt64 Failed.");
432 return nullptr;
433 }
434 if (retVal2 != -1) {
435 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase01:OH_JSVM_GetValueInt64 val Failed.");
436 return nullptr;
437 }
438
439 double retVal3 = 0.0;
440 status = OH_JSVM_GetValueDouble(env, numVal, &retVal3);
441 if (status != JSVM_OK) {
442 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase01:OH_JSVM_GetValueDouble Failed.");
443 return nullptr;
444 }
445 if (retVal3 != -1.0) {
446 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase01:OH_JSVM_GetValueDouble val Failed.");
447 return nullptr;
448 }
449
450 bool setValue = true;
451 JSVM_Value retValue = nullptr;
452 OH_JSVM_GetBoolean(env, setValue, &retValue);
453 return retValue;
454 }
455 //CreateUint32 value -> GetValueUint32 -> GetValueInt32 uint32 convert int32 -> GetValueInt64 uint32 convert int64 ->
456 //GetValueDouble uint32 convert double
TestBasicDataTypesCase02(JSVM_Env env,JSVM_CallbackInfo info)457 [[maybe_unused]] JSVM_Value TestBasicDataTypesCase02(JSVM_Env env, JSVM_CallbackInfo info)
458 {
459 JSVM_Value jsNum = nullptr;
460 uint32_t testNum = 1;
461 JSVM_Status status = OH_JSVM_CreateUint32(env, testNum, &jsNum);
462 uint32_t retValue;
463 status = OH_JSVM_GetValueUint32(env, jsNum, &retValue);
464 if (retValue != 1) {
465 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase02:OH_JSVM_GetValueUint32 val Failed.");
466 return nullptr;
467 }
468
469 int32_t retValue1;
470 status = OH_JSVM_GetValueInt32(env, jsNum, &retValue1);
471 if (status != JSVM_OK) {
472 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase02:OH_JSVM_GetValueInt32 Failed.");
473 return nullptr;
474 }
475 if (retValue1 != 1) {
476 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase02:OH_JSVM_GetValueInt32 val Failed.");
477 return nullptr;
478 }
479
480 int64_t retValue2;
481 status = OH_JSVM_GetValueInt64(env, jsNum, &retValue2);
482 if (status != JSVM_OK) {
483 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase02:OH_JSVM_GetValueInt64 Failed.");
484 return nullptr;
485 }
486 if (retValue2 != 1) {
487 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase02:OH_JSVM_GetValueInt64 val Failed.");
488 return nullptr;
489 }
490
491 double retValue3;
492 status = OH_JSVM_GetValueDouble(env, jsNum, &retValue3);
493 if (status != JSVM_OK) {
494 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase02:OH_JSVM_GetValueDouble Failed.");
495 return nullptr;
496 }
497 if (retValue3 != 1.0) {
498 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase02:OH_JSVM_GetValueDouble val Failed.");
499 return nullptr;
500 }
501
502 bool setValue = true;
503 JSVM_Value returnValue = nullptr;
504 OH_JSVM_GetBoolean(env, setValue, &returnValue);
505 return returnValue;
506 }
507 //CreateInt64 -> GetValueUint32 int64 convert uint32 ->GetValueInt32 int64 convert int32 ->
508 //GetValueInt64 int64->GetValueDouble int64 convert double
TestBasicDataTypesCase03(JSVM_Env env,JSVM_CallbackInfo info)509 [[maybe_unused]] JSVM_Value TestBasicDataTypesCase03(JSVM_Env env, JSVM_CallbackInfo info)
510 {
511 int64_t srcNum = INT64_MAX - 1;
512 JSVM_Value desNum = nullptr;
513 JSVM_Status status = OH_JSVM_CreateInt64(env, srcNum, &desNum);
514 if (status != JSVM_OK || desNum == nullptr) {
515 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase03:OH_JSVM_CreateInt64 Failed.");
516 return nullptr;
517 }
518
519 uint32_t retValue;
520 status = OH_JSVM_GetValueUint32(env, desNum, &retValue);
521 if (status != JSVM_OK) {
522 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase03:OH_JSVM_GetValueUint32 Failed.");
523 return nullptr;
524 }
525 if (retValue != 0) {
526 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase03:OH_JSVM_GetValueUint32 val Failed.");
527 return nullptr;
528 }
529
530 int32_t retValue1;
531 status = OH_JSVM_GetValueInt32(env, desNum, &retValue1);
532 if (status != JSVM_OK) {
533 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase03:OH_JSVM_GetValueInt32 Failed.");
534 return nullptr;
535 }
536 if (retValue1 != 0) {
537 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase03:OH_JSVM_GetValueInt32 val Failed.");
538 return nullptr;
539 }
540
541 int64_t retValue2;
542 status = OH_JSVM_GetValueInt64(env, desNum, &retValue2);
543 if (status != JSVM_OK) {
544 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase03:OH_JSVM_GetValueInt64 Failed.");
545 return nullptr;
546 }
547 if (retValue2 != INT64_MAX) {
548 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase03:OH_JSVM_GetValueInt64 val Failed.");
549 return nullptr;
550 }
551
552 double retValue3;
553 status = OH_JSVM_GetValueDouble(env, desNum, &retValue3);
554 if (status != JSVM_OK) {
555 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase03:OH_JSVM_GetValueDouble Failed.");
556 return nullptr;
557 }
558
559 bool setValue = true;
560 JSVM_Value returnValue = nullptr;
561 OH_JSVM_GetBoolean(env, setValue, &returnValue);
562 return returnValue;
563 }
564 //CreateDouble -> GetValueUint32 double convert uint32 -> GetValueInt32 double convert int32 ->
565 //GetValueInt64 double convert int64 -> GetValueDouble double value
TestBasicDataTypesCase04(JSVM_Env env,JSVM_CallbackInfo info)566 [[maybe_unused]] JSVM_Value TestBasicDataTypesCase04(JSVM_Env env, JSVM_CallbackInfo info)
567 {
568 JSVM_Value desNum = nullptr;
569 JSVM_Status status = OH_JSVM_CreateDouble(env, 1.0, &desNum);
570 if (status != JSVM_OK) {
571 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase04:OH_JSVM_CreateDouble Failed.");
572 return nullptr;
573 }
574
575 uint32_t retValue;
576 status = OH_JSVM_GetValueUint32(env, desNum, &retValue);
577 if (status != JSVM_OK) {
578 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase04:OH_JSVM_GetValueUint32 Failed.");
579 return nullptr;
580 }
581 if (retValue != 1) {
582 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase04:OH_JSVM_GetValueUint32 val Failed.");
583 return nullptr;
584 }
585
586 int32_t retValue1;
587 OH_JSVM_GetValueInt32(env, desNum, &retValue1);
588 if (retValue1 != 1) {
589 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase04:OH_JSVM_GetValueInt32 val Failed.");
590 return nullptr;
591 }
592
593 int64_t retValue2;
594 status = OH_JSVM_GetValueInt64(env, desNum, &retValue2);
595 if (status != JSVM_OK) {
596 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase04:OH_JSVM_GetValueInt64 Failed.");
597 return nullptr;
598 }
599 if (retValue2 != 1) {
600 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase04:OH_JSVM_GetValueInt64 val Failed.");
601 return nullptr;
602 }
603
604 double retValue3;
605 status = OH_JSVM_GetValueDouble(env, desNum, &retValue3);
606 if (status != JSVM_OK) {
607 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase04:OH_JSVM_GetValueDouble Failed.");
608 return nullptr;
609 }
610 if (retValue3 != 1.0) {
611 OH_JSVM_ThrowError(env, nullptr, "TestBasicDataTypesCase04:OH_JSVM_GetValueDouble val Failed.");
612 return nullptr;
613 }
614
615 bool setValue = true;
616 JSVM_Value returnValue = nullptr;
617 OH_JSVM_GetBoolean(env, setValue, &returnValue);
618 return returnValue;
619 }