Optimize ST test cases

Signed-off-by: zhaojunxia <zhaojunxia@kaihong.com>
This commit is contained in:
zhaojunxia 2022-09-23 10:30:27 +08:00 committed by zhaojunxia
parent 2e05541606
commit 7a9180b793
30 changed files with 1117 additions and 273 deletions

View File

@ -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;

View File

@ -12,15 +12,31 @@
* 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 $fun1', function () {
let ret = $fun1("1");
it('test $getMaxAge', function () {
let pe = new Person();
let ret = pe.$getMaxAge("1");
assert.strictEqual(ret, 0);
});
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);
});
});

View File

@ -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<string[]>): void;
function fun1(v1: string[]): Promise<string[]>;
function fun2(v1: number[], v2: AsyncCallback<number[]>): void;
function fun2(v1: number[]): Promise<number[]>;
function fun3(v1: boolean[], v2: AsyncCallback<boolean[]>): void;
function fun3(v1: boolean[]): Promise<boolean[]>;
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<string, string[]>): number;
function fun12(v1: Map<string, number[]>): string;
function fun13(v1: Map<string, boolean[]>): boolean;
function fun14(v1: string[], callback: Callback<string[]>): void;
function fun15(v1: number[], callback: Callback<number[]>): void;
function fun16(v1: boolean[], callback: Callback<boolean[]>): void;
function fun17(callback: Callback<Test[]>): void;
function fun18(v2: AsyncCallback<Test[]>): void;
function fun18(): Promise<Test[]>;*/
}
export default napitest;
export default napitest;

View File

@ -12,28 +12,48 @@
* 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),'[]');
});
});

View File

@ -15,10 +15,30 @@
declare namespace napitest {
interface TestClass1 {
any1: any;
focused?: any;
$def?: any;
arr?: Array<any>;
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<any>): number;
function fun5(v: string, v1: any[]): number;
function $fun6(v: boolean, param: Array<any>): number;
function fun8(v1: string[], v?: any): number;
/*function fun10(v: string, v1?: number | Array<any>): string;
function fun7(v: string, v1: { [key: string]: any }): number;
function fun3(v: string): any;
function fun9(v: string, v1: { name: Array<any>, age: number }): number;*/
}
export default napitest;

View File

@ -13,33 +13,115 @@
* 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);
});
});

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { fun1, fun2, fun4, fun5, fun6, TestClass1 } = require("./out/build/Release/napitest")
const { fun1, fun2, fun4, fun5 } = require("./out/build/Release/napitest")
var assert = require("assert");
describe('any[]', function () {
@ -40,7 +40,7 @@ describe('any[]', function () {
let ret = fun4([1, 2, 3, 4], 0);
assert.strictEqual(ret, 0);
});
it('test fun5', function () {
let ret = fun5(0, ['a', 'b', 'c', 'd']);
assert.strictEqual(ret, 0);

View File

@ -12,18 +12,45 @@
* 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<string>): number;
function fun2(v1: Array<number>): number;
function fun3(v1: Array<boolean>): number;
function fun4(callback: AsyncCallback<Array<PeerInfo>>): void;
interface Entry {
key: Array<number>;
value: Array<string>;
isExit: Array<boolean>;
}
function fun1(v1: string, v2: AsyncCallback<Array<string>>): void;
function fun1(v1: string): Promise<Array<string>>;
function fun2(v1: Array<number>, v2: AsyncCallback<Array<number>>): void;
function fun2(v1: Array<number>): Promise<Array<number>>;
function fun3(v1: Array<boolean>, v2: AsyncCallback<Array<boolean>>): void;
function fun3(v1: Array<boolean>): Promise<Array<boolean>>;
function testArray(v: Array<string>): Array<string>;
function testArray1(v: Array<number>): Array<number>;
function testArray2(v: Array<boolean>): Array<boolean>;
function fun4(v1: Array<string>, v2: Array<Test>): Array<number>;
function fun5(v1: Array<number>, v2: Array<Test>): Array<string>;
function fun6(v1: Array<boolean>, v2: Array<Test>): Array<boolean>;
function fun7(v0: Array<string>, v1: { [key: string]: Array<string> }): number;
function fun8(v0: Array<number>, v1: { [key: string]: Array<number> }): number;
function fun9(v0: Array<boolean>, v1: { [key: string]: Array<boolean> }): number;
function fun11(v1: Map<string, Array<string>>): number;
function fun12(v1: Map<string, Array<number>>): string;
function fun13(v1: Map<string, Array<boolean>>): boolean;
function fun14(v1: Array<string>, callback: Callback<Array<string>>): void;
function fun15(v1: Array<number>, callback: Callback<Array<number>>): void;
function fun16(v1: Array<boolean>, callback: Callback<Array<boolean>>): void;
function fun17(callback: Callback<Array<Test>>): void;
function fun21(v: string, v1: Array<Entry>): Array<Entry>;
/*function fun10(v1: { [key: string]: Array<Test> }): void;*/
}
export default napitest;

184
test/storytest/test_array/test.js Normal file → Executable file
View File

@ -12,37 +12,175 @@
* 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
describe('AsyncCallback<string/number>', function () {
function asynFun1(err, ret) {
assert.strictEqual(err.code, 0)
assert.deepStrictEqual(ret, [])
}
function def1(ret) {
assert.deepStrictEqual(ret, [])
}
it('test fun1', function () {
let ret = fun1(['a', 'b', 'c', 'd']);
assert.strictEqual(ret, 0);
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 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);
let promiseObj = test.fun2([2, 3]);
promiseObj.then(ret => { def2(ret) });
});
});
describe('AsyncCallback<boolean>', 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<basic>', 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<interface>/map<array>', 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<array>', 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');
});
});

