diff --git a/test/storytest/test_$/@ohos.test.d.ts b/test/storytest/test_$/@ohos.test.d.ts index f64c1aa9a3cdbf7b43c5cbeb2069bf038dd7fa9d..8b9755638230a57eff8c64db9768df00c281d141 100644 --- a/test/storytest/test_$/@ohos.test.d.ts +++ b/test/storytest/test_$/@ohos.test.d.ts @@ -12,10 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { AsyncCallback, Callback } from './../basic'; - declare namespace napitest { - function $fun1(v: string): string; + interface Test { + $name: string; + $listInputMethod(V: string): void; + } + class Person { + static $getMaxAge(v1: string): number; + } + function $fun2(v: string): string; + function fun3(v: Test): number; } export default napitest; + diff --git a/test/storytest/test_$/test.js b/test/storytest/test_$/test.js index 62cb6717ad532d8147098307ce85d35aa7740bb8..2c3eeff23a2054d76bab22a9509b4a7e403c2388 100644 --- a/test/storytest/test_$/test.js +++ b/test/storytest/test_$/test.js @@ -12,15 +12,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { $fun1 } = require("./out/build/Release/napitest") +const test = require("./out/build/Release/napitest") +const { Test, Person } = require("./out/build/Release/napitest") var assert = require("assert"); -describe('String', function () { +describe('$', function () { + it('test $listInputMethod', function () { + let te = new Test(); + let ret = te.$listInputMethod("1"); + assert.deepStrictEqual(typeof ret, 'undefined'); + }); + + it('test $getMaxAge', function () { + let pe = new Person(); + let ret = pe.$getMaxAge("1"); + assert.strictEqual(ret, 0); + }); - it('test $fun1', function () { - let ret = $fun1("1"); + it('test $fun2', function () { + let ret = test.$fun2("1"); assert.strictEqual(ret, ''); }); + it('test fun3', function () { + let ret = test.fun3('aaaaa'); + assert.strictEqual(ret, 0); + }); + }); diff --git a/test/storytest/test_[]/@ohos.test.d.ts b/test/storytest/test_[]/@ohos.test.d.ts index 53d2efa0cb60d40d1f37cfa7cc43a7dcd2f322fd..fb263b310e2079aa90c86ff34918468af9bf190e 100644 --- a/test/storytest/test_[]/@ohos.test.d.ts +++ b/test/storytest/test_[]/@ohos.test.d.ts @@ -15,9 +15,45 @@ import { AsyncCallback, Callback } from './../basic'; declare namespace napitest { - function fun1(v1: string[]): number; - function fun2(v1: number[]): number; - function fun3(v1: boolean[]): number; + interface Test { + name: string; + age: number; + } + + interface Entry { + key: number[]; + value: string[]; + isExit: boolean[]; + } + + function testArray(v: string[]): string[]; + function testArray1(v: number[]): number[]; + function testArray2(v: boolean[]): boolean[]; + function fun4(v1: string[], v2: Test[]): number[]; + function fun5(v1: number[], v2: Test[]): string[]; + function fun6(v1: boolean[], v2: Test[]): boolean[]; + function fun21(v: string, v1: Entry[]): Entry[]; + + /* ----以下接口,当前工具不支持,Aarray<>书写方式支持 + function fun1(v1: string[], v2: AsyncCallback): void; + function fun1(v1: string[]): Promise; + function fun2(v1: number[], v2: AsyncCallback): void; + function fun2(v1: number[]): Promise; + function fun3(v1: boolean[], v2: AsyncCallback): void; + function fun3(v1: boolean[]): Promise; + function fun7(v0: string[], v1: { [key: string]: string[] }): number; + function fun8(v0: number[], v1: { [key: string]: number[] }): number; + function fun9(v0: boolean[], v1: { [key: string]: boolean[] }): number; + function fun10(v1: { [key: string]: Test[] }): void; + function fun11(v1: Map): number; + function fun12(v1: Map): string; + function fun13(v1: Map): boolean; + function fun14(v1: string[], callback: Callback): void; + function fun15(v1: number[], callback: Callback): void; + function fun16(v1: boolean[], callback: Callback): void; + function fun17(callback: Callback): void; + function fun18(v2: AsyncCallback): void; + function fun18(): Promise;*/ } -export default napitest; +export default napitest; \ No newline at end of file diff --git a/test/storytest/test_[]/test.js b/test/storytest/test_[]/test.js index 1ca45d4767a2a11bbcf47cd74def8348c2d7ef9e..cbc1964dbdd1023e0ab3dd6e0dad7ee7234f0ac1 100644 --- a/test/storytest/test_[]/test.js +++ b/test/storytest/test_[]/test.js @@ -12,28 +12,45 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { fun1, fun2, fun3, fun4 } = require("./out/build/Release/napitest") +const test = require("./out/build/Release/napitest") var assert = require("assert"); -describe('String', function () { - var GrantStatus = { - PERMISSION_DENIED: -1, - PERMISSION_GRANTED: 2, - PERMISSION_PASS: 3 - } - it('test fun1', function () { - let ret = fun1(['a', 'b', 'c', 'd']); - assert.strictEqual(ret, 0); +describe('[]', function () { + it('test testArray', function () { + let ret = test.testArray(['kkk', 'hhh']); + assert.deepStrictEqual(ret, []); }); - it('test fun2', function () { - let ret = fun2([1, 2, 3, 4]); - assert.strictEqual(ret, 0); + it('test testArray1', function () { + let ret = test.testArray1([15, 18]); + assert.deepStrictEqual(ret, []); }); - it('test fun3', function () { - let ret = fun3([true, true, false, false]); - assert.strictEqual(ret, 0); + it('test testArray2', function () { + let ret = test.testArray2([true, false]); + assert.deepStrictEqual(ret, []); + }); + + it('test fun4', function () { + let ret = test.fun4(['kkk', 'hhh'], [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); + assert.strictEqual(JSON.stringify(ret), '[]'); + }); + + it('test fun5', function () { + let ret = test.fun5([12, 18], [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); + assert.strictEqual(JSON.stringify(ret), '[]'); }); -}); + it('test fun6', function () { + let ret = test.fun6([true, false], [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); + assert.strictEqual(JSON.stringify(ret), '[]'); + }); + +    it('test fun21', function () { +        let ret = test.fun21('sdfghjk', + [{ key: [11,12],value: ['aa','bb'],isExit: [true,true]}, + { key: [13,14],value: ['cc','dd'],isExit: [false,false]}]); +        assert.strictEqual(JSON.stringify(ret),'[]'); +    }); + +}); diff --git a/test/storytest/test_any/@ohos.test.d.ts b/test/storytest/test_any/@ohos.test.d.ts index 829061013f75ed728df59740295190f3a9119f30..517b3e5f532ab73335d37ab4b01a345caaaf7311 100644 --- a/test/storytest/test_any/@ohos.test.d.ts +++ b/test/storytest/test_any/@ohos.test.d.ts @@ -15,10 +15,29 @@ declare namespace napitest { interface TestClass1 { any1: any; + focused?: any; + $def?: any; + arr?: Array; + arr1?: any[]; + extraInfo?: { [key: string]: any }; + test?: (data: any, code: number) => void; } - function fun1(v: any): number; - function fun2(v: number): any; + export class Want { + parameters?: { [key: string]: any }; + static Prop(propName: string): any; + } + + function fun1(v: any, v1: string): number; + function fun2(v: number, v1: TestClass1): number; + function fun4(v: number, v1: Array): number; + function fun5(v: string, v1: any[]): number; + function $fun6(v: boolean, param: Array): number; + function fun8(v1: string[], v?: any): number; + /*function fun10(v: string, v1?: number | Array): string; + function fun7(v: string, v1: { [key: string]: any }): number; + function fun3(v: string): any; + function fun9(v: string, v1: { name: Array, age: number }): number;*/ } export default napitest; \ No newline at end of file diff --git a/test/storytest/test_any/test.js b/test/storytest/test_any/test.js index 44c6f745277d48fb24885f1d33b6128339a3edee..8c3a20e41d696ce688fcb7698b05bfa461ace0ea 100644 --- a/test/storytest/test_any/test.js +++ b/test/storytest/test_any/test.js @@ -13,33 +13,136 @@ * limitations under the License. */ const { fun1 } = require("./out/build/Release/napitest") +const test = require("./out/build/Release/napitest") var assert = require("assert"); describe('Any', function () { it('test fun1', function () { - let ret = fun1("1"); + let ret = test.fun1("1", "aa"); + assert.strictEqual(ret, 0); + ret = test.fun1(45678, "aa"); + assert.strictEqual(ret, 0); + ret = test.fun1(true, "aa"); + assert.strictEqual(ret, 0); + ret = test.fun1(['11', '22', '33'], "aa"); + assert.strictEqual(ret, 0); + ret = test.fun1([1, 2, 3], "aa"); + assert.strictEqual(ret, 0); + ret = test.fun1([true, true, false], "aa"); + assert.strictEqual(ret, 0); + ret = test.fun1({ "test": "okay", "test1": "res" }, "aa"); + assert.strictEqual(ret, 0); + ret = test.fun1({ "test": 15, "test1": 18 }, "aa"); + assert.strictEqual(ret, 0); + ret = test.fun1({ "test": true, "test1": false }, "aa"); + assert.strictEqual(ret, 0); + ret = test.fun1('guding', 'aaa'); assert.strictEqual(ret, 0); }); +}); - it('test fun1', function () { - let ret = fun1(45678); +describe('Any', function () { + + it('test fun2', function () { + let ret = test.fun2(15, { 'any1': 'aaa', 'focused': 'aaa' }); + assert.strictEqual(ret, 0); + ret = test.fun2(15, { 'any1': 11, 'def': 15 }); + assert.strictEqual(ret, 0); + ret = test.fun2(15, { 'any1': true, 'arr': [15, 20] }); + assert.strictEqual(ret, 0); + ret = test.fun2(15, { 'any1': ['222', '333'], 'arr1': ['aaa', 'bbb'] }); + assert.strictEqual(ret, 0); + ret = test.fun2(15,{'any1':[11,12],'extraInfo':{'name':'zhangsan','name1':'lisi'}}); + assert.strictEqual(ret, 0); + ret = test.fun2(15, { 'any1': [true, true], 'focused': true }); + assert.strictEqual(ret, 0); + ret = test.fun2(15, { 'any1': { 'test': '666' }, 'def': ['12', '15'] }); + assert.strictEqual(ret, 0); + ret = test.fun2(15, { 'any1': { 'test': 88 }, 'arr': [true, false] }); + assert.strictEqual(ret, 0); + ret = test.fun2(15,{'any1':{'test':true},'arr1':[{'name':'hhh'},{'name':'lisi'}]}); + assert.strictEqual(ret, 0); + ret = test.fun2(15,{'any1':'guding','extraInfo':{'name':[11, 15],'name1':[15, 18]}}); assert.strictEqual(ret, 0); }); +}); - it('test fun1', function () { - let ret = fun1(true); +describe('Any', function () { + it('test fun4', function () { + let ret = test.fun4(15,['aaa', 'bbb']); + assert.strictEqual(ret, 0); + ret = test.fun4(15, [15, 18]); + assert.strictEqual(ret, 0); + ret = test.fun4(15, [true, true]); assert.strictEqual(ret, 0); }); +}); - it('test fun1', function () { - let ret = fun1([1,2,3,4,5,6,7,8,9]); +describe('Any', function () { + it('test fun5', function () { + let ret = test.fun5('aaa',['aaa', 'bbb']); + assert.strictEqual(ret, 0); + ret = test.fun5('aaa',[15, 18]); + assert.strictEqual(ret, 0); + ret = test.fun5('aaa',[true, true]); assert.strictEqual(ret, 0); }); +}); - it('test fun1', function () { - let ret = fun1({"test":"okay","test1":"res"}); +describe('Any', function () { + it('test fun6', function () { + let ret = test.$fun6(true,['aaa', 'bbb']); + assert.strictEqual(ret, 0); + ret = test.$fun6(true,[15, 18]); + assert.strictEqual(ret, 0); + ret = test.$fun6(true,[true, true]); + assert.strictEqual(ret, 0); + }); +}); + +describe('Any', function () { + + it('test fun8', function () { + let ret = test.fun8(['aaa','bbb']); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],"1"); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],45678); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],true); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],['11', '22', '33']); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],[1, 2, 3]); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],[true, true, false]); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],{ "test": "okay", "test1": "res" }); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],{ "test": 15, "test1": 18 }); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],{ "test": true, "test1": false }); + assert.strictEqual(ret, 0); + ret = test.fun8(['aaa','bbb'],'guding'); assert.strictEqual(ret, 0); }); +}); + +// describe('Any', function () { -}); \ No newline at end of file +// it('test fun9', function () { +// let ret = test.fun9("aaa", { 'name': ['11', '22', '33'], 'age': 18 }); +// assert.strictEqual(ret, 0); +// ret = test.fun9("aaa", { 'name': [11, 22, 33], 'age': 18 }); +// assert.strictEqual(ret, 0); +// ret = test.fun9("aaa", { 'name': [true, true, false], 'age': 18 }); +// assert.strictEqual(ret, 0); +// ret = test.fun9("aaa", { 'name': [{'test':'aaa'},{'test':'ccc'}], 'age': 18 }); +// assert.strictEqual(ret, 0); +// ret = test.fun9("aaa", { 'name': [{'test':15},{'test':18}], 'age': 18 }); +// assert.strictEqual(ret, 0); +// ret = test.fun9("aaa", { 'name': [{'test':true},{'test':true}], 'age': 18 }); +// assert.strictEqual(ret, 0); +// }); +// }); diff --git a/test/storytest/test_array/@ohos.test.d.ts b/test/storytest/test_array/@ohos.test.d.ts index 3fc42c12872e68f230045c432cf299b53930681d..34ebb33aa8cae29cabfca702a3b2b52378a6c5e0 100644 --- a/test/storytest/test_array/@ohos.test.d.ts +++ b/test/storytest/test_array/@ohos.test.d.ts @@ -12,18 +12,54 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { AsyncCallback } from './../basic'; +import { AsyncCallback, Callback } from './../basic'; declare namespace napitest { - interface PeerInfo { - readonly deviceName: string; - readonly networkId: string; - readonly isOnline: boolean; + interface Test { + name: string; + age: number; } - function fun1(v1: Array): number; - function fun2(v1: Array): number; - function fun3(v1: Array): number; - function fun4(callback: AsyncCallback>): void; + + interface Entry { + key: Array; + value: Array; + isExit: Array; + } + + function fun1(v1: string, v2: AsyncCallback>): void; + function fun1(v1: string): Promise>; + + function fun2(v1: Array, v2: AsyncCallback>): void; + function fun2(v1: Array): Promise>; + + function fun3(v1: Array, v2: AsyncCallback>): void; + function fun3(v1: Array): Promise>; + + function testArray(v: Array): Array; + function testArray1(v: Array): Array; + function testArray2(v: Array): Array; + + function fun4(v1: Array, v2: Array): Array; + function fun5(v1: Array, v2: Array): Array; + function fun6(v1: Array, v2: Array): Array; + + function fun7(v0: Array, v1: { [key: string]: Array }): number; + function fun8(v0: Array, v1: { [key: string]: Array }): number; + function fun9(v0: Array, v1: { [key: string]: Array }): number; + + function fun11(v1: Map>): number; + function fun12(v1: Map>): string; + function fun13(v1: Map>): boolean; + + function fun14(v1: Array, callback: Callback>): void; + function fun15(v1: Array, callback: Callback>): void; + function fun16(v1: Array, callback: Callback>): void; + + function fun17(callback: Callback>): void; + + function fun21(v: string, v1: Array): Array; + /*function fun10(v1: { [key: string]: Array }): void;*/ } export default napitest; + diff --git a/test/storytest/test_array/test.js b/test/storytest/test_array/test.js index a42ecfd6ae9f6656e038a8d3dcbf0c7c5a2eb0b8..4977c03fb88ea5c32ad36978ae1b87cf273d2b41 100644 --- a/test/storytest/test_array/test.js +++ b/test/storytest/test_array/test.js @@ -12,37 +12,174 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { fun1, fun2, fun3, fun4 } = require("./out/build/Release/napitest") +const test = require("./out/build/Release/napitest") var assert = require("assert"); -describe('String', function () { - var GrantStatus = { - PERMISSION_DENIED: -1, - PERMISSION_GRANTED: 2, - PERMISSION_PASS: 3 - } - - it('test fun1', function () { - let ret = fun1(['a', 'b', 'c', 'd']); - assert.strictEqual(ret, 0); - }); - - it('test fun2', function () { - let ret = fun2([1, 2, 3, 4]); - assert.strictEqual(ret, 0); - }); - - it('test fun3', function () { - let ret = fun3([true, true, true, true]); - assert.strictEqual(ret, 0); - }); - - function abc(ret) { - assert.strictEqual(ret, ''); - } - - it('test fun4', function () { - fun4().then(abc); - }); +describe('AsyncCallback', function () { +    function asynFun1(err, ret) { +        assert.strictEqual(err.code,0) +        assert.deepStrictEqual(ret, []) +    } +    function def1(ret) { +        assert.deepStrictEqual(ret, []) +    } + +    it('test fun1', function () { +        test.fun1('a', asynFun1) +        test.fun1('a').then(def1) +    }); + +    it('test fun1', function () { +        let promiseObj = test.fun1('a'); +        promiseObj.then(ret => { def1(ret) }) +    }); + +    function asynFun2(err, ret) { +        assert.strictEqual(err.code,0) +        assert.deepStrictEqual(ret, []) +    } + +    function def2(ret) { +        assert.deepStrictEqual(ret, []); +    } + +    it('test fun2', function () { +        test.fun2([2,3], asynFun2); +        test.fun2([2,3]).then(def2); +    }); + +    it('test fun2', function () { +        let promiseObj = test.fun2([2,3]); +        promiseObj.then(ret => { def2(ret) }); +    }); +}); + +describe('AsyncCallback', function () { +    function asynFun3(err, ret) { +        assert.strictEqual(err.code,0) +        assert.deepStrictEqual(ret, []) +    } + +    function def3(ret) { +        assert.deepStrictEqual(ret, []); +    } +    it('test fun3', function () { + test.fun3([true,false], asynFun3); +     test.fun3([true,false]).then(def3); +    }); + +    it('test fun3', function () { +        let promiseObj = test.fun3([true,false]); +        promiseObj.then(ret => { def3(ret) }); +    }); + +}); + +describe('array', function () { +    it('test testArray', function () { +        let ret = test.testArray(['kkk','hhh']); +        assert.deepStrictEqual(ret, []); +    }); + +    it('test testArray1', function () { +        let ret = test.testArray1([15,18]); +        assert.deepStrictEqual(ret, []); +    }); + +    it('test testArray2', function () { +        let ret = test.testArray2([true,false]); +        assert.deepStrictEqual(ret,[]); +    }); +}); + +describe('Array/map', function () { +    it('test fun4', function () { +        let ret = test.fun4( + ['kkk','hhh'],[{'name':'kkk','age':18},{'name':'kkk','age':18}]); +        assert.deepStrictEqual(ret,[]); +    }); + +    it('test fun5', function () { +        let ret = test.fun5( + [12,18],[{'name':'kkk','age':18},{'name':'kkk','age':18}]); +        assert.deepStrictEqual(ret,[]); +    }); + +    it('test fun6', function () { +        let ret = test.fun6( + [true,false],[{'name':'kkk','age':18},{'name':'kkk','age':18}]); +        assert.deepStrictEqual(ret,[]); +    }); + +    it('test fun7', function () { +        let ret = test.fun7( + ['hhh','ooo'],{'name':['aaa','bbb'],'age':['ccc','ddd']}); +        assert.strictEqual(ret,0); +    }); + +    it('test fun8', function () { +        let ret = test.fun8([13,15],{'name':[125,126],'age':[145,146]}); +        assert.strictEqual(ret,0); +    }); + +    it('test fun9', function () { +        let ret = test.fun9([false,true],{'name':[true,false],'age':[false,true]}); +        assert.strictEqual(ret,0); +    }); + +    it('test fun11', function () { +        let ret = test.fun11({'name':['aaa','bbb'],'age':['ccc','ddd']}); +        assert.strictEqual(ret,0); +    }); +    it('test fun12', function () { +        let ret = test.fun12({'name':[111,222],'age':[333,444]}); +        assert.strictEqual(ret,''); +    }); +        +    it('test fun13', function () { +        let ret = test.fun13({'name':[true,true],'age':[false,false]}); +        assert.deepStrictEqual(ret,false); +    }); }); +describe('map', function () { +    function cb1(ret) { +        assert.deepStrictEqual(ret,[]) +    } + +    it('test fun14', function () { + test.fun14(['aaa','bbb','ccc'],cb1); +    }); + +    function cb2(ret) { +        assert.deepStrictEqual(ret,[]) +    } + +    it('test fun15', function () { + test.fun15([12,15,18],cb2); +    }); + +    function cb3(ret) { +        assert.deepStrictEqual(ret,[]) +    } + +    it('test fun16', function () { + test.fun16([true,true,false],cb3); +    }); + +    function cb4(ret) { +        assert.deepStrictEqual(ret,[]) +    } + +    it('test fun17', function () { + test.fun17(cb4); +    }); + +    it('test fun21', function () { +        let ret = test.fun21('sdfghjk', +            [{'key':[15,18],'value':['aa','bb'],'isExit':[true,true]}, +            {'key':[15,18],'value':['aa','bb'],'isExit':[true,true]} +            ]); +        assert.strictEqual(typeof ret,'object'); +    }); +}); diff --git a/test/storytest/test_bool/@ohos.test.d.ts b/test/storytest/test_bool/@ohos.test.d.ts index c7f32c66aae0583b04fb15382b59c357debd2a79..7c1f625e6d59e283e8a8430b9060412ad49cf7e3 100644 --- a/test/storytest/test_bool/@ohos.test.d.ts +++ b/test/storytest/test_bool/@ohos.test.d.ts @@ -15,7 +15,29 @@ import { AsyncCallback, Callback } from './../basic'; declare namespace napitest { + interface Test { + age: boolean; + height: boolean[]; + width: Array; + } function fun1(v: boolean): boolean; + function fun2(v1: boolean, v2: boolean[]): boolean[]; + function fun3(v1: Array, v2: boolean): Array; + function fun4(v: { [key: string]: boolean }): boolean; + function fun5(v1: Map, v2: boolean): boolean; + function fun6(v1: number, callback: AsyncCallback): void; + function fun6(v1: number): Promise; + function fun7(v: number, v1: AsyncCallback>): void; + function fun7(v: number): Promise>; + function fun9(v1: number, callback: Callback): void; + function fun10(v1: Test): Test; + /* + function fun8(v1: number, callback: AsyncCallback): void; + function fun8(v1: number): Promise; + interface Test1 { + address: { [key: string]: boolean }; + long: Map; + }*/ } -export default napitest; +export default napitest; \ No newline at end of file diff --git a/test/storytest/test_bool/test.js b/test/storytest/test_bool/test.js index 25636be4f1067576624ee7f26d75cfe603cfef60..b8310a936e4b5690e297c9c8e5ab883770d6589f 100644 --- a/test/storytest/test_bool/test.js +++ b/test/storytest/test_bool/test.js @@ -12,14 +12,91 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { fun1 } = require("./out/build/Release/napitest") +const test = require("./out/build/Release/napitest") var assert = require("assert"); describe('boolean', function () { it('test fun1', function () { - let ret = fun1(true); - assert.strictEqual(ret, false); + let ret = test.fun1(true); + assert.deepStrictEqual(ret, false); }); + it('test fun2', function () { + let ret = test.fun2(true, [true, false]); + assert.deepStrictEqual(ret, []); + }); + + it('test fun3', function () { + let ret = test.fun3([true, false], false); + assert.deepStrictEqual(ret, []); + }); + + it('test fun4', function () { + let ret = test.fun4({ 'isTrue': true, 'isExit': false }); + assert.deepStrictEqual(ret, false); + }); + + it('test fun5', function () { + let ret = test.fun5({ 'isTrue': true, 'isExit': false }, true); + assert.deepStrictEqual(ret, false); + }); + + function asynFun1(err, ret) { + assert.strictEqual(err.code, 0) + assert.deepStrictEqual(ret, false) + } + + function def1(ret) { + assert.deepStrictEqual(ret, false); + } + + it('test fun6', function () { + test.fun6(15, asynFun1); + test.fun6(15).then(def1); + }); + + it('test fun6', function () { + let promiseObj = test.fun6(15); + promiseObj.then(ret => { def1(ret) }); + }); }); + +describe('boolean', function () { + + function asynFun2(err, ret) { + assert.deepStrictEqual(err.code, 0) + assert.deepStrictEqual(ret, []) + } + + function def2(ret) { + assert.deepStrictEqual(ret, []); + } + + it('test fun7', function () { + test.fun7(15, asynFun2); + test.fun7(15).then(def2); + }); + + it('test fun7', function () { + let promiseObj = test.fun7(15); + promiseObj.then(ret => { def2(ret) }); + }); + + function cb1(ret) { + assert.deepStrictEqual(ret, false) + } + + it('test fun9', function () { + test.fun9(15, cb1); + }); + + it('test fun10', function () { + let ret = test.fun10({ age: true, height: [false, false], width: [true, true] }); + assert.deepStrictEqual(typeof ret, 'object'); + assert.strictEqual(ret.age, false) + assert.deepStrictEqual(ret.height, []) + assert.deepStrictEqual(ret.width, []) + }); + +}); diff --git a/test/storytest/test_enum/@ohos.test.d.ts b/test/storytest/test_enum/@ohos.test.d.ts index d63426ea48cd600edf8143d4e17b6fabdfa5ed76..2f973a0e392ee420d5be9c053927f3049e4ea77a 100644 --- a/test/storytest/test_enum/@ohos.test.d.ts +++ b/test/storytest/test_enum/@ohos.test.d.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Callback } from './../basic'; +import { AsyncCallback, Callback } from './../basic'; declare namespace napitest { export enum GrantStatus { @@ -22,14 +22,34 @@ declare namespace napitest { PERMISSION_PASS = "3", } - export enum HttpStatus { - STATUS0 = 0, - STATUS1 = 500, - STATUS2 = 503, + export enum LaunchReason { + UNKNOWN = 0, + START_ABILITY = 1, + CALL = 2, + CONTINUATION = 3, } - function fun1(v1: GrantStatus): HttpStatus; - function fun2(v1: HttpStatus): GrantStatus; - function fun3(reason: string, callback: Callback): void; + + export enum Action { + ACTION_HOME = "ohos.want.action.home", + ACTION_DIAL = "ohos.want.action.dial", + ACTION_SEARCH = "ohos.want.action.search", + } + + export enum PlayingState { + STATE_NOT_PLAYING, + STATE_PLAYING, + } + + function fun1(v0: string, v1: GrantStatus): GrantStatus; + function fun2(v0: number, v1: LaunchReason): LaunchReason; + function fun3(v0: string, v1: Action): Action; + function fun4(v0: number, v1: PlayingState): PlayingState; + function fun5(V0: string, callback: Callback): void; + function fun6(v0: string, callback: AsyncCallback): void; + function fun6(v0: string): Promise; + /*function fun7(v0: LaunchReason[], v1: LaunchReason): number;*/ + } export default napitest; + diff --git a/test/storytest/test_enum/test.js b/test/storytest/test_enum/test.js index 682c30e325864880eea7d99080ba5fa705de7c91..341ef9b12521067538103b1a3bdeeed78e6c7510 100644 --- a/test/storytest/test_enum/test.js +++ b/test/storytest/test_enum/test.js @@ -12,38 +12,58 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { fun1, fun2, fun3 } = require("./out/build/Release/napitest") +const { fun1, fun2, fun3, fun4,fun5,fun6 } = require("./out/build/Release/napitest") +const test = require("./out/build/Release/napitest") var assert = require("assert"); -describe('String', function () { - var GrantStatus = { - PERMISSION_DEFAULT: "", - PERMISSION_DENIED: "-1", - PERMISSION_GRANTED: "2", - PERMISSION_PASS: "3", - } - var HttpStatus = { - STATUS0: 0, - STATUS1: 500, - STATUS2: 503, - } - - it('test fun1', function () { - let ret = fun1(GrantStatus.PERMISSION_DENIED); - assert.strictEqual(ret, HttpStatus.STATUS0); - }); - - it('test fun2', function () { - let ret = fun2(HttpStatus.STATUS1); - assert.strictEqual(ret, GrantStatus.PERMISSION_DEFAULT); - }); - - function abc(ret) { - assert.strictEqual(ret, 0); - } - - it('test fun3', function () { - fun3('1', abc); - }); +describe('enum', function () { + +    it('test fun1', function () { +        let ret = fun1('aaaa',test.GrantStatus.PERMISSION_DENIED); +        assert.strictEqual(ret, test.GrantStatus.PERMISSION_DEFAULT); +    }); + +    it('test fun2', function () { +        let ret = fun2(18,test.LaunchReason.START_ABILITY); +        assert.strictEqual(ret, test.LaunchReason.UNKNOWN); +    }); + +    it('test fun3', function () { +        let ret = fun3('ggg',test.Action.ACTION_DIAL); +        assert.strictEqual(ret, ''); +    }); + +    it('test fun4', function () { +        let ret = fun4(18,test.PlayingState.STATE_PLAYING); +        assert.strictEqual(ret,0); +    }); + +    function abc(ret) { +        assert.deepStrictEqual(ret, test.LaunchReason.UNKNOWN); +    } + +    it('test fun5', function () { +        fun5('aaa',abc); +    }); + +    function asynFun1(err, ret) { +        assert.deepStrictEqual(err.code, 0) +        assert.deepStrictEqual(ret, '') +    } + +    it('test fun6', function () { +        fun6('hhh', asynFun1); +        fun6('hhh').then(def1); +    }); + +    function def1(ret) { +        assert.deepStrictEqual(ret, ''); +    } + +    it('test fun6', function () { +        let promiseObj = fun6('hhh'); +        promiseObj.then(ret => { def1(ret) }); +    }); + }); diff --git a/test/storytest/test_interface/@ohos.test.d.ts b/test/storytest/test_interface/@ohos.test.d.ts index 1f8fc2334c20fe7148733e70d5b24271fff1a5fd..b02db68922c5bcf9e63bca6e44fc80dff099ce5b 100755 --- a/test/storytest/test_interface/@ohos.test.d.ts +++ b/test/storytest/test_interface/@ohos.test.d.ts @@ -20,14 +20,24 @@ declare namespace napitest { age: number; } + export enum LaunchReason { + UNKNOWN = 0, + START_ABILITY = 1, + CALL = 2, + CONTINUATION = 3, + } + interface TestClass1 { ahuman: Human; - num1: number; fun1(v: number): number; fun2(numcc: Array, mancc: Human): Human; - fun3(v: number): boolean; - fun4(v2: string, mancc: Array): Human; + fun3: (v: number, v1: string, v2: boolean) => boolean; + fun4: (mancc: Map,v?: string) => Array; fun5: (data: Array) => Human; + fun6: (v: string[], v1: { [key: string]: boolean }) => string[]; + fun8: () => void; + //fun7: (v: string, v1: LaunchReason) => LaunchReason; --待支持 + } } diff --git a/test/storytest/test_interface/test.js b/test/storytest/test_interface/test.js index bbc0762cf2b11f15adf1abf28144775bf212a18a..70da4953f817e4f156689a7823a8ebc4eda07a3c 100755 --- a/test/storytest/test_interface/test.js +++ b/test/storytest/test_interface/test.js @@ -34,15 +34,18 @@ describe('Interface', function () { it('test TestClass1 fun3', function () { let tc = new TestClass1(); - let ret = tc.fun3(2); + let ret = tc.fun3(2,'aaa',true); assert.strictEqual(ret, false); }); it('test TestClass1 fun4', function () { let tc = new test.TestClass1(); - let ret = tc.fun4('aaa', [{ name: 'haha', age: 20 }, { name: 'houhou', age: 23 }]); + let ret = tc.fun4({ 'name': 'haha', 'age': '20' }); let retJson = JSON.stringify(ret); - assert.strictEqual(retJson, '{"name":"","age":0}'); + assert.strictEqual(retJson, '[]'); + ret = tc.fun4({ 'name': 'haha', 'age': '20' },'aaa'); + retJson = JSON.stringify(ret); + assert.strictEqual(retJson, '[]'); }); it('test TestClass1 fun5', function () { @@ -51,6 +54,19 @@ describe('Interface', function () { let retJson = JSON.stringify(ret); assert.strictEqual(retJson, '{"name":"","age":0}'); }); + + it('test TestClass1 fun6', function () { + let tc = new test.TestClass1(); + let ret = tc.fun6(['11','22','33'],{'isExit':true,'isTrue':false}); + let retJson = JSON.stringify(ret); + assert.strictEqual(retJson, '[]'); + }); + + it('test TestClass1 fun8', function () { + let tc = new test.TestClass1(); + let ret = tc.fun8(); + assert.deepStrictEqual(typeof ret, 'undefined'); + }); }); diff --git a/test/storytest/test_map/@ohos.test.d.ts b/test/storytest/test_map/@ohos.test.d.ts index 54007d19d8a9629e563d083e7db85174fbc1c872..e62958ea791f9c3e1d3dfc06642d82879a7a95a0 100644 --- a/test/storytest/test_map/@ohos.test.d.ts +++ b/test/storytest/test_map/@ohos.test.d.ts @@ -28,7 +28,7 @@ declare namespace napitest { } interface TestClass2 { - fun1(v: {[key: string]: string}): number; + fun1(v: {[key: string]: string},v1:string): number; fun2(v: {[key: string]: number}): number; fun3(v: {[key: string]: boolean}): number; fun4(v: {[key: string]: Array}): number; diff --git a/test/storytest/test_map/test.js b/test/storytest/test_map/test.js index 52a195f5e2cbc69af1c9219de27dbeb53ed599ea..98351e6141521415df52d272f8e13c22242ffc07 100644 --- a/test/storytest/test_map/test.js +++ b/test/storytest/test_map/test.js @@ -19,7 +19,7 @@ describe('Map', function () { it('test TestClass2 fun1', function () { let tc2 = new TestClass2(); - let ret = tc2.fun1({"age":"ageValue","name":"nameValue"}); + let ret = tc2.fun1({"age":"ageValue","name":"nameValue"},'aaaa'); assert.strictEqual(ret, 0); }); diff --git a/test/storytest/test_number/@ohos.test.d.ts b/test/storytest/test_number/@ohos.test.d.ts index 0a30e7e5c4a0cafca0849661f6adcc8c7f811a35..60090b8275b2c62327e3fe678b0acd9b4b2362f5 100755 --- a/test/storytest/test_number/@ohos.test.d.ts +++ b/test/storytest/test_number/@ohos.test.d.ts @@ -15,16 +15,31 @@ import { AsyncCallback, Callback } from './../basic'; declare namespace napitest { - interface TestClass1 { - num1: number; + function fun1(v: number): number; + function fun2(v1: number, v2: number[]): number[]; + function fun3(v1: Array, v2: number): Array; + function fun4(v: { [key: string]: number }): number; + function fun5(v1: Map, v2: number): number; + function fun6(v1: number, callback: AsyncCallback): void; + function fun6(v1: number): Promise; + function fun7(v: number, v1: AsyncCallback>): void; + function fun7(v: number): Promise>; + function fun9(v1: number, callback: Callback): void; + function fun10(v1: Test): Test; + interface Test { + age: number; + height: number[]; + width: Array; } - function fun1(v: number): number; - function fun2(v: Array, cb: Callback): void; - function fun3(v: TestClass1, cb: AsyncCallback): void; - function fun4(v: string): number; - function fun5(v: number, cb: AsyncCallback): void; - function fun5(v: number): Promise; + /* + function fun11(v1: Test1): Test; + interface Test1 { +     address: { [key: string]: number }; +     long: Map; + } + function fun8(v1: number, callback: AsyncCallback): void; + function fun8(v1: number): Promise;*/ } export default napitest; diff --git a/test/storytest/test_number/test.js b/test/storytest/test_number/test.js index 09f6610db34a91243c7579d1fae709575484bbd8..6122cadd28f391e228e08f4d703dca8287c9aea2 100755 --- a/test/storytest/test_number/test.js +++ b/test/storytest/test_number/test.js @@ -12,43 +12,86 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { fun1, fun2, fun3, fun4, fun5 } = require("./out/build/Release/napitest") +const test = require("./out/build/Release/napitest") var assert = require("assert"); -describe('Number', function () { +describe('number', function () { +    it('test fun1', function () { +        let ret = test.fun1(18); +        assert.deepStrictEqual(ret, 0); +    }); - it('test fun1', function () { - let ret = fun1(1); - assert.strictEqual(ret, 0); - }); +    it('test fun2', function () { +        let ret = test.fun2(18, [18, 20]); +        assert.deepStrictEqual(ret, []); +    }); - function abc(ret) { - assert.strictEqual(ret, 0); - } +    it('test fun3', function () { +        let ret = test.fun3([18, 20], 20); +        assert.deepStrictEqual(ret, []); +    }); - it('test fun2', function () { - fun2([1, 2, 3, 4], abc); - }); +    it('test fun4', function () { +        let ret = test.fun4({ 'isTrue': 18, 'isExit': 20 }); +        assert.deepStrictEqual(ret, 0); +    }); - // it('test fun2', function () { - // fun2([1, 2, 3, 4]).then(abc); - // }); +    it('test fun5', function () { +        let ret = test.fun5({ 'isTrue': 18, 'isExit': 20 }, 18); +        assert.deepStrictEqual(ret, 0); +    }); - it('test fun3', function () { - fun3({ num1: 3 }).then(abc); - }); +    function asynFun1(err, ret) { +        assert.strictEqual(err.code, 0) +        assert.deepStrictEqual(ret, 0) +    } - it('test fun4', function () { - fun4('aaa', abc); - }); +    function def1(ret) { +        assert.deepStrictEqual(ret, 0); +    } - function def(ret) { - assert.strictEqual(ret, ''); - } +    it('test fun6', function () { +        test.fun6(15, asynFun1); +        test.fun6(15).then(def1); +    }); - it('test fun5', function () { - let promiseObj = fun5(12); - promiseObj.then(ret => {def(ret)}); - }); -}); +    it('test fun6', function () { +        let promiseObj = test.fun6(15); +        promiseObj.then(ret => { def1(ret) }); +    }); + +    function asynFun2(err, ret) { +        assert.deepStrictEqual(err.code, 0) +        assert.deepStrictEqual(ret, []) +    } + +    function def2(ret) { +        assert.deepStrictEqual(ret, []); +    } + +    it('test fun7', function () { +        test.fun7(15, asynFun2); +        test.fun7(15).then(def2); +    }); +    it('test fun7', function () { +        let promiseObj = test.fun7(15); +        promiseObj.then(ret => { def2(ret) }); +    }); + +    function cb1(ret) { +        assert.deepStrictEqual(ret, 0) +    } + +    it('test fun9', function () { +        test.fun9(15, cb1); +    }); + +    it('test fun10', function () { +        let ret = test.fun10({ age: 18, height: [20, 20], width: [18, 18] }); +        assert.deepStrictEqual(typeof ret, 'object'); +        assert.strictEqual(ret.age,0) +        assert.deepStrictEqual(ret.height,[]) +        assert.deepStrictEqual(ret.width,[]) +    }); +}); diff --git a/test/storytest/test_object/@ohos.test.d.ts b/test/storytest/test_object/@ohos.test.d.ts index 565cc65da55a10c1dbc7282d5719ea551979c8f8..309832239ca29060a3f57cd2ea8c4150921ff31a 100755 --- a/test/storytest/test_object/@ohos.test.d.ts +++ b/test/storytest/test_object/@ohos.test.d.ts @@ -14,24 +14,28 @@ */ import { AsyncCallback, Callback } from './../basic'; -declare namespace napitest { - interface TestClass1 { +declare namespace napitest { + interface TestClass1 { fun1(v: Object): number; //Interface func para1 - fun2(num :number, v: Object): number; //Interface func para2 - fun3(num :number, v: Object, Sam:string): number; //Interface func para3 + fun2(num: number, v: Object): number; //Interface func para2 + fun3(num: number, v: Object, Sam: string): number; //Interface func para3 fun4(numcc: number): Object; //Interface func return fun9(): number; } - + interface TestClass2 { num1: number; obj: Object; //Interface var } function fun5(v1: Object): number; //namespace function para1 - function fun6(num1 :number, v2: Object): number; //namespace function para2 - function fun7(num2:number, v3: Object, nike:string): number; //namespace function para3 - function fun8(dd: number): Object; //namespace function return - + function fun6(num1: number, v2: Object): number; //namespace function para2 + function fun7(num2: number, v3: Object, nike: string): number; //namespace function para3 + function fun8(dd: number): Object; //namespace function return + /* + function fun7(v: number[], cb: Callback<{ name: string, age: number }>): void; + function fun6(v: string, cb: AsyncCallback<{ psTech: string, csTech: number }>): void; + function fun6(v: string): Promise<{ psTech: string, csTech: number }>;*/ + } export default napitest; diff --git a/test/storytest/test_object/test.js b/test/storytest/test_object/test.js index 3efff7063ce421b923c7fe09fe6d61ee8253218f..324433d65555bf4130779be78b20f189bca51782 100755 --- a/test/storytest/test_object/test.js +++ b/test/storytest/test_object/test.js @@ -16,10 +16,24 @@ const { TestClass1, fun5, fun6, fun7, fun8} = require("./out/build/Release/napit var assert = require("assert"); describe('Object', function () { + var Radio = { + RADIO_UNKNOWN : 0, + RADIO_GSM : 1, + RADIO_1XRTT : 2, + } + let tc1 = new TestClass1(); it('test TestClass1 fun1', function () { - let ret = tc1.fun1({"age":10,"name":"nameValue"}); + let ret = tc1.fun1({"age":10,"name":"nameValue"}); //basic assert.strictEqual(ret, 0); + ret = tc1.fun1({"age":[10,15],"name":"nameValue"}); //array + assert.strictEqual(ret,0) + ret = tc1.fun1({"age":10,"name":{'test':'"nameValue"'}}); //map + assert.strictEqual(ret,0) + ret = tc1.fun1({"age":10,"name":{'test':'nameValue','test1':15}}); //interface + assert.strictEqual(ret,0) + ret = tc1.fun1({"age":10,"name": Radio.RADIO_GSM}); //enum + assert.strictEqual(ret,0) }); it('test TestClass1 fun2', function () { @@ -34,7 +48,7 @@ describe('Object', function () { it('test TestClass1 fun4', function () { let ret = tc1.fun4(2); - //assert.strictEqual(ret, 0); + assert.deepStrictEqual(typeof ret, 'object'); }); it('test TestClass1 fun9', function () { @@ -43,7 +57,15 @@ describe('Object', function () { }); it('test fun5', function () { - let ret = fun5({"name":"sam","age":10}); + let ret = fun5({"name":"sam","age":10}); //basic + assert.strictEqual(ret, 0); + ret = fun5({"name":['Sam','Peter'],"age":10}); //array + assert.strictEqual(ret, 0); + ret = fun5({"name":{'test': '11'},"age":10}); //map + assert.strictEqual(ret, 0); + ret = fun5({"name":{'test': '11','test1':true},"age":10}); //interface + assert.strictEqual(ret, 0); + ret = fun5({"name":Radio.RADIO_GSM,"age":10}); //enum assert.strictEqual(ret, 0); }); @@ -58,8 +80,8 @@ describe('Object', function () { }); it('test fun8', function () { - fun8(2); - //assert.strictEqual(ret, 0); + let ret = fun8(2); + assert.deepStrictEqual(typeof ret, 'object'); }); }); diff --git a/test/storytest/test_optional/@ohos.test.d.ts b/test/storytest/test_optional/@ohos.test.d.ts index 4140f01749665721186f7d5c518ec4bf2f27817e..0ea245423eee75452377db51bf5b7f8d62cf1c67 100644 --- a/test/storytest/test_optional/@ohos.test.d.ts +++ b/test/storytest/test_optional/@ohos.test.d.ts @@ -21,17 +21,30 @@ declare namespace napitest { } // test basic type + function fun1(v0:string, v1?: string, v2?: number, v3?: boolean): number; + interface TestClass1 { interFun1(v0?:string, v1?: string, v2?: number, v3?: boolean): number; } - - function fun1(v0:string, v1?: string, v2?: number, v3?: boolean): number; - - + // test array - function fun21(v0: string, v1?: Array): number; + function fun21(v0: string, v1?: Array,v2?:Array,v3?:Array): number; + function fun22(v0: string, v1?: string[],v2?:number[],v3?:boolean[]): number; + function fun23(v0: string, v1?: AsyncCallback): number; + function fun23(v0: string): Promise; + interface TestClass2 { interFun21(v0?: Array, v1?: Array, v2?: Array): number; + interFun22(v0?: number[], v1?: string[], v2?: boolean[]): number; + } + + // test map + function fun31(v0: string, v1?: {[key:string]:number}): number; + function fun32(v0: string, v1?: Map): number; + + interface TestClass3 { + interFun31(v0:string, v1?: {[key:string]:number}): number; + interFun32(v0:string, v1?: Map): number; } // test enum @@ -48,18 +61,20 @@ declare namespace napitest { STATUS2 = 503, } - function fun31(v0?: HttpStatus, v1?: GrantStatus): number; - function fun32(reason: string, callback?: Callback): void; + function fun41(v0?: HttpStatus, v1?: GrantStatus): number; + function fun42(reason: string, callback?: Callback): void; // test interface + function fun51(v0?: Human, v1?: Human, v2?: Human): number; + function fun52(v0?: Human, v2?: Array): number; + function fun53(v0?: Human, callback?: Callback): void; + interface TestClass4 { - interFun41(v0?: Human, v1?: Human, v2?: Human): number; + interFun51(v0?: Human, v1?: Human, v2?: Human): number; } - function fun41(v0?: Human, v1?: Human, v2?: Human): number; - function fun42(v0?: Human, v2?: Array): number; - function fun43(v0?: Human, callback?: Callback): void; - function fun44(v0?: {name: string, age: number}): number; + // test object + function fun61(v0?: {name: string, age: number}): number; } export default napitest; diff --git a/test/storytest/test_optional/test.js b/test/storytest/test_optional/test.js index 49cb8c6d28b347701f0c38606d8bb1c336d0b7af..c23fd58c396c50db7f873def81f69cfd6240b343 100644 --- a/test/storytest/test_optional/test.js +++ b/test/storytest/test_optional/test.js @@ -13,10 +13,11 @@ * limitations under the License. */ const test = require("./out/build/Release/napitest") -const { TestClass1, TestClass2, TestClass4} = require("./out/build/Release/napitest") +const { TestClass1, TestClass2, TestClass3, TestClass4 } = require("./out/build/Release/napitest") var assert = require("assert"); +const { type } = require("os"); -describe('Optional1', function () { +describe('Optional basic', function () { it('test basic type', function () { let ret = test.fun1("a"); @@ -27,7 +28,7 @@ describe('Optional1', function () { assert.strictEqual(ret, 0); ret = test.fun1("a", "b", 3, true); assert.strictEqual(ret, 0); - + let tc = new TestClass1(); ret = tc.interFun1(); assert.strictEqual(ret, 0); @@ -40,13 +41,55 @@ describe('Optional1', function () { ret = tc.interFun1("a", "b", 3, true); assert.strictEqual(ret, 0); }); - - it('test array type', function () { - let ret = test.fun21("abc"); +}); + +describe('Optional Array', function () { + + it('test Array', function () { + let ret = test.fun21("a"); assert.strictEqual(ret, 0); - ret = test.fun21("abc", ['a', 'b', 'c', 'd']); + ret = test.fun21("a", ['aa', 'bb', 'cc']); assert.strictEqual(ret, 0); - + ret = test.fun21("a", ['aa', 'bb', 'cc'], [1, 2, 3]); + assert.strictEqual(ret, 0); + ret = test.fun21("a", ['aa', 'bb', 'cc'], [1, 2, 3], [true, true, true]); + assert.strictEqual(ret, 0); + }); + + // it('test []', function () { + // let ret = test.fun22("a"); + // assert.strictEqual(ret, 0); + // ret = test.fun22("a", ['aa','bb','cc']); + // assert.strictEqual(ret, 0); + // ret = test.fun22("a", ['aa','bb','cc'], [1,2,3]); + // assert.strictEqual(ret, 0); + // ret = test.fun22("a", ['aa','bb','cc'], [1,2,3], [true,true,true]); + // assert.strictEqual(ret, 0); + // }); + + function asynFun(err, ret) { + assert.strictEqual(err.code, 0) + assert.deepStrictEqual(ret, '') + } + + function def(ret) { + assert.deepStrictEqual(ret, ''); + } + + it('test AsyncCallback', function () { + //test.fun23('15', asynFun); + test.fun23('15').then(def); + }); + + it('test AsyncCallback', function () { + let promiseObj = test.fun23('15'); + promiseObj.then(ret => { def(ret) }); + }); +}); + + +describe('Optional Array', function () { + it('test interface array', function () { let tc = new TestClass2(); ret = tc.interFun21(); assert.strictEqual(ret, 0); @@ -54,12 +97,58 @@ describe('Optional1', function () { assert.strictEqual(ret, 0); ret = tc.interFun21([1, 2, 3, 4], ['a', 'b', 'c', 'd']); assert.strictEqual(ret, 0); - ret = tc.interFun21([1, 2, 3, 4], ['a', 'b', 'c', 'd'],[true, false, true, false]); + ret = tc.interFun21([1, 2, 3, 4], ['a', 'b', 'c', 'd'], [true, false, true, false]); + assert.strictEqual(ret, 0); + }); + + // it('test interface []', function () { + // let tc = new TestClass2(); + // ret = tc.interFun22(); + // assert.strictEqual(ret, 0); + // ret = tc.interFun22([1, 2, 3, 4]); + // assert.strictEqual(ret, 0); + // ret = tc.interFun22([1, 2, 3, 4], ['a', 'b', 'c', 'd']); + // assert.strictEqual(ret, 0); + // ret = tc.interFun22([1, 2, 3, 4], ['a', 'b', 'c', 'd'],[true, false, true, false]); + // assert.strictEqual(ret, 0); + // }); + +}); + +describe('Optional Map', function () { + + it('test map{}', function () { + let ret = test.fun31("a"); + assert.strictEqual(ret, 0); + ret = test.fun31("a", { 'test': 15, 'test1': 18 }); + assert.strictEqual(ret, 0); + }); + + it('test map<>', function () { + let ret = test.fun32("a"); + assert.strictEqual(ret, 0); + ret = test.fun32("a", { 'test': '15', 'test1': '18' }); + assert.strictEqual(ret, 0); + }); + + it('test interface map{}', function () { + let tc = new TestClass3(); + ret = tc.interFun31('aaaa'); + assert.strictEqual(ret, 0); + ret = tc.interFun31('aaaa', { 'test': 18, 'tst1': 20 }); + assert.strictEqual(ret, 0); + }); + + it('test interface map<>', function () { + let tc = new TestClass3(); + ret = tc.interFun32('aaaa'); + assert.strictEqual(ret, 0); + ret = tc.interFun32('aaaa', { 'test': true, 'tst1': false }); assert.strictEqual(ret, 0); }); }); -describe('Optional2', function () { +describe('Optional enum', function () { var GrantStatus = { PERMISSION_DEFAULT: "", PERMISSION_DENIED: "-1", @@ -75,53 +164,53 @@ describe('Optional2', function () { assert.strictEqual(typeof ret, 'number'); } it('test enum type', function () { - let ret = test.fun31(); + let ret = test.fun41(); assert.strictEqual(ret, 0); - ret = test.fun31(HttpStatus.STATUS1); + ret = test.fun41(HttpStatus.STATUS1); assert.strictEqual(ret, 0); - ret = test.fun31(HttpStatus.STATUS1, GrantStatus.PERMISSION_DENIED); + ret = test.fun41(HttpStatus.STATUS1, GrantStatus.PERMISSION_DENIED); assert.strictEqual(ret, 0); - ret = test.fun32('1'); - ret = test.fun32('1', cb3); - }); + ret = test.fun42('1'); + ret = test.fun42('1', cb3); + }); }); -describe('Optional3', function () { +describe('Optional interface', function () { function cb4(ret) { - assert.notEqual(ret.name,undefined) - assert.notEqual(ret.age,undefined) + assert.notEqual(ret.name, undefined) + assert.notEqual(ret.age, undefined) } - it('test interface type', function () { - let ret = test.fun41(); + it('test interface', function () { + let ret = test.fun51(); assert.strictEqual(ret, 0); - ret = test.fun41({ name: 'n1', age: 20 }); + ret = test.fun51({ name: 'n1', age: 20 }); assert.strictEqual(ret, 0); - ret = test.fun41({ name: 'n1', age: 20 }, { name: 'n2', age: 30 }); + ret = test.fun51({ name: 'n1', age: 20 }, { name: 'n2', age: 30 }); assert.strictEqual(ret, 0); - ret = test.fun41({ name: 'n1', age: 20 }, { name: 'n2', age: 30 }, { name: 'n3', age: 40 }); + ret = test.fun51({ name: 'n1', age: 20 }, { name: 'n2', age: 30 }, { name: 'n3', age: 40 }); assert.strictEqual(ret, 0); - - ret = test.fun42({ name: 'n1', age: 20 }); + + ret = test.fun52({ name: 'n1', age: 20 }); assert.strictEqual(ret, 0); - ret = test.fun42({ name: 'n1', age: 20 }, [{ name: 'm1', age: 121 }, { name: 'm2', age: 123 }]); + ret = test.fun52({ name: 'n1', age: 20 }, [{ name: 'm1', age: 121 }, { name: 'm2', age: 123 }]); assert.strictEqual(ret, 0); - - ret = test.fun43({ name: 'n1', age: 20 }); - ret = test.fun43({ name: 'n1', age: 20 }, cb4); - - ret = test.fun44(); + + ret = test.fun53({ name: 'n1', age: 20 }); + ret = test.fun53({ name: 'n1', age: 20 }, cb4); + + ret = test.fun61(); assert.strictEqual(ret, 0); - ret = test.fun44({ name: 'n2', age: 25 }); + ret = test.fun61({ name: 'n2', age: 25 }); assert.strictEqual(ret, 0); - + }); + + it('test interface type', function () { let tc = new TestClass4(); - ret = tc.interFun41(); - assert.strictEqual(ret, 0); - ret = tc.interFun41({ name: 'n1', age: 20 }); + ret = tc.interFun51({ name: 'n2', age: 25 }); assert.strictEqual(ret, 0); - ret = tc.interFun41({ name: 'n1', age: 20 }, { name: 'n2', age: 30 }); + ret = tc.interFun51({ name: 'n2', age: 25 }, { name: 'n2', age: 25 }); assert.strictEqual(ret, 0); - ret = tc.interFun41({ name: 'n1', age: 20 }, { name: 'n2', age: 30 }, { name: 'n3', age: 40 }); + ret = tc.interFun51({ name: 'n2', age: 25 }, { name: 'n2', age: 25 }, { name: 'n2', age: 25 }); assert.strictEqual(ret, 0); }); diff --git a/test/storytest/test_string/@ohos.test.d.ts b/test/storytest/test_string/@ohos.test.d.ts index 8d3634e500d7653da5e249c7cf98d343efc6c596..6eac3028092604e915cbe327444a4b8036e5a7a6 100755 --- a/test/storytest/test_string/@ohos.test.d.ts +++ b/test/storytest/test_string/@ohos.test.d.ts @@ -15,14 +15,32 @@ import { AsyncCallback, Callback } from './../basic'; declare namespace napitest { - interface TestClass1 { - string1: string; - } - function fun1(v: string): string; - function fun2(v: Array, cb: Callback): void; - function fun3(v: TestClass1, cb: AsyncCallback): void; + function fun2(v1: string, v2: string[]): string[]; + function fun3(v1: Array, v2: string): Array; + function fun4(v: { [key: string]: string }): string; + function fun5(v1: Map, v2: string): string; + function fun6(v1: string, callback: AsyncCallback): void; + function fun6(v1: string): Promise; + function fun7(v: string, v1: AsyncCallback>): void; + function fun7(v: string): Promise>; + function fun9(v1: string, callback: Callback): void; + function fun10(v1: Test): Test; + interface Test { + age: string; + height: string[]; + width: Array; + } + /* + function fun11(v1: Test1): Test; + interface Test1 { + address: { [key: string]: string }; + long: Map; + } + function fun8(v1: string, callback: AsyncCallback): void; + function fun8(v1: string): Promise;*/ } export default napitest; + diff --git a/test/storytest/test_string/test.js b/test/storytest/test_string/test.js index 0cef459d143cb9a68d6220fd89f7530bbb402e0a..9a14767dfcf9dea752ee5371466119f2ae919f5a 100755 --- a/test/storytest/test_string/test.js +++ b/test/storytest/test_string/test.js @@ -12,27 +12,87 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { fun1, fun2, fun3 } = require("./out/build/Release/napitest") +const test = require("./out/build/Release/napitest") var assert = require("assert"); -describe('String', function () { +describe('string', function () { +    it('test fun1', function () { +        let ret = test.fun1('18'); +        assert.deepStrictEqual(ret, ''); +    }); - it('test fun1', function () { - let ret = fun1("1"); - assert.strictEqual(ret, ''); - }); +    it('test fun2', function () { +        let ret = test.fun2('18', ['18', '20']); +        assert.deepStrictEqual(ret, []); +    }); - function abc(ret) { - assert.strictEqual(ret, ''); - } +    it('test fun3', function () { +        let ret = test.fun3(['18', '20'], '20'); +        assert.deepStrictEqual(ret, []); +    }); - it('test fun2', function () { - fun2(['1', '2', '3', '4'], abc); - }); +    it('test fun4', function () { +        let ret = test.fun4({ 'isTrue': '18', 'isExit': '20' }); +        assert.deepStrictEqual(ret, ''); +    }); - it('test fun3', function () { - fun3({ string1: '3' }).then(abc); - }); +    it('test fun5', function () { +        let ret = test.fun5({ 'isTrue': '18', 'isExit': '20' }, '18'); +        assert.deepStrictEqual(ret, ''); +    }); +    function asynFun1(err, ret) { +        assert.strictEqual(err.code, 0) +        assert.deepStrictEqual(ret, '') +    } + +    function def1(ret) { +        assert.deepStrictEqual(ret, ''); +    } + +    it('test fun6', function () { +        test.fun6('15', asynFun1); +        test.fun6('15').then(def1); +    }); + +    it('test fun6', function () { +        let promiseObj = test.fun6('15'); +        promiseObj.then(ret => { def1(ret) }); +    }); + +    function asynFun2(err, ret) { +        assert.deepStrictEqual(err.code, 0) +        assert.deepStrictEqual(ret, []) +    } + +    function def2(ret) { +        assert.deepStrictEqual(ret, []); +    } + +    it('test fun7', function () { +        test.fun7('15', asynFun2); +        test.fun7('15').then(def2); +    }); + +    it('test fun7', function () { +        let promiseObj = test.fun7('15'); +        promiseObj.then(ret => { def2(ret) }); +    }); + +    function cb1(ret) { +        assert.deepStrictEqual(ret, '') +    } + +    it('test fun9', function () { +        test.fun9('15', cb1); +    }); + +    it('test fun10', function () { +        let ret = test.fun10({ age: '18', height: ['20', '20'], width: ['18', '18'] }); +        assert.deepStrictEqual(typeof ret, 'object'); +        assert.strictEqual(ret.age,'') +        assert.deepStrictEqual(ret.height,[]) +        assert.deepStrictEqual(ret.width,[]) +    }); }); diff --git a/test/storytest/test_type/@ohos.test.d.ts b/test/storytest/test_type/@ohos.test.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..81b7fcb447aa32f0e81841258137090ee4c424c9 --- /dev/null +++ b/test/storytest/test_type/@ohos.test.d.ts @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import { Callback } from './../basic'; + +declare namespace napitest { + + interface Test1 { + fun1(type: 'callDetailsChange', callback: Callback): void; + fun3(type: 'activate' | 'activating', name: string, callback: Callback): void; + } + + class Cat { + fun4(v: 'FixedParamClass', v1: number[]): boolean; + } + + type WindowUpdateType = 'add' | 'remove' | 'bounds' | 'active' | 'focus'; + function fun5(type: 'FixedParamName', tag: Array): number; + function fun6(type: WindowUpdateType, v: number): string; + function fun7(type: 'add' | 'remove' | 'change', v: string[]): void; + function fun8(commands: Array<'set_status' | 'set_navigation'>, autoHide: boolean): void; + function fun9(v: string, v1: { name: number, type: 'delete' | 'return' }): number; + /* + interface Test { + name: 'IPv4' | 'IPv6'; + }*/ +} + +export default napitest; \ No newline at end of file diff --git a/test/storytest/test_type/test.js b/test/storytest/test_type/test.js new file mode 100755 index 0000000000000000000000000000000000000000..4b1255523decdc4cc5ae4c2d4cd6662d10314960 --- /dev/null +++ b/test/storytest/test_type/test.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +const { fun5,fun6,fun7,fun8,fun9 } = require("./out/build/Release/napitest") +const { Test1, Cat } = require("./out/build/Release/napitest") +var assert = require("assert"); + +describe('test', function () { + function cb(ret) { + assert.strictEqual(ret, '') + } + + function cb1(ret) { + assert.strictEqual(ret, 0) + } + + it('test fun1', function () { + let test = new Test1() + test.fun1('callDetailsChange', cb) + }); + + it('test fun3', function () { + let test = new Test1() + test.fun3('activate','aaaa', cb1) + }); + + it('test fun4', function () { + let cat = new Cat() + let ret = cat.fun4('FixedParamClass', [15, 18]) + assert.deepStrictEqual(ret, false) + }); + + it('test fun5', function () { + let ret = fun5('FixedParamName', ['aaa','bbb']) + assert.deepStrictEqual(ret, 0) + }); + + it('test fun6', function () { + let ret = fun6('add', 15) + assert.deepStrictEqual(ret, '') + }); + + it('test fun7', function () { + let ret = fun7('remove', ['aaa','bbb']) + assert.deepStrictEqual(typeof ret, 'undefined') + }); + + // it('test fun9', function () { + // let ret = fun9('remove', { 'name': 18, 'type': 'return' }) + // assert.deepStrictEqual(ret, 0) + // }); +}); \ No newline at end of file