From ed0d133d836e2b6cec935b357369f2e95f089a7e Mon Sep 17 00:00:00 2001 From: lisitao Date: Tue, 4 Jun 2024 03:41:26 +0000 Subject: [PATCH] [NDK] add native node napi tdd Signed-off-by:lisitaolisitao3@huawei.com Signed-off-by: lisitao Change-Id: Ie1e747574b02f312120e6ea6561468d795943202 --- test/unittest/interfaces/BUILD.gn | 40 ++++++++++++++ .../interfaces/native_node_napi_test.cpp | 55 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 test/unittest/interfaces/native_node_napi_test.cpp diff --git a/test/unittest/interfaces/BUILD.gn b/test/unittest/interfaces/BUILD.gn index ff670f71cee..22e14fb98dd 100644 --- a/test/unittest/interfaces/BUILD.gn +++ b/test/unittest/interfaces/BUILD.gn @@ -315,6 +315,45 @@ ohos_unittest("navigation_controller_test") { ] } +ohos_unittest("native_node_napi_test") { + module_out_path = interface_test_output_path + + sources = [ + "$ace_root/adapter/ohos/osal/log_wrapper.cpp", + "$ace_root/interfaces/native/node/native_node_napi.cpp", + "$ace_root/test/mock/adapter/mock_log_wrapper.cpp", + "native_node_napi_test.cpp", + ] + + configs = [ "$ace_root/test/unittest:ace_unittest_config" ] + + include_dirs = [ + "$ace_root/frameworks/core/interfaces/arkoala", + "$ace_root/frameworks/", + "$ace_root/interfaces/native/", + "$ace_root/interfaces/native/node", + "$ace_root", + "$ace_root/interfaces/inner_api/drawable_descriptor", + ] + + deps = [ "//third_party/googletest:gmock_main" ] + + public_deps = [ + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "hilog:libhilog", + "image_framework:image", + "image_framework:image_native", + "napi:ace_napi", + "resource_management:global_resmgr", + ] +} + group("interfaces_unittest") { testonly = true deps = [ @@ -323,6 +362,7 @@ group("interfaces_unittest") { ":extension_custom_node_test_ng", ":form_render_group_test", ":form_render_test", + ":native_node_napi_test", ":navigation_controller_test", ":ui_content_test", ":ui_event_test", diff --git a/test/unittest/interfaces/native_node_napi_test.cpp b/test/unittest/interfaces/native_node_napi_test.cpp new file mode 100644 index 00000000000..f8e6cd86e2f --- /dev/null +++ b/test/unittest/interfaces/native_node_napi_test.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "native_node_napi.h" + +using namespace testing; +using namespace testing::ext; + +class NativeNodeNapiTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; +}; + +/** + * @tc.name: NativeNodeNapiTest001 + * @tc.desc: Test OH_ArkUI_GetContextFromNapiValue function. + * @tc.type: FUNC + */ +HWTEST_F(NativeNodeNapiTest, NativeNodeNapiTest001, TestSize.Level1) +{ + napi_env__* env = nullptr; + napi_value__* value = nullptr; + ArkUI_ContextHandle* context = nullptr; + int32_t code = OH_ArkUI_GetContextFromNapiValue(env, value, context); + EXPECT_EQ(code, 401); +} + + +/** + * @tc.name: NativeNodeNapiTest002 + * @tc.desc: Test OH_ArkUI_GetNodeContentFromNapiValue function. + * @tc.type: FUNC + */ +HWTEST_F(NativeNodeNapiTest, NativeNodeNapiTest002, TestSize.Level1) +{ + napi_env__* env = nullptr; + napi_value__* value = nullptr; + ArkUI_NodeContentHandle* context = nullptr; + int32_t code = OH_ArkUI_GetNodeContentFromNapiValue(env, value, context); + EXPECT_EQ(code, 401); +} \ No newline at end of file