• 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
16let baseFunc = globalThis.gtest.etsVm.getClass('Lfunction_this/ETSGLOBAL;').baseFunc;
17let childFunc = globalThis.gtest.etsVm.getClass('Lfunction_this/ETSGLOBAL;').childFunc;
18let fooBaseObj = globalThis.gtest.etsVm.getClass('Lfunction_this/ETSGLOBAL;').fooBaseObj;
19let fooChildObj = globalThis.gtest.etsVm.getClass('Lfunction_this/ETSGLOBAL;').fooChildObj;
20let etsDoCallbackFunction = globalThis.gtest.etsVm.getClass('Lfunction_this/ETSGLOBAL;').etsDoCallbackFunction;
21let etsDoCallbackLambda = globalThis.gtest.etsVm.getClass('Lfunction_this/ETSGLOBAL;').etsDoCallbackLambda;
22
23
24function doCallbackFunction(callback: Function) {
25    return callback();
26}
27
28function doCallbackLambda(callback: ()=>object) {
29    return callback();
30}
31
32function testBaseClassFunc() {
33    let obj1 = doCallbackFunction(baseFunc);
34    ASSERT_TRUE(typeof obj1 === 'object');
35    ASSERT_TRUE(obj1.baseVal === 1);
36
37    let obj2 = doCallbackLambda(baseFunc);
38    ASSERT_TRUE(typeof obj2 === 'object');
39    ASSERT_TRUE(obj2.baseVal === 1);
40}
41
42function testBaseClassFuncEts() {
43    let obj1 = etsDoCallbackFunction(baseFunc);
44    ASSERT_TRUE(typeof obj1 === 'object');
45    ASSERT_TRUE(obj1.baseVal === 1);
46
47    let obj2 = etsDoCallbackLambda(baseFunc)
48    ASSERT_TRUE(typeof obj2 === 'object');
49    ASSERT_TRUE(obj2.baseVal === 1);
50}
51
52function testChildClassFunc() {
53    let obj1 = doCallbackFunction(childFunc);
54    ASSERT_TRUE(typeof obj1 === 'object');
55    ASSERT_TRUE(obj1.baseVal === 1);
56    ASSERT_TRUE(obj1.childVal === 2);
57
58    let obj2 = doCallbackLambda(childFunc)
59    ASSERT_TRUE(typeof obj2 === 'object');
60    ASSERT_TRUE(obj2.baseVal === 1);
61    ASSERT_TRUE(obj2.childVal === 2);
62}
63
64function testChildClassFuncEts() {
65    let obj1 = etsDoCallbackFunction(childFunc);
66    ASSERT_TRUE(typeof obj1 === 'object');
67    ASSERT_TRUE(obj1.baseVal === 1);
68    ASSERT_TRUE(obj1.childVal === 2);
69
70    let obj2 = etsDoCallbackLambda(childFunc)
71    ASSERT_TRUE(typeof obj2 === 'object');
72    ASSERT_TRUE(obj2.baseVal === 1);
73    ASSERT_TRUE(obj2.childVal === 2);
74}
75
76function testFooBaseObj() {
77    let obj1 = doCallbackFunction(fooBaseObj.foo)
78    ASSERT_TRUE(typeof obj1 === 'object');
79    ASSERT_TRUE(obj1.baseVal === 1);
80
81    let obj2 = doCallbackLambda(fooBaseObj.foo)
82    ASSERT_TRUE(typeof obj2 === 'object');
83    ASSERT_TRUE(obj2.baseVal === 1);
84}
85
86function testFooBaseObjEts() {
87    let obj1 = etsDoCallbackFunction(fooBaseObj.foo)
88    ASSERT_TRUE(typeof obj1 === 'object');
89    ASSERT_TRUE(obj1.baseVal === 1);
90
91    let obj2 = etsDoCallbackLambda(fooBaseObj.foo)
92    ASSERT_TRUE(typeof obj2 === 'object');
93    ASSERT_TRUE(obj2.baseVal === 1);
94}
95
96function testFooChildObj() {
97    let obj1 = doCallbackFunction(fooChildObj.foo)
98    ASSERT_TRUE(typeof obj1 === 'object');
99    ASSERT_TRUE(obj1.baseVal === 1);
100    ASSERT_TRUE(obj1.childVal === 2);
101
102    let obj2 = doCallbackLambda(fooChildObj.foo)
103    ASSERT_TRUE(typeof obj2 === 'object');
104    ASSERT_TRUE(obj2.baseVal === 1);
105    ASSERT_TRUE(obj2.childVal === 2);
106}
107
108function testFooChildObjEts() {
109    let obj1 = etsDoCallbackFunction(fooChildObj.foo)
110    ASSERT_TRUE(typeof obj1 === 'object');
111    ASSERT_TRUE(obj1.baseVal === 1);
112    ASSERT_TRUE(obj1.childVal === 2);
113
114    let obj2 = etsDoCallbackLambda(fooChildObj.foo)
115    ASSERT_TRUE(typeof obj2 === 'object');
116    ASSERT_TRUE(obj2.baseVal === 1);
117    ASSERT_TRUE(obj2.childVal === 2);
118}
119
120function testFooInterfaceCall() {
121    let obj1 = fooBaseObj.foo()
122    ASSERT_TRUE(typeof obj1 === 'object');
123    ASSERT_TRUE(obj1.baseVal === 1);
124
125    let obj2 = fooChildObj.foo()
126    ASSERT_TRUE(typeof obj2 === 'object');
127    ASSERT_TRUE(obj2.baseVal === 1);
128    ASSERT_TRUE(obj2.childVal === 2);
129}
130
131testBaseClassFunc();
132testBaseClassFuncEts();
133testChildClassFunc();
134testChildClassFuncEts();
135testFooBaseObj();
136testFooBaseObjEts();
137testFooChildObj();
138testFooChildObjEts();
139testFooInterfaceCall();