11cb0ef41Sopenharmony_ci#include <stdio.h>
21cb0ef41Sopenharmony_ci#include <cstdio>
31cb0ef41Sopenharmony_ci#include <string>
41cb0ef41Sopenharmony_ci#include "env-inl.h"
51cb0ef41Sopenharmony_ci#include "gtest/gtest.h"
61cb0ef41Sopenharmony_ci#include "node_api_internals.h"
71cb0ef41Sopenharmony_ci#include "node_binding.h"
81cb0ef41Sopenharmony_ci#include "node_test_fixture.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciusing v8::Local;
111cb0ef41Sopenharmony_ciusing v8::Object;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cistatic napi_env addon_env;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciclass NodeApiTest : public EnvironmentTestFixture {
161cb0ef41Sopenharmony_ci private:
171cb0ef41Sopenharmony_ci  void SetUp() override { EnvironmentTestFixture::SetUp(); }
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  void TearDown() override { EnvironmentTestFixture::TearDown(); }
201cb0ef41Sopenharmony_ci};
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciTEST_F(NodeApiTest, CreateNodeApiEnv) {
231cb0ef41Sopenharmony_ci  const v8::HandleScope handle_scope(isolate_);
241cb0ef41Sopenharmony_ci  Argv argv;
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  Env test_env{handle_scope, argv};
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  node::Environment* env = *test_env;
291cb0ef41Sopenharmony_ci  node::LoadEnvironment(env, "");
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  napi_addon_register_func init = [](napi_env env, napi_value exports) {
321cb0ef41Sopenharmony_ci    addon_env = env;
331cb0ef41Sopenharmony_ci    return exports;
341cb0ef41Sopenharmony_ci  };
351cb0ef41Sopenharmony_ci  Local<Object> module_obj = Object::New(isolate_);
361cb0ef41Sopenharmony_ci  Local<Object> exports_obj = Object::New(isolate_);
371cb0ef41Sopenharmony_ci  napi_module_register_by_symbol(
381cb0ef41Sopenharmony_ci      exports_obj, module_obj, env->context(), init, NAPI_VERSION);
391cb0ef41Sopenharmony_ci  ASSERT_NE(addon_env, nullptr);
401cb0ef41Sopenharmony_ci  node_napi_env internal_env = reinterpret_cast<node_napi_env>(addon_env);
411cb0ef41Sopenharmony_ci  EXPECT_EQ(internal_env->node_env(), env);
421cb0ef41Sopenharmony_ci}
43