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