View File

@ -15,7 +15,28 @@
import { AsyncCallback, Callback } from './../basic';
declare namespace napitest {
interface Test {
age: boolean;
height: boolean[];
width: Array<boolean>;
}
function fun1(v: boolean): boolean;
function fun2(v1: boolean, v2: boolean[]): boolean[];
function fun3(v1: Array<boolean>, v2: boolean): Array<boolean>;
function fun4(v: { [key: string]: boolean }): boolean;
function fun5(v1: Map<string, boolean>, v2: boolean): boolean;
function fun6(v1: number, callback: AsyncCallback<boolean>): void;
function fun6(v1: number): Promise<boolean>;
function fun7(v: number, v1: AsyncCallback<Array<boolean>>): void;
function fun7(v: number): Promise<Array<boolean>>;
function fun9(v1: number, callback: Callback<boolean>): void;
function fun10(v1: Test): Test;
/*function fun8(v1: number, callback: AsyncCallback<boolean[]>): void;
function fun8(v1: number): Promise<boolean[]>;
interface Test1 {
address: { [key: string]: boolean };
long: Map<string, boolean>;
}*/
}
export default napitest;
export default napitest;

View File

@ -12,14 +12,90 @@
* 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, [])
});
});

View File

@ -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,33 @@ 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<HttpStatus>): 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<LaunchReason>): void;
function fun6(v0: string, callback: AsyncCallback<GrantStatus>): void;
function fun6(v0: string): Promise<GrantStatus>;
/*function fun7(v0: LaunchReason[], v1: LaunchReason): number;*/
}
export default napitest;

View File

@ -13,37 +13,56 @@
* limitations under the License.
*/
const { fun1, fun2, fun3 } = require("./out/build/Release/napitest")
const { 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,
}
describe('enum', function () {
it('test fun1', function () {
let ret = fun1(GrantStatus.PERMISSION_DENIED);
assert.strictEqual(ret, HttpStatus.STATUS0);
let ret = fun1('aaaa', test.GrantStatus.PERMISSION_DENIED);
assert.strictEqual(ret, test.GrantStatus.PERMISSION_DEFAULT);
});
it('test fun2', function () {
let ret = fun2(HttpStatus.STATUS1);
assert.strictEqual(ret, GrantStatus.PERMISSION_DEFAULT);
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.strictEqual(ret, 0);
assert.deepStrictEqual(ret, test.LaunchReason.UNKNOWN);
}
it('test fun3', function () {
fun3('1', abc);
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) });
});
});

