Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
f22678c7
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看板
提交
f22678c7
编写于
2月 21, 2023
作者:
H
hekun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
submit the test code
Signed-off-by:
N
hekun
<
hekun18@huawei.com
>
上级
431ea5a8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
155 addition
and
34 deletion
+155
-34
arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp
arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp
+75
-34
arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets
...napi_test/entry/src/main/ets/test/NativeApiStringTest.ets
+80
-0
未找到文件。
arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp
浏览文件 @
f22678c7
...
...
@@ -248,15 +248,28 @@ static napi_value deleteReference(napi_env env, napi_callback_info info) {
}
static
napi_value
referenceRef
(
napi_env
env
,
napi_callback_info
info
)
{
NAPI_ASSERT
(
env
,
test_reference
!=
NULL
,
napi_value
result
=
nullptr
;
napi_ref
resultRef
=
nullptr
;
napi_create_object
(
env
,
&
result
);
napi_create_reference
(
env
,
result
,
1
,
&
resultRef
);
uint32_t
resultRefCount
=
0
;
napi_reference_ref
(
env
,
resultRef
,
&
resultRefCount
);
napi_reference_unref
(
env
,
resultRef
,
&
resultRefCount
);
napi_value
refValue
=
nullptr
;
napi_get_reference_value
(
env
,
resultRef
,
&
refValue
);
NAPI_ASSERT
(
env
,
refValue
!=
NULL
,
"A reference must have been created."
);
napi_delete_reference
(
env
,
resultRef
);
uint32_t
refcount
;
NAPI_CALL
(
env
,
napi_reference_ref
(
env
,
test_reference
,
&
refcount
));
napi_value
_value
;
NAPI_CALL
(
env
,
napi_create_int32
(
env
,
0
,
&
_value
));
return
_value
;
napi_value
result
;
NAPI_CALL
(
env
,
napi_create_uint32
(
env
,
refcount
,
&
result
));
return
result
;
}
static
napi_value
referenceUnref
(
napi_env
env
,
napi_callback_info
info
)
{
...
...
@@ -390,7 +403,15 @@ static napi_value createSymbol(napi_env env, napi_callback_info info) {
napi_value
symbol
;
NAPI_CALL
(
env
,
napi_create_symbol
(
env
,
description
,
&
symbol
));
return
symbol
;
napi_valuetype
valuetypeSymbol
;
NAPI_CALL
(
env
,
napi_typeof
(
env
,
symbol
,
&
valuetypeSymbol
));
NAPI_ASSERT
(
env
,
valuetypeSymbol
==
napi_symbol
,
"Wrong type of arguments. Expects a string."
);
napi_value
_value
;
NAPI_CALL
(
env
,
napi_create_int32
(
env
,
0
,
&
_value
));
return
_value
;
}
static
napi_value
createTypeArray
(
napi_env
env
,
napi_callback_info
info
)
{
...
...
@@ -582,39 +603,37 @@ static napi_value getPrototype(napi_env env, napi_callback_info info) {
}
static
napi_value
getDataViewInfo
(
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_value
arrayBuffer
=
nullptr
;
void
*
arrayBufferPtr
=
nullptr
;
size_t
arrayBufferSize
=
1024
;
napi_create_arraybuffer
(
env
,
arrayBufferSize
,
&
arrayBufferPtr
,
&
arrayBuffer
);
NAPI_ASSERT
(
env
,
arrayBufferPtr
!=
nullptr
,
"napi_create_arraybuffer success"
);
bool
isArrayBuffer
=
false
;
napi_is_arraybuffer
(
env
,
arrayBuffer
,
&
isArrayBuffer
);
napi_value
result
=
nullptr
;
napi_create_dataview
(
env
,
arrayBufferSize
,
arrayBuffer
,
0
,
&
result
);
napi_valuetype
valuetyp
e
;
napi_
value
input_dataview
=
args
[
0
]
;
bool
isDataView
=
fals
e
;
napi_
is_dataview
(
env
,
result
,
&
isDataView
)
;
NAPI_CALL
(
env
,
napi_typeof
(
env
,
input_dataview
,
&
valuetype
));
NAPI_ASSERT
(
env
,
valuetype
==
napi_object
,
"Wrong type of arguments. Expects a DataView as the first "
"argument."
);
napi_value
retArrayBuffer
=
nullptr
;
void
*
data
=
nullptr
;
size_t
byteLength
=
0
;
size_t
byteOffset
=
0
;
napi_get_dataview_info
(
env
,
result
,
&
byteLength
,
&
data
,
&
retArrayBuffer
,
&
byteOffset
);
bool
is_dataview
;
NAPI_CALL
(
env
,
napi_is_dataview
(
env
,
input_dataview
,
&
is_dataview
));
NAPI_ASSERT
(
env
,
is_dataview
,
"Wrong type of arguments. Expects a DataView as the first "
"argument."
);
size_t
byte_offset
=
0
;
size_t
length
=
0
;
napi_value
buffer
;
NAPI_CALL
(
env
,
napi_get_dataview_info
(
env
,
input_dataview
,
&
length
,
NULL
,
&
buffer
,
&
byte_offset
));
napi_value
output_dataview
;
NAPI_CALL
(
env
,
napi_create_dataview
(
env
,
length
,
buffer
,
byte_offset
,
&
output_dataview
));
bool
retIsArrayBuffer
=
false
;
napi_is_arraybuffer
(
env
,
arrayBuffer
,
&
retIsArrayBuffer
);
NAPI_ASSERT
(
env
,
arrayBufferPtr
==
data
,
"napi_get_dataview_info success"
);
NAPI_ASSERT
(
env
,
arrayBufferSize
==
byteLength
,
"napi_get_dataview_info success two"
);
return
output_dataview
;
napi_value
_value
;
NAPI_CALL
(
env
,
napi_create_int32
(
env
,
0
,
&
_value
));
return
_value
;
}
static
napi_value
getValueBool
(
napi_env
env
,
napi_callback_info
info
)
{
...
...
@@ -1336,6 +1355,27 @@ static napi_value napCreateArrayBuffer(napi_env env, napi_callback_info info)
return
arrayBuffer
;
}
static
napi_value
napiGetCbInfo
(
napi_env
env
,
napi_callback_info
info
)
{
size_t
argc
=
1
;
napi_value
args
[
1
];
napi_status
status
=
napi_get_cb_info
(
env
,
info
,
&
argc
,
args
,
NULL
,
NULL
);
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"get_cb_info ok"
);
NAPI_ASSERT
(
env
,
argc
>=
1
,
"Wrong number of arguments"
);
double
value
;
napi_get_value_double
(
env
,
args
[
0
],
&
value
);
napi_valuetype
valuetype
;
NAPI_CALL
(
env
,
napi_typeof
(
env
,
args
[
0
],
&
valuetype
));
NAPI_ASSERT
(
env
,
valuetype
==
napi_number
,
"Wrong type of argment. Expects a nunber."
);
napi_value
returnValue
;
napi_status
statusDouble
=
napi_create_double
(
env
,
value
,
&
returnValue
);
NAPI_ASSERT
(
env
,
statusDouble
==
napi_ok
,
"success to napi_create_double"
);
return
returnValue
;
}
static
napi_value
naiGetArrayBufferInfo
(
napi_env
env
,
napi_callback_info
info
)
{
// the value to return
...
...
@@ -1687,6 +1727,7 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintUint64"
,
napiCreateBigintUint64
),
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintInt64"
,
napiCreateBigintInt64
),
DECLARE_NAPI_FUNCTION
(
"napiCreateBigintWords"
,
napiCreateBigintWords
),
DECLARE_NAPI_FUNCTION
(
"napiGetCbInfo"
,
napiGetCbInfo
),
{
"napiCancelAsyncWork"
,
nullptr
,
napiCancelAsyncWork
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"napiCreateFunction"
,
nullptr
,
napiCreateFunction
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
DECLARE_NAPI_FUNCTION
(
"napiFatalerror"
,
napiFatalerror
),
};
...
...
arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets
浏览文件 @
f22678c7
...
...
@@ -253,5 +253,85 @@ export default function nativeApiStringJsunit() {
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0018
* @tc.name napiGetCbInfo
* @tc.desc aceNapiEtsTest
*/
it
(
'napiGetCbInfo018'
,
0
,
async
function
(
done
)
{
console
.
info
(
'napiGetCbInfo018 START'
);
value
=
napitest
.
napiGetCbInfo
(
12.06
);
console
.
info
(
'napiGetCbInfo018 testString result is: '
+
JSON
.
stringify
(
value
));
expect
(
value
==
12
)
.
assertTrue
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0220
* @tc.name aceNapiTest013
* @tc.desc aceNapiEtsTest
*/
it
(
'aceNapiTest013'
,
0
,
async
function
(
done
)
{
console
.
info
(
'aceNapiTest013 START'
);
let
value
=
napitest
.
getAndClearLastException
();
console
.
info
(
'aceNapiTest013 testString result is: '
+
JSON
.
stringify
(
value
)
+
"--"
+
value
);
expect
(
value
==
undefined
)
.
assertTrue
();
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0280
* @tc.name aceNapiTest019
* @tc.desc aceNapiEtsTest
*/
it
(
'aceNapiTest019'
,
0
,
async
function
(
done
)
{
console
.
info
(
'aceNapiTest019 START'
);
let
value
=
napitest
.
referenceRef
();
console
.
info
(
'napireferenceRef019 testString result is: '
+
value
+
"---"
+
JSON
.
stringify
(
value
)
);
expect
(
value
)
.
assertEqual
(
0
);
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0370
* @tc.name napicreateSymbol028
* @tc.desc aceNapiEtsTest
*/
it
(
'napicreateSymbol028'
,
0
,
async
function
(
done
)
{
console
.
info
(
'napicreateSymbol028 START'
);
let
value
=
napitest
.
createSymbol
(
'symbol'
);
console
.
info
(
'napicreateSymbol028 testString result is: '
+
value
+
"--"
+
JSON
.
stringify
(
value
));
expect
(
value
)
.
assertEqual
(
0
);
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0420
* @tc.name napicreateAndGetInt033
* @tc.desc aceNapiEtsTest
*/
it
(
'napicreateAndGetInt033'
,
0
,
async
function
(
done
)
{
console
.
info
(
'aceNapiTest033 START'
);
let
value
=
napitest
.
createAndGetInt64
(
6
);
console
.
info
(
'aceNapiTest033 testString result is: '
+
value
+
"---"
+
JSON
.
stringify
(
value
));
expect
(
value
)
.
assertEqual
(
6
)
done
();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0480
* @tc.name napigetDataView039
* @tc.desc aceNapiEtsTest
*/
it
(
'napigetDataView039'
,
0
,
async
function
(
done
)
{
console
.
info
(
'napigetDataView039 START'
);
var
buffer
=
new
ArrayBuffer
(
2
);
let
dView
=
new
DataView
(
buffer
)
.
setInt16
(
0
,
256
,
true
);
let
value
=
napitest
.
getDataViewInfo
(
dView
);
console
.
info
(
'napigetDataView039 testString result is: '
+
value
+
"--"
+
JSON
.
stringify
(
value
));
expect
(
value
)
.
assertEqual
(
0
)
done
();
});
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录