• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-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
16import { launch } from "std/concurrency"
17
18let passed = false;
19
20function reset() {
21    passed = false;
22}
23
24function check(test: String) {
25    if (!passed) {
26        console.println("Test " + test + " failed");
27        throw new Error();
28    }
29}
30
31function noarg(): Object | null {
32    passed = true;
33    return null;
34}
35
36function onearg(x: int): Object | null {
37    if (x != 1) {
38        console.println("Test 'onearg': expected argument '1' but was " + x);
39        throw new Error();
40    }
41    passed = true;
42    return null;
43}
44
45function twoargs(x: int, y: int): Object | null {
46    if (x != 1) {
47        console.println("Test 'twoargs': expected first argument '1' but was " + x);
48        throw new Error();
49    }
50    if (y != 2) {
51        console.println("Test 'twoargs': expected second argument '2' but was " + y);
52        throw new Error();
53    }
54    passed = true;
55    return null;
56}
57
58function threeargs(x: int, y: int, z: int): Object | null {
59    if (x != 1) {
60        console.println("Test 'threeargs': expected first argument '1' but was " + x);
61        throw new Error();
62    }
63    if (y != 2) {
64        console.println("Test 'threeargs': expected second argument '2' but was " + y);
65        throw new Error();
66    }
67    if (z != 3) {
68        console.println("Test 'threeargs': expected third argument '3' but was " + z);
69        throw new Error();
70    }
71    passed = true;
72    return null;
73}
74
75function fourargs(x1: int, x2: int, x3: int, x4: int): Object | null {
76    if (x1 != 1) {
77        console.println("Test 'fourargs': expected first argument '1' but was " + x1);
78        throw new Error();
79    }
80    if (x2 != 2) {
81        console.println("Test 'fourargs': expected second argument '2' but was " + x2);
82        throw new Error();
83    }
84    if (x3 != 3) {
85        console.println("Test 'fourargs': expected third argument '3' but was " + x3);
86        throw new Error();
87    }
88    if (x4 != 4) {
89        console.println("Test 'fourargs': expected fourth argument '4' but was " + x4);
90        throw new Error();
91    }
92    passed = true;
93    return null;
94}
95
96function fiveargs(x1: int, x2: int, x3: int, x4: int, x5: int): Object | null {
97    if (x1 != 1) {
98        console.println("Test 'fiveargs': expected first argument '1' but was " + x1);
99        throw new Error();
100    }
101    if (x2 != 2) {
102        console.println("Test 'fiveargs': expected second argument '2' but was " + x2);
103        throw new Error();
104    }
105    if (x3 != 3) {
106        console.println("Test 'fiveargs': expected third argument '3' but was " + x3);
107        throw new Error();
108    }
109    if (x4 != 4) {
110        console.println("Test 'fiveargs': expected fourth argument '4' but was " + x4);
111        throw new Error();
112    }
113    if (x5 != 5) {
114        console.println("Test 'fiveargs': expected fifth argument '5' but was " + x5);
115        throw new Error();
116    }
117    passed = true;
118    return null;
119}
120
121export function main(): int {
122    reset()
123    launch<Object | null , () => Object | null>(noarg);
124    Coroutine.Schedule();
125    check("noarg");
126
127    reset()
128    launch<Object | null , (x: int) => Object | null>(onearg, 1);
129    Coroutine.Schedule();
130    check("onearg");
131
132    reset()
133    launch<Object | null , (x1: int, x2: int) => Object | null>(twoargs, 1, 2);
134    Coroutine.Schedule();
135    check("twoargs");
136
137    reset()
138    launch<Object | null , (x1: int, x2: int, x3: int) => Object | null>(threeargs, 1, 2, 3);
139    Coroutine.Schedule();
140    check("threeargs");
141
142    reset()
143    launch<Object | null , (x1: int, x2: int, x3: int, x4: int) => Object | null>(fourargs, 1, 2, 3, 4);
144    Coroutine.Schedule();
145    check("fourargs");
146
147    reset()
148    launch<Object | null , (x1: int, x2: int, x3: int, x4: int, x5: int) => Object | null>(fiveargs, 1, 2, 3, 4, 5);
149    Coroutine.Schedule();
150    check("fiveargs");
151    return 0;
152}
153