From 67e0372e2a475d07dde58409d35a1b7326941903 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Fri, 12 May 2017 17:26:38 -0400 Subject: [PATCH] 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 Reviewed-By: Anna Henningsen Reviewed-By: Jason Ginchereau --- test/addons-napi/test_globals/binding.gyp | 8 ++++++ test/addons-napi/test_globals/test.js | 8 ++++++ test/addons-napi/test_globals/test_globals.c | 26 ++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 test/addons-napi/test_globals/binding.gyp create mode 100644 test/addons-napi/test_globals/test.js create mode 100644 test/addons-napi/test_globals/test_globals.c diff --git a/test/addons-napi/test_globals/binding.gyp b/test/addons-napi/test_globals/binding.gyp new file mode 100644 index 00000000000000..0160dc72e18017 --- /dev/null +++ b/test/addons-napi/test_globals/binding.gyp @@ -0,0 +1,8 @@ +{ + "targets": [ + { + "target_name": "test_globals", + "sources": [ "test_globals.c" ] + } + ] +} diff --git a/test/addons-napi/test_globals/test.js b/test/addons-napi/test_globals/test.js new file mode 100644 index 00000000000000..a6e5f722cb9379 --- /dev/null +++ b/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); diff --git a/test/addons-napi/test_globals/test_globals.c b/test/addons-napi/test_globals/test_globals.c new file mode 100644 index 00000000000000..709e42a2e0e6c8 --- /dev/null +++ b/test/addons-napi/test_globals/test_globals.c @@ -0,0 +1,26 @@ +#include +#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)