From 616730d992e2730aca23edb5ba0f1de63d0901bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=A3=AB=E8=BE=B0?= Date: Tue, 10 Jun 2025 15:41:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?add=20tdd=20Signed-off-by:=20=E9=A9=AC?= =?UTF-8?q?=E5=A3=AB=E8=BE=B0=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bundle.json | 3 + test/BUILD.gn | 20 + test/unittest/napi/BUILD.gn | 76 +++ test/unittest/napi/napi/native_api.h | 55 +++ test/unittest/napi/napi/native_node_api.h | 19 + .../napi/napi_event_subscribe_module_test.cpp | 443 ++++++++++++++++++ test/unittest/napi/nv.h | 19 + 7 files changed, 635 insertions(+) create mode 100644 test/BUILD.gn create mode 100644 test/unittest/napi/BUILD.gn create mode 100644 test/unittest/napi/napi/native_api.h create mode 100644 test/unittest/napi/napi/native_node_api.h create mode 100644 test/unittest/napi/napi_event_subscribe_module_test.cpp create mode 100644 test/unittest/napi/nv.h diff --git a/bundle.json b/bundle.json index c52eef0a..1a1b3552 100644 --- a/bundle.json +++ b/bundle.json @@ -272,6 +272,9 @@ }, "name": "//foundation/communication/bluetooth/frameworks/js/napi/src/common:bt_napi_common" } + ], + "test": [ + "//foundation/communication/bluetooth/test:unit_test" ] } } diff --git a/test/BUILD.gn b/test/BUILD.gn new file mode 100644 index 00000000..00c39c84 --- /dev/null +++ b/test/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (C) 2025 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. + +import("//foundation/communication/bluetooth/bluetooth.gni") +group("unit_test") { + testonly = true + deps = [ + "unittest/napi:unittest", + ] +} \ No newline at end of file diff --git a/test/unittest/napi/BUILD.gn b/test/unittest/napi/BUILD.gn new file mode 100644 index 00000000..fbc53f89 --- /dev/null +++ b/test/unittest/napi/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (C) 2025 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. + +import("//build/test.gni") +import("//foundation/communication/bluetooth/bluetooth.gni") + +module_output_path = "bluetooth/bluetooth" +FRAMWORK_DIR = "//foundation/communication/bluetooth" + +config("module_private_config") { + cflags = [ + "-Werror", + "-Wno-macro-redefined", + "-Wno-non-c-typedef-for-linkage", + "-Wno-unused-const-variable", + "-Wno-deprecated-builtins", + "-Wno-defaulted-function-deleted", + "-Woverloaded-virtual", + ] + include_dirs = [ + ".", + "$FRAMWORK_DIR/frameworks/inner/include", + "$FRAMWORK_DIR/frameworks/js/napi/include", + "$FRAMWORK_DIR/interfaces/inner_api/include", + "$FRAMWORK_DIR/interfaces/inner_api/include/c_header", + ] + defines = [ + "BTFW_LOG_TAG = \"bluetooth_test\"", + "BTFW_LOG_DOMAIN = 0xD005300", + "private = public", + "protected = public", + ] +} + +ohos_unittest("bluetooth_napi_event_subscribe_module_test") { + module_out_path = module_output_path + + sources = [ + "$FRAMWORK_DIR/frameworks/js/napi/src/common/napi_event_subscribe_module.cpp", + "napi_event_subscribe_module_test.cpp", + ] + + configs = [ + ":module_private_config", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "googletest:gmock_main", + "googletest:gtest_main", + ] +} + +################################################################################ +group("unittest") { + testonly = true + + deps = [] + + if (is_phone_product) { + deps += [ + ":bluetooth_napi_event_subscribe_module_test", + ] + } +} \ No newline at end of file diff --git a/test/unittest/napi/napi/native_api.h b/test/unittest/napi/napi/native_api.h new file mode 100644 index 00000000..65bc3d6e --- /dev/null +++ b/test/unittest/napi/napi/native_api.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2025 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. + */ + +#ifndef NAPI_NATIVE_API_H +#define NAPI_NATIVE_API_H + +struct napi_env {}; +using napi_value = void *; +enum napi_status { + napi_ok = 0, + napi_invalid_arg, +}; +struct napi_async_work {}; +struct napi_deferred {}; +using napi_ref = int; +struct uv_work_t { + void *data; +}; +struct napi_callback_info {}; +using napi_handle_scope = void *; +typedef enum { + napi_undefined, + napi_null, +} napi_valuetype; + +napi_status napi_create_reference(napi_env env, napi_value value, uint32_t initial_refcount, napi_ref* result); +napi_status napi_get_reference_value(napi_env env, napi_ref ref, napi_value* result); +napi_status napi_call_function(napi_env env, napi_value recv, napi_value func, size_t argc, + const napi_value* argv, napi_value* result); +napi_status napi_is_exception_pending(napi_env env, bool* result); +napi_status napi_delete_reference(napi_env env, napi_ref ref); +napi_status napi_get_and_clear_last_exception(napi_env env, napi_value* result); +napi_status napi_strict_equals(napi_env env, napi_value lhs, napi_value rhs, bool* result); +napi_status napi_create_promise(napi_env env, napi_deferred* deferred, napi_value* promise); +napi_status napi_resolve_deferred(napi_env env, napi_deferred deferred, napi_value resolution); +napi_status napi_reject_deferred(napi_env env, napi_deferred deferred, napi_value rejection); +napi_status napi_open_handle_scope(napi_env env, napi_handle_scope* result); +napi_status napi_get_cb_info(napi_env env, napi_callback_info cbinfo, size_t* argc, napi_value* argv, + napi_value* this_arg, void** data); +napi_status napi_close_handle_scope(napi_env env, napi_handle_scope scope); + +using napi_threadsafe_function = void *; +#endif // NAPI_NATIVE_API_H \ No newline at end of file diff --git a/test/unittest/napi/napi/native_node_api.h b/test/unittest/napi/napi/native_node_api.h new file mode 100644 index 00000000..9cdd1c25 --- /dev/null +++ b/test/unittest/napi/napi/native_node_api.h @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2025 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. + */ + +#ifndef NATIVE_NODE_API_H +#define NATIVE_NODE_API_H + +#endif // NATIVE_NODE_API_H \ No newline at end of file diff --git a/test/unittest/napi/napi_event_subscribe_module_test.cpp b/test/unittest/napi/napi_event_subscribe_module_test.cpp new file mode 100644 index 00000000..5b6bff84 --- /dev/null +++ b/test/unittest/napi/napi_event_subscribe_module_test.cpp @@ -0,0 +1,443 @@ +/* + * Copyright (C) 2025 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 +#include + +#include "bluetooth_log.h" +#include "napi_event_subscribe_module.h" + +using namespace testing; +using namespace testing::ext; + +static size_t g_napiGetCbInfoArgc = 0; +void NapiGetCbInfoMockSetArgc(size_t argc) +{ + g_napiGetCbInfoArgc = argc; +} +napi_status napi_get_cb_info(napi_env env, napi_callback_info cbinfo, size_t* argc, napi_value* argv, + napi_value* this_arg, void** data) +{ + *argc = g_napiGetCbInfoArgc; + return napi_ok; +} +napi_status napi_close_handle_scope(napi_env env, napi_handle_scope scope) +{ + return napi_ok; +} + +namespace OHOS { +namespace Bluetooth { +void NapiMockClear(void); + +class NapiEventSubscribeModuleTest : public testing::Test { +public: + NapiEventSubscribeModuleTest() = default; + ~NapiEventSubscribeModuleTest() = default; + + static void SetUpTestSuite(void) {} + static void TearDownTestSuite(void) {} + void SetUp() + { + NapiMockClear(); + } + void TearDown() {} + + napi_env env_; + napi_callback_info info_; +}; + +static std::string g_napiParseStringStr = ""; +static bool g_napiParseStringIsString = false; + +void NapiParseStringMock(std::string str, bool isString) +{ + g_napiParseStringStr = str; + g_napiParseStringIsString = isString; +} + +napi_status NapiParseString(napi_env env, napi_value value, std::string &outStr) +{ + outStr = g_napiParseStringStr; + return g_napiParseStringIsString ? napi_ok : napi_invalid_arg; +} + +static bool g_napiIsFunction = false; + +napi_status NapiIsFunctionMock(bool isFunction) +{ + g_napiIsFunction = isFunction; + return napi_ok; +} + +napi_status NapiIsFunction(napi_env env, napi_value value) +{ + return g_napiIsFunction ? napi_ok : napi_invalid_arg; +} + +NapiCallback::NapiCallback(napi_env env, napi_value callback) {} +NapiCallback::~NapiCallback() {} + +static int g_napiCallFunctionCount = 0; +void NapiCallback::CallFunction(const std::shared_ptr &object) +{ + g_napiCallFunctionCount++; +} +void NapiCallback::CallFunction(int errCode, const std::shared_ptr &object) {} +napi_env NapiCallback::GetNapiEnv(void) +{ + return env_; +} +std::string NapiCallback::ToLogString(void) const +{ + return ""; +} + +static bool g_napiCallbackIsEqual = false; +void NapiCallbackIsEqualMock(bool equal) +{ + g_napiCallbackIsEqual = equal; +} +bool NapiCallback::Equal(napi_env env, napi_value &callback) const +{ + return g_napiCallbackIsEqual; +} + +int DoInJsMainThread(std::function func) +{ + func(); + return 0; +} + +int DoInJsMainThread(napi_env env, std::function func) +{ + func(); + return 0; +} + +void NapiMockClear(void) +{ + g_napiGetCbInfoArgc = 0; + g_napiParseStringStr = ""; + g_napiParseStringIsString = false; + g_napiIsFunction = false; + g_napiCallbackIsEqual = false; + g_napiCallFunctionCount = 0; +} + +static const char * const TEST_CALLBACK_NAME = "testCallback"; + +/** + * @tc.name: NapiEventSubscribeModuleTest_001 + * @tc.desc: Test register and deregister normal + * @tc.type: FUNC + */ +HWTEST_F(NapiEventSubscribeModuleTest, NapiEventSubscribeModuleTest_001, TestSize.Level0) +{ + HILOGI("NapiEventSubscribeModuleTest_001 enter"); + NapiEventSubscribeModule subscribe(TEST_CALLBACK_NAME, "testModule"); + + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + + NapiIsFunctionMock(true); + NapiCallbackIsEqualMock(false); + + napi_status ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 1); + + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + + NapiIsFunctionMock(true); + NapiCallbackIsEqualMock(true); + + ret = subscribe.Deregister(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 0); + + HILOGI("NapiEventSubscribeModuleTest_001 end"); +} + +/** + * @tc.name: NapiEventSubscribeModuleTest_002 + * @tc.desc: Test register the type callback, and the same callback Repeated + * @tc.type: FUNC + */ +HWTEST_F(NapiEventSubscribeModuleTest, NapiEventSubscribeModuleTest_002, TestSize.Level0) +{ + HILOGI("NapiEventSubscribeModuleTest_002 enter"); + NapiEventSubscribeModule subscribe(TEST_CALLBACK_NAME, "testModule"); + + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + + NapiIsFunctionMock(true); + NapiCallbackIsEqualMock(false); + + napi_status ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 1); + + // Mock the same callback + NapiCallbackIsEqualMock(true); + ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 1); + + HILOGI("NapiEventSubscribeModuleTest_002 end"); +} + +/** + * @tc.name: NapiEventSubscribeModuleTest_003 + * @tc.desc: Test register the type callback, and multi callback + * @tc.type: FUNC + */ +HWTEST_F(NapiEventSubscribeModuleTest, NapiEventSubscribeModuleTest_003, TestSize.Level0) +{ + HILOGI("NapiEventSubscribeModuleTest_003 enter"); + NapiEventSubscribeModule subscribe(TEST_CALLBACK_NAME, "testModule"); + + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + + NapiIsFunctionMock(true); + NapiCallbackIsEqualMock(false); + + napi_status ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 1); + + ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 2); + + HILOGI("NapiEventSubscribeModuleTest_003 end"); +} + +/** + * @tc.name: NapiEventSubscribeModuleTest_004 + * @tc.desc: Test publish event + * @tc.type: FUNC + */ +HWTEST_F(NapiEventSubscribeModuleTest, NapiEventSubscribeModuleTest_004, TestSize.Level0) +{ + HILOGI("NapiEventSubscribeModuleTest_004 enter"); + NapiEventSubscribeModule subscribe(TEST_CALLBACK_NAME, "testModule"); + + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + + NapiIsFunctionMock(true); + NapiCallbackIsEqualMock(false); + + napi_status ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 1); + + subscribe.PublishEvent(TEST_CALLBACK_NAME, nullptr); + EXPECT_EQ(g_napiCallFunctionCount, 1); + + HILOGI("NapiEventSubscribeModuleTest_004 end"); +} + +/** + * @tc.name: NapiEventSubscribeModuleTest_005 + * @tc.desc: Test register failed + * @tc.type: FUNC + */ +HWTEST_F(NapiEventSubscribeModuleTest, NapiEventSubscribeModuleTest_005, TestSize.Level0) +{ + HILOGI("NapiEventSubscribeModuleTest_005 enter"); + NapiEventSubscribeModule subscribe(TEST_CALLBACK_NAME, "testModule"); + + // Invalid params size + NapiGetCbInfoMockSetArgc(1); + napi_status ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_invalid_arg); + + // Invalid argv[0] string type + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, false); + ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_invalid_arg); + + // Invalid type name + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock("errCallbackName", true); + ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_invalid_arg); + + // Invalid argv[1] function type + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + NapiIsFunctionMock(false); + ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_invalid_arg); + + HILOGI("NapiEventSubscribeModuleTest_005 end"); +} + +/** + * @tc.name: NapiEventSubscribeModuleTest_006 + * @tc.desc: Test register failed + * @tc.type: FUNC + */ +HWTEST_F(NapiEventSubscribeModuleTest, NapiEventSubscribeModuleTest_006, TestSize.Level0) +{ + HILOGI("NapiEventSubscribeModuleTest_006 enter"); + NapiEventSubscribeModule subscribe(TEST_CALLBACK_NAME, "testModule"); + + // Invalid params size + NapiGetCbInfoMockSetArgc(3); + napi_status ret = subscribe.Deregister(env_, info_); + EXPECT_EQ(ret, napi_invalid_arg); + + NapiGetCbInfoMockSetArgc(0); + ret = subscribe.Deregister(env_, info_); + EXPECT_EQ(ret, napi_invalid_arg); + + // Invalid argv[0] string type + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, false); + ret = subscribe.Deregister(env_, info_); + EXPECT_EQ(ret, napi_invalid_arg); + + // Invalid type name + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock("errCallbackName", true); + ret = subscribe.Deregister(env_, info_); + EXPECT_EQ(ret, napi_invalid_arg); + + // Invalid argv[1] function type + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + NapiIsFunctionMock(false); + ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_invalid_arg); + + // The callback is not registered + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + NapiIsFunctionMock(true); + NapiCallbackIsEqualMock(true); + ret = subscribe.Deregister(env_, info_); + EXPECT_EQ(ret, napi_ok); + + HILOGI("NapiEventSubscribeModuleTest_006 end"); +} + +/** + * @tc.name: NapiEventSubscribeModuleTest_007 + * @tc.desc: Test publish event failed + * @tc.type: FUNC + */ +HWTEST_F(NapiEventSubscribeModuleTest, NapiEventSubscribeModuleTest_007, TestSize.Level0) +{ + HILOGI("NapiEventSubscribeModuleTest_007 enter"); + NapiEventSubscribeModule subscribe(TEST_CALLBACK_NAME, "testModule"); + + // Invalid eventName + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + + NapiIsFunctionMock(true); + NapiCallbackIsEqualMock(false); + + napi_status ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 1); + + subscribe.PublishEvent("errCallbackName", nullptr); + EXPECT_EQ(g_napiCallFunctionCount, 0); + + // Empty callback in map + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + + NapiIsFunctionMock(true); + NapiCallbackIsEqualMock(true); + + ret = subscribe.Deregister(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 0); + + subscribe.PublishEvent(TEST_CALLBACK_NAME, nullptr); + EXPECT_EQ(g_napiCallFunctionCount, 0); + + HILOGI("NapiEventSubscribeModuleTest_007 end"); +} + +/** + * @tc.name: NapiEventSubscribeModuleTest_008 + * @tc.desc: Test Deregister all callback + * @tc.type: FUNC + */ +HWTEST_F(NapiEventSubscribeModuleTest, NapiEventSubscribeModuleTest_008, TestSize.Level0) +{ + HILOGI("NapiEventSubscribeModuleTest_008 enter"); + NapiEventSubscribeModule subscribe(TEST_CALLBACK_NAME, "testModule"); + + NapiGetCbInfoMockSetArgc(2); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + + NapiIsFunctionMock(true); + NapiCallbackIsEqualMock(false); + + napi_status ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 1); + + ret = subscribe.Register(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 2); + + NapiGetCbInfoMockSetArgc(1); + NapiParseStringMock(TEST_CALLBACK_NAME, true); + + ret = subscribe.Deregister(env_, info_); + EXPECT_EQ(ret, napi_ok); + EXPECT_EQ(subscribe.eventSubscribeMap_.ReadVal(TEST_CALLBACK_NAME).size(), 0); + + HILOGI("NapiEventSubscribeModuleTest_008 end"); +} + +/** + * @tc.name: NapiEventSubscribeModuleTest_009 + * @tc.desc: Test publish a event with multi callback + * @tc.type: FUNC + */ +HWTEST_F(NapiEventSubscribeModuleTest, NapiEventSubscribeModuleTest_009, TestSize.Level0) +{ + HILOGI("NapiEventSubscribeModuleTest_009 enter"); + napi_env env; + napi_value callback = nullptr; + NapiEventSubscribeModule subscribe(TEST_CALLBACK_NAME, "testModule"); + + subscribe.eventSubscribeMap_.ChangeValueByLambda(TEST_CALLBACK_NAME, [env, callback](auto & callbackVec) { + auto napiCallback = std::make_shared(env, callback); + callbackVec.push_back(napiCallback); + napiCallback = std::make_shared(env, callback); + callbackVec.push_back(napiCallback); + }); + + subscribe.PublishEvent(TEST_CALLBACK_NAME, nullptr); + EXPECT_EQ(g_napiCallFunctionCount, 2); + + HILOGI("NapiEventSubscribeModuleTest_009 end"); +} +} // namespace Bluetooth +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/napi/nv.h b/test/unittest/napi/nv.h new file mode 100644 index 00000000..48526dc0 --- /dev/null +++ b/test/unittest/napi/nv.h @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2025 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. + */ + +#ifndef UV_H +#define UV_H + +#endif // UV_H \ No newline at end of file -- Gitee From ab076859ceb52a6c5d01236a809a5dd0d783d52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=A3=AB=E8=BE=B0?= Date: Sat, 28 Jun 2025 09:50:18 +0800 Subject: [PATCH 2/3] =?UTF-8?q?file=20name=20change=20Signed-off-by:=20?= =?UTF-8?q?=E9=A9=AC=E5=A3=AB=E8=BE=B0=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unittest/napi/{nv.h => uv.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/unittest/napi/{nv.h => uv.h} (100%) diff --git a/test/unittest/napi/nv.h b/test/unittest/napi/uv.h similarity index 100% rename from test/unittest/napi/nv.h rename to test/unittest/napi/uv.h -- Gitee From af3ee1ab0959ce035897b4c7f3c58c3167ef5fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=A3=AB=E8=BE=B0?= Date: Wed, 27 Aug 2025 06:27:18 +0000 Subject: [PATCH 3/3] =?UTF-8?q?update=20test/unittest/napi/BUILD.gn=20Sign?= =?UTF-8?q?ed-off-by:=20=E9=A9=AC=E5=A3=AB=E8=BE=B0=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unittest/napi/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/napi/BUILD.gn b/test/unittest/napi/BUILD.gn index fbc53f89..4a740aba 100644 --- a/test/unittest/napi/BUILD.gn +++ b/test/unittest/napi/BUILD.gn @@ -31,6 +31,7 @@ config("module_private_config") { ".", "$FRAMWORK_DIR/frameworks/inner/include", "$FRAMWORK_DIR/frameworks/js/napi/include", + "$FRAMWORK_DIR/frameworks/js/napi/src/parser", "$FRAMWORK_DIR/interfaces/inner_api/include", "$FRAMWORK_DIR/interfaces/inner_api/include/c_header", ] -- Gitee