• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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*/
15const { TestClass1, TestClass2, TestClassUse, TestClassLater } = require("./out/build/Release/napitest")
16const { Demo, Test, funcTest, funcTest2, Woman } = require("./out/build/Release/napitest")
17const test = require("./out/build/Release/napitest")
18var assert = require("assert");
19const { consumers } = require("stream");
20
21describe('Class', function () {
22    it('test TestClass1 fun1', function () {
23        let tc1 = new TestClass1();
24        let ret = tc1.fun1(1);
25        assert.strictEqual(ret, 0);
26    });
27
28    it('test TestClass1 fun2', function () {
29        let tc = new TestClass1();
30        let ret = tc.fun2([1, 2, 3], { name: 'haha', age: 20 });
31        let retJson = JSON.stringify(ret);
32        assert.strictEqual(retJson, '{"name":"","age":0}');
33    });
34
35    it('test TestClass1 fun3', function () {
36        let tc = new TestClass1();
37        let ret = tc.fun3(2,'aaa',true);
38        assert.strictEqual(ret, false);
39    });
40
41    it('test TestClass1 fun4', function () {
42        let tc = new test.TestClass1();
43        let ret = tc.fun4({ 'name': 'haha', 'age': '20' });
44        let retJson = JSON.stringify(ret);
45        assert.strictEqual(retJson, '[]');
46        ret = tc.fun4({ 'name': 'haha', 'age': '20' },'aaa');
47        retJson = JSON.stringify(ret);
48        assert.strictEqual(retJson, '[]');
49    });
50
51    // export class Woman {
52    //   constructor(name_: string, age_: number, isMarried_: boolean);
53    //   w_name: string;
54    //   w_age: number;
55    //   w_isMarried: boolean;
56    // }
57    it('test Woman constructor', function () {
58      let tc = new Woman("haha", 22, true);
59      console.info("w_name is " + tc.w_name);
60      console.info("w_age is " + tc.w_age);
61      console.info("w_isMarried is " + tc.w_isMarried);
62    });
63});
64
65describe('Class defined later', function () {
66    it('test TestClassUse funceUse', function () {
67        let testLater = new TestClassLater();
68        let tUse = new TestClassUse();
69        let ret = tUse.funceUse(testLater);
70        assert.strictEqual(ret, "");
71    });
72});
73
74describe('Class part2', function () {
75    it('test TestClass1 fun5', function () {
76        let tc = new test.TestClass1();
77        let ret = tc.fun5(
78            [{ name: 'haha', age: 20 }, { name: 'houhou', age: 23 }]);
79        let retJson = JSON.stringify(ret);
80        assert.strictEqual(retJson, '{"name":"","age":0}');
81    });
82
83    it('test TestClass1 fun6', function () {
84        let tc = new test.TestClass1();
85        let ret = tc.fun6(['11','22','33'],{'isExit':true,'isTrue':false});
86        let retJson = JSON.stringify(ret);
87        assert.strictEqual(retJson, '[]');
88    });
89
90    it('test TestClass1 fun8', function () {
91        let tc = new test.TestClass1();
92        let ret = tc.fun8();
93        assert.deepStrictEqual(typeof ret, 'undefined');
94    });
95
96    // fun9(manA: Man): string;
97    // class Man
98    // {
99    //     name: string;
100    //     age: number;
101    // }
102    it('test TestClass1 fun9', function () {
103        let tc = new test.TestClass1();
104        let ret = tc.fun9({ name: "testaa", age: 10});
105        assert.strictEqual(ret, '');
106    });
107
108    // fun10(v: Image): Image;
109    // export class Image {
110    //     width: number;
111    //     height: number;
112    //     toDataURL(type?: string, quality?: number): string;
113    // }
114    it('test TestClass1 fun10', function () {
115        let tc = new test.TestClass1();
116        let ret = tc.fun10({ width: 5, height: 10});
117        assert.strictEqual(ret, '');
118    });
119
120    // fun11(v: LaunchReason): string;
121    it('test TestClass1 fun11', function () {
122        let tc = new test.TestClass1();
123        let ret = tc.fun11(test.LaunchReason.START_ABILITY);
124        assert.strictEqual(ret, '');
125    });
126
127    // fun12(v: TestStatus): number;
128    // export enum TestStatus {
129    //     UNKNOWN = 0,
130    //     START_ABILITY = 1,
131    //     CALL = 2,
132    //     CONTINUATION = 3,
133    // }
134    it('test TestClass1 fun12', function () {
135        let tc = new test.TestClass1();
136        let ret = tc.fun12(test.TestStatus.CALL);
137        assert.strictEqual(ret, '');
138    });
139
140    // fun13(v: TestEnumString): number;
141    // export enum TestEnumString {
142    //     ACTION_HOME = 'ohos.want.action.home',
143    //     ACTION_DIAL = 'ohos.want.action.dial',
144    //     ACTION_SEARCH = 'ohos.want.action.search',
145    //     ACTION_WIRELESS_SETTINGS = 'ohos.settings.wireless',
146    // }
147    it('test TestClass1 fun13', function () {
148        let tc = new test.TestClass1();
149        let ret = tc.fun13(test.TestEnumString.ACTION_DIAL);
150        assert.strictEqual(ret, '');
151    });
152
153    // interface testClassUse {
154    //     v0: string;
155    //     //v1: testClassLater;
156    //     // funceUse(n0: number): string;
157    //     funceUse(n0: testClassLater): string;
158    // }
159});
160
161describe('TestClass2', function () {
162    // func1(name : string, fp3: {nm: string, age: number}): string;
163    it('test TestClass2 func1', function () {
164        let tc = new TestClass2()
165        let ret = tc.func1("func1p1", {nm:"aaa",age:18,flag:false});
166        //assert.strictEqual(ret.read, 0);
167    });
168
169    // func2(input: string): { read: number; written: number; flag: boolean };
170    it('test TestClass2 func2', function () {
171        let tc = new TestClass2()
172        let ret = tc.func2("name");
173        //assert.strictEqual(ret.read, 0);
174    });
175
176    // func3(from: string, to: string): Promise<{result: number, errMsg: string, isT: boolean}>;
177    it('test TestClass2 func3', function () {
178        let tc = new TestClass2()
179        let ret = tc.func3("from", "to");
180        //assert.strictEqual(ret.read, 0);
181    });
182
183    // func4(from: string, to: string): Promise<{result: number; errMsg: string; isT: boolean}>;
184    it('test TestClass2 func4', function () {
185        let tc = new TestClass2()
186        let ret = tc.func4("responeFrom", "responseTo");
187        //assert.strictEqual(ret.read, 0);
188    });
189
190    // func5(v1: string, v2: number, v3: boolean);
191    it('test TestClass2 func5', function () {
192      let tc = new TestClass2()
193      tc.func5("func5", 5, false);
194    });
195});
196
197describe('Class Nest', function () {
198  // class Demo {
199  //     equals(other: Demo): boolean;
200  //     handleCallback(): void;
201  //     intPro: number;
202  //     strPro: string;
203  //     boolPro: boolean;
204  //     inter: aa;
205  //     type: Type;
206  // }
207  it('test Demo equals', function () {
208      let tc1 = new test.Demo();
209      let ret = tc1.equals({
210          intPro: 1,
211          strPro: "string",
212          boolPro: true,
213          inter: {abc: "abc", def: 7},
214          type: test.Type.typeA,
215      });
216      assert.strictEqual(ret, false);
217  });
218
219    // class Test {
220    //     type: Type;
221    //     func(param: Type): boolean;
222    // }
223    it('test Test func', function () {
224        let tc1 = new test.Test();
225        let ret = tc1.func(test.Type.typeB);
226        assert.strictEqual(ret, false);
227    });
228
229    // function funcTest(v: Type): boolean;
230    it('test funcTest', function () {
231        let ret = test.funcTest(test.Type.typeA);
232        assert.strictEqual(ret, false);
233    });
234
235    // function funcTest2(v: Test): boolean;
236    it('test funcTest2', function () {
237        let ret = test.funcTest2({type: test.Type.typeB});
238        assert.strictEqual(ret, false);
239    });
240});
241
242
243