• 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 test = require("./out/build/Release/napitest")
16var assert = require("assert");
17
18describe('boolean', function () {
19
20    // function fun1(v: boolean): boolean;
21    it('test fun1', function () {
22        let ret = test.fun1(true);
23        assert.deepStrictEqual(ret, false);
24    });
25
26    // function fun2(v1: boolean, v2: boolean[]): boolean[];
27    it('test fun2', function () {
28        let ret = test.fun2(true, [true, false]);
29        assert.deepStrictEqual(ret, []);
30    });
31
32    // function fun3(v1: Array<boolean>, v2: boolean): Array<boolean>;
33    it('test fun3', function () {
34        let ret = test.fun3([true, false], false);
35        assert.deepStrictEqual(ret, []);
36    });
37
38    // function fun4(v: { [key: string]: boolean }): boolean;
39    it('test fun4', function () {
40        let ret = test.fun4({ 'isTrue': true, 'isExit': false });
41        assert.deepStrictEqual(ret, false);
42    });
43
44    // function fun5(v1: Map<string, boolean>, v2: boolean): boolean;
45    it('test fun5', function () {
46        let ret = test.fun5({ 'isTrue': true, 'isExit': false }, true);
47        assert.deepStrictEqual(ret, false);
48    });
49
50    function asynFun1(err, ret) {
51        assert.strictEqual(err.code, 0)
52        assert.deepStrictEqual(ret, false)
53    }
54
55    function def1(ret) {
56        assert.deepStrictEqual(ret, false);
57    }
58
59    // function fun6(v1: number, callback: AsyncCallback<boolean>): void;
60    it('test fun6_callback', function () {
61        test.fun6(15, asynFun1);
62        test.fun6(15).then(def1);
63    });
64
65    // function fun6(v1: number): Promise<boolean>;
66    it('test fun6_promise', function () {
67        let promiseObj = test.fun6(15);
68        promiseObj.then(ret => { def1(ret) });
69    });
70});
71
72
73describe('boolean', function () {
74    function asynFun2(err, ret) {
75        assert.deepStrictEqual(err.code, 0)
76        assert.deepStrictEqual(ret, [])
77    }
78
79    function def2(ret) {
80        assert.deepStrictEqual(ret, []);
81    }
82
83    // function fun7(v: number, v1: AsyncCallback<Array<boolean>>): void;
84    it('test fun7_callback', function () {
85        test.fun7(15, asynFun2);
86        test.fun7(15).then(def2);
87    });
88
89    // function fun7(v: number): Promise<Array<boolean>>;
90    it('test fun7_promise', function () {
91        let promiseObj = test.fun7(15);
92        promiseObj.then(ret => { def2(ret) });
93    });
94
95    function cb1(ret) {
96        assert.deepStrictEqual(ret, false)
97    }
98
99    // function fun9(v1: number, callback: Callback<boolean>): void;
100    it('test fun9', function () {
101        test.fun9(15, cb1);
102    });
103
104    // function fun10(v1: Test): Test;
105    it('test fun10', function () {
106        let ret = test.fun10(
107            { age: true, height: [false, false], width: [true, true] });
108        assert.deepStrictEqual(typeof ret, 'object');
109        assert.strictEqual(ret.age, false)
110        assert.deepStrictEqual(ret.height, [])
111        assert.deepStrictEqual(ret.width, [])
112    });
113});
114