1/* 2 * Copyright (c) 2025 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 */ 15import {BusinessError} from "@ohos.base"; 16import * as ArrayTest from "array_test"; 17 18loadLibrary("ani_array"); 19 20function sumArray() { 21 let numbers: int[] = [1, 2, 3, 4, 5]; 22 let sum = ArrayTest.sumArray(numbers, 100) 23 console.log("sum is " + sum) 24 assertEQ(sum, 115) 25} 26 27function getArrayValue() { 28 let nums: long[] = [35, 45, 55]; 29 let res = ArrayTest.getArrayValue(nums, 2) 30 console.log("index 2 is " + res) 31 assertEQ(res, 55) 32} 33 34function toStingArray() { 35 let nums: int[] = [35, 45, 55]; 36 let res = ArrayTest.toStingArray(nums) 37 console.log("new array is " + res) 38 assertEQ(res.length, nums.length) 39 for (let i = 0; i < res.length; i++) { 40 assertEQ(res[i], `${nums[i]}`) 41 } 42} 43 44function makeIntArray() { 45 let arr = ArrayTest.makeIntArray(5, 3) 46 console.log("new array is " + arr) 47 assertEQ(arr.length, 3) 48 for (let i = 0; i < arr.length; i++) { 49 assertEQ(arr[i], 5) 50 } 51} 52 53function makeEnumArray() { 54 let arr = ArrayTest.makeEnumArray(ArrayTest.Color.GREEN, 5) 55 console.log("new array is " + arr) 56 assertEQ(arr.length, 5) 57 for (let i = 0; i < arr.length; i++) { 58 assertEQ(arr[i], ArrayTest.Color.GREEN) 59 } 60} 61 62function makeRecordArray() { 63 let arr = ArrayTest.makeRecordArray("k", 128, 3) 64 console.log("new array is " + arr) 65 assertEQ(arr.length, 3) 66 for (let i = 0; i < arr.length; i++) { 67 assertEQ(arr[i]["k"], 128) 68 } 69} 70 71function makeStructArray() { 72 let arr = ArrayTest.makeStructArray("a", "b", 5, 3) 73 console.log("new array is " + arr) 74 assertEQ(arr.length, 3) 75 for (let i = 0; i < arr.length; i++) { 76 assertEQ(arr[i].a, "a") 77 assertEQ(arr[i].b, "b") 78 assertEQ(arr[i].c, 5) 79 } 80} 81 82function makeIntArray2() { 83 let arr = ArrayTest.makeIntArray(5, 3); 84 let arr2 = ArrayTest.makeIntArray2(arr, 3); 85 assertEQ(arr2.length, 3); 86 for (let i = 0; i < arr2.length; i++) { 87 assertEQ(arr2[i].length, 3) 88 } 89} 90 91function changeEnumArray() { 92 let arr = ArrayTest.makeEnumArray(ArrayTest.Color.GREEN, 5); 93 let arr2 = ArrayTest.changeEnumArray(arr, ArrayTest.Color.BLUE); 94 assertEQ(arr.length, arr2.length) 95 for (let i = 0; i < arr2.length; i++) { 96 assertEQ(arr2[i], ArrayTest.Color.BLUE) 97 } 98} 99 100function changeRecordArray() { 101 let arr = ArrayTest.makeRecordArray("k", 128, 3) 102 let arr2 = ArrayTest.changeRecordArray(arr, "v", 21); 103 assertEQ(arr.length, arr2.length) 104 for (let i = 0; i < arr2.length; i++) { 105 assertEQ(arr2[i]["v"], 21) 106 } 107} 108 109function changeStructArray() { 110 let arr = ArrayTest.makeStructArray("a", "b", 5, 3) 111 let arr2 = ArrayTest.changeStructArray(arr, "aa", "bb", 3); 112 assertEQ(arr.length, arr2.length) 113 for (let i = 0; i < arr2.length; i++) { 114 assertEQ(arr2[i].a, "aa") 115 assertEQ(arr2[i].b, "bb") 116 assertEQ(arr2[i].c, 3) 117 } 118} 119 120function fetchBinaryData() { 121 let promise = new Promise<Array<float>>( 122 (resolve, reject) => {ArrayTest.fetchBinaryData( 123 5, (error: BusinessError, data: Array<float>) => { 124 if (error.code !== 0) { 125 reject(error); 126 } else { 127 resolve(data); 128 } 129 })}); 130 let data: Array<float> = new Array<float>(0); 131 let error: BusinessError; 132 try { 133 data = await promise; 134 } catch (e) { 135 error = e as BusinessError; 136 } 137 assertEQ(data.length, 5); 138} 139 140function makeStructArrayArray() { 141 let arr = ArrayTest.makeStructArrayArray("a", "b", 5, 2, 3) 142 console.log("new array is " + arr) 143 assertEQ(arr.length, 3) 144 assertEQ(arr[0].length, 2) 145 for (let i = 0; i < arr.length; i++) { 146 for (let j = 0; j < arr[i].length; j++) { 147 assertEQ(arr[i][j].a, "a") 148 assertEQ(arr[i][j].b, "b") 149 assertEQ(arr[i][j].c, 5) 150 } 151 } 152} 153 154function test_ani_array_with_arrayi8() { 155 let arrayi8: ArrayTest.ArrayI8 = ArrayTest.getArrayI8(); 156 let info = arrayi8.arrayI8Value(127 as byte); 157 158 console.log("arrayi8.arrayI8Value is: " + info); 159 assertEQ(info[0], 127 as byte); 160} 161 162function test_ani_array_with_arrayi16() { 163 let arrayi16: ArrayTest.ArrayI16 = ArrayTest.getArrayI16(); 164 let info = arrayi16.arrayI16Value(-32768 as short); 165 166 console.log("arrayi16.arrayI16Value is: " + info); 167 assertEQ(info[0], -32768 as short); 168} 169 170function test_ani_array_with_arrayi32() { 171 let arrayi32: ArrayTest.ArrayI32 = ArrayTest.getArrayI32(); 172 let info = arrayi32.arrayI32Value(2147483647 as int); 173 174 console.log("arrayi32.arrayI32Value is: " + info); 175 assertEQ(info[0], 2147483647 as int); 176} 177 178function test_ani_array_with_arrayi64() { 179 let arrayi64: ArrayTest.ArrayI64 = ArrayTest.getArrayI64(); 180 let info = arrayi64.arrayI64Value(-9223372036854775808 as long); 181 182 console.log("arrayi64.arrayI64Value is: " + info); 183 assertEQ(info[0], -9223372036854775808 as long); 184} 185 186function test_ani_array_with_arrayf32() { 187 let arrayf32: ArrayTest.ArrayF32 = ArrayTest.getArrayF32(); 188 let info = arrayf32.arrayF32Value(202510.25 as float); 189 190 console.log("arrayf32.arrayF32Value is: " + info); 191 assertEQ(info[0], 202510.25 as float); 192} 193 194function test_ani_array_with_arrayf64() { 195 let arrayf64: ArrayTest.ArrayF64 = ArrayTest.getArrayF64(); 196 let info = arrayf64.arrayF64Value(20250521.1027 as double); 197 198 console.log("arrayf64.arrayF64Value is: " + info); 199 assertEQ(info[0], 20250521.1027 as double); 200} 201 202function test_ani_array_with_arrayString() { 203 let arrayString: ArrayTest.ArrayString = ArrayTest.getArrayString(); 204 let info = arrayString.arrayStringValue("20250521.1035"); 205 206 console.log("arrayString.arrayStringValue is: " + info); 207 assertEQ(info[0], "20250521.1035"); 208} 209 210function test_ani_array_with_arrayBool() { 211 let arrayBool: ArrayTest.ArrayBool = ArrayTest.getArrayBool(); 212 let info = arrayBool.arrayBoolValue(true); 213 214 console.log("arrayBool.arrayBoolValue is: " + info); 215 assertEQ(info[0], true); 216} 217 218function test_ani_array_with_arrayEnum() { 219 let arr: ArrayTest.ArrayEnum = ArrayTest.getArrayEnum(); 220 let info = arr.arrayEnumValue("Color"); 221 222 console.log("arr.arrayEnumValue is: " + info); 223 assertEQ(info[0], ArrayTest.Color.RED); 224} 225 226function test_ani_array_with_arrayRecord() { 227 let arr: ArrayTest.ArrayRecord = ArrayTest.getArrayRecord(); 228 let info = arr.arrayRecordValue("Color", 255 as long); 229 230 console.log("arr.arrayRecordValue is: " + info); 231 assertEQ(info[0].size, 1); 232} 233 234function test_ani_array_with_arrayRecord_stri8() { 235 let arr: ArrayTest.ArrayRecordStrI8 = ArrayTest.getArrayRecordStrI8(); 236 let info = arr.arrayRecordValue("Color", 127 as byte); 237 238 console.log("arr.arrayRecordValue is: " + info); 239 assertEQ(info[0].size, 1); 240} 241 242function test_ani_array_with_arrayRecord_strf32() { 243 let arr: ArrayTest.ArrayRecordStrF32 = ArrayTest.getArrayRecordStrF32(); 244 let info = arr.arrayRecordValue("Color", 52115.24 as float); 245 246 console.log("arr.arrayRecordValue is: " + info); 247 assertEQ(info[0].size, 1); 248} 249 250function test_ani_array_with_arrayRecord_strf64() { 251 let arr: ArrayTest.ArrayRecordStrF64 = ArrayTest.getArrayRecordStrF64(); 252 let info = arr.arrayRecordValue("Color", 202552115.24 as double); 253 254 console.log("arr.arrayRecordValue is: " + info); 255 assertEQ(info[0].size, 1); 256} 257 258function test_ani_array_with_arrayRecord_strbool() { 259 let arr: ArrayTest.ArrayRecordStrBool = ArrayTest.getArrayRecordStrBool(); 260 let info = arr.arrayRecordValue("Color", true); 261 262 console.log("arr.arrayRecordValue is: " + info); 263 assertEQ(info[0].size, 1); 264} 265 266function test_ani_array_with_union() { 267 let arr: ArrayTest.ArrayUnion = ArrayTest.getArrayUnion(); 268 let info = arr.arrayValue("Color"); 269 270 console.log("arr.arrayValue is: " + info); 271 assertEQ(info[0], "Color"); 272} 273 274let arrI8: ArrayTest.ArrayPromiseI8 = ArrayTest.getArrayPromiseI8(); 275let arrI16: ArrayTest.ArrayPromiseI16 = ArrayTest.getArrayPromiseI16(); 276let arrI32: ArrayTest.ArrayPromiseI32 = ArrayTest.getArrayPromiseI32(); 277let arrI64: ArrayTest.ArrayPromiseI64 = ArrayTest.getArrayPromiseI64(); 278let arrF32: ArrayTest.ArrayPromiseF32 = ArrayTest.getArrayPromiseF32(); 279let arrF64: ArrayTest.ArrayPromiseF64 = ArrayTest.getArrayPromiseF64(); 280let arrStr: ArrayTest.ArrayPromiseString = ArrayTest.getArrayPromiseString(); 281let arrBool: ArrayTest.ArrayPromiseBool = ArrayTest.getArrayPromiseBool(); 282let arrU8: ArrayTest.ArrayPromiseU8 = ArrayTest.getArrayPromiseU8(); 283let arrU16: ArrayTest.ArrayPromiseU16 = ArrayTest.getArrayPromiseU16(); 284function test_ani_array_with_PromiseI8() { 285 let info: byte[] = new Array<byte>(0); 286 let err: BusinessError = new BusinessError(); 287 try { 288 info = arrI8.fetchDataI8(); 289 } catch (e) { 290 err = e as BusinessError; 291 } 292 293 console.log("arr.fetchDataI8 is: " + info); 294 assertEQ(info[0], -128 as byte); 295} 296 297function test_ani_array_with_PromiseI8_sync() { 298 let promise = new Promise<byte[]>((resolve, reject) => { 299 arrI8.fetchData((err: BusinessError, data: byte[]) => { 300 if (err.code !== 0) { 301 reject(err); 302 } else { 303 resolve(data); 304 } 305 }); 306 }); 307 let info: byte[] = new Array<byte>(0); 308 let err: BusinessError = new BusinessError(); 309 try { 310 info = await promise; 311 console.log("info is: " + info); 312 } catch (e) { 313 err = e as BusinessError; 314 } 315 assertEQ(info[0], -128 as byte); 316} 317 318function test_ani_array_with_PromiseI8_promise() { 319 let info: byte[] = new Array<byte>(0); 320 let err: BusinessError = new BusinessError(); 321 try { 322 info = await arrI8.fetchData(); 323 } catch (e) { 324 err = e as BusinessError; 325 } 326 assertEQ(info[0], -128 as byte); 327} 328 329function test_ani_array_with_PromiseI16() { 330 let info: short[] = new Array<short>(0); 331 let err: BusinessError = new BusinessError(); 332 try { 333 info = arrI16.fetchDataI16(); 334 } catch (e) { 335 err = e as BusinessError; 336 } 337 338 console.log("arr.fetchDataI16 is: " + info); 339 assertEQ(info[0], -32768 as short); 340} 341 342function test_ani_array_with_PromiseI16_sync() { 343 let promise = new Promise<short[]>((resolve, reject) => { 344 arrI16.fetchData((err: BusinessError, data: short[]) => { 345 if (err.code !== 0) { 346 reject(err); 347 } else { 348 resolve(data); 349 } 350 }); 351 }); 352 let info: short[] = new Array<short>(0); 353 let err: BusinessError = new BusinessError(); 354 try { 355 info = await promise; 356 console.log("info is: " + info); 357 } catch (e) { 358 err = e as BusinessError; 359 } 360 assertEQ(info[0], -32768 as short); 361} 362 363function test_ani_array_with_PromiseI16_promise() { 364 let info: short[] = new Array<short>(0); 365 let err: BusinessError = new BusinessError(); 366 try { 367 info = await arrI16.fetchData(); 368 } catch (e) { 369 err = e as BusinessError; 370 } 371 assertEQ(info[0], -32768 as short); 372} 373 374function test_ani_array_with_PromiseI32() { 375 let info: int[] = new Array<int>(0); 376 let err: BusinessError = new BusinessError(); 377 try { 378 info = arrI32.fetchDataI32(); 379 } catch (e) { 380 err = e as BusinessError; 381 } 382 383 console.log("arr.fetchDataI32 is: " + info); 384 assertEQ(info[0], -2147483648); 385} 386 387function test_ani_array_with_PromiseI32_sync() { 388 let promise = new Promise<int[]>((resolve, reject) => { 389 arrI32.fetchData((err: BusinessError, data: int[]) => { 390 if (err.code !== 0) { 391 reject(err); 392 } else { 393 resolve(data); 394 } 395 }); 396 }); 397 let info: int[] = new Array<int>(0); 398 let err: BusinessError = new BusinessError(); 399 try { 400 info = await promise; 401 console.log("info is: " + info); 402 } catch (e) { 403 err = e as BusinessError; 404 } 405 assertEQ(info[0], -2147483648); 406} 407 408function test_ani_array_with_PromiseI32_promise() { 409 let info: int[] = new Array<int>(0); 410 let err: BusinessError = new BusinessError(); 411 try { 412 info = await arrI32.fetchData(); 413 } catch (e) { 414 err = e as BusinessError; 415 } 416 assertEQ(info[0], -2147483648); 417} 418 419function test_ani_array_with_PromiseI64() { 420 let info: long[] = new Array<long>(0); 421 let err: BusinessError = new BusinessError(); 422 try { 423 info = arrI64.fetchDataI64(); 424 } catch (e) { 425 err = e as BusinessError; 426 } 427 428 console.log("arr.fetchDataI64 is: " + info); 429 assertEQ(info[0], -9223372036854775807 as long); 430} 431 432function test_ani_array_with_PromiseI64_sync() { 433 let promise = new Promise<long[]>((resolve, reject) => { 434 arrI64.fetchData((err: BusinessError, data: long[]) => { 435 if (err.code !== 0) { 436 reject(err); 437 } else { 438 resolve(data); 439 } 440 }); 441 }); 442 let info: long[] = new Array<long>(0); 443 let err: BusinessError = new BusinessError(); 444 try { 445 info = await promise; 446 console.log("info is: " + info); 447 } catch (e) { 448 err = e as BusinessError; 449 } 450 assertEQ(info[0], -9223372036854775807 as long); 451} 452 453function test_ani_array_with_PromiseI64_promise() { 454 let info: long[] = new Array<long>(0); 455 let err: BusinessError = new BusinessError(); 456 try { 457 info = await arrI64.fetchData(); 458 } catch (e) { 459 err = e as BusinessError; 460 } 461 assertEQ(info[0], -9223372036854775807 as long); 462} 463 464function test_ani_array_with_PromiseF32() { 465 let info: float[] = new Array<float>(0); 466 let err: BusinessError = new BusinessError(); 467 try { 468 info = arrF32.fetchDataF32(); 469 } catch (e) { 470 err = e as BusinessError; 471 } 472 473 console.log("arr.fetchDataF32 is: " + info); 474 assertEQ(info[0], -202505.22 as float); 475} 476 477function test_ani_array_with_PromiseF32_sync() { 478 let promise = new Promise<float[]>((resolve, reject) => { 479 arrF32.fetchData((err: BusinessError, data: float[]) => { 480 if (err.code !== 0) { 481 reject(err); 482 } else { 483 resolve(data); 484 } 485 }); 486 }); 487 let info: float[] = new Array<float>(0); 488 let err: BusinessError = new BusinessError(); 489 try { 490 info = await promise; 491 console.log("info is: " + info); 492 } catch (e) { 493 err = e as BusinessError; 494 } 495 assertEQ(info[0], -202505.22 as float); 496} 497 498function test_ani_array_with_PromiseF32_promise() { 499 let info: float[] = new Array<float>(0); 500 let err: BusinessError = new BusinessError(); 501 try { 502 info = await arrF32.fetchData(); 503 } catch (e) { 504 err = e as BusinessError; 505 } 506 assertEQ(info[0], -202505.22 as float); 507} 508 509function test_ani_array_with_PromiseF64() { 510 let info: double[] = new Array<double>(0); 511 let err: BusinessError = new BusinessError(); 512 try { 513 info = arrF64.fetchDataF64(); 514 } catch (e) { 515 err = e as BusinessError; 516 } 517 518 console.log("arr.fetchDataF64 is: " + info); 519 assertEQ(info[0], -202505.221539 as double); 520} 521 522function test_ani_array_with_PromiseF64_sync() { 523 let promise = new Promise<double[]>((resolve, reject) => { 524 arrF64.fetchData((err: BusinessError, data: double[]) => { 525 if (err.code !== 0) { 526 reject(err); 527 } else { 528 resolve(data); 529 } 530 }); 531 }); 532 let info: double[] = new Array<double>(0); 533 let err: BusinessError = new BusinessError(); 534 try { 535 info = await promise; 536 console.log("info is: " + info); 537 } catch (e) { 538 err = e as BusinessError; 539 } 540 assertEQ(info[0], -202505.221539 as double); 541} 542 543function test_ani_array_with_PromiseF64_promise() { 544 let info: double[] = new Array<double>(0); 545 let err: BusinessError = new BusinessError(); 546 try { 547 info = await arrF64.fetchData(); 548 } catch (e) { 549 err = e as BusinessError; 550 } 551 assertEQ(info[0], -202505.221539 as double); 552} 553 554function test_ani_array_with_PromiseString() { 555 let info: string[] = new Array<string>(0); 556 let err: BusinessError = new BusinessError(); 557 try { 558 info = arrStr.fetchDataString(); 559 } catch (e) { 560 err = e as BusinessError; 561 } 562 563 console.log("arr.fetchDataString is: " + info); 564 assertEQ(info[0], "String"); 565} 566 567function test_ani_array_with_PromiseString_sync() { 568 let promise = new Promise<string[]>((resolve, reject) => { 569 arrStr.fetchData((err: BusinessError, data: string[]) => { 570 if (err.code !== 0) { 571 reject(err); 572 } else { 573 resolve(data); 574 } 575 }); 576 }); 577 let info: string[] = new Array<string>(0); 578 let err: BusinessError = new BusinessError(); 579 try { 580 info = await promise; 581 console.log("info is: " + info); 582 } catch (e) { 583 err = e as BusinessError; 584 } 585 assertEQ(info[0], "String"); 586} 587 588function test_ani_array_with_PromiseString_promise() { 589 let info: string[] = new Array<string>(0); 590 let err: BusinessError = new BusinessError(); 591 try { 592 info = await arrStr.fetchData(); 593 } catch (e) { 594 err = e as BusinessError; 595 } 596 assertEQ(info[0], "String"); 597} 598 599function test_ani_array_with_PromiseBool() { 600 let info: boolean[] = new Array<boolean>(0); 601 let err: BusinessError = new BusinessError(); 602 try { 603 info = arrBool.fetchDataBool(); 604 } catch (e) { 605 err = e as BusinessError; 606 } 607 608 console.log("arr.fetchDataBool is: " + info); 609 assertEQ(info[0], true); 610} 611 612function test_ani_array_with_PromiseBool_sync() { 613 let promise = new Promise<boolean[]>((resolve, reject) => { 614 arrBool.fetchData((err: BusinessError, data: boolean[]) => { 615 if (err.code !== 0) { 616 reject(err); 617 } else { 618 resolve(data); 619 } 620 }); 621 }); 622 let info: boolean[] = new Array<boolean>(0); 623 let err: BusinessError = new BusinessError(); 624 try { 625 info = await promise; 626 console.log("info is: " + info); 627 } catch (e) { 628 err = e as BusinessError; 629 } 630 assertEQ(info[0], true); 631} 632 633function test_ani_array_with_PromiseBool_promise() { 634 let info: boolean[] = new Array<boolean>(0); 635 let err: BusinessError = new BusinessError(); 636 try { 637 info = await arrBool.fetchData(); 638 } catch (e) { 639 err = e as BusinessError; 640 } 641 assertEQ(info[0], true); 642} 643 644function test_ani_array_with_PromiseU8() { 645 let a = new ArrayBuffer(10); 646 let info = new Uint8Array(a); 647 let err: BusinessError = new BusinessError(); 648 try { 649 info = arrU8.fetchDataPro(); 650 } catch (e) { 651 err = e as BusinessError; 652 } 653 654 console.log("arr.fetchDataPro is: " + info); 655 assertEQ(info[1], 255); 656} 657 658function test_ani_array_with_PromiseU8_sync() { 659 let promise = new Promise<Uint8Array>((resolve, reject) => { 660 arrU8.fetchData((err: BusinessError, data: Uint8Array) => { 661 if (err.code !== 0) { 662 reject(err); 663 } else { 664 resolve(data); 665 } 666 }); 667 }); 668 let info: Uint8Array = new Uint8Array(0); 669 let err: BusinessError = new BusinessError(); 670 try { 671 info = await promise; 672 console.log("info is: " + info); 673 } catch (e) { 674 err = e as BusinessError; 675 } 676 assertEQ(info[1], 255); 677} 678 679function test_ani_array_with_PromiseU8_promise() { 680 let info: Uint8Array = new Uint8Array(0); 681 let err: BusinessError = new BusinessError(); 682 try { 683 info = await arrU8.fetchData(); 684 } catch (e) { 685 err = e as BusinessError; 686 } 687 assertEQ(info[1], 255); 688} 689 690function test_ani_array_with_PromiseU16() { 691 let info: Uint16Array = new Uint16Array(0); 692 let err: BusinessError = new BusinessError(); 693 try { 694 info = arrU16.fetchDataPro(); 695 } catch (e) { 696 err = e as BusinessError; 697 } 698 699 console.log("arr.fetchDataPro is: " + info); 700 assertEQ(info[1], 65535); 701} 702 703function test_ani_array_with_PromiseU16_sync() { 704 let promise = new Promise<Uint16Array>((resolve, reject) => { 705 arrU16.fetchData((err: BusinessError, data: Uint16Array) => { 706 if (err.code !== 0) { 707 reject(err); 708 } else { 709 resolve(data); 710 } 711 }); 712 }); 713 let info: Uint16Array = new Uint16Array(0); 714 let err: BusinessError = new BusinessError(); 715 try { 716 info = await promise; 717 console.log("info is: " + info); 718 } catch (e) { 719 err = e as BusinessError; 720 } 721 assertEQ(info[1], 65535); 722} 723 724function test_ani_array_with_PromiseU16_promise() { 725 let info: Uint16Array = new Uint16Array(0); 726 let err: BusinessError = new BusinessError(); 727 try { 728 info = await arrU16.fetchData(); 729 } catch (e) { 730 err = e as BusinessError; 731 } 732 assertEQ(info[1], 65535); 733} 734 735let arrNest: ArrayTest.ArrayNest = ArrayTest.getArrayNest(); 736function test_ani_array_with_nest_i8() { 737 let info = arrNest.arrayNestI8(120 as byte); 738 739 console.log("arrNest.ArrayNestI8 is: " + info); 740 assertEQ(info.length, 4); 741} 742 743function test_ani_array_with_nest_i16() { 744 let info = arrNest.arrayNestI16(32700 as short); 745 746 console.log("arrNest.ArrayNestI16 is: " + info); 747 assertEQ(info.length, 4); 748} 749 750function test_ani_array_with_nest_f32() { 751 let info = arrNest.arrayNestF32(202505.28 as float); 752 753 console.log("arrNest.ArrayNestF32 is: " + info); 754 assertEQ(info.length, 4); 755} 756 757function test_ani_array_with_nest_string() { 758 let info = arrNest.arrayNestStrng("0528"); 759 760 console.log("arrNest.ArrayNestStrng is: " + info); 761 assertEQ(info.length, 4); 762} 763 764function test_ani_array_with_nest_bool() { 765 let info = arrNest.arrayNestBool(true); 766 767 console.log("arrNest.ArrayNestBool is: " + info); 768 assertEQ(info.length, 3); 769} 770 771function test_ani_array_with_optional() { 772 let arrOpt: ArrayTest.ArrayOptional = ArrayTest.getArrayOptional(); 773 let info = arrOpt.arrayOpt("optional"); 774 775 console.log("arrOpt.arrayOpt is: " + info); 776 assertEQ(info?.[0], "optional"); 777} 778 779function main() { 780 console.log("run main ... ArrayTest ...") 781 const suite = new ArkTestsuite("ArrayTest") 782 783 suite.addTest("sumArray", sumArray) 784 suite.addTest("getArrayValue", getArrayValue) 785 suite.addTest("toStingArray", toStingArray) 786 suite.addTest("makeIntArray", makeIntArray) 787 suite.addTest("makeIntArray2", makeIntArray2) 788 suite.addTest("makeEnumArray", makeEnumArray) 789 suite.addTest("changeEnumArray", changeEnumArray) 790 suite.addTest("makeRecordArray", makeRecordArray) 791 suite.addTest("changeRecordArray", changeRecordArray) 792 suite.addTest("makeStructArray", makeStructArray) 793 suite.addTest("changeStructArray", changeStructArray) 794 suite.addTest("fetchBinaryData", fetchBinaryData) 795 suite.addTest("makeStructArrayArray", makeStructArrayArray) 796 797 suite.addTest("test_ani_array_with_arrayi8", test_ani_array_with_arrayi8) 798 suite.addTest("test_ani_array_with_arrayi16", test_ani_array_with_arrayi16) 799 suite.addTest("test_ani_array_with_arrayi32", test_ani_array_with_arrayi32) 800 suite.addTest("test_ani_array_with_arrayi64", test_ani_array_with_arrayi64) 801 suite.addTest("test_ani_array_with_arrayf32", test_ani_array_with_arrayf32) 802 suite.addTest("test_ani_array_with_arrayf64", test_ani_array_with_arrayf64) 803 suite.addTest("test_ani_array_with_arrayString", test_ani_array_with_arrayString) 804 suite.addTest("test_ani_array_with_arrayBool", test_ani_array_with_arrayBool) 805 suite.addTest("test_ani_array_with_arrayEnum", test_ani_array_with_arrayEnum) 806 suite.addTest("test_ani_array_with_arrayRecord", test_ani_array_with_arrayRecord) 807 suite.addTest("test_ani_array_with_arrayRecord", test_ani_array_with_arrayRecord_stri8) 808 suite.addTest("test_ani_array_with_arrayRecord", test_ani_array_with_arrayRecord_strf32) 809 suite.addTest("test_ani_array_with_arrayRecord", test_ani_array_with_arrayRecord_strf64) 810 suite.addTest("test_ani_array_with_arrayRecord", test_ani_array_with_arrayRecord_strbool) 811 suite.addTest("test_ani_array_with_union", test_ani_array_with_union) 812 suite.addTest("test_ani_array_with_PromiseI8", test_ani_array_with_PromiseI8) 813 suite.addTest("test_ani_array_with_PromiseI8_sync", test_ani_array_with_PromiseI8_sync) 814 suite.addTest("test_ani_array_with_PromiseI8_promise", test_ani_array_with_PromiseI8_promise) 815 suite.addTest("test_ani_array_with_PromiseI16", test_ani_array_with_PromiseI16) 816 suite.addTest("test_ani_array_with_PromiseI16_sync", test_ani_array_with_PromiseI16_sync) 817 suite.addTest("test_ani_array_with_PromiseI16_promise", test_ani_array_with_PromiseI16_promise) 818 suite.addTest("test_ani_array_with_PromiseI32", test_ani_array_with_PromiseI32) 819 suite.addTest("test_ani_array_with_PromiseI32_sync", test_ani_array_with_PromiseI32_sync) 820 suite.addTest("test_ani_array_with_PromiseI32_promise", test_ani_array_with_PromiseI32_promise) 821 suite.addTest("test_ani_array_with_PromiseI64", test_ani_array_with_PromiseI64) 822 suite.addTest("test_ani_array_with_PromiseI64_sync", test_ani_array_with_PromiseI64_sync) 823 suite.addTest("test_ani_array_with_PromiseI64_promise", test_ani_array_with_PromiseI64_promise) 824 suite.addTest("test_ani_array_with_PromiseF32", test_ani_array_with_PromiseF32) 825 suite.addTest("test_ani_array_with_PromiseF32_sync", test_ani_array_with_PromiseF32_sync) 826 suite.addTest("test_ani_array_with_PromiseF32_promise", test_ani_array_with_PromiseF32_promise) 827 suite.addTest("test_ani_array_with_PromiseF64", test_ani_array_with_PromiseF64) 828 suite.addTest("test_ani_array_with_PromiseF64_sync", test_ani_array_with_PromiseF64_sync) 829 suite.addTest("test_ani_array_with_PromiseF64_promise", test_ani_array_with_PromiseF64_promise) 830 suite.addTest("test_ani_array_with_PromiseString", test_ani_array_with_PromiseString) 831 suite.addTest("test_ani_array_with_PromiseString_sync", test_ani_array_with_PromiseString_sync) 832 suite.addTest("test_ani_array_with_PromiseString_promise", test_ani_array_with_PromiseString_promise) 833 suite.addTest("test_ani_array_with_PromiseBool", test_ani_array_with_PromiseBool) 834 suite.addTest("test_ani_array_with_PromiseBool_sync", test_ani_array_with_PromiseBool_sync) 835 suite.addTest("test_ani_array_with_PromiseBool_promise", test_ani_array_with_PromiseBool_promise) 836 suite.addTest("test_ani_array_with_PromiseU8", test_ani_array_with_PromiseU8) 837 suite.addTest("test_ani_array_with_PromiseU8_sync", test_ani_array_with_PromiseU8_sync) 838 suite.addTest("test_ani_array_with_PromiseU8_promise", test_ani_array_with_PromiseU8_promise) 839 suite.addTest("test_ani_array_with_PromiseU16", test_ani_array_with_PromiseU16) 840 suite.addTest("test_ani_array_with_PromiseU16_sync", test_ani_array_with_PromiseU16_sync) 841 suite.addTest("test_ani_array_with_PromiseU16_promise", test_ani_array_with_PromiseU16_promise) 842 843 suite.addTest("test_ani_array_with_nest_i8", test_ani_array_with_nest_i8) 844 suite.addTest("test_ani_array_with_nest_i16", test_ani_array_with_nest_i16) 845 suite.addTest("test_ani_array_with_nest_f32", test_ani_array_with_nest_f32) 846 suite.addTest("test_ani_array_with_nest_string", test_ani_array_with_nest_string) 847 suite.addTest("test_ani_array_with_nest_bool", test_ani_array_with_nest_bool) 848 suite.addTest("test_ani_array_with_optional", test_ani_array_with_optional) 849 850 exit(suite.run()) 851} 852