mirror of
https://gitee.com/openharmony/napi_generator
synced 2024-11-23 16:30:17 +00:00
add storytest
Signed-off-by: zhaojunxia <zhaojunxia@kaihongdigi.com>
This commit is contained in:
parent
c6869eb126
commit
39ca831ab7
@ -131,7 +131,6 @@ function paramGenerateArray(p, name, type, param) {
|
||||
} else {
|
||||
NapiLog.logError("The current version do not support to this param to generate :", name, "type :", type);
|
||||
}
|
||||
return param
|
||||
}
|
||||
|
||||
// 函数的参数处理
|
||||
@ -142,7 +141,7 @@ function paramGenerate(p, name, type, param, data) {
|
||||
param.valueFill += "%svio->in%d".format(param.valueFill.length > 0 ? ", " : "", p)
|
||||
param.valueDefine += "%sstd::string &%s".format(param.valueDefine.length > 0 ? ", " : "", name)
|
||||
}
|
||||
else if (type.substring(0, 12) == "NUMBER_TYPE_") {
|
||||
else if (type.substring(0, 12) == "NUMBER_TYPE_" && type.indexOf("[]") < 0) {
|
||||
param.valueIn += "\n %s in%d;".format(type, p)
|
||||
param.valueCheckout += jsToC("vio->in" + p, "pxt->GetArgv(%d)".format(p), type)
|
||||
param.valueFill += "%svio->in%d".format(param.valueFill.length > 0 ? ", " : "", p)
|
||||
@ -167,7 +166,7 @@ function paramGenerate(p, name, type, param, data) {
|
||||
param.valueFill += "%svio->in%d".format(param.valueFill.length > 0 ? ", " : "", p)
|
||||
param.valueDefine += "%sbool &%s".format(param.valueDefine.length > 0 ? ", " : "", name)
|
||||
} else {
|
||||
param = paramGenerateArray(p, name, type, param);
|
||||
paramGenerateArray(p, name, type, param);
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
|
0
test/storytest/test_direct/basic.d.ts → test/storytest/basic.d.ts
vendored
Executable file → Normal file
0
test/storytest/test_direct/basic.d.ts → test/storytest/basic.d.ts
vendored
Executable file → Normal file
@ -15,11 +15,11 @@ def do_test():
|
||||
return
|
||||
if not os.path.exists("out"):
|
||||
os.mkdir("out")
|
||||
ret=os.popen("node ../../../src/gen/cmd_gen.js -f @ohos.test.d.ts -o ./out")
|
||||
ret = os.popen("node ../../../src/gen/cmd_gen.js -f @ohos.test.d.ts -o ./out")
|
||||
print(ret.read())
|
||||
|
||||
os.chdir("out")
|
||||
ret=os.popen("npx node-gyp configure build")
|
||||
ret = os.popen("npx node-gyp configure build")
|
||||
os.chdir("..")
|
||||
|
||||
if "COPY Release" not in ret.read():
|
||||
@ -35,7 +35,7 @@ if __name__ == "__main__":
|
||||
work_path = os.path.split(sys.argv[0])[0]
|
||||
os.chdir(work_path)
|
||||
|
||||
if len(sys.argv)>=2:
|
||||
if len(sys.argv) >= 2:
|
||||
for fn in sys.argv[1:]:
|
||||
if os.path.isdir(fn):
|
||||
os.chdir(fn)
|
||||
|
17
test/storytest/test_interface/basic.d.ts → test/storytest/test_$/@ohos.test.d.ts
vendored
Executable file → Normal file
17
test/storytest/test_interface/basic.d.ts → test/storytest/test_$/@ohos.test.d.ts
vendored
Executable file → Normal file
@ -12,19 +12,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
export interface Callback<T> {
|
||||
(data: T): void;
|
||||
declare namespace napitest {
|
||||
function $fun1(v: string): string;
|
||||
}
|
||||
|
||||
export interface ErrorCallback<T extends Error = BusinessError> {
|
||||
(err: T): void;
|
||||
}
|
||||
|
||||
export interface AsyncCallback<T> {
|
||||
(err: BusinessError, data: T): void;
|
||||
}
|
||||
|
||||
export interface BusinessError extends Error {
|
||||
code: number;
|
||||
}
|
||||
export default napitest;
|
26
test/storytest/test_$/test.js
Normal file
26
test/storytest/test_$/test.js
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 { $fun1 } = require("./out/build/Release/napitest")
|
||||
var assert = require("assert");
|
||||
|
||||
describe('String', function () {
|
||||
|
||||
it('test $fun1', function () {
|
||||
let ret = $fun1("1");
|
||||
assert.strictEqual(ret, '');
|
||||
});
|
||||
|
||||
});
|
||||
|
19
test/storytest/test_namespace/basic.d.ts → test/storytest/test_[]/@ohos.test.d.ts
vendored
Executable file → Normal file
19
test/storytest/test_namespace/basic.d.ts → test/storytest/test_[]/@ohos.test.d.ts
vendored
Executable file → Normal file
@ -12,19 +12,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
export interface Callback<T> {
|
||||
(data: T): void;
|
||||
declare namespace napitest {
|
||||
function fun1(v1: string[]): number;
|
||||
function fun2(v1: number[]): number;
|
||||
function fun3(v1: boolean[]): number;
|
||||
}
|
||||
|
||||
export interface ErrorCallback<T extends Error = BusinessError> {
|
||||
(err: T): void;
|
||||
}
|
||||
|
||||
export interface AsyncCallback<T> {
|
||||
(err: BusinessError, data: T): void;
|
||||
}
|
||||
|
||||
export interface BusinessError extends Error {
|
||||
code: number;
|
||||
}
|
||||
export default napitest;
|
39
test/storytest/test_[]/test.js
Normal file
39
test/storytest/test_[]/test.js
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 { fun1, fun2, fun3, fun4 } = 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, false, false]);
|
||||
assert.strictEqual(ret, 0);
|
||||
});
|
||||
});
|
||||
|
19
test/storytest/test_number/basic.d.ts → test/storytest/test_array/@ohos.test.d.ts
vendored
Executable file → Normal file
19
test/storytest/test_number/basic.d.ts → test/storytest/test_array/@ohos.test.d.ts
vendored
Executable file → Normal file
@ -12,19 +12,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
export interface Callback<T> {
|
||||
(data: T): void;
|
||||
declare namespace napitest {
|
||||
function fun1(v1: Array<string>): number;
|
||||
function fun2(v1: Array<number>): number;
|
||||
function fun3(v1: Array<boolean>): number;
|
||||
}
|
||||
|
||||
export interface ErrorCallback<T extends Error = BusinessError> {
|
||||
(err: T): void;
|
||||
}
|
||||
|
||||
export interface AsyncCallback<T> {
|
||||
(err: BusinessError, data: T): void;
|
||||
}
|
||||
|
||||
export interface BusinessError extends Error {
|
||||
code: number;
|
||||
}
|
||||
export default napitest;
|
41
test/storytest/test_array/test.js
Normal file
41
test/storytest/test_array/test.js
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 { fun1, fun2, fun3, fun4 } = 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);
|
||||
});
|
||||
|
||||
});
|
||||
|
21
test/storytest/test_bool/@ohos.test.d.ts
vendored
Normal file
21
test/storytest/test_bool/@ohos.test.d.ts
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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 { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
declare namespace napitest {
|
||||
function fun1(v: boolean): boolean;
|
||||
}
|
||||
|
||||
export default napitest;
|
25
test/storytest/test_bool/test.js
Normal file
25
test/storytest/test_bool/test.js
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 { fun1 } = require("./out/build/Release/napitest")
|
||||
var assert = require("assert");
|
||||
|
||||
describe('boolean', function () {
|
||||
it('test fun1', function () {
|
||||
let ret = fun1(true);
|
||||
assert.strictEqual(ret, 0);
|
||||
});
|
||||
|
||||
});
|
||||
|
4
test/storytest/test_direct/@ohos.test.d.ts
vendored
4
test/storytest/test_direct/@ohos.test.d.ts
vendored
@ -12,13 +12,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AsyncCallback, Callback } from './basic';
|
||||
import { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
declare namespace napitest {
|
||||
export interface Result {
|
||||
code: number;
|
||||
data: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface TestClass1 {
|
||||
num1: number;
|
||||
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AsyncCallback, Callback } from './basic';
|
||||
import { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
declare namespace napitest {
|
||||
interface Human {
|
||||
@ -25,7 +25,7 @@ declare namespace napitest {
|
||||
num1: number;
|
||||
fun1(v: number): number;
|
||||
fun2(numcc: Array<number>, mancc: Human): Human;
|
||||
fun3(v: number):boolean;
|
||||
fun3(v: number): boolean;
|
||||
fun4(v2: string, mancc: Array<Human>): Human;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const { TestClass1,TestClass2 } = require("./out/build/Release/napitest")
|
||||
const { TestClass1 } = require("./out/build/Release/napitest")
|
||||
const test = require("./out/build/Release/napitest")
|
||||
var assert = require("assert");
|
||||
const { consumers } = require("stream");
|
||||
@ -27,22 +27,22 @@ describe('Interface', function () {
|
||||
|
||||
it('test TestClass1 fun2', function () {
|
||||
let tc = new TestClass1();
|
||||
let ret = tc.fun2([1,2,3],{name:'haha',age:20});
|
||||
let retJson=JSON.stringify(ret);
|
||||
let ret = tc.fun2([1, 2, 3], { name: 'haha', age: 20 });
|
||||
let retJson = JSON.stringify(ret);
|
||||
assert.strictEqual(retJson, '{"name":"","age":0}');
|
||||
});
|
||||
|
||||
it('test TestClass1 fun3', function () {
|
||||
let tc = new TestClass1();
|
||||
let ret = tc.fun3(2);
|
||||
let retJson=JSON.stringify(ret);
|
||||
let retJson = JSON.stringify(ret);
|
||||
assert.strictEqual(retJson, '0');
|
||||
});
|
||||
|
||||
it('test TestClass1 fun4', function () {
|
||||
let tc = new test.TestClass1();
|
||||
let ret = tc.fun4('aaa',[{name:'haha',age:20},{name:'houhou',age:23}]);
|
||||
let retJson=JSON.stringify(ret);
|
||||
let ret = tc.fun4('aaa', [{ name: 'haha', age: 20 }, { name: 'houhou', age: 23 }]);
|
||||
let retJson = JSON.stringify(ret);
|
||||
assert.strictEqual(retJson, '{"name":"","age":0}');
|
||||
});
|
||||
});
|
||||
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AsyncCallback, Callback } from './basic';
|
||||
import { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
declare namespace napitest {
|
||||
namespace Space3 {
|
||||
@ -23,7 +23,7 @@ declare namespace napitest {
|
||||
}
|
||||
interface TestClass2 {
|
||||
animal: Animal;
|
||||
fix(v1:string):string;
|
||||
fix(v1: string): string;
|
||||
fun2(numcc: Array<number>, animalcc: Animal): Animal;
|
||||
}
|
||||
}
|
||||
|
2
test/storytest/test_number/@ohos.test.d.ts
vendored
2
test/storytest/test_number/@ohos.test.d.ts
vendored
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AsyncCallback, Callback } from './basic';
|
||||
import { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
declare namespace napitest {
|
||||
interface TestClass1 {
|
||||
|
@ -12,7 +12,7 @@
|
||||
* 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 { fun1, fun2, fun3, fun4, fun5 } = require("./out/build/Release/napitest")
|
||||
var assert = require("assert");
|
||||
|
||||
describe('Number', function () {
|
||||
@ -39,7 +39,7 @@ describe('Number', function () {
|
||||
});
|
||||
|
||||
it('test fun4', function () {
|
||||
fun4('aaa',abc);
|
||||
fun4('aaa', abc);
|
||||
});
|
||||
|
||||
function def(ret) {
|
||||
@ -47,7 +47,7 @@ describe('Number', function () {
|
||||
}
|
||||
|
||||
it('test fun5', function () {
|
||||
fun5(12,def);
|
||||
fun5(12, def);
|
||||
//fun5(12).then(def);
|
||||
});
|
||||
|
||||
|
23
test/storytest/test_static/@ohos.test.d.ts
vendored
Normal file
23
test/storytest/test_static/@ohos.test.d.ts
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
declare namespace napitest {
|
||||
class Person {
|
||||
static getMaxAge(v1: string): number;
|
||||
}
|
||||
}
|
||||
|
||||
export default napitest;
|
32
test/storytest/test_static/test.js
Normal file
32
test/storytest/test_static/test.js
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 { Person } = require("./out/build/Release/napitest")
|
||||
const test = require("./out/build/Release/napitest")
|
||||
var assert = require("assert");
|
||||
const { consumers } = require("stream");
|
||||
|
||||
describe('class static', function () {
|
||||
|
||||
it('test PersonClass fun1', function () {
|
||||
let person = new Person();
|
||||
let ret = person.getMaxAge('20');
|
||||
assert.strictEqual(ret, 0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
test/storytest/test_string/@ohos.test.d.ts
vendored
2
test/storytest/test_string/@ohos.test.d.ts
vendored
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AsyncCallback, Callback } from './basic';
|
||||
import { AsyncCallback, Callback } from './../basic';
|
||||
|
||||
declare namespace napitest {
|
||||
interface TestClass1 {
|
||||
|
30
test/storytest/test_string/basic.d.ts
vendored
30
test/storytest/test_string/basic.d.ts
vendored
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export interface Callback<T> {
|
||||
(data: T): void;
|
||||
}
|
||||
|
||||
export interface ErrorCallback<T extends Error = BusinessError> {
|
||||
(err: T): void;
|
||||
}
|
||||
|
||||
export interface AsyncCallback<T> {
|
||||
(err: BusinessError, data: T): void;
|
||||
}
|
||||
|
||||
export interface BusinessError extends Error {
|
||||
code: number;
|
||||
}
|
Loading…
Reference in New Issue
Block a user