Browse Source

test: improve N-API test coverage

Add tests to cover functions that return globals

PR-URL: https://github.com/nodejs/node/pull/13006
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
v6
Michael Dawson 8 years ago
parent
commit
47c3c58704
  1. 8
      test/addons-napi/test_globals/binding.gyp
  2. 8
      test/addons-napi/test_globals/test.js
  3. 26
      test/addons-napi/test_globals/test_globals.c

8
test/addons-napi/test_globals/binding.gyp

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "test_globals",
"sources": [ "test_globals.c" ]
}
]
}

8
test/addons-napi/test_globals/test.js

@ -0,0 +1,8 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const test_globals = require(`./build/${common.buildType}/test_globals`);
assert.strictEqual(test_globals.getUndefined(), undefined);
assert.strictEqual(test_globals.getNull(), null);

26
test/addons-napi/test_globals/test_globals.c

@ -0,0 +1,26 @@
#include <node_api.h>
#include "../common.h"
napi_value getNull(napi_env env, napi_callback_info info) {
napi_value result;
NAPI_CALL(env, napi_get_null(env, &result));
return result;
}
napi_value getUndefined(napi_env env, napi_callback_info info) {
napi_value result;
NAPI_CALL(env, napi_get_undefined(env, &result));
return result;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("getUndefined", getUndefined),
DECLARE_NAPI_PROPERTY("getNull", getNull),
};
NAPI_CALL_RETURN_VOID(env, napi_define_properties(
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors));
}
NAPI_MODULE(addon, Init)
Loading…
Cancel
Save