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, func1, func2, func3 } = require("./out/build/Release/napitest") 16const { TestInterfaceUse, TestInterfaceLater} = require("./out/build/Release/napitest") 17 18const test = require("./out/build/Release/napitest") 19var assert = require("assert"); 20const { consumers } = require("stream"); 21 22describe('Interface', function () { 23 24 // 测试:fun1(v: number): number; 25 it('test TestClass1 fun1', function () { 26 let tc1 = new TestClass1(); 27 let ret = tc1.fun1(1); 28 assert.strictEqual(ret, 0); 29 }); 30 31 // 测试:fun2(numcc: Array<number>, mancc: Human): Human; 32 it('test TestClass1 fun2', function () { 33 let tc = new TestClass1(); 34 let ret = tc.fun2([1, 2, 3], { name: 'haha', age: 20 }); 35 let retJson = JSON.stringify(ret); 36 assert.strictEqual(retJson, '{"name":"","age":0}'); 37 }); 38 39 // 测试:fun3: (v: number, v1: string, v2: boolean) => boolean; 40 it('test TestClass1 fun3', function () { 41 let tc = new TestClass1(); 42 let ret = tc.fun3(2,'aaa',true); 43 assert.strictEqual(ret, false); 44 }); 45 46 // 测试:fun4: (mancc: Map<string, string>,v?: string) => Array<number>; 47 it('test TestClass1 fun4', function () { 48 let tc = new test.TestClass1(); 49 let ret = tc.fun4({ 'name': 'haha', 'age': '20' }); 50 let retJson = JSON.stringify(ret); 51 assert.strictEqual(retJson, '[]'); 52 ret = tc.fun4({ 'name': 'haha', 'age': '20' },'aaa'); 53 retJson = JSON.stringify(ret); 54 assert.strictEqual(retJson, '[]'); 55 }); 56}); 57 58describe('Interface', function () { 59 60 // 测试:fun5: (data: Array<Human>) => Human; 61 it('test TestClass1 fun5', function () { 62 let tc = new test.TestClass1(); 63 let ret = tc.fun5( 64 [{ name: 'haha', age: 20 }, { name: 'houhou', age: 23 }]); 65 let retJson = JSON.stringify(ret); 66 assert.strictEqual(retJson, '{"name":"","age":0}'); 67 }); 68 69 // 测试:fun6: (v: string[], v1: { [key: string]: boolean }) => string[]; 70 it('test TestClass1 fun6', function () { 71 let tc = new test.TestClass1(); 72 let ret = tc.fun6(['11','22','33'],{'isExit':true,'isTrue':false}); 73 let retJson = JSON.stringify(ret); 74 assert.strictEqual(retJson, '[]'); 75 }); 76 77 // 测试:fun8: () => void; 78 it('test TestClass1 fun8', function () { 79 let tc = new test.TestClass1(); 80 let ret = tc.fun8(); 81 assert.deepStrictEqual(typeof ret, 'undefined'); 82 }); 83 84 /* 测试:fun9(manA: Man): void; 85 interface Man 86 { 87 name: string; 88 age: number; 89 } 90 */ 91 it('test TestClass1 fun9', function () { 92 let tc = new test.TestClass1(); 93 let ret = tc.fun9({name: 'asa', age: 3}); 94 assert.deepStrictEqual(typeof ret, 'undefined'); 95 }); 96 97 /* 测试:fun12(v: TestStatus): string; 98 export enum TestStatus { 99 UNKNOWN = 0, 100 START_ABILITY = 1, 101 CALL = 2, 102 CONTINUATION = 3, 103 } 104 */ 105 it('test TestClass1 fun12', function () { 106 let tc = new test.TestClass1(); 107 let ret = tc.fun12(test.TestStatus.CONTINUATION); 108 assert.strictEqual(ret, 0); 109 }); 110 111 /* 测试:fun13(v: TestEnumString): string; 112 export enum TestEnumString { 113 ACTION_HOME = 'ohos.want.action.home', 114 ACTION_DIAL = 'ohos.want.action.dial', 115 ACTION_SEARCH = 'ohos.want.action.search', 116 ACTION_WIRELESS_SETTINGS = 'ohos.settings.wireless', 117 } 118 */ 119 it('test TestClass1 fun13', function () { 120 let tc = new test.TestClass1(); 121 let ret = tc.fun13(test.TestEnumString.ACTION_SEARCH); 122 assert.strictEqual(ret, 0); 123 }); 124}); 125 126describe('Interface', function () { 127 // 测试:fun16(v1: number, v2: string, v3: boolean); 128 it('test TestClass1 fun16', function () { 129 let tc = new TestClass1() 130 tc.fun16(5, "fun16",false); 131 }); 132}); 133 134describe('Interface Optional Param func1', function () { 135 it('test Function func1 test1', function () { 136 let ret = func1({aa: 'aa', bb: false, cc: 7, dd: 'dd', ee: 27}, 17); 137 let retJson = JSON.stringify(ret); 138 assert.strictEqual(retJson, '""'); 139 }); 140 141 it('test Function func1 test2', function () { 142 let ret = func1({aa: 'aa', bb: false, cc: 7, dd: 'dd', ee: 27}); 143 let retJson = JSON.stringify(ret); 144 assert.strictEqual(retJson, '""'); 145 }); 146 147 it('test Function func1 test3', function () { 148 let ret = func1({aa: 'aa', dd: 'dd', bb: false, cc: 7,ee: 27}); 149 let retJson = JSON.stringify(ret); 150 assert.strictEqual(retJson, '""'); 151 }); 152 153 it('test Function func1 test4', function () { 154 let ret = func1({aa: 'aa', bb: false, cc: 7}, 17); 155 let retJson = JSON.stringify(ret); 156 assert.strictEqual(retJson, '""'); 157 }); 158 159 it('test Function func1 test5', function () { 160 let ret = func1({aa: 'aa', cc: 7}, 17); 161 let retJson = JSON.stringify(ret); 162 assert.strictEqual(retJson, '""'); 163 }); 164 165 it('test Function func1 test6', function () { 166 let ret = func1({aa: 'aa', dd: 'ababab', cc: 7}, 17); 167 let retJson = JSON.stringify(ret); 168 assert.strictEqual(retJson, '""'); 169 }); 170}); 171 172describe('Interface Optional Param func2', function () { 173 it('test Function func2 test1', function () { 174 let ret = func2({ 175 a1: { 'name': 999, 'age': 20 }, 176 c1: [1, 2, 3], 177 }); 178 let retJson = JSON.stringify(ret); 179 assert.strictEqual(retJson, '""'); 180 }); 181 182 it('test Function func2 test2', function () { 183 let ret = func2({ 184 a1: { 'name': 999, 'age': 20 }, 185 b1: { 'name': 'ahah', 'age': '02' }, 186 c1: [1, 2, 3], 187 d1: ['a', 'b', 'c'], 188 e1: 999, 189 g1: {aa: 'aa', dd: 'ababab', cc: 7} 190 }); 191 let retJson = JSON.stringify(ret); 192 assert.strictEqual(retJson, '""'); 193 }); 194 195 it('test Function func3 test1', function () { 196 let ret = func3({ 197 test: {a1: 23, 198 bb: [1,2,3], cc:{'map': 'value'}, 199 aa: false, dd: [true, false], ee: {'map2': 25}, 200 gg: 23} 201 }); 202 let retJson = JSON.stringify(ret); 203 assert.strictEqual(retJson, '""'); 204 }); 205 206 /* 测试 207 fun1(v: number): number; 208 interface testInterfaceUse { 209 v0: string; 210 //v1: testInterfaceLater; 211 // funceUse(n0: number): string; 212 funceUse(n0: testInterfaceLater): string; 213 } 214 */ 215 it('test TestInterfaceUse funceUse', function () { 216 let testLater = new TestInterfaceLater(); 217 let tUse = new TestInterfaceUse(); 218 let ret = tUse.funceUse(testLater); 219 assert.strictEqual(ret, ""); 220 }); 221});