File: test_null.c

package info (click to toggle)
nodejs 22.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 246,928 kB
  • sloc: cpp: 1,582,349; javascript: 582,017; ansic: 82,400; python: 60,561; sh: 4,009; makefile: 2,263; asm: 1,732; pascal: 1,565; perl: 248; lisp: 222; xml: 42
file content (71 lines) | stat: -rw-r--r-- 3,178 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <js_native_api.h>

#include "../common.h"
#include "test_null.h"

#define DECLARE_TEST(charset, str_arg)                                    \
  static napi_value                                                       \
  test_create_##charset(napi_env env, napi_callback_info info) {          \
    napi_value return_value, result;                                      \
    NODE_API_CALL(env, napi_create_object(env, &return_value));           \
                                                                          \
    add_returned_status(env,                                              \
                        "envIsNull",                                      \
                        return_value,                                     \
                        "Invalid argument",                               \
                        napi_invalid_arg,                                 \
                        napi_create_string_##charset(NULL,                \
                                                     (str_arg),           \
                                                     NAPI_AUTO_LENGTH,    \
                                                     &result));           \
                                                                          \
    napi_create_string_##charset(env, NULL, NAPI_AUTO_LENGTH, &result);   \
    add_last_status(env, "stringIsNullNonZeroLength", return_value);      \
                                                                          \
    napi_create_string_##charset(env, NULL, 0, &result);                  \
    add_last_status(env, "stringIsNullZeroLength", return_value);         \
                                                                          \
    napi_create_string_##charset(env, (str_arg), NAPI_AUTO_LENGTH, NULL); \
    add_last_status(env, "resultIsNull", return_value);                   \
                                                                          \
    return return_value;                                                  \
  }

static const char16_t something[] = {
  (char16_t)'s',
  (char16_t)'o',
  (char16_t)'m',
  (char16_t)'e',
  (char16_t)'t',
  (char16_t)'h',
  (char16_t)'i',
  (char16_t)'n',
  (char16_t)'g',
  (char16_t)'\0'
};

DECLARE_TEST(utf8, "something")
DECLARE_TEST(latin1, "something")
DECLARE_TEST(utf16, something)

void init_test_null(napi_env env, napi_value exports) {
  napi_value test_null;

  const napi_property_descriptor test_null_props[] = {
    DECLARE_NODE_API_PROPERTY("test_create_utf8", test_create_utf8),
    DECLARE_NODE_API_PROPERTY("test_create_latin1", test_create_latin1),
    DECLARE_NODE_API_PROPERTY("test_create_utf16", test_create_utf16),
  };

  NODE_API_CALL_RETURN_VOID(env, napi_create_object(env, &test_null));
  NODE_API_CALL_RETURN_VOID(env, napi_define_properties(
      env, test_null, sizeof(test_null_props) / sizeof(*test_null_props),
      test_null_props));

  const napi_property_descriptor test_null_set = {
    "testNull", NULL, NULL, NULL, NULL, test_null, napi_enumerable, NULL
  };

  NODE_API_CALL_RETURN_VOID(env,
      napi_define_properties(env, exports, 1, &test_null_set));
}