View File

@ -18,7 +18,6 @@ var assert = require("assert");
const { consumers } = require("stream");
describe('test_Interface', function () {
function abc(ret) {
assert.strictEqual(ret, '');
}

View File

@ -20,14 +20,23 @@ 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<number>, mancc: Human): Human;
fun3(v: number): boolean;
fun4(v2: string, mancc: Array<Human>): Human;
fun3: (v: number, v1: string, v2: boolean) => boolean;
fun4: (mancc: Map<string, string>,v?: string) => Array<number>;
fun5: (data: Array<Human>) => Human;
fun6: (v: string[], v1: { [key: string]: boolean }) => string[];
fun8: () => void;
/*fun7: (v: string, v1: LaunchReason) => LaunchReason; --待支持*/
}
}

View File

@ -18,7 +18,6 @@ var assert = require("assert");
const { consumers } = require("stream");
describe('Interface', function () {
it('test TestClass1 fun1', function () {
let tc1 = new TestClass1();
let ret = tc1.fun1(1);
@ -34,26 +33,43 @@ 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, '[]');
ret = tc.fun4({ 'name': 'haha', 'age': '20' },'aaa');
retJson = JSON.stringify(ret);
assert.strictEqual(retJson, '[]');
});
});
describe('Interface', function () {
it('test TestClass1 fun5', function () {
let tc = new test.TestClass1();
let ret = tc.fun5(
[{ name: 'haha', age: 20 }, { name: 'houhou', age: 23 }]);
let retJson = JSON.stringify(ret);
assert.strictEqual(retJson, '{"name":"","age":0}');
});
it('test TestClass1 fun5', function () {
it('test TestClass1 fun6', function () {
let tc = new test.TestClass1();
let ret = tc.fun5([{ name: 'haha', age: 20 }, { name: 'houhou', age: 23 }]);
let ret = tc.fun6(['11','22','33'],{'isExit':true,'isTrue':false});
let retJson = JSON.stringify(ret);
assert.strictEqual(retJson, '{"name":"","age":0}');
assert.strictEqual(retJson, '[]');
});
it('test TestClass1 fun8', function () {
let tc = new test.TestClass1();
let ret = tc.fun8();
assert.deepStrictEqual(typeof ret, 'undefined');
});
});

View File

@ -24,11 +24,10 @@ declare namespace napitest {
map2 : Map<string,Human> ;
//map3: {[key: string]: Object} // to support
//map3: {[key: string]: object} // to support
}
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<string>}): number;

View File

