Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
dfdb98ac
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
dfdb98ac
编写于
1年前
作者:
O
openharmony_ci
提交者:
Gitee
1年前
浏览文件
操作
浏览文件
下载
差异文件
!8445 Add Napi xts use case
Merge pull request !8445 from lwx1067109/master
上级
cb7c1bab
20b7aa28
master
OpenHarmony-4.0-Beta1
OpenHarmony-4.0-Beta2
monthly_20230815
revert-merge-8920-master
revert-merge-9046-master
revert-merge-9047-master
revert-merge-9049-master
revert-merge-9077-master
revert-merge-9108-master
revert-merge-9210-master
revert-merge-9281-master
revert-merge-9324-master
revert-merge-9325-master
revert-merge-9329-master
revert-merge-9330-master
revert-merge-9359-master
revert-merge-9361-master
weekly_20230425
weekly_20230502
weekly_20230509
weekly_20230516
weekly_20230523
weekly_20230530
weekly_20230606
weekly_20230613
weekly_20230619
weekly_20230626
weekly_20230627
weekly_20230704
weekly_20230712
weekly_20230725
weekly_20230801
weekly_20230808
weekly_20230815
weekly_20230822
weekly_20230829
OpenHarmony-v4.0-Beta2
OpenHarmony-v4.0-Beta1
无相关合并请求
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
178 addition
and
0 deletion
+178
-0
arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp
arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp
+94
-0
arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets
...napi_test/entry/src/main/ets/test/NativeApiStringTest.ets
+84
-0
未找到文件。
arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp
浏览文件 @
dfdb98ac
...
...
@@ -666,6 +666,96 @@ static napi_value createAndGetStringUtf8(napi_env env, napi_callback_info info)
return
output
;
}
static
napi_value
CreateAndGetStringUtf16
(
napi_env
env
,
napi_callback_info
info
)
{
size_t
argc
=
1
;
napi_value
args
[
1
];
NAPI_CALL
(
env
,
napi_get_cb_info
(
env
,
info
,
&
argc
,
args
,
NULL
,
NULL
));
NAPI_ASSERT
(
env
,
argc
>=
1
,
"Wrong number of arguments."
);
napi_valuetype
valuetype
;
NAPI_CALL
(
env
,
napi_typeof
(
env
,
args
[
0
],
&
valuetype
));
NAPI_ASSERT
(
env
,
valuetype
==
napi_string
,
"Expect a string."
);
char16_t
buffer
[
128
];
// 128: char16_t type of element size
size_t
buffer_size
=
128
;
// 128: char16_t type of element size
size_t
copied
=
0
;
NAPI_CALL
(
env
,
napi_get_value_string_utf16
(
env
,
args
[
0
],
buffer
,
buffer_size
,
&
copied
));
napi_value
result
;
NAPI_CALL
(
env
,
napi_create_string_utf16
(
env
,
buffer
,
copied
,
&
result
));
return
result
;
}
static
napi_value
StringUtf16OfCase
(
napi_env
env
,
napi_callback_info
info
)
{
size_t
argc
=
1
;
napi_value
args
[
1
];
NAPI_CALL
(
env
,
napi_get_cb_info
(
env
,
info
,
&
argc
,
args
,
NULL
,
NULL
));
NAPI_ASSERT
(
env
,
argc
>=
1
,
"Wrong number of arguments."
);
napi_valuetype
valuetype
;
NAPI_CALL
(
env
,
napi_typeof
(
env
,
args
[
0
],
&
valuetype
));
NAPI_ASSERT
(
env
,
valuetype
==
napi_string
,
"Expects a string."
);
char16_t
buffer
[
5
];
// 5: char16_t type of element size
size_t
buffer_size
=
5
;
// 5: char16_t type of element size
size_t
copied
=
0
;
NAPI_CALL
(
env
,
napi_get_value_string_utf16
(
env
,
args
[
0
],
buffer
,
buffer_size
,
&
copied
));
napi_value
result
;
NAPI_CALL
(
env
,
napi_create_string_utf16
(
env
,
buffer
,
copied
,
&
result
));
return
result
;
}
static
const
napi_type_tag
typeTags
[
5
]
=
{
{
0xdaf987b3cc62481a
,
0xb745b0497f299531
},
{
0xbb7936c374084d9b
,
0xa9548d0762eeedb9
},
{
0xa5ed9ce2e4c00c38
,
0xa9548d0762eeedb1
},
{
0
,
0
},
{
0xa5ed9ce2e4c00c38
,
0xdaf987b3cc62481a
},
};
static
napi_value
TypeTaggedInstance
(
napi_env
env
,
napi_callback_info
info
)
{
size_t
argc
=
1
;
uint32_t
typeIndex
=
0
;
napi_value
instance
=
nullptr
;
napi_value
whichType
=
nullptr
;
NAPI_CALL
(
env
,
napi_get_cb_info
(
env
,
info
,
&
argc
,
&
whichType
,
NULL
,
NULL
));
NAPI_CALL
(
env
,
napi_get_value_uint32
(
env
,
whichType
,
&
typeIndex
));
NAPI_ASSERT
(
env
,
typeIndex
<=
5
,
"typeIndex out of range"
);
NAPI_CALL
(
env
,
napi_create_object
(
env
,
&
instance
));
NAPI_CALL
(
env
,
napi_type_tag_object
(
env
,
instance
,
&
typeTags
[
typeIndex
]));
return
instance
;
}
static
napi_value
CheckTypeTag
(
napi_env
env
,
napi_callback_info
info
)
{
size_t
argc
=
2
;
bool
result
;
napi_value
argv
[
2
];
napi_value
jsResult
=
nullptr
;
uint32_t
typeIndex
;
NAPI_CALL
(
env
,
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
NULL
,
NULL
));
NAPI_CALL
(
env
,
napi_get_value_uint32
(
env
,
argv
[
0
],
&
typeIndex
));
NAPI_ASSERT
(
env
,
typeIndex
<=
5
,
"typeIndex out of range"
);
NAPI_CALL
(
env
,
napi_check_object_type_tag
(
env
,
argv
[
1
],
&
typeTags
[
typeIndex
],
&
result
));
NAPI_CALL
(
env
,
napi_get_boolean
(
env
,
result
,
&
jsResult
));
return
jsResult
;
}
static
napi_value
getPrototype
(
napi_env
env
,
napi_callback_info
info
)
{
napi_value
testWrapClass
=
nullptr
;
...
...
@@ -2192,6 +2282,10 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintInt64"
,
napiCreateBigintInt64
),
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintWords"
,
napiCreateBigintWords
),
DECLARE_NAPI_FUNCTION
(
"napiGetCbInfo"
,
napiGetCbInfo
),
DECLARE_NAPI_FUNCTION
(
"checkTypeTag"
,
CheckTypeTag
),
DECLARE_NAPI_FUNCTION
(
"typeTaggedInstance"
,
TypeTaggedInstance
),
DECLARE_NAPI_FUNCTION
(
"stringUtf16OfCase"
,
StringUtf16OfCase
),
DECLARE_NAPI_FUNCTION
(
"createAndGetStringUtf16"
,
CreateAndGetStringUtf16
),
{
"napiCancelAsyncWork"
,
nullptr
,
napiCancelAsyncWork
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"testAsyncWork"
,
nullptr
,
testAsyncWork
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"testPromise"
,
nullptr
,
testPromise
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
...
...
This diff is collapsed.
Click to expand it.
arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets
浏览文件 @
dfdb98ac
...
...
@@ -1339,5 +1339,89 @@ export default function nativeApiStringJsunit() {
expect
(
value
)
.
assertEqual
(
0
);
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0093
* @tc.name aceNapiTest093
* @tc.desc aceNapiEtsTest
*/
it
(
'aceNapiTest093'
,
0
,
async
function
(
done
)
{
console
.
info
(
'aceNapiTest093 START'
);
let
value
=
napitest
.
createAndGetStringUtf16
(
'he'
);
console
.
info
(
'aceNapiTest093 testString result is: '
+
value
+
"--"
+
JSON
.
stringify
(
value
));
let
value1
=
napitest
.
stringUtf16OfCase
(
'abc2r42'
);
console
.
info
(
'aceNapiTest093 testString result is: '
+
value1
+
"--"
+
JSON
.
stringify
(
value1
));
expect
(
value
)
.
assertEqual
(
'he'
);
expect
(
value1
)
.
assertEqual
(
'abc2'
);
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0094
* @tc.name aceNapiTest094
* @tc.desc aceNapiEtsTest
*/
it
(
'aceNapiTest094'
,
0
,
async
function
(
done
)
{
console
.
info
(
'aceNapiTest094 START'
);
let
valueeEmpty
=
napitest
.
createAndGetStringUtf16
(
' '
);
console
.
info
(
'aceNapiTest094 testString result is: '
+
valueeEmpty
+
"--"
+
JSON
.
stringify
(
valueeEmpty
));
expect
(
valueeEmpty
)
.
assertEqual
(
' '
);
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0095
* @tc.name aceNapiTest095
* @tc.desc aceNapiEtsTest
*/
it
(
'aceNapiTest095'
,
0
,
async
function
(
done
)
{
console
.
info
(
'aceNapiTest095 START'
);
let
obj1
=
napitest
.
typeTaggedInstance
(
0
);
let
obj2
=
napitest
.
typeTaggedInstance
(
1
);
let
obj3
=
napitest
.
typeTaggedInstance
(
2
);
let
obj4
=
napitest
.
typeTaggedInstance
(
3
);
let
isTag
=
napitest
.
checkTypeTag
(
0
,
obj1
);
let
isTag1
=
napitest
.
checkTypeTag
(
1
,
obj2
);
let
isTag2
=
napitest
.
checkTypeTag
(
2
,
obj3
);
let
isTag3
=
napitest
.
checkTypeTag
(
3
,
obj4
);
console
.
info
(
'aceNapiTest095 testTypeTag result is: '
+
isTag
+
"--"
+
JSON
.
stringify
(
isTag
));
expect
(
isTag
)
.
assertTrue
();
console
.
info
(
'aceNapiTest095 testTypeTag result is: '
+
isTag1
+
"--"
+
JSON
.
stringify
(
isTag1
));
expect
(
isTag1
)
.
assertTrue
();
console
.
info
(
'aceNapiTest095 testTypeTag result is: '
+
isTag2
+
"--"
+
JSON
.
stringify
(
isTag2
));
expect
(
isTag2
)
.
assertTrue
();
console
.
info
(
'aceNapiTest095 testTypeTag result is: '
+
isTag3
+
"--"
+
JSON
.
stringify
(
isTag3
));
expect
(
isTag3
)
.
assertTrue
();
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0096
* @tc.name aceNapiTest096
* @tc.desc aceNapiEtsTest
*/
it
(
'aceNapiTest096'
,
0
,
async
function
(
done
)
{
console
.
info
(
'aceNapiTest096 START'
);
let
obj1
=
napitest
.
typeTaggedInstance
(
0
);
let
obj2
=
napitest
.
typeTaggedInstance
(
1
);
let
obj3
=
napitest
.
typeTaggedInstance
(
2
);
let
obj4
=
napitest
.
typeTaggedInstance
(
3
);
let
isTag
=
napitest
.
checkTypeTag
(
1
,
obj1
);
let
isTag1
=
napitest
.
checkTypeTag
(
0
,
obj2
);
let
isTag2
=
napitest
.
checkTypeTag
(
1
,
obj4
);
let
isTag3
=
napitest
.
checkTypeTag
(
3
,
obj3
);
let
isTag4
=
napitest
.
checkTypeTag
(
4
,
obj3
);
console
.
info
(
'aceNapiTest096 testTypeTag result is: '
+
isTag
+
"--"
+
JSON
.
stringify
(
isTag
));
expect
(
isTag
)
.
assertFalse
();
console
.
info
(
'aceNapiTest096 testTypeTag result is: '
+
isTag1
+
"--"
+
JSON
.
stringify
(
isTag1
));
expect
(
isTag1
)
.
assertFalse
();
console
.
info
(
'aceNapiTest096 testTypeTag result is: '
+
isTag2
+
"--"
+
JSON
.
stringify
(
isTag2
));
expect
(
isTag2
)
.
assertFalse
();
console
.
info
(
'aceNapiTest096 testTypeTag result is: '
+
isTag3
+
"--"
+
JSON
.
stringify
(
isTag3
));
expect
(
isTag3
)
.
assertFalse
();
console
.
info
(
'aceNapiTest096 testTypeTag result is: '
+
isTag4
+
"--"
+
JSON
.
stringify
(
isTag4
));
expect
(
isTag4
)
.
assertFalse
();
done
();
});
})
}
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录