From 9a80ee65c2bf7f0a78e2c14ecbfd7f9c4a62d72f Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Sat, 28 Jun 2025 15:00:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=B1=E8=B4=A5UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- .../component_manager/BUILD.gn | 7 ++ .../src/component_manager_test.cpp | 1 + .../src/component_manager_test_ext.cpp | 3 - .../common/transport/dh_transport_test.cpp | 64 +++++++++++++++++++ .../utils/dh_modem_context_ext_test.cpp | 8 --- 5 files changed, 72 insertions(+), 11 deletions(-) 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 d6fe8df2..5c8f76ca 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/BUILD.gn @@ -33,6 +33,9 @@ config("module_private_config") { "${services_path}/distributedhardwarefwkservice/include/utils", "${services_path}/distributedhardwarefwkservice/include/task", "${services_path}/distributedhardwarefwkservice/include/transport", + "${services_path}/distributedhardwarefwkservice/include/publisher", + "${services_path}/distributedhardwarefwkservice/include/hidumphelper", + "${services_path}/distributedhardwarefwkservice/include/hdfoperate", "${common_path}/utils/include", "${common_path}/log/include", ] @@ -99,6 +102,7 @@ ohos_unittest("ComponentManagerTestExt") { "src/mock_dh_utils_tool.cpp", "src/mock_meta_info_manager.cpp", "src/mock_version_manager.cpp", + "${services_path}/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp", ] cflags = [ @@ -124,9 +128,12 @@ ohos_unittest("ComponentManagerTestExt") { "device_manager:devicemanagersdk", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "ffrt:libffrt", "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", "ipc:ipc_single", "kv_store:distributeddata_inner", "samgr:samgr_proxy", 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 9d9d05b2..b5c11d47 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 @@ -1211,6 +1211,7 @@ HWTEST_F(ComponentManagerTest, UninitCompSource_001, TestSize.Level1) HWTEST_F(ComponentManagerTest, UninitCompSink_001, TestSize.Level1) { + ComponentLoader::GetInstance().compHandlerMap_.clear(); SetUpComponentLoaderConfig(); auto ret = ComponentManager::GetInstance().UninitCompSink(DHType::AUDIO); SetDownComponentLoaderConfig(); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp index f6157c9c..95a7cc59 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp @@ -136,7 +136,6 @@ HWTEST_F(ComponentManagerTestExt, EnableSinkAndDisableSink_001, testing::ext::Te EXPECT_CALL(*componentLoader_, GetHardwareHandler(_, _)) .WillRepeatedly(DoAll(SetArgReferee<1>(handler.get()), Return(DH_FWK_SUCCESS))); EXPECT_CALL(*componentLoader_, ReleaseSink(_)).WillRepeatedly(Return(DH_FWK_SUCCESS)); - EXPECT_CALL(*handler, UnRegisterPluginListener()).Times(AtLeast(1)); ret = ComponentManager::GetInstance().DisableSink(CAMERA_DESCRIPTOR, CAMERA_UID, CAMERA_PID); EXPECT_EQ(ret, DH_FWK_SUCCESS); @@ -172,7 +171,6 @@ HWTEST_F(ComponentManagerTestExt, EnableSinkAndDisableSink_002, testing::ext::Te EXPECT_CALL(*componentLoader_, GetHardwareHandler(_, _)) .WillRepeatedly(DoAll(SetArgReferee<1>(handler.get()), Return(DH_FWK_SUCCESS))); EXPECT_CALL(*componentLoader_, ReleaseSink(_)).WillRepeatedly(Return(DH_FWK_SUCCESS)); - EXPECT_CALL(*handler, UnRegisterPluginListener()).Times(AtLeast(1)); ComponentManager::GetInstance().DisableSink(newAudio, AUDIO_UID, newAudioPid); ret = ComponentManager::GetInstance().DisableSink(AUDIO_DESCRIPTOR, AUDIO_UID, AUDIO_PID); @@ -533,7 +531,6 @@ HWTEST_F(ComponentManagerTestExt, EnableSinkAndForceDisableSink_001, testing::ex EXPECT_CALL(*componentLoader_, GetHardwareHandler(_, _)) .WillRepeatedly(DoAll(SetArgReferee<1>(handler.get()), Return(DH_FWK_SUCCESS))); EXPECT_CALL(*componentLoader_, ReleaseSink(_)).WillRepeatedly(Return(DH_FWK_SUCCESS)); - EXPECT_CALL(*handler, UnRegisterPluginListener()).Times(AtLeast(1)); auto ret = ComponentManager::GetInstance().ForceDisableSink(newAudio); EXPECT_EQ(ret, DH_FWK_SUCCESS); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_transport_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_transport_test.cpp index 451ac8ff..0937d583 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_transport_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/transport/dh_transport_test.cpp @@ -22,6 +22,7 @@ #include "dh_transport.h" #include "dh_comm_tool.h" #include "dh_transport_obj.h" +#include "dh_utils_tool.h" #include "capability_info_manager.h" #include "distributed_hardware_errno.h" #include "mock_other_method.h" @@ -39,6 +40,8 @@ namespace { constexpr int32_t SOCKETID = 10; constexpr int32_t INVALID_USER_ID = -100; constexpr int32_t INVALID_ACCOUNT_INFO_VALUE = -101; + constexpr int32_t DH_COMM_REQ_FULL_CAPS = 1; + constexpr int32_t DH_COMM_RSP_FULL_CAPS = 2; } static std::string g_mocklocalNetworkId = "123456789"; @@ -525,5 +528,66 @@ HWTEST_F(DhTransportTest, CheckCalleeAclRight_007, TestSize.Level1) auto ret = dhTransportTest_->CheckCalleeAclRight(commMsg); EXPECT_EQ(true, ret); } + +HWTEST_F(DhTransportTest, HandleReceiveMessage_001, TestSize.Level1) +{ + ASSERT_TRUE(dhTransportTest_ != nullptr); + int32_t userId = 1; + uint64_t tokenId = 1; + std::string networkId = "123456"; + std::string accountId = "111"; + CommMsg commMsg(DH_COMM_REQ_FULL_CAPS, userId, tokenId, networkId, accountId); + std::string payload = GetCommMsgString(commMsg); + std::string compressedPayLoad = Compress(payload); + std::vector userIds; + EXPECT_CALL(*otherMethodMock_, QueryActiveOsAccountIds(_)) + .WillOnce(DoAll(SetArgReferee<0>(userIds), Return(INVALID_USER_ID))); + ASSERT_NO_FATAL_FAILURE(dhTransportTest_->HandleReceiveMessage(compressedPayLoad)); +} + +HWTEST_F(DhTransportTest, HandleReceiveMessage_002, TestSize.Level1) +{ + ASSERT_TRUE(dhTransportTest_ != nullptr); + int32_t userId = -1; + uint64_t tokenId = 1; + std::string networkId = "123456"; + std::string accountId = "111"; + CommMsg commMsg(DH_COMM_REQ_FULL_CAPS, userId, tokenId, networkId, accountId); + std::string payload = GetCommMsgString(commMsg); + std::string compressedPayLoad = Compress(payload); + std::shared_ptr dhCommTool = std::make_shared(); + dhTransportTest_->dhCommToolWPtr_ = dhCommTool; + ASSERT_NO_FATAL_FAILURE(dhTransportTest_->HandleReceiveMessage(compressedPayLoad)); +} + +HWTEST_F(DhTransportTest, HandleReceiveMessage_003, TestSize.Level1) +{ + ASSERT_TRUE(dhTransportTest_ != nullptr); + int32_t userId = 1; + uint64_t tokenId = 1; + std::string networkId = "123456"; + std::string accountId = "111"; + CommMsg commMsg(DH_COMM_RSP_FULL_CAPS, userId, tokenId, networkId, accountId); + std::string payload = GetCommMsgString(commMsg); + std::string compressedPayLoad = Compress(payload); + ASSERT_NO_FATAL_FAILURE(dhTransportTest_->HandleReceiveMessage(compressedPayLoad)); +} + +HWTEST_F(DhTransportTest, HandleReceiveMessage_004, TestSize.Level1) +{ + ASSERT_TRUE(dhTransportTest_ != nullptr); + int32_t userId = 1; + uint64_t tokenId = 1; + std::string networkId = "123456"; + std::string accountId = "111"; + CommMsg commMsg(DH_COMM_RSP_FULL_CAPS, userId, tokenId, networkId, accountId); + std::string payload = GetCommMsgString(commMsg); + std::string compressedPayLoad = Compress(payload); + std::shared_ptr dhCommTool = std::make_shared(); + dhTransportTest_->dhCommToolWPtr_ = dhCommTool; + dhCommTool->Init(); + ASSERT_NO_FATAL_FAILURE(dhTransportTest_->HandleReceiveMessage(compressedPayLoad)); + dhCommTool->UnInit(); +} } } \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/test/unittest/common/utils/dh_modem_context_ext_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/utils/dh_modem_context_ext_test.cpp index 87394518..11207584 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/utils/dh_modem_context_ext_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/utils/dh_modem_context_ext_test.cpp @@ -47,14 +47,6 @@ void DHModemContextExtTest::TearDownTestCase() {} EXPECT_EQ(ret, DH_FWK_SUCCESS); } - HWTEST_F(DHModemContextExtTest, GetModemExtInstance_002, TestSize.Level1) - { - int32_t ret = DHModemContextExt::GetInstance().GetHandler(); - EXPECT_EQ(ret, DH_FWK_SUCCESS); - DHModemContextExt::GetInstance().GetModemExtInstance(); - EXPECT_NE(DHModemContextExt::GetInstance().distributedModemExt_, nullptr); - } - HWTEST_F(DHModemContextExtTest, UnInit_001, TestSize.Level1) { DHModemContextExt::GetInstance().soHandle_ = nullptr; -- Gitee