@ -16,10 +16,9 @@ const { TestClass1 ,TestClass2 } = require("./out/build/Release/napitest")
var assert = require("assert");
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);
});
@ -40,7 +39,7 @@ describe('Map', function () {
let ret = tc2.fun4({"age":["1","12","145"],"name":["21","22","23"]});
assert.strictEqual(ret, 0);
});
it('test TestClass2 fun5', function () {
let tc2 = new TestClass2();
let ret = tc2.fun5({"age":[122,222,322],"name":[422,522,622]});
@ -49,7 +48,6 @@ describe('Map', function () {
});
describe('Map', function () {
it('test TestClass2 fun6', function () {
let tc2 = new TestClass2();
let ret = tc2.fun6({"age":[true,true,true],"name":[false,false,false]});
@ -65,24 +63,24 @@ describe('Map', function () {
it('test TestClass2 fun8', function () {
let tc2 = new TestClass2();
let ret = tc2.fun8(
{"peter":{"age":"ageValue","name":"nameValue"},"jane":{"age":"ageValue","name":"nameValue"}}
);
{"peter":{"age":"ageValue","name":"nameValue"},
"jane":{"age":"ageValue","name":"nameValue"}});
assert.strictEqual(ret, 0);
});
it('test TestClass2 fun9', function () {
let tc2 = new TestClass2();
let ret = tc2.fun9(
{"peter":{"age":666,"name":"peter","isTrue":true},"jane":{"age":666,"name":"jane","isTrue":false}}
);
{"peter":{"age":666,"name":"peter","isTrue":true},
"jane":{"age":666,"name":"jane","isTrue":false}});
assert.strictEqual(ret, 0);
});
it('test TestClass2 fun10', function () {
let tc2 = new TestClass2();
let ret = tc2.fun10(
{"peter":{"age":666,"name":"peter","isTrue":true},"jane":{"age":666,"name":"jane","isTrue":false}}
);
{"peter":{"age":666,"name":"peter","isTrue":true},
"jane":{"age":666,"name":"jane","isTrue":false}});
assert.strictEqual(ret, 0);
});
});

View File

@ -15,16 +15,30 @@
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<number>, v2: number): Array<number>;
function fun4(v: { [key: string]: number }): number;
function fun5(v1: Map<string, number>, v2: number): number;
function fun6(v1: number, callback: AsyncCallback<number>): void;
function fun6(v1: number): Promise<number>;
function fun7(v: number, v1: AsyncCallback<Array<number>>): void;
function fun7(v: number): Promise<Array<number>>;
function fun9(v1: number, callback: Callback<number>): void;
function fun10(v1: Test): Test;
interface Test {
age: number;
height: number[];
width: Array<number>;
}
function fun1(v: number): number;
function fun2(v: Array<number>, cb: Callback<number>): void;
function fun3(v: TestClass1, cb: AsyncCallback<number>): void;
function fun4(v: string): number;
function fun5(v: number, cb: AsyncCallback<string>): void;
function fun5(v: number): Promise<string>;
/*function fun11(v1: Test1): Test;
interface Test1 {
address: { [key: string]: number };
long: Map<string, number>;
}
function fun8(v1: number, callback: AsyncCallback<number[]>): void;
function fun8(v1: number): Promise<number[]>;*/
}
export default napitest;

View File

@ -12,43 +12,88 @@
* 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 = fun1(1);
assert.strictEqual(ret, 0);
let ret = test.fun1(18);
assert.deepStrictEqual(ret, 0);
});
function abc(ret) {
assert.strictEqual(ret, 0);
}
it('test fun2', function () {
fun2([1, 2, 3, 4], abc);
let ret = test.fun2(18, [18, 20]);
assert.deepStrictEqual(ret, []);
});
// it('test fun2', function () {
// fun2([1, 2, 3, 4]).then(abc);
// });
it('test fun3', function () {
fun3({ num1: 3 }).then(abc);
let ret = test.fun3([18, 20], 20);
assert.deepStrictEqual(ret, []);
});
it('test fun4', function () {
fun4('aaa', abc);
let ret = test.fun4({ 'isTrue': 18, 'isExit': 20 });
assert.deepStrictEqual(ret, 0);
});
function def(ret) {
assert.strictEqual(ret, '');
it('test fun5', function () {
let ret = test.fun5({ 'isTrue': 18, 'isExit': 20 }, 18);
assert.deepStrictEqual(ret, 0);
});
function asynFun1(err, ret) {
assert.strictEqual(err.code, 0)
assert.deepStrictEqual(ret, 0)
}
it('test fun5', function () {
let promiseObj = fun5(12);
promiseObj.then(ret => {def(ret)});
function def1(ret) {
assert.deepStrictEqual(ret, 0);
}
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('number', 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, 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,[])
});
});

View File

@ -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;

View File

