11cb0ef41Sopenharmony_ci#include <js_native_api.h>
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci#include "../common.h"
41cb0ef41Sopenharmony_ci#include "test_null.h"
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cistatic int some_data = 0;
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cistatic napi_value TestConstructor(napi_env env, napi_callback_info info) {
91cb0ef41Sopenharmony_ci  return NULL;
101cb0ef41Sopenharmony_ci}
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cistatic napi_value TestDefineClass(napi_env env, napi_callback_info info) {
131cb0ef41Sopenharmony_ci  napi_value return_value, cons;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  const napi_property_descriptor prop =
161cb0ef41Sopenharmony_ci      DECLARE_NODE_API_PROPERTY("testConstructor", TestConstructor);
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  NODE_API_CALL(env, napi_create_object(env, &return_value));
191cb0ef41Sopenharmony_ci  add_returned_status(env,
201cb0ef41Sopenharmony_ci                      "envIsNull",
211cb0ef41Sopenharmony_ci                      return_value,
221cb0ef41Sopenharmony_ci                      "Invalid argument",
231cb0ef41Sopenharmony_ci                      napi_invalid_arg,
241cb0ef41Sopenharmony_ci                      napi_define_class(NULL,
251cb0ef41Sopenharmony_ci                                        "TestClass",
261cb0ef41Sopenharmony_ci                                        NAPI_AUTO_LENGTH,
271cb0ef41Sopenharmony_ci                                        TestConstructor,
281cb0ef41Sopenharmony_ci                                        &some_data,
291cb0ef41Sopenharmony_ci                                        1,
301cb0ef41Sopenharmony_ci                                        &prop,
311cb0ef41Sopenharmony_ci                                        &cons));
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  napi_define_class(env,
341cb0ef41Sopenharmony_ci                    NULL,
351cb0ef41Sopenharmony_ci                    NAPI_AUTO_LENGTH,
361cb0ef41Sopenharmony_ci                    TestConstructor,
371cb0ef41Sopenharmony_ci                    &some_data,
381cb0ef41Sopenharmony_ci                    1,
391cb0ef41Sopenharmony_ci                    &prop,
401cb0ef41Sopenharmony_ci                    &cons);
411cb0ef41Sopenharmony_ci  add_last_status(env, "nameIsNull", return_value);
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  napi_define_class(
441cb0ef41Sopenharmony_ci      env, "TestClass", 0, TestConstructor, &some_data, 1, &prop, &cons);
451cb0ef41Sopenharmony_ci  add_last_status(env, "lengthIsZero", return_value);
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  napi_define_class(
481cb0ef41Sopenharmony_ci      env, "TestClass", NAPI_AUTO_LENGTH, NULL, &some_data, 1, &prop, &cons);
491cb0ef41Sopenharmony_ci  add_last_status(env, "nativeSideIsNull", return_value);
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  napi_define_class(env,
521cb0ef41Sopenharmony_ci                    "TestClass",
531cb0ef41Sopenharmony_ci                    NAPI_AUTO_LENGTH,
541cb0ef41Sopenharmony_ci                    TestConstructor,
551cb0ef41Sopenharmony_ci                    NULL,
561cb0ef41Sopenharmony_ci                    1,
571cb0ef41Sopenharmony_ci                    &prop,
581cb0ef41Sopenharmony_ci                    &cons);
591cb0ef41Sopenharmony_ci  add_last_status(env, "dataIsNull", return_value);
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci  napi_define_class(env,
621cb0ef41Sopenharmony_ci                    "TestClass",
631cb0ef41Sopenharmony_ci                    NAPI_AUTO_LENGTH,
641cb0ef41Sopenharmony_ci                    TestConstructor,
651cb0ef41Sopenharmony_ci                    &some_data,
661cb0ef41Sopenharmony_ci                    0,
671cb0ef41Sopenharmony_ci                    &prop,
681cb0ef41Sopenharmony_ci                    &cons);
691cb0ef41Sopenharmony_ci  add_last_status(env, "propsLengthIsZero", return_value);
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci  napi_define_class(env,
721cb0ef41Sopenharmony_ci                    "TestClass",
731cb0ef41Sopenharmony_ci                    NAPI_AUTO_LENGTH,
741cb0ef41Sopenharmony_ci                    TestConstructor,
751cb0ef41Sopenharmony_ci                    &some_data,
761cb0ef41Sopenharmony_ci                    1,
771cb0ef41Sopenharmony_ci                    NULL,
781cb0ef41Sopenharmony_ci                    &cons);
791cb0ef41Sopenharmony_ci  add_last_status(env, "propsIsNull", return_value);
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci  napi_define_class(env,
821cb0ef41Sopenharmony_ci                    "TestClass",
831cb0ef41Sopenharmony_ci                    NAPI_AUTO_LENGTH,
841cb0ef41Sopenharmony_ci                    TestConstructor,
851cb0ef41Sopenharmony_ci                    &some_data,
861cb0ef41Sopenharmony_ci                    1,
871cb0ef41Sopenharmony_ci                    &prop,
881cb0ef41Sopenharmony_ci                    NULL);
891cb0ef41Sopenharmony_ci  add_last_status(env, "resultIsNull", return_value);
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci  return return_value;
921cb0ef41Sopenharmony_ci}
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_civoid init_test_null(napi_env env, napi_value exports) {
951cb0ef41Sopenharmony_ci  napi_value test_null;
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci  const napi_property_descriptor test_null_props[] = {
981cb0ef41Sopenharmony_ci      DECLARE_NODE_API_PROPERTY("testDefineClass", TestDefineClass),
991cb0ef41Sopenharmony_ci  };
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ci  NODE_API_CALL_RETURN_VOID(env, napi_create_object(env, &test_null));
1021cb0ef41Sopenharmony_ci  NODE_API_CALL_RETURN_VOID(
1031cb0ef41Sopenharmony_ci      env,
1041cb0ef41Sopenharmony_ci      napi_define_properties(env,
1051cb0ef41Sopenharmony_ci                             test_null,
1061cb0ef41Sopenharmony_ci                             sizeof(test_null_props) / sizeof(*test_null_props),
1071cb0ef41Sopenharmony_ci                             test_null_props));
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ci  NODE_API_CALL_RETURN_VOID(
1101cb0ef41Sopenharmony_ci      env, napi_set_named_property(env, exports, "testNull", test_null));
1111cb0ef41Sopenharmony_ci}
112