From d919838fdb4b0918330796bf9b13c47202e0da84 Mon Sep 17 00:00:00 2001 From: z00838083 Date: Mon, 11 Nov 2024 21:00:30 +0800 Subject: [PATCH 1/7] BugFix: add dtbWant to dataCmd Signed-off-by: z00838083 --- .../include/continue/dsched_continue_event.h | 6 + .../src/continue/dsched_continue.cpp | 2 +- .../src/continue/dsched_continue_event.cpp | 150 +++++++++++++----- .../distributed_want_params_wrapper.cpp | 1 + 4 files changed, 121 insertions(+), 38 deletions(-) diff --git a/services/dtbschedmgr/include/continue/dsched_continue_event.h b/services/dtbschedmgr/include/continue/dsched_continue_event.h index f625104c..5e7e6cdb 100644 --- a/services/dtbschedmgr/include/continue/dsched_continue_event.h +++ b/services/dtbschedmgr/include/continue/dsched_continue_event.h @@ -18,6 +18,8 @@ #include +#include "cJSON.h" + #include "ability_info.h" #include "caller_info.h" #include "distributed_sched_interface.h" @@ -88,9 +90,13 @@ public: int32_t Unmarshal(const std::string &jsonStr); private: + bool MarshalInner(cJSON* rootValue); int32_t MarshalCallerInfo(std::string &jsonStr); int32_t MarshalAccountInfo(std::string &jsonStr); int32_t UnmarshalParcel(const std::string &jsonStr); + bool UnmarshalWantParcel(cJSON* rootValue); + int32_t UnmarshalWantStr(const std::string &jsonStr); + int32_t UnmarshalDtbWantStr(const std::string &jsonStr); int32_t UnmarshalCallerInfo(const std::string &jsonStr); int32_t UnmarshalCallerInfoExtra(const std::string &jsonStr); int32_t UnmarshalAccountInfo(const std::string &jsonStr); diff --git a/services/dtbschedmgr/src/continue/dsched_continue.cpp b/services/dtbschedmgr/src/continue/dsched_continue.cpp index ec73eeca..8fba3b2f 100644 --- a/services/dtbschedmgr/src/continue/dsched_continue.cpp +++ b/services/dtbschedmgr/src/continue/dsched_continue.cpp @@ -139,7 +139,7 @@ DSchedContinue::DSchedContinue(std::shared_ptr startCmd, HILOGE("startCmd is null"); return; } - version_ = startCmd->version_; + version_ = DSCHED_CONTINUE_PROTOCOL_VERSION; subServiceType_ = startCmd->subServiceType_; continueByType_ = startCmd->continueByType_; direction_ = (startCmd->direction_ == CONTINUE_SOURCE) ? CONTINUE_SINK : CONTINUE_SOURCE; diff --git a/services/dtbschedmgr/src/continue/dsched_continue_event.cpp b/services/dtbschedmgr/src/continue/dsched_continue_event.cpp index 592a86ae..87a06676 100644 --- a/services/dtbschedmgr/src/continue/dsched_continue_event.cpp +++ b/services/dtbschedmgr/src/continue/dsched_continue_event.cpp @@ -15,9 +15,9 @@ #include "dsched_continue_event.h" -#include "cJSON.h" #include "parcel.h" +#include "distributedWant/distributed_want.h" #include "distributed_sched_utils.h" #include "dms_constant.h" #include "dtbschedmgr_log.h" @@ -217,21 +217,49 @@ int32_t DSchedContinueDataCmd::Marshal(std::string &jsonStr) cJSON_Delete(rootValue); return INVALID_PARAMETERS_ERR; } - cJSON_AddStringToObject(rootValue, "BaseCmd", baseJsonStr.c_str()); + if (!MarshalInner(rootValue)) { + cJSON_Delete(rootValue); + return INVALID_PARAMETERS_ERR; + } + + char *data = cJSON_Print(rootValue); + if (data == nullptr) { + cJSON_Delete(rootValue); + return INVALID_PARAMETERS_ERR; + } + + jsonStr = std::string(data); + cJSON_Delete(rootValue); + cJSON_free(data); + return ERR_OK; +} + +bool DSchedContinueDataCmd::MarshalInner(cJSON* rootValue) +{ + if (rootValue == nullptr) { + return false; + } + Parcel wantParcel; if (!want_.Marshalling(wantParcel)) { - cJSON_Delete(rootValue); - return INVALID_PARAMETERS_ERR; + return false; } std::string wantStr = ParcelToBase64Str(wantParcel); cJSON_AddStringToObject(rootValue, "Want", wantStr.c_str()); + DistributedWant dtbWant(want_); + Parcel dtbWantParcel; + if (!dtbWant.Marshalling(dtbWantParcel)) { + return false; + } + std::string dtbWantStr = ParcelToBase64Str(dtbWantParcel); + cJSON_AddStringToObject(rootValue, "DtbWant", dtbWantStr.c_str()); + Parcel abilityParcel; if (!abilityInfo_.Marshalling(abilityParcel)) { - cJSON_Delete(rootValue); - return INVALID_PARAMETERS_ERR; + return false; } std::string abilityInfoStr = ParcelToBase64Str(abilityParcel); cJSON_AddStringToObject(rootValue, "AbilityInfo", abilityInfoStr.c_str()); @@ -240,29 +268,20 @@ int32_t DSchedContinueDataCmd::Marshal(std::string &jsonStr) std::string callerInfoStr; if (MarshalCallerInfo(callerInfoStr) != ERR_OK) { - cJSON_Delete(rootValue); - return INVALID_PARAMETERS_ERR; + return false; } cJSON_AddStringToObject(rootValue, "CallerInfo", callerInfoStr.c_str()); std::string accountInfoStr; if (MarshalAccountInfo(accountInfoStr) != ERR_OK) { - cJSON_Delete(rootValue); - return INVALID_PARAMETERS_ERR; + return false; } cJSON_AddStringToObject(rootValue, "AccountInfo", accountInfoStr.c_str()); - char *data = cJSON_Print(rootValue); - if (data == nullptr) { - cJSON_Delete(rootValue); - return INVALID_PARAMETERS_ERR; - } - jsonStr = std::string(data); - cJSON_Delete(rootValue); - cJSON_free(data); - return ERR_OK; + return true; } + int32_t DSchedContinueDataCmd::MarshalCallerInfo(std::string &jsonStr) { cJSON *callerInfoJson = cJSON_CreateObject(); @@ -412,26 +431,10 @@ int32_t DSchedContinueDataCmd::UnmarshalParcel(const std::string &jsonStr) return INVALID_PARAMETERS_ERR; } - cJSON *wantStr = cJSON_GetObjectItemCaseSensitive(rootValue, "Want"); - if (wantStr == nullptr || !cJSON_IsString(wantStr) || (wantStr->valuestring == nullptr)) { + if (!UnmarshalWantParcel(rootValue)) { cJSON_Delete(rootValue); - HILOGE("Want term is null or not string."); return INVALID_PARAMETERS_ERR; } - Parcel wantParcel; - int32_t ret = Base64StrToParcel(wantStr->valuestring, wantParcel); - if (ret != ERR_OK) { - cJSON_Delete(rootValue); - HILOGE("Want parcel Base64Str unmarshal fail, ret %{public}d.", ret); - return INVALID_PARAMETERS_ERR; - } - auto wantPtr = AAFwk::Want::Unmarshalling(wantParcel); - if (wantPtr == nullptr) { - cJSON_Delete(rootValue); - HILOGE("AAFwk Want unmarshalling fail, check return null."); - return INVALID_PARAMETERS_ERR; - } - want_ = *wantPtr; cJSON *abilityInfoStr = cJSON_GetObjectItemCaseSensitive(rootValue, "AbilityInfo"); if (abilityInfoStr == nullptr || !cJSON_IsString(abilityInfoStr) || (abilityInfoStr->valuestring == nullptr)) { @@ -440,7 +443,7 @@ int32_t DSchedContinueDataCmd::UnmarshalParcel(const std::string &jsonStr) return INVALID_PARAMETERS_ERR; } Parcel abilityParcel; - ret = Base64StrToParcel(abilityInfoStr->valuestring, abilityParcel); + int32_t ret = Base64StrToParcel(abilityInfoStr->valuestring, abilityParcel); if (ret != ERR_OK) { cJSON_Delete(rootValue); HILOGE("AbilityInfo parcel Base64Str unmarshal fail, ret %{public}d.", ret); @@ -458,6 +461,79 @@ int32_t DSchedContinueDataCmd::UnmarshalParcel(const std::string &jsonStr) return ERR_OK; } +bool DSchedContinueDataCmd::UnmarshalWantParcel(cJSON* rootValue) +{ + if (rootValue == nullptr) { + return false; + } + + cJSON *dtbWantStr = cJSON_GetObjectItemCaseSensitive(rootValue, "DtbWant"); + if (dtbWantStr != nullptr) { + if (!cJSON_IsString(dtbWantStr) || (dtbWantStr->valuestring == nullptr)) { + HILOGE("DtbWant term is null or not string."); + return false; + } + if (UnmarshalDtbWantStr(dtbWantStr->valuestring) != ERR_OK) { + HILOGE("UnmarshalDtbWantStr failed!"); + return false; + } + } else { + cJSON *wantStr = cJSON_GetObjectItemCaseSensitive(rootValue, "Want"); + if (wantStr == nullptr|| !cJSON_IsString(wantStr) || (wantStr->valuestring == nullptr)) { + HILOGE("Want term is null or not string."); + return false; + } + if (UnmarshalWantStr(wantStr->valuestring) != ERR_OK) { + HILOGE("UnmarshalWantStr failed!"); + return false; + } + } + return true; +} + +int32_t DSchedContinueDataCmd::UnmarshalDtbWantStr(const std::string &jsonStr) +{ + Parcel wantParcel; + int32_t ret = Base64StrToParcel(jsonStr, wantParcel); + if (ret != ERR_OK) { + HILOGE("Want parcel Base64Str unmarshal fail, ret %{public}d.", ret); + return INVALID_PARAMETERS_ERR; + } + + auto dtbWantPtr = DistributedWant::Unmarshalling(wantParcel); + if (dtbWantPtr == nullptr) { + HILOGE("Distributed want unmarshalling fail, check return null."); + return INVALID_PARAMETERS_ERR; + } + + DistributedWant dtbWant = *dtbWantPtr; + auto wantPtr = dtbWant.ToWant(); + if (wantPtr == nullptr) { + HILOGE("Convert distributedWant to want failed."); + return INVALID_PARAMETERS_ERR; + } + want_ = *wantPtr; + return ERR_OK; +} + +int32_t DSchedContinueDataCmd::UnmarshalWantStr(const std::string &jsonStr) +{ + Parcel wantParcel; + int32_t ret = Base64StrToParcel(jsonStr, wantParcel); + if (ret != ERR_OK) { + HILOGE("Want parcel Base64Str unmarshal fail, ret %{public}d.", ret); + return INVALID_PARAMETERS_ERR; + } + + auto wantPtr = AAFwk::Want::Unmarshalling(wantParcel); + if (wantPtr == nullptr) { + HILOGE("Want unmarshalling fail, check return null."); + return INVALID_PARAMETERS_ERR; + } + want_ = *wantPtr; + return ERR_OK; +} + int32_t DSchedContinueDataCmd::UnmarshalCallerInfo(const std::string &jsonStr) { cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); diff --git a/services/dtbschedmgr/src/distributedWant/distributed_want_params_wrapper.cpp b/services/dtbschedmgr/src/distributedWant/distributed_want_params_wrapper.cpp index d86312b2..01e3c8e1 100644 --- a/services/dtbschedmgr/src/distributedWant/distributed_want_params_wrapper.cpp +++ b/services/dtbschedmgr/src/distributedWant/distributed_want_params_wrapper.cpp @@ -143,6 +143,7 @@ sptr DistributedWantParamWrapper::Parse(const std::strin strKey = ""; typeId = 0; strnum = num + 1; + continue; } else if (str[strnum] != '"') { continue; } From 0713d0c9d90d12c68e35ed2abd55da59aa847d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A6=E5=9B=BD=E5=BA=86?= Date: Tue, 12 Nov 2024 15:43:34 +0800 Subject: [PATCH 2/7] =?UTF-8?q?Init=E6=97=B6=E5=BA=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韦国庆 --- .../mission/dms_continue_recv_manager.h | 2 - .../dtbschedmgr/include/multi_user_manager.h | 7 ++- .../src/distributed_sched_service.cpp | 9 +-- .../src/dtbschedmgr_device_info_storage.cpp | 9 +-- .../src/mission/dms_continue_recv_manager.cpp | 6 -- .../dtbschedmgr/src/multi_user_manager.cpp | 46 +++++++++------ .../test/unittest/multi_user_manager_test.cpp | 59 ++++++++++++++++--- 7 files changed, 88 insertions(+), 50 deletions(-) diff --git a/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h b/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h index 242c9970..fe9b110e 100644 --- a/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h +++ b/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h @@ -87,7 +87,6 @@ public: void OnContinueSwitchOff(); void OnUserSwitch(); std::string GetContinueType(const std::string& bundleName); - bool CheckRegSoftbusListener(); private: void StartEvent(); @@ -119,7 +118,6 @@ private: std::mutex eventMutex_; std::mutex iconMutex_; std::shared_ptr eventHandler_; - bool hasRegSoftbusEventListener_ = false; }; } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/include/multi_user_manager.h b/services/dtbschedmgr/include/multi_user_manager.h index 01a11e8a..f11bd57d 100644 --- a/services/dtbschedmgr/include/multi_user_manager.h +++ b/services/dtbschedmgr/include/multi_user_manager.h @@ -34,8 +34,8 @@ public: void OnUserSwitched(int32_t userId); void OnUserRemoved(int32_t userId); AccountSA::OsAccountType GetOsAccountType(int32_t &accountId); - int32_t CreateNewSendMgr(); - int32_t CreateNewRecvMgr(); + int32_t CreateNewSendMgrLocked(); + int32_t CreateNewRecvMgrLocked(); std::shared_ptr GetCurrentSendMgr(); std::shared_ptr GetCurrentRecvMgr(); std::shared_ptr GetSendMgrByCallingUid(int32_t callingUid); @@ -45,6 +45,8 @@ public: int32_t GetForegroundUser(); bool IsUserForeground(int32_t userId); bool IsCallerForeground(int32_t callingUid); + bool CheckRegSoftbusListener(); + void RegisterSoftbusListener(); private: void UserSwitchedOnRegisterListenerCache(); @@ -57,6 +59,7 @@ private: std::mutex sendMutex_; std::mutex recvMutex_; std::mutex listenerMutex_; + bool hasRegSoftbusEventListener_ = false; }; } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/src/distributed_sched_service.cpp b/services/dtbschedmgr/src/distributed_sched_service.cpp index 4067877b..20fe095f 100644 --- a/services/dtbschedmgr/src/distributed_sched_service.cpp +++ b/services/dtbschedmgr/src/distributed_sched_service.cpp @@ -270,15 +270,10 @@ void DistributedSchedService::DeviceOnlineNotify(const std::string& networkId) DistributedSchedAdapter::GetInstance().DeviceOnline(networkId); #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(networkId); - auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - HILOGI("GetRecvMgr failed."); - return; - } - if (!recvMgr->CheckRegSoftbusListener() && + if (!MultiUserManager::GetInstance().CheckRegSoftbusListener() && DistributedHardware::DeviceManager::GetInstance().IsSameAccount(networkId)) { HILOGI("DMSContinueRecvMgr need init"); - recvMgr->Init(); + MultiUserManager::GetInstance().RegisterSoftbusListener(); } #endif } diff --git a/services/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp b/services/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp index e5104cc5..2b42e5e7 100644 --- a/services/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp +++ b/services/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp @@ -403,15 +403,10 @@ void DtbschedmgrDeviceInfoStorage::DeviceOfflineNotify(const std::string& networ void DtbschedmgrDeviceInfoStorage::OnDeviceInfoChanged(const std::string& deviceId) { HILOGI("OnDeviceInfoChanged called"); - auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - HILOGI("GetRecvMgr failed."); - return; - } - if (!recvMgr->CheckRegSoftbusListener() && + if (!MultiUserManager::GetInstance().CheckRegSoftbusListener() && DistributedHardware::DeviceManager::GetInstance().IsSameAccount(deviceId)) { HILOGI("DMSContinueRecvMgr need init"); - recvMgr->Init(); + MultiUserManager::GetInstance().RegisterSoftbusListener(); } } diff --git a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp index 35539618..2bc6717f 100644 --- a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp +++ b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp @@ -58,7 +58,6 @@ void DMSContinueRecvMgr::Init() return; } { - hasRegSoftbusEventListener_ = true; missionDiedListener_ = new DistributedMissionDiedListener(); eventThread_ = std::thread(&DMSContinueRecvMgr::StartEvent, this); std::unique_lock lock(eventMutex_); @@ -658,10 +657,5 @@ std::string DMSContinueRecvMgr::GetContinueType(const std::string& bundleName) return iconInfo_.continueType; } - -bool DMSContinueRecvMgr::CheckRegSoftbusListener() -{ - return hasRegSoftbusEventListener_; -} } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/src/multi_user_manager.cpp b/services/dtbschedmgr/src/multi_user_manager.cpp index 99eec7ee..254128b0 100644 --- a/services/dtbschedmgr/src/multi_user_manager.cpp +++ b/services/dtbschedmgr/src/multi_user_manager.cpp @@ -44,18 +44,13 @@ void MultiUserManager::Init() HILOGI("GetSendMgr failed."); return; } - sendMgr->Init(); auto recvMgr = GetCurrentRecvMgr(); if (recvMgr == nullptr) { HILOGI("GetRecvMgr failed."); return; } - recvMgr->Init(); - std::shared_ptr missionBroadcastListener = - std::make_shared(); - int32_t ret = SoftbusAdapter::GetInstance().RegisterSoftbusEventListener(missionBroadcastListener); - if (ret != ERR_OK) { - HILOGE("get RegisterSoftbusEventListener failed, ret: %{public}d", ret); + if (!CheckRegSoftbusListener()) { + RegisterSoftbusListener(); } HILOGI("Init end."); } @@ -130,14 +125,11 @@ void MultiUserManager::OnUserSwitched(int32_t accountId) HILOGI("GetSendMgr failed."); return; } - sendMgr->Init(); recvMgr = GetCurrentRecvMgr(); if (recvMgr == nullptr) { HILOGI("GetRecvMgr failed."); return; } - recvMgr->Init(); - if (!DataShareManager::GetInstance().IsCurrentContinueSwitchOn()) { recvMgr->OnContinueSwitchOff(); HILOGI("ICurrentContinueSwitch is off, %{public}d", DataShareManager::GetInstance() @@ -214,19 +206,21 @@ AccountSA::OsAccountType MultiUserManager::GetOsAccountType(int32_t &accountId) return type; } -int32_t MultiUserManager::CreateNewSendMgr() +int32_t MultiUserManager::CreateNewSendMgrLocked() { HILOGI("CreateNewSendMgr begin. accountId: %{public}d.", currentUserId_); auto sendMgr = std::make_shared(); + sendMgr->Init(); sendMgrMap_.emplace(currentUserId_, sendMgr); HILOGI("CreateNewSendMgr end."); return ERR_OK; } -int32_t MultiUserManager::CreateNewRecvMgr() +int32_t MultiUserManager::CreateNewRecvMgrLocked() { HILOGI("CreateNewRecvMgr begin. accountId: %{public}d.", currentUserId_); auto recvMgr = std::make_shared(); + recvMgr->Init(); recvMgrMap_.emplace(currentUserId_, recvMgr); HILOGI("CreateNewRecvMgr end."); return ERR_OK; @@ -238,7 +232,7 @@ std::shared_ptr MultiUserManager::GetCurrentSendMgr() std::lock_guard lock(sendMutex_); if (sendMgrMap_.empty() || sendMgrMap_.find(currentUserId_) == sendMgrMap_.end()) { HILOGI("sendMgr need to create."); - CreateNewSendMgr(); + CreateNewSendMgrLocked(); } auto cur = sendMgrMap_.find(currentUserId_); return cur->second; @@ -250,7 +244,7 @@ std::shared_ptr MultiUserManager::GetCurrentRecvMgr() std::lock_guard lock(recvMutex_); if (recvMgrMap_.empty() || recvMgrMap_.find(currentUserId_) == recvMgrMap_.end()) { HILOGI("recvMgr need to create."); - CreateNewRecvMgr(); + CreateNewRecvMgrLocked(); } auto cur = recvMgrMap_.find(currentUserId_); return cur->second; @@ -260,11 +254,11 @@ std::shared_ptr MultiUserManager::GetSendMgrByCallingUid(int { int32_t accountId = -1; OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, accountId); - HILOGI("GetRecvMgrByCallingUid. accountId: %{public}d , callingUid: %{public}d.", accountId, callingUid); + HILOGI("GetSendMgrByCallingUid. accountId: %{public}d , callingUid: %{public}d.", accountId, callingUid); std::lock_guard lock(sendMutex_); if (sendMgrMap_.empty() || sendMgrMap_.find(accountId) == sendMgrMap_.end()) { HILOGI("sendMgr need to create."); - CreateNewSendMgr(); + CreateNewSendMgrLocked(); } auto cur = sendMgrMap_.find(accountId); return cur->second; @@ -278,7 +272,7 @@ std::shared_ptr MultiUserManager::GetRecvMgrByCallingUid(int std::lock_guard lock(recvMutex_); if (recvMgrMap_.empty() || recvMgrMap_.find(accountId) == recvMgrMap_.end()) { HILOGI("recvMgr need to create."); - CreateNewRecvMgr(); + CreateNewRecvMgrLocked(); } auto cur = recvMgrMap_.find(accountId); return cur->second; @@ -361,5 +355,23 @@ bool MultiUserManager::IsCallerForeground(int32_t callingUid) OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, accountId); return IsUserForeground(accountId); } + +void MultiUserManager::RegisterSoftbusListener() +{ + HILOGI("Register softbusListener start. accountId: %{public}d.", currentUserId_); + std::shared_ptr missionBroadcastListener = + std::make_shared(); + int32_t ret = SoftbusAdapter::GetInstance().RegisterSoftbusEventListener(missionBroadcastListener); + if (ret != ERR_OK) { + HILOGE("get RegisterSoftbusEventListener failed, ret: %{public}d", ret); + } + hasRegSoftbusEventListener_ = true; + HILOGI("Register softbusListener end."); +} + +bool MultiUserManager::CheckRegSoftbusListener() +{ + return hasRegSoftbusEventListener_; +} } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp b/services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp index a6197b6a..919bd8ed 100644 --- a/services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp @@ -179,11 +179,8 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_CreateNewSendMgr_001, TestSize.L /** * @tc.steps: step1. test OnUserRemoved with create current user sendMgr; */ - MultiUserManager::GetInstance().Init(); - int32_t ret = MultiUserManager::GetInstance().CreateNewSendMgr(); + int32_t ret = MultiUserManager::GetInstance().CreateNewSendMgrLocked(); EXPECT_EQ(ret, ERR_OK); - - MultiUserManager::GetInstance().UnInit(); DTEST_LOG << "MultiUserManager_CreateNewSendMgr_001 end" << std::endl; } @@ -198,11 +195,8 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_CreateNewRecvMgr_001, TestSize.L /** * @tc.steps: step1. test OnUserRemoved with create current user recvMgr; */ - MultiUserManager::GetInstance().Init(); - int32_t ret = MultiUserManager::GetInstance().CreateNewRecvMgr(); + int32_t ret = MultiUserManager::GetInstance().CreateNewRecvMgrLocked(); EXPECT_EQ(ret, ERR_OK); - - MultiUserManager::GetInstance().UnInit(); DTEST_LOG << "MultiUserManager_CreateNewRecvMgr_001 end" << std::endl; } @@ -246,7 +240,7 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentRecvMgr_001, TestSize. int32_t accountId = 100; MultiUserManager::GetInstance().Init(); auto recvMgr = MultiUserManager::GetInstance().recvMgrMap_.find(accountId)->second; - + MultiUserManager::GetInstance().hasRegSoftbusEventListener_ = true; auto ret = MultiUserManager::GetInstance().GetCurrentRecvMgr(); EXPECT_EQ(ret, recvMgr); @@ -259,6 +253,53 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentRecvMgr_001, TestSize. DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_001 end" << std::endl; } +/** + * @tc.name: MultiUserManager_GetCurrentRecvMgr_002 + * @tc.desc: test GetCurrentRecvMgr + * @tc.type: FUNC + */ +HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentRecvMgr_002, TestSize.Level3) +{ + DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_002 start" << std::endl; + /** + * @tc.steps: step1. test OnUserRemoved with create current user recvMgr; + */ + int32_t accountId = 100; + MultiUserManager::GetInstance().Init(); + auto recvMgr = MultiUserManager::GetInstance().recvMgrMap_.find(accountId)->second; + MultiUserManager::GetInstance().hasRegSoftbusEventListener_ = false; + auto ret = MultiUserManager::GetInstance().GetCurrentRecvMgr(); + EXPECT_EQ(ret, recvMgr); + EXPECT_TRUE(MultiUserManager::GetInstance().hasRegSoftbusEventListener_); + + MultiUserManager::GetInstance().recvMgrMap_.insert({accountId, nullptr}); + ret = MultiUserManager::GetInstance().GetCurrentRecvMgr(); + EXPECT_NE(ret, nullptr); + + + MultiUserManager::GetInstance().UnInit(); + DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_002 end" << std::endl; +} + +/** + * @tc.name: MultiUserManager_CheckRegSoftbusListener_001 + * @tc.desc: test CheckRegSoftbusListener + * @tc.type: FUNC + */ +HWTEST_F(MultiUserManagerTest, MultiUserManager_CheckRegSoftbusListener_001, TestSize.Level3) +{ + DTEST_LOG << "MultiUserManager_CheckRegSoftbusListener_001 start" << std::endl; + /** + * @tc.steps: step1. test OnUserRemoved with create current user recvMgr; + */ + MultiUserManager::GetInstance().hasRegSoftbusEventListener_ = false; + EXPECT_FALSE(MultiUserManager::GetInstance().CheckRegSoftbusListener()); + MultiUserManager::GetInstance().RegisterSoftbusListener(); + EXPECT_TRUE(MultiUserManager::GetInstance().hasRegSoftbusEventListener_); + EXPECT_TRUE(MultiUserManager::GetInstance().CheckRegSoftbusListener()); + DTEST_LOG << "MultiUserManager_CheckRegSoftbusListener_001 end" << std::endl; +} + /** * @tc.name: MultiUserManager_OnRegisterOnListener_001 * @tc.desc: test OnRegisterOnListener From fa2db294e18b344b1052150a2380f9b4223b7848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=88=E7=9A=93=E6=9D=B0?= Date: Thu, 14 Nov 2024 16:30:03 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 师皓杰 --- services/dtbschedmgr/test/BUILD.gn | 10 +- .../unittest/bundle_manager_internal_test.cpp | 95 ++++++ .../unittest/common_event_listener_test.cpp | 126 ++++++++ .../continue/dsched_continue_manager_test.cpp | 2 + .../continue/dsched_continue_state_test.cpp | 33 ++ .../continue/dsched_continue_test.cpp | 35 +++ .../distributed_want_params_test.cpp | 28 +- .../distributedWant/distributed_want_test.cpp | 171 +++++++++++ .../unittest/distributed_sched_stub_test.cpp | 78 +++++ .../unittest/dms_network_adapter_test.cpp | 29 ++ .../mission/dms_continue_manager_test.cpp | 290 ++++-------------- .../test/unittest/multi_user_manager_test.cpp | 28 -- .../softbus_transport_test.cpp | 24 +- 13 files changed, 666 insertions(+), 283 deletions(-) create mode 100644 services/dtbschedmgr/test/unittest/common_event_listener_test.cpp diff --git a/services/dtbschedmgr/test/BUILD.gn b/services/dtbschedmgr/test/BUILD.gn index 0d320d62..e4bc105a 100644 --- a/services/dtbschedmgr/test/BUILD.gn +++ b/services/dtbschedmgr/test/BUILD.gn @@ -162,6 +162,9 @@ ohos_unittest("distributedschedservicetest") { "unittest/distributed_sched_service_second_test.cpp", "unittest/mock_distributed_sched.cpp", ] + if (dmsfwk_ces_listener) { + sources += [ "unittest/common_event_listener_test.cpp" ] + } sources += dtbschedmgr_sources configs = [ @@ -203,8 +206,13 @@ ohos_unittest("distributedschedstubtest") { public_deps = dsched_public_deps } + defines = [] if (dmsfwk_report_memmgr || dmsfwk_report_memmgr_plugins) { - defines = [ "SUPPORT_DISTRIBUTEDCOMPONENT_TO_MEMMGR" ] + defines += [ "SUPPORT_DISTRIBUTEDCOMPONENT_TO_MEMMGR" ] + } + + if (!dmsfwk_softbus_adapter_common) { + defines += [ "DMSFWK_INTERACTIVE_ADAPTER" ] } part_name = "dmsfwk" diff --git a/services/dtbschedmgr/test/unittest/bundle_manager_internal_test.cpp b/services/dtbschedmgr/test/unittest/bundle_manager_internal_test.cpp index 0f10a64e..2ef81228 100644 --- a/services/dtbschedmgr/test/unittest/bundle_manager_internal_test.cpp +++ b/services/dtbschedmgr/test/unittest/bundle_manager_internal_test.cpp @@ -31,11 +31,38 @@ using namespace testing::ext; namespace OHOS { namespace DistributedSchedule { + +static std::string g_mockString = ""; +static bool g_mockBool = false; + namespace { const string GROUP_ID = "TEST_GROUP_ID"; constexpr int32_t SLEEP_TIME = 1000; } +bool DmsBmStorage::GetBundleNameId(const std::string& bundleName, uint16_t &bundleNameId) +{ + return g_mockBool; +} + +std::string DmsBmStorage::GetContinueType(const std::string &networkId, std::string &bundleName, + uint8_t continueTypeId) +{ + return g_mockString; +} + +bool DmsBmStorage::GetContinueTypeId(const std::string &bundleName, const std::string &abilityName, + uint8_t &continueTypeId) +{ + return g_mockBool; +} + +bool DmsBmStorage::GetDistributedBundleName(const std::string &networkId, const uint16_t& bundleNameId, + std::string &bundleName) +{ + return g_mockBool; +} + void BundleManagerInternalTest::SetUpTestCase() { DTEST_LOG << "BundleManagerInternalTest::SetUpTestCase" << std::endl; @@ -646,5 +673,73 @@ HWTEST_F(BundleManagerInternalTest, GetBundleNameById_001, TestSize.Level3) EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR); DTEST_LOG << "BundleManagerInternalTest GetBundleNameById_001 end "<< std::endl; } + + +/** + * @tc.name: GetBundleNameId_003 + * @tc.desc: test get bundleNameId from bms + * @tc.type: FUNC + */ +HWTEST_F(BundleManagerInternalTest, GetBundleNameId_003, TestSize.Level3) +{ + DTEST_LOG << "BundleManagerInternalTest GetBundleNameId_003 begin" << std::endl; + const std::string bundleName = "com.ohos.mms"; + uint16_t bundleNameId = 0; + g_mockBool = true; + int32_t ret = BundleManagerInternal::GetBundleNameId(bundleName, bundleNameId); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "BundleManagerInternalTest GetBundleNameId_003 end "<< std::endl; +} + +/** + * @tc.name: GetContinueType_002 + * @tc.desc: GetContinueType + * @tc.type: FUNC + */ +HWTEST_F(BundleManagerInternalTest, GetContinueType_002, TestSize.Level3) +{ + DTEST_LOG << "BundleManagerInternalTest GetContinueType_002 begin" << std::endl; + std::string networkId = "networkId"; + std::string bundleName; + uint8_t continueTypeId = 0; + g_mockString = "continueType"; + std::string str = BundleManagerInternal::GetContinueType(networkId, bundleName, continueTypeId); + EXPECT_NE(str, ""); + DTEST_LOG << "BundleManagerInternalTest GetContinueType_002 end "<< std::endl; +} + +/** + * @tc.name: GetContinueTypeId_002 + * @tc.desc: GetContinueTypeId + * @tc.type: FUNC + */ +HWTEST_F(BundleManagerInternalTest, GetContinueTypeId_002, TestSize.Level3) +{ + DTEST_LOG << "BundleManagerInternalTest GetContinueTypeId_002 begin" << std::endl; + std::string networkId = "networkId"; + std::string abilityName; + uint8_t continueTypeId = 0; + g_mockBool = true; + int32_t ret = BundleManagerInternal::GetContinueTypeId(networkId, abilityName, continueTypeId); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "BundleManagerInternalTest GetContinueTypeId_002 end "<< std::endl; +} + +/** + * @tc.name: GetBundleNameById_002 + * @tc.desc: GetBundleNameById + * @tc.type: FUNC + */ +HWTEST_F(BundleManagerInternalTest, GetBundleNameById_002, TestSize.Level3) +{ + DTEST_LOG << "BundleManagerInternalTest GetBundleNameById_002 begin" << std::endl; + std::string networkId = "networkId"; + std::string bundleName; + uint16_t bundleNameId = 0; + g_mockBool = true; + int32_t ret = BundleManagerInternal::GetBundleNameById(networkId, bundleNameId, bundleName); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "BundleManagerInternalTest GetBundleNameById_002 end "<< std::endl; +} } } diff --git a/services/dtbschedmgr/test/unittest/common_event_listener_test.cpp b/services/dtbschedmgr/test/unittest/common_event_listener_test.cpp new file mode 100644 index 00000000..84bb0dd6 --- /dev/null +++ b/services/dtbschedmgr/test/unittest/common_event_listener_test.cpp @@ -0,0 +1,126 @@ +/* + * 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 "common_event_listener.h" + +#include "gtest/gtest.h" +#include "test_log.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace DistributedSchedule { +class CommonEventListenerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + std::shared_ptr applyMonitor = nullptr; +}; + +void CommonEventListenerTest::SetUpTestCase() +{ +} + +void CommonEventListenerTest::TearDownTestCase() +{ +} + +void CommonEventListenerTest::SetUp() +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + applyMonitor = std::make_shared(subscribeInfo); +} + +void CommonEventListenerTest::TearDown() +{ +} + +/** + * @tc.name: OnReceiveEvent001 + * @tc.desc: call OnReceiveEvent + * @tc.type: FUNC + */ +HWTEST_F(CommonEventListenerTest, OnReceiveEvent001, TestSize.Level3) +{ + DTEST_LOG << "CommonEventListenerTest OnReceiveEvent001 start" << std::endl; + AAFwk::Want want; + EventFwk::CommonEventData eventData; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED); + eventData.SetWant(want); + applyMonitor->OnReceiveEvent(eventData); + + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); + eventData.SetWant(want); + applyMonitor->OnReceiveEvent(eventData); + + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED); + eventData.SetWant(want); + applyMonitor->OnReceiveEvent(eventData); + + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); + eventData.SetWant(want); + applyMonitor->OnReceiveEvent(eventData); + + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); + eventData.SetWant(want); + EXPECT_NO_FATAL_FAILURE(applyMonitor->OnReceiveEvent(eventData)); + DTEST_LOG << "CommonEventListenerTest OnReceiveEvent001 end" << std::endl; +} + +/** + * @tc.name: OnReceiveEvent002 + * @tc.desc: call OnReceiveEvent + * @tc.type: FUNC + */ +HWTEST_F(CommonEventListenerTest, OnReceiveEvent002, TestSize.Level3) +{ + DTEST_LOG << "CommonEventListenerTest OnReceiveEvent002 start" << std::endl; + AAFwk::Want want; + EventFwk::CommonEventData eventData; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED); + eventData.SetWant(want); + applyMonitor->OnReceiveEvent(eventData); + + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED); + eventData.SetWant(want); + applyMonitor->OnReceiveEvent(eventData); + + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + eventData.SetWant(want); + applyMonitor->OnReceiveEvent(eventData); + + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED); + eventData.SetWant(want); + applyMonitor->OnReceiveEvent(eventData); + + want.SetAction("receiveEvent"); + eventData.SetWant(want); + EXPECT_NO_FATAL_FAILURE(applyMonitor->OnReceiveEvent(eventData)); + DTEST_LOG << "CommonEventListenerTest OnReceiveEvent002 end" << std::endl; +} +} +} diff --git a/services/dtbschedmgr/test/unittest/continue/dsched_continue_manager_test.cpp b/services/dtbschedmgr/test/unittest/continue/dsched_continue_manager_test.cpp index 52c7ed5d..5c6f703c 100644 --- a/services/dtbschedmgr/test/unittest/continue/dsched_continue_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/continue/dsched_continue_manager_test.cpp @@ -316,6 +316,7 @@ HWTEST_F(DSchedContinueManagerTest, GetContinueInfo_002, TestSize.Level3) DSchedContinueInfo info; std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); std::string localDeviceId = "localdeviceid"; std::string remoteDeviceId = "remotedeviceid"; DSchedContinueManager::GetInstance().continues_[info] = dContinue; @@ -546,6 +547,7 @@ HWTEST_F(DSchedContinueManagerTest, GetDSchedContinueByWant_002, TestSize.Level3 EXPECT_EQ(ret, nullptr); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); DSchedContinueManager::GetInstance().continues_[info] = nullptr; DSchedContinueManager::GetInstance().continues_[info] = dContinue; diff --git a/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.cpp b/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.cpp index 5f5f3daf..e59f1054 100644 --- a/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.cpp +++ b/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.cpp @@ -483,6 +483,7 @@ HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueDataTask001, TestSize.Level3 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = dataStateTest_->DoContinueDataTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueDataTask001 end" << std::endl; @@ -500,6 +501,7 @@ HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueDataTask002, TestSize.Level3 auto data = std::make_shared(); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_DATA_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); EXPECT_CALL(*mockStateTest_, GetLocalDeviceId(_)).WillOnce(Return(true)); int32_t ret = dataStateTest_->DoContinueDataTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); @@ -530,6 +532,7 @@ HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueEndTask001, TestSize.Level3) EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = dataStateTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueEndTask001 end" << std::endl; @@ -547,6 +550,7 @@ HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueEndTask002, TestSize.Level3) auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = dataStateTest_->DoContinueEndTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueEndTask002 end" << std::endl; @@ -576,6 +580,7 @@ HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueErrorTask001, TestSize.Level EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = dataStateTest_->DoContinueErrorTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueErrorTask001 end" << std::endl; @@ -593,6 +598,7 @@ HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueErrorTask002, TestSize.Level auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = dataStateTest_->DoContinueErrorTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueErrorTask002 end" << std::endl; @@ -683,6 +689,7 @@ HWTEST_F(DSchedContinueSinkEndStateTest, TestSinkDoContinueEndTask001, TestSize. EXPECT_NE(ret, ERR_OK); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); sinkEndStateTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_NE(ret, ERR_OK); DTEST_LOG << "DSchedContinueSinkEndStateTest TestSinkDoContinueEndTask001 end" << std::endl; @@ -700,6 +707,7 @@ HWTEST_F(DSchedContinueSinkEndStateTest, TestSinkDoContinueEndTask002, TestSize. auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = sinkEndStateTest_->DoContinueEndTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkEndStateTest TestSinkDoContinueEndTask002 end" << std::endl; @@ -792,6 +800,7 @@ HWTEST_F(DSchedContinueSinkStartStateTest, SinkDoContinuePullReqTaskTest_001, Te EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = sinkStartStateTest_->DoContinuePullReqTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -824,6 +833,7 @@ HWTEST_F(DSchedContinueSinkStartStateTest, SinkDoContinueAbilityTaskTest_001, Te EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = sinkStartStateTest_->DoContinueAbilityTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -856,6 +866,7 @@ HWTEST_F(DSchedContinueSinkStartStateTest, SinkDoContinueEndTaskTest_001, TestSi EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = sinkStartStateTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -887,6 +898,7 @@ HWTEST_F(DSchedContinueSinkStartStateTest, SinkDoContinueErrorTask001, TestSize. EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = sinkStartStateTest_->DoContinueErrorTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -980,6 +992,7 @@ HWTEST_F(DSchedContinueSinkWaitEndStateTest, SinkDoNotifyCompleteTask001, TestSi EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = sinkWaitEndTest_->DoNotifyCompleteTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoNotifyCompleteTask001 end" << std::endl; @@ -997,6 +1010,7 @@ HWTEST_F(DSchedContinueSinkWaitEndStateTest, SinkDoNotifyCompleteTask002, TestSi auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = sinkWaitEndTest_->DoNotifyCompleteTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoNotifyCompleteTask002 end" << std::endl; @@ -1027,6 +1041,7 @@ HWTEST_F(DSchedContinueSinkWaitEndStateTest, SinkDoContinueEndTask001, TestSize. EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = sinkWaitEndTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoContinueEndTask001 end" << std::endl; @@ -1044,6 +1059,7 @@ HWTEST_F(DSchedContinueSinkWaitEndStateTest, SinkDoContinueEndTask002, TestSize. auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = sinkWaitEndTest_->DoContinueEndTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoContinueEndTask002 end" << std::endl; @@ -1134,6 +1150,7 @@ HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueSendTask001, TestSize.Leve EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = abilityStateTest_->DoContinueSendTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueSendTask001 end" << std::endl; @@ -1151,6 +1168,7 @@ HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueSendTask002, TestSize.Leve auto data = std::make_shared(); auto event = AppExecFwk::InnerEvent::Get(DSHCED_CONTINUE_SEND_DATA_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = abilityStateTest_->DoContinueSendTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueSendTask002 end" << std::endl; @@ -1180,6 +1198,7 @@ HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueEndTask001, TestSize.Level EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = abilityStateTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueEndTask001 end" << std::endl; @@ -1197,6 +1216,7 @@ HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueErrorTask002, TestSize.Lev auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = abilityStateTest_->DoContinueErrorTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueErrorTask002 end" << std::endl; @@ -1226,6 +1246,7 @@ HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueErrorTask001, TestSize.Lev EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = abilityStateTest_->DoContinueErrorTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueErrorTask001 end" << std::endl; @@ -1243,6 +1264,7 @@ HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueEndTask002, TestSize.Level auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = abilityStateTest_->DoContinueEndTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueEndTask002 end" << std::endl; @@ -1333,6 +1355,7 @@ HWTEST_F(DSchedContinueEndStateTest, SrcDoContinueEndTaskTest001, TestSize.Level EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = srcEndStateTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueEndStateTest SrcDoContinueEndTaskTest001 end" << std::endl; @@ -1350,6 +1373,7 @@ HWTEST_F(DSchedContinueEndStateTest, SrcDoContinueEndTaskTest002, TestSize.Level auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = srcEndStateTest_->DoContinueEndTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueEndStateTest SrcDoContinueEndTaskTest002 end" << std::endl; @@ -1460,6 +1484,7 @@ HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinuePushReqTaskTest_002, T } }; std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = srcStartStateTest_->DoContinuePushReqTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -1491,6 +1516,7 @@ HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinuePushReqTaskTest_003, T auto wantParamsPtr = std::make_shared(wantParams); auto event = AppExecFwk::InnerEvent::Get(DSHCED_CONTINUE_REQ_PUSH_EVENT, wantParamsPtr, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = srcStartStateTest_->DoContinuePushReqTask(dContinue, event); EXPECT_NE(ret, ERR_OK); DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinuePushReqTaskTest_003 end" << std::endl; @@ -1534,6 +1560,7 @@ HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinueAbilityTaskTest_002, T auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSHCED_CONTINUE_ABILITY_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = srcStartStateTest_->DoContinueAbilityTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueAbilityTaskTest_002 end" << std::endl; @@ -1577,6 +1604,7 @@ HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinueEndTaskTest_002, TestS auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = srcStartStateTest_->DoContinueEndTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueEndTaskTest_002 end" << std::endl; @@ -1619,6 +1647,7 @@ HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinueErrorTaskTest_002, Tes auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = srcStartStateTest_->DoContinueErrorTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueErrorTaskTest_002 end" << std::endl; @@ -1710,6 +1739,7 @@ HWTEST_F(DSchedContinueWaitEndStateTest, SrcDoNotifyCompleteTask_001, TestSize.L EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = srcWaitEndTest_->DoNotifyCompleteTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoNotifyCompleteTask_001 end" << std::endl; @@ -1727,6 +1757,7 @@ HWTEST_F(DSchedContinueWaitEndStateTest, SrcDoNotifyCompleteTask_002, TestSize.L auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = srcWaitEndTest_->DoNotifyCompleteTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoNotifyCompleteTask_002 end" << std::endl; @@ -1757,6 +1788,7 @@ HWTEST_F(DSchedContinueWaitEndStateTest, SrcDoContinueEndTask_001, TestSize.Leve EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); ret = srcWaitEndTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoContinueEndTask_001 end" << std::endl; @@ -1774,6 +1806,7 @@ HWTEST_F(DSchedContinueWaitEndStateTest, SrcDoContinueEndTask_002, TestSize.Leve auto data = std::make_shared(1); auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); std::shared_ptr dContinue = CreateObject(); + usleep(WAITTIME); int32_t ret = srcWaitEndTest_->DoContinueEndTask(dContinue, event); EXPECT_NE(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoContinueEndTask_002 end" << std::endl; diff --git a/services/dtbschedmgr/test/unittest/continue/dsched_continue_test.cpp b/services/dtbschedmgr/test/unittest/continue/dsched_continue_test.cpp index 0eee55cf..a83d7553 100644 --- a/services/dtbschedmgr/test/unittest/continue/dsched_continue_test.cpp +++ b/services/dtbschedmgr/test/unittest/continue/dsched_continue_test.cpp @@ -88,6 +88,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_001_1, TestSize.Level0) // eventHandler_ not null conti->Init(); + usleep(WAITTIME); ret = conti->PostStartTask(wantParams); EXPECT_EQ(ret, ERR_OK); DTEST_LOG << "DSchedContinueTest DSchedContinueTest_001_1 end ret:" << ret << std::endl; @@ -120,6 +121,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_002_1, TestSize.Level0) // eventHandler_ not null conti->Init(); + usleep(WAITTIME); ret = conti->PostCotinueAbilityTask(appVersion); EXPECT_EQ(ret, ERR_OK); DTEST_LOG << "DSchedContinueTest DSchedContinueTest_002_1 end ret:" << ret << std::endl; @@ -153,6 +155,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_003_1, TestSize.Level0) // eventHandler_ not null conti->Init(); + usleep(WAITTIME); cmd->replyCmd_ = DSCHED_CONTINUE_END_EVENT; ret = conti->OnReplyCmd(cmd); @@ -202,6 +205,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_004_1, TestSize.Level0) // eventHandler_ not null conti->Init(); + usleep(WAITTIME); ret = conti->OnStartContinuation(want, callerUid, status, accessToken); EXPECT_EQ(ret, ERR_OK); @@ -242,6 +246,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_005_1, TestSize.Level0) // eventHandler_ not null conti->Init(); + usleep(WAITTIME); ret = conti->OnContinueDataCmd(cmd); EXPECT_EQ(ret, ERR_OK); @@ -292,6 +297,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_006_1, TestSize.Level0) // eventHandler_ not null conti->Init(); + usleep(WAITTIME); ret = conti->PostNotifyCompleteTask(ERR_OK); EXPECT_EQ(ret, ERR_OK); @@ -328,6 +334,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_007_1, TestSize.Level0) // eventHandler_ not null conti->Init(); + usleep(WAITTIME); ret = conti->PostContinueEndTask(result); EXPECT_EQ(ret, ERR_OK); DTEST_LOG << "DSchedContinueTest DSchedContinueTest_007_1 end ret:" << ret << std::endl; @@ -350,6 +357,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_008_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); auto wantParams = std::make_shared(); int32_t ret = conti->ExecuteContinueReq(wantParams); @@ -375,6 +383,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_009_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); auto cmd = std::make_shared(); auto wantParams = std::make_shared(); @@ -410,6 +419,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0010_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, deviceId, missionId); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t appVersion = 0; int32_t ret = conti->ExecuteContinueAbility(appVersion); @@ -434,6 +444,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0011_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, deviceId, missionId); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t ret = conti->GetMissionIdByBundleName(); EXPECT_EQ(ret, ERR_OK); @@ -457,6 +468,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0012_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t ret = conti->CheckContinueAbilityPermission(); EXPECT_EQ(ret, NO_MISSION_INFO_FOR_MISSION_ID); @@ -480,6 +492,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0013_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t ret = conti->ExecuteContinueReply(); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -503,6 +516,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0014_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); auto data = std::make_shared(); int32_t ret = conti->ExecuteContinueSend(data); @@ -531,6 +545,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0015_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); AAFwk::Want want; int32_t ret = conti->SetWantForContinuation(want); @@ -555,6 +570,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0016_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); auto cmd = std::make_shared(); OHOS::AAFwk::Want want; @@ -588,6 +604,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0017_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); auto cmd = std::make_shared(); @@ -618,6 +635,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0018_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t result = ERR_OK; int32_t ret = conti->ExecuteNotifyComplete(result); @@ -646,6 +664,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0019_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); auto cmd = std::make_shared(); int32_t replyCmd = 0; @@ -678,6 +697,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0020_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t result = 0; @@ -703,6 +723,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0021_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t result = 0; int32_t ret = conti->ExecuteContinueError(result); @@ -731,6 +752,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0022_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); auto cmd = std::make_shared(); int32_t result = 0; @@ -761,6 +783,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0023_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); auto cmd = std::make_shared(); int32_t ret = conti->SendCommand(cmd); @@ -785,6 +808,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0024_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); std::string localDeviceId; EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true)); @@ -810,6 +834,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_0025_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); bool ret = conti->CheckDeviceIdFromRemote("", "", ""); EXPECT_FALSE(ret); @@ -853,6 +878,7 @@ HWTEST_F(DSchedContinueTest, WaitAbilityStateInitialTest_0026_1, TestSize.Level0 auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t persistentId = 100; bool ret = conti->WaitAbilityStateInitial(persistentId); @@ -877,6 +903,7 @@ HWTEST_F(DSchedContinueTest, StartAbilityTest_0027_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); AAFwk::Want want; AppExecFwk::ElementName element("devicdId", "com.ohos.distributedmusicplayer", @@ -905,6 +932,7 @@ HWTEST_F(DSchedContinueTest, QuerySinkAbilityNameTest_0028_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, continueType); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); std::string sinkBundleName = conti->QuerySinkAbilityName(); EXPECT_TRUE(sinkBundleName.empty()); @@ -928,6 +956,7 @@ HWTEST_F(DSchedContinueTest, QuickStartAbilityTest_0029_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t ret = conti->QuickStartAbility(); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -951,6 +980,7 @@ HWTEST_F(DSchedContinueTest, UpdateWantForContinueTypeTest_0030_1, TestSize.Leve auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); AAFwk::Want want; AppExecFwk::ElementName element("devicdId", "com.ohos.distributedmusicplayer", @@ -978,6 +1008,7 @@ HWTEST_F(DSchedContinueTest, DSchedContinueTest_031_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); AppExecFwk::InnerEvent *event = nullptr; auto destructor = [](AppExecFwk::InnerEvent *event) { @@ -1011,6 +1042,7 @@ HWTEST_F(DSchedContinueTest, OnDataRecvTest_032_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t command = 0; std::shared_ptr dataBuffer = nullptr; @@ -1052,6 +1084,7 @@ HWTEST_F(DSchedContinueTest, UpdateStateTest_033_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); DSchedContinueStateType stateType = DSCHED_CONTINUE_SINK_START_STATE; conti->UpdateState(stateType); @@ -1079,6 +1112,7 @@ HWTEST_F(DSchedContinueTest, CheckStartPermission_034_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t ret = conti->CheckStartPermission(cmd); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -1108,6 +1142,7 @@ HWTEST_F(DSchedContinueTest, ConvertToDmsSdkErr_035_1, TestSize.Level0) auto info = DSchedContinueInfo(deviceId, bundleName, deviceId, bundleName, ""); auto conti = std::make_shared(subType, direction, callback, info); conti->Init(); + usleep(WAITTIME); int32_t ret = conti->ConvertToDmsSdkErr(0); EXPECT_EQ(ret, ERR_OK); diff --git a/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_params_test.cpp b/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_params_test.cpp index e60ba775..46f1f883 100644 --- a/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_params_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_params_test.cpp @@ -1154,4 +1154,30 @@ HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_ReadFromParcelPara bool result = wantParams.ReadFromParcelParam(parcel, key, type); EXPECT_TRUE(result); DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_ReadFromParcelParam_1000 end" << std::endl; -} \ No newline at end of file +} + +/** + * @tc.number: ReadFromParcelWantParamWrapper_1000 + * @tc.name: ReadFromParcelWantParamWrapper + * @tc.desc: Test ReadFromParcelWantParamWrapper. + * @tc.require: I77HFZ + */ +HWTEST_F(DistributedWantParamsBaseTest, ReadFromParcelWantParamWrapper_1000, Function | MediumTest | Level3) +{ + DTEST_LOG << "DistributedWantParamsBaseTest ReadFromParcelWantParamWrapper_1000 begin" << std::endl; + DistributedWantParams wantParams; + Parcel parcel; + std::string key = "this is key"; + int type = DistributedWantParams::VALUE_TYPE_FD; + int bufferSize = 1; + parcel.WriteInt32(bufferSize); + parcel.WriteInt32(0); + bool result = wantParams.ReadFromParcelWantParamWrapper(parcel, key, type); + EXPECT_TRUE(result); + + type = DistributedWantParams::VALUE_TYPE_REMOTE_OBJECT; + result = wantParams.ReadFromParcelWantParamWrapper(parcel, key, type); + EXPECT_TRUE(result); + DTEST_LOG << "DistributedWantParamsBaseTest ReadFromParcelWantParamWrapper_1000 end" << std::endl; +} + \ No newline at end of file diff --git a/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_test.cpp b/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_test.cpp index 87be16df..1c139195 100644 --- a/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_test.cpp @@ -3758,5 +3758,176 @@ HWTEST_F(DistributedWantBaseTest, GetLowerCaseScheme_test_003, TestSize.Level3) EXPECT_FALSE(strUri.empty()); GTEST_LOG_(INFO) << "GetLowerCaseScheme_test_003 end"; } + +/** + * @tc.number: GetLowerCaseScheme_test_004 + * @tc.name: GetLowerCaseScheme + * @tc.desc: Test GetLowerCaseScheme. + */ +HWTEST_F(DistributedWantBaseTest, GetLowerCaseScheme_test_004, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "GetLowerCaseScheme_test_004 start"; + DistributedWant want; + Uri lowerCaseUri("http://TEST.COM"); + Uri result = want.GetLowerCaseScheme(lowerCaseUri); + EXPECT_EQ(result, lowerCaseUri); + GTEST_LOG_(INFO) << "GetLowerCaseScheme_test_004 end"; +} + +/** + * @tc.number: ReadUriFromParcel_test_001 + * @tc.name: ReadUriFromParcel + * @tc.desc: Test ReadUriFromParcel. + */ +HWTEST_F(DistributedWantBaseTest, ReadUriFromParcel_test_001, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ReadUriFromParcel_test_001 start"; + DistributedWant want; + Parcel parcel; + parcel.WriteInt32(DistributedOperation::VALUE_OBJECT); + bool result = want.ReadUriFromParcel(parcel); + EXPECT_EQ(result, true); + GTEST_LOG_(INFO) << "ReadUriFromParcel_test_001 end"; +} + +/** + * @tc.number: CanReadFromJson_test_001 + * @tc.name: CanReadFromJson + * @tc.desc: Test CanReadFromJson. + */ +HWTEST_F(DistributedWantBaseTest, CanReadFromJson_test_001, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "CanReadFromJson_test_001 start"; + DistributedWant want; + nlohmann::json wantJson; + wantJson["deviceId"] = "device1"; + wantJson["bundleName"] = "bundle1"; + wantJson["abilityName"] = "ability1"; + wantJson["uri"] = "uri1"; + wantJson["type"] = "type1"; + wantJson["flags"] = 1; + wantJson["action"] = "action1"; + wantJson["parameters"] = "parameters1"; + bool result = want.CanReadFromJson(wantJson); + EXPECT_EQ(result, false); + + wantJson["deviceId"] = 1; + wantJson["entities"] = "entities1"; + result = want.CanReadFromJson(wantJson); + EXPECT_EQ(result, false); + + wantJson["deviceId"] = "device1"; + wantJson["bundleName"] = 1; + result = want.CanReadFromJson(wantJson); + EXPECT_EQ(result, false); + GTEST_LOG_(INFO) << "CanReadFromJson_test_001 end"; +} + +/** + * @tc.number: CanReadFromJson_test_002 + * @tc.name: CanReadFromJson + * @tc.desc: Test CanReadFromJson. + */ +HWTEST_F(DistributedWantBaseTest, CanReadFromJson_test_002, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "CanReadFromJson_test_002 start"; + DistributedWant want; + nlohmann::json wantJson; + wantJson["deviceId"] = "device1"; + wantJson["bundleName"] = "bundle1"; + wantJson["abilityName"] = 1; + wantJson["uri"] = "uri1"; + wantJson["type"] = "type1"; + wantJson["flags"] = 1; + wantJson["action"] = "action1"; + wantJson["parameters"] = "parameters1"; + wantJson["entities"] = "entities1"; + bool result = want.CanReadFromJson(wantJson); + EXPECT_EQ(result, false); + + wantJson["abilityName"] = "ability1"; + wantJson["uri"] = 1; + result = want.CanReadFromJson(wantJson); + EXPECT_EQ(result, false); + + wantJson["uri"] = "uri1"; + wantJson["type"] = 1; + result = want.CanReadFromJson(wantJson); + EXPECT_EQ(result, false); + GTEST_LOG_(INFO) << "CanReadFromJson_test_002 end"; +} + +/** + * @tc.number: CanReadFromJson_test_003 + * @tc.name: CanReadFromJson + * @tc.desc: Test CanReadFromJson. + */ +HWTEST_F(DistributedWantBaseTest, CanReadFromJson_test_003, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "CanReadFromJson_test_003 start"; + DistributedWant want; + nlohmann::json wantJson; + wantJson["deviceId"] = "device1"; + wantJson["bundleName"] = "bundle1"; + wantJson["abilityName"] = "ability1"; + wantJson["uri"] = "uri1"; + wantJson["type"] = "type1"; + wantJson["flags"] = "flags1"; + wantJson["action"] = "action1"; + wantJson["parameters"] = "parameters1"; + wantJson["entities"] = "entities1"; + bool result = want.CanReadFromJson(wantJson); + EXPECT_EQ(result, false); + + wantJson["flags"] = 1; + wantJson["action"] = 1; + result = want.CanReadFromJson(wantJson); + EXPECT_EQ(result, false); + + + wantJson["action"] = "action1"; + wantJson["parameters"] = 1; + result = want.CanReadFromJson(wantJson); + EXPECT_EQ(result, false); + GTEST_LOG_(INFO) << "CanReadFromJson_test_003 end"; +} + +/** + * @tc.number: ReadFromJson_test_001 + * @tc.name: ReadFromJson + * @tc.desc: Test ReadFromJson. + */ +HWTEST_F(DistributedWantBaseTest, ReadFromJson_test_001, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ReadFromJson_test_001 start"; + DistributedWant want; + nlohmann::json wantJson; + wantJson["deviceId"] = "device1"; + wantJson["bundleName"] = "bundle1"; + wantJson["abilityName"] = "ability1"; + wantJson["uri"] = "uri1"; + wantJson["type"] = "type1"; + wantJson["flags"] = 1; + wantJson["action"] = "action1"; + wantJson["parameters"] = "parameters1"; + wantJson["entities"] = "entities1"; + bool result = want.ReadFromJson(wantJson); + EXPECT_EQ(result, false); + GTEST_LOG_(INFO) << "ReadFromJson_test_001 end"; +} + +/** + * @tc.number: ReadFromJson_test_002 + * @tc.name: ReadFromJson + * @tc.desc: Test ReadFromJson. + */ +HWTEST_F(DistributedWantBaseTest, ReadFromJson_test_002, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ReadFromJson_test_002 start"; + DistributedWant want; + std::string str = ""; + EXPECT_EQ(want.FromString(str), nullptr); + GTEST_LOG_(INFO) << "ReadFromJson_test_002 end"; +} } // namespace DistributedSchedule } // namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp b/services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp index c764cb5d..d40346fd 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp @@ -2292,5 +2292,83 @@ HWTEST_F(DistributedSchedStubTest, NotifyDSchedEventResultFromRemoteInner_001, T EXPECT_NE(result, ERR_NULL_OBJECT); DTEST_LOG << "DistributedSchedStubTest NotifyDSchedEventResultFromRemoteInner_001 end" << std::endl; } + +#ifdef DMSFWK_INTERACTIVE_ADAPTER +/** + * @tc.name: StartAbilityFromRemoteAdapterInner_001 + * @tc.desc: check StartAbilityFromRemoteAdapterInner + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedStubTest, StartAbilityFromRemoteAdapterInner_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedStubTest StartAbilityFromRemoteAdapterInner_001 begin" << std::endl; + MessageParcel data; + MessageParcel reply; + int32_t result = DistributedSchedService::GetInstance().StartAbilityFromRemoteAdapterInner(data, reply); + EXPECT_NE(result, DMS_PERMISSION_DENIED); + DTEST_LOG << "DistributedSchedStubTest StartAbilityFromRemoteAdapterInner_001 end" << std::endl; +} + +/** + * @tc.name: StopAbilityFromRemoteAdapterInner_001 + * @tc.desc: check StopAbilityFromRemoteAdapterInner + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedStubTest, StopAbilityFromRemoteAdapterInner_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedStubTest StopAbilityFromRemoteAdapterInner_001 begin" << std::endl; + MessageParcel data; + MessageParcel reply; + int32_t result = DistributedSchedService::GetInstance().StopAbilityFromRemoteAdapterInner(data, reply); + EXPECT_NE(result, DMS_PERMISSION_DENIED); + DTEST_LOG << "DistributedSchedStubTest StopAbilityFromRemoteAdapterInner_001 end" << std::endl; +} + +/** + * @tc.name: ConnectAbilityFromRemoteAdapterInner_001 + * @tc.desc: check ConnectAbilityFromRemoteAdapterInner + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedStubTest, ConnectAbilityFromRemoteAdapterInner_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedStubTest ConnectAbilityFromRemoteAdapterInner_001 begin" << std::endl; + MessageParcel data; + MessageParcel reply; + int32_t result = DistributedSchedService::GetInstance().ConnectAbilityFromRemoteAdapterInner(data, reply); + EXPECT_NE(result, DMS_PERMISSION_DENIED); + DTEST_LOG << "DistributedSchedStubTest ConnectAbilityFromRemoteAdapterInner_001 end" << std::endl; +} + +/** + * @tc.name: DisconnectAbilityFromRemoteAdapterInner_001 + * @tc.desc: check DisconnectAbilityFromRemoteAdapterInner + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedStubTest, DisconnectAbilityFromRemoteAdapterInner_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedStubTest DisconnectAbilityFromRemoteAdapterInner_001 begin" << std::endl; + MessageParcel data; + MessageParcel reply; + int32_t result = DistributedSchedService::GetInstance().DisconnectAbilityFromRemoteAdapterInner(data, reply); + EXPECT_NE(result, DMS_PERMISSION_DENIED); + DTEST_LOG << "DistributedSchedStubTest DisconnectAbilityFromRemoteAdapterInner_001 end" << std::endl; +} + +/** + * @tc.name: NotifyAbilityLifecycleChangedFromRemoteAdapterInner_001 + * @tc.desc: check NotifyAbilityLifecycleChangedFromRemoteAdapterInner + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedStubTest, NotifyAbilityLifecycleChangedFromRemoteAdapterInner_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedStubTest NotifyAbilityLifecycleChangedFromRemoteAdapterInner_001 begin" << std::endl; + MessageParcel data; + MessageParcel reply; + int32_t result = DistributedSchedService::GetInstance().NotifyAbilityLifecycleChangedFromRemoteAdapterInner( + data, reply); + EXPECT_NE(result, DMS_PERMISSION_DENIED); + DTEST_LOG << "DistributedSchedStubTest NotifyAbilityLifecycleChangedFromRemoteAdapterInner_001 end" << std::endl; +} +#endif } } \ No newline at end of file diff --git a/services/dtbschedmgr/test/unittest/dms_network_adapter_test.cpp b/services/dtbschedmgr/test/unittest/dms_network_adapter_test.cpp index 734319a3..295947b9 100644 --- a/services/dtbschedmgr/test/unittest/dms_network_adapter_test.cpp +++ b/services/dtbschedmgr/test/unittest/dms_network_adapter_test.cpp @@ -432,5 +432,34 @@ HWTEST_F(DMSNetworkAdapterTest, UpdateDeviceInfoStorage_001, TestSize.Level3) bool result = DnetworkAdapter::GetInstance()->UpdateDeviceInfoStorage(); EXPECT_EQ(result, true); } + +/** + * @tc.name: OnDeviceTrustChange_001 + * @tc.desc: test OnDeviceTrustChange + * @tc.type: FUNC + */ +HWTEST_F(DMSNetworkAdapterTest, OnDeviceTrustChange_001, TestSize.Level3) +{ + std::string udid = ""; + std::string uuid = ""; + DnetworkAdapter::GetInstance()->Init(); + DnetworkAdapter::GetInstance()->devTrustChangeCallback_->OnDeviceTrustChange( + udid, uuid, DistributedHardware::DmAuthForm::IDENTICAL_ACCOUNT); + + udid = "udid"; + DnetworkAdapter::GetInstance()->devTrustChangeCallback_->OnDeviceTrustChange( + udid, uuid, DistributedHardware::DmAuthForm::IDENTICAL_ACCOUNT); + + udid = ""; + uuid = "uuid"; + DnetworkAdapter::GetInstance()->devTrustChangeCallback_->OnDeviceTrustChange( + udid, uuid, DistributedHardware::DmAuthForm::IDENTICAL_ACCOUNT); + + udid = "udid"; + uuid = "uuid"; + DnetworkAdapter::GetInstance()->devTrustChangeCallback_->OnDeviceTrustChange( + udid, uuid, DistributedHardware::DmAuthForm::IDENTICAL_ACCOUNT); + EXPECT_EQ(udid.empty(), false); +} } // namespace DistributedSchedule } // namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp index fbf6dad4..481c2ecf 100644 --- a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp @@ -15,10 +15,6 @@ #include "dms_continue_manager_test.h" -#ifdef DMSFWK_INTERACTIVE_ADAPTER -#include "broadcast.h" -#endif - #include "datetime_ex.h" #include "distributed_sched_test_util.h" #include "dtbschedmgr_log.h" @@ -32,13 +28,6 @@ using namespace testing; using namespace testing::ext; -#ifdef DMSFWK_INTERACTIVE_ADAPTER -int32_t SendEvent(const char* pkgName, BroadCastAddr target, EventData *event) -{ - return 1; -} -#endif - namespace OHOS { namespace DistributedSchedule { namespace { @@ -70,6 +59,7 @@ void DMSContinueManagerTest::TearDownTestCase() void DMSContinueManagerTest::SetUp() { + MultiUserManager::GetInstance().Init(); } void DMSContinueManagerTest::TearDown() @@ -92,12 +82,8 @@ HWTEST_F(DMSContinueManagerTest, testUnInit001, TestSize.Level3) DTEST_LOG << "DMSContinueManagerTest testUnInit001 begin" << std::endl; DistributedSchedUtil::MockManageMissions(); - MultiUserManager::GetInstance().Init(); auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->Init(); EXPECT_NE(sendMgr->eventHandler_, nullptr); @@ -127,12 +113,8 @@ HWTEST_F(DMSContinueManagerTest, testUnInit002, TestSize.Level3) DTEST_LOG << "DMSContinueManagerTest testUnInit002 begin" << std::endl; DistributedSchedUtil::MockManageMissions(); - MultiUserManager::GetInstance().Init(); auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->Init(); EXPECT_NE(sendMgr->eventHandler_, nullptr); @@ -151,12 +133,8 @@ HWTEST_F(DMSContinueManagerTest, testPostUnfocusedTaskWithDelay001, TestSize.Lev DTEST_LOG << "DMSContinueManagerTest testPostUnfocusedTaskWithDelay001 begin" << std::endl; DistributedSchedUtil::MockManageMissions(); - MultiUserManager::GetInstance().Init(); auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->Init(); /** @@ -186,12 +164,8 @@ HWTEST_F(DMSContinueManagerTest, testNotifyMissionFocused001, TestSize.Level3) DTEST_LOG << "DMSContinueManagerTest testNotifyMissionFocused001 begin" << std::endl; DistributedSchedUtil::MockManageMissions(); - MultiUserManager::GetInstance().Init(); auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->Init(); /** @@ -221,12 +195,8 @@ HWTEST_F(DMSContinueManagerTest, testNotifyMissionUnfocused001, TestSize.Level3) DTEST_LOG << "DMSContinueManagerTest testNotifyMissionUnfocused001 begin" << std::endl; DistributedSchedUtil::MockManageMissions(); - MultiUserManager::GetInstance().Init(); auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->Init(); /** * @tc.steps: step1. test NotifyMissionUnfocused when eventHandler is not nullptr; @@ -252,10 +222,7 @@ HWTEST_F(DMSContinueManagerTest, testRegisterOnListener001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest testRegisterOnListener001 start" << std::endl; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->Init(); sptr obj01(new RemoteOnListenerStubTest()); int32_t ret = recvMgr->RegisterOnListener(TYPE, obj01); @@ -281,10 +248,7 @@ HWTEST_F(DMSContinueManagerTest, testRegisterOffListener001, TestSize.Level1) DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener001 start" << std::endl; sptr obj01(new RemoteOnListenerStubTest()); auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); int32_t ret = recvMgr->RegisterOnListener(TYPE, obj01); ret = recvMgr->RegisterOffListener(TYPE, obj01); EXPECT_EQ(ret, ERR_OK); @@ -305,10 +269,7 @@ HWTEST_F(DMSContinueManagerTest, testRegisterOffListener002, TestSize.Level3) DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener002 start" << std::endl; sptr obj01(new RemoteOnListenerStubTest()); auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); int32_t ret = recvMgr->RegisterOnListener(TYPE, obj01); EXPECT_EQ(ret, ERR_OK); @@ -330,10 +291,7 @@ HWTEST_F(DMSContinueManagerTest, testGetMissionId001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest testGetMissionId001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->focusedMission_[BUNDLENAME_01] = MISSIONID_01; int32_t missionId; int32_t ret = sendMgr->GetMissionIdByBundleName(BUNDLENAME_01, missionId); @@ -359,10 +317,7 @@ HWTEST_F(DMSContinueManagerTest, testDealFocusedBusiness001, TestSize.Level3) * @tc.steps: step1. test DealFocusedBusiness when missionId is invalid; */ auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); int32_t ret = sendMgr->DealFocusedBusiness(-1, FocusedReason::MIN); EXPECT_NE(ret, ERR_OK); @@ -383,10 +338,7 @@ HWTEST_F(DMSContinueManagerTest, testDealUnfocusedBusiness001, TestSize.Level3) * @tc.steps: step1. test DealUnfocusedBusiness when missionId is invalid; */ auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); int32_t ret = sendMgr->DealUnfocusedBusiness(-1, UnfocusedReason::NORMAL); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -403,10 +355,7 @@ HWTEST_F(DMSContinueManagerTest, testDealUnfocusedBusiness001, TestSize.Level3) */ sptr obj01 = nullptr; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->NotifyDied(obj01); /** @@ -438,10 +387,7 @@ HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource001, TestSize.Level3) std::string sinkBundleName = "test sinkBundleName"; std::string continueType = "test continueType"; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); int32_t ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state); EXPECT_EQ(ret, ERR_OK); @@ -466,10 +412,7 @@ HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource002, TestSize.Level3) std::string sinkBundleName = "test sinkBundleName"; std::string continueType = "test continueType"; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); int32_t ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state); EXPECT_EQ(ret, ERR_OK); @@ -494,10 +437,7 @@ HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource003, TestSize.Level3) std::string sinkBundleName = "test sinkBundleName"; std::string continueType = "test continueType"; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); int32_t ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state); EXPECT_EQ(ret, ERR_OK); @@ -527,10 +467,7 @@ HWTEST_F(DMSContinueManagerTest, testDealOnBroadcastBusiness001, TestSize.Level3 int32_t state = 0; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->PostOnBroadcastBusiness(senderNetworkId, bundleNameId, continueTypeId, state); int32_t ret = recvMgr->DealOnBroadcastBusiness(senderNetworkId, bundleNameId, continueTypeId, state, 0); @@ -569,10 +506,7 @@ HWTEST_F(DMSContinueManagerTest, testGetBundleName001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest testGetBundleName001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->focusedMission_[BUNDLENAME_01] = MISSIONID_01; std::string bundleName; int32_t ret = sendMgr->GetBundleNameByMissionId(MISSIONID_01, bundleName); @@ -593,10 +527,7 @@ HWTEST_F(DMSContinueManagerTest, testIsContinue001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest testIsContinue001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->focusedMission_[BUNDLENAME_02] = MISSIONID_02; sendMgr->info_.currentMissionId = MISSIONID_01; sendMgr->info_.currentIsContinuable = true; @@ -622,10 +553,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDied001, TestSize.Level1) DTEST_LOG << "DMSContinueManagerTest testNotifyDied001 start" << std::endl; sptr obj01(new RemoteOnListenerStubTest()); auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); int32_t ret = recvMgr->RegisterOnListener(TYPE, obj01); EXPECT_EQ(false, recvMgr->registerOnListener_.empty()); recvMgr->NotifyDied(obj01); @@ -641,12 +569,8 @@ HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState001, TestSize.Level3 { DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState001 start" << std::endl; DistributedSchedUtil::MockManageMissions(); - MultiUserManager::GetInstance().Init(); auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->Init(); OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE; @@ -674,12 +598,8 @@ HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState002, TestSize.Level3 { DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState002 start" << std::endl; DistributedSchedUtil::MockManageMissions(); - MultiUserManager::GetInstance().Init(); auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->Init(); OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_INACTIVE; @@ -708,10 +628,7 @@ HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness001, Tes DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness001 start" << std::endl; OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->info_.currentMissionId = MISSIONID_01; /** @@ -739,10 +656,7 @@ HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness002, Tes { DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness002 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->info_.currentIsContinuable = true; OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE; int32_t ret = sendMgr->DealSetMissionContinueStateBusiness(MISSIONID_01, state); @@ -764,12 +678,8 @@ HWTEST_F(DMSContinueManagerTest, testOnDeviceScreenOff001, TestSize.Level1) /** * @tc.steps: step1. test OnDeviceScreenOff when eventHandler is not nullptr; */ - MultiUserManager::GetInstance().Init(); auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->Init(); sendMgr->OnDeviceScreenOff(); EXPECT_NE(sendMgr->eventHandler_, nullptr); @@ -793,10 +703,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline001 start" << std::endl; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->iconInfo_.senderNetworkId = NETWORKID_01; recvMgr->NotifyDeviceOffline(NETWORKID_01); @@ -815,10 +722,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline002, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline002 start" << std::endl; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->iconInfo_.senderNetworkId = NETWORKID_01; recvMgr->NotifyDeviceOffline(""); EXPECT_EQ(recvMgr->iconInfo_.senderNetworkId, NETWORKID_01); @@ -835,10 +739,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline003, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 start" << std::endl; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->iconInfo_.senderNetworkId = NETWORKID_01; recvMgr->NotifyDeviceOffline(NETWORKID_02); EXPECT_EQ(recvMgr->iconInfo_.senderNetworkId, NETWORKID_01); @@ -856,10 +757,7 @@ HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved001, TestSize.Level1) DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved001 start" << std::endl; sptr obj01(new RemoteOnListenerStubTest()); auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->RegisterOnListener(TYPE, obj01); EXPECT_NE(recvMgr->registerOnListener_.size(), 0); @@ -879,10 +777,7 @@ HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved002, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved002 start" << std::endl; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->iconInfo_.bundleName = BUNDLENAME_01; recvMgr->NotifyPackageRemoved(""); EXPECT_EQ(recvMgr->iconInfo_.bundleName, BUNDLENAME_01); @@ -899,10 +794,7 @@ HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved003, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved003 start" << std::endl; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->iconInfo_.bundleName = BUNDLENAME_01; recvMgr->NotifyPackageRemoved(BUNDLENAME_02); EXPECT_EQ(recvMgr->iconInfo_.bundleName, BUNDLENAME_01); @@ -922,10 +814,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDataRecv001, TestSize.Level1) uint8_t payload[] = {0xf0}; uint32_t dataLen1 = DMS_SEND_LEN - 1; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->NotifyDataRecv(senderNetworkId, payload, dataLen1); uint32_t dataLen2 = DMS_SEND_LEN; @@ -946,10 +835,7 @@ HWTEST_F(DMSContinueManagerTest, testSendSoftbusEvent001, TestSize.Level1) uint8_t continueType = 1; uint8_t type = 0; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); bool ret = sendMgr->SendSoftbusEvent(bundleNameId, continueType, type); EXPECT_NE(ret, CAN_NOT_FOUND_ABILITY_ERR); DTEST_LOG << "DMSContinueManagerTest testSendSoftbusEvent001 end" << std::endl; @@ -964,10 +850,7 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOnline001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOnline001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); int32_t ret = sendMgr->NotifyDeviceOnline(); EXPECT_EQ(ret, ERR_OK); DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOnline001 end" << std::endl; @@ -982,10 +865,7 @@ HWTEST_F(DMSContinueManagerTest, testGetAbilityNameByMissionId_001, TestSize.Lev { DTEST_LOG << "DMSContinueManagerTest testGetAbilityNameByMissionId_001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->focusedMissionAbility_[MISSIONID_01] = ABILITY_NAME_01; std::string abilityName; int32_t ret = sendMgr->GetAbilityNameByMissionId(MISSIONID_01, abilityName); @@ -1003,10 +883,7 @@ HWTEST_F(DMSContinueManagerTest, testFocusedBusinessSendEvent_001, TestSize.Leve { DTEST_LOG << "DMSContinueManagerTest testFocusedBusinessSendEvent_001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); int32_t ret = sendMgr->FocusedBusinessSendEvent(BUNDLENAME_01, ABILITY_NAME_01); EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR); @@ -1022,10 +899,7 @@ HWTEST_F(DMSContinueManagerTest, testGetBundleNameIdAndContinueTypeId_001, TestS { DTEST_LOG << "DMSContinueManagerTest testGetBundleNameIdAndContinueTypeId_001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->focusedMission_[BUNDLENAME_01] = MISSIONID_01; sendMgr->focusedMissionAbility_[MISSIONID_01] = ABILITY_NAME_01; uint16_t bundleNameId = 0; @@ -1051,10 +925,7 @@ HWTEST_F(DMSContinueManagerTest, testGetContinueType_001, TestSize.Level1) std::string sinkBundleName = "test sinkBundleName"; std::string continueType = "test continueType"; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); int32_t ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state); EXPECT_EQ(ret, ERR_OK); @@ -1075,10 +946,7 @@ HWTEST_F(DMSContinueManagerTest, testSetScreenOffInfo_001, TestSize.Level1) uint16_t bundleNameId = 0; std::string abilityName = "abilityName"; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->screenOffHandler_ = std::make_shared(); sendMgr->screenOffHandler_->SetScreenOffInfo(missionId, bundleName, @@ -1099,10 +967,7 @@ HWTEST_F(DMSContinueManagerTest, testSetStateSendEvent_001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest testSetStateSendEvent_001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); int32_t ret = sendMgr->SetStateSendEvent(0, 0, AAFwk::ContinueState::CONTINUESTATE_INACTIVE); EXPECT_NE(ret, DMS_PERMISSION_DENIED); @@ -1121,10 +986,7 @@ HWTEST_F(DMSContinueManagerTest, testGetContinueLaunchMissionInfo_001, TestSize. DTEST_LOG << "DMSContinueManagerTest testGetContinueLaunchMissionInfo_001 start" << std::endl; ContinueLaunchMissionInfo missionInfo = {"com.test.missionInfo", "MainAbility"}; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->continueLaunchMission_.clear(); int32_t ret = sendMgr->GetContinueLaunchMissionInfo(MISSIONID_01, missionInfo); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -1151,10 +1013,7 @@ HWTEST_F(DMSContinueManagerTest, testUpdateContinueLaunchMission_001, TestSize.L info.id = MISSIONID_01; info.want = want; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); EXPECT_FALSE(sendMgr->UpdateContinueLaunchMission(info)); info.want.SetFlags(AAFwk::Want::FLAG_ABILITY_CONTINUATION); @@ -1178,10 +1037,7 @@ HWTEST_F(DMSContinueManagerTest, testGetFinalBundleName_001, TestSize.Level1) AppExecFwk::BundleInfo localBundleInfo; std::string continueType; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); bool ret = recvMgr->GetFinalBundleName(info, finalBundleName, localBundleInfo, continueType); EXPECT_EQ(ret, false); DTEST_LOG << "DMSContinueManagerTest testGetFinalBundleName_001 end" << std::endl; @@ -1211,10 +1067,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_001, TestSize.Level1) localBundleInfo.abilityInfos = abilityInfos; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType, isSameBundle); EXPECT_EQ(ret, false); @@ -1250,10 +1103,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_002, TestSize.Level1) localBundleInfo.abilityInfos = abilityInfos; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType, isSameBundle); EXPECT_EQ(ret, true); @@ -1291,10 +1141,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_003, TestSize.Level1) localBundleInfo.abilityInfos = abilityInfos; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType, isSameBundle); EXPECT_EQ(ret, false); @@ -1327,10 +1174,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_004, TestSize.Level1) localBundleInfo.abilityInfos = abilityInfos; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType, isSameBundle); EXPECT_EQ(ret, false); @@ -1363,10 +1207,7 @@ HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_005, TestSize.Level1) localBundleInfo.abilityInfos = abilityInfos; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcContinueType, isSameBundle); EXPECT_EQ(ret, true); @@ -1382,10 +1223,7 @@ HWTEST_F(DMSContinueManagerTest, GetBundleNameByScreenOffInfo_001, TestSize.Leve { DTEST_LOG << "DMSContinueManagerTest GetBundleNameByScreenOffInfo_001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->screenOffHandler_ = nullptr; int32_t missionId = 0; std::string bundleName; @@ -1415,10 +1253,7 @@ HWTEST_F(DMSContinueManagerTest, SendScreenOffEvent_001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest SendScreenOffEvent_001 start" << std::endl; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->screenOffHandler_ = nullptr; int32_t ret = sendMgr->SendScreenOffEvent(DMS_FOCUSED_TYPE); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); @@ -1439,10 +1274,7 @@ HWTEST_F(DMSContinueManagerTest, DeleteContinueLaunchMissionInfo_001, TestSize.L DTEST_LOG << "DMSContinueManagerTest DeleteContinueLaunchMissionInfo_001 start" << std::endl; int32_t missionId = 0; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); sendMgr->continueLaunchMission_.clear(); sendMgr->DeleteContinueLaunchMissionInfo(missionId); @@ -1463,10 +1295,7 @@ HWTEST_F(DMSContinueManagerTest, CheckContinueState_001, TestSize.Level1) DTEST_LOG << "DMSContinueManagerTest CheckContinueState_001 start" << std::endl; int32_t missionId = 0; auto sendMgr = MultiUserManager::GetInstance().GetCurrentSendMgr(); - if (sendMgr == nullptr) { - DTEST_LOG << "GetSendMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, sendMgr); int32_t ret = sendMgr->CheckContinueState(missionId); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DMSContinueManagerTest CheckContinueState_001 end" << std::endl; @@ -1481,10 +1310,7 @@ HWTEST_F(DMSContinueManagerTest, OnContinueSwitchOff_001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest OnContinueSwitchOff_001 start" << std::endl; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->iconInfo_.senderNetworkId = ""; recvMgr->iconInfo_.bundleName = ""; recvMgr->iconInfo_.continueType = ""; @@ -1509,10 +1335,7 @@ HWTEST_F(DMSContinueManagerTest, OnUserSwitch_001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest OnUserSwitch_001 start" << std::endl; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); recvMgr->iconInfo_.senderNetworkId = ""; recvMgr->iconInfo_.bundleName = ""; recvMgr->iconInfo_.continueType = ""; @@ -1537,10 +1360,7 @@ HWTEST_F(DMSContinueManagerTest, FindToNotifyRecvBroadcast_001, TestSize.Level1) { DTEST_LOG << "DMSContinueManagerTest FindToNotifyRecvBroadcast_001 start" << std::endl; auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - if (recvMgr == nullptr) { - DTEST_LOG << "GetRecvMgr failed." << std::endl; - return; - } + ASSERT_NE(nullptr, recvMgr); std::string senderNetworkId = "senderNetworkId"; std::string bundleName = "bundleName"; std::string continueType = "senderNetworkId"; diff --git a/services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp b/services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp index 919bd8ed..76798499 100644 --- a/services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/multi_user_manager_test.cpp @@ -253,34 +253,6 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentRecvMgr_001, TestSize. DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_001 end" << std::endl; } -/** - * @tc.name: MultiUserManager_GetCurrentRecvMgr_002 - * @tc.desc: test GetCurrentRecvMgr - * @tc.type: FUNC - */ -HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentRecvMgr_002, TestSize.Level3) -{ - DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_002 start" << std::endl; - /** - * @tc.steps: step1. test OnUserRemoved with create current user recvMgr; - */ - int32_t accountId = 100; - MultiUserManager::GetInstance().Init(); - auto recvMgr = MultiUserManager::GetInstance().recvMgrMap_.find(accountId)->second; - MultiUserManager::GetInstance().hasRegSoftbusEventListener_ = false; - auto ret = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - EXPECT_EQ(ret, recvMgr); - EXPECT_TRUE(MultiUserManager::GetInstance().hasRegSoftbusEventListener_); - - MultiUserManager::GetInstance().recvMgrMap_.insert({accountId, nullptr}); - ret = MultiUserManager::GetInstance().GetCurrentRecvMgr(); - EXPECT_NE(ret, nullptr); - - - MultiUserManager::GetInstance().UnInit(); - DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_002 end" << std::endl; -} - /** * @tc.name: MultiUserManager_CheckRegSoftbusListener_001 * @tc.desc: test CheckRegSoftbusListener diff --git a/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_transport_test.cpp b/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_transport_test.cpp index 5c8b7529..e0cefe09 100644 --- a/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_transport_test.cpp +++ b/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_transport_test.cpp @@ -465,12 +465,10 @@ HWTEST_F(DSchedSoftbusSessionTest, GetFragDataHeader_001, TestSize.Level3) HWTEST_F(DSchedSoftbusSessionTest, PackRecvData_001, TestSize.Level3) { DTEST_LOG << "DSchedSoftbusSessionTest PackRecvData_001 begin" << std::endl; - int32_t sessionId = 0; std::shared_ptr buffer = std::make_shared(DSCHED_BUFFER_SIZE_100); softbusSessionTest_ = std::make_shared(); ASSERT_NE(softbusSessionTest_, nullptr); - softbusSessionTest_->PackRecvData(buffer); - EXPECT_EQ(0, sessionId); + EXPECT_NO_FATAL_FAILURE(softbusSessionTest_->PackRecvData(buffer)); DTEST_LOG << "DSchedSoftbusSessionTest PackRecvData_001 end" << std::endl; } @@ -483,7 +481,6 @@ HWTEST_F(DSchedSoftbusSessionTest, PackRecvData_001, TestSize.Level3) HWTEST_F(DSchedSoftbusSessionTest, AssembleNoFrag_001, TestSize.Level3) { DTEST_LOG << "DSchedSoftbusSessionTest AssembleFrag_001 begin" << std::endl; - int32_t sessionId = 0; std::shared_ptr buffer = std::make_shared(SIZE_1); DSchedSoftbusSession::SessionDataHeader headerPara = {0, 0, 0, SEQ_1, 0, SEQ_2, TOTALLEN_1}; softbusSessionTest_ = std::make_shared(); @@ -491,8 +488,7 @@ HWTEST_F(DSchedSoftbusSessionTest, AssembleNoFrag_001, TestSize.Level3) softbusSessionTest_->AssembleNoFrag(buffer, headerPara); headerPara.totalLen = TOTALLEN_1; - softbusSessionTest_->AssembleNoFrag(buffer, headerPara); - EXPECT_EQ(0, sessionId); + EXPECT_NO_FATAL_FAILURE(softbusSessionTest_->AssembleNoFrag(buffer, headerPara)); DTEST_LOG << "DSchedSoftbusSessionTest AssembleNoFrag_001 end" << std::endl; } @@ -504,7 +500,6 @@ HWTEST_F(DSchedSoftbusSessionTest, AssembleNoFrag_001, TestSize.Level3) HWTEST_F(DSchedSoftbusSessionTest, AssembleFrag_001, TestSize.Level3) { DTEST_LOG << "DSchedSoftbusSessionTest AssembleFrag_001 begin" << std::endl; - int32_t sessionId = 0; std::shared_ptr buffer = std::make_shared(SIZE_1); DSchedSoftbusSession::SessionDataHeader headerPara = {0, DSchedSoftbusSession::FRAG_START, 0, SEQ_1, 0, SEQ_2, TOTALLEN_1}; @@ -514,8 +509,7 @@ HWTEST_F(DSchedSoftbusSessionTest, AssembleFrag_001, TestSize.Level3) headerPara.fragFlag = DSchedSoftbusSession::FRAG_MID; softbusSessionTest_->AssembleFrag(buffer, headerPara); headerPara.fragFlag = DSchedSoftbusSession::FRAG_END; - softbusSessionTest_->AssembleFrag(buffer, headerPara); - EXPECT_EQ(0, sessionId); + EXPECT_NO_FATAL_FAILURE(softbusSessionTest_->AssembleFrag(buffer, headerPara)); DTEST_LOG << "DSchedSoftbusSessionTest AssembleFrag_001 end" << std::endl; } @@ -527,7 +521,6 @@ HWTEST_F(DSchedSoftbusSessionTest, AssembleFrag_001, TestSize.Level3) HWTEST_F(DSchedSoftbusSessionTest, SetHeadParaDataLen_001, TestSize.Level3) { DTEST_LOG << "DSchedSoftbusSessionTest SetHeadParaDataLen_001 begin" << std::endl; - int32_t sessionId = 0; DSchedSoftbusSession::SessionDataHeader headerPara = {0, 0, 0, SEQ_1, 0, SEQ_2, TOTALLEN_1}; uint32_t totalLen = TOTALLEN; uint32_t offset = OFFSET_1; @@ -537,8 +530,7 @@ HWTEST_F(DSchedSoftbusSessionTest, SetHeadParaDataLen_001, TestSize.Level3) softbusSessionTest_->SetHeadParaDataLen(headerPara, totalLen, offset, maxSendSize); offset = DSCHED_BUFFER_SIZE_100; softbusSessionTest_->SetHeadParaDataLen(headerPara, totalLen, offset, maxSendSize); - softbusSessionTest_->GetNowTimeStampUs(); - EXPECT_EQ(0, sessionId); + EXPECT_NO_FATAL_FAILURE(softbusSessionTest_->GetNowTimeStampUs()); DTEST_LOG << "DSchedSoftbusSessionTest SetHeadParaDataLen_001 end" << std::endl; } @@ -550,7 +542,6 @@ HWTEST_F(DSchedSoftbusSessionTest, SetHeadParaDataLen_001, TestSize.Level3) HWTEST_F(DSchedSoftbusSessionTest, MakeFragDataHeader_001, TestSize.Level3) { DTEST_LOG << "DSchedSoftbusSessionTest MakeFragDataHeader_001 begin" << std::endl; - int32_t sessionId = 0; DSchedSoftbusSession::SessionDataHeader headerPara = {0}; uint8_t *header = new uint8_t[DSCHED_BUFFER_SIZE_100] {0}; uint32_t len = HEADERLEN; @@ -558,8 +549,7 @@ HWTEST_F(DSchedSoftbusSessionTest, MakeFragDataHeader_001, TestSize.Level3) ASSERT_NE(softbusSessionTest_, nullptr); softbusSessionTest_->MakeFragDataHeader(headerPara, header, len); uint8_t *header1 = new uint8_t[HEADERLEN] {0}; - softbusSessionTest_->MakeFragDataHeader(headerPara, header1, len); - EXPECT_EQ(0, sessionId); + EXPECT_NO_FATAL_FAILURE(softbusSessionTest_->MakeFragDataHeader(headerPara, header1, len)); delete[] header; delete[] header1; DTEST_LOG << "DSchedSoftbusSessionTest MakeFragDataHeader_001 end" << std::endl; @@ -573,7 +563,6 @@ HWTEST_F(DSchedSoftbusSessionTest, MakeFragDataHeader_001, TestSize.Level3) HWTEST_F(DSchedSoftbusSessionTest, WriteTlvToBuffer_001, TestSize.Level3) { DTEST_LOG << "DSchedSoftbusSessionTest WriteTlvToBuffer_001 begin" << std::endl; - int32_t sessionId = 0; DSchedSoftbusSession::TlvItem tlvItem = {SIZE_4, SIZE_4, SEQ_2}; uint8_t *buffer = new uint8_t[SIZE_50] {0}; uint32_t bufLen = SIZE_50; @@ -582,8 +571,7 @@ HWTEST_F(DSchedSoftbusSessionTest, WriteTlvToBuffer_001, TestSize.Level3) softbusSessionTest_->WriteTlvToBuffer(tlvItem, buffer, bufLen); uint8_t * buffer1 = new uint8_t[SEQ_1] {0}; uint32_t bufLen1 = SIZE_1; - softbusSessionTest_->WriteTlvToBuffer(tlvItem, buffer1, bufLen1); - EXPECT_EQ(0, sessionId); + EXPECT_NO_FATAL_FAILURE(softbusSessionTest_->WriteTlvToBuffer(tlvItem, buffer1, bufLen1)); delete[] buffer; delete[] buffer1; DTEST_LOG << "DSchedSoftbusSessionTest WriteTlvToBuffer_001 end" << std::endl; From 4c785895e8b58548c8e2de1dd4a3b13ef05d46be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=88=E7=9A=93=E6=9D=B0?= Date: Fri, 15 Nov 2024 13:53:54 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=B6=E5=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 师皓杰 --- .../test/unittest/softbus_adapter/softbus_adapter_test.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_adapter_test.cpp b/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_adapter_test.cpp index 28346e1a..930a4691 100644 --- a/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_adapter_test.cpp +++ b/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_adapter_test.cpp @@ -28,6 +28,7 @@ namespace DistributedSchedule { namespace { const std::string NETWORKID_01 = "networkId01"; constexpr int32_t RETRY_SENT_EVENT_MAX_TIME = 3; +const int32_t WAITTIME = 2000; } void SoftbusAdapterTest::SetUpTestCase() @@ -64,8 +65,8 @@ HWTEST_F(SoftbusAdapterTest, SendSoftbusEvent_001, TestSize.Level3) int32_t result = SoftbusAdapter::GetInstance().SendSoftbusEvent(buffer); EXPECT_EQ(result, SOFTBUS_OK); - SoftbusMock sortbusMock; SoftbusAdapter::GetInstance().Init(); + usleep(WAITTIME); result = SoftbusAdapter::GetInstance().SendSoftbusEvent(buffer); EXPECT_EQ(result, SOFTBUS_OK); SoftbusAdapter::GetInstance().UnInit(); @@ -88,6 +89,7 @@ HWTEST_F(SoftbusAdapterTest, DealSendSoftbusEvent_001, TestSize.Level3) EXPECT_EQ(result, INVALID_PARAMETERS_ERR); SoftbusAdapter::GetInstance().Init(); + usleep(WAITTIME); result = SoftbusAdapter::GetInstance().DealSendSoftbusEvent(nullptr, retry); EXPECT_EQ(result, INVALID_PARAMETERS_ERR); @@ -124,6 +126,7 @@ HWTEST_F(SoftbusAdapterTest, RetrySendSoftbusEvent_001, TestSize.Level3) EXPECT_EQ(result, INVALID_PARAMETERS_ERR); SoftbusAdapter::GetInstance().Init(); + usleep(WAITTIME); result = SoftbusAdapter::GetInstance().RetrySendSoftbusEvent(buffer, retry); EXPECT_EQ(result, ERR_OK); SoftbusAdapter::GetInstance().UnInit(); From cfdbecf4244bb04342c5ac29a6ff0e7f214748c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A6=E5=9B=BD=E5=BA=86?= Date: Mon, 18 Nov 2024 10:19:04 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E7=84=B6=E5=90=8E=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=AE=A1=E7=90=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韦国庆 --- services/dtbschedmgr/include/multi_user_manager.h | 10 +++++++++- services/dtbschedmgr/src/multi_user_manager.cpp | 14 +++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/services/dtbschedmgr/include/multi_user_manager.h b/services/dtbschedmgr/include/multi_user_manager.h index f11bd57d..bfb845f0 100644 --- a/services/dtbschedmgr/include/multi_user_manager.h +++ b/services/dtbschedmgr/include/multi_user_manager.h @@ -26,7 +26,15 @@ namespace OHOS { namespace DistributedSchedule { class MultiUserManager { - DECLARE_SINGLE_INSTANCE(MultiUserManager); +public: + static MultiUserManager& GetInstance(); +private: + MultiUserManager(const MultiUserManager&) = delete; + MultiUserManager& operator= (const MultiUserManager&) = delete; + MultiUserManager(MultiUserManager&&) = delete; + MultiUserManager& operator= (MultiUserManager&&) = delete; + MultiUserManager(); + ~MultiUserManager() = default; public: void Init(); diff --git a/services/dtbschedmgr/src/multi_user_manager.cpp b/services/dtbschedmgr/src/multi_user_manager.cpp index 254128b0..90dc5182 100644 --- a/services/dtbschedmgr/src/multi_user_manager.cpp +++ b/services/dtbschedmgr/src/multi_user_manager.cpp @@ -31,7 +31,19 @@ namespace { const std::string TAG = "MultiUserManager"; } -IMPLEMENT_SINGLE_INSTANCE(MultiUserManager); +MultiUserManager& MultiUserManager::GetInstance() +{ + static auto instance = new MultiUserManager(); + return *instance; +} + +MultiUserManager::MultiUserManager() +{ + HILOGI("Start."); + if (currentUserId_ <= 0) { + Init(); + } +} void MultiUserManager::Init() { From 504e222a1887061eca339336305d75ef3819fa86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=88=E7=9A=93=E6=9D=B0?= Date: Tue, 19 Nov 2024 16:51:02 +0800 Subject: [PATCH 6/7] add service ut MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 师皓杰 --- .../distributed_sched_service_second_test.cpp | 99 +++++++++++++++++++ .../dtbschedmgr_device_info_storage_test.cpp | 62 +++++++++++- .../mission/dms_continue_manager_test.cpp | 6 ++ 3 files changed, 165 insertions(+), 2 deletions(-) diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_service_second_test.cpp b/services/dtbschedmgr/test/unittest/distributed_sched_service_second_test.cpp index 8671e234..df526a6a 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_service_second_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributed_sched_service_second_test.cpp @@ -1617,5 +1617,104 @@ HWTEST_F(DistributedSchedServiceSecondTest, NotifyDSchedEventResultFromRemote_00 EXPECT_EQ(ret, ERR_OK); DTEST_LOG << "DistributedSchedServiceSecondTest NotifyDSchedEventResultFromRemote_001 end" << std::endl; } + +/** + * @tc.name: ContinueLocalMission_001 + * @tc.desc: ContinueLocalMission + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceSecondTest, ContinueLocalMission_001, TestSize.Level3) +{ + DTEST_LOG << "DistributedSchedServiceSecondTest ContinueLocalMission_001 start" << std::endl; + std::string dstDeviceId; + int32_t missionId = 0; + OHOS::AAFwk::WantParams wantParams; + DistributedSchedService::GetInstance().dschedContinuation_ = nullptr; + int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMission( + dstDeviceId, missionId, nullptr, wantParams); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = DistributedSchedService::GetInstance().ContinueAbilityWithTimeout( + dstDeviceId, missionId, nullptr, 0); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + DistributedSchedService::GetInstance().NotifyDSchedEventCallbackResult(FOREGROUND); + + ret = DistributedSchedService::GetInstance().NotifyContinuationResultFromRemote( + FOREGROUND, true, dstDeviceId); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DistributedSchedServiceSecondTest ContinueLocalMission_001 end" << std::endl; +} + +/** + * @tc.name: GetContinueInfo_001 + * @tc.desc: GetContinueInfo + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceSecondTest, GetContinueInfo_001, TestSize.Level3) +{ + DTEST_LOG << "DistributedSchedServiceSecondTest GetContinueInfo_001 start" << std::endl; + std::string dstNetworkId; + std::string srcNetworkId; + DistributedSchedService::GetInstance().dschedContinuation_ = nullptr; + int32_t ret = DistributedSchedService::GetInstance().GetContinueInfo(dstNetworkId, srcNetworkId); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared(); + ret = DistributedSchedService::GetInstance().GetContinueInfo(dstNetworkId, srcNetworkId); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DistributedSchedServiceSecondTest GetContinueInfo_001 end" << std::endl; +} + +/** + * @tc.name: GetDSchedEventInfo_001 + * @tc.desc: GetDSchedEventInfo + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceSecondTest, GetDSchedEventInfo_001, TestSize.Level3) +{ + DTEST_LOG << "DistributedSchedServiceSecondTest GetDSchedEventInfo_001 start" << std::endl; + std::vector events; + int32_t ret = DistributedSchedService::GetInstance().GetDSchedEventInfo(DMS_CONTINUE, events); + EXPECT_EQ(ret, ERR_OK); + + ret = DistributedSchedService::GetInstance().GetDSchedEventInfo(DMS_ALL, events); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DistributedSchedServiceSecondTest GetDSchedEventInfo_001 end" << std::endl; +} + +/** + * @tc.name: RegisterDSchedEventListener_001 + * @tc.desc: RegisterDSchedEventListener + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceSecondTest, RegisterDSchedEventListener_001, TestSize.Level3) +{ + DTEST_LOG << "DistributedSchedServiceSecondTest RegisterDSchedEventListener_001 start" << std::endl; + DistributedSchedService::GetInstance().dschedContinuation_ = nullptr; + DistributedSchedService::GetInstance().collaborateCbMgr_ = nullptr; + int32_t ret = DistributedSchedService::GetInstance().RegisterDSchedEventListener(DMS_CONTINUE, nullptr); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DMS_CONTINUE, nullptr); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared(); + ret = DistributedSchedService::GetInstance().RegisterDSchedEventListener(DMS_CONTINUE, nullptr); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DMS_CONTINUE, nullptr); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + DistributedSchedService::GetInstance().collaborateCbMgr_ = std::make_shared(); + DistributedSchedService::GetInstance().collaborateCbMgr_->Init(); + auto callback = GetDSchedService(); + ret = DistributedSchedService::GetInstance().RegisterDSchedEventListener(DMS_COLLABORATION, callback); + EXPECT_EQ(ret, ERR_OK); + + ret = DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DMS_COLLABORATION, callback); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DistributedSchedServiceSecondTest RegisterDSchedEventListener_001 end" << std::endl; +} } } diff --git a/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp b/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp index f8769e44..fce16534 100644 --- a/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp +++ b/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp @@ -444,12 +444,70 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetNetworkIdList_001, TestSize.Level3 std::string netWorkId = "netWorkId"; devices = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdList(); EXPECT_EQ(devices.empty(), true); - - std::shared_ptr deviceInfo = std::make_shared("deviceName", 0, "netWorkId"); + + std::shared_ptr deviceInfo = nullptr; + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[netWorkId] = deviceInfo; + devices = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdList(); + EXPECT_EQ(devices.empty(), true); + + deviceInfo = std::make_shared("deviceName", 0, "netWorkId"); DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[netWorkId] = deviceInfo; devices = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdList(); EXPECT_EQ(devices.empty(), false); DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetNetworkIdList_001 end" << std::endl; } + +/** + * @tc.name: InitNetworkIdManager_001 + * @tc.desc: test InitNetworkIdManager + * @tc.type: FUNC + */ +HWTEST_F(DtbschedmgrDeviceInfoStorageTest, InitNetworkIdManager_001, TestSize.Level3) +{ + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest InitNetworkIdManager_001 start" << std::endl; + bool ret = DtbschedmgrDeviceInfoStorage::GetInstance().InitNetworkIdManager(nullptr); + EXPECT_EQ(ret, false); + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest InitNetworkIdManager_001 end" << std::endl; +} + +/** + * @tc.name: RegisterUuidNetworkIdMap_001 + * @tc.desc: test RegisterUuidNetworkIdMap + * @tc.type: FUNC + */ +HWTEST_F(DtbschedmgrDeviceInfoStorageTest, RegisterUuidNetworkIdMap_001, TestSize.Level3) +{ + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest RegisterUuidNetworkIdMap_001 start" << std::endl; + std::string networkId = "networkId"; + EXPECT_NO_FATAL_FAILURE(DtbschedmgrDeviceInfoStorage::GetInstance().RegisterUuidNetworkIdMap(networkId)); + EXPECT_NO_FATAL_FAILURE(DtbschedmgrDeviceInfoStorage::GetInstance().UnregisterUuidNetworkIdMap(networkId)); + EXPECT_NO_FATAL_FAILURE(DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(nullptr)); + networkId = ""; + EXPECT_NO_FATAL_FAILURE(DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOfflineNotify(networkId)); + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest RegisterUuidNetworkIdMap_001 end" << std::endl; +} + +/** + * @tc.name: GetDeviceName_002 + * @tc.desc: test GetDeviceName + * @tc.type: FUNC + */ +HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetDeviceName_002, TestSize.Level3) +{ + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetDeviceName_002 start" << std::endl; + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear(); + std::string netWorkId = "netWorkId"; + std::shared_ptr deviceInfo = nullptr; + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[netWorkId] = deviceInfo; + std::string str = DtbschedmgrDeviceInfoStorage::GetInstance().GetDeviceName(netWorkId); + EXPECT_EQ(str, ""); + + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear(); + deviceInfo = std::make_shared("deviceName", 0, "netWorkId"); + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[netWorkId] = deviceInfo; + str = DtbschedmgrDeviceInfoStorage::GetInstance().GetDeviceName(netWorkId); + EXPECT_EQ(str, "deviceName"); + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetDeviceName_002 end" << std::endl; +} } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp index 481c2ecf..1e0cde3a 100644 --- a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp @@ -23,6 +23,7 @@ #include "mission/dms_continue_recv_manager.h" #undef private #include "multi_user_manager.h" +#include "softbus_adapter/softbus_adapter.h" #include "test_log.h" using namespace testing; @@ -49,6 +50,11 @@ constexpr int32_t DBMS_RETRY_MAX_TIME = 5; constexpr uint8_t DMS_FOCUSED_TYPE = 0x00; } +int32_t SoftbusAdapter::SendSoftbusEvent(std::shared_ptr buffer) +{ + return CAN_NOT_FOUND_ABILITY_ERR; +} + void DMSContinueManagerTest::SetUpTestCase() { } From f3c95dc72ec4233ab322e3f0e0953c302f11c855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=88=E7=9A=93=E6=9D=B0?= Date: Wed, 20 Nov 2024 11:30:54 +0800 Subject: [PATCH 7/7] fix ut log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 师皓杰 --- .../test/unittest/mission/distributed_bm_storage_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/dtbschedmgr/test/unittest/mission/distributed_bm_storage_test.cpp b/services/dtbschedmgr/test/unittest/mission/distributed_bm_storage_test.cpp index 3868e88e..1a31fba0 100644 --- a/services/dtbschedmgr/test/unittest/mission/distributed_bm_storage_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/distributed_bm_storage_test.cpp @@ -43,7 +43,6 @@ constexpr uint16_t ONE = 1; bool DtbschedmgrDeviceInfoStorage::GetLocalUdid(std::string& udid) { udid = g_mockGetLocalUdid; - DTEST_LOG << "shihaojie GetLocalUdid" << std::endl; return true; }