@ -12,14 +12,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { TestClass1, fun5, fun6, fun7, fun8} = require("./out/build/Release/napitest")
const { TestClass1, fun5} = require("./out/build/Release/napitest")
const { fun6, fun7, fun8} = require("./out/build/Release/napitest")
const test = require("./out/build/Release/napitest")
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"});
assert.strictEqual(ret, 0);
ret = tc1.fun1({"age":[10,15],"name":"nameValue"});
assert.strictEqual(ret,0)
ret = tc1.fun1({"age":10,"name":{'test':'"nameValue"'}});
assert.strictEqual(ret,0)
ret = tc1.fun1({"age":10,"name":{'test':'nameValue','test1':15}});
assert.strictEqual(ret,0)
ret = tc1.fun1({"age":10,"name": Radio.RADIO_GSM});
assert.strictEqual(ret,0)
});
it('test TestClass1 fun2', function () {
@ -32,9 +48,9 @@ describe('Object', function () {
assert.strictEqual(ret, 0);
});
it('test TestClass1 fun4', 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 () {
@ -42,9 +58,26 @@ describe('Object', function () {
assert.strictEqual(ret, 0);
});
});
describe('Object', function () {
var Radio = {
RADIO_UNKNOWN : 0,
RADIO_GSM : 1,
RADIO_1XRTT : 2,
}
it('test fun5', function () {
let ret = fun5({"name":"sam","age":10});
assert.strictEqual(ret, 0);
ret = fun5({"name":['Sam','Peter'],"age":10});
assert.strictEqual(ret, 0);
ret = fun5({"name":{'test': '11'},"age":10});
assert.strictEqual(ret, 0);
ret = fun5({"name":{'test': '11','test1':true},"age":10});
assert.strictEqual(ret, 0);
ret = fun5({"name":Radio.RADIO_GSM,"age":10});
assert.strictEqual(ret, 0);
});
it('test fun6', function () {
@ -58,13 +91,7 @@ describe('Object', function () {
});
it('test fun8', function () {
fun8(2);
//assert.strictEqual(ret, 0);
let ret = fun8(2);
assert.deepStrictEqual(typeof ret, 'object');
});
});
});

View File

@ -20,46 +20,44 @@ declare namespace napitest {
age: number;
}
// 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<string>): number;
function fun21(v0: string, v1?: Array<string>,v2?:Array<number>,v3?:Array<boolean>): number;
function fun22(v0: string, v1?: string[],v2?:number[],v3?:boolean[]): number;
function fun23(v0: string, v1?: AsyncCallback<string>): number;
function fun23(v0: string): Promise<string>;
interface TestClass2 {
interFun21(v0?: Array<number>, v1?: Array<string>, v2?: Array<boolean>): number;
interFun22(v0?: number[], v1?: string[], v2?: boolean[]): number;
}
// test enum
function fun31(v0: string, v1?: {[key:string]:number}): number;
function fun32(v0: string, v1?: Map<string,string>): number;
interface TestClass3 {
interFun31(v0:string, v1?: {[key:string]:number}): number;
interFun32(v0:string, v1?: Map<string,boolean>): number;
}
export enum GrantStatus {
PERMISSION_DEFAULT = "",
PERMISSION_DENIED = "-1",
PERMISSION_GRANTED = "2",
PERMISSION_PASS = "3",
}
}
export enum HttpStatus {
STATUS0 = 0,
STATUS1 = 500,
STATUS2 = 503,
}
function fun31(v0?: HttpStatus, v1?: GrantStatus): number;
function fun32(reason: string, callback?: Callback<HttpStatus>): void;
// test interface
}
function fun41(v0?: HttpStatus, v1?: GrantStatus): number;
function fun42(reason: string, callback?: Callback<HttpStatus>): void;
function fun51(v0?: Human, v1?: Human, v2?: Human): number;
function fun52(v0?: Human, v2?: Array<Human>): number;
function fun53(v0?: Human, callback?: Callback<Human>): void;
interface TestClass4 {
interFun41(v0?: Human, v1?: Human, v2?: Human): number;
}
function fun41(v0?: Human, v1?: Human, v2?: Human): number;
function fun42(v0?: Human, v2?: Array<Human>): number;
function fun43(v0?: Human, callback?: Callback<Human>): void;
function fun44(v0?: {name: string, age: number}): number;
interFun51(v0?: Human, v1?: Human, v2?: Human): number;
}
function fun61(v0?: {name: string, age: number}): number;
}
export default napitest;

View File

