• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15
16class TestA {
17    public a:string = "";
18}
19
20function tesObject(a:TestA) : TestA {
21    a.a = "bbb";
22    return a;
23}
24
25function testReturnArray(a:TestA, b:TestA, c:string) : Array<TestA> {
26    a.a = "bbb";
27    b.a = c;
28    let arr = new Array<TestA>();
29    arr.push(a);
30    arr.push(b);
31    return arr;
32}
33
34function testArrayObjects(arr:Array<TestA>) : Array<TestA> {
35    arr[0].a = "value1";
36    arr[1].a = "value2";
37    return arr;
38}
39
40function testPrimitive(a:int, b:string, c:boolean, d:double) {
41    assertEQ(a, 1);
42    assertEQ(b, "bbb");
43    assertEQ(c, true);
44    assertEQ(d, 1.0);
45}
46
47function singleObject():void {
48    let job = eaw.run<TestA>(tesObject, new TestA());
49    assertEQ(job.Await().a, "bbb");
50}
51
52function returnArray():void {
53    let a1 = new TestA();
54    let a2 = new TestA();
55    let job = eaw.run<Array<TestA>>(testReturnArray, a1, a2, "ccc");
56    let arr = job.Await();
57    assertEQ(arr[0].a, "bbb");
58    assertEQ(arr[1].a, "ccc");
59    assertEQ(a1.a, "bbb");
60    assertEQ(a2.a, "ccc");
61}
62
63function arrayParameter():void {
64    let arr:Array<TestA> = new Array<TestA>();
65    let a1 = new TestA();
66    let a2 = new TestA();
67    arr.push(a1);
68    arr.push(a2);
69    let job = eaw.run<Array<TestA>>(testArrayObjects, arr);
70    let arr2 = job.Await();
71    assertEQ(arr2[0].a, "value1");
72    assertEQ(arr2[1].a, "value2");
73    assertEQ(arr2, arr);
74    assertEQ(a1.a, "value1");
75    assertEQ(a2.a, "value2");
76}
77
78function primitiveParameter() : void {
79    eaw.run<void>(testPrimitive, 1, "bbb", true, 1.0).Await();
80}
81
82
83let eaw:EAWorker = new EAWorker();
84function main() {
85    const testSuite = new ArkTestsuite("EAWorkerParameterTest");
86    testSuite.addTest("singleObject", singleObject);
87    testSuite.addTest("returnArray", returnArray);
88    testSuite.addTest("arrayParameter", arrayParameter);
89    testSuite.addTest("primitiveParameter", primitiveParameter);
90    testSuite.run();
91    eaw.join();
92}
93