diff options
| author | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2021-02-03 12:01:28 -0800 |
|---|---|---|
| committer | Rich Trott <rtrott@gmail.com> | 2021-02-06 05:03:38 -0800 |
| commit | 4b7f23f8689966c50c7b985537a57cf4d8a72fef (patch) | |
| tree | e478712fe1b8b3f3b483a567b21c74aec0efd599 /test/node-api/test_buffer/test_buffer.c | |
| parent | 2ff1c835180906836b9101cc12eb32f8fa45f4d8 (diff) | |
| download | node-new-4b7f23f8689966c50c7b985537a57cf4d8a72fef.tar.gz | |
test: rename n-api to node-api
This renames the macros used in the tests from `NAPI_*` to
`NODE_API_*`.
PR-URL: https://github.com/nodejs/node/pull/37217
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/node-api/test_buffer/test_buffer.c')
| -rw-r--r-- | test/node-api/test_buffer/test_buffer.c | 101 |
1 files changed, 45 insertions, 56 deletions
diff --git a/test/node-api/test_buffer/test_buffer.c b/test/node-api/test_buffer/test_buffer.c index 15d7c46e97..abe2162646 100644 --- a/test/node-api/test_buffer/test_buffer.c +++ b/test/node-api/test_buffer/test_buffer.c @@ -8,14 +8,16 @@ static const char theText[] = static int deleterCallCount = 0; static void deleteTheText(napi_env env, void* data, void* finalize_hint) { - NAPI_ASSERT_RETURN_VOID(env, data != NULL && strcmp(data, theText) == 0, "invalid data"); + NODE_API_ASSERT_RETURN_VOID( + env, data != NULL && strcmp(data, theText) == 0, "invalid data"); (void)finalize_hint; free(data); deleterCallCount++; } static void noopDeleter(napi_env env, void* data, void* finalize_hint) { - NAPI_ASSERT_RETURN_VOID(env, data != NULL && strcmp(data, theText) == 0, "invalid data"); + NODE_API_ASSERT_RETURN_VOID( + env, data != NULL && strcmp(data, theText) == 0, "invalid data"); (void)finalize_hint; deleterCallCount++; } @@ -25,13 +27,10 @@ static napi_value newBuffer(napi_env env, napi_callback_info info) { char* theCopy; const unsigned int kBufferSize = sizeof(theText); - NAPI_CALL(env, - napi_create_buffer( - env, - sizeof(theText), - (void**)(&theCopy), - &theBuffer)); - NAPI_ASSERT(env, theCopy, "Failed to copy static text for newBuffer"); + NODE_API_CALL(env, + napi_create_buffer( + env, sizeof(theText), (void**)(&theCopy), &theBuffer)); + NODE_API_ASSERT(env, theCopy, "Failed to copy static text for newBuffer"); memcpy(theCopy, theText, kBufferSize); return theBuffer; @@ -40,28 +39,25 @@ static napi_value newBuffer(napi_env env, napi_callback_info info) { static napi_value newExternalBuffer(napi_env env, napi_callback_info info) { napi_value theBuffer; char* theCopy = strdup(theText); - NAPI_ASSERT(env, theCopy, "Failed to copy static text for newExternalBuffer"); - NAPI_CALL(env, - napi_create_external_buffer( - env, - sizeof(theText), - theCopy, - deleteTheText, - NULL, // finalize_hint - &theBuffer)); + NODE_API_ASSERT( + env, theCopy, "Failed to copy static text for newExternalBuffer"); + NODE_API_CALL(env, + napi_create_external_buffer( + env, sizeof(theText), theCopy, deleteTheText, + NULL /* finalize_hint */, &theBuffer)); return theBuffer; } static napi_value getDeleterCallCount(napi_env env, napi_callback_info info) { napi_value callCount; - NAPI_CALL(env, napi_create_int32(env, deleterCallCount, &callCount)); + NODE_API_CALL(env, napi_create_int32(env, deleterCallCount, &callCount)); return callCount; } static napi_value copyBuffer(napi_env env, napi_callback_info info) { napi_value theBuffer; - NAPI_CALL(env, napi_create_buffer_copy( + NODE_API_CALL(env, napi_create_buffer_copy( env, sizeof(theText), theText, NULL, &theBuffer)); return theBuffer; } @@ -69,38 +65,34 @@ static napi_value copyBuffer(napi_env env, napi_callback_info info) { static napi_value bufferHasInstance(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"); + NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); + NODE_API_ASSERT(env, argc == 1, "Wrong number of arguments"); napi_value theBuffer = args[0]; bool hasInstance; napi_valuetype theType; - NAPI_CALL(env, napi_typeof(env, theBuffer, &theType)); - NAPI_ASSERT(env, - theType == napi_object, - "bufferHasInstance: instance is not an object"); - NAPI_CALL(env, napi_is_buffer(env, theBuffer, &hasInstance)); - NAPI_ASSERT(env, hasInstance, "bufferHasInstance: instance is not a buffer"); + NODE_API_CALL(env, napi_typeof(env, theBuffer, &theType)); + NODE_API_ASSERT(env, + theType == napi_object, "bufferHasInstance: instance is not an object"); + NODE_API_CALL(env, napi_is_buffer(env, theBuffer, &hasInstance)); + NODE_API_ASSERT(env, hasInstance, "bufferHasInstance: instance is not a buffer"); napi_value returnValue; - NAPI_CALL(env, napi_get_boolean(env, hasInstance, &returnValue)); + NODE_API_CALL(env, napi_get_boolean(env, hasInstance, &returnValue)); return returnValue; } static napi_value bufferInfo(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"); + NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); + NODE_API_ASSERT(env, argc == 1, "Wrong number of arguments"); napi_value theBuffer = args[0]; char *bufferData; napi_value returnValue; size_t bufferLength; - NAPI_CALL(env, - napi_get_buffer_info( - env, - theBuffer, - (void**)(&bufferData), - &bufferLength)); - NAPI_CALL(env, napi_get_boolean(env, + NODE_API_CALL(env, + napi_get_buffer_info( + env, theBuffer, (void**)(&bufferData), &bufferLength)); + NODE_API_CALL(env, napi_get_boolean(env, !strcmp(bufferData, theText) && bufferLength == sizeof(theText), &returnValue)); return returnValue; @@ -108,35 +100,32 @@ static napi_value bufferInfo(napi_env env, napi_callback_info info) { static napi_value staticBuffer(napi_env env, napi_callback_info info) { napi_value theBuffer; - NAPI_CALL( - env, - napi_create_external_buffer(env, - sizeof(theText), - (void*)theText, - noopDeleter, - NULL, // finalize_hint - &theBuffer)); + NODE_API_CALL(env, + napi_create_external_buffer( + env, sizeof(theText), (void*)theText, noopDeleter, + NULL /* finalize_hint */, &theBuffer)); return theBuffer; } static napi_value Init(napi_env env, napi_value exports) { napi_value theValue; - NAPI_CALL(env, + NODE_API_CALL(env, napi_create_string_utf8(env, theText, sizeof(theText), &theValue)); - NAPI_CALL(env, napi_set_named_property(env, exports, "theText", theValue)); + NODE_API_CALL(env, + napi_set_named_property(env, exports, "theText", theValue)); napi_property_descriptor methods[] = { - DECLARE_NAPI_PROPERTY("newBuffer", newBuffer), - DECLARE_NAPI_PROPERTY("newExternalBuffer", newExternalBuffer), - DECLARE_NAPI_PROPERTY("getDeleterCallCount", getDeleterCallCount), - DECLARE_NAPI_PROPERTY("copyBuffer", copyBuffer), - DECLARE_NAPI_PROPERTY("bufferHasInstance", bufferHasInstance), - DECLARE_NAPI_PROPERTY("bufferInfo", bufferInfo), - DECLARE_NAPI_PROPERTY("staticBuffer", staticBuffer), + DECLARE_NODE_API_PROPERTY("newBuffer", newBuffer), + DECLARE_NODE_API_PROPERTY("newExternalBuffer", newExternalBuffer), + DECLARE_NODE_API_PROPERTY("getDeleterCallCount", getDeleterCallCount), + DECLARE_NODE_API_PROPERTY("copyBuffer", copyBuffer), + DECLARE_NODE_API_PROPERTY("bufferHasInstance", bufferHasInstance), + DECLARE_NODE_API_PROPERTY("bufferInfo", bufferInfo), + DECLARE_NODE_API_PROPERTY("staticBuffer", staticBuffer), }; - NAPI_CALL(env, napi_define_properties( + NODE_API_CALL(env, napi_define_properties( env, exports, sizeof(methods) / sizeof(methods[0]), methods)); return exports; |
