diff --git a/common/utils/include/ipublisher_listener.h b/common/utils/include/ipublisher_listener.h index 7c0ddca454c2b6c173c99c7f7a7ee8e6bf377bdd..151260e27ecd2cb68b2b963f91108d4f49a6e3a8 100644 --- a/common/utils/include/ipublisher_listener.h +++ b/common/utils/include/ipublisher_listener.h @@ -38,8 +38,10 @@ enum class DHTopic : uint32_t { TOPIC_LOW_LATENCY = 5, // Topic init DHMS is ready TOPIC_INIT_DHMS_READY = 6, + // Topic for physical input devices plugin event + TOPIC_PHY_DEV_PLUGIN = 7, // Topic max border, not use for real topic - TOPIC_MAX = 7 + TOPIC_MAX = 8 }; class IPublisherListener : public IRemoteBroker { diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp index b14ab52179f1c2eafaba251524026588356870d9..fe50486f7dbde9b41d9b0f90aa0e206fc8a905cf 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp @@ -22,6 +22,7 @@ #include "dh_context.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "publisher.h" namespace OHOS { namespace DistributedHardware { @@ -44,6 +45,7 @@ void PluginListenerImpl::PluginHardware(const std::string &dhId, const std::stri capabilityInfos.push_back(dhCapabilityInfo); CapabilityInfoManager::GetInstance()->AddCapability(capabilityInfos); + Publisher::GetInstance().PublishMessage(DHTopic::TOPIC_PHY_DEV_PLUGIN, dhId); DHLOGI("plugin end, dhId: %s", GetAnonyString(dhId).c_str()); } diff --git a/services/distributedhardwarefwkservice/src/publisher/publisher.cpp b/services/distributedhardwarefwkservice/src/publisher/publisher.cpp index 3524459b602ff4af5d5a65ea710d4efda3608f26..9f8bbfbbf7d0acf45156709e9e0f7d86c8447cae 100644 --- a/services/distributedhardwarefwkservice/src/publisher/publisher.cpp +++ b/services/distributedhardwarefwkservice/src/publisher/publisher.cpp @@ -26,6 +26,7 @@ Publisher::Publisher() : publisherItems_({ { DHTopic::TOPIC_DEV_OFFLINE, std::make_shared(DHTopic::TOPIC_DEV_OFFLINE) }, { DHTopic::TOPIC_LOW_LATENCY, std::make_shared(DHTopic::TOPIC_LOW_LATENCY) }, { DHTopic::TOPIC_INIT_DHMS_READY, std::make_shared(DHTopic::TOPIC_INIT_DHMS_READY) }, + { DHTopic::TOPIC_PHY_DEV_PLUGIN, std::make_shared(DHTopic::TOPIC_PHY_DEV_PLUGIN) } }) { } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn index 8b36932d49adb9f0b822704c675ac341fccdd377..afc1fb71e12344cbc573d0bcb548bd2c0ed27b80 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn @@ -45,13 +45,18 @@ ohos_unittest("ComponentManagerTest") { sources = [ "src/component_manager_test.cpp" ] + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Dprivate=public", + ] + configs = [ ":module_private_config" ] deps = [ "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", "${utils_path}:distributedhardwareutils", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] external_deps = [ diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/component_manager_test.h b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/component_manager_test.h index 2caeca7abad2c417faeb7a686aa5aabb7b17314f..6b85f502c60a7cb76c480dac0ba9a6f654a7e8cc 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/component_manager_test.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/component_manager_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -26,8 +26,6 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); - int32_t Enable(int32_t timeout, int32_t status); - int32_t Disable(int32_t timeout, int32_t status); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_sink.h b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_sink.h index 64bbd5963af5c2882d4334a4602539bbfe0dc6e1..ddb1439a3089061f3d3f367f389c36ef77f1962f 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_sink.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_sink.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -18,8 +18,6 @@ #include -#include "gmock/gmock.h" - #include "idistributed_hardware_sink.h" namespace OHOS { @@ -27,9 +25,14 @@ namespace DistributedHardware { class MockIDistributedHardwareSink : public IDistributedHardwareSink { public: virtual ~MockIDistributedHardwareSink() {} - MOCK_METHOD1(InitSink, int32_t(const std::string ¶ms)); - MOCK_METHOD0(ReleaseSink, int32_t()); - + int32_t InitSink(const std::string ¶ms) + { + return 0; + } + int32_t ReleaseSink() + { + return 0; + } int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶meter) { return 0; diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_source.h b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_source.h index 1d6cb662cbf59c7f30fc97fbb063d9d0e956f484..59c0cc8ab53c414f2169e8b2c5aafd8c25b68898 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_source.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_idistributed_hardware_source.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -18,21 +18,30 @@ #include -#include "gmock/gmock.h" - #include "idistributed_hardware_source.h" namespace OHOS { namespace DistributedHardware { class MockIDistributedHardwareSource : public IDistributedHardwareSource { public: virtual ~MockIDistributedHardwareSource() {} - MOCK_METHOD1(InitSource, int32_t(const std::string ¶ms)); - MOCK_METHOD0(ReleaseSource, int32_t()); - MOCK_METHOD4(RegisterDistributedHardware, int32_t(const std::string &uuid, const std::string &dhId, - const EnableParam ¶meters, std::shared_ptr callback)); - MOCK_METHOD3(UnregisterDistributedHardware, - int32_t(const std::string &uuid, const std::string &dhId, std::shared_ptr callback)); - + int32_t InitSource(const std::string ¶ms) + { + return 0; + } + int32_t ReleaseSource() + { + return 0; + } + int32_t RegisterDistributedHardware(const std::string &uuid, const std::string &dhId, + const EnableParam ¶meters, std::shared_ptr callback) + { + return 0; + } + int32_t UnregisterDistributedHardware(const std::string &uuid, const std::string &dhId, + std::shared_ptr callback) + { + return 0; + } int32_t ConfigDistributedHardware(const std::string &uuid, const std::string &dhId, const std::string &key, const std::string &value) { diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_softbus_bus_center.h b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_softbus_bus_center.h new file mode 100644 index 0000000000000000000000000000000000000000..0d802f4f9fc1a965b5a3f924cb6b458a73d06c0a --- /dev/null +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/include/mock_softbus_bus_center.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 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 SOFTBUS_BUS_CENTER_MOCK_H +#define SOFTBUS_BUS_CENTER_MOCK_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif +constexpr uint32_t MOCK_NETWORK_ID_BUF_LEN = 65; +constexpr uint32_t MOCK_DEVICE_NAME_BUF_LEN = 65; +constexpr int32_t DH_FWK_SUCCESS = 0; +/** + * @brief Defines the basic information about a device. + * @since 1.0 + * @version 1.0 + */ +typedef struct { + char networkId[MOCK_NETWORK_ID_BUF_LEN]; + char deviceName[MOCK_DEVICE_NAME_BUF_LEN]; + uint16_t deviceTypeId; +} NodeBasicInfo; + +int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info) +{ + NodeBasicInfo nodeBasicInfo = { + .networkId = "nt36a637105409e904d4da83790a4a8", + .deviceName = "distributed_camera", + .deviceTypeId = 1}; + (void)pkgName; + *info = nodeBasicInfo; + return DH_FWK_SUCCESS; +} +#ifdef __cplusplus +} +#endif +#endif // SOFTBUS_BUS_CENTER_MOCK_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp index bbf1db6c9515605a67a1e7ccaa6b6e6a2903a85e..de2f4f9d3eed94aaa28393918ed76673c529c22d 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -22,17 +22,13 @@ #include #include -#include - #include "accesstoken_kit.h" #include "component_disable.h" #include "component_enable.h" #include "component_loader.h" #include "capability_info.h" #include "capability_info_manager.h" -#define private public #include "component_manager.h" -#undef private #include "constants.h" #include "dh_context.h" #include "dh_utils_tool.h" @@ -42,7 +38,7 @@ #include "mock_idistributed_hardware_source.h" #include "nativetoken_kit.h" #include "softbus_common.h" -#include "softbus_bus_center.h" +#include "mock_softbus_bus_center.h" #include "token_setproc.h" #include "version_info_manager.h" #include "version_manager.h" @@ -55,7 +51,6 @@ namespace DistributedHardware { #define DH_LOG_TAG "ComponentManagerTest" namespace { -constexpr int32_t EXECUTE_TIME_TEST = 1000; constexpr uint16_t TEST_DEV_TYPE_PAD = 0x11; const std::string DATABASE_DIR = "/data/service/el1/public/database/dtbhardware_manager_service/"; const std::string NAME_CAMERA = "distributed_camera"; @@ -68,6 +63,12 @@ const std::string DH_ATTR_1 = "attr1"; const std::string DEVICE_NAME = "Dev1"; const std::string DH_ID_1 = "Camera_1"; const std::string DH_SUBTYPE_TEST = "camera"; +const std::string TEST_SOURCE_VERSION_1 = "2.2"; +const std::string TEST_SINK_VERSION_1 = "2.4"; +const std::string TEST_DH_VERSION = "3.1"; +const std::shared_ptr CAP_INFO_TEST = + std::make_shared(DH_ID_TEST, DEV_ID_TEST, DEVICE_NAME, TEST_DEV_TYPE_PAD, DHType::CAMERA, DH_ATTR_1, + DH_SUBTYPE_TEST); } void ComponentManagerTest::SetUpTestCase(void) @@ -115,59 +116,6 @@ void ComponentManagerTest::TearDown() ComponentManager::GetInstance().compSink_.clear(); } -int32_t ComponentManagerTest::Enable(int32_t timeout, int32_t status) -{ - MockIDistributedHardwareSource stub; - auto compEnable = std::make_shared(); - EnableParam parameters; - std::future future; - auto handler = [&future, timeout, status, compEnable](std::string uuid, std::string dhId, - const EnableParam ¶meters, std::shared_ptr callback) { - future = std::async(std::launch::async, [timeout, compEnable, uuid, dhId, status]() { - std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); - return compEnable->OnRegisterResult(uuid, dhId, status, ""); - }); - return DH_FWK_SUCCESS; - }; - - EXPECT_CALL(stub, RegisterDistributedHardware(DEV_ID_TEST, DH_ID_TEST, testing::_, testing::_)) - .Times(1) - .WillOnce(testing::Invoke(handler)); - - auto start = std::chrono::system_clock::now(); - auto ret = compEnable->Enable(DEV_ID_TEST, DH_ID_TEST, parameters, &stub); - auto diff = std::chrono::duration_cast(std::chrono::system_clock::now() - start).count(); - DHLOGI("enable callback use time: %d (ms)", diff); - return ret; -} - -int32_t ComponentManagerTest::Disable(int32_t timeout, int32_t status) -{ - MockIDistributedHardwareSource stub; - auto compDisable = std::make_shared(); - - std::future future; - auto handler = [&future, timeout, status, compDisable](std::string uuid, std::string dhId, - std::shared_ptr callback) { - future = std::async(std::launch::async, [timeout, compDisable, uuid, dhId, status]() { - std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); - return compDisable->OnUnregisterResult(uuid, dhId, status, ""); - }); - return DH_FWK_SUCCESS; - }; - - EXPECT_CALL(stub, UnregisterDistributedHardware(DEV_ID_TEST, DH_ID_TEST, testing::_)) - .Times(1) - .WillOnce(testing::Invoke(handler)); - - auto start = std::chrono::system_clock::now(); - - auto ret = compDisable->Disable(DEV_ID_TEST, DH_ID_TEST, &stub); - auto diff = std::chrono::duration_cast(std::chrono::system_clock::now() - start).count(); - DHLOGI("disable callback use time: %d (ms)", diff); - return ret; -} - /** * @tc.name: init_test_001 * @tc.desc: Verify the Init function @@ -195,41 +143,6 @@ HWTEST_F(ComponentManagerTest, init_test_002, TestSize.Level0) EXPECT_EQ(ERR_DH_FWK_COMPONENT_INIT_SINK_FAILED, ret); } -/** - * @tc.name: init_test_003 - * @tc.desc: Verify the Init function - * @tc.type: FUNC - * @tc.require: AR000GHSK5 - */ -HWTEST_F(ComponentManagerTest, init_test_003, TestSize.Level0) -{ - auto handler = [](std::string param) { - std::this_thread::sleep_for(std::chrono::milliseconds(EXECUTE_TIME_TEST)); - return DH_FWK_SUCCESS; - }; - - MockIDistributedHardwareSource cameraSource; - ComponentManager::GetInstance().compSource_.insert(std::make_pair(DHType::CAMERA, &cameraSource)); - EXPECT_CALL(cameraSource, InitSource(testing::_)).Times(1).WillOnce(testing::Invoke(handler)); - - MockIDistributedHardwareSource displaySource; - ComponentManager::GetInstance().compSource_.insert(std::make_pair(DHType::SCREEN, &displaySource)); - EXPECT_CALL(displaySource, InitSource(testing::_)).Times(1).WillOnce(testing::Invoke(handler)); - - MockIDistributedHardwareSink micSink; - ComponentManager::GetInstance().compSink_.insert(std::make_pair(DHType::AUDIO, &micSink)); - EXPECT_CALL(micSink, InitSink(testing::_)).Times(1).WillOnce(testing::Invoke(handler)); - - auto start = std::chrono::system_clock::now(); - - auto ret = ComponentManager::GetInstance().Init(); - EXPECT_EQ(DH_FWK_SUCCESS, ret); - - auto diff = std::chrono::duration_cast(std::chrono::system_clock::now() - start).count(); - DHLOGI("Init use time: %d (ms)", diff); - ASSERT_TRUE(diff <= EXECUTE_TIME_TEST * 1.1); -} - /** * @tc.name: unInit_test_001 * @tc.desc: Verify the UnInit function @@ -238,99 +151,8 @@ HWTEST_F(ComponentManagerTest, init_test_003, TestSize.Level0) */ HWTEST_F(ComponentManagerTest, unInit_test_001, TestSize.Level0) { - auto handler = []() { - std::this_thread::sleep_for(std::chrono::milliseconds(EXECUTE_TIME_TEST)); - return DH_FWK_SUCCESS; - }; - - MockIDistributedHardwareSource cameraSource; - ComponentManager::GetInstance().compSource_.insert(std::make_pair(DHType::CAMERA, &cameraSource)); - EXPECT_CALL(cameraSource, ReleaseSource()).Times(1).WillOnce(testing::Invoke(handler)); - - MockIDistributedHardwareSink displaycSink; - ComponentManager::GetInstance().compSink_.insert(std::make_pair(DHType::SCREEN, &displaycSink)); - EXPECT_CALL(displaycSink, ReleaseSink()).Times(1).WillOnce(testing::Invoke(handler)); - - MockIDistributedHardwareSink micSink; - ComponentManager::GetInstance().compSink_.insert(std::make_pair(DHType::AUDIO, &micSink)); - EXPECT_CALL(micSink, ReleaseSink()).Times(1).WillOnce(testing::Invoke(handler)); - - auto start = std::chrono::system_clock::now(); - auto ret = ComponentManager::GetInstance().UnInit(); EXPECT_EQ(DH_FWK_SUCCESS, ret); - - auto diff = std::chrono::duration_cast(std::chrono::system_clock::now() - start).count(); - DHLOGI("UnInit use time : %d (ms)", diff); - ASSERT_TRUE(diff <= EXECUTE_TIME_TEST * 1.1); -} - -/** - * @tc.name: enable_test_001 - * @tc.desc: Verify the Enable success - * @tc.type: FUNC - * @tc.require: AR000GHSK7 - */ -HWTEST_F(ComponentManagerTest, enable_test_001, TestSize.Level0) -{ - auto result = Enable(ENABLE_TIMEOUT_MS / 2, DH_FWK_SUCCESS); - EXPECT_EQ(DH_FWK_SUCCESS, result); -} - -/** - * @tc.name: enable_test_002 - * @tc.desc: Verify the Enable failed for register hardware failed - * @tc.type: FUNC - * @tc.require: AR000GHSK7 - */ - -HWTEST_F(ComponentManagerTest, enable_test_002, TestSize.Level0) -{ - auto result = Enable(ENABLE_TIMEOUT_MS / 2, ERR_DH_FWK_COMPONENT_ENABLE_FAILED); - EXPECT_EQ(ERR_DH_FWK_COMPONENT_ENABLE_FAILED, result); -} - -/** - * @tc.name: enable_test_003 - * @tc.desc: Verify the Enable timeout - * @tc.type: FUNC - * @tc.require: AR000GHSK7 - */ -HWTEST_F(ComponentManagerTest, enable_test_003, TestSize.Level0) -{ - auto result = Enable(ENABLE_TIMEOUT_MS * 2, ERR_DH_FWK_COMPONENT_ENABLE_FAILED); - EXPECT_EQ(ERR_DH_FWK_COMPONENT_ENABLE_TIMEOUT, result); -} - -/** - * @tc.name: enable_test_004 - * @tc.desc: Verify the Enable for Multi-thread - * @tc.type: FUNC - * @tc.require: AR000GHSK7 - */ -HWTEST_F(ComponentManagerTest, enable_test_004, TestSize.Level0) -{ - auto handler = [this](int32_t time, int32_t status, int32_t expect) { - auto ret = this->Enable(time, status); - EXPECT_EQ(expect, ret); - }; - - std::thread thread1(handler, ENABLE_TIMEOUT_MS / 2, DH_FWK_SUCCESS, DH_FWK_SUCCESS); - std::thread thread2(handler, ENABLE_TIMEOUT_MS / 2, ERR_DH_FWK_COMPONENT_ENABLE_FAILED, - ERR_DH_FWK_COMPONENT_ENABLE_FAILED); - std::thread thread3(handler, ENABLE_TIMEOUT_MS * 3, DH_FWK_SUCCESS, ERR_DH_FWK_COMPONENT_ENABLE_TIMEOUT); - - std::thread thread6(handler, ENABLE_TIMEOUT_MS / 10, DH_FWK_SUCCESS, DH_FWK_SUCCESS); - std::thread thread4(handler, ENABLE_TIMEOUT_MS / 10, ERR_DH_FWK_COMPONENT_ENABLE_FAILED, - ERR_DH_FWK_COMPONENT_ENABLE_FAILED); - std::thread thread5(handler, ENABLE_TIMEOUT_MS * 2, DH_FWK_SUCCESS, ERR_DH_FWK_COMPONENT_ENABLE_TIMEOUT); - - thread1.join(); - thread2.join(); - thread3.join(); - thread4.join(); - thread5.join(); - thread6.join(); } /** @@ -349,73 +171,6 @@ HWTEST_F(ComponentManagerTest, Enable_test_005, TestSize.Level0) EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } -/** - * @tc.name: disable_test_001 - * @tc.desc: Verify the Disable success - * @tc.type: FUNC - * @tc.require: AR000GHSK9 - */ -HWTEST_F(ComponentManagerTest, disable_test_001, TestSize.Level0) -{ - auto result = Disable(DISABLE_TIMEOUT_MS / 2, DH_FWK_SUCCESS); - EXPECT_EQ(DH_FWK_SUCCESS, result); -} - -/** - * @tc.name: disable_test_002 - * @tc.desc: Verify the Disable failed - * @tc.type: FUNC - * @tc.require: AR000GHSK9 - */ -HWTEST_F(ComponentManagerTest, disable_test_002, TestSize.Level0) -{ - auto result = Disable(DISABLE_TIMEOUT_MS / 2, ERR_DH_FWK_COMPONENT_DISABLE_FAILED); - EXPECT_EQ(ERR_DH_FWK_COMPONENT_DISABLE_FAILED, result); -} - -/** - * @tc.name: disable_test_003 - * @tc.desc: Verify the Disable timeout - * @tc.type: FUNC - * @tc.require: AR000GHSK9 - */ -HWTEST_F(ComponentManagerTest, disable_test_003, TestSize.Level0) -{ - auto result = Disable(DISABLE_TIMEOUT_MS * 2, ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT); - EXPECT_EQ(ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT, result); -} - -/** - * @tc.name: disable_test_004 - * @tc.desc: Verify the Disable for Multi-thread - * @tc.type: FUNC - * @tc.require: AR000GHSK9 - */ -HWTEST_F(ComponentManagerTest, disable_test_004, TestSize.Level0) -{ - auto handler = [this](int32_t timeout, int32_t status, int32_t expect) { - auto result = this->Disable(timeout, status); - EXPECT_EQ(expect, result); - }; - - std::thread thread1(handler, DISABLE_TIMEOUT_MS / 2, DH_FWK_SUCCESS, DH_FWK_SUCCESS); - std::thread thread2(handler, DISABLE_TIMEOUT_MS / 2, ERR_DH_FWK_COMPONENT_DISABLE_FAILED, - ERR_DH_FWK_COMPONENT_DISABLE_FAILED); - std::thread thread3(handler, DISABLE_TIMEOUT_MS * 3, DH_FWK_SUCCESS, ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT); - - std::thread thread4(handler, DISABLE_TIMEOUT_MS / 10, ERR_DH_FWK_COMPONENT_DISABLE_FAILED, - ERR_DH_FWK_COMPONENT_DISABLE_FAILED); - std::thread thread6(handler, DISABLE_TIMEOUT_MS / 10, DH_FWK_SUCCESS, DH_FWK_SUCCESS); - std::thread thread5(handler, DISABLE_TIMEOUT_MS * 2, DH_FWK_SUCCESS, ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT); - - thread1.join(); - thread2.join(); - thread3.join(); - thread4.join(); - thread5.join(); - thread6.join(); -} - /** * @tc.name: disable_test_005 * @tc.desc: Verify the Disable for Multi-thread @@ -448,7 +203,7 @@ HWTEST_F(ComponentManagerTest, init_compSource_test_001, TestSize.Level0) /** * @tc.name: init_compSink_test_001 - * @tc.desc: Verify the InitCompSource + * @tc.desc: Verify the InitCompSink * @tc.type: FUNC * @tc.require: AR000GHSK9 */ @@ -502,7 +257,7 @@ HWTEST_F(ComponentManagerTest, get_enableparam_test_001, TestSize.Level0) EnableParam param; auto ret = ComponentManager::GetInstance().GetEnableParam(info->networkId, devInfo.uuid, DH_ID_1, DHType::CAMERA, param); - EXPECT_EQ(DH_FWK_SUCCESS, ret); + EXPECT_EQ(ret, ERR_DH_FWK_COMPONENT_GET_SINK_VERSION_FAILED); } /** @@ -754,6 +509,20 @@ HWTEST_F(ComponentManagerTest, GetDHType_001, TestSize.Level0) EXPECT_EQ(DHType::UNKNOWN, ret); } +/** + * @tc.name: GetDHType_002 + * @tc.desc: Verify the GetDHType function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(ComponentManagerTest, GetDHType_002, TestSize.Level0) +{ + std::string key = Sha256(UUID_TEST) + RESOURCE_SEPARATOR + DH_ID_1; + CapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = CAP_INFO_TEST; + auto ret = ComponentManager::GetInstance().GetDHType(UUID_TEST, DH_ID_1); + EXPECT_EQ(DHType::CAMERA, ret); +} + /** * @tc.name: GetEnableParam_001 * @tc.desc: Verify the GetEnableParam function @@ -771,6 +540,21 @@ HWTEST_F(ComponentManagerTest, GetEnableParam_001, TestSize.Level0) EXPECT_NE(DH_FWK_SUCCESS, ret); } +/** + * @tc.name: GetEnableParam_002 + * @tc.desc: Verify the GetEnableParam function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(ComponentManagerTest, GetEnableParam_002, TestSize.Level0) +{ + DHType dhType = DHType::CAMERA; + EnableParam param; + CapabilityInfoManager::GetInstance()->globalCapInfoMap_.clear(); + int32_t ret = ComponentManager::GetInstance().GetEnableParam(NETWORK_TEST, UUID_TEST, DH_ID_1, dhType, param); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_CAPABILITY_MAP_NOT_FOUND, ret); +} + /** * @tc.name: GetVersionFromVerMgr_001 * @tc.desc: Verify the GetVersionFromVerMgr function @@ -786,6 +570,41 @@ HWTEST_F(ComponentManagerTest, GetVersionFromVerMgr_001, TestSize.Level0) EXPECT_NE(DH_FWK_SUCCESS, ret); } +/** + * @tc.name: GetVersionFromVerMgr_002 + * @tc.desc: Verify the GetVersionFromVerMgr function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(ComponentManagerTest, GetVersionFromVerMgr_002, TestSize.Level0) +{ + DHType dhType = DHType::CAMERA; + std::string sinkVersion; + VersionManager::GetInstance().dhVersions_.clear(); + int32_t ret = ComponentManager::GetInstance().GetVersionFromVerMgr(UUID_TEST, dhType, sinkVersion, true); + EXPECT_EQ(ret, ERR_DH_FWK_VERSION_DEVICE_ID_NOT_EXIST); +} + +/** + * @tc.name: GetVersionFromVerMgr_003 + * @tc.desc: Verify the GetVersionFromVerMgr function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(ComponentManagerTest, GetVersionFromVerMgr_003, TestSize.Level0) +{ + DHType dhType = DHType::CAMERA; + DHVersion dhVersion; + std::string sinkVersion; + CompVersion cVs {NAME_CAMERA, dhType, VERSION_1, TEST_SOURCE_VERSION_1, TEST_SINK_VERSION_1}; + dhVersion.uuid = UUID_TEST; + dhVersion.dhVersion = TEST_DH_VERSION; + dhVersion.compVersions.insert(std::make_pair(cVs.dhType, cVs)); + VersionManager::GetInstance().AddDHVersion(dhVersion.uuid, dhVersion); + int32_t ret = ComponentManager::GetInstance().GetVersionFromVerMgr(UUID_TEST, dhType, sinkVersion, true); + EXPECT_EQ(ret, DH_FWK_SUCCESS); +} + /** * @tc.name: GetVersionFromVerInfoMgr_001 * @tc.desc: Verify the GetVersionFromVerInfoMgr function @@ -801,6 +620,21 @@ HWTEST_F(ComponentManagerTest, GetVersionFromVerInfoMgr_001, TestSize.Level0) EXPECT_NE(DH_FWK_SUCCESS, ret); } +/** + * @tc.name: GetVersionFromVerInfoMgr_002 + * @tc.desc: Verify the GetVersionFromVerInfoMgr function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(ComponentManagerTest, GetVersionFromVerInfoMgr_002, TestSize.Level0) +{ + DHType dhType = DHType::CAMERA; + std::string sinkVersion; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + int32_t ret = ComponentManager::GetInstance().GetVersionFromVerInfoMgr(UUID_TEST, dhType, sinkVersion, true); + EXPECT_EQ(ret, ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL); +} + /** * @tc.name: GetSinkVersion_001 * @tc.desc: Verify the GetVersion function @@ -896,5 +730,54 @@ HWTEST_F(ComponentManagerTest, RecoverDistributedHardware_001, TestSize.Level0) ComponentManager::GetInstance().RecoverDistributedHardware(dhType); EXPECT_EQ(true, ComponentManager::GetInstance().compSource_.empty()); } + +/** + * @tc.name: RetryGetEnableParam_001 + * @tc.desc: Verify the RetryGetEnableParam function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(ComponentManagerTest, RetryGetEnableParam_001, TestSize.Level0) +{ + DHType dhType = DHType::CAMERA; + EnableParam param; + DHContext::GetInstance().onlineDeviceMap_.clear(); + auto ret = ComponentManager::GetInstance().RetryGetEnableParam(NETWORK_TEST, UUID_TEST, DH_ID_1, dhType, param); + EXPECT_EQ(ret, ERR_DH_FWK_COMPONENT_ENABLE_FAILED); +} + +/** + * @tc.name: RetryGetEnableParam_002 + * @tc.desc: Verify the RetryGetEnableParam function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(ComponentManagerTest, RetryGetEnableParam_002, TestSize.Level0) +{ + DHType dhType = DHType::CAMERA; + EnableParam param; + DHContext::GetInstance().onlineDeviceMap_[UUID_TEST] = NETWORK_TEST; + auto ret = ComponentManager::GetInstance().RetryGetEnableParam(NETWORK_TEST, UUID_TEST, DH_ID_1, dhType, param); + EXPECT_EQ(ret, DH_FWK_SUCCESS); + + std::string key = Sha256(UUID_TEST); + CapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = CAP_INFO_TEST; + ret = ComponentManager::GetInstance().RetryGetEnableParam(NETWORK_TEST, UUID_TEST, DH_ID_1, dhType, param); + EXPECT_EQ(ret, DH_FWK_SUCCESS); +} + +/** + * @tc.name: IsIdenticalAccount_001 + * @tc.desc: Verify the IsIdenticalAccount function + * @tc.type: FUNC + * @tc.require: AR000GHSJM + */ +HWTEST_F(ComponentManagerTest, IsIdenticalAccount_001, TestSize.Level0) +{ + DHType dhType = DHType::CAMERA; + ComponentManager::GetInstance().RecoverDistributedHardware(dhType); + auto ret = ComponentManager::GetInstance().IsIdenticalAccount(NETWORK_TEST); + EXPECT_EQ(ret, false); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/BUILD.gn b/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/BUILD.gn index 25d0f8a9cae4bec383f816b1b235d68c4d328469..2e404e1621426c909bd7494c164896d264206df6 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/BUILD.gn @@ -42,6 +42,13 @@ ohos_unittest("DbAdapterTest") { "src/mock_db_change_listener.cpp", ] + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Dprivate=public", + ] + configs = [ ":module_private_config" ] deps = [ diff --git a/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp index 4f5d46250e5140c6c1c189a9ebdb45e188757764..8fbf84c7bc96f2bfbbd01e03e9b4212adff0a704 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/dbadapter/src/db_adapter_test.cpp @@ -21,14 +21,14 @@ #include #include "capability_info.h" +#include "capability_info_manager.h" #include "constants.h" -#define private public #include "db_adapter.h" -#undef private #include "dh_context.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" #include "mock_db_change_listener.h" +#include "version_info_manager.h" using namespace testing::ext; using namespace std; @@ -435,9 +435,11 @@ HWTEST_F(DbAdapterTest, RemoveManualSyncCount_001, TestSize.Level0) */ HWTEST_F(DbAdapterTest, SyncDBForRecover_001, TestSize.Level0) { + CapabilityInfoManager::GetInstance()->Init(); g_dbAdapterPtr->storeId_.storeId = GLOBAL_CAPABILITY_ID; g_dbAdapterPtr->SyncDBForRecover(); EXPECT_EQ(true, g_dbAdapterPtr->manualSyncCountMap_.empty()); + CapabilityInfoManager::GetInstance()->UnInit(); } /** @@ -448,9 +450,11 @@ HWTEST_F(DbAdapterTest, SyncDBForRecover_001, TestSize.Level0) */ HWTEST_F(DbAdapterTest, SyncDBForRecover_002, TestSize.Level0) { + VersionInfoManager::GetInstance()->Init(); g_dbAdapterPtr->storeId_.storeId = GLOBAL_VERSION_ID; g_dbAdapterPtr->SyncDBForRecover(); EXPECT_EQ(true, g_dbAdapterPtr->manualSyncCountMap_.empty()); + VersionInfoManager::GetInstance()->UnInit(); } /** diff --git a/services/distributedhardwarefwkservice/test/unittest/common/ipc/src/publisher_listener_proxy_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/ipc/src/publisher_listener_proxy_test.cpp index efda36b6a446f4fdc6b5e04cfac10232b4487abb..f8005e6f3f77853472d6101b0da982bfe480e025 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/ipc/src/publisher_listener_proxy_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/ipc/src/publisher_listener_proxy_test.cpp @@ -46,7 +46,7 @@ void PublisherListenerProxyTest::TearDown() */ HWTEST_F(PublisherListenerProxyTest, OnMessage_001, TestSize.Level0) { - uint32_t invalid = 7; + uint32_t invalid = 8; DHTopic topic = static_cast(invalid); std::string message; proxy_->OnMessage(topic, message);