• 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
16const etsVm = globalThis.gtest.etsVm;
17
18let testFoo = etsVm.getFunction('Larg_interface/ETSGLOBAL;', 'testFoo');
19let testAgeable = etsVm.getFunction('Larg_interface/ETSGLOBAL;', 'testAgeable');
20let testCallable = etsVm.getFunction('Larg_interface/ETSGLOBAL;', 'testCallable');
21let testMultiInterface = etsVm.getFunction('Larg_interface/ETSGLOBAL;', 'testMultiInterface');
22
23class MyImpl {
24    constructor() {
25        'implements static:Larg_interface/Foo;,Larg_interface/AnotherInterface;';
26    }
27    foo(): boolean {
28        return true;
29    }
30    get age(): number {
31        return 1;
32    }
33    call(): string {
34        return '1';
35    }
36    run(): boolean {
37        return false;
38    }
39}
40
41class NotImpl {}
42
43function checkSingleObject(): void {
44    ASSERT_TRUE(testFoo(new MyImpl()));
45    ASSERT_TRUE(testAgeable(new MyImpl()));
46    ASSERT_TRUE(testCallable(new MyImpl()));
47    ASSERT_TRUE(testMultiInterface(new MyImpl()));
48}
49
50function checkCommonObj(): void {
51    let obj = new MyImpl();
52    ASSERT_TRUE(testFoo(obj));
53    ASSERT_TRUE(testAgeable(obj));
54    ASSERT_TRUE(testCallable(obj));
55    ASSERT_TRUE(testMultiInterface(obj));
56}
57
58function checkNotImplError() {
59    try {
60        testFoo(new NotImpl());
61    } catch (e: Error) {
62        ASSERT_TRUE(e.toString() === 'TypeError: object is not a type of Interface: Larg_interface/Foo;');
63    }
64}
65
66checkSingleObject();
67checkCommonObj();
68checkNotImplError();
69