未验证 提交 a8a1c50e 编写于 作者: O openharmony_ci 提交者: Gitee

!7877 napi xts 用例修复与补充

Merge pull request !7877 from huangzhenghua/master20230307-2
......@@ -21,17 +21,19 @@
#include <vector>
#include <malloc.h>
#include <ctime>
#include <thread>
#include <uv.h>
static bool exceptionWasPending = false;
static napi_ref test_reference = NULL;
const int TAG_NUMBER = 666;
static void add_returned_status(napi_env env,
const char* key,
napi_value object,
const char* expected_message,
napi_status expected_status,
napi_status actual_status) {
napi_status actual_status)
{
char napi_message_string[100] = "";
napi_value prop_value;
......@@ -53,7 +55,8 @@ static void add_returned_status(napi_env env,
prop_value));
}
static void add_last_status(napi_env env, const char* key, napi_value return_value) {
static void add_last_status(napi_env env, const char* key, napi_value return_value)
{
napi_value prop_value;
const napi_extended_error_info* p_last_error;
NAPI_CALL_RETURN_VOID(env, napi_get_last_error_info(env, &p_last_error));
......@@ -71,7 +74,8 @@ static void add_last_status(napi_env env, const char* key, napi_value return_val
prop_value));
}
static napi_value getLastErrorInfo(napi_env env, napi_callback_info info) {
static napi_value getLastErrorInfo(napi_env env, napi_callback_info info)
{
napi_value value;
NAPI_CALL(env, napi_create_string_utf8(env, "xyz", 3, &value));
double double_value;
......@@ -89,7 +93,8 @@ static napi_value getLastErrorInfo(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value cleanUpErrorInfo(napi_env env, napi_callback_info info) {
static napi_value cleanUpErrorInfo(napi_env env, napi_callback_info info)
{
const napi_extended_error_info * error_info = 0;
NAPI_CALL(env, napi_get_last_error_info(env, &error_info));
......@@ -100,7 +105,8 @@ static napi_value cleanUpErrorInfo(napi_env env, napi_callback_info info) {
return result;
}
static napi_value throwExistingError(napi_env env, napi_callback_info info) {
static napi_value throwExistingError(napi_env env, napi_callback_info info)
{
napi_value code = nullptr;
napi_value message = nullptr;
napi_create_string_latin1(env, "600", NAPI_AUTO_LENGTH, &code);
......@@ -119,7 +125,8 @@ static napi_value throwExistingError(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value throwError(napi_env env, napi_callback_info info) {
static napi_value throwError(napi_env env, napi_callback_info info)
{
napi_value code = nullptr;
napi_value message = nullptr;
napi_create_string_latin1(env, "600", NAPI_AUTO_LENGTH, &code);
......@@ -136,11 +143,12 @@ static napi_value throwError(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value throwTypeError(napi_env env, napi_callback_info info) {
static napi_value throwTypeError(napi_env env, napi_callback_info info)
{
napi_value code = nullptr;
napi_value message = nullptr;
napi_create_string_latin1(env, "500", NAPI_AUTO_LENGTH, &code);
napi_create_string_latin1(env, "type error1", NAPI_AUTO_LENGTH, &message);
napi_create_string_latin1(env, "type error 500", NAPI_AUTO_LENGTH, &message);
napi_value error = nullptr;
napi_create_type_error(env, code, message, &error);
NAPI_ASSERT(env, error != nullptr, "error succes");
......@@ -154,11 +162,12 @@ static napi_value throwTypeError(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value throwRangeError(napi_env env, napi_callback_info info) {
static napi_value throwRangeError(napi_env env, napi_callback_info info)
{
napi_value code = nullptr;
napi_value message = nullptr;
napi_create_string_latin1(env, "500", NAPI_AUTO_LENGTH, &code);
napi_create_string_latin1(env, "range error", NAPI_AUTO_LENGTH, &message);
napi_create_string_latin1(env, "range error 500", NAPI_AUTO_LENGTH, &message);
napi_value error = nullptr;
napi_create_range_error(env, code, message, &error);
NAPI_ASSERT(env, error != nullptr, "error succes");
......@@ -172,7 +181,8 @@ static napi_value throwRangeError(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value isError(napi_env env, napi_callback_info info) {
static napi_value isError(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));
......@@ -186,7 +196,8 @@ static napi_value isError(napi_env env, napi_callback_info info) {
return result;
}
static napi_value createError(napi_env env, napi_callback_info info) {
static napi_value createError(napi_env env, napi_callback_info info)
{
napi_value code = nullptr;
napi_value message = nullptr;
......@@ -202,7 +213,8 @@ static napi_value createError(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value createTypeError(napi_env env, napi_callback_info info) {
static napi_value createTypeError(napi_env env, napi_callback_info info)
{
napi_value code = nullptr;
napi_value message = nullptr;
napi_create_string_latin1(env, "500", NAPI_AUTO_LENGTH, &code);
......@@ -216,7 +228,8 @@ static napi_value createTypeError(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value createRangeError(napi_env env, napi_callback_info info) {
static napi_value createRangeError(napi_env env, napi_callback_info info)
{
napi_value code = nullptr;
napi_value message = nullptr;
napi_create_string_latin1(env, "500", NAPI_AUTO_LENGTH, &code);
......@@ -231,37 +244,48 @@ static napi_value createRangeError(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value getAndClearLastException(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));
static napi_value getAndClearLastException(napi_env env, napi_callback_info info)
{
napi_value code = nullptr;
napi_value message = nullptr;
napi_create_string_latin1(env, "600", NAPI_AUTO_LENGTH, &code);
napi_create_string_latin1(env, "tag range error", NAPI_AUTO_LENGTH, &message);
napi_value error = nullptr;
napi_create_range_error(env, code, message, &error);
NAPI_ASSERT(env, error != nullptr, "tag error succes");
napi_value global;
NAPI_CALL(env, napi_get_global(env, &global));
bool isError = false;
napi_is_error(env, error, &isError);
NAPI_ASSERT(env, isError, "tag isError 1");
napi_value result;
napi_status status = napi_call_function(env, global, args[0], 0, 0, &result);
if (status == napi_pending_exception) {
napi_value ex;
NAPI_CALL(env, napi_get_and_clear_last_exception(env, &ex));
return ex;
}
napi_get_and_clear_last_exception(env, &ex);
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
bool exceptionWasPending = true;
napi_is_exception_pending(env, &exceptionWasPending);
NAPI_ASSERT(env, !exceptionWasPending, "tag !exceptionWasPending 1");
static napi_value isExceptionPending(napi_env env, napi_callback_info info) {
napi_value code = nullptr;
napi_value message = nullptr;
napi_create_string_latin1(env, "500", NAPI_AUTO_LENGTH, &code);
napi_create_string_latin1(env, "range error", NAPI_AUTO_LENGTH, &message);
napi_value error = nullptr;
napi_create_range_error(env, code, message, &error);
napi_throw(env, error);
NAPI_ASSERT(env, error != nullptr, "error succes");
napi_is_exception_pending(env, &exceptionWasPending);
NAPI_ASSERT(env, exceptionWasPending, "tag exceptionWasPending 2");
napi_value ex1;
napi_get_and_clear_last_exception(env, &ex1);
isError = false;
napi_is_error(env, ex1, &isError);
NAPI_ASSERT(env, isError, "tag isError 2");
napi_is_exception_pending(env, &exceptionWasPending);
NAPI_ASSERT(env, !exceptionWasPending, "tag !exceptionWasPending 3");
return ex1;
}
static napi_value isExceptionPending(napi_env env, napi_callback_info info)
{
bool exceptionWasPending = false;
napi_is_exception_pending(env, &exceptionWasPending);
NAPI_ASSERT(env, exceptionWasPending, "error succes");
......@@ -271,58 +295,72 @@ static napi_value isExceptionPending(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value openAndCloseHandleScope(napi_env env, napi_callback_info info) {
static napi_value openAndCloseHandleScope(napi_env env, napi_callback_info info)
{
napi_handle_scope scope;
napi_value output = NULL;
NAPI_CALL(env, napi_open_handle_scope(env, &scope));
napi_value output = NULL;
NAPI_CALL(env, napi_create_object(env, &output));
NAPI_CALL(env, napi_close_handle_scope(env, scope));
return NULL;
return output;
}
static napi_value openAndCloseEscapableHandleScope(napi_env env, napi_callback_info info) {
static napi_value openAndCloseEscapableHandleScope(napi_env env, napi_callback_info info)
{
napi_escapable_handle_scope scope;
NAPI_CALL(env, napi_open_escapable_handle_scope(env, &scope));
napi_value output = NULL;
napi_value escapee = NULL;
NAPI_CALL(env, napi_open_escapable_handle_scope(env, &scope));
NAPI_CALL(env, napi_create_object(env, &output));
NAPI_CALL(env, napi_escape_handle(env, scope, output, &escapee));
NAPI_CALL(env, napi_close_escapable_handle_scope(env, scope));
return escapee;
}
static napi_value createReference(napi_env env, napi_callback_info info) {
static napi_value createReference(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_ref resultRef = nullptr;
napi_create_object(env, &result);
NAPI_CALL(env, napi_create_reference(env, result, 1, &resultRef));
napi_create_int32(env, TAG_NUMBER, &result);
NAPI_CALL(env, napi_create_reference(env, result, 1, &test_reference));
napi_value value;
NAPI_CALL(env, napi_create_int32(env, 0, &value));
return value;
}
static napi_value deleteReference(napi_env env, napi_callback_info info) {
static napi_value getAndDeleteReference(napi_env env, napi_callback_info info)
{
NAPI_ASSERT(env, test_reference != NULL,
"A reference must have been created.");
napi_value refValue = nullptr;
napi_get_reference_value(env, test_reference, &refValue);
int32_t value = 0;
napi_get_value_int32(env, refValue, &value);
NAPI_ASSERT(env, value == TAG_NUMBER,
"refValue expect equal to 666.");
NAPI_CALL(env, napi_delete_reference(env, test_reference));
test_reference = NULL;
return NULL;
}
static napi_value referenceRef(napi_env env, napi_callback_info info) {
static napi_value referenceRefAndUnref(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
napi_ref resultRef = nullptr;
uint32_t resultRefCount = 0;
napi_create_object(env, &result);
napi_create_reference(env, result, 1, &resultRef);
uint32_t resultRefCount = 0;
napi_reference_ref(env, resultRef, &resultRefCount);
NAPI_ASSERT(env, resultRefCount == 2,
"resultRefCount expect equal to 2");
napi_reference_unref(env, resultRef, &resultRefCount);
NAPI_ASSERT(env, resultRefCount == 1,
"resultRefCount expect equal to 1.");
napi_value refValue = nullptr;
napi_get_reference_value(env, resultRef, &refValue);
......@@ -336,46 +374,8 @@ static napi_value referenceRef(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value referenceUnref(napi_env env, napi_callback_info info) {
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_CALL(env, napi_reference_unref(env, resultRef, &resultRefCount));
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
static napi_value getReferenceValue(napi_env env, napi_callback_info info) {
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_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
static napi_value createArrayAndGetLength(napi_env env, napi_callback_info info) {
static napi_value createArrayAndGetLength(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));
......@@ -399,11 +399,11 @@ static napi_value createArrayAndGetLength(napi_env env, napi_callback_info info)
NAPI_CALL(env, napi_get_element(env, args[0], i, &e));
NAPI_CALL(env, napi_set_element(env, ret, i, e));
}
return ret;
}
static napi_value getArrayWithLength(napi_env env, napi_callback_info info) {
static napi_value getArrayWithLength(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));
......@@ -416,19 +416,23 @@ static napi_value getArrayWithLength(napi_env env, napi_callback_info info) {
NAPI_ASSERT(env, valuetype0 == napi_object,
"Wrong type of arguments. Expects an integer the first argument.");
uint32_t array_length;
uint32_t array_length = 0;
NAPI_CALL(env, napi_get_array_length(env, args[0], &array_length));
NAPI_ASSERT(env, array_length == 2, "array_length expect equal to 2");
napi_value ret;
NAPI_CALL(env, napi_create_array_with_length(env, array_length, &ret));
for (uint32_t i = 0; i < array_length * 2; i++) {
napi_value e;
NAPI_CALL(env, napi_create_uint32(env, i, &e));
NAPI_CALL(env, napi_set_element(env, ret, i, e));
}
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
return ret;
}
static napi_value createExternal(napi_env env, napi_callback_info info) {
static napi_value createExternal(napi_env env, napi_callback_info info)
{
const char testStr[] = "test";
napi_value external = nullptr;
napi_create_external(
......@@ -437,6 +441,8 @@ static napi_value createExternal(napi_env env, napi_callback_info info) {
(void*)testStr, &external);
void* tempExternal = nullptr;
NAPI_CALL(env, napi_get_value_external(env, external, &tempExternal));
NAPI_ASSERT(env, tempExternal != nullptr, "tempExternal expect not equal to nullptr");
NAPI_ASSERT(env, tempExternal == testStr, "tempExternal expect equal to testStr");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
......@@ -444,33 +450,35 @@ static napi_value createExternal(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value createExternalArraybuffer(napi_env env, napi_callback_info info) {
const char testStr[] = "test";
static napi_value createExternalArraybuffer(napi_env env, napi_callback_info info)
{
int* testInt = (int*)malloc(sizeof(int));
*testInt = TAG_NUMBER;
napi_value external = nullptr;
size_t arrayBufferSize = 1024;
napi_create_external_arraybuffer(
env, (void*)testStr, arrayBufferSize,
[](napi_env env, void* data, void* hint) {},
(void*)testStr, &external);
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
env, (void*)testInt, arrayBufferSize,
[](napi_env env, void* data, void* hint) {
int* temp = static_cast<int*>(data);
free(temp);
temp = nullptr;
},
(void*)testInt, &external);
return _value;
return external;
}
static napi_value createObject(napi_env env, napi_callback_info info) {
static napi_value createObject(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
NAPI_CALL(env, napi_create_object(env, &result));
NAPI_ASSERT(env, result != nullptr, "napi_create_object");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
return result;
}
static napi_value createSymbol(napi_env env, napi_callback_info info) {
static napi_value createSymbol(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));
......@@ -500,10 +508,12 @@ static napi_value createSymbol(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value createTypeArray(napi_env env, napi_callback_info info) {
static napi_value createTypeArray(napi_env env, napi_callback_info info)
{
napi_value arrayBuffer = nullptr;
void* arrayBufferPtr = nullptr;
size_t arrayBufferSize = 1024;
size_t arrayBufferSize = 16;
size_t typedArrayLength = 4;
napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer);
void* tmpArrayBufferPtr = nullptr;
......@@ -514,15 +524,16 @@ static napi_value createTypeArray(napi_env env, napi_callback_info info) {
NAPI_ASSERT(env, arrayBufferSize == arrayBufferLength, "napi_create_arraybuffer success");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
napi_create_typedarray(env, napi_int32_array, typedArrayLength, arrayBuffer, 0, &_value);
return _value;
}
static napi_value createDataView(napi_env env, napi_callback_info info) {
static napi_value createDataView(napi_env env, napi_callback_info info)
{
napi_value arrayBuffer = nullptr;
void* arrayBufferPtr = nullptr;
size_t arrayBufferSize = 1024;
size_t arrayBufferSize = 16;
napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer);
NAPI_ASSERT(env, arrayBufferPtr != nullptr, "napi_create_arraybuffer success");
bool isArrayBuffer = false;
......@@ -534,14 +545,13 @@ static napi_value createDataView(napi_env env, napi_callback_info info) {
bool isDataView = false;
napi_is_dataview(env, result, &isDataView);
NAPI_ASSERT(env, isDataView, " napi_is_dataview success");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
return result;
}
static napi_value createAndGetInt32(napi_env env, napi_callback_info info) {
static napi_value createAndGetInt32(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));
......@@ -555,7 +565,8 @@ static napi_value createAndGetInt32(napi_env env, napi_callback_info info) {
return output;
}
static napi_value createAndGetUInt32(napi_env env, napi_callback_info info) {
static napi_value createAndGetUInt32(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));
......@@ -569,7 +580,8 @@ static napi_value createAndGetUInt32(napi_env env, napi_callback_info info) {
return output;
}
static napi_value createAndGetInt64(napi_env env, napi_callback_info info) {
static napi_value createAndGetInt64(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));
......@@ -583,7 +595,8 @@ static napi_value createAndGetInt64(napi_env env, napi_callback_info info) {
return output;
}
static napi_value createDouble(napi_env env, napi_callback_info info) {
static napi_value createDouble(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));
......@@ -597,7 +610,8 @@ static napi_value createDouble(napi_env env, napi_callback_info info) {
return output;
}
static napi_value createAndGetStringLatin1(napi_env env, napi_callback_info info) {
static napi_value createAndGetStringLatin1(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));
......@@ -612,10 +626,11 @@ static napi_value createAndGetStringLatin1(napi_env env, napi_callback_info info
char buffer[128];
size_t buffer_size = 128;
size_t copied;
size_t copied = 0;
NAPI_CALL(env,
napi_get_value_string_latin1(env, args[0], buffer, buffer_size, &copied));
NAPI_ASSERT(env, copied == 3, "napi_get_value_string_latin1 fail");
napi_value output;
NAPI_CALL(env, napi_create_string_latin1(env, buffer, copied, &output));
......@@ -623,7 +638,8 @@ static napi_value createAndGetStringLatin1(napi_env env, napi_callback_info info
return output;
}
static napi_value createAndGetStringUtf8(napi_env env, napi_callback_info info) {
static napi_value createAndGetStringUtf8(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));
......@@ -638,10 +654,11 @@ static napi_value createAndGetStringUtf8(napi_env env, napi_callback_info info)
char buffer[128];
size_t buffer_size = 128;
size_t copied;
size_t copied = 0;
NAPI_CALL(env,
napi_get_value_string_utf8(env, args[0], buffer, buffer_size, &copied));
NAPI_ASSERT(env, copied == 2, "napi_get_value_string_utf8 fail");
napi_value output;
NAPI_CALL(env, napi_create_string_utf8(env, buffer, copied, &output));
......@@ -649,7 +666,8 @@ static napi_value createAndGetStringUtf8(napi_env env, napi_callback_info info)
return output;
}
static napi_value getPrototype(napi_env env, napi_callback_info info) {
static napi_value getPrototype(napi_env env, napi_callback_info info)
{
napi_value testWrapClass = nullptr;
napi_define_class(env, "TestWrapClass", NAPI_AUTO_LENGTH, [](napi_env env, napi_callback_info info) -> napi_value {
napi_value thisVar = nullptr;
......@@ -659,48 +677,113 @@ static napi_value getPrototype(napi_env env, napi_callback_info info) {
napi_value customClassPrototype = nullptr;
NAPI_CALL(env, napi_get_prototype(env, testWrapClass, &customClassPrototype));
NAPI_ASSERT(env, customClassPrototype != nullptr, "napi_get_prototype fail");
return customClassPrototype;
}
static napi_value getPrototype2(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_function,
"Wrong type of argment. Expects a napi_function.");
napi_value customClassPrototype = nullptr;
NAPI_CALL(env, napi_get_prototype(env, args[0], &customClassPrototype));
NAPI_ASSERT(env, customClassPrototype != nullptr, "napi_get_prototype fail");
return customClassPrototype;
}
static napi_value getTypedArrayInfo(napi_env env, napi_callback_info info)
{
napi_value arrayBuffer = nullptr;
void* arrayBufferPtr = nullptr;
size_t arrayBufferSize = 16;
size_t typedArrayLength = 4;
napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer);
NAPI_ASSERT(env, arrayBufferPtr != nullptr, "getTypedArrayInfo napi_create_arraybuffer fail");
bool isArrayBuffer = false;
napi_is_arraybuffer(env, arrayBuffer, &isArrayBuffer);
NAPI_ASSERT(env, isArrayBuffer, "getTypedArrayInfo napi_is_arraybuffer fail");
napi_value result;
napi_create_typedarray(env, napi_int32_array, typedArrayLength, arrayBuffer, 0, &result);
bool isTypedArray = false;
napi_is_typedarray(env, result, &isTypedArray);
NAPI_ASSERT(env, isTypedArray, "getTypedArrayInfo napi_is_dataview fail");
napi_typedarray_type type;
size_t length = 0;
void* data = nullptr;
napi_value retArrayBuffer;
size_t byteOffset = -1;
NAPI_CALL(env, napi_get_typedarray_info(env, result, &type, &length, &data, &retArrayBuffer, &byteOffset));
NAPI_ASSERT(env, type == napi_int32_array, "napi_get_typedarray_info success 0");
NAPI_ASSERT(env, length == arrayBufferSize, "napi_get_typedarray_info success 1");
NAPI_ASSERT(env, data == arrayBufferPtr, "napi_get_dataview_info success 2");
bool retIsArrayBuffer = false;
NAPI_CALL(env, napi_is_arraybuffer(env, retArrayBuffer, &retIsArrayBuffer));
void* tmpArrayBufferPtr = nullptr;
size_t arrayBufferLength = 0;
NAPI_CALL(env, napi_get_arraybuffer_info(env, retArrayBuffer, &tmpArrayBufferPtr, &arrayBufferLength));
NAPI_ASSERT(env, byteOffset == 0, "napi_get_dataview_info success 3");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
static napi_value getDataViewInfo(napi_env env, napi_callback_info info) {
static napi_value getDataViewInfo(napi_env env, napi_callback_info info)
{
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");
NAPI_ASSERT(env, arrayBufferPtr != nullptr, "getDataViewInfo napi_create_arraybuffer fail");
bool isArrayBuffer = false;
napi_is_arraybuffer(env, arrayBuffer, &isArrayBuffer);
NAPI_ASSERT(env, isArrayBuffer, "getDataViewInfo napi_is_arraybuffer fail");
napi_value result = nullptr;
napi_create_dataview(env, arrayBufferSize, arrayBuffer, 0, &result);
bool isDataView = false;
napi_is_dataview(env, result, &isDataView);
NAPI_ASSERT(env, isDataView, "getDataViewInfo napi_is_dataview fail");
napi_value retArrayBuffer = nullptr;
void* data = nullptr;
size_t byteLength = 0;
size_t byteOffset = 0;
size_t byteOffset = -1;
napi_get_dataview_info(env, result, &byteLength, &data, &retArrayBuffer, &byteOffset);
bool retIsArrayBuffer = false;
napi_is_arraybuffer(env, arrayBuffer, &retIsArrayBuffer);
napi_is_arraybuffer(env, retArrayBuffer, &retIsArrayBuffer);
void* tmpArrayBufferPtr = nullptr;
size_t arrayBufferLength = 0;
napi_get_arraybuffer_info(env, retArrayBuffer, &tmpArrayBufferPtr, &arrayBufferLength);
NAPI_ASSERT(env, arrayBufferPtr == data, "napi_get_dataview_info success");
NAPI_ASSERT(env, arrayBufferSize == byteLength, "napi_get_dataview_info success two");
NAPI_ASSERT(env, arrayBufferLength == arrayBufferSize, "napi_get_dataview_info success 0");
NAPI_ASSERT(env, arrayBufferPtr == data, "napi_get_dataview_info success 1");
NAPI_ASSERT(env, byteOffset == 0, "napi_get_dataview_info success 2");
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) {
static napi_value getValueBool(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));
......@@ -714,7 +797,8 @@ static napi_value getValueBool(napi_env env, napi_callback_info info) {
return output;
}
static napi_value getValueDouble(napi_env env, napi_callback_info info) {
static napi_value getValueDouble(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));
......@@ -728,7 +812,8 @@ static napi_value getValueDouble(napi_env env, napi_callback_info info) {
return output;
}
static napi_value getValueExternal(napi_env env, napi_callback_info info) {
static napi_value getValueExternal(napi_env env, napi_callback_info info)
{
const char testStr[] = "test";
napi_value external = nullptr;
napi_create_external(
......@@ -738,7 +823,7 @@ static napi_value getValueExternal(napi_env env, napi_callback_info info) {
void* tempExternal = nullptr;
napi_get_value_external(env, external, &tempExternal);
NAPI_ASSERT(env, tempExternal, "napi_get_value_external true");
NAPI_ASSERT(env, tempExternal == testStr, "napi_get_value_external true");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
......@@ -746,10 +831,14 @@ static napi_value getValueExternal(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value getNull(napi_env env, napi_callback_info info) {
static napi_value getNull(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
NAPI_CALL(env, napi_get_null(env, &result));
NAPI_ASSERT(env, result != nullptr, "napi_get_null success");
napi_valuetype type;
NAPI_CALL(env, napi_typeof(env, result, &type));
NAPI_ASSERT(env, type == napi_null, "napi_get_null fail");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
......@@ -757,10 +846,14 @@ static napi_value getNull(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value getUndefined(napi_env env, napi_callback_info info) {
static napi_value getUndefined(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
NAPI_CALL(env, napi_get_undefined(env, &result));
NAPI_ASSERT(env, result != nullptr, "napi_get_undefined success");
napi_valuetype type;
NAPI_CALL(env, napi_typeof(env, result, &type));
NAPI_ASSERT(env, type == napi_undefined, "napi_get_undefined fail");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
......@@ -768,7 +861,8 @@ static napi_value getUndefined(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value coerceToBool(napi_env env, napi_callback_info info) {
static napi_value coerceToBool(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));
......@@ -779,7 +873,8 @@ static napi_value coerceToBool(napi_env env, napi_callback_info info) {
return output;
}
static napi_value coerceToNumber(napi_env env, napi_callback_info info) {
static napi_value coerceToNumber(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));
......@@ -790,7 +885,8 @@ static napi_value coerceToNumber(napi_env env, napi_callback_info info) {
return output;
}
static napi_value coerceToObject(napi_env env, napi_callback_info info) {
static napi_value coerceToObject(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));
......@@ -801,7 +897,8 @@ static napi_value coerceToObject(napi_env env, napi_callback_info info) {
return output;
}
static napi_value coerceToString(napi_env env, napi_callback_info info) {
static napi_value coerceToString(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));
......@@ -812,10 +909,12 @@ static napi_value coerceToString(napi_env env, napi_callback_info info) {
return output;
}
static napi_value instanceOf(napi_env env, napi_callback_info info) {
static napi_value instanceOf(napi_env env, napi_callback_info info)
{
napi_value customClass = nullptr;
napi_define_class(env, "TestWrapClass", NAPI_AUTO_LENGTH, [](napi_env env, napi_callback_info info) -> napi_value {
napi_define_class(env, "TestWrapClass", NAPI_AUTO_LENGTH,
[](napi_env env, napi_callback_info info) -> napi_value {
napi_value thisVar = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
return thisVar;
......@@ -838,7 +937,8 @@ static napi_value instanceOf(napi_env env, napi_callback_info info) {
return result;
}
static napi_value isArray(napi_env env, napi_callback_info info) {
static napi_value isArray(napi_env env, napi_callback_info info)
{
napi_value array = nullptr;
napi_create_array(env, &array);
NAPI_ASSERT(env, array != nullptr, "napi_get_undefined success");
......@@ -851,10 +951,11 @@ static napi_value isArray(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value isDate(napi_env env, napi_callback_info info) {
static napi_value isDate(napi_env env, napi_callback_info info)
{
napi_value date, result;
size_t argc = 1;
bool is_date;
bool is_date = false;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &date, NULL, NULL));
NAPI_CALL(env, napi_is_date(env, date, &is_date));
......@@ -863,26 +964,36 @@ static napi_value isDate(napi_env env, napi_callback_info info) {
return result;
}
static napi_value strictEquals(napi_env env, napi_callback_info info) {
static napi_value strictEquals(napi_env env, napi_callback_info info)
{
const char* testStringStr = "test";
napi_value testString = nullptr;
napi_create_string_utf8(env, testStringStr, strlen(testStringStr), &testString);
bool isStrictEquals = false;
napi_strict_equals(env, testString, testString, &isStrictEquals);
NAPI_ASSERT(env, isStrictEquals, "napi_strict_equals success");
NAPI_ASSERT(env, isStrictEquals, "napi_strict_equals success 0");
napi_value testObject = nullptr;
napi_create_object(env, &testObject);
isStrictEquals = false;
napi_strict_equals(env, testObject, testObject, &isStrictEquals);
NAPI_ASSERT(env, isStrictEquals, "napi_strict_equals success");
NAPI_ASSERT(env, isStrictEquals, "napi_strict_equals success 1");
napi_value napi_number1 = nullptr;
napi_value napi_number2 = nullptr;
napi_create_double(env, 10.1, &napi_number1);
napi_create_int32(env, 10, &napi_number2);
isStrictEquals = true;
napi_strict_equals(env, napi_number1, napi_number2, &isStrictEquals);
NAPI_ASSERT(env, !isStrictEquals, "napi_strict_equals success 2");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
static napi_value getPropertyNames(napi_env env, napi_callback_info info) {
static napi_value getPropertyNames(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
NAPI_CALL(env, napi_create_object(env, &result));
......@@ -895,10 +1006,21 @@ static napi_value getPropertyNames(napi_env env, napi_callback_info info) {
NAPI_ASSERT(env, strAttribute != nullptr, "napi_create_string_utf8 success");
NAPI_CALL(env, napi_set_named_property(env, result, "strAttribute", strAttribute));
bool hasNamedProperty = false;
NAPI_CALL(env, napi_has_named_property(env, result, "strAttribute", &hasNamedProperty));
NAPI_ASSERT(env, hasNamedProperty, "napi_has_named_property fail");
napi_value retStrAttribute = nullptr;
NAPI_CALL(env, napi_get_named_property(env, result, "strAttribute", &retStrAttribute));
NAPI_ASSERT(env, retStrAttribute != nullptr, "napi_get_named_property success");
napi_valuetype type;
NAPI_CALL(env, napi_typeof(env, retStrAttribute, &type));
NAPI_ASSERT(env, type == napi_string, "napi_get_named_property fail");
napi_value res;
napi_coerce_to_number(env, retStrAttribute, &res);
int32_t num = 0;
napi_get_value_int32(env, res, &num);
NAPI_ASSERT(env, num == 1234567, "getPropertyNames fail");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
......@@ -906,7 +1028,8 @@ static napi_value getPropertyNames(napi_env env, napi_callback_info info) {
}
static napi_value setProperty(napi_env env,
napi_callback_info info) {
napi_callback_info info)
{
napi_status status;
napi_value object, key, value;
......@@ -941,7 +1064,8 @@ static napi_value setProperty(napi_env env,
}
static napi_value getProperty(napi_env env,
napi_callback_info info) {
napi_callback_info info)
{
napi_status status;
napi_value object, key, result;
......@@ -975,7 +1099,8 @@ static napi_value getProperty(napi_env env,
return object;
}
static napi_value hasProperty(napi_env env, napi_callback_info info) {
static napi_value hasProperty(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
NAPI_CALL(env, napi_create_object(env, &result));
......@@ -1006,26 +1131,35 @@ static napi_value hasProperty(napi_env env, napi_callback_info info) {
for (uint32_t i = 0; i < arrayLength; i++) {
bool hasElement = false;
NAPI_CALL(env, napi_has_element(env, propNames, i, &hasElement));
NAPI_ASSERT(env, hasElement, "napi_has_element success");
napi_value propName = nullptr;
NAPI_CALL(env, napi_get_element(env, propNames, i, &propName));
NAPI_ASSERT(env, propName != nullptr, "napi_get_element success");
bool hasProperty = false;
napi_has_property(env, result, propName, &hasProperty);
NAPI_ASSERT(env, hasProperty, "napi_get_element success");
bool hasProp = false;
napi_has_property(env, result, propName, &hasProp);
NAPI_ASSERT(env, hasProp, "napi_get_element success");
napi_value propValue = nullptr;
napi_get_property(env, result, propName, &propValue);
NAPI_ASSERT(env, propValue != nullptr, "napi_get_property success");
}
bool deletion = false;
NAPI_CALL(env, napi_delete_element(env, propNames, 1, &deletion));
NAPI_ASSERT(env, deletion, "napi_delete_element fail");
bool hasElement = true;
NAPI_CALL(env, napi_has_element(env, propNames, 1, &hasElement));
NAPI_ASSERT(env, !hasElement, "napi_has_element fail");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
static napi_value deleteProperty(napi_env env, napi_callback_info info) {
static napi_value setAndDeleteProperty(napi_env env, napi_callback_info info)
{
size_t argc = 2;
napi_value args[2];
......@@ -1042,15 +1176,31 @@ static napi_value deleteProperty(napi_env env, napi_callback_info info) {
NAPI_ASSERT(env, valuetype1 == napi_string || valuetype1 == napi_symbol,
"Wrong type of arguments. Expects a string or symbol as second.");
const char testStr[] = "cKey";
napi_value cKey;
napi_value cValue;
NAPI_CALL(env, napi_create_string_utf8(env, testStr, strlen(testStr), &cKey));
NAPI_CALL(env, napi_create_int32(env, 3, &cValue));
NAPI_CALL(env, napi_set_property(env, args[0], cKey, cValue));
bool hasProp = false;
NAPI_CALL(env, napi_has_property(env, args[0], cKey, &hasProp));
NAPI_ASSERT(env, hasProp, "setAndDeleteProperty napi_has_property fail 1");
bool result;
napi_value ret;
NAPI_CALL(env, napi_delete_property(env, args[0], args[1], &result));
NAPI_CALL(env, napi_delete_property(env, args[0], cKey, &result));
NAPI_CALL(env, napi_get_boolean(env, result, &ret));
NAPI_CALL(env, napi_has_property(env, args[0], cKey, &hasProp));
NAPI_ASSERT(env, !hasProp, "setAndDeleteProperty napi_has_property fail 2");
return ret;
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
static napi_value hasOwnProperty(napi_env env, napi_callback_info info) {
static napi_value hasOwnProperty(napi_env env, napi_callback_info info)
{
size_t argc = 2;
napi_value args[2];
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
......@@ -1072,7 +1222,8 @@ static napi_value hasOwnProperty(napi_env env, napi_callback_info info) {
return ret;
}
static napi_value setNamedProperty(napi_env env, napi_callback_info info) {
static napi_value setNamedProperty(napi_env env, napi_callback_info info)
{
size_t argc = 3;
napi_value args[3];
char key[256] = "";
......@@ -1107,7 +1258,8 @@ static napi_value setNamedProperty(napi_env env, napi_callback_info info) {
return value_true;
}
static napi_value getNamedProperty(napi_env env, napi_callback_info info) {
static napi_value getNamedProperty(napi_env env, napi_callback_info info)
{
size_t argc = 2;
napi_value args[2];
char key[256] = "";
......@@ -1140,7 +1292,8 @@ static napi_value getNamedProperty(napi_env env, napi_callback_info info) {
return output;
}
static napi_value hasNamedProperty(napi_env env, napi_callback_info info) {
static napi_value hasNamedProperty(napi_env env, napi_callback_info info)
{
size_t argc = 2;
napi_value args[2];
char key[256] = "";
......@@ -1176,7 +1329,8 @@ static napi_value hasNamedProperty(napi_env env, napi_callback_info info) {
return ret;
}
static napi_value setElement(napi_env env, napi_callback_info info) {
static napi_value setElement(napi_env env, napi_callback_info info)
{
napi_value return_value, object;
NAPI_CALL(env, napi_create_object(env, &return_value));
......@@ -1199,7 +1353,8 @@ static napi_value setElement(napi_env env, napi_callback_info info) {
return return_value;
}
static napi_value getElement(napi_env env, napi_callback_info info) {
static napi_value getElement(napi_env env, napi_callback_info info)
{
napi_value return_value, object, prop;
NAPI_CALL(env, napi_create_object(env, &return_value));
......@@ -1222,7 +1377,8 @@ static napi_value getElement(napi_env env, napi_callback_info info) {
}
static napi_value TestBoolValuedElementApi(napi_env env,
napi_status (* api)(napi_env, napi_value, uint32_t, bool*)) {
napi_status (* api)(napi_env, napi_value, uint32_t, bool*))
{
napi_value return_value, object;
bool result;
......@@ -1245,18 +1401,21 @@ static napi_value TestBoolValuedElementApi(napi_env env,
return return_value;
}
static napi_value hasElement(napi_env env, napi_callback_info info) {
static napi_value hasElement(napi_env env, napi_callback_info info)
{
return TestBoolValuedElementApi(env, napi_has_element);
}
static napi_value deleteElement(napi_env env, napi_callback_info info) {
static napi_value deleteElement(napi_env env, napi_callback_info info)
{
return TestBoolValuedElementApi(env, napi_delete_element);
}
static napi_value defineProperties(napi_env env, napi_callback_info info) {
static napi_value defineProperties(napi_env env, napi_callback_info info)
{
napi_value object, return_value;
napi_property_descriptor desc = { "prop", NULL, defineProperties, NULL, NULL, NULL, napi_enumerable, NULL };
napi_property_descriptor desc = {"prop", NULL, defineProperties, NULL, NULL, NULL, napi_enumerable, NULL};
NAPI_CALL(env, napi_create_object(env, &object));
NAPI_CALL(env, napi_create_object(env, &return_value));
......@@ -1287,28 +1446,21 @@ static napi_value defineProperties(napi_env env, napi_callback_info info) {
return return_value;
}
static napi_value getNewTarget(napi_env env, napi_callback_info info) {
napi_value newTargetArg;
NAPI_CALL(env, napi_get_new_target(env, info, &newTargetArg));
napi_value thisArg;
NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &thisArg, NULL));
napi_value undefined;
NAPI_CALL(env, napi_get_undefined(env, &undefined));
bool result;
NAPI_CALL(env, napi_strict_equals(env, newTargetArg, thisArg, &result));
NAPI_ASSERT(env, !result, "this !== new.target");
NAPI_ASSERT(env, newTargetArg != NULL, "newTargetArg != NULL");
NAPI_CALL(env, napi_strict_equals(env, newTargetArg, undefined, &result));
NAPI_ASSERT(env, !result, "new.target !== undefined");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
static napi_value MyConstructor(napi_env env, napi_callback_info info)
{
napi_value thisVar = nullptr;
size_t argc = 0;
napi_value constructor = nullptr;
napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr);
napi_get_new_target(env, info, &constructor);
if (constructor == nullptr) {
napi_throw_error(env, nullptr, "is not new instance");
}
return thisVar;
}
static napi_value wrap(napi_env env, napi_callback_info info) {
static napi_value wrap(napi_env env, napi_callback_info info)
{
napi_value testClass = nullptr;
napi_define_class(
env, "TestClass", NAPI_AUTO_LENGTH,
......@@ -1332,7 +1484,8 @@ static napi_value wrap(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value unwrap(napi_env env, napi_callback_info info) {
static napi_value unwrap(napi_env env, napi_callback_info info)
{
napi_value testClass = nullptr;
napi_define_class(
env, "TestClass", NAPI_AUTO_LENGTH,
......@@ -1353,13 +1506,15 @@ static napi_value unwrap(napi_env env, napi_callback_info info) {
const char* tmpTestStr = nullptr;
NAPI_CALL(env, napi_unwrap(env, instanceValue, (void**)&tmpTestStr));
NAPI_ASSERT(env, tmpTestStr == testStr, "napi_unwrap fail");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
static napi_value removeWrap(napi_env env, napi_callback_info info) {
static napi_value removeWrap(napi_env env, napi_callback_info info)
{
napi_value testClass = nullptr;
napi_define_class(
env, "TestClass", NAPI_AUTO_LENGTH,
......@@ -1380,16 +1535,22 @@ static napi_value removeWrap(napi_env env, napi_callback_info info) {
const char* tmpTestStr = nullptr;
NAPI_CALL(env, napi_unwrap(env, instanceValue, (void**)&tmpTestStr));
NAPI_ASSERT(env, tmpTestStr == testStr, "napi_unwrap fail");
const char* tmpTestStr1 = nullptr;
napi_remove_wrap(env, instanceValue, (void**)&tmpTestStr1);
NAPI_ASSERT(env, tmpTestStr1 == testStr, "napi_remove_wrap fail 1");
NAPI_CALL(env, napi_unwrap(env, instanceValue, (void**)&tmpTestStr1));
NAPI_ASSERT(env, tmpTestStr1 == nullptr, "napi_remove_wrap fail");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
static napi_value getVersion(napi_env env, napi_callback_info info) {
static napi_value getVersion(napi_env env, napi_callback_info info)
{
uint32_t version;
napi_value result;
NAPI_CALL(env, napi_get_version(env, &version));
......@@ -1397,7 +1558,8 @@ static napi_value getVersion(napi_env env, napi_callback_info info) {
return result;
}
static napi_value createPromise(napi_env env, napi_callback_info info) {
static napi_value createPromise(napi_env env, napi_callback_info info)
{
napi_deferred deferred = nullptr;
napi_value promise = nullptr;
napi_create_promise(env, &deferred, &promise);
......@@ -1409,7 +1571,8 @@ static napi_value createPromise(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value resolveAndRejectDeferred(napi_env env, napi_callback_info info) {
static napi_value resolveAndRejectDeferred(napi_env env, napi_callback_info info)
{
napi_deferred deferred = nullptr;
napi_value promise = nullptr;
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
......@@ -1426,7 +1589,8 @@ static napi_value resolveAndRejectDeferred(napi_env env, napi_callback_info info
return _value;
}
static napi_value isPromise(napi_env env, napi_callback_info info) {
static napi_value isPromise(napi_env env, napi_callback_info info)
{
napi_deferred deferred = nullptr;
napi_value promise = nullptr;
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
......@@ -1440,7 +1604,8 @@ static napi_value isPromise(napi_env env, napi_callback_info info) {
return _value;
}
static napi_value runScript(napi_env env, napi_callback_info info) {
static napi_value runScript(napi_env env, napi_callback_info info)
{
napi_value script, result;
size_t argc = 1;
......@@ -1451,7 +1616,18 @@ static napi_value runScript(napi_env env, napi_callback_info info) {
return result;
}
static napi_value TestLatin1(napi_env env, napi_callback_info info) {
static napi_value getUvEventLoop(napi_env env, napi_callback_info info)
{
struct uv_loop_s* loop = nullptr;
NAPI_CALL(env, napi_get_uv_event_loop(env, &loop));
NAPI_ASSERT(env, loop != nullptr, "napi_get_uv_event_loop fail");
return nullptr;
}
static napi_value TestLatin1(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));
......@@ -1532,23 +1708,6 @@ static napi_value naiGetArrayBufferInfo(napi_env env, napi_callback_info info)
return arrayLength;
}
static napi_value napiNewInstance(napi_env env, napi_callback_info info)
{
// the value to return
napi_value global, constructor, arg, value;
napi_status status = napi_get_global(env, &global);
NAPI_ASSERT(env, status == napi_ok, "napi_get_global success");
status = napi_get_named_property(env, global, "MyObject", &constructor);
NAPI_ASSERT(env, status == napi_ok, "napi_get_named_property success");
status = napi_create_string_utf8(env, "hello", NAPI_AUTO_LENGTH, &arg);
napi_value* argv = &arg;
size_t argc = 1;
napi_status _status = napi_new_instance(env, constructor, argc, argv, &value);
NAPI_ASSERT(env, _status != napi_ok, "fail to napi_new_instance");
return value;
}
static napi_value napiDefineClass(napi_env env, napi_callback_info info)
{
napi_value testWrapClass = nullptr;
......@@ -1573,6 +1732,7 @@ static napi_value napiRunScriptPath(napi_env env, napi_callback_info info)
const char* path = "index/page";
napi_status status = napi_run_script_path(env, path, &value);
NAPI_ASSERT(env, status == napi_ok, "napi_run_script_path ok");
NAPI_ASSERT(env, value == nullptr, "napi_run_script_path fail");
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
......@@ -1635,6 +1795,110 @@ static napi_value napiCreateThreadsafeFunction(napi_env env, napi_callback_info
return _value;
}
struct AddonData {
napi_async_work asyncWork = nullptr;
napi_deferred deferred = nullptr;
napi_ref callback = nullptr;
double args = 0;
double result = 0;
};
static void AddExecuteCB(napi_env env, void *data) {
AddonData *addonData = (AddonData *)data;
addonData->result = addonData->args;
}
static void AddCallbackCompleteCB(napi_env env, napi_status status, void *data) {
AddonData *addonData = (AddonData *)data;
napi_value callback = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, addonData->callback, &callback));
napi_value result = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_create_double(env, addonData->result, &result));
napi_value callbackResult = nullptr;
int32_t ret = 0;
NAPI_CALL_RETURN_VOID(env, napi_call_function(env, nullptr, callback, 1, &result, &callbackResult));
NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, callbackResult, &ret));
NAPI_ASSERT_RETURN_VOID(env, ret == 2000, "AddCallbackCompleteCB failed");
if (addonData->callback != nullptr) {
NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, addonData->callback));
}
NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, addonData->asyncWork));
free(addonData);
}
static napi_value testAsyncWork(napi_env env, napi_callback_info info) {
size_t argc = 2;
napi_value args[2];
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
struct AddonData* addonData = (struct AddonData*)malloc(sizeof(struct AddonData));
if (addonData == nullptr) {
return nullptr;
}
NAPI_CALL(env, napi_get_value_double(env, args[0], &addonData->args));
NAPI_CALL(env, napi_create_reference(env, args[1], 1, &addonData->callback));
napi_value resourceName = nullptr;
NAPI_CALL(env, napi_create_string_utf8(env, "AsyncWorkTest", NAPI_AUTO_LENGTH, &resourceName));
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, AddExecuteCB, AddCallbackCompleteCB,
(void *)addonData, &addonData->asyncWork));
NAPI_CALL(env, napi_queue_async_work(env, addonData->asyncWork));
napi_value _value = 0;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
return _value;
}
static void AddPromiseCompleteCB(napi_env env, napi_status status, void *data) {
AddonData *addonData = (AddonData *)data;
napi_value result = nullptr;
NAPI_CALL_RETURN_VOID(env, napi_create_double(env, addonData->result, &result));
if (addonData->result > 0) {
NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, addonData->deferred, result));
} else {
NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, addonData->deferred, result));
}
if (addonData->callback != nullptr) {
NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, addonData->callback));
}
NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, addonData->asyncWork));
free(addonData);
addonData = nullptr;
}
static napi_value testPromise(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, nullptr, nullptr));
napi_value promise = nullptr;
napi_deferred deferred = nullptr;
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
struct AddonData* addonData = (struct AddonData*)malloc(sizeof(struct AddonData));
if (addonData == nullptr) {
return nullptr;
}
addonData->deferred = deferred;
NAPI_CALL(env, napi_get_value_double(env, args[0], &addonData->args));
napi_value resourceName = nullptr;
NAPI_CALL(env, napi_create_string_utf8(env, "AsyncCallback", NAPI_AUTO_LENGTH, &resourceName));
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, AddExecuteCB,
AddPromiseCompleteCB, (void *)addonData, &addonData->asyncWork));
napi_queue_async_work(env, addonData->asyncWork);
return promise;
}
static napi_value napiCancelAsyncWork(napi_env env, napi_callback_info info)
{
napi_async_work work = nullptr;
......@@ -1646,7 +1910,7 @@ static napi_value napiCancelAsyncWork(napi_env env, napi_callback_info info)
napi_delete_async_work(env, workData);
}, work, &work);
napi_queue_async_work(env, work);
napi_cancel_async_work(env, work);
NAPI_CALL(env, napi_cancel_async_work(env, work));
napi_value value;
NAPI_CALL(env, napi_create_int32(env, 0, &value));
......@@ -1656,19 +1920,21 @@ static napi_value napiCancelAsyncWork(napi_env env, napi_callback_info info)
static napi_value SayHello(napi_env env, napi_callback_info info)
{
printf("Hello\n");
return NULL;
napi_value ret;
NAPI_CALL(env, napi_create_int32(env, TAG_NUMBER, &ret));
return ret;
}
static napi_value napiCreateFunction(napi_env env, napi_callback_info info)
{
napi_value funcValue = nullptr;
napi_status status = napi_create_function(env, NULL, 0, SayHello, NULL, &funcValue);
NAPI_ASSERT(env, status != napi_ok, "napi_create_function fail");
napi_status status = napi_create_function(env, "func", NAPI_AUTO_LENGTH, SayHello, NULL, &funcValue);
NAPI_ASSERT(env, funcValue != nullptr, "napi_create_function fail");
NAPI_ASSERT(env, status == napi_ok, "napi_create_function fail");
napi_value value;
NAPI_CALL(env, napi_create_int32(env, 1, &value));
return value;
return funcValue;
}
static napi_value napiRefthreadSafeFunction(napi_env env, napi_callback_info info)
......@@ -1718,6 +1984,7 @@ static napi_value napiCreateBigintUint64(napi_env env, napi_callback_info info)
uint64_t resultValue = 0;
bool flag = false;
napi_get_value_bigint_uint64(env, result, &resultValue, &flag);
NAPI_ASSERT(env, resultValue == testValue, "napi_get_value_bigint_int64 failed");
napi_value value;
NAPI_CALL(env, napi_create_int32(env, flag, &value));
......@@ -1732,6 +1999,7 @@ static napi_value napiCreateBigintInt64(napi_env env, napi_callback_info info)
int64_t resultValue = 0;
bool flag = false;
napi_get_value_bigint_int64(env, result, &resultValue, &flag);
NAPI_ASSERT(env, resultValue == testValue, "napi_get_value_bigint_int64 failed");
napi_value value;
NAPI_CALL(env, napi_create_int32(env, flag, &value));
......@@ -1742,15 +2010,22 @@ static napi_value napiCreateBigintWords(napi_env env, napi_callback_info info)
{
int signBit = 0;
size_t wordCount = 4;
uint64_t words[] = { 0xFFFFFFFFFFFFFFFF, 34ULL, 56ULL, 0xFFFFFFFFFFFFFFFF };
uint64_t wordsOut[] = { 0ULL, 0ULL, 0ULL, 0ULL };
uint64_t words[] = {0ULL, 34ULL, 56ULL, 2ULL};
uint64_t wordsOut[] = {0ULL, 0ULL, 0ULL, 0ULL};
napi_value result = nullptr;
NAPI_CALL(env, napi_create_bigint_words(env, signBit, wordCount, words, &result));
NAPI_CALL(env, napi_get_value_bigint_words(env, result, &signBit, &wordCount, wordsOut));
bool testResult = false;
const int wCount = 2;
if (signBit == 0 && wordCount == wCount && words[0] == wordsOut[0] && words[1] == wordsOut[1]) {
testResult = true;
int retSignBit = -1;
size_t retWordCount = 4;
NAPI_CALL(env, napi_get_value_bigint_words(env, result, &retSignBit, &retWordCount, wordsOut));
bool testResult = true;
if (retSignBit != signBit || retWordCount != wordCount) {
testResult = false;
}
for (size_t i = 0; i < wordCount; i++) {
if (wordsOut[i] != words[i]) {
testResult = false;
break;
}
}
napi_value value;
NAPI_CALL(env, napi_create_int32(env, testResult, &value));
......@@ -1758,17 +2033,75 @@ static napi_value napiCreateBigintWords(napi_env env, napi_callback_info info)
return value;
}
static napi_value napiFatalerror(napi_env env, napi_callback_info info)
static napi_value callFunction(napi_env env, napi_callback_info info)
{
void *data = nullptr;
napi_threadsafe_function tsfun = static_cast<napi_threadsafe_function>(data);
if (napi_release_threadsafe_function(tsfun, napi_tsfn_release) == napi_ok) {
napi_fatal_error("ReleaseThreadsafeFunction", NAPI_AUTO_LENGTH,
"napi_release_threadsafe_function failed", NAPI_AUTO_LENGTH);
}
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 0, &_value));
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_function,
"Wrong type of argment. Expects a string.");
napi_value ret;
NAPI_CALL(env, napi_call_function(env, nullptr, args[0], 0, nullptr, &ret));
return ret;
}
static napi_value getGlobal(napi_env env, napi_callback_info info)
{
napi_value result = nullptr;
NAPI_CALL(env, napi_get_global(env, &result));
NAPI_ASSERT(env, result != nullptr, "napi_get_global failed");
return nullptr;
}
napi_threadsafe_function tsfn;
napi_ref functionRef;
static void CallJs(napi_env env, napi_value js_cb, void *context, void *data) {
napi_value undefined;
NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined));
napi_value cb;
NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, functionRef, &cb));
napi_value ret;
int32_t num = 0;
NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, cb, 0, nullptr, &ret));
NAPI_CALL_RETURN_VOID(env, napi_get_value_int32(env, ret, &num));
NAPI_ASSERT_RETURN_VOID(env, num == TAG_NUMBER, "CallJs fail");
}
static napi_value ThreadSafeTest(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value js_cb, work_name;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &js_cb, NULL, NULL));
napi_create_reference(env, js_cb, 1, &functionRef);
NAPI_CALL(env, napi_create_string_utf8(env, "work_name", NAPI_AUTO_LENGTH, &work_name));
napi_valuetype valueType = napi_undefined;
NAPI_CALL(env, napi_typeof(env, js_cb, &valueType));
NAPI_ASSERT(env, valueType == napi_function, "valueType expect equal to napi_function");
const char context[] = "context";
NAPI_CALL(env, napi_create_threadsafe_function(
env, js_cb, NULL, work_name, 0, 1, NULL, NULL, (void*)context, CallJs, &tsfn));
void* retContext = nullptr;
NAPI_CALL(env, napi_get_threadsafe_function_context(tsfn, &retContext));
NAPI_ASSERT(env, retContext == context, "napi_get_threadsafe_function_context failed");
napi_acquire_threadsafe_function(tsfn);
napi_call_threadsafe_function(tsfn, NULL, napi_tsfn_blocking);
NAPI_CALL(env, napi_ref_threadsafe_function(env, tsfn));
NAPI_CALL(env, napi_unref_threadsafe_function(env, tsfn));
NAPI_CALL(env, napi_release_threadsafe_function(tsfn, napi_tsfn_release));
napi_value _value;
NAPI_CALL(env, napi_create_int32(env, 1, &_value));
return _value;
}
......@@ -1776,7 +2109,8 @@ EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor properties[] = { DECLARE_NAPI_FUNCTION("getLastErrorInfo", getLastErrorInfo),
napi_property_descriptor properties[] = {
DECLARE_NAPI_FUNCTION("getLastErrorInfo", getLastErrorInfo),
DECLARE_NAPI_FUNCTION("cleanUpErrorInfo", cleanUpErrorInfo),
DECLARE_NAPI_FUNCTION("throwExistingError", throwExistingError),
DECLARE_NAPI_FUNCTION("throwError", throwError),
......@@ -1791,10 +2125,8 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("openAndCloseHandleScope", openAndCloseHandleScope),
DECLARE_NAPI_FUNCTION("openAndCloseEscapableHandleScope", openAndCloseEscapableHandleScope),
DECLARE_NAPI_FUNCTION("createReference", createReference),
DECLARE_NAPI_FUNCTION("deleteReference", deleteReference),
DECLARE_NAPI_FUNCTION("referenceRef", referenceRef),
DECLARE_NAPI_FUNCTION("referenceUnref", referenceUnref),
DECLARE_NAPI_FUNCTION("getReferenceValue", getReferenceValue),
DECLARE_NAPI_FUNCTION("getAndDeleteReference", getAndDeleteReference),
DECLARE_NAPI_FUNCTION("referenceRefAndUnref", referenceRefAndUnref),
DECLARE_NAPI_FUNCTION("createArrayAndGetLength", createArrayAndGetLength),
DECLARE_NAPI_FUNCTION("getArrayWithLength", getArrayWithLength),
DECLARE_NAPI_FUNCTION("createExternal", createExternal),
......@@ -1810,6 +2142,8 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("createAndGetStringLatin1", createAndGetStringLatin1),
DECLARE_NAPI_FUNCTION("createAndGetStringUtf8", createAndGetStringUtf8),
DECLARE_NAPI_FUNCTION("getPrototype", getPrototype),
DECLARE_NAPI_FUNCTION("getPrototype2", getPrototype2),
DECLARE_NAPI_FUNCTION("getTypedArrayInfo", getTypedArrayInfo),
DECLARE_NAPI_FUNCTION("getDataViewInfo", getDataViewInfo),
DECLARE_NAPI_FUNCTION("getValueBool", getValueBool),
DECLARE_NAPI_FUNCTION("getValueDouble", getValueDouble),
......@@ -1828,7 +2162,7 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("setProperty", setProperty),
DECLARE_NAPI_FUNCTION("getProperty", getProperty),
DECLARE_NAPI_FUNCTION("hasProperty", hasProperty),
DECLARE_NAPI_FUNCTION("deleteProperty", deleteProperty),
DECLARE_NAPI_FUNCTION("setAndDeleteProperty", setAndDeleteProperty),
DECLARE_NAPI_FUNCTION("hasOwnProperty", hasOwnProperty),
DECLARE_NAPI_FUNCTION("setNamedProperty", setNamedProperty),
DECLARE_NAPI_FUNCTION("getNamedProperty", getNamedProperty),
......@@ -1838,7 +2172,6 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("hasElement", hasElement),
DECLARE_NAPI_FUNCTION("deleteElement", deleteElement),
DECLARE_NAPI_FUNCTION("defineProperties", defineProperties),
DECLARE_NAPI_FUNCTION("getNewTarget", getNewTarget),
DECLARE_NAPI_FUNCTION("wrap", wrap),
DECLARE_NAPI_FUNCTION("unwrap", unwrap),
DECLARE_NAPI_FUNCTION("removeWrap", removeWrap),
......@@ -1848,9 +2181,9 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("isPromise", isPromise),
DECLARE_NAPI_FUNCTION("TestLatin1", TestLatin1),
DECLARE_NAPI_FUNCTION("runScript", runScript),
DECLARE_NAPI_FUNCTION("getUvEventLoop", getUvEventLoop),
DECLARE_NAPI_FUNCTION("napCreateArrayBuffer", napCreateArrayBuffer),
DECLARE_NAPI_FUNCTION("naiGetArrayBufferInfo", naiGetArrayBufferInfo),
DECLARE_NAPI_FUNCTION("napiNewInstance", napiNewInstance),
DECLARE_NAPI_FUNCTION("napiDefineClass", napiDefineClass),
DECLARE_NAPI_FUNCTION("napiRunScriptPath", napiRunScriptPath),
DECLARE_NAPI_FUNCTION("napiGetNodeVersion", napiGetNodeVersion),
......@@ -1863,27 +2196,38 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("napiCreateBigintWords", napiCreateBigintWords),
DECLARE_NAPI_FUNCTION("napiGetCbInfo", napiGetCbInfo),
{ "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 },
{ "napiCreateFunction", nullptr, napiCreateFunction, nullptr, nullptr, nullptr, napi_default, nullptr },
DECLARE_NAPI_FUNCTION("napiFatalerror", napiFatalerror), };
DECLARE_NAPI_FUNCTION("getGlobal", getGlobal),
DECLARE_NAPI_FUNCTION("callFunction", callFunction),
DECLARE_NAPI_FUNCTION("ThreadSafeTest", ThreadSafeTest),
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties));
napi_property_descriptor descClass[] = {
DECLARE_NAPI_FUNCTION("sayHello", SayHello),
};
napi_value myClass;
napi_define_class(env, "myClass", NAPI_AUTO_LENGTH, MyConstructor, nullptr,
sizeof(descClass) / sizeof(descClass[0]), descClass, &myClass);
napi_set_named_property(env, exports, "myClass", myClass);
return exports;
}
EXTERN_C_END
static napi_module
demoModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = Init,
.nm_modname = "napitest",
.nm_priv = ((void *)0),
.reserved = {
0 },
static napi_module demoModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = Init,
.nm_modname = "napitest",
.nm_priv = ((void *)0),
.reserved = {0},
};
extern "C" __attribute__((constructor)) void RegisterModule(void)
{
napi_module_register(& demoModule);
napi_module_register(&demoModule);
}
......@@ -22,7 +22,8 @@ export default function nativeApiStringJsunit() {
describe('napiStringTest', function () {
const empty = 'hh';
var value;
let value;
let obj;
async function sleep(time) {
return new Promise((resolve, reject) => {
......@@ -43,7 +44,7 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0100
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0001
* @tc.name napiStringTest001
* @tc.desc aceNapiEtsTest
*/
......@@ -56,66 +57,53 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0200
* @tc.name napCreateArrayBuffer
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0002
* @tc.name napCreateArrayBuffer002
* @tc.desc aceNapiEtsTest
*/
it('napCreateArrayBuffer002', 0, async function (done) {
it('napiCreateArrayBuffer002', 0, async function (done) {
console.info('napiCreateArrayBuffer002 START');
value = napitest.napCreateArrayBuffer();
console.info('apiCreateArrayBuffer testString result is: ' + JSON.stringify(value));
console.info('napiCreateArrayBuffer testString result is: ' + JSON.stringify(value));
expect(value instanceof ArrayBuffer).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0300
* @tc.name naiGetArrayBufferInfo
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0003
* @tc.name naiGetArrayBufferInfo003
* @tc.desc aceNapiEtsTest
*/
it('naiGetArrayBufferInfo003', 0, async function (done) {
console.info('naiGetArrayBufferInfo003 START');
it('napiGetArrayBufferInfo003', 0, async function (done) {
console.info('napiGetArrayBufferInfo003 START');
value = napitest.naiGetArrayBufferInfo();
console.info('naiGetArrayBufferInfo testString result is: ' + JSON.stringify(value));
console.info('napiGetArrayBufferInfo testString result is: ' + JSON.stringify(value));
expect(value).assertEqual(1024);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0400
* @tc.name napiCreateFunction
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0004
* @tc.name napiCreateFunction004
* @tc.desc aceNapiEtsTest
*/
it('napiCreateFunction004', 0, async function (done) {
console.info('napiCreateFunction004 START');
value = napitest.napiCreateFunction();
let func = napitest.napiCreateFunction();
value = func();
console.info('napiCreateFunction testString result is: ' + JSON.stringify(value));
expect(value).assertEqual(1);
expect(value).assertEqual(666);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0500
* @tc.name napiNewInstance
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0005
* @tc.name napiDefineClass005
* @tc.desc aceNapiEtsTest
*/
it('napiNewInstance005', 0, async function (done) {
console.info(' napiNewInstance005 START');
value = napitest.napiNewInstance('hello');
console.info('napiNewInstance testString result is: ' + JSON.stringify(value));
expect(value == undefined).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0600
* @tc.name napiDefineClass
* @tc.desc aceNapiEtsTest
*/
it('napiDefineClass006', 0, async function (done) {
console.info('napiDefineClass006 START');
it('napiDefineClass005', 0, async function (done) {
console.info('napiDefineClass005 START');
value = napitest.napiDefineClass();
console.info('napiDefineClass testString result is: ' + JSON.stringify(value));
expect(value).assertEqual(0)
......@@ -123,12 +111,12 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0700
* @tc.name napiCancelAsyncWork
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0006
* @tc.name napiCancelAsyncWork006
* @tc.desc aceNapiEtsTest
*/
it('napiCancelAsyncWork007', 0, async function (done) {
console.info('napiCancelAsyncWork007 START');
it('napiCancelAsyncWork006', 0, async function (done) {
console.info('napiCancelAsyncWork006 START');
value = napitest.napiCancelAsyncWork();
console.info('napiCancelAsyncWork testString result is: ' + JSON.stringify(value));
expect(value).assertEqual(0)
......@@ -136,11 +124,11 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0900
* @tc.name napiRunScriptPath
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0007
* @tc.name napiRunScriptPath007
* @tc.desc aceNapiEtsTest
*/
it('napiRunScriptPath009', 0, async function (done) {
it('napiRunScriptPath007', 0, async function (done) {
console.info('napiRunScriptPath START');
value = napitest.napiRunScriptPath();
console.info('napiRunScriptPath testString result is: ' + JSON.stringify(value));
......@@ -149,11 +137,11 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0100
* @tc.name napiCallThreadsafeFunction
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0008
* @tc.name napiCallThreadsafeFunction008
* @tc.desc aceNapiEtsTest
*/
it('napiCallThreadsafeFunction010', 0, async function (done) {
it('napiCallThreadsafeFunction008', 0, async function (done) {
console.info('napiCallThreadsafeFunction START');
value = napitest.napiCallThreadsafeFunction();
console.info('napiCallThreadsafeFunction testString result is: ' + JSON.stringify(value));
......@@ -162,11 +150,11 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0011
* @tc.name napiCreateThreadsafeFunction
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0009
* @tc.name napiCreateThreadsafeFunction009
* @tc.desc aceNapiEtsTest
*/
it('napiCreateThreadsafeFunction011', 0, async function (done) {
it('napiCreateThreadsafeFunction009', 0, async function (done) {
console.info('napiCreateThreadsafeFunction START');
value = napitest.napiCreateThreadsafeFunction();
console.info('napiCreateThreadsafeFunction testString result is: ' + JSON.stringify(value));
......@@ -175,11 +163,11 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0012
* @tc.name napiRefthreadSafeFunction
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0010
* @tc.name napiRefthreadSafeFunction010
* @tc.desc aceNapiEtsTest
*/
it('napiRefthreadSafeFunction012', 0, async function (done) {
it('napiRefthreadSafeFunction010', 0, async function (done) {
console.info('napiRefthreadSafeFunction START');
value = napitest.napiRefthreadSafeFunction();
console.info('napiRefthreadSafeFunction testString result is: ' + JSON.stringify(value));
......@@ -188,11 +176,11 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0013
* @tc.name napiCreateDate
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0011
* @tc.name napiCreateDate011
* @tc.desc aceNapiEtsTest
*/
it('napiCreateDate013', 0, async function (done) {
it('napiCreateDate011', 0, async function (done) {
console.info('napiCreateDate START');
value = napitest.napiCreateDate();
console.info('napiCreateDate testString result is: ' + JSON.stringify(value));
......@@ -201,11 +189,11 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0014
* @tc.name napiCreateBigintUint64
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0012
* @tc.name napiCreateBigintUint64012
* @tc.desc aceNapiEtsTest
*/
it('napiCreateBigintUint64014', 0, async function (done) {
it('napiCreateBigintUint64012', 0, async function (done) {
console.info('napiCreateBigintUint64 START');
value = napitest.napiCreateBigintUint64();
console.info('napiCreateBigintUint64 testString result is: ' + JSON.stringify(value));
......@@ -214,11 +202,11 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0015
* @tc.name napiCreateBigintInt64
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0013
* @tc.name napiCreateBigintInt64013
* @tc.desc aceNapiEtsTest
*/
it('napiCreateBigintInt64015', 0, async function (done) {
it('napiCreateBigintInt64013', 0, async function (done) {
console.info('napiCreateBigintInt64 START');
value = napitest.napiCreateBigintInt64();
console.info('napiCreateBigintInt64 testString result is: ' + JSON.stringify(value));
......@@ -227,793 +215,637 @@ export default function nativeApiStringJsunit() {
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0016
* @tc.name napiCreateBigintWords
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0014
* @tc.name napiCreateBigintWords014
* @tc.desc aceNapiEtsTest
*/
it('napiCreateBigintWords016', 0, async function (done) {
it('napiCreateBigintWords014', 0, async function (done) {
console.info('napiCreateBigintWords START');
value = napitest.napiCreateBigintWords();
console.info('napiCreateBigintWords testString result is: ' + JSON.stringify(value));
expect(value).assertEqual(0)
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0017
* @tc.name napiFatalerror
* @tc.desc aceNapiEtsTest
*/
it('napiFatalerror017', 0, async function (done) {
console.info('napiFatalerror START');
value = napitest.napiFatalerror();
console.info('napiFatalerror testString result is: ' + JSON.stringify(value));
expect(value).assertEqual(0)
expect(value).assertEqual(1)
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0018
* @tc.name napiGetCbInfo
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0015
* @tc.name napiGetCbInfo015
* @tc.desc aceNapiEtsTest
*/
it('napiGetCbInfo018', 0, async function (done) {
console.info('napiGetCbInfo018 START');
it('napiGetCbInfo015', 0, async function (done) {
console.info('napiGetCbInfo015 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 == 0).assertTrue();
console.info('napiGetCbInfo015 testString result is: ' + JSON.stringify(value));
expect(value == 12.06).assertTrue
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0280
* @tc.name aceNapiTest019
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0016
* @tc.name aceNapiTest016
* @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) );
it('aceNapiTest016', 0, async function (done) {
console.info('aceNapiTest016 START');
value = napitest.referenceRefAndUnref();
console.info('aceNapiTest016 testString result is: ' + value + "---" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0370
* @tc.name napicreateSymbol028
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0017
* @tc.name napicreateSymbol017
* @tc.desc aceNapiEtsTest
*/
it('napicreateSymbol028', 0, async function (done) {
console.info('napicreateSymbol028 START');
it('napicreateSymbol017', 0, async function (done) {
console.info('napicreateSymbol017 START');
let value = napitest.createSymbol('symbol');
console.info('napicreateSymbol028 testString result is: ' + value + "--" + JSON.stringify(value));
console.info('napicreateSymbol017 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0420
* @tc.name napicreateAndGetInt033
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0018
* @tc.name napicreateAndGetInt018
* @tc.desc aceNapiEtsTest
*/
it('napicreateAndGetInt033', 0, async function (done) {
console.info('aceNapiTest033 START');
it('napicreateAndGetInt018', 0, async function (done) {
console.info('napicreateAndGetInt018 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();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0120
* @tc.name aceNapiTest003
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest003', 0, async function (done) {
console.info('aceNapiTest003 START');
let value = napitest.getLastErrorInfo();
console.info('aceNapiTest003 testString result is: ' + value + "--" + JSON.stringify(value));
console.info('napicreateAndGetInt018 testString result is: '+ value + "---" + JSON.stringify(value));
expect(value).assertEqual(6);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0130
* @tc.name aceNapiTest004
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest004', 0, async function (done) {
console.info('aceNapiTest004 START');
let value = napitest.cleanUpErrorInfo();
console.info('aceNapiTest004 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0140
* @tc.name aceNapiTest005
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest005', 0, async function (done) {
console.info('aceNapiTest005 START');
try {
let value = napitest.throwExistingError();
console.info('aceNapiTest005 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
} catch (err) {
console.info('aceNapiTest005 testString result is err: ' + err + "--" + JSON.stringify(err));
let er = JSON.stringify(err)
expect(er).assertEqual('{"code":"600"}');
done();
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0150
* @tc.name aceNapiTest006
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest006', 0, async function (done) {
console.info('aceNapiTest006 START');
try {
let value = napitest.throwError();
console.info('aceNapiTest006 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
} catch (err) {
console.info('aceNapiTest006 testString result is err: ' + err + "--" + JSON.stringify(err));
let er = JSON.stringify(err)
expect(er).assertEqual('{"code":"500"}');
done();
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0160
* @tc.name aceNapiTest007
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest007', 0, async function (done) {
console.info('aceNapiTest007 START');
try {
let value = napitest.throwTypeError();
console.info('aceNapiTest007 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
} catch (err) {
console.info('aceNapiTest007 testString result is err: ' + err + "--" + JSON.stringify(err));
expect(err instanceof TypeError).assertTrue();
done();
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0170
* @tc.name aceNapiTest008
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest008', 0, async function (done) {
console.info('aceNapiTest008 START');
try {
let value = napitest.throwRangeError();
console.info('aceNapiTest008 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
} catch (err) {
console.info('aceNapiTest008 testString result is err: ' + err + "--" + JSON.stringify(err));
expect(err instanceof RangeError).assertTrue();
done();
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0180
* @tc.name aceNapiTest009
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest009', 0, async function (done) {
console.info('aceNapiTest009 START');
let value = napitest.isError(false);
console.info('aceNapiTest009 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertFalse();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0190
* @tc.name aceNapiTest010
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest010', 0, async function (done) {
console.info('aceNapiTest010 START');
let value = napitest.createError();
console.info('aceNapiTest010 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0200
* @tc.name aceNapiTest011
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest011', 0, async function (done) {
console.info('aceNapiTest011 START');
let value = napitest.createTypeError();
console.info('aceNapiTest011 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0210
* @tc.name aceNapiTest012
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest012', 0, async function (done) {
console.info('aceNapiTest012 START');
let value = napitest.createRangeError();
console.info('aceNapiTest012 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0230
* @tc.name aceNapiTest014
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest014', 0, async function (done) {
console.info('aceNapiTest014 START');
let value = napitest.isExceptionPending();
console.info('aceNapiTest014 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0240
* @tc.name aceNapiTest015
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest015', 0, async function (done) {
console.info('aceNapiTest015 START');
let value = napitest.openAndCloseHandleScope();
console.info('aceNapiTest015 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value == undefined).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0260
* @tc.name aceNapiTest017
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0019
* @tc.name aceNapiTest019
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest017', 0, async function (done) {
console.info('aceNapiTest017 START');
let value = napitest.createReference();
console.info('aceNapiTest017 testString result is: ' + value + "--" + JSON.stringify(value));
it('aceNapiTest019', 0, async function (done) {
console.info('aceNapiTest019 START');
value = napitest.getTypedArrayInfo();
console.info('aceNapiTest019 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0290
* @tc.name aceNapiTest020
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0020
* @tc.name napigetDataView020
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest020', 0, async function (done) {
console.info('aceNapiTest020 START');
let value = napitest.referenceUnref();
console.info('aceNapiTest020 testString result is: ' + value + "--" + JSON.stringify(value));
it('napigetDataView020', 0, async function (done) {
console.info('napigetDataView020 START');
var buffer = new ArrayBuffer(2);
let dView = new DataView(buffer).setInt16(0, 256, true);
let value = napitest.getDataViewInfo(dView);
console.info('napigetDataView020 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0300
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0021
* @tc.name aceNapiTest021
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest021', 0, async function (done) {
console.info('aceNapiTest021 START');
let value = napitest.getReferenceValue();
let value = napitest.openAndCloseHandleScope();
console.info('aceNapiTest021 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value == undefined).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0310
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0022
* @tc.name aceNapiTest022
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest022', 0, async function (done) {
console.info('aceNapiTest022 START');
var array = [1,2];
let value = napitest.createArrayAndGetLength(array);
value = napitest.openAndCloseEscapableHandleScope();
console.info('aceNapiTest022 testString result is: ' + value + "--" + JSON.stringify(value));
let obj = JSON.stringify(value);
expect(obj).assertEqual('[1,2]');
expect(value instanceof Object).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0320
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0023
* @tc.name aceNapiTest023
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest023', 0, async function (done) {
console.info('aceNapiTest023 START');
let value = napitest.getArrayWithLength([1,2]);
let value = napitest.createReference();
console.info('aceNapiTest023 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0024
* @tc.name aceNapiTest024
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest024', 0, async function (done) {
console.info('aceNapiTest024 START');
var array = [1,2];
let value = napitest.createArrayAndGetLength(array);
console.info('aceNapiTest024 testString result is: ' + value + "--" + JSON.stringify(value));
let obj = JSON.stringify(value);
expect(obj).assertEqual('[1,2]');
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0340
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0025
* @tc.name aceNapiTest025
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest025', 0, async function (done) {
console.info('aceNapiTest025 START');
let value = napitest.createExternal();
let value = napitest.getArrayWithLength([1,2]);
console.info('aceNapiTest025 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
obj = JSON.stringify(value);
expect(obj).assertEqual('[0,1,2,3]');
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0350
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0026
* @tc.name aceNapiTest026
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest026', 0, async function (done) {
console.info('aceNapiTest026 START');
let value = napitest.createExternalArraybuffer();
let value = napitest.createExternal();
console.info('aceNapiTest026 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0360
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0027
* @tc.name aceNapiTest027
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest027', 0, async function (done) {
console.info('aceNapiTest027 START');
let value = napitest.createObject();
let value = napitest.createExternalArraybuffer();
console.info('aceNapiTest027 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value instanceof ArrayBuffer).assertTrue();
let view = new Int32Array(value);
expect(view[0]).assertEqual(666);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0370
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0028
* @tc.name aceNapiTest028
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest028', 0, async function (done) {
console.info('aceNapiTest028 START');
let value = napitest.createSymbol("teststr");
value = napitest.createObject();
console.info('aceNapiTest028 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value instanceof Object).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0380
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0029
* @tc.name aceNapiTest029
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest029', 0, async function (done) {
console.info('aceNapiTest029 START');
let value = napitest.createTypeArray();
let value = napitest.createSymbol("teststr");
console.info('aceNapiTest029 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0390
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0030
* @tc.name aceNapiTest030
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest030', 0, async function (done) {
console.info('aceNapiTest030 START');
let value = napitest.createDataView();
let value = napitest.createTypeArray();
console.info('aceNapiTest030 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value instanceof Int32Array).assertTrue();
expect(value.length).assertEqual(4);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0400
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0031
* @tc.name aceNapiTest031
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest031', 0, async function (done) {
console.info('aceNapiTest031 START');
let value = napitest.createAndGetInt32(32);
let value = napitest.createDataView();
console.info('aceNapiTest031 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(32);
expect(value instanceof DataView).assertTrue();
value.setInt16(1, 42);
expect(value.getInt16(1)).assertEqual(42);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0410
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0032
* @tc.name aceNapiTest032
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest032', 0, async function (done) {
console.info('aceNapiTest032 START');
let value = napitest.createAndGetUInt32(12);
let value = napitest.createAndGetInt32(32);
console.info('aceNapiTest032 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(12);
expect(value).assertEqual(32);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0420
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0033
* @tc.name aceNapiTest033
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest033', 0, async function (done) {
console.info('aceNapiTest033 START');
let value = napitest.createAndGetInt64(23);
let value = napitest.createAndGetUInt32(12);
console.info('aceNapiTest033 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(23);
expect(value).assertEqual(12);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0430
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0034
* @tc.name aceNapiTest034
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest034', 0, async function (done) {
console.info('aceNapiTest034 START');
let value = napitest.createDouble(24.67);
let value = napitest.createAndGetInt64(23);
console.info('aceNapiTest034 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(24.67);
expect(value).assertEqual(23);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0440
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0035
* @tc.name aceNapiTest035
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest035', 0, async function (done) {
console.info('aceNapiTest035 START');
let value = napitest.createAndGetStringLatin1("tst");
let value = napitest.createDouble(24.67);
console.info('aceNapiTest035 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual("tst");
expect(value).assertEqual(24.67);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0450
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0036
* @tc.name aceNapiTest036
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest036', 0, async function (done) {
console.info('aceNapiTest036 START');
let value = napitest.createAndGetStringUtf8('he');
let value = napitest.createAndGetStringLatin1("tst");
console.info('aceNapiTest036 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual('he');
expect(value).assertEqual("tst");
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0460
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0037
* @tc.name aceNapiTest037
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest037', 0, async function (done) {
console.info('aceNapiTest037 START');
let value = napitest.getPrototype();
let value = napitest.createAndGetStringUtf8('he');
console.info('aceNapiTest037 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value).assertEqual('he');
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0490
* @tc.name aceNapiTest040
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0038
* @tc.name aceNapiTest038
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest040', 0, async function (done) {
console.info('aceNapiTest040 START');
let value = napitest.getValueBool(false);
console.info('aceNapiTest040 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertFalse();
it('aceNapiTest038', 0, async function (done) {
console.info('aceNapiTest038 START');
value = napitest.getPrototype();
console.info('aceNapiTest038 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value instanceof Object).assertTrue();
function testFunc() {
this.a = 0
}
value = napitest.getPrototype2(testFunc);
console.info('aceNapiTest038 testString result is: ' + value + "--" + JSON.stringify(value));
console.info('aceNapiTest038 testString Object.getPrototypeOf(testObj) is: ' + Object.getPrototypeOf(testFunc) + "--" + JSON.stringify(Object.getPrototypeOf(testFunc)));
expect(value === Object.getPrototypeOf(testFunc)).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0500
* @tc.name aceNapiTest041
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0039
* @tc.name aceNapiTest039
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest041', 0, async function (done) {
console.info('aceNapiTest041 START');
let value = napitest.getValueDouble(25.0);
console.info('aceNapiTest041 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(25);
it('aceNapiTest039', 0, async function (done) {
console.info('aceNapiTest039 START');
let value = napitest.getValueBool(false);
console.info('aceNapiTest039 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertFalse();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0510
* @tc.name aceNapiTest042
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0040
* @tc.name aceNapiTest040
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest040', 0, async function (done) {
console.info('aceNapiTest040 START');
value = napitest.getValueDouble(24.5);
console.info('aceNapiTest040 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value === 24.5).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0041
* @tc.name aceNapiTest041
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest041', 0, async function (done) {
console.info('aceNapiTest041 START');
let value = napitest.getValueExternal();
console.info('aceNapiTest041 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0042
* @tc.name aceNapiTest042
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest042', 0, async function (done) {
console.info('aceNapiTest042 START');
let value = napitest.getValueExternal();
let value = napitest.getNull();
console.info('aceNapiTest042 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0520
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0043
* @tc.name aceNapiTest043
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest043', 0, async function (done) {
console.info('aceNapiTest043 START');
let value = napitest.getNull();
let value = napitest.getUndefined();
console.info('aceNapiTest043 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0530
* @tc.number SUB_ACE_BASIC_ETS_NAPI_00044
* @tc.name aceNapiTest044
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest044', 0, async function (done) {
console.info('aceNapiTest044 START');
let value = napitest.getUndefined();
value = napitest.coerceToBool(0);
console.info('aceNapiTest044 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value).assertFalse();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0540
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0045
* @tc.name aceNapiTest045
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest045', 0, async function (done) {
console.info('aceNapiTest045 START');
let value = napitest.coerceToBool(false);
value = napitest.coerceToNumber('12');
console.info('aceNapiTest045 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertFalse();
expect(value).assertEqual(12);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0550
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0046
* @tc.name aceNapiTest046
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest046', 0, async function (done) {
console.info('aceNapiTest046 START');
let value = napitest.coerceToNumber(12);
let value = napitest.coerceToObject([2,3]);
console.info('aceNapiTest046 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(12);
let obj = JSON.stringify(value);
expect(obj).assertEqual('[2,3]');
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0560
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0047
* @tc.name aceNapiTest047
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest047', 0, async function (done) {
console.info('aceNapiTest047 START');
let value = napitest.coerceToObject([2,3]);
value = napitest.coerceToString(123);
console.info('aceNapiTest047 testString result is: ' + value + "--" + JSON.stringify(value));
let obj = JSON.stringify(value);
expect(obj).assertEqual('[2,3]');
expect(value).assertEqual('123');
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0570
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0048
* @tc.name aceNapiTest048
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest048', 0, async function (done) {
console.info('aceNapiTest048 START');
let value = napitest.coerceToString("he");
let value = napitest.instanceOf();
console.info('aceNapiTest048 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual('he');
expect(value).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0580
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0049
* @tc.name aceNapiTest049
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest049', 0, async function (done) {
console.info('aceNapiTest049 START');
let value = napitest.instanceOf();
let value = napitest.isArray();
console.info('aceNapiTest049 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertTrue();
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0590
/* @tc.number SUB_ACE_BASIC_ETS_NAPI_0050
* @tc.name aceNapiTest050
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest050', 0, async function (done) {
console.info('aceNapiTest050 START');
let value = napitest.isArray();
const date1 = new Date('December 17, 1995 03:24:00');
value = napitest.isDate(date1);
console.info('aceNapiTest050 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value).assertTrue();
done();
});
/* @tc.number SUB_ACE_BASIC_ETS_NAPI_0600
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0051
* @tc.name aceNapiTest051
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest051', 0, async function (done) {
console.info('aceNapiTest051 START');
let value = napitest.isDate("2023-12-15");
let value = napitest.strictEquals();
console.info('aceNapiTest051 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertFalse();
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0610
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0052
* @tc.name aceNapiTest052
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest052', 0, async function (done) {
console.info('aceNapiTest052 START');
let value = napitest.strictEquals();
let value = napitest.getPropertyNames();
console.info('aceNapiTest052 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0620
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0053
* @tc.name aceNapiTest053
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest053', 0, async function (done) {
console.info('aceNapiTest053 START');
let value = napitest.getPropertyNames();
let value = napitest.setProperty();
console.info('aceNapiTest053 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value instanceof Object).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0630
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0054
* @tc.name aceNapiTest054
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest054', 0, async function (done) {
console.info('aceNapiTest054 START');
let value = napitest.setProperty();
let value = napitest.getProperty();
console.info('aceNapiTest054 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value instanceof Object).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0640
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0055
* @tc.name aceNapiTest055
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest055', 0, async function (done) {
console.info('aceNapiTest055 START');
let value = napitest.getProperty();
let value = napitest.hasProperty();
console.info('aceNapiTest055 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value instanceof Object).assertTrue();
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0650
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0056
* @tc.name aceNapiTest056
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest056', 0, async function (done) {
console.info('aceNapiTest056 START');
let value = napitest.hasProperty();
let testObj = {
'a':1,
'b':2
}
value = napitest.setAndDeleteProperty(testObj, 'a');
console.info('aceNapiTest056 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value === 0).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0660
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0057
* @tc.name aceNapiTest057
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest057', 0, async function (done) {
console.info('aceNapiTest057 START');
let value = napitest.deleteProperty([1,2], "hhe");
let testObj = {
'a':1,
'b':2
}
value = napitest.hasOwnProperty(testObj, 'a');
console.info('aceNapiTest057 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0670
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0058
* @tc.name aceNapiTest058
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest058', 0, async function (done) {
console.info('aceNapiTest058 START');
let value = napitest.hasOwnProperty([1,2], "hhe");
let value = napitest.setNamedProperty([1,2], "e", false);
console.info('aceNapiTest058 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertFalse();
expect(value).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0680
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0059
* @tc.name aceNapiTest059
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest059', 0, async function (done) {
console.info('aceNapiTest059 START');
let value = napitest.setNamedProperty([1,2], "e", false);
let obj = {
foo: "bar",
age: 42,
baz: { myProp: 12 },
};
let value = napitest.getNamedProperty(obj, "foo");
console.info('aceNapiTest059 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertTrue();
expect(value).assertEqual('bar');
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0690
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0060
* @tc.name aceNapiTest060
* @tc.desc aceNapiEtsTest
*/
......@@ -1024,202 +856,478 @@ export default function nativeApiStringJsunit() {
age: 42,
baz: { myProp: 12 },
};
let value = napitest.getNamedProperty(obj, "foo");
let value = napitest.hasNamedProperty(obj, "foo");
console.info('aceNapiTest060 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual('bar');
expect(value).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0700
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0061
* @tc.name aceNapiTest061
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest061', 0, async function (done) {
console.info('aceNapiTest061 START');
let obj = {
foo: "bar",
age: 42,
baz: { myProp: 12 },
};
let value = napitest.hasNamedProperty(obj, "foo");
let value = napitest.setElement();
console.info('aceNapiTest061 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertTrue();
expect(value instanceof Object).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0710
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0062
* @tc.name aceNapiTest062
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest062', 0, async function (done) {
console.info('aceNapiTest062 START');
let value = napitest.setElement();
let value = napitest.getElement();
console.info('aceNapiTest062 testString result is: ' + value + "--" + JSON.stringify(value));
let fi = value.envIsNull;
expect(value instanceof Object).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0720
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0063
* @tc.name aceNapiTest063
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest063', 0, async function (done) {
console.info('aceNapiTest063 START');
let value = napitest.getElement();
let value = napitest.hasElement();
console.info('aceNapiTest063 testString result is: ' + value + "--" + JSON.stringify(value));
let fi = value.envIsNull;
expect(value instanceof Object).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0730
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0064
* @tc.name aceNapiTest064
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest064', 0, async function (done) {
console.info('aceNapiTest064 START');
let value = napitest.hasElement();
let value = napitest.deleteElement();
console.info('aceNapiTest064 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value instanceof Object).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0740
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0065
* @tc.name aceNapiTest065
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest065', 0, async function (done) {
console.info('aceNapiTest065 START');
let value = napitest.deleteElement();
let value = napitest.defineProperties();
console.info('aceNapiTest065 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value instanceof Object).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0750
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0066
* @tc.name aceNapiTest066
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest066', 0, async function (done) {
console.info('aceNapiTest066 START');
let value = napitest.defineProperties();
let value = napitest.wrap();
console.info('aceNapiTest066 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value instanceof Object).assertTrue();
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0067
* @tc.name aceNapiTest067
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest067', 0, async function (done) {
console.info('aceNapiTest067 START');
let value = napitest.unwrap();
console.info('aceNapiTest067 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0770
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0068
* @tc.name aceNapiTest068
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest068', 0, async function (done) {
console.info('aceNapiTest068 START');
let value = napitest.wrap();
let value = napitest.removeWrap();
console.info('aceNapiTest068 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0780
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0069
* @tc.name aceNapiTest069
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest069', 0, async function (done) {
console.info('aceNapiTest069 START');
let value = napitest.unwrap();
let value = napitest.getVersion();
console.info('aceNapiTest069 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value).assertEqual(2147483647 );
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0790
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0070
* @tc.name aceNapiTest070
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest070', 0, async function (done) {
console.info('aceNapiTest070 START');
let value = napitest.removeWrap();
let value = napitest.createPromise();
console.info('aceNapiTest070 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0800
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0071
* @tc.name aceNapiTest071
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest071', 0, async function (done) {
console.info('aceNapiTest071 START');
let value = napitest.getVersion();
let value = napitest.resolveAndRejectDeferred();
console.info('aceNapiTest071 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(2147483647 );
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0810
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0072
* @tc.name aceNapiTest072
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest072', 0, async function (done) {
console.info('aceNapiTest072 START');
let value = napitest.createPromise();
let value = napitest.isPromise();
console.info('aceNapiTest072 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0820
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0073
* @tc.name aceNapiTest073
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest073', 0, async function (done) {
console.info('aceNapiTest073 START');
let value = napitest.resolveAndRejectDeferred();
let value = napitest.runScript("25");
console.info('aceNapiTest073 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value == undefined).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0830
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0074
* @tc.name aceNapiTest074
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest074', 0, async function (done) {
console.info('aceNapiTest074 START');
let value = napitest.isPromise();
function testFunc() {
return 666;
}
value = napitest.callFunction(testFunc);
console.info('aceNapiTest074 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
expect(value === 666).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0840
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0075
* @tc.name aceNapiTest075
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest075', 0, async function (done) {
console.info('aceNapiTest075 START');
let value = napitest.runScript("25");
value = napitest.getUvEventLoop();
console.info('aceNapiTest075 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value == undefined).assertTrue();
expect(value === undefined).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0076
* @tc.name aceNapiTest076
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest076', 0, async function (done) {
console.info('aceNapiTest076 START');
let myClass = new napitest.myClass();
value = myClass.sayHello();
console.info('aceNapiTest076 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value === 666).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0077
* @tc.name aceNapiTest077
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest077', 0, async function (done) {
console.info('aceNapiTest077 START');
value = napitest.getGlobal();
console.info('aceNapiTest077 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value === undefined).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0078
* @tc.name aceNapiTest078
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest078', 0, async function (done) {
console.info('aceNapiTest078 START');
value = napitest.testAsyncWork(1000, (input) => {
console.info('testAsyncWork ' + (input * 2));
return input * 2;
});
console.info('aceNapiTest078 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value === 0).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0079
* @tc.name aceNapiTest079
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest079', 0, async function (done) {
console.info('aceNapiTest079 START');
value = napitest.testPromise(1).then(
(result)=>{
console.info('aceNapiTest079 testString result is: ' + result + "--" + JSON.stringify(result));
expect(result > 0).assertTrue();
}
);
value = napitest.testPromise(-1).then(
(result)=>{
console.info('aceNapiTest079 testString result is: ' + result + "--" + JSON.stringify(result));
expect(result > 0).assertTrue();
}
);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0080
* @tc.name aceNapiTest080
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest080', 0, async function (done) {
console.info('aceNapiTest080 START');
value = napitest.ThreadSafeTest(() => {
return 666;
});
expect(value === 1).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0081
* @tc.name aceNapiTest081
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest081', 0, async function (done) {
console.info('aceNapiTest081 START');
try {
napitest.getAndClearLastException();
console.info('aceNapiTest081 testString result is: ' + value + "--" + JSON.stringify(value));
} catch (err) {
console.info('aceNapiTest081 testString result is err: ' + err + "--" + JSON.stringify(err));
let er = JSON.stringify(err)
expect(er === '{"code":"600"}').assertTrue();
}
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0082
* @tc.name aceNapiTest082
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest082', 0, async function (done) {
console.info('aceNapiTest082 START');
let value = napitest.getLastErrorInfo();
console.info('aceNapiTest082 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(6);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0083
* @tc.name aceNapiTest083
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest083', 0, async function (done) {
console.info('aceNapiTest083 START');
let value = napitest.cleanUpErrorInfo();
console.info('aceNapiTest083 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0084
* @tc.name aceNapiTest084
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest084', 0, async function (done) {
console.info('aceNapiTest084 START');
try {
let value = napitest.throwExistingError();
console.info('aceNapiTest084 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
} catch (err) {
console.info('aceNapiTest084 testString result is err: ' + err + "--" + JSON.stringify(err));
let er = JSON.stringify(err)
expect(er).assertEqual('{"code":"600"}');
done();
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0085
* @tc.name aceNapiTest085
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest085', 0, async function (done) {
console.info('aceNapiTest085 START');
try {
let value = napitest.throwError();
console.info('aceNapiTest085 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
} catch (err) {
console.info('aceNapiTest085 testString result is err: ' + err + "--" + JSON.stringify(err));
let er = JSON.stringify(err)
expect(er).assertEqual('{"code":"500"}');
done();
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0086
* @tc.name aceNapiTest086
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest086', 0, async function (done) {
console.info('aceNapiTest086 START');
try {
let value = napitest.throwTypeError();
console.info('aceNapiTest086 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
} catch (err) {
console.info('aceNapiTest086 testString result is err: ' + err + "--" + JSON.stringify(err));
expect(err instanceof TypeError).assertTrue();
done();
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0087
* @tc.name aceNapiTest087
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest087', 0, async function (done) {
console.info('aceNapiTest087 START');
try {
let value = napitest.throwRangeError();
console.info('aceNapiTest087 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
} catch (err) {
console.info('aceNapiTest087 testString result is err: ' + err + "--" + JSON.stringify(err));
expect(err instanceof RangeError).assertTrue();
done();
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0088
* @tc.name aceNapiTest088
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest088', 0, async function (done) {
console.info('aceNapiTest088 START');
let value = napitest.isError(false);
console.info('aceNapiTest088 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertFalse();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0089
* @tc.name aceNapiTest089
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest089', 0, async function (done) {
console.info('aceNapiTest089 START');
let value = napitest.createError();
console.info('aceNapiTest089 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0090
* @tc.name aceNapiTest090
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest090', 0, async function (done) {
console.info('aceNapiTest090 START');
let value = napitest.createTypeError();
console.info('aceNapiTest090 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0091
* @tc.name aceNapiTest091
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest091', 0, async function (done) {
console.info('aceNapiTest091 START');
let value = napitest.createRangeError();
console.info('aceNapiTest091 testString result is: ' + value + "--" + JSON.stringify(value));
expect(value).assertEqual(0);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0092
* @tc.name aceNapiTest092
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest092', 0, async function (done) {
console.info('aceNapiTest092 START');
let value = napitest.isExceptionPending();
console.info('aceNapiTest092 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.
先完成此消息的编辑!
想要评论请 注册