mirror of
https://gitee.com/openharmony/napi_generator
synced 2024-11-23 08:20:01 +00:00
add testcase for arrow callback
Signed-off-by: zhaojunxia <zhaojunxia@kaihong.com>
This commit is contained in:
parent
603f953059
commit
2d1df115cc
@ -48,9 +48,9 @@ napi_value [middleClassName][funcName]_middle(napi_env env, napi_callback_info i
|
||||
napi_value args[ARGS_SIZE];
|
||||
[valuePackage]
|
||||
{
|
||||
// 回调为,参数个数为1,其转换结果保存在result中
|
||||
// 回调给箭头函数,支持参数个数大于1,参数转换结果保存在args[i]
|
||||
if (ARGS_SIZE == XNapiTool::ONE) {
|
||||
// 回调为Callback<XX>,参数个数为1,其转换结果保存在result中
|
||||
// 回调为箭头函数,支持参数个数大于1,参数转换结果保存在args[i]
|
||||
if (ARGS_SIZE == XNapiTool::ONE && result != nullptr) {
|
||||
args[0] = result;
|
||||
}
|
||||
retVal = pxt->SyncCallBack(pxt->GetArgv([callback_param_offset]), ARGS_SIZE, args);
|
||||
|
2
test/storytest/test_callback/@ohos.test.d.ts
vendored
2
test/storytest/test_callback/@ohos.test.d.ts
vendored
@ -74,7 +74,7 @@ declare namespace napitest {
|
||||
// function fun23nm(cb: (wid: boolean) => TestClass2): string; // 待支持
|
||||
// function fun24nm(cb: (wid: boolean) => Human): string; // 待支持
|
||||
|
||||
// 以下测试用例待支持
|
||||
// // 以下测试用例待支持
|
||||
|
||||
function fun9(cb: (wid: boolean, str: string, tc2:number) => string): string;
|
||||
|
||||
|
@ -43,6 +43,14 @@ function onCallbackVoid () {
|
||||
|
||||
}
|
||||
|
||||
function onCallbackBooleanVStr (isOK) {
|
||||
let str
|
||||
if (isOK) {
|
||||
str = 'a' + 'b'
|
||||
}
|
||||
// return 'test aaa'
|
||||
}
|
||||
|
||||
describe('Test interface callback', function () {
|
||||
// fun11(cb: Callback<number>): void;
|
||||
it('test callback in interface fun11', function () {
|
||||
@ -124,4 +132,11 @@ describe('Test callback', function () {
|
||||
let ret = testObj.fun7(onCallbackVoid);
|
||||
assert.strictEqual(ret, '');
|
||||
});
|
||||
|
||||
// function fun8(cb: (wid: boolean) => void): string;
|
||||
it('test common func callback fun8', function () {
|
||||
let ret = ''
|
||||
ret = testObj.fun8(onCallbackBooleanVStr);
|
||||
assert.strictEqual(ret, '');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user