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_bigint_test.h"
18
19 //OH_JSVM_CreateBigintInt64:value int64_max + result not null
TestCreateBigintInt64Case01(JSVM_Env env,JSVM_CallbackInfo info)20 [[maybe_unused]] JSVM_Value TestCreateBigintInt64Case01(JSVM_Env env, JSVM_CallbackInfo info)
21 {
22 JSVM_Value returnValue = nullptr;
23 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, INT64_MAX, &returnValue);
24 if (status != JSVM_OK) {
25 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintInt64Case01:OH_JSVM_CreateBigintInt64 Failed.");
26 return nullptr;
27 }
28
29 bool setValue = true;
30 JSVM_Value retValue = nullptr;
31 OH_JSVM_GetBoolean(env, setValue, &retValue);
32 return retValue;
33 }
34 //value int64_min + result not null
TestCreateBigintInt64Case02(JSVM_Env env,JSVM_CallbackInfo info)35 [[maybe_unused]] JSVM_Value TestCreateBigintInt64Case02(JSVM_Env env, JSVM_CallbackInfo info)
36 {
37 JSVM_Value returnValue = nullptr;
38 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, INT64_MIN, &returnValue);
39 if (status != JSVM_OK) {
40 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintInt64Case02:OH_JSVM_CreateBigintInt64 Failed.");
41 return nullptr;
42 }
43
44 bool setValue = true;
45 JSVM_Value retValue = nullptr;
46 OH_JSVM_GetBoolean(env, setValue, &retValue);
47 return retValue;
48 }
49 //value 0 + result not null
TestCreateBigintInt64Case03(JSVM_Env env,JSVM_CallbackInfo info)50 [[maybe_unused]] JSVM_Value TestCreateBigintInt64Case03(JSVM_Env env, JSVM_CallbackInfo info)
51 {
52 JSVM_Value returnValue = nullptr;
53 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, 0, &returnValue);
54 if (status != JSVM_OK) {
55 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintInt64Case03:OH_JSVM_CreateBigintInt64 Failed.");
56 return nullptr;
57 }
58
59 bool setValue = true;
60 JSVM_Value retValue = nullptr;
61 OH_JSVM_GetBoolean(env, setValue, &retValue);
62 return retValue;
63 }
64 //value 0 + result NULL
TestCreateBigintInt64Case04(JSVM_Env env,JSVM_CallbackInfo info)65 [[maybe_unused]] JSVM_Value TestCreateBigintInt64Case04(JSVM_Env env, JSVM_CallbackInfo info)
66 {
67 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, 0, nullptr);
68 if (status != JSVM_INVALID_ARG) {
69 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintInt64Case04:OH_JSVM_CreateBigintInt64 Failed.");
70 return nullptr;
71 }
72
73 bool setValue = true;
74 JSVM_Value retValue = nullptr;
75 OH_JSVM_GetBoolean(env, setValue, &retValue);
76 return retValue;
77 }
78 //OH_JSVM_CreateBigintUint64:value uint64_max + result not null
TestCreateBigintUint64Case01(JSVM_Env env,JSVM_CallbackInfo info)79 [[maybe_unused]] JSVM_Value TestCreateBigintUint64Case01(JSVM_Env env, JSVM_CallbackInfo info)
80 {
81 JSVM_Value returnValue = nullptr;
82 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, UINT64_MAX, &returnValue);
83 if (status != JSVM_OK) {
84 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintUint64Case01:OH_JSVM_CreateBigintUint64 Failed.");
85 return nullptr;
86 }
87
88 bool setValue = true;
89 JSVM_Value retValue = nullptr;
90 OH_JSVM_GetBoolean(env, setValue, &retValue);
91 return retValue;
92 }
93 //value 0 + result not null
TestCreateBigintUint64Case02(JSVM_Env env,JSVM_CallbackInfo info)94 [[maybe_unused]] JSVM_Value TestCreateBigintUint64Case02(JSVM_Env env, JSVM_CallbackInfo info)
95 {
96 JSVM_Value returnValue = nullptr;
97 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, 0, &returnValue);
98 if (status != JSVM_OK) {
99 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintUint64Case02:OH_JSVM_CreateBigintInt64 Failed.");
100 return nullptr;
101 }
102
103 bool setValue = true;
104 JSVM_Value retValue = nullptr;
105 OH_JSVM_GetBoolean(env, setValue, &retValue);
106 return retValue;
107 }
108 //value 0 + result NULL
TestCreateBigintUint64Case03(JSVM_Env env,JSVM_CallbackInfo info)109 [[maybe_unused]] JSVM_Value TestCreateBigintUint64Case03(JSVM_Env env, JSVM_CallbackInfo info)
110 {
111 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, 0, nullptr);
112 if (status == JSVM_OK) {
113 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintUint64Case03:OH_JSVM_CreateBigintInt64 Failed.");
114 return nullptr;
115 }
116
117 bool setValue = true;
118 JSVM_Value retValue = nullptr;
119 OH_JSVM_GetBoolean(env, setValue, &retValue);
120 return retValue;
121 }
122 //OH_JSVM_CreateBigintWords:signBit 0 + wordCount 3 + words {uint64_max,0,1} + result not null
TestCreateBigintWordsCase01(JSVM_Env env,JSVM_CallbackInfo info)123 [[maybe_unused]] JSVM_Value TestCreateBigintWordsCase01(JSVM_Env env, JSVM_CallbackInfo info)
124 {
125 int signBit = 0;
126 size_t wordCount = 3;
127 uint64_t words[] = {UINT64_MAX, 0, 1};
128 JSVM_Value result1 = nullptr;
129 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &result1);
130 if (status != JSVM_OK) {
131 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintWordsCase01:OH_JSVM_CreateBigintWords Failed.");
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 //signBit not 0 + wordCount 3 + words {uint64_max,0,1} + result not null
TestCreateBigintWordsCase02(JSVM_Env env,JSVM_CallbackInfo info)141 [[maybe_unused]] JSVM_Value TestCreateBigintWordsCase02(JSVM_Env env, JSVM_CallbackInfo info)
142 {
143 int signBit = 1;
144 size_t wordCount = 3;
145 uint64_t words[] = {UINT64_MAX, 0, 1};
146 JSVM_Value result1 = nullptr;
147 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &result1);
148 if (status != JSVM_OK) {
149 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintWordsCase02:OH_JSVM_CreateBigintWords Failed.");
150 return nullptr;
151 }
152
153 bool setValue = true;
154 JSVM_Value retValue = nullptr;
155 OH_JSVM_GetBoolean(env, setValue, &retValue);
156 return retValue;
157 }
158 //signBit 0 + wordCount 0 + words {uint64_max,0,1} + result not null
TestCreateBigintWordsCase03(JSVM_Env env,JSVM_CallbackInfo info)159 [[maybe_unused]] JSVM_Value TestCreateBigintWordsCase03(JSVM_Env env, JSVM_CallbackInfo info)
160 {
161 int signBit = 0;
162 size_t wordCount = 0;
163 uint64_t words[] = {UINT64_MAX, 0, 1};
164 JSVM_Value result1 = nullptr;
165 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &result1);
166 if (status != JSVM_OK) {
167 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintWordsCase03:OH_JSVM_CreateBigintWords Failed.");
168 return nullptr;
169 }
170
171 bool setValue = true;
172 JSVM_Value retValue = nullptr;
173 OH_JSVM_GetBoolean(env, setValue, &retValue);
174 return retValue;
175 }
176 //signBit 0 + wordCount 4 + words {uint64_max,0,1} + result not null
TestCreateBigintWordsCase04(JSVM_Env env,JSVM_CallbackInfo info)177 [[maybe_unused]] JSVM_Value TestCreateBigintWordsCase04(JSVM_Env env, JSVM_CallbackInfo info)
178 {
179 int signBit = 0;
180 size_t wordCount = 4;
181 uint64_t words[] = {UINT64_MAX, 0, 1};
182 JSVM_Value result1 = nullptr;
183 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &result1);
184 if (status != JSVM_OK) {
185 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintWordsCase04:OH_JSVM_CreateBigintWords Failed.");
186 return nullptr;
187 }
188
189 bool setValue = true;
190 JSVM_Value retValue = nullptr;
191 OH_JSVM_GetBoolean(env, setValue, &retValue);
192 return retValue;
193 }
194 //signBit 0 + wordCount 3 + words {uint64_max,0,1} + result NULL
TestCreateBigintWordsCase05(JSVM_Env env,JSVM_CallbackInfo info)195 [[maybe_unused]] JSVM_Value TestCreateBigintWordsCase05(JSVM_Env env, JSVM_CallbackInfo info)
196 {
197 int signBit = 0;
198 size_t wordCount = 3;
199 uint64_t words[] = {UINT64_MAX, 0, 1};
200 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, nullptr);
201 if (status == JSVM_OK) {
202 OH_JSVM_ThrowError(env, nullptr, "TestCreateBigintWordsCase05:OH_JSVM_CreateBigintWords Failed.");
203 return nullptr;
204 }
205
206 bool setValue = true;
207 JSVM_Value retValue = nullptr;
208 OH_JSVM_GetBoolean(env, setValue, &retValue);
209 return retValue;
210 }
211 //OH_JSVM_GetValueBigintInt64:"value int64_max+1" + result nogt null + lossless not null
TestGetValueBigintInt64Case01(JSVM_Env env,JSVM_CallbackInfo info)212 [[maybe_unused]] JSVM_Value TestGetValueBigintInt64Case01(JSVM_Env env, JSVM_CallbackInfo info)
213 {
214 int64_t testValue = INT64_MAX + 1;
215 JSVM_Value result = nullptr;
216 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, testValue, &result);
217 if (status != JSVM_OK) {
218 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case01:OH_JSVM_CreateBigintInt64 Failed.");
219 return nullptr;
220 }
221
222 int64_t resultValue = 0;
223 bool flag = false;
224 status = OH_JSVM_GetValueBigintInt64(env, result, &resultValue, &flag);
225 if (status != JSVM_OK) {
226 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case01:OH_JSVM_GetValueBigintInt64 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 int64_max" + result not null + lossless not null
TestGetValueBigintInt64Case02(JSVM_Env env,JSVM_CallbackInfo info)236 [[maybe_unused]] JSVM_Value TestGetValueBigintInt64Case02(JSVM_Env env, JSVM_CallbackInfo info)
237 {
238 int64_t testValue = INT64_MAX;
239 JSVM_Value result = nullptr;
240 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, testValue, &result);
241 if (status != JSVM_OK) {
242 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case02:OH_JSVM_CreateBigintInt64 Failed.");
243 return nullptr;
244 }
245
246 int64_t resultValue = 0;
247 bool flag = false;
248 status = OH_JSVM_GetValueBigintInt64(env, result, &resultValue, &flag);
249 if (status != JSVM_OK) {
250 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case02:OH_JSVM_GetValueBigintInt64 Failed.");
251 return nullptr;
252 }
253
254 bool setValue = true;
255 JSVM_Value retValue = nullptr;
256 OH_JSVM_GetBoolean(env, setValue, &retValue);
257 return retValue;
258 }
259 //"value int64_min" + result not null + lossless not null
TestGetValueBigintInt64Case03(JSVM_Env env,JSVM_CallbackInfo info)260 [[maybe_unused]] JSVM_Value TestGetValueBigintInt64Case03(JSVM_Env env, JSVM_CallbackInfo info)
261 {
262 int64_t testValue = INT64_MIN;
263 JSVM_Value result = nullptr;
264 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, testValue, &result);
265 if (status != JSVM_OK) {
266 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case03:CreateBigintInt64 Execution abnormal.");
267 return nullptr;
268 }
269
270 int64_t resultValue = 0;
271 bool flag = false;
272 status = OH_JSVM_GetValueBigintInt64(env, result, &resultValue, &flag);
273 if (status != JSVM_OK) {
274 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case03:CreateBigintWords Execution abnormal.");
275 return nullptr;
276 }
277
278 bool setValue = true;
279 JSVM_Value retValue = nullptr;
280 OH_JSVM_GetBoolean(env, setValue, &retValue);
281 return retValue;
282 }
283 //"value int64_min-1" + result not null + lossless not null
TestGetValueBigintInt64Case04(JSVM_Env env,JSVM_CallbackInfo info)284 [[maybe_unused]] JSVM_Value TestGetValueBigintInt64Case04(JSVM_Env env, JSVM_CallbackInfo info)
285 {
286 int64_t testValue = INT64_MIN - 1;
287 JSVM_Value result = nullptr;
288 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, testValue, &result);
289 if (status != JSVM_OK) {
290 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case04:CreateBigintInt64 Execution abnormal.");
291 return nullptr;
292 }
293
294 int64_t resultValue = 0;
295 bool flag = false;
296 status = OH_JSVM_GetValueBigintInt64(env, result, &resultValue, &flag);
297 if (status != JSVM_OK) {
298 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case04:CreateBigintWords Execution abnormal.");
299 return nullptr;
300 }
301
302 bool setValue = true;
303 JSVM_Value retValue = nullptr;
304 OH_JSVM_GetBoolean(env, setValue, &retValue);
305 return retValue;
306 }
307 //"value int64_max" + result NULL + lossless not null
TestGetValueBigintInt64Case05(JSVM_Env env,JSVM_CallbackInfo info)308 [[maybe_unused]] JSVM_Value TestGetValueBigintInt64Case05(JSVM_Env env, JSVM_CallbackInfo info)
309 {
310 int64_t testValue = INT64_MAX;
311 JSVM_Value result = nullptr;
312 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, testValue, &result);
313 if (status != JSVM_OK) {
314 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case05:CreateBigintInt64 Execution abnormal.");
315 return nullptr;
316 }
317
318 bool flag = false;
319 status = OH_JSVM_GetValueBigintInt64(env, result, nullptr, &flag);
320 if (status != JSVM_INVALID_ARG) {
321 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case05:CreateBigintWords Execution abnormal.");
322 return nullptr;
323 }
324
325 bool setValue = true;
326 JSVM_Value retValue = nullptr;
327 OH_JSVM_GetBoolean(env, setValue, &retValue);
328 return retValue;
329 }
330 //"value int64_max" + result not null + lossless NULL
TestGetValueBigintInt64Case06(JSVM_Env env,JSVM_CallbackInfo info)331 [[maybe_unused]] JSVM_Value TestGetValueBigintInt64Case06(JSVM_Env env, JSVM_CallbackInfo info)
332 {
333 int64_t testValue = INT64_MAX;
334 JSVM_Value result = nullptr;
335 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, testValue, &result);
336 if (status != JSVM_OK) {
337 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case06:OH_JSVM_CreateBigintInt64 Failed.");
338 return nullptr;
339 }
340
341 int64_t resultValue = 0;
342 status = OH_JSVM_GetValueBigintInt64(env, result, &resultValue, nullptr);
343 if (status == JSVM_OK) {
344 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintInt64Case06:GetValueBigintInt64 Execution abnormal.");
345 return nullptr;
346 }
347
348 bool setValue = true;
349 JSVM_Value retValue = nullptr;
350 OH_JSVM_GetBoolean(env, setValue, &retValue);
351 return retValue;
352 }
353 //OH_JSVM_GetValueBigintUint64:"value Uint64_max+1" + result not null + lossless not null
TestGetValueBigintUint64Case01(JSVM_Env env,JSVM_CallbackInfo info)354 [[maybe_unused]] JSVM_Value TestGetValueBigintUint64Case01(JSVM_Env env, JSVM_CallbackInfo info)
355 {
356 uint64_t testValue = UINT64_MAX + 1;
357 JSVM_Value result = nullptr;
358 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, testValue, &result);
359 if (status != JSVM_OK) {
360 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case01:OH_JSVM_CreateBigintUint64 Failed.");
361 return nullptr;
362 }
363
364 uint64_t resultValue1 = 0;
365 bool flag1 = false;
366 status = OH_JSVM_GetValueBigintUint64(env, result, &resultValue1, &flag1);
367 if (status != JSVM_OK) {
368 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case01:OH_JSVM_GetValueBigintUint64 Failed.");
369 return nullptr;
370 }
371
372 bool setValue = true;
373 JSVM_Value retValue = nullptr;
374 OH_JSVM_GetBoolean(env, setValue, &retValue);
375 return retValue;
376 }
377 //"value Uint64_max" + result not null + lossless not null
TestGetValueBigintUint64Case02(JSVM_Env env,JSVM_CallbackInfo info)378 [[maybe_unused]] JSVM_Value TestGetValueBigintUint64Case02(JSVM_Env env, JSVM_CallbackInfo info)
379 {
380 uint64_t testValue = UINT64_MAX;
381 JSVM_Value result = nullptr;
382 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, testValue, &result);
383 if (status != JSVM_OK) {
384 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case02:OH_JSVM_CreateBigintUint64 Failed.");
385 return nullptr;
386 }
387
388 uint64_t resultValue1 = 0;
389 bool flag1 = false;
390 status = OH_JSVM_GetValueBigintUint64(env, result, &resultValue1, &flag1);
391 if (status != JSVM_OK) {
392 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case02:OH_JSVM_GetValueBigintUint64 Failed.");
393 return nullptr;
394 }
395
396 bool setValue = true;
397 JSVM_Value retValue = nullptr;
398 OH_JSVM_GetBoolean(env, setValue, &retValue);
399 return retValue;
400 }
401 //"value 0" + result not null + lossless not null
TestGetValueBigintUint64Case03(JSVM_Env env,JSVM_CallbackInfo info)402 [[maybe_unused]] JSVM_Value TestGetValueBigintUint64Case03(JSVM_Env env, JSVM_CallbackInfo info)
403 {
404 uint64_t testValue = 0;
405 JSVM_Value result = nullptr;
406 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, testValue, &result);
407 if (status != JSVM_OK) {
408 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case03:OH_JSVM_CreateBigintUint64 Failed.");
409 return nullptr;
410 }
411
412 uint64_t resultValue1 = 0;
413 bool flag1 = false;
414 status = OH_JSVM_GetValueBigintUint64(env, result, &resultValue1, &flag1);
415 if (status != JSVM_OK) {
416 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case03:OH_JSVM_GetValueBigintUint64 Failed.");
417 return nullptr;
418 }
419
420 bool setValue = true;
421 JSVM_Value retValue = nullptr;
422 OH_JSVM_GetBoolean(env, setValue, &retValue);
423 return retValue;
424 }
425 //"value -1" + result not null + lossless not null
TestGetValueBigintUint64Case04(JSVM_Env env,JSVM_CallbackInfo info)426 [[maybe_unused]] JSVM_Value TestGetValueBigintUint64Case04(JSVM_Env env, JSVM_CallbackInfo info)
427 {
428 uint64_t testValue = -1;
429 JSVM_Value result = nullptr;
430 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, testValue, &result);
431 if (status != JSVM_OK) {
432 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case04:OH_JSVM_CreateBigintUint64 Failed.");
433 return nullptr;
434 }
435
436 uint64_t resultValue1 = 0;
437 bool flag1 = false;
438 status = OH_JSVM_GetValueBigintUint64(env, result, &resultValue1, &flag1);
439 if (status != JSVM_OK) {
440 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case04:OH_JSVM_GetValueBigintUint64 Failed.");
441 return nullptr;
442 }
443
444 bool setValue = true;
445 JSVM_Value retValue = nullptr;
446 OH_JSVM_GetBoolean(env, setValue, &retValue);
447 return retValue;
448 }
449 //"value 0" + result NULL + lossless not null
TestGetValueBigintUint64Case05(JSVM_Env env,JSVM_CallbackInfo info)450 [[maybe_unused]] JSVM_Value TestGetValueBigintUint64Case05(JSVM_Env env, JSVM_CallbackInfo info)
451 {
452 uint64_t testValue = 0;
453 JSVM_Value result = nullptr;
454 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, testValue, &result);
455 if (status != JSVM_OK) {
456 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case05:OH_JSVM_CreateBigintUint64 Failed.");
457 return nullptr;
458 }
459
460 bool flag1 = false;
461 status = OH_JSVM_GetValueBigintUint64(env, result, nullptr, &flag1);
462 if (status != JSVM_INVALID_ARG) {
463 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case05:OH_JSVM_GetValueBigintUint64 Failed.");
464 return nullptr;
465 }
466
467 bool setValue = true;
468 JSVM_Value retValue = nullptr;
469 OH_JSVM_GetBoolean(env, setValue, &retValue);
470 return retValue;
471 }
472 //"value 0" + result not null + lossless NULL
TestGetValueBigintUint64Case06(JSVM_Env env,JSVM_CallbackInfo info)473 [[maybe_unused]] JSVM_Value TestGetValueBigintUint64Case06(JSVM_Env env, JSVM_CallbackInfo info)
474 {
475 uint64_t testValue = 0;
476 JSVM_Value result = nullptr;
477 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, testValue, &result);
478 if (status != JSVM_OK) {
479 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case06:OH_JSVM_CreateBigintUint64 Failed.");
480 return nullptr;
481 }
482
483 uint64_t resultValue1 = 0;
484 status = OH_JSVM_GetValueBigintUint64(env, result, &resultValue1, nullptr);
485 if (status != JSVM_INVALID_ARG) {
486 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintUint64Case06:OH_JSVM_GetValueBigintUint64 Failed.");
487 return nullptr;
488 }
489
490 bool setValue = true;
491 JSVM_Value retValue = nullptr;
492 OH_JSVM_GetBoolean(env, setValue, &retValue);
493 return retValue;
494 }
495 //OH_JSVM_GetValueBigintWords:value is BigInt + signBit/wordCount/words not null
TestGetValueBigintWordsCase01(JSVM_Env env,JSVM_CallbackInfo info)496 [[maybe_unused]] JSVM_Value TestGetValueBigintWordsCase01(JSVM_Env env, JSVM_CallbackInfo info)
497 {
498 int signBit = 0;
499 size_t wordCount = 2;
500 uint64_t words[] = {1ULL, 1ULL};
501
502 JSVM_Value rst = nullptr;
503 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &rst);
504 if (status != JSVM_OK) {
505 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase01:OH_JSVM_CreateBigintWords Failed.");
506 return nullptr;
507 }
508
509 int retSignBit = -1;
510 size_t retWordCount = 2;
511 uint64_t wordsOut[] = {0ULL, 0ULL};
512 status = OH_JSVM_GetValueBigintWords(env, rst, &retSignBit, &retWordCount, wordsOut);
513 if (status != JSVM_OK) {
514 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase01:OH_JSVM_GetValueBigintWords Failed.");
515 return nullptr;
516 }
517
518 bool setValue = true;
519 JSVM_Value retValue = nullptr;
520 OH_JSVM_GetBoolean(env, setValue, &retValue);
521 return retValue;
522 }
523 //value is BigInt + signBit NULL + wordCount not null + words not null
TestGetValueBigintWordsCase02(JSVM_Env env,JSVM_CallbackInfo info)524 [[maybe_unused]] JSVM_Value TestGetValueBigintWordsCase02(JSVM_Env env, JSVM_CallbackInfo info)
525 {
526 int signBit = 0;
527 size_t wordCount = 2;
528 uint64_t words[] = {1ULL, 1ULL};
529
530 JSVM_Value rst = nullptr;
531 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &rst);
532 if (status != JSVM_OK) {
533 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase02:OH_JSVM_CreateBigintWords Failed.");
534 return nullptr;
535 }
536
537 size_t retWordCount = 2;
538 uint64_t wordsOut[] = {0ULL, 0ULL};
539 status = OH_JSVM_GetValueBigintWords(env, rst, nullptr, &retWordCount, wordsOut);
540 if (status == JSVM_OK) {
541 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase02:GetValueBigintWords Execution abnormal.");
542 return nullptr;
543 }
544
545 bool setValue = true;
546 JSVM_Value retValue = nullptr;
547 OH_JSVM_GetBoolean(env, setValue, &retValue);
548 return retValue;
549 }
550 //value is BigInt + signBit not null + wordCount NULL + words not null
TestGetValueBigintWordsCase03(JSVM_Env env,JSVM_CallbackInfo info)551 [[maybe_unused]] JSVM_Value TestGetValueBigintWordsCase03(JSVM_Env env, JSVM_CallbackInfo info)
552 {
553 int signBit = 0;
554 size_t wordCount = 2;
555 uint64_t words[] = {1ULL, 1ULL};
556
557 JSVM_Value rst = nullptr;
558 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &rst);
559 if (status != JSVM_OK) {
560 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase03:OH_JSVM_CreateBigintWords Failed.");
561 return nullptr;
562 }
563
564 int retSignBit = 1;
565 uint64_t wordsOut[] = {0ULL, 0ULL};
566 status = OH_JSVM_GetValueBigintWords(env, rst, &retSignBit, nullptr, wordsOut);
567 if (status == JSVM_OK) {
568 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase03:GetValueBigintWords Execution abnormal.");
569 return nullptr;
570 }
571
572 bool setValue = true;
573 JSVM_Value retValue = nullptr;
574 OH_JSVM_GetBoolean(env, setValue, &retValue);
575 return retValue;
576 }
577 //value is BigInt + signBit not null + wordCount not null + words NULL
TestGetValueBigintWordsCase04(JSVM_Env env,JSVM_CallbackInfo info)578 [[maybe_unused]] JSVM_Value TestGetValueBigintWordsCase04(JSVM_Env env, JSVM_CallbackInfo info)
579 {
580 int signBit = 0;
581 size_t wordCount = 2;
582 uint64_t words[] = {1ULL, 1ULL};
583
584 JSVM_Value rst = nullptr;
585 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &rst);
586 if (status != JSVM_OK) {
587 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase04:OH_JSVM_CreateBigintWords Failed.");
588 return nullptr;
589 }
590
591 int retSignBit = -1;
592 size_t retWordCount = 2;
593 status = OH_JSVM_GetValueBigintWords(env, rst, &retSignBit, &retWordCount, nullptr);
594 if (status == JSVM_OK) {
595 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase04:GetValueBigintWords Execution abnormal.");
596 return nullptr;
597 }
598
599 bool setValue = true;
600 JSVM_Value retValue = nullptr;
601 OH_JSVM_GetBoolean(env, setValue, &retValue);
602 return retValue;
603 }
604 //value is BigInt + signBit NULL + wordCount not null + words NULL
TestGetValueBigintWordsCase05(JSVM_Env env,JSVM_CallbackInfo info)605 [[maybe_unused]] JSVM_Value TestGetValueBigintWordsCase05(JSVM_Env env, JSVM_CallbackInfo info)
606 {
607 int signBit = 0;
608 size_t wordCount = 1;
609 uint64_t words[] = {0ULL};
610
611 JSVM_Value rst = nullptr;
612 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &rst);
613 if (status != JSVM_OK) {
614 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase05:OH_JSVM_CreateBigintWords Failed.");
615 return nullptr;
616 }
617
618 size_t retWordCount = 2;
619 status = OH_JSVM_GetValueBigintWords(env, rst, nullptr, &retWordCount, nullptr);
620 if (status != JSVM_OK) {
621 OH_JSVM_ThrowError(env, nullptr, "TestGetValueBigintWordsCase05:GetValueBigintWords Failed.");
622 return nullptr;
623 }
624
625 bool setValue = true;
626 JSVM_Value retValue = nullptr;
627 OH_JSVM_GetBoolean(env, setValue, &retValue);
628 return retValue;
629 }
630 //APICombination:CreateBigintInt64 -> GetValueBigintInt64 Same as the input value of int64 -> GetValueBigintUint64->
631 //GetValueBigintWords signBit Return the actual value, wordCount is 1, words Return the actual value
TestCreateAndGetBigIntProgramCase01(JSVM_Env env,JSVM_CallbackInfo info)632 [[maybe_unused]] JSVM_Value TestCreateAndGetBigIntProgramCase01(JSVM_Env env, JSVM_CallbackInfo info)
633 {
634 int64_t testValue = -10;
635 JSVM_Value result = nullptr;
636 JSVM_Status status = OH_JSVM_CreateBigintInt64(env, testValue, &result);
637 if (status != JSVM_OK) {
638 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase01:OH_JSVM_CreateBigintInt64 Failed.");
639 return nullptr;
640 }
641
642 bool flag = false;
643 int64_t resultValue = 0;
644 status = OH_JSVM_GetValueBigintInt64(env, result, &resultValue, &flag);
645 if (status != JSVM_OK || !flag || resultValue != testValue) {
646 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase01:OH_JSVM_GetValueBigintInt64 Failed.");
647 return nullptr;
648 }
649
650 uint64_t resultValue1 = 0;
651 bool flag1 = false;
652 status = OH_JSVM_GetValueBigintUint64(env, result, &resultValue1, &flag1);
653 if (status != JSVM_OK) {
654 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase01:OH_JSVM_GetValueBigintUint64 Failed.");
655 return nullptr;
656 }
657 if (flag1) {
658 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase01:OH_JSVM_GetValueBigintUint64 data loss.");
659 return nullptr;
660 }
661
662 int retSignBit = -1;
663 size_t retWordCount = 5;
664 uint64_t wordsOut[] = {0ULL, 0ULL};
665 status = OH_JSVM_GetValueBigintWords(env, result, &retSignBit, &retWordCount, wordsOut);
666 if (status != JSVM_OK) {
667 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase01:OH_JSVM_GetValueBigintWords Failed.");
668 return nullptr;
669 }
670 size_t testNum = 10;
671 if (retWordCount != 1 || wordsOut[0] != testNum) {
672 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase01:GetValueBigintWords count error.");
673 return nullptr;
674 }
675
676 bool setValue = true;
677 JSVM_Value retValue = nullptr;
678 OH_JSVM_GetBoolean(env, setValue, &retValue);
679 return retValue;
680 }
681 //CreateBigintUint64 -> GetValueBigintUint64 -> GetValueBigintInt64 -> GetValueBigintWords ->
682 //signBit is 0,wordCount is 1,words return actual value
TestCreateAndGetBigIntProgramCase02(JSVM_Env env,JSVM_CallbackInfo info)683 [[maybe_unused]] JSVM_Value TestCreateAndGetBigIntProgramCase02(JSVM_Env env, JSVM_CallbackInfo info)
684 {
685 uint64_t testValue = 10;
686 JSVM_Value result = nullptr;
687 JSVM_Status status = OH_JSVM_CreateBigintUint64(env, testValue, &result);
688 if (status != JSVM_OK) {
689 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase02:OH_JSVM_CreateBigintUint64 Failed.");
690 return nullptr;
691 }
692
693 uint64_t resultValue = 0;
694 bool flag = false;
695 status = OH_JSVM_GetValueBigintUint64(env, result, &resultValue, &flag);
696 if (status != JSVM_OK || !flag) {
697 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase02:OH_JSVM_GetValueBigintUint64 Failed.");
698 return nullptr;
699 }
700 if (resultValue != testValue) {
701 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase02:GetValueBigintUint64 Value Failed.");
702 return nullptr;
703 }
704
705 bool flag1 = false;
706 int64_t resultValue1 = 0;
707 status = OH_JSVM_GetValueBigintInt64(env, result, &resultValue1, &flag1);
708 if (status != JSVM_OK || !flag1 || resultValue1 != testValue) {
709 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase02:OH_JSVM_GetValueBigintInt64 Failed.");
710 return nullptr;
711 }
712
713 int retSignBit = 1;
714 size_t retWordCount = 2;
715 uint64_t wordsOut[] = {1ULL, 0ULL};
716 status = OH_JSVM_GetValueBigintWords(env, result, &retSignBit, &retWordCount, wordsOut);
717 if (status != JSVM_OK) {
718 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase02:OH_JSVM_GetValueBigintWords Failed.");
719 return nullptr;
720 }
721 if (retSignBit != 0) {
722 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase02:GetValueBigintWords retSignBit error.");
723 return nullptr;
724 }
725 if (retWordCount != 1 || wordsOut[0] != testValue) {
726 OH_JSVM_ThrowError(env,
727 nullptr,
728 "TestCreateAndGetBigIntProgramCase02:GetValueBigintWords retWordCount Failed.");
729 return nullptr;
730 }
731
732 bool setValue = true;
733 JSVM_Value retValue = nullptr;
734 OH_JSVM_GetBoolean(env, setValue, &retValue);
735 return retValue;
736 }
737 //CreateBigintWords uint64 argc <-> Js Bigint -> GetValueBigintInt64,compare values -> GetValueBigintUint64
738 //-> GetValueBigintWords,signBit actual symbol value,wordCount is argc length,words actual value.
TestCreateAndGetBigIntProgramCase03(JSVM_Env env,JSVM_CallbackInfo info)739 [[maybe_unused]] JSVM_Value TestCreateAndGetBigIntProgramCase03(JSVM_Env env, JSVM_CallbackInfo info)
740 {
741 int signBit = 0;
742 size_t wordCount = 2;
743 size_t testNum = 4;
744 uint64_t words[] = {4, 5};
745 JSVM_Value result = nullptr;
746 JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &result);
747 int64_t resultValue = 0;
748 bool flag = false;
749 status = OH_JSVM_GetValueBigintInt64(env, result, &resultValue, &flag);
750 if (status != JSVM_OK) {
751 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase03:OH_JSVM_GetValueBigintInt64 Failed.");
752 return nullptr;
753 }
754 if (resultValue != testNum) {
755 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase03:OH_JSVM_GetValueBigintInt64 Failed.");
756 return nullptr;
757 }
758 uint64_t resultValue1 = 0;
759 bool flag1 = false;
760 status = OH_JSVM_GetValueBigintUint64(env, result, &resultValue1, &flag1);
761 if (status != JSVM_OK) {
762 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase03:OH_JSVM_GetValueBigintUint64 Failed.");
763 return nullptr;
764 }
765 if (flag1) {
766 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase03:GetValueBigintUint64 flag Abnormal.");
767 return nullptr;
768 }
769 if (resultValue1 != testNum) {
770 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase03:GetValueBigintUint64 Value Abnormal.");
771 return nullptr;
772 }
773
774 int retSignBit = 1;
775 size_t retWordCount = 3;
776 uint64_t wordsOut[] = {0ULL, 0ULL};
777 status = OH_JSVM_GetValueBigintWords(env, result, &retSignBit, &retWordCount, wordsOut);
778 if (status != JSVM_OK) {
779 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase03:OH_JSVM_GetValueBigintWords Failed.");
780 return nullptr;
781 }
782 if (retWordCount != wordCount || wordsOut[0] != testNum) {
783 OH_JSVM_ThrowError(env, nullptr, "TestCreateAndGetBigIntProgramCase03:GetValueBigintWords WordCount Failed.");
784 return nullptr;
785 }
786
787 bool setValue = true;
788 JSVM_Value retValue = nullptr;
789 OH_JSVM_GetBoolean(env, setValue, &retValue);
790 return retValue;
791 }