提交 f22678c7 编写于 作者: H hekun

submit the test code

Signed-off-by: Nhekun <hekun18@huawei.com>
上级 431ea5a8
...@@ -248,15 +248,28 @@ static napi_value deleteReference(napi_env env, napi_callback_info info) { ...@@ -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) { 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."); "A reference must have been created.");
napi_delete_reference(env, resultRef);
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
uint32_t refcount;
NAPI_CALL(env, napi_reference_ref(env, test_reference, &refcount));
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) { 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) { ...@@ -390,7 +403,15 @@ static napi_value createSymbol(napi_env env, napi_callback_info info) {
napi_value symbol; napi_value symbol;
NAPI_CALL(env, napi_create_symbol(env, description, &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) { 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) { ...@@ -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) { 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_valuetype valuetype; napi_value result = nullptr;
napi_value input_dataview = args[0]; napi_create_dataview(env, arrayBufferSize, arrayBuffer, 0, &result);
NAPI_CALL(env, napi_typeof(env, input_dataview, &valuetype)); bool isDataView = false;
NAPI_ASSERT(env, valuetype == napi_object, napi_is_dataview(env, result, &isDataView);
"Wrong type of arguments. Expects a DataView as the first "
"argument.");
bool is_dataview; napi_value retArrayBuffer = nullptr;
NAPI_CALL(env, napi_is_dataview(env, input_dataview, &is_dataview)); void* data = nullptr;
NAPI_ASSERT(env, is_dataview, size_t byteLength = 0;
"Wrong type of arguments. Expects a DataView as the first " size_t byteOffset = 0;
"argument."); napi_get_dataview_info(env, result, &byteLength, &data, &retArrayBuffer, &byteOffset);
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; bool retIsArrayBuffer = false;
NAPI_CALL(env, napi_is_arraybuffer(env, arrayBuffer, &retIsArrayBuffer);
napi_create_dataview(env, length, buffer,
byte_offset, &output_dataview));
NAPI_ASSERT(env, arrayBufferPtr == data, "napi_get_dataview_info success");
NAPI_ASSERT(env, arrayBufferSize == byteLength, "napi_get_dataview_info success two");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
return output_dataview;
} }
static napi_value getValueBool(napi_env env, napi_callback_info info) { 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) ...@@ -1336,6 +1355,27 @@ static napi_value napCreateArrayBuffer(napi_env env, napi_callback_info info)
return arrayBuffer; 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) static napi_value naiGetArrayBufferInfo(napi_env env, napi_callback_info info)
{ {
// the value to return // the value to return
...@@ -1687,6 +1727,7 @@ static napi_value Init(napi_env env, napi_value exports) ...@@ -1687,6 +1727,7 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("napiCreateBigintUint64", napiCreateBigintUint64), DECLARE_NAPI_FUNCTION("napiCreateBigintUint64", napiCreateBigintUint64),
DECLARE_NAPI_FUNCTION("napiCreateBigintInt64", napiCreateBigintInt64), DECLARE_NAPI_FUNCTION("napiCreateBigintInt64", napiCreateBigintInt64),
DECLARE_NAPI_FUNCTION("napiCreateBigintWords", napiCreateBigintWords), DECLARE_NAPI_FUNCTION("napiCreateBigintWords", napiCreateBigintWords),
DECLARE_NAPI_FUNCTION("napiGetCbInfo", napiGetCbInfo),
{ "napiCancelAsyncWork", nullptr, napiCancelAsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr }, { "napiCancelAsyncWork", nullptr, napiCancelAsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "napiCreateFunction", nullptr, napiCreateFunction, nullptr, nullptr, nullptr, napi_default, nullptr }, { "napiCreateFunction", nullptr, napiCreateFunction, nullptr, nullptr, nullptr, napi_default, nullptr },
DECLARE_NAPI_FUNCTION("napiFatalerror", napiFatalerror), }; DECLARE_NAPI_FUNCTION("napiFatalerror", napiFatalerror), };
......
...@@ -253,5 +253,85 @@ export default function nativeApiStringJsunit() { ...@@ -253,5 +253,85 @@ export default function nativeApiStringJsunit() {
done(); 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.
先完成此消息的编辑!
想要评论请 注册