@ -13,10 +13,12 @@
* limitations under the License.
*/
const test = require("./out/build/Release/napitest")
const { TestClass1, TestClass2, TestClass4} = require("./out/build/Release/napitest")
const { TestClass1, TestClass2 } = require("./out/build/Release/napitest")
const { 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 +29,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 +42,36 @@ 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);
});
function def(ret) {
assert.deepStrictEqual(ret, '');
}
it('test AsyncCallback<Array>', function () {
test.fun23('15').then(def);
});
it('test AsyncCallback<Array>', function () {
let promiseObj = test.fun23('15');
promiseObj.then(ret => { def(ret) });
});
it('test interface array', function () {
let tc = new TestClass2();
ret = tc.interFun21();
assert.strictEqual(ret, 0);
@ -54,12 +79,46 @@ 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);
});
});
describe('Optional2', function () {
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('Optional enum', function () {
var GrantStatus = {
PERMISSION_DEFAULT: "",
PERMISSION_DENIED: "-1",
@ -75,53 +134,56 @@ describe('Optional2', function () {
assert.strictEqual(typeof ret, 'number');
}
it('test enum type', function () {
let ret = test.fun31();
assert.strictEqual(ret, 0);
ret = test.fun31(HttpStatus.STATUS1);
assert.strictEqual(ret, 0);
ret = test.fun31(HttpStatus.STATUS1, GrantStatus.PERMISSION_DENIED);
assert.strictEqual(ret, 0);
ret = test.fun32('1');
ret = test.fun32('1', cb3);
});
});
describe('Optional3', function () {
function cb4(ret) {
assert.notEqual(ret.name,undefined)
assert.notEqual(ret.age,undefined)
}
it('test interface type', function () {
let ret = test.fun41();
assert.strictEqual(ret, 0);
ret = test.fun41({ name: 'n1', age: 20 });
ret = test.fun41(HttpStatus.STATUS1);
assert.strictEqual(ret, 0);
ret = test.fun41({ name: 'n1', age: 20 }, { name: 'n2', age: 30 });
ret = test.fun41(HttpStatus.STATUS1, GrantStatus.PERMISSION_DENIED);
assert.strictEqual(ret, 0);
ret = test.fun41({ name: 'n1', age: 20 }, { name: 'n2', age: 30 }, { name: 'n3', age: 40 });
ret = test.fun42('1');
ret = test.fun42('1', cb3);
});
});
describe('Optional interface', function () {
function cb4(ret) {
assert.notEqual(ret.name, undefined)
assert.notEqual(ret.age, undefined)
}
it('test interface', function () {
let ret = test.fun51();
assert.strictEqual(ret, 0);
ret = test.fun42({ name: 'n1', age: 20 });
ret = test.fun51({ 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.fun51({ name: 'n1', age: 20 }, { name: 'n2', age: 30 });
assert.strictEqual(ret, 0);
ret = test.fun43({ name: 'n1', age: 20 });
ret = test.fun43({ name: 'n1', age: 20 }, cb4);
ret = test.fun44();
ret = test.fun51({ name: 'n1', age: 20 },
{ name: 'n2', age: 30 }, { name: 'n3', age: 40 });
assert.strictEqual(ret, 0);
ret = test.fun44({ name: 'n2', age: 25 });
ret = test.fun52({ name: 'n1', age: 20 });
assert.strictEqual(ret, 0);
ret = test.fun52({ name: 'n1', age: 20 },
[{ name: 'm1', age: 121 }, { name: 'm2', age: 123 }]);
assert.strictEqual(ret, 0);
ret = test.fun53({ name: 'n1', age: 20 });
ret = test.fun53({ name: 'n1', age: 20 }, cb4);
ret = test.fun61();
assert.strictEqual(ret, 0);
ret = test.fun61({ name: 'n2', age: 25 });
assert.strictEqual(ret, 0);
});
it('test interface type', function () {
let tc = new TestClass4();
ret = tc.interFun41();
ret = tc.interFun51({ name: 'n2', age: 25 });
assert.strictEqual(ret, 0);
ret = tc.interFun41({ name: 'n1', age: 20 });
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 });
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);
});

View File

@ -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<string>, cb: Callback<string>): void;
function fun3(v: TestClass1, cb: AsyncCallback<string>): void;
function fun2(v1: string, v2: string[]): string[];
function fun3(v1: Array<string>, v2: string): Array<string>;
function fun4(v: { [key: string]: string }): string;
function fun5(v1: Map<string, string>, v2: string): string;
function fun6(v1: string, callback: AsyncCallback<string>): void;
function fun6(v1: string): Promise<string>;
function fun7(v: string, v1: AsyncCallback<Array<string>>): void;
function fun7(v: string): Promise<Array<string>>;
function fun9(v1: string, callback: Callback<string>): void;
function fun10(v1: Test): Test;
function fun11(v: string, v1: string, v2: string): void;
interface Test {
age: string;
height: string[];
width: Array<string>;
}
/*
function fun11(v1: Test1): Test;
interface Test1 {
address: { [key: string]: string };
long: Map<string, string>;
}
function fun8(v1: string, callback: AsyncCallback<string[]>): void;
function fun8(v1: string): Promise<string[]>;*/
}
export default napitest;

View File

@ -12,27 +12,89 @@
* 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 = fun1("1");
assert.strictEqual(ret, '');
let ret = test.fun1('18');
assert.deepStrictEqual(ret, '');
});
function abc(ret) {
assert.strictEqual(ret, '');
}
it('test fun2', function () {
fun2(['1', '2', '3', '4'], abc);
let ret = test.fun2('18', ['18', '20']);
assert.deepStrictEqual(ret, []);
});
it('test fun3', function () {
fun3({ string1: '3' }).then(abc);
let ret = test.fun3(['18', '20'], '20');
assert.deepStrictEqual(ret, []);
});
it('test fun4', function () {
let ret = test.fun4({ 'isTrue': '18', 'isExit': '20' });
assert.deepStrictEqual(ret, '');
});
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) });
});
});
describe('string', 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, '')
}
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, [])
});
});

