From bc8a59a3968d435092340c7f76856bf49727b76b Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Tue, 31 May 2022 20:14:37 +0800 Subject: [PATCH] =?UTF-8?q?TDD=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=8Acodecheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- common/include/dm_constants.h | 1 + ext/profile/src/profile_connector.cpp | 2 -- .../src/discovery/dm_discovery_manager.cpp | 2 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 6 ++++-- test/unittest/UTTest_auth_request_state.cpp | 3 +++ test/unittest/UTTest_auth_response_state.cpp | 1 + test/unittest/UTTest_dm_auth_manager.cpp | 6 ++++-- test/unittest/UTTest_dm_discovery_manager.cpp | 2 ++ utils/src/dm_error_message.cpp | 3 +++ 9 files changed, 19 insertions(+), 7 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 58c26ce3..0023f134 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -76,6 +76,7 @@ enum { ERR_DM_CREATE_GROUP_FAILED = -20028, ERR_DM_IPC_READ_TOKEN_FAILED = -20029, ERR_DM_AUTH_INPUT_PARAMETER_FAILED = -20030, + ERR_DM_IPC_READ_FA_FAILED = -20031, }; const std::string TARGET_PKG_NAME_KEY = "targetPkgName"; diff --git a/ext/profile/src/profile_connector.cpp b/ext/profile/src/profile_connector.cpp index d8d4b9fd..e0b57852 100755 --- a/ext/profile/src/profile_connector.cpp +++ b/ext/profile/src/profile_connector.cpp @@ -107,10 +107,8 @@ int32_t ProfileConnector::UnSubscribeProfileEvents() void ProfileConnector::OnSyncCompleted(const SyncResult &syncResults) { std::string deviceId; - u_int32_t SyncStatus; for (auto &iterResult : syncResults) { deviceId = iterResult.first; - SyncStatus = iterResult.second; } LOGI("ProfileEventCallback::OnSyncCompleted, deviceId = %s", GetAnonyString(deviceId).c_str()); std::lock_guard mutexLock(callbackMapMutex_); diff --git a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp index 659d5a1f..9ecadecf 100644 --- a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp +++ b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp @@ -39,7 +39,6 @@ DmDiscoveryManager::~DmDiscoveryManager() int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, const std::string &extra) { - std::lock_guard autoLock(locks_); if (!discoveryQueue_.empty()) { if (pkgName == discoveryQueue_.front()) { LOGE("DmDiscoveryManager::StartDeviceDiscovery repeated, pkgName:%s", pkgName.c_str()); @@ -50,6 +49,7 @@ int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, con StopDeviceDiscovery(discoveryQueue_.front(), discoveryContextMap_[discoveryQueue_.front()].subscribeId); } } + std::lock_guard autoLock(locks_); discoveryQueue_.push(pkgName); DmDiscoveryContext context = {pkgName, extra, subscribeInfo.subscribeId}; discoveryContextMap_.emplace(pkgName, context); diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp index 260070f4..6aaca338 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp @@ -440,8 +440,10 @@ ON_IPC_CMD(SERVER_GET_DMFA_INFO, MessageParcel &data, MessageParcel &reply) { std::string packName = data.ReadString(); DmAuthParam authParam; - int32_t ret = DM_OK; - ret = DeviceManagerService::GetInstance().GetFaParam(packName, authParam); + if (DeviceManagerService::GetInstance().GetFaParam(packName, authParam) != DM_OK) { + LOGE("ipc read fa parm failed"); + return ERR_DM_IPC_READ_FA_FAILED; + } int32_t appIconLen = authParam.imageinfo.GetAppIconLen(); int32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen(); diff --git a/test/unittest/UTTest_auth_request_state.cpp b/test/unittest/UTTest_auth_request_state.cpp index 9d0b6b0d..5e232668 100644 --- a/test/unittest/UTTest_auth_request_state.cpp +++ b/test/unittest/UTTest_auth_request_state.cpp @@ -428,6 +428,7 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) authManager->authRequestContext_ = std::make_shared(); authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_->sessionId = 1; + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); authManager->SetAuthRequestState(authRequestState); @@ -494,6 +495,7 @@ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; authRequestState->SetAuthManager(authManager); + authManager->timer_ = std::make_shared(); authManager->SetAuthRequestState(authRequestState); authManager->hiChainConnector_->RegisterHiChainCallback(authManager); authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); @@ -555,6 +557,7 @@ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authRequestState_ = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp index 51ef19ee..348bf9f3 100644 --- a/test/unittest/UTTest_auth_response_state.cpp +++ b/test/unittest/UTTest_auth_response_state.cpp @@ -464,6 +464,7 @@ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0) authManager->authResponseContext_->reply = 5; authManager->authRequestContext_->reason = 6; authManager->SetAuthResponseState(authResponseState); + authManager->timer_ = std::make_shared(); authResponseState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); authResponseState->SetAuthContext(context); diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index a6c76070..70857a01 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -209,10 +209,11 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; int32_t pinCode = 444444; + authManager->timer_ = std::make_shared(); authManager->hiChainConnector_->RegisterHiChainCallback(authManager); authManager->SetAuthResponseState(authResponseState); int32_t ret = authManager->AddMember(pinCode); - ASSERT_EQ(ret, ERR_DM_FAILED); + ASSERT_EQ(ret, DM_OK); } /** @@ -264,8 +265,9 @@ HWTEST_F(DmAuthManagerTest, GetPinCode_001, testing::ext::TestSize.Level0) std::shared_ptr authManager = std::make_shared(softbusConnector, listener, hiChainConnector_); authManager->authResponseContext_ = std::make_shared(); + authManager->authResponseContext_->code = 123456; int32_t ret = authManager->GetPinCode(); - ASSERT_EQ(ret, ERR_DM_FAILED); + ASSERT_EQ(ret, 123456); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_dm_discovery_manager.cpp b/test/unittest/UTTest_dm_discovery_manager.cpp index 27b40b4e..c168d029 100644 --- a/test/unittest/UTTest_dm_discovery_manager.cpp +++ b/test/unittest/UTTest_dm_discovery_manager.cpp @@ -88,6 +88,7 @@ HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_001, testing::ext::TestSiz discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); EXPECT_EQ(ret, ERR_DM_DISCOVERY_REPEATED); + discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); } /** @@ -106,6 +107,7 @@ HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_002, testing::ext::TestSiz pkgName = "com.ohos.helloworld.new"; int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); ASSERT_EQ(ret, ERR_DM_DISCOVERY_FAILED); + discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); } /** diff --git a/utils/src/dm_error_message.cpp b/utils/src/dm_error_message.cpp index bdc166d7..26393531 100644 --- a/utils/src/dm_error_message.cpp +++ b/utils/src/dm_error_message.cpp @@ -52,6 +52,9 @@ static ERROR_INFO g_errorMessages[] = { {ERR_DM_AUTH_NOT_START, "auth process not started."}, {ERR_DM_AUTH_MESSAGE_INCOMPLETE, "authentication message is incomplete."}, {ERR_DM_CREATE_GROUP_FAILED, "create group failed."}, + {ERR_DM_IPC_READ_TOKEN_FAILED, "read ipc token failed."}, + {ERR_DM_AUTH_INPUT_PARAMETER_FAILED, "auth input parameter failed."}, + {ERR_DM_IPC_READ_FA_FAILED, "ipc read fa parms failed."}, }; std::string GetErrorString(int failedReason)