n-api: refactoring napi_create_function testing
This is a refactoring of https://github.com/nodejs/node/pull/26998 following https://github.com/nodejs/node/pull/28505. The functions `add_last_status()` and `add_returned_status()` are now reused, see also https://github.com/nodejs/node/pull/28848. PR-URL: https://github.com/nodejs/node/pull/28894 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
8492acfd57
commit
1ee47d550c
@ -3,6 +3,7 @@
|
|||||||
{
|
{
|
||||||
"target_name": "test_function",
|
"target_name": "test_function",
|
||||||
"sources": [
|
"sources": [
|
||||||
|
"../common.c",
|
||||||
"../entry_point.c",
|
"../entry_point.c",
|
||||||
"test_function.c"
|
"test_function.c"
|
||||||
]
|
]
|
||||||
|
@ -37,8 +37,8 @@ tracked_function = null;
|
|||||||
global.gc();
|
global.gc();
|
||||||
|
|
||||||
assert.deepStrictEqual(test_function.TestCreateFunctionParameters(), {
|
assert.deepStrictEqual(test_function.TestCreateFunctionParameters(), {
|
||||||
envIsNull: 'pass',
|
envIsNull: 'Invalid argument',
|
||||||
nameIsNull: 'pass',
|
nameIsNull: 'napi_ok',
|
||||||
cbIsNull: 'pass',
|
cbIsNull: 'Invalid argument',
|
||||||
resultIsNull: 'pass'
|
resultIsNull: 'Invalid argument'
|
||||||
});
|
});
|
||||||
|
@ -3,79 +3,51 @@
|
|||||||
|
|
||||||
static napi_value TestCreateFunctionParameters(napi_env env,
|
static napi_value TestCreateFunctionParameters(napi_env env,
|
||||||
napi_callback_info info) {
|
napi_callback_info info) {
|
||||||
napi_status ret[4];
|
napi_status status;
|
||||||
napi_value result, return_value, prop_value;
|
napi_value result, return_value;
|
||||||
|
|
||||||
|
|
||||||
ret[0] = napi_create_function(NULL,
|
|
||||||
"TrackedFunction",
|
|
||||||
NAPI_AUTO_LENGTH,
|
|
||||||
TestCreateFunctionParameters,
|
|
||||||
NULL,
|
|
||||||
&result);
|
|
||||||
|
|
||||||
ret[1] = napi_create_function(env,
|
|
||||||
NULL,
|
|
||||||
NAPI_AUTO_LENGTH,
|
|
||||||
TestCreateFunctionParameters,
|
|
||||||
NULL,
|
|
||||||
&result);
|
|
||||||
|
|
||||||
ret[2] = napi_create_function(env,
|
|
||||||
"TrackedFunction",
|
|
||||||
NAPI_AUTO_LENGTH,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
&result);
|
|
||||||
|
|
||||||
ret[3] = napi_create_function(env,
|
|
||||||
"TrackedFunction",
|
|
||||||
NAPI_AUTO_LENGTH,
|
|
||||||
TestCreateFunctionParameters,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
NAPI_CALL(env, napi_create_object(env, &return_value));
|
NAPI_CALL(env, napi_create_object(env, &return_value));
|
||||||
|
|
||||||
NAPI_CALL(env, napi_create_string_utf8(env,
|
status = napi_create_function(NULL,
|
||||||
(ret[0] == napi_invalid_arg ?
|
"TrackedFunction",
|
||||||
"pass" : "fail"),
|
NAPI_AUTO_LENGTH,
|
||||||
NAPI_AUTO_LENGTH,
|
TestCreateFunctionParameters,
|
||||||
&prop_value));
|
NULL,
|
||||||
NAPI_CALL(env, napi_set_named_property(env,
|
&result);
|
||||||
return_value,
|
|
||||||
"envIsNull",
|
|
||||||
prop_value));
|
|
||||||
|
|
||||||
NAPI_CALL(env, napi_create_string_utf8(env,
|
add_returned_status(env,
|
||||||
(ret[1] == napi_ok ?
|
"envIsNull",
|
||||||
"pass" : "fail"),
|
return_value,
|
||||||
NAPI_AUTO_LENGTH,
|
"Invalid argument",
|
||||||
&prop_value));
|
napi_invalid_arg,
|
||||||
NAPI_CALL(env, napi_set_named_property(env,
|
status);
|
||||||
return_value,
|
|
||||||
"nameIsNull",
|
|
||||||
prop_value));
|
|
||||||
|
|
||||||
NAPI_CALL(env, napi_create_string_utf8(env,
|
napi_create_function(env,
|
||||||
(ret[2] == napi_invalid_arg ?
|
NULL,
|
||||||
"pass" : "fail"),
|
NAPI_AUTO_LENGTH,
|
||||||
NAPI_AUTO_LENGTH,
|
TestCreateFunctionParameters,
|
||||||
&prop_value));
|
NULL,
|
||||||
NAPI_CALL(env, napi_set_named_property(env,
|
&result);
|
||||||
return_value,
|
|
||||||
"cbIsNull",
|
|
||||||
prop_value));
|
|
||||||
|
|
||||||
NAPI_CALL(env, napi_create_string_utf8(env,
|
add_last_status(env, "nameIsNull", return_value);
|
||||||
(ret[3] == napi_invalid_arg ?
|
|
||||||
"pass" : "fail"),
|
napi_create_function(env,
|
||||||
NAPI_AUTO_LENGTH,
|
"TrackedFunction",
|
||||||
&prop_value));
|
NAPI_AUTO_LENGTH,
|
||||||
NAPI_CALL(env, napi_set_named_property(env,
|
NULL,
|
||||||
return_value,
|
NULL,
|
||||||
"resultIsNull",
|
&result);
|
||||||
prop_value));
|
|
||||||
|
add_last_status(env, "cbIsNull", return_value);
|
||||||
|
|
||||||
|
napi_create_function(env,
|
||||||
|
"TrackedFunction",
|
||||||
|
NAPI_AUTO_LENGTH,
|
||||||
|
TestCreateFunctionParameters,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
add_last_status(env, "resultIsNull", return_value);
|
||||||
|
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user