40
test/storytest/test_type/@ohos.test.d.ts vendored Executable file
View File

@ -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<string>): void;
fun3(type: 'activate' | 'activating', name: string, callback: Callback<number>): void;
}
class Cat {
fun4(v: 'FixedParamClass', v1: number[]): boolean;
}
type WindowUpdateType = 'add' | 'remove' | 'bounds' | 'active' | 'focus';
function fun5(type: 'FixedParamName', tag: Array<string>): 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;

View File

@ -0,0 +1,58 @@
/*
* 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')
});
});

View File

@ -12,14 +12,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare namespace napitest {
import { AsyncCallback, Callback } from './../basic';
declare namespace napitest {
interface TestClass1 {
union1: string | number | boolean;
}
function fun1(v: number | string | boolean): string;
function fun1(v: number | string | boolean): string;
function fun2(v0: string, v: number | string | boolean): string;
function fun3(v0: string, v: number | string | boolean, no: number): string;
/*
function fun2(v?: Object | Array<any>): number;   --
function fun3(v: Array<string | number | boolean>): number;  --
function fun4(v: { [key: string]: number | string | boolean }): number;   --
function fun5(v: { [key: string]: Test | Array<string | number | boolean> })  --
function fun6(v: Test | string): number;    --
function fun7(v: ResponseCode | string): number;    --
function fun8(v: string, v1: { name: string | boolean | number, age: number }): number;  --
function fun9(v: string, v1: AsyncCallback<string | boolean | number | Test>): void;  --
function fun9(key: string): Promise<string | boolean | number | Test>;
function fun9(v: string, v1: AsyncCallback< Array<string | number | boolean>>): void;  --
function fun9(key: string): Promise<Array<string | number | boolean>>;*/
}
export default napitest;

View File

@ -15,7 +15,7 @@
const { fun1, fun2, fun3 } = require("./out/build/Release/napitest")
var assert = require("assert");
describe('Union', function () {
describe('Union', function () {
it('test fun1_0', function () {
let ret = fun1("1");
assert.strictEqual(ret, '');
@ -30,7 +30,7 @@ describe('Union', function () {
let ret = fun1(true);
assert.strictEqual(ret, '');
});
it('test fun2', function () {
let ret = fun2('0', true);
assert.strictEqual(ret, '');