|
| 1 | +#include <js_native_api.h> |
| 2 | + |
| 3 | +#include "../common.h" |
| 4 | +#include "test_null.h" |
| 5 | + |
| 6 | +#define DECLARE_TEST(charset, str_arg) \ |
| 7 | + static napi_value \ |
| 8 | + test_create_##charset(napi_env env, napi_callback_info info) { \ |
| 9 | + napi_value return_value, result; \ |
| 10 | + NODE_API_CALL(env, napi_create_object(env, &return_value)); \ |
| 11 | + \ |
| 12 | + add_returned_status(env, \ |
| 13 | + "envIsNull", \ |
| 14 | + return_value, \ |
| 15 | + "Invalid argument", \ |
| 16 | + napi_invalid_arg, \ |
| 17 | + napi_create_string_##charset(NULL, \ |
| 18 | + (str_arg), \ |
| 19 | + NAPI_AUTO_LENGTH, \ |
| 20 | + &result)); \ |
| 21 | + \ |
| 22 | + napi_create_string_##charset(env, NULL, NAPI_AUTO_LENGTH, &result); \ |
| 23 | + add_last_status(env, "stringIsNullNonZeroLength", return_value); \ |
| 24 | + \ |
| 25 | + napi_create_string_##charset(env, NULL, 0, &result); \ |
| 26 | + add_last_status(env, "stringIsNullZeroLength", return_value); \ |
| 27 | + \ |
| 28 | + napi_create_string_##charset(env, (str_arg), NAPI_AUTO_LENGTH, NULL); \ |
| 29 | + add_last_status(env, "resultIsNull", return_value); \ |
| 30 | + \ |
| 31 | + return return_value; \ |
| 32 | + } |
| 33 | + |
| 34 | +static const char16_t something[] = { |
| 35 | + (char16_t)'s', |
| 36 | + (char16_t)'o', |
| 37 | + (char16_t)'m', |
| 38 | + (char16_t)'e', |
| 39 | + (char16_t)'t', |
| 40 | + (char16_t)'h', |
| 41 | + (char16_t)'i', |
| 42 | + (char16_t)'n', |
| 43 | + (char16_t)'g', |
| 44 | + (char16_t)'\0' |
| 45 | +}; |
| 46 | + |
| 47 | +DECLARE_TEST(utf8, "something") |
| 48 | +DECLARE_TEST(latin1, "something") |
| 49 | +DECLARE_TEST(utf16, something) |
| 50 | + |
| 51 | +void init_test_null(napi_env env, napi_value exports) { |
| 52 | + napi_value test_null; |
| 53 | + |
| 54 | + const napi_property_descriptor test_null_props[] = { |
| 55 | + DECLARE_NODE_API_PROPERTY("test_create_utf8", test_create_utf8), |
| 56 | + DECLARE_NODE_API_PROPERTY("test_create_latin1", test_create_latin1), |
| 57 | + DECLARE_NODE_API_PROPERTY("test_create_utf16", test_create_utf16), |
| 58 | + }; |
| 59 | + |
| 60 | + NODE_API_CALL_RETURN_VOID(env, napi_create_object(env, &test_null)); |
| 61 | + NODE_API_CALL_RETURN_VOID(env, napi_define_properties( |
| 62 | + env, test_null, sizeof(test_null_props) / sizeof(*test_null_props), |
| 63 | + test_null_props)); |
| 64 | + |
| 65 | + const napi_property_descriptor test_null_set = { |
| 66 | + "testNull", NULL, NULL, NULL, NULL, test_null, napi_enumerable, NULL |
| 67 | + }; |
| 68 | + |
| 69 | + NODE_API_CALL_RETURN_VOID(env, |
| 70 | + napi_define_properties(env, exports, 1, &test_null_set)); |
| 71 | +} |
0 commit comments