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 { fun1 } = require("./out/build/Release/napitest")
16const test = require("./out/build/Release/napitest")
17var assert = require("assert");
18
19// 测试:function fun1(v: any, v1: string): number;
20describe('Any fun1', function () {
21    it('test fun1 any num string', function () {
22        let ret = test.fun1("1", "aa");
23        assert.strictEqual(ret, 0);
24    });
25
26    it('test fun1 any number', function () {
27        let ret = test.fun1(45678, "aa");
28        assert.strictEqual(ret, 0);
29    });
30
31    it('test fun1 any boolean', function () {
32        let ret = test.fun1(true, "aa");
33        assert.strictEqual(ret, 0);
34    });
35
36    it('test fun1 any string array', function () {
37        let ret = test.fun1(['11', '22', '33'], "aa");
38        assert.strictEqual(ret, 0);
39    });
40
41    it('test fun1 any number array', function () {
42        let ret = test.fun1([1, 2, 3], "aa");
43        assert.strictEqual(ret, 0);
44    });
45
46    it('test fun1 any boolean array', function () {
47        let ret = test.fun1({ "test": "okay", "test1": "res" }, "aa");
48        assert.strictEqual(ret, 0);
49    });
50
51    it('test fun1 any map number', function () {
52        let ret = test.fun1({ "test": 15, "test1": 18 }, "aa");
53        assert.strictEqual(ret, 0);
54    });
55
56    it('test fun1 any map number', function () {
57        let ret = test.fun1({ "test": true, "test1": false }, "aa");
58        assert.strictEqual(ret, 0);
59    });
60
61    it('test fun1 string', function () {
62        let ret = test.fun1('guding', 'aaa');
63        assert.strictEqual(ret, 0);
64    });
65
66});
67
68describe('Any fun1 array map part', function () {
69    it('test fun1 Array<map<string>>', function () {
70        let ret = test.fun1([{ "test": "okay", "test1": "res" }, { "test2": "okay2", "test3": "res3" }], 'aaa');
71        assert.strictEqual(ret, 0);
72    });
73    it('test fun1 Array<map<number>>', function () {
74        let ret = test.fun1([{ "test": 17, "test1": 18 }, { "test2": 20, "test3": 22 }], 'aaa');
75        assert.strictEqual(ret, 0);
76    });
77    it('test fun1 Array<map<boolean>>', function () {
78        let ret = test.fun1([{ "test": true, "test1": false }, { "test2": true, "test3": false }], 'aaa');
79        assert.strictEqual(ret, 0);
80    });
81
82    it('test fun1 map<Array<string>>', function () {
83        let ret = test.fun1({ "test": ["okay", "okay1"], "test1": ["res", "res1"] }, 'aaa');
84        assert.strictEqual(ret, 0);
85    });
86    it('test fun1 Array<map<number>>', function () {
87        let ret = test.fun1({ "test": [15, 18], "test1": [18, 20] }, 'aaa');
88        assert.strictEqual(ret, 0);
89    });
90    it('test fun1 Array<map<boolean>>', function () {
91        let ret = test.fun1({ "test": [true, true], "test1": [false, false] }, 'aaa');
92        assert.strictEqual(ret, 0);
93    });
94});
95
96// 测试:function fun2(v: number, v1: TestClass1): number;
97describe('Any fun2', function () {
98    it('test fun2 interface any string', function () {
99        let ret = test.fun2(15, { 'any1': 'aaa', 'focused': 'aaa' });
100        assert.strictEqual(ret, 0);
101    });
102
103    it('test fun2 interface any number', function () {
104        let ret = test.fun2(15, { 'any1': 11, 'def': 15 });
105        assert.strictEqual(ret, 0);
106    });
107
108    it('test fun2 interface any boolean', function () {
109        let ret = test.fun2(15, { 'any1': true, 'arr': [15, 20] });
110        assert.strictEqual(ret, 0);
111    });
112
113    it('test fun2 interface any string array', function () {
114        let ret = test.fun2(15, { 'any1': ['222', '333'], 'arr1': ['aaa', 'bbb'] });
115        assert.strictEqual(ret, 0);
116    });
117
118    it('test fun2 interface any number array', function () {
119        let ret = test.fun2(15,{'any1':[11,12],'extraInfo':{'name':'zhangsan','name1':'lisi'}});
120        assert.strictEqual(ret, 0);
121    });
122
123    it('test fun2 interface any boolean array', function () {
124        let ret = test.fun2(15, { 'any1': [true, true], 'focused': true });
125        assert.strictEqual(ret, 0);
126    });
127
128    it('test fun2 interface any map string', function () {
129        ret = test.fun2(15, { 'any1': { 'test': '666' }, 'def': ['12', '15'] });
130        assert.strictEqual(ret, 0);
131    });
132
133    it('test fun2 interface any map number', function () {
134        let ret = test.fun2(15, { 'any1': { 'test': 88 }, 'arr': [true, false] });
135        assert.strictEqual(ret, 0);
136    });
137
138    it('test fun2 interface any map boolean', function () {
139        let ret = test.fun2(15,{'any1':{'test':true},'arr1':[{'name':'hhh'},{'name':'lisi'}]});
140        assert.strictEqual(ret, 0);
141    });
142
143    it('test fun2 interface any string number array', function () {
144        ret = test.fun2(15,{'any1':'guding','extraInfo':{'name':[11, 15],'name1':[15, 18]}});
145        assert.strictEqual(ret, 0);
146    });
147});
148
149// 测试:function fun4(v: number, v1: Array<any>): number;
150describe('Any fun4', function () {
151    it('test fun4 Array string', function () {
152        let ret = test.fun4(15,['aaa', 'bbb']);
153        assert.strictEqual(ret, 0);
154    });
155
156    it('test fun4 Array number', function () {
157        let ret = test.fun4(15, [15, 18]);
158        assert.strictEqual(ret, 0);
159    });
160
161    it('test fun4 Array boolean', function () {
162        let ret = test.fun4(15, [true, true]);
163        assert.strictEqual(ret, 0);
164    });
165});
166
167// 测试:function fun5(v: string, v1: any[]): number;
168describe('Any fun5', function () {
169    it('test fun5 any string', function () {
170        let ret = test.fun5('aaa',['aaa', 'bbb']);
171        assert.strictEqual(ret, 0);
172    });
173
174    it('test fun5 any number', function () {
175        let ret = test.fun5('aaa',[15, 18]);
176        assert.strictEqual(ret, 0);
177    });
178
179    it('test fun5 any boolean', function () {
180        let ret = test.fun5('aaa',[true, true]);
181        assert.strictEqual(ret, 0);
182    });
183});
184
185// 测试:function $fun6(v: boolean, param: Array<any>): number;
186describe('Any fun6', function () {
187    it('test fun6 array string', function () {
188        let ret = test.$fun6(true,['aaa', 'bbb']);
189        assert.strictEqual(ret, 0);
190    });
191
192    it('test fun6 array number', function () {
193        let ret = test.$fun6(true,[15, 18]);
194        assert.strictEqual(ret, 0);
195    });
196
197    it('test fun6 array boolean', function () {
198        let ret = test.$fun6(true,[true, true]);
199        assert.strictEqual(ret, 0);
200    });
201});
202
203// 测试:function fun8(v1: string[], v?: any): number;
204describe('Any fun8', function () {
205    it('test fun8 option any null', function () {
206        let ret = test.fun8(['aaa','bbb']);
207        assert.strictEqual(ret, 0);
208    });
209
210    it('test fun8 option any number string', function () {
211        let ret = test.fun8(['aaa','bbb'],"1");
212        assert.strictEqual(ret, 0);
213    });
214
215    it('test fun8 option any number', function () {
216        let ret = test.fun8(['aaa','bbb'],45678);
217        assert.strictEqual(ret, 0);
218    });
219
220    it('test fun8 option any boolean', function () {
221        let ret = test.fun8(['aaa','bbb'],true);
222        assert.strictEqual(ret, 0);
223    });
224
225    it('test fun8 option any array string', function () {
226        let ret = test.fun8(['aaa','bbb'],['11', '22', '33']);
227        assert.strictEqual(ret, 0);
228    });
229
230    it('test fun8 option any array number', function () {
231        let ret = test.fun8(['aaa','bbb'],[1, 2, 3]);
232        assert.strictEqual(ret, 0);
233    });
234
235    it('test fun8 option any array boolean', function () {
236        let ret = test.fun8(['aaa','bbb'],[true, true, false]);
237        assert.strictEqual(ret, 0);
238    });
239
240    it('test fun8 option any map string', function () {
241        let ret = test.fun8(['aaa','bbb'],{ "test": "okay", "test1": "res" });
242        assert.strictEqual(ret, 0);
243    });
244
245    it('test fun8 option any map number', function () {
246        let ret = test.fun8(['aaa','bbb'],{ "test": 15, "test1": 18 });
247        assert.strictEqual(ret, 0);
248    });
249
250    it('test fun8 option any map boolean', function () {
251        let ret = test.fun8(['aaa','bbb'],{ "test": true, "test1": false });
252        assert.strictEqual(ret, 0);
253    });
254
255    it('test fun8  option any string', function () {
256        let ret = test.fun8(['aaa','bbb'],'guding');
257        assert.strictEqual(ret, 0);
258    });
259});
260