diff --git a/arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp b/arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp index ffe33370d36b7a9c5a99878b7a705d1cebff35f9..20740aaf96a0b8e1ca95ba1e8e1c9ea39d8b63fe 100644 --- a/arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp +++ b/arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp @@ -21,19 +21,19 @@ #include #include #include +#include #include -static bool exceptionWasPending = false; static napi_ref test_reference = NULL; -static int test_value = 1; -static napi_deferred deferred = 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; @@ -55,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)); @@ -73,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; @@ -86,10 +88,13 @@ static napi_value getLastErrorInfo(napi_env env, napi_callback_info info) { "Last error info code should match last status"); NAPI_ASSERT(env, error_info->error_message, "Last error info message should not be null"); - return NULL; + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, error_info->error_code, &_value)); + 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,31 +105,84 @@ static napi_value cleanUpErrorInfo(napi_env env, napi_callback_info info) { return result; } -static napi_value throwExistingError(napi_env env, napi_callback_info info) { - napi_value message; - napi_value error; - NAPI_CALL(env, napi_create_string_utf8(env, "existing error", NAPI_AUTO_LENGTH, &message)); - NAPI_CALL(env, napi_create_error(env, NULL, message, &error)); +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); + napi_create_string_latin1(env, "test error", NAPI_AUTO_LENGTH, &message); + napi_value error = nullptr; + napi_create_error(env, code, message, &error); + NAPI_ASSERT(env, error != nullptr, "error succes"); + bool isError = false; + napi_is_error(env, error, &isError); + NAPI_ASSERT(env, isError, "error succes"); + NAPI_CALL(env, napi_throw(env, error)); - return NULL; + + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + return _value; } -static napi_value throwError(napi_env env, napi_callback_info info) { - NAPI_CALL(env, napi_throw_error(env, NULL, "error")); - return NULL; +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); + napi_create_string_latin1(env, "test error", NAPI_AUTO_LENGTH, &message); + napi_value error = nullptr; + napi_create_error(env, code, message, &error); + NAPI_ASSERT(env, error != nullptr, "error succes"); + bool isError = false; + napi_is_error(env, error, &isError); + NAPI_ASSERT(env, isError, "error succes"); + napi_throw_error(env, "500", "Common error"); + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + return _value; } -static napi_value throwTypeError(napi_env env, napi_callback_info info) { - NAPI_CALL(env, napi_throw_type_error(env, NULL, "type error")); - return NULL; +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 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"); + bool isError = false; + napi_is_error(env, error, &isError); + NAPI_ASSERT(env, isError, "error succes"); + napi_throw_type_error(env, NULL, "type error1"); + + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + return _value; } -static napi_value throwRangeError(napi_env env, napi_callback_info info) { - NAPI_CALL(env, napi_throw_range_error(env, NULL, "range error")); - return NULL; +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 500", NAPI_AUTO_LENGTH, &message); + napi_value error = nullptr; + napi_create_range_error(env, code, message, &error); + NAPI_ASSERT(env, error != nullptr, "error succes"); + bool isError = false; + napi_is_error(env, error, &isError); + NAPI_ASSERT(env, isError, "error succes"); + napi_throw_range_error(env, NULL, "range error"); + + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + 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)); @@ -138,149 +196,186 @@ static napi_value isError(napi_env env, napi_callback_info info) { return result; } -static napi_value createError(napi_env env, napi_callback_info info) { - napi_value result; - napi_value message; - NAPI_CALL(env, napi_create_string_utf8(env, "error", NAPI_AUTO_LENGTH, &message)); - NAPI_CALL(env, napi_create_error(env, NULL, message, &result)); - return result; -} +static napi_value createError(napi_env env, napi_callback_info info) +{ + napi_value code = nullptr; + napi_value message = nullptr; -static napi_value createTypeError(napi_env env, napi_callback_info info) { - napi_value result; - napi_value message; - NAPI_CALL(env, napi_create_string_utf8(env, "type error", NAPI_AUTO_LENGTH, &message)); - NAPI_CALL(env, napi_create_type_error(env, NULL, message, &result)); - return result; + napi_create_string_latin1(env, "500", NAPI_AUTO_LENGTH, &code); + napi_create_string_latin1(env, "common error", NAPI_AUTO_LENGTH, &message); + + napi_value error = nullptr; + napi_create_error(env, code, message, &error); + NAPI_ASSERT(env, error != nullptr, "error succes"); + + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + return _value; } -static napi_value createRangeError(napi_env env, napi_callback_info info) { - napi_value result; - napi_value message; - NAPI_CALL(env, napi_create_string_utf8(env, "range error", NAPI_AUTO_LENGTH, &message)); - NAPI_CALL(env, napi_create_range_error(env, NULL, message, &result)); - return result; +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); + napi_create_string_latin1(env, "type error", NAPI_AUTO_LENGTH, &message); + napi_value error = nullptr; + napi_create_type_error(env, code, message, &error); + NAPI_ASSERT(env, error != nullptr, "error succes"); + + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + 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 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); + napi_create_string_latin1(env, "range error", NAPI_AUTO_LENGTH, &message); + napi_value error = nullptr; + napi_create_range_error(env, code, message, &error); - napi_value global; - NAPI_CALL(env, napi_get_global(env, &global)); + NAPI_ASSERT(env, error != nullptr, "error succes"); - 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; - } - return NULL; + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + return _value; } -static napi_value isExceptionPending(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_call_function(env, global, args[0], 0, 0, &result); + napi_value ex; + napi_get_and_clear_last_exception(env, &ex); + + bool exceptionWasPending = true; + napi_is_exception_pending(env, &exceptionWasPending); + NAPI_ASSERT(env, !exceptionWasPending, "tag !exceptionWasPending 1"); + + napi_throw(env, error); + + 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"); - NAPI_CALL(env, napi_is_exception_pending(env, &exceptionWasPending)); - return NULL; + return ex1; } -static napi_value openAndCloseHandleScope(napi_env env, napi_callback_info info) { - napi_handle_scope scope; - napi_value output = NULL; +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"); + + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + return _value; +} +static napi_value openAndCloseHandleScope(napi_env env, napi_callback_info info) +{ + napi_handle_scope scope; 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) { - NAPI_ASSERT(env, test_reference == NULL, - "The test allows only one reference at a time."); - - size_t argc = 2; - napi_value args[2]; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); - NAPI_ASSERT(env, argc == 2, "Expected two arguments."); - - uint32_t initial_refcount; - NAPI_CALL(env, napi_get_value_uint32(env, args[1], &initial_refcount)); - - NAPI_CALL(env, - napi_create_reference(env, args[0], initial_refcount, &test_reference)); - - NAPI_ASSERT(env, test_reference != NULL, - "A reference should have been created."); +static napi_value createReference(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; - return NULL; + 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) { - NAPI_ASSERT(env, test_reference != NULL, - "A reference must have been created."); - - uint32_t refcount; - NAPI_CALL(env, napi_reference_ref(env, test_reference, &refcount)); - - napi_value result; - NAPI_CALL(env, napi_create_uint32(env, refcount, &result)); - return result; -} - -static napi_value referenceUnref(napi_env env, napi_callback_info info) { - NAPI_ASSERT(env, test_reference != NULL, - "A reference must have been created."); - - uint32_t refcount; - NAPI_CALL(env, napi_reference_unref(env, test_reference, &refcount)); - - napi_value result; - NAPI_CALL(env, napi_create_uint32(env, refcount, &result)); - return result; -} +static napi_value referenceRefAndUnref(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + napi_ref resultRef = nullptr; + uint32_t resultRefCount = 0; -static napi_value getReferenceValue(napi_env env, napi_callback_info info) { - NAPI_ASSERT(env, test_reference != NULL, - "A reference must have been created."); + napi_create_object(env, &result); + napi_create_reference(env, result, 1, &resultRef); + + 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); + NAPI_ASSERT(env, refValue != NULL, + "A reference must have been created."); + napi_delete_reference(env, resultRef); - napi_value result; - NAPI_CALL(env, napi_get_reference_value(env, test_reference, &result)); - return result; + 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)); @@ -304,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)); @@ -318,60 +413,72 @@ static napi_value getArrayWithLength(napi_env env, napi_callback_info info) { napi_valuetype valuetype0; NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0)); - NAPI_ASSERT(env, valuetype0 == napi_number, + NAPI_ASSERT(env, valuetype0 == napi_object, "Wrong type of arguments. Expects an integer the first argument."); - int32_t array_length; - NAPI_CALL(env, napi_get_value_int32(env, args[0], &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)); + } + return ret; } -static void finalizer(napi_env env, void * data, void * hint) { - NAPI_CALL_RETURN_VOID(env, - napi_throw_error(env, NULL, "Error during Finalize")); +static napi_value createExternal(napi_env env, napi_callback_info info) +{ + const char testStr[] = "test"; + napi_value external = nullptr; + napi_create_external( + env, (void*)testStr, + [](napi_env env, void* data, void* hint) {}, + (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)); + + return _value; } -static napi_value createExternal(napi_env env, napi_callback_info info) { - napi_value external; - - NAPI_CALL(env, - napi_create_external(env, NULL, finalizer, NULL, &external)); +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*)testInt, arrayBufferSize, + [](napi_env env, void* data, void* hint) { + int* temp = static_cast(data); + free(temp); + temp = nullptr; + }, + (void*)testInt, &external); + return external; } -static napi_value createExternalArraybuffer(napi_env env, napi_callback_info info) { - static void* data = NULL; - napi_value arraybuffer; - NAPI_CALL(env, - napi_create_external_arraybuffer(env, data, 0, NULL, NULL, &arraybuffer)); - return arraybuffer; -} - -static napi_value createObject(napi_env env, napi_callback_info info) { - napi_value ret; - NAPI_CALL(env, napi_create_object(env, &ret)); - - napi_value num; - NAPI_CALL(env, napi_create_int32(env, 987654321, &num)); - - NAPI_CALL(env, napi_set_named_property(env, ret, "test_number", num)); - - napi_value str; - const char* str_val = "test string"; - size_t str_len = strlen(str_val); - NAPI_CALL(env, napi_create_string_utf8(env, str_val, str_len, &str)); - - NAPI_CALL(env, napi_set_named_property(env, ret, "test_string", str)); - - return ret; +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"); + 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)); @@ -390,79 +497,61 @@ static napi_value createSymbol(napi_env env, napi_callback_info info) { napi_value symbol; NAPI_CALL(env, napi_create_symbol(env, description, &symbol)); - return symbol; -} - -static napi_value createTypeArray(napi_env env, napi_callback_info info) { - static int8_t externalData[] = { 0, 1, 2 }; - - napi_value output_buffer; - NAPI_CALL(env, napi_create_external_arraybuffer(env, - externalData, - sizeof(externalData), - NULL, // finalize_callback - NULL, // finalize_hint - &output_buffer)); + napi_valuetype valuetypeSymbol; + NAPI_CALL(env, napi_typeof(env, symbol, &valuetypeSymbol)); - napi_value output_array; - NAPI_CALL(env, napi_create_typedarray(env, - napi_int8_array, - sizeof(externalData) / sizeof(int8_t), - output_buffer, - 0, - &output_array)); - - return output_array; + NAPI_ASSERT(env, valuetypeSymbol == napi_symbol, + "Wrong type of arguments. Expects a string."); + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + + return _value; } -static napi_value createDataView(napi_env env, napi_callback_info info) { - size_t argc = 3; - napi_value args [3]; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); - - NAPI_ASSERT(env, argc == 3, "Wrong number of arguments"); - - napi_valuetype valuetype0; - napi_value arraybuffer = args[0]; - - NAPI_CALL(env, napi_typeof(env, arraybuffer, &valuetype0)); - NAPI_ASSERT(env, valuetype0 == napi_object, - "Wrong type of arguments. Expects a ArrayBuffer as the first " - "argument."); - - bool is_arraybuffer; - NAPI_CALL(env, napi_is_arraybuffer(env, arraybuffer, &is_arraybuffer)); - NAPI_ASSERT(env, is_arraybuffer, - "Wrong type of arguments. Expects a ArrayBuffer as the first " - "argument."); - - napi_valuetype valuetype1; - NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1)); - - NAPI_ASSERT(env, valuetype1 == napi_number, - "Wrong type of arguments. Expects a number as second argument."); - - size_t byte_offset = 0; - NAPI_CALL(env, napi_get_value_uint32(env, args[1], (uint32_t*)(&byte_offset))); +static napi_value createTypeArray(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_valuetype valuetype2; - NAPI_CALL(env, napi_typeof(env, args[2], &valuetype2)); + void* tmpArrayBufferPtr = nullptr; + size_t arrayBufferLength = 0; + napi_get_arraybuffer_info(env, arrayBuffer, &tmpArrayBufferPtr, &arrayBufferLength); + + NAPI_ASSERT(env, arrayBufferPtr == tmpArrayBufferPtr, "napi_get_arraybuffer_info success"); + NAPI_ASSERT(env, arrayBufferSize == arrayBufferLength, "napi_create_arraybuffer success"); - NAPI_ASSERT(env, valuetype2 == napi_number, - "Wrong type of arguments. Expects a number as third argument."); + napi_value _value; + napi_create_typedarray(env, napi_int32_array, typedArrayLength, arrayBuffer, 0, &_value); + + return _value; +} - size_t length = 0; - NAPI_CALL(env, napi_get_value_uint32(env, args[2], (uint32_t*)(&length))); +static napi_value createDataView(napi_env env, napi_callback_info info) +{ + napi_value arrayBuffer = nullptr; + void* arrayBufferPtr = nullptr; + size_t arrayBufferSize = 16; + napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer); + NAPI_ASSERT(env, arrayBufferPtr != nullptr, "napi_create_arraybuffer success"); + bool isArrayBuffer = false; + napi_is_arraybuffer(env, arrayBuffer, &isArrayBuffer); + NAPI_ASSERT(env, isArrayBuffer, " napi_is_arraybuffer success"); - napi_value output_dataview; - NAPI_CALL(env, - napi_create_dataview(env, length, arraybuffer, - byte_offset, &output_dataview)); + napi_value result = nullptr; + NAPI_CALL(env, napi_create_dataview(env, arrayBufferSize, arrayBuffer, 0, &result)); - return output_dataview; + bool isDataView = false; + napi_is_dataview(env, result, &isDataView); + NAPI_ASSERT(env, isDataView, " napi_is_dataview success"); + + 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)); @@ -476,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)); @@ -490,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)); @@ -504,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)); @@ -518,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)); @@ -533,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_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)); @@ -544,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)); @@ -559,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_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)); @@ -570,54 +666,124 @@ 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; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); + return thisVar; + }, nullptr, 0, nullptr, &testWrapClass); + + 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_value result; - NAPI_CALL(env, napi_get_prototype(env, args[0], &result)); + NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments"); - return result; + 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 getDataViewInfo(napi_env env, napi_callback_info info) { - size_t argc = 1; - napi_value args [1]; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); +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); - NAPI_ASSERT(env, argc == 1, "Wrong number of arguments"); + bool isTypedArray = false; + napi_is_typedarray(env, result, &isTypedArray); + NAPI_ASSERT(env, isTypedArray, "getTypedArrayInfo napi_is_dataview fail"); - napi_valuetype valuetype; - napi_value input_dataview = args[0]; - - NAPI_CALL(env, napi_typeof(env, input_dataview, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, - "Wrong type of arguments. Expects a DataView as the first " - "argument."); - - bool is_dataview; - NAPI_CALL(env, napi_is_dataview(env, input_dataview, &is_dataview)); - NAPI_ASSERT(env, is_dataview, - "Wrong type of arguments. Expects a DataView as the first " - "argument."); - size_t byte_offset = 0; + napi_typedarray_type type; size_t length = 0; - napi_value buffer; - NAPI_CALL(env, - napi_get_dataview_info(env, input_dataview, &length, NULL, - &buffer, &byte_offset)); + 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 output_dataview; - NAPI_CALL(env, - napi_create_dataview(env, length, buffer, - byte_offset, &output_dataview)); + 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) +{ + napi_value arrayBuffer = nullptr; + void* arrayBufferPtr = nullptr; + size_t arrayBufferSize = 1024; + napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPtr, &arrayBuffer); + 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 = -1; + napi_get_dataview_info(env, result, &byteLength, &data, &retArrayBuffer, &byteOffset); + bool retIsArrayBuffer = false; + napi_is_arraybuffer(env, retArrayBuffer, &retIsArrayBuffer); + void* tmpArrayBufferPtr = nullptr; + size_t arrayBufferLength = 0; + napi_get_arraybuffer_info(env, retArrayBuffer, &tmpArrayBufferPtr, &arrayBufferLength); - return output_dataview; + 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)); @@ -631,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)); @@ -645,40 +812,57 @@ static napi_value getValueDouble(napi_env env, napi_callback_info info) { return output; } -static napi_value getValueExternal(napi_env env, napi_callback_info info) { - size_t argc = 1; - napi_value arg; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &arg, NULL, NULL)); - - NAPI_ASSERT(env, argc == 1, "Expected one argument."); - - napi_valuetype argtype; - NAPI_CALL(env, napi_typeof(env, arg, &argtype)); - - NAPI_ASSERT(env, argtype == napi_external, "Expected an external value."); - - void* data; - NAPI_CALL(env, napi_get_value_external(env, arg, &data)); +static napi_value getValueExternal(napi_env env, napi_callback_info info) +{ + const char testStr[] = "test"; + napi_value external = nullptr; + napi_create_external( + env, (void*)testStr, + [](napi_env env, void* data, void* hint) {}, + (void*)testStr, &external); + void* tempExternal = nullptr; + napi_get_value_external(env, external, &tempExternal); - NAPI_ASSERT(env, data != NULL && *(int*)data == test_value, - "An external data value of 1 was expected."); + NAPI_ASSERT(env, tempExternal == testStr, "napi_get_value_external true"); - return NULL; + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + + return _value; } -static napi_value getNull(napi_env env, napi_callback_info info) { - napi_value result; +static napi_value getNull(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; NAPI_CALL(env, napi_get_null(env, &result)); - return 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)); + + return _value; } -static napi_value getUndefined(napi_env env, napi_callback_info info) { - napi_value result; +static napi_value getUndefined(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; NAPI_CALL(env, napi_get_undefined(env, &result)); - return 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)); + + 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)); @@ -689,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)); @@ -700,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)); @@ -711,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)); @@ -722,67 +909,53 @@ static napi_value coerceToString(napi_env env, napi_callback_info info) { return output; } -static napi_value instanceOf(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)); - - bool instanceof; - NAPI_CALL(env, napi_instanceof(env, args[0], args[1], &instanceof)); - - napi_value result; - NAPI_CALL(env, napi_get_boolean(env, instanceof, &result)); - - return result; -} - -static napi_value isArray(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)); - - NAPI_ASSERT(env, argc >= 2, "Wrong number of arguments"); - - napi_valuetype valuetype0; - NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0)); - - NAPI_ASSERT(env, valuetype0 == napi_object, - "Wrong type of arguments. Expects an array as first argument."); - - napi_valuetype valuetype1; - NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1)); +static napi_value instanceOf(napi_env env, napi_callback_info info) +{ + napi_value customClass = nullptr; - NAPI_ASSERT(env, valuetype1 == napi_number, - "Wrong type of arguments. Expects an integer as second argument."); + 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; + }, nullptr, 0, nullptr, &customClass); - napi_value array = args[0]; - int32_t index; - NAPI_CALL(env, napi_get_value_int32(env, args[1], &index)); + napi_value customClassPrototype = nullptr; + napi_get_prototype(env, customClass, &customClassPrototype); + + napi_value customInstance = nullptr; + NAPI_CALL(env, napi_new_instance(env, customClass, 0, nullptr, &customInstance)); - NAPI_ASSERT(env, index >= 0, "Invalid index. Expects a positive integer."); + bool isInstanceOf = false; + NAPI_CALL(env, napi_instanceof(env, customInstance, customClass, &isInstanceOf)); - bool isarray; - NAPI_CALL(env, napi_is_array(env, array, &isarray)); + NAPI_ASSERT(env, isInstanceOf, "isInstanceOf success"); - if (!isarray) { - return NULL; - } - - uint32_t length; - NAPI_CALL(env, napi_get_array_length(env, array, &length)); + napi_value result; + NAPI_CALL(env, napi_get_boolean(env, isInstanceOf, &result)); - NAPI_ASSERT(env, ((uint32_t)index < length), "Index out of bounds!"); + return result; +} - napi_value ret; - NAPI_CALL(env, napi_get_element(env, array, index, &ret)); +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"); + bool isArray = false; + napi_is_array(env, array, &isArray); + NAPI_ASSERT(env, isArray, "napi_is_arrayd success"); - return ret; + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + 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)); @@ -791,40 +964,72 @@ static napi_value isDate(napi_env env, napi_callback_info info) { return result; } -static napi_value strictEquals(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)); - - bool bool_result; - napi_value result; - NAPI_CALL(env, napi_strict_equals(env, args[0], args[1], &bool_result)); - NAPI_CALL(env, napi_get_boolean(env, bool_result, &result)); +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 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 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"); - return result; + 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) { - size_t argc = 1; - napi_value args[1]; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); +static napi_value getPropertyNames(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments"); + NAPI_ASSERT(env, result != nullptr, "napi_create_object success"); - napi_valuetype value_type0; - NAPI_CALL(env, napi_typeof(env, args[0], &value_type0)); + const char testStr[] = "1234567"; + napi_value strAttribute = nullptr; - NAPI_ASSERT(env, value_type0 == napi_object, - "Wrong type of arguments. Expects an object as first argument."); + NAPI_CALL(env, napi_create_string_utf8(env, testStr, strlen(testStr), &strAttribute)); + NAPI_ASSERT(env, strAttribute != nullptr, "napi_create_string_utf8 success"); - napi_value output; - NAPI_CALL(env, napi_get_property_names(env, args[0], &output)); + 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"); - return output; + 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)); + return _value; } static napi_value setProperty(napi_env env, - napi_callback_info info) { + napi_callback_info info) +{ napi_status status; napi_value object, key, value; @@ -859,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; @@ -893,35 +1099,67 @@ static napi_value getProperty(napi_env env, return object; } -static napi_value hasProperty(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)); +static napi_value hasProperty(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_ASSERT(env, argc >= 2, "Wrong number of arguments"); + const char testStr[] = "1234567"; + napi_value strAttribute = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, testStr, strlen(testStr), &strAttribute)); + NAPI_CALL(env, napi_set_named_property(env, result, "strAttribute", strAttribute)); - napi_valuetype valuetype0; - NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0)); + napi_value retStrAttribute = nullptr; + NAPI_CALL(env, napi_get_named_property(env, result, "strAttribute", &retStrAttribute)); - NAPI_ASSERT(env, valuetype0 == napi_object, - "Wrong type of arguments. Expects an object as first argument."); + int32_t testNumber = 12345; + napi_value numberAttribute = nullptr; + NAPI_CALL(env, napi_create_int32(env, testNumber, &numberAttribute)); + NAPI_CALL(env, napi_set_named_property(env, result, "numberAttribute", numberAttribute)); - napi_valuetype valuetype1; - NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1)); + napi_value propNames = nullptr; + NAPI_CALL(env, napi_get_property_names(env, result, &propNames)); + NAPI_ASSERT(env, propNames != nullptr, "napi_get_property_names success"); - NAPI_ASSERT(env, valuetype1 == napi_string || valuetype1 == napi_symbol, - "Wrong type of arguments. Expects a string or symbol as second."); + bool isArray = false; + NAPI_CALL(env, napi_is_array(env, propNames, &isArray)); + NAPI_ASSERT(env, isArray, "napi_is_array success"); - bool has_property; - NAPI_CALL(env, napi_has_property(env, args[0], args[1], &has_property)); + uint32_t arrayLength = 0; + NAPI_CALL(env, napi_get_array_length(env, propNames, &arrayLength)); - napi_value ret; - NAPI_CALL(env, napi_get_boolean(env, has_property, &ret)); + 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"); - return ret; + napi_value propName = nullptr; + NAPI_CALL(env, napi_get_element(env, propNames, i, &propName)); + NAPI_ASSERT(env, propName != nullptr, "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]; @@ -938,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)); @@ -968,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] = ""; @@ -1003,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] = ""; @@ -1036,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] = ""; @@ -1072,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)); @@ -1095,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)); @@ -1118,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; @@ -1141,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)); @@ -1183,60 +1446,111 @@ 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)); +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; +} - bool result; - NAPI_CALL(env, napi_strict_equals(env, newTargetArg, thisArg, &result)); - NAPI_ASSERT(env, !result, "this !== new.target"); +static napi_value wrap(napi_env env, napi_callback_info info) +{ + napi_value testClass = nullptr; + napi_define_class( + env, "TestClass", 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); - NAPI_ASSERT(env, newTargetArg != NULL, "newTargetArg != NULL"); - NAPI_CALL(env, napi_strict_equals(env, newTargetArg, undefined, &result)); - NAPI_ASSERT(env, !result, "new.target !== undefined"); + return thisVar; + }, + nullptr, 0, nullptr, &testClass); + + napi_value instanceValue = nullptr; + napi_new_instance(env, testClass, 0, nullptr, &instanceValue); - return thisArg; + const char* testStr = "test"; + napi_wrap( + env, instanceValue, (void*)testStr, [](napi_env env, void* data, void* hint) {}, nullptr, nullptr); + + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + return _value; } -static napi_value wrap(napi_env env, napi_callback_info info) { - size_t argc = 1; - napi_value arg; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &arg, NULL, NULL)); +static napi_value unwrap(napi_env env, napi_callback_info info) +{ + napi_value testClass = nullptr; + napi_define_class( + env, "TestClass", 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); - NAPI_CALL(env, napi_wrap(env, arg, &test_value, NULL, NULL, NULL)); - return NULL; -} + return thisVar; + }, + nullptr, 0, nullptr, &testClass); -static napi_value unwrap(napi_env env, napi_callback_info info) { - size_t argc = 1; - napi_value arg; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &arg, NULL, NULL)); + napi_value instanceValue = nullptr; + napi_new_instance(env, testClass, 0, nullptr, &instanceValue); - void* data; - NAPI_CALL(env, napi_unwrap(env, arg, &data)); + const char* testStr = "test"; + napi_wrap( + env, instanceValue, (void*)testStr, [](napi_env env, void* data, void* hint) {}, nullptr, nullptr); - bool is_expected = (data != NULL && *(int*)data == 3); - napi_value result; - NAPI_CALL(env, napi_get_boolean(env, is_expected, &result)); - return result; + 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) { - size_t argc = 1; - napi_value wrapped; - void* data; +static napi_value removeWrap(napi_env env, napi_callback_info info) +{ + napi_value testClass = nullptr; + napi_define_class( + env, "TestClass", 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); - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &wrapped, NULL, NULL)); - NAPI_CALL(env, napi_remove_wrap(env, wrapped, &data)); + return thisVar; + }, + nullptr, 0, nullptr, &testClass); - return NULL; + napi_value instanceValue = nullptr; + napi_new_instance(env, testClass, 0, nullptr, &instanceValue); + + const char* testStr = "test"; + napi_wrap( + env, instanceValue, (void*)testStr, [](napi_env env, void* data, void* hint) {}, nullptr, nullptr); + + 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)); @@ -1244,50 +1558,54 @@ static napi_value getVersion(napi_env env, napi_callback_info info) { return result; } -static napi_value createPromise(napi_env env, napi_callback_info info) { - napi_value promise; - - // We do not overwrite an existing deferred. - if (deferred != NULL) { - return NULL; - } - - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - - return promise; +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); + NAPI_ASSERT(env, deferred != nullptr, "create promise success"); + NAPI_ASSERT(env, promise != nullptr, "create promise success"); + + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + return _value; } -static napi_value resolveAndRejectDeferred(napi_env env, napi_callback_info info) { - napi_value argv[2]; - size_t argc = 2; - bool resolution; +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)); - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - NAPI_CALL(env, napi_get_value_bool(env, argv[1], &resolution)); - if (resolution) { - NAPI_CALL(env, napi_resolve_deferred(env, deferred, argv[0])); - } else { - NAPI_CALL(env, napi_reject_deferred(env, deferred, argv[0])); - } + bool isPromise = false; + napi_is_promise(env, promise, &isPromise); - deferred = NULL; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + NAPI_CALL(env, napi_resolve_deferred(env, deferred, undefined)); - return NULL; + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + return _value; } -static napi_value isPromise(napi_env env, napi_callback_info info) { - napi_value promise, result; - size_t argc = 1; - bool is_promise; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &promise, NULL, NULL)); - NAPI_CALL(env, napi_is_promise(env, promise, &is_promise)); - NAPI_CALL(env, napi_get_boolean(env, is_promise, &result)); +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)); + + bool isPromise = false; + NAPI_CALL(env, napi_is_promise(env, promise, &isPromise)); + NAPI_ASSERT(env, isPromise, "napi_is_promise success"); - return result; + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + 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; @@ -1298,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)); @@ -1336,6 +1665,27 @@ static napi_value napCreateArrayBuffer(napi_env env, napi_callback_info info) return arrayBuffer; } +static napi_value napiGetCbInfo(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1]; + napi_status status = napi_get_cb_info(env, info, &argc, args, NULL, NULL); + NAPI_ASSERT(env, status == napi_ok, "get_cb_info ok"); + NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments"); + double value; + napi_get_value_double(env, args[0], &value); + + napi_valuetype valuetype; + NAPI_CALL(env, napi_typeof(env, args[0], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong type of argment. Expects a nunber."); + + napi_value returnValue; + napi_status statusDouble = napi_create_double(env, value, &returnValue); + NAPI_ASSERT(env, statusDouble == napi_ok, "success to napi_create_double"); + + return returnValue; +} + static napi_value naiGetArrayBufferInfo(napi_env env, napi_callback_info info) { // the value to return @@ -1358,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; @@ -1399,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)); @@ -1461,6 +1795,107 @@ 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)); + } + + 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; @@ -1472,7 +1907,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)); @@ -1482,19 +1917,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) @@ -1544,6 +1981,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)); @@ -1558,6 +1996,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)); @@ -1568,15 +2007,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)); @@ -1584,61 +2030,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) -{ - void *data = nullptr; - napi_threadsafe_function tsfun = static_cast(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)); - - return _value; +static napi_value callFunction(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 string."); + napi_value ret; + NAPI_CALL(env, napi_call_function(env, nullptr, args[0], 0, nullptr, &ret)); + return ret; } -static napi_value napiGetTypedarrayInfo(napi_env env, napi_callback_info info) +static napi_value getGlobal(napi_env env, napi_callback_info info) { - napi_value arrayBuffer = nullptr; - void* arrayBufferPr = nullptr; - size_t arrayBufferSize = 200; - // create a JavaScript ArrayBuffer - napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPr, &arrayBuffer); - - // convert from N-API to C types - void* tmpArrayBufferPr = nullptr; - size_t arrayBufferLength = 0; - napi_get_arraybuffer_info(env, arrayBuffer, &tmpArrayBufferPr, &arrayBufferLength); - - NAPI_ASSERT(env, arrayBufferPr == tmpArrayBufferPr, "creat and get ArrayBuffer success"); - NAPI_ASSERT(env, arrayBufferSize == arrayBufferLength, "creat and get ArrayBuffer size success"); + 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 typedarray = nullptr; - // create a JavaScript TypedArray - napi_status status = napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &typedarray); - NAPI_ASSERT(env, status == napi_ok, "napi_create_typedarray success"); + 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)); - bool isTypedArray = false; - // Whether the given napi_value represents a TypedArray - napi_is_typedarray(env, typedarray, &isTypedArray); - NAPI_ASSERT(env, isTypedArray, "the type is TypeArray"); + 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"); - // convert from N-API to C types - napi_typedarray_type typedarrayType; - size_t typedarrayLength = 0; - void* typedarrayBufferPtr = nullptr; - napi_value tmpArrayBuffer = nullptr; - size_t byteOffset = 0; - // returns various properties of a typed array - napi_get_typedarray_info(env, typedarray, &typedarrayType, &typedarrayLength, &typedarrayBufferPtr, &tmpArrayBuffer, &byteOffset); - NAPI_ASSERT(env, typedarrayBufferPtr == arrayBufferPr, "napi_get_typedarray_info success"); - NAPI_ASSERT(env, arrayBufferSize == typedarrayLength, "napi_get_typedarray_info size success"); + 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); - // return the value of success + 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, 0, &_value)); - + NAPI_CALL(env, napi_create_int32(env, 1, &_value)); return _value; } @@ -1646,81 +2106,81 @@ EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) { - napi_property_descriptor properties[] = { DECLARE_NAPI_FUNCTION("getLastErrorInfo", getLastErrorInfo), - DECLARE_NAPI_FUNCTION("cleanUpErrorInfo", cleanUpErrorInfo), - DECLARE_NAPI_FUNCTION("throwExistingError", throwExistingError), - DECLARE_NAPI_FUNCTION("throwError", throwError), - DECLARE_NAPI_FUNCTION("throwTypeError", throwTypeError), - DECLARE_NAPI_FUNCTION("throwRangeError", throwRangeError), - DECLARE_NAPI_FUNCTION("isError", isError), - DECLARE_NAPI_FUNCTION("createError", createError), - DECLARE_NAPI_FUNCTION("createTypeError", createTypeError), - DECLARE_NAPI_FUNCTION("createRangeError", createRangeError), - DECLARE_NAPI_FUNCTION("getAndClearLastException", getAndClearLastException), - DECLARE_NAPI_FUNCTION("isExceptionPending", isExceptionPending), - 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("createArrayAndGetLength", createArrayAndGetLength), - DECLARE_NAPI_FUNCTION("getArrayWithLength", getArrayWithLength), - DECLARE_NAPI_FUNCTION("createExternal", createExternal), - DECLARE_NAPI_FUNCTION("createExternalArraybuffer", createExternalArraybuffer), - DECLARE_NAPI_FUNCTION("createObject", createObject), - DECLARE_NAPI_FUNCTION("createSymbol", createSymbol), - DECLARE_NAPI_FUNCTION("createTypeArray", createTypeArray), - DECLARE_NAPI_FUNCTION("createDataView", createDataView), - DECLARE_NAPI_FUNCTION("createAndGetInt32", createAndGetInt32), - DECLARE_NAPI_FUNCTION("createAndGetUInt32", createAndGetUInt32), - DECLARE_NAPI_FUNCTION("createAndGetInt64", createAndGetInt64), - DECLARE_NAPI_FUNCTION("createDouble", createDouble), - DECLARE_NAPI_FUNCTION("createAndGetStringLatin1", createAndGetStringLatin1), - DECLARE_NAPI_FUNCTION("createAndGetStringUtf8", createAndGetStringUtf8), - DECLARE_NAPI_FUNCTION("getPrototype", getPrototype), - DECLARE_NAPI_FUNCTION("getDataViewInfo", getDataViewInfo), - DECLARE_NAPI_FUNCTION("getValueBool", getValueBool), - DECLARE_NAPI_FUNCTION("getValueDouble", getValueDouble), - DECLARE_NAPI_FUNCTION("getValueExternal", getValueExternal), - DECLARE_NAPI_FUNCTION("getNull", getNull), - DECLARE_NAPI_FUNCTION("getUndefined", getUndefined), - DECLARE_NAPI_FUNCTION("coerceToBool", coerceToBool), - DECLARE_NAPI_FUNCTION("coerceToNumber", coerceToNumber), - DECLARE_NAPI_FUNCTION("coerceToObject", coerceToObject), - DECLARE_NAPI_FUNCTION("coerceToString", coerceToString), - DECLARE_NAPI_FUNCTION("instanceOf", instanceOf), - DECLARE_NAPI_FUNCTION("isArray", isArray), - DECLARE_NAPI_FUNCTION("isDate", isDate), - DECLARE_NAPI_FUNCTION("strictEquals", strictEquals), - DECLARE_NAPI_FUNCTION("getPropertyNames", getPropertyNames), - DECLARE_NAPI_FUNCTION("setProperty", setProperty), - DECLARE_NAPI_FUNCTION("getProperty", getProperty), - DECLARE_NAPI_FUNCTION("hasProperty", hasProperty), - DECLARE_NAPI_FUNCTION("deleteProperty", deleteProperty), - DECLARE_NAPI_FUNCTION("hasOwnProperty", hasOwnProperty), - DECLARE_NAPI_FUNCTION("setNamedProperty", setNamedProperty), - DECLARE_NAPI_FUNCTION("getNamedProperty", getNamedProperty), - DECLARE_NAPI_FUNCTION("hasNamedProperty", hasNamedProperty), - DECLARE_NAPI_FUNCTION("setElement", setElement), - DECLARE_NAPI_FUNCTION("getElement", getElement), - 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), - DECLARE_NAPI_FUNCTION("getVersion", getVersion), - DECLARE_NAPI_FUNCTION("createPromise", createPromise), - DECLARE_NAPI_FUNCTION("resolveAndRejectDeferred", resolveAndRejectDeferred), - DECLARE_NAPI_FUNCTION("isPromise", isPromise), - DECLARE_NAPI_FUNCTION("TestLatin1", TestLatin1), - DECLARE_NAPI_FUNCTION("runScript", runScript), + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("getLastErrorInfo", getLastErrorInfo), + DECLARE_NAPI_FUNCTION("cleanUpErrorInfo", cleanUpErrorInfo), + DECLARE_NAPI_FUNCTION("throwExistingError", throwExistingError), + DECLARE_NAPI_FUNCTION("throwError", throwError), + DECLARE_NAPI_FUNCTION("throwTypeError", throwTypeError), + DECLARE_NAPI_FUNCTION("throwRangeError", throwRangeError), + DECLARE_NAPI_FUNCTION("isError", isError), + DECLARE_NAPI_FUNCTION("createError", createError), + DECLARE_NAPI_FUNCTION("createTypeError", createTypeError), + DECLARE_NAPI_FUNCTION("createRangeError", createRangeError), + DECLARE_NAPI_FUNCTION("getAndClearLastException", getAndClearLastException), + DECLARE_NAPI_FUNCTION("isExceptionPending", isExceptionPending), + DECLARE_NAPI_FUNCTION("openAndCloseHandleScope", openAndCloseHandleScope), + DECLARE_NAPI_FUNCTION("openAndCloseEscapableHandleScope", openAndCloseEscapableHandleScope), + DECLARE_NAPI_FUNCTION("createReference", createReference), + 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), + DECLARE_NAPI_FUNCTION("createExternalArraybuffer", createExternalArraybuffer), + DECLARE_NAPI_FUNCTION("createObject", createObject), + DECLARE_NAPI_FUNCTION("createSymbol", createSymbol), + DECLARE_NAPI_FUNCTION("createTypeArray", createTypeArray), + DECLARE_NAPI_FUNCTION("createDataView", createDataView), + DECLARE_NAPI_FUNCTION("createAndGetInt32", createAndGetInt32), + DECLARE_NAPI_FUNCTION("createAndGetUInt32", createAndGetUInt32), + DECLARE_NAPI_FUNCTION("createAndGetInt64", createAndGetInt64), + DECLARE_NAPI_FUNCTION("createDouble", createDouble), + 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), + DECLARE_NAPI_FUNCTION("getValueExternal", getValueExternal), + DECLARE_NAPI_FUNCTION("getNull", getNull), + DECLARE_NAPI_FUNCTION("getUndefined", getUndefined), + DECLARE_NAPI_FUNCTION("coerceToBool", coerceToBool), + DECLARE_NAPI_FUNCTION("coerceToNumber", coerceToNumber), + DECLARE_NAPI_FUNCTION("coerceToObject", coerceToObject), + DECLARE_NAPI_FUNCTION("coerceToString", coerceToString), + DECLARE_NAPI_FUNCTION("instanceOf", instanceOf), + DECLARE_NAPI_FUNCTION("isArray", isArray), + DECLARE_NAPI_FUNCTION("isDate", isDate), + DECLARE_NAPI_FUNCTION("strictEquals", strictEquals), + DECLARE_NAPI_FUNCTION("getPropertyNames", getPropertyNames), + DECLARE_NAPI_FUNCTION("setProperty", setProperty), + DECLARE_NAPI_FUNCTION("getProperty", getProperty), + DECLARE_NAPI_FUNCTION("hasProperty", hasProperty), + DECLARE_NAPI_FUNCTION("setAndDeleteProperty", setAndDeleteProperty), + DECLARE_NAPI_FUNCTION("hasOwnProperty", hasOwnProperty), + DECLARE_NAPI_FUNCTION("setNamedProperty", setNamedProperty), + DECLARE_NAPI_FUNCTION("getNamedProperty", getNamedProperty), + DECLARE_NAPI_FUNCTION("hasNamedProperty", hasNamedProperty), + DECLARE_NAPI_FUNCTION("setElement", setElement), + DECLARE_NAPI_FUNCTION("getElement", getElement), + DECLARE_NAPI_FUNCTION("hasElement", hasElement), + DECLARE_NAPI_FUNCTION("deleteElement", deleteElement), + DECLARE_NAPI_FUNCTION("defineProperties", defineProperties), + DECLARE_NAPI_FUNCTION("wrap", wrap), + DECLARE_NAPI_FUNCTION("unwrap", unwrap), + DECLARE_NAPI_FUNCTION("removeWrap", removeWrap), + DECLARE_NAPI_FUNCTION("getVersion", getVersion), + DECLARE_NAPI_FUNCTION("createPromise", createPromise), + DECLARE_NAPI_FUNCTION("resolveAndRejectDeferred", resolveAndRejectDeferred), + 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), @@ -1731,29 +2191,40 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("napiCreateBigintUint64", napiCreateBigintUint64), DECLARE_NAPI_FUNCTION("napiCreateBigintInt64", napiCreateBigintInt64), DECLARE_NAPI_FUNCTION("napiCreateBigintWords", napiCreateBigintWords), - DECLARE_NAPI_FUNCTION("napiGetTypedarrayInfo", napiGetTypedarrayInfo), + 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); } diff --git a/arkui/ace_napi_test/entry/src/main/ets/test/List.test.ets b/arkui/ace_napi_test/entry/src/main/ets/test/List.test.ets index ae1a06d64937523e8dffdf8938f07255115fa1f5..43dca6e7d2672a3e8733b52002b4e22020060609 100644 --- a/arkui/ace_napi_test/entry/src/main/ets/test/List.test.ets +++ b/arkui/ace_napi_test/entry/src/main/ets/test/List.test.ets @@ -13,9 +13,7 @@ * limitations under the License. */ import napiStringTest from './NativeApiStringTest'; -import aceNapiEtsTest from './NapiEtsTest' export default function testsuite() { napiStringTest() - aceNapiEtsTest() } \ No newline at end of file diff --git a/arkui/ace_napi_test/entry/src/main/ets/test/NapiEtsTest.ets b/arkui/ace_napi_test/entry/src/main/ets/test/NapiEtsTest.ets deleted file mode 100644 index 9d7459acd9f04980bb8977ee58bfed4fb142cab8..0000000000000000000000000000000000000000 --- a/arkui/ace_napi_test/entry/src/main/ets/test/NapiEtsTest.ets +++ /dev/null @@ -1,849 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import napitest from 'libnapitest.so' - -export default function aceNapiEtsTest() { - describe('aceNapiEtsTest', function () { - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0100 - * @tc.name aceNapiTest001 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest001', 0, async function (done) { - console.info('aceNapiTest001 START'); - napitest.add_returned_status() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0110 - * @tc.name aceNapiTest002 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest002', 0, async function (done) { - console.info('aceNapiTest002 START'); - napitest.add_last_status() - 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'); - napitest.getLastErrorInfo() - 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'); - napitest.cleanUpErrorInfo() - 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'); - napitest.throwExistingError() - 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'); - napitest.throwError() - 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'); - napitest.throwTypeError() - 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'); - napitest.throwRangeError() - 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'); - napitest.isError() - 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'); - napitest.createError() - 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'); - napitest.createTypeError() - 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'); - napitest.createRangeError() - 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'); - napitest.getAndClearLastException() - 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'); - napitest.isExceptionPending() - 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'); - napitest.openAndCloseHandleScope() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0250 - * @tc.name aceNapiTest016 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest016', 0, async function (done) { - console.info('aceNapiTest016 START'); - napitest.openAndCloseEscapableHandleScope() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0260 - * @tc.name aceNapiTest017 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest017', 0, async function (done) { - console.info('aceNapiTest017 START'); - napitest.createReference() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0270 - * @tc.name aceNapiTest018 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest018', 0, async function (done) { - console.info('aceNapiTest018 START'); - napitest.deleteReference() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0280 - * @tc.name aceNapiTest019 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest019', 0, async function (done) { - console.info('aceNapiTest019 START'); - napitest.referenceRef() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0290 - * @tc.name aceNapiTest020 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest020', 0, async function (done) { - console.info('aceNapiTest020 START'); - napitest.referenceUnref() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0300 - * @tc.name aceNapiTest021 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest021', 0, async function (done) { - console.info('aceNapiTest021 START'); - napitest.getReferenceValue() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0310 - * @tc.name aceNapiTest022 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest022', 0, async function (done) { - console.info('aceNapiTest022 START'); - napitest.createArrayAndGetLength() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0320 - * @tc.name aceNapiTest023 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest023', 0, async function (done) { - console.info('aceNapiTest023 START'); - napitest.getArrayWithLength() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0330 - * @tc.name aceNapiTest024 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest024', 0, async function (done) { - console.info('aceNapiTest024 START'); - napitest.finalizer() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0340 - * @tc.name aceNapiTest025 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest025', 0, async function (done) { - console.info('aceNapiTest025 START'); - napitest.createExternal() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0350 - * @tc.name aceNapiTest026 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest026', 0, async function (done) { - console.info('aceNapiTest026 START'); - napitest.createExternalArraybuffer() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0360 - * @tc.name aceNapiTest027 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest027', 0, async function (done) { - console.info('aceNapiTest027 START'); - napitest.createObject() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0370 - * @tc.name aceNapiTest028 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest028', 0, async function (done) { - console.info('aceNapiTest028 START'); - napitest.createSymbol() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0380 - * @tc.name aceNapiTest029 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest029', 0, async function (done) { - console.info('aceNapiTest029 START'); - napitest.createTypeArray() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0390 - * @tc.name aceNapiTest030 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest030', 0, async function (done) { - console.info('aceNapiTest030 START'); - napitest.createDataView() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0400 - * @tc.name aceNapiTest031 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest031', 0, async function (done) { - console.info('aceNapiTest031 START'); - napitest.createAndGetInt32() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0410 - * @tc.name aceNapiTest032 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest032', 0, async function (done) { - console.info('aceNapiTest032 START'); - napitest.createAndGetUInt32() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0420 - * @tc.name aceNapiTest033 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest033', 0, async function (done) { - console.info('aceNapiTest033 START'); - napitest.createAndGetInt64() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0430 - * @tc.name aceNapiTest034 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest034', 0, async function (done) { - console.info('aceNapiTest034 START'); - napitest.createDouble() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0440 - * @tc.name aceNapiTest035 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest035', 0, async function (done) { - console.info('aceNapiTest035 START'); - napitest.createAndGetStringLatin1() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0450 - * @tc.name aceNapiTest036 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest036', 0, async function (done) { - console.info('aceNapiTest036 START'); - napitest.createAndGetStringUtf8() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0460 - * @tc.name aceNapiTest037 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest037', 0, async function (done) { - console.info('aceNapiTest037 START'); - napitest.getPrototype() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0470 - * @tc.name aceNapiTest038 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest038', 0, async function (done) { - console.info('aceNapiTest038 START'); - napitest.getTypedArrayInfo() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0480 - * @tc.name aceNapiTest039 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest039', 0, async function (done) { - console.info('aceNapiTest039 START'); - napitest.getDataViewInfo() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0490 - * @tc.name aceNapiTest040 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest040', 0, async function (done) { - console.info('aceNapiTest040 START'); - napitest.getValueBool() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0500 - * @tc.name aceNapiTest041 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest041', 0, async function (done) { - console.info('aceNapiTest041 START'); - napitest.getValueDouble() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0510 - * @tc.name aceNapiTest042 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest042', 0, async function (done) { - console.info('aceNapiTest042 START'); - napitest.getValueExternal() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0520 - * @tc.name aceNapiTest043 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest043', 0, async function (done) { - console.info('aceNapiTest043 START'); - napitest.getNull() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0530 - * @tc.name aceNapiTest044 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest044', 0, async function (done) { - console.info('aceNapiTest044 START'); - napitest.getUndefined() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0540 - * @tc.name aceNapiTest045 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest045', 0, async function (done) { - console.info('aceNapiTest045 START'); - napitest.coerceToBool() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0550 - * @tc.name aceNapiTest046 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest046', 0, async function (done) { - console.info('aceNapiTest046 START'); - napitest.coerceToNumber() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0560 - * @tc.name aceNapiTest047 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest047', 0, async function (done) { - console.info('aceNapiTest047 START'); - napitest.coerceToObject() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0570 - * @tc.name aceNapiTest048 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest048', 0, async function (done) { - console.info('aceNapiTest048 START'); - napitest.coerceToString() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0580 - * @tc.name aceNapiTest049 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest049', 0, async function (done) { - console.info('aceNapiTest049 START'); - napitest.instanceOf() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0590 - * @tc.name aceNapiTest050 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest050', 0, async function (done) { - console.info('aceNapiTest050 START'); - napitest.isArray() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0600 - * @tc.name aceNapiTest051 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest051', 0, async function (done) { - console.info('aceNapiTest051 START'); - napitest.isDate() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0610 - * @tc.name aceNapiTest052 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest052', 0, async function (done) { - console.info('aceNapiTest052 START'); - napitest.strictEquals() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0620 - * @tc.name aceNapiTest053 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest053', 0, async function (done) { - console.info('aceNapiTest053 START'); - napitest.getPropertyNames() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0630 - * @tc.name aceNapiTest054 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest054', 0, async function (done) { - console.info('aceNapiTest054 START'); - napitest.setProperty() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0640 - * @tc.name aceNapiTest055 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest055', 0, async function (done) { - console.info('aceNapiTest055 START'); - napitest.getProperty() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0650 - * @tc.name aceNapiTest056 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest056', 0, async function (done) { - console.info('aceNapiTest056 START'); - napitest.hasProperty() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0660 - * @tc.name aceNapiTest057 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest057', 0, async function (done) { - console.info('aceNapiTest057 START'); - napitest.deleteProperty() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0670 - * @tc.name aceNapiTest058 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest058', 0, async function (done) { - console.info('aceNapiTest058 START'); - napitest.hasOwnProperty() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0680 - * @tc.name aceNapiTest059 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest059', 0, async function (done) { - console.info('aceNapiTest059 START'); - napitest.setNamedProperty() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0690 - * @tc.name aceNapiTest060 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest060', 0, async function (done) { - console.info('aceNapiTest060 START'); - napitest.getNamedProperty() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0700 - * @tc.name aceNapiTest061 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest061', 0, async function (done) { - console.info('aceNapiTest061 START'); - napitest.hasNamedProperty() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0710 - * @tc.name aceNapiTest062 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest062', 0, async function (done) { - console.info('aceNapiTest062 START'); - napitest.setElement() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0720 - * @tc.name aceNapiTest063 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest063', 0, async function (done) { - console.info('aceNapiTest063 START'); - napitest.getElement() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0730 - * @tc.name aceNapiTest064 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest064', 0, async function (done) { - console.info('aceNapiTest064 START'); - napitest.hasElement() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0740 - * @tc.name aceNapiTest065 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest065', 0, async function (done) { - console.info('aceNapiTest065 START'); - napitest.deleteElement() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0750 - * @tc.name aceNapiTest066 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest066', 0, async function (done) { - console.info('aceNapiTest066 START'); - napitest.defineProperties() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0760 - * @tc.name aceNapiTest067 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest067', 0, async function (done) { - console.info('aceNapiTest067 START'); - napitest.getNewTarget() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0770 - * @tc.name aceNapiTest068 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest068', 0, async function (done) { - console.info('aceNapiTest068 START'); - napitest.wrap() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0780 - * @tc.name aceNapiTest069 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest069', 0, async function (done) { - console.info('aceNapiTest069 START'); - napitest.unwrap() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0790 - * @tc.name aceNapiTest070 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest070', 0, async function (done) { - console.info('aceNapiTest070 START'); - napitest.removeWrap() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0800 - * @tc.name aceNapiTest071 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest071', 0, async function (done) { - console.info('aceNapiTest071 START'); - napitest.getVersion() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0810 - * @tc.name aceNapiTest072 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest072', 0, async function (done) { - console.info('aceNapiTest072 START'); - napitest.createPromise() - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0820 - * @tc.name aceNapiTest073 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest073', 0, async function (done) { - console.info('aceNapiTest073 START'); - napitest.resolveAndRejectDeferred() - done(); - }); - - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0830 - * @tc.name aceNapiTest074 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest074', 0, async function (done) { - console.info('aceNapiTest074 START'); - napitest.isPromise() - done(); - }); - - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0840 - * @tc.name aceNapiTest075 - * @tc.desc aceNapiEtsTest - */ - it('aceNapiTest075', 0, async function (done) { - console.info('aceNapiTest075 START'); - napitest.runScript() - done(); - }); - }) -} \ No newline at end of file diff --git a/arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets b/arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets index 85060b7ae947e10b13e4a630f7f9fad9a3b8f495..6e462b33a8bc80e9c57327b2bbea97413aef3e45 100644 --- a/arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets +++ b/arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets @@ -1,4 +1,3 @@ -// @ts-nocheck /* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,12 +22,13 @@ 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) => { setTimeout(() => { - resolve() + resolve("ok") }, time) }).then(() => { console.info( `sleep ${time} over...`) @@ -44,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 */ @@ -57,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); - done(); - }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0500 - * @tc.name napiNewInstance - * @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(); + expect(value).assertEqual(666); done(); }); /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0600 - * @tc.name napiDefineClass + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0005 + * @tc.name napiDefineClass005 * @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) @@ -124,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) @@ -137,134 +124,1219 @@ 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) { - console.info('napiRunScriptPath START'); - value = napitest.napiRunScriptPath(); - console.info('napiRunScriptPath testString result is: ' + JSON.stringify(value)); - expect(value).assertEqual(0) - done(); + it('napiRunScriptPath007', 0, async function (done) { + console.info('napiRunScriptPath START'); + value = napitest.napiRunScriptPath(); + console.info('napiRunScriptPath testString result is: ' + JSON.stringify(value)); + expect(value).assertEqual(0) + done(); }); /** - * @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) { - console.info('napiCallThreadsafeFunction START'); - value = napitest.napiCallThreadsafeFunction(); - console.info('napiCallThreadsafeFunction testString result is: ' + JSON.stringify(value)); - expect(value).assertEqual(0) - done(); + it('napiCallThreadsafeFunction008', 0, async function (done) { + console.info('napiCallThreadsafeFunction START'); + value = napitest.napiCallThreadsafeFunction(); + console.info('napiCallThreadsafeFunction testString result is: ' + JSON.stringify(value)); + expect(value).assertEqual(0) + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0009 + * @tc.name napiCreateThreadsafeFunction009 + * @tc.desc aceNapiEtsTest + */ + it('napiCreateThreadsafeFunction009', 0, async function (done) { + console.info('napiCreateThreadsafeFunction START'); + value = napitest.napiCreateThreadsafeFunction(); + console.info('napiCreateThreadsafeFunction testString result is: ' + JSON.stringify(value)); + expect(value).assertEqual(0) + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0010 + * @tc.name napiRefthreadSafeFunction010 + * @tc.desc aceNapiEtsTest + */ + it('napiRefthreadSafeFunction010', 0, async function (done) { + console.info('napiRefthreadSafeFunction START'); + value = napitest.napiRefthreadSafeFunction(); + console.info('napiRefthreadSafeFunction testString result is: ' + JSON.stringify(value)); + expect(value).assertEqual(0) + done(); }); /** * @tc.number SUB_ACE_BASIC_ETS_NAPI_0011 - * @tc.name napiCreateThreadsafeFunction + * @tc.name napiCreateDate011 * @tc.desc aceNapiEtsTest */ - it('napiCreateThreadsafeFunction011', 0, async function (done) { - console.info('napiCreateThreadsafeFunction START'); - value = napitest.napiCreateThreadsafeFunction(); - console.info('napiCreateThreadsafeFunction testString result is: ' + JSON.stringify(value)); - expect(value).assertEqual(0) - done(); + it('napiCreateDate011', 0, async function (done) { + console.info('napiCreateDate START'); + value = napitest.napiCreateDate(); + console.info('napiCreateDate testString result is: ' + JSON.stringify(value)); + expect(value).assertEqual(1) + done(); }); /** * @tc.number SUB_ACE_BASIC_ETS_NAPI_0012 - * @tc.name napiRefthreadSafeFunction + * @tc.name napiCreateBigintUint64012 * @tc.desc aceNapiEtsTest */ - it('napiRefthreadSafeFunction012', 0, async function (done) { - console.info('napiRefthreadSafeFunction START'); - value = napitest.napiRefthreadSafeFunction(); - console.info('napiRefthreadSafeFunction testString result is: ' + JSON.stringify(value)); - expect(value).assertEqual(0) - done(); + it('napiCreateBigintUint64012', 0, async function (done) { + console.info('napiCreateBigintUint64 START'); + value = napitest.napiCreateBigintUint64(); + console.info('napiCreateBigintUint64 testString result is: ' + JSON.stringify(value)); + expect(value).assertEqual(1) + done(); }); /** * @tc.number SUB_ACE_BASIC_ETS_NAPI_0013 - * @tc.name napiCreateDate + * @tc.name napiCreateBigintInt64013 * @tc.desc aceNapiEtsTest */ - it('napiCreateDate013', 0, async function (done) { - console.info('napiCreateDate START'); - value = napitest.napiCreateDate(); - console.info('napiCreateDate testString result is: ' + JSON.stringify(value)); - expect(value).assertEqual(1) - done(); + it('napiCreateBigintInt64013', 0, async function (done) { + console.info('napiCreateBigintInt64 START'); + value = napitest.napiCreateBigintInt64(); + console.info('napiCreateBigintInt64 testString result is: ' + JSON.stringify(value)); + expect(value).assertEqual(1) + done(); }); /** * @tc.number SUB_ACE_BASIC_ETS_NAPI_0014 - * @tc.name napiCreateBigintUint64 + * @tc.name napiCreateBigintWords014 * @tc.desc aceNapiEtsTest */ - it('napiCreateBigintUint64014', 0, async function (done) { - console.info('napiCreateBigintUint64 START'); - value = napitest.napiCreateBigintUint64(); - console.info('napiCreateBigintUint64 testString result is: ' + JSON.stringify(value)); - expect(value).assertEqual(1) - 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(1) + done(); }); - /** + /** * @tc.number SUB_ACE_BASIC_ETS_NAPI_0015 - * @tc.name napiCreateBigintInt64 + * @tc.name napiGetCbInfo015 * @tc.desc aceNapiEtsTest */ - it('napiCreateBigintInt64015', 0, async function (done) { - console.info('napiCreateBigintInt64 START'); - value = napitest.napiCreateBigintInt64(); - console.info('napiCreateBigintInt64 testString result is: ' + JSON.stringify(value)); - expect(value).assertEqual(1) - done(); + it('napiGetCbInfo015', 0, async function (done) { + console.info('napiGetCbInfo015 START'); + value = napitest.napiGetCbInfo(12.06); + console.info('napiGetCbInfo015 testString result is: ' + JSON.stringify(value)); + expect(value == 12.06).assertTrue + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0016 + * @tc.name aceNapiTest016 + * @tc.desc aceNapiEtsTest + */ + 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_0017 + * @tc.name napicreateSymbol017 + * @tc.desc aceNapiEtsTest + */ + it('napicreateSymbol017', 0, async function (done) { + console.info('napicreateSymbol017 START'); + let value = napitest.createSymbol('symbol'); + console.info('napicreateSymbol017 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0018 + * @tc.name napicreateAndGetInt018 + * @tc.desc aceNapiEtsTest + */ + it('napicreateAndGetInt018', 0, async function (done) { + console.info('napicreateAndGetInt018 START'); + let value = napitest.createAndGetInt64(6); + console.info('napicreateAndGetInt018 testString result is: '+ value + "---" + JSON.stringify(value)); + expect(value).assertEqual(6); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0019 + * @tc.name aceNapiTest019 + * @tc.desc aceNapiEtsTest + */ + 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_0020 + * @tc.name napigetDataView020 + * @tc.desc aceNapiEtsTest + */ + 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_0021 + * @tc.name aceNapiTest021 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest021', 0, async function (done) { + console.info('aceNapiTest021 START'); + let value = napitest.openAndCloseHandleScope(); + console.info('aceNapiTest021 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value == undefined).assertTrue(); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0022 + * @tc.name aceNapiTest022 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest022', 0, async function (done) { + console.info('aceNapiTest022 START'); + value = napitest.openAndCloseEscapableHandleScope(); + console.info('aceNapiTest022 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof Object).assertTrue(); + done(); + }); + + /** + * @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.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_0025 + * @tc.name aceNapiTest025 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest025', 0, async function (done) { + console.info('aceNapiTest025 START'); + let value = napitest.getArrayWithLength([1,2]); + console.info('aceNapiTest025 testString result is: ' + value + "--" + JSON.stringify(value)); + obj = JSON.stringify(value); + expect(obj).assertEqual('[0,1,2,3]'); + done(); + }); + + + /** + * @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.createExternal(); + console.info('aceNapiTest026 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /** + * @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.createExternalArraybuffer(); + console.info('aceNapiTest027 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof ArrayBuffer).assertTrue(); + let view = new Int32Array(value); + expect(view[0]).assertEqual(666); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0028 + * @tc.name aceNapiTest028 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest028', 0, async function (done) { + console.info('aceNapiTest028 START'); + value = napitest.createObject(); + console.info('aceNapiTest028 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof Object).assertTrue(); + done(); + }); + + /** + * @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.createSymbol("teststr"); + console.info('aceNapiTest029 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /** + * @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.createTypeArray(); + console.info('aceNapiTest030 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof Int32Array).assertTrue(); + expect(value.length).assertEqual(4); + done(); + }); + + /** + * @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.createDataView(); + console.info('aceNapiTest031 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof DataView).assertTrue(); + value.setInt16(1, 42); + expect(value.getInt16(1)).assertEqual(42); + done(); + }); + + /** + * @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.createAndGetInt32(32); + console.info('aceNapiTest032 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(32); + done(); + }); + + /** + * @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.createAndGetUInt32(12); + console.info('aceNapiTest033 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(12); + done(); + }); + + /** + * @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.createAndGetInt64(23); + console.info('aceNapiTest034 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(23); + done(); + }); + + /** + * @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.createDouble(24.67); + console.info('aceNapiTest035 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(24.67); + done(); + }); + + /** + * @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.createAndGetStringLatin1("tst"); + console.info('aceNapiTest036 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual("tst"); + done(); + }); + + /** + * @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.createAndGetStringUtf8('he'); + console.info('aceNapiTest037 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual('he'); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0038 + * @tc.name aceNapiTest038 + * @tc.desc aceNapiEtsTest + */ + 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_0039 + * @tc.name aceNapiTest039 + * @tc.desc aceNapiEtsTest + */ + 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_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.getNull(); + console.info('aceNapiTest042 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /** + * @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.getUndefined(); + console.info('aceNapiTest043 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_00044 + * @tc.name aceNapiTest044 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest044', 0, async function (done) { + console.info('aceNapiTest044 START'); + value = napitest.coerceToBool(0); + console.info('aceNapiTest044 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertFalse(); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0045 + * @tc.name aceNapiTest045 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest045', 0, async function (done) { + console.info('aceNapiTest045 START'); + value = napitest.coerceToNumber('12'); + console.info('aceNapiTest045 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(12); + done(); + }); + + /** + * @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.coerceToObject([2,3]); + console.info('aceNapiTest046 testString result is: ' + value + "--" + JSON.stringify(value)); + let obj = JSON.stringify(value); + expect(obj).assertEqual('[2,3]'); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0047 + * @tc.name aceNapiTest047 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest047', 0, async function (done) { + console.info('aceNapiTest047 START'); + value = napitest.coerceToString(123); + console.info('aceNapiTest047 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual('123'); + done(); + }); + + /** + * @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.instanceOf(); + console.info('aceNapiTest048 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertTrue(); + done(); + }); + + /** + * @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.isArray(); + console.info('aceNapiTest049 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /* @tc.number SUB_ACE_BASIC_ETS_NAPI_0050 + * @tc.name aceNapiTest050 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest050', 0, async function (done) { + console.info('aceNapiTest050 START'); + 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).assertTrue(); + done(); + }); + + /** + * @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.strictEquals(); + console.info('aceNapiTest051 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /** + * @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.getPropertyNames(); + console.info('aceNapiTest052 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /** + * @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.setProperty(); + console.info('aceNapiTest053 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof Object).assertTrue(); + done(); + }); + + /** + * @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.getProperty(); + console.info('aceNapiTest054 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof Object).assertTrue(); + done(); + }); + + /** + * @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.hasProperty(); + console.info('aceNapiTest055 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /** + * @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 testObj = { + 'a':1, + 'b':2 + } + value = napitest.setAndDeleteProperty(testObj, 'a'); + console.info('aceNapiTest056 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value === 0).assertTrue(); + done(); + }); + + /** + * @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 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_0016 - * @tc.name napiCreateBigintWords + * @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.setNamedProperty([1,2], "e", false); + console.info('aceNapiTest058 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertTrue(); + done(); + }); + + /** + * @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 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).assertEqual('bar'); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0060 + * @tc.name aceNapiTest060 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest060', 0, async function (done) { + console.info('aceNapiTest060 START'); + let obj = { + foo: "bar", + age: 42, + baz: { myProp: 12 }, + }; + let value = napitest.hasNamedProperty(obj, "foo"); + console.info('aceNapiTest060 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertTrue(); + done(); + }); + + /** + * @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 value = napitest.setElement(); + console.info('aceNapiTest061 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof Object).assertTrue(); + done(); + }); + + /** + * @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.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_0063 + * @tc.name aceNapiTest063 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest063', 0, async function (done) { + console.info('aceNapiTest063 START'); + let value = napitest.hasElement(); + console.info('aceNapiTest063 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof Object).assertTrue(); + done(); + }); + + /** + * @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.deleteElement(); + console.info('aceNapiTest064 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof Object).assertTrue(); + done(); + }); + + /** + * @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.defineProperties(); + console.info('aceNapiTest065 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value instanceof Object).assertTrue(); + done(); + }); + + /** + * @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.wrap(); + console.info('aceNapiTest066 testString result is: ' + value + "--" + JSON.stringify(value)); + 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_0068 + * @tc.name aceNapiTest068 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest068', 0, async function (done) { + console.info('aceNapiTest068 START'); + 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_0069 + * @tc.name aceNapiTest069 + * @tc.desc aceNapiEtsTest + */ + it('aceNapiTest069', 0, async function (done) { + console.info('aceNapiTest069 START'); + let value = napitest.getVersion(); + console.info('aceNapiTest069 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(2147483647 ); + done(); + }); + + /** + * @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.createPromise(); + console.info('aceNapiTest070 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + /** + * @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.resolveAndRejectDeferred(); + console.info('aceNapiTest071 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + + /** + * @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.isPromise(); + console.info('aceNapiTest072 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value).assertEqual(0); + done(); + }); + + + /** + * @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.runScript("25"); + console.info('aceNapiTest073 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value == undefined).assertTrue(); + done(); + }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0074 + * @tc.name aceNapiTest074 * @tc.desc aceNapiEtsTest */ - it('napiCreateBigintWords016', 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(); + it('aceNapiTest074', 0, async function (done) { + console.info('aceNapiTest074 START'); + function testFunc() { + return 666; + } + value = napitest.callFunction(testFunc); + console.info('aceNapiTest074 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value === 666).assertTrue(); + done(); }); /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0017 - * @tc.name napiFatalerror + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0075 + * @tc.name aceNapiTest075 * @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) - done(); + it('aceNapiTest075', 0, async function (done) { + console.info('aceNapiTest075 START'); + value = napitest.getUvEventLoop(); + console.info('aceNapiTest075 testString result is: ' + value + "--" + JSON.stringify(value)); + expect(value === undefined).assertTrue(); + done(); }); - - /** - * @tc.number SUB_ACE_BASIC_ETS_NAPI_0018 - * @tc.name napiGetTypedarrayInfo + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0076 + * @tc.name aceNapiTest076 * @tc.desc aceNapiEtsTest */ - it('napiGetTypedarrayInfo018', 0, async function (done) { - console.info('napiFatalerror START'); - value = napitest.napiGetTypedarrayInfo(); - console.info('napiGetTypedarrayInfo testString result is: ' + JSON.stringify(value)); - expect(value).assertEqual(0) - done(); + 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 resolve1 result is: ' + result + "--" + JSON.stringify(result)); + expect(result > 0).assertTrue(); + done(); + }, (result) =>{ + console.info('aceNapiTest079 testString reject1 result is: ' + result + "--" + JSON.stringify(result)); + expect(result < 0).assertTrue(); + done(); + } + ); + value = napitest.testPromise(-1).then( + (result)=>{ + console.info('aceNapiTest079 testString resolve2 result is: ' + result + "--" + JSON.stringify(result)); + expect(result > 0).assertTrue(); + done(); + }, (result) =>{ + console.info('aceNapiTest079 testString reject2 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(); + }); }) }