From 58288d540bd3bf746a1f987b61a86c9f8d799501 Mon Sep 17 00:00:00 2001 From: zhangmingxiang Date: Sat, 27 Aug 2022 15:50:52 +0800 Subject: [PATCH] add distributedschedsvrtest unittest Signed-off-by: zhangmingxiang Change-Id: If74534de2908eb482ac1ff21dbf94d8d30afaf5a --- services/dtbschedmgr/test/BUILD.gn | 5 +- .../distributed_sched_service_test.cpp | 209 ++++++++++++++++++ 2 files changed, 213 insertions(+), 1 deletion(-) diff --git a/services/dtbschedmgr/test/BUILD.gn b/services/dtbschedmgr/test/BUILD.gn index 91d25d4d..9db67779 100644 --- a/services/dtbschedmgr/test/BUILD.gn +++ b/services/dtbschedmgr/test/BUILD.gn @@ -119,7 +119,10 @@ if (dmsfwk_standard_form_share) { ohos_unittest("distributedschedsvrtest") { module_out_path = module_output_path - sources = [ "unittest/distributed_sched_service_test.cpp" ] + sources = [ + "unittest/distributed_sched_service_test.cpp", + "unittest/mock_distributed_sched.cpp", + ] sources += dtbschedmgr_sources configs = [ ":test_config", diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_service_test.cpp b/services/dtbschedmgr/test/unittest/distributed_sched_service_test.cpp index c431bff9..833352d7 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_service_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributed_sched_service_test.cpp @@ -27,6 +27,7 @@ #include "ipc_skeleton.h" #include "iservice_registry.h" #include "mock_form_mgr_service.h" +#include "mock_distributed_sched.h" #include "system_ability_definition.h" #include "test_log.h" #include "thread_pool.h" @@ -44,7 +45,11 @@ using namespace AAFwk; using namespace AppExecFwk; namespace { const string LOCAL_DEVICEID = "192.168.43.100"; + const string REMOTE_DEVICEID = "255.255.255.255"; + const std::u16string DEVICE_ID = u"192.168.43.100"; + constexpr int32_t SESSION_ID = 123; const std::string DMS_MISSION_ID = "dmsMissionId"; + constexpr int32_t MISSION_ID = 1; const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId"; const int DEFAULT_REQUEST_CODE = -1; } @@ -63,6 +68,7 @@ protected: LOOP_TIME = 10, LOOP_PRESSURE_TIME = 100, }; + sptr GetDSchedService() const; void GetAbilityInfo(const std::string& package, const std::string& name, const std::string& bundleName, const std::string& deviceId, OHOS::AppExecFwk::AbilityInfo& abilityInfo); @@ -104,6 +110,12 @@ sptr DistributedSchedServiceTest::GetDms() return proxy_; } +sptr DistributedSchedServiceTest::GetDSchedService() const +{ + sptr dsched = new MockDistributedSched(); + return dsched; +} + void DistributedSchedServiceTest::GetAbilityInfo(const std::string& package, const std::string& name, const std::string& bundleName, const std::string& deviceId, OHOS::AppExecFwk::AbilityInfo& abilityInfo) { @@ -742,6 +754,7 @@ HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_004, TestSize.Level1) DTEST_LOG << "result2:" << result2 << std::endl; DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_004 end" << std::endl; } + /** * @tc.name: StartRemoteShareForm_001 * @tc.desc: call StartRemoteShareForm with dms @@ -814,5 +827,201 @@ HWTEST_F(DistributedSchedServiceTest, StartShareFormFromRemote_002, TestSize.Lev EXPECT_EQ(static_cast(INVALID_REMOTE_PARAMETERS_ERR), result); DTEST_LOG << "DistributedSchedServiceTest StartShareFormFromRemote_002 end" << std::endl; } + +/** + * @tc.name: StartAbilityFromRemote_006 + * @tc.desc: call StartAbilityFromRemote + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_006, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_006 start" << std::endl; + AAFwk::Want want; + std::string localDeviceId; + DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId); + AppExecFwk::ElementName element(localDeviceId, "com.ohos.distributedmusicplayer", + "com.ohos.distributedmusicplayer.MainAbility"); + want.SetElement(element); + AppExecFwk::AbilityInfo abilityInfo; + GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility", + "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo); + abilityInfo.visible = true; + abilityInfo.permissions.clear(); + CallerInfo callerInfo; + callerInfo.uid = 0; + callerInfo.sourceDeviceId = LOCAL_DEVICEID; + IDistributedSched::AccountInfo accountInfo; + accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE; + accountInfo.groupIdList.push_back("123456"); + int result = DistributedSchedService::GetInstance().StartAbilityFromRemote(want, + abilityInfo, 0, callerInfo, accountInfo); + DTEST_LOG << "result:" << result << std::endl; + EXPECT_EQ(static_cast(INVALID_PARAMETERS_ERR), result); + DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_006 end" << std::endl; +} + +/** + * @tc.name: SendResultFromRemote_006 + * @tc.desc: call SendResultFromRemote + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_006, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_006 start" << std::endl; + AAFwk::Want want; + AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer", + "com.ohos.distributedmusicplayer.MainAbility"); + want.SetElement(element); + std::string localDeviceId; + DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId); + want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId); + CallerInfo callerInfo; + callerInfo.uid = 0; + callerInfo.sourceDeviceId = LOCAL_DEVICEID; + IDistributedSched::AccountInfo accountInfo; + int result = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0); + DTEST_LOG << "result:" << result << std::endl; + EXPECT_EQ(static_cast(INVALID_PARAMETERS_ERR), result); + DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_006 end" << std::endl; +} + +/** + * @tc.name: RemoveContinuationTimeout_001 + * @tc.desc: call RemoveContinuationTimeout + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, RemoveContinuationTimeout_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedServiceTest RemoveContinuationTimeout_001 start" << std::endl; + if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) { + DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared(); + } + int32_t missionId = MISSION_ID; + DistributedSchedService::GetInstance().RemoveContinuationTimeout(missionId); + DTEST_LOG << "DistributedSchedServiceTest RemoveContinuationTimeout_001 end" << std::endl; +} + +/** + * @tc.name: SetContinuationTimeout_001 + * @tc.desc: call GetContinuaitonDevice + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, SetContinuationTimeout_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedServiceTest SetContinuationTimeout_001 start" << std::endl; + if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) { + DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared(); + } + int32_t missionId = MISSION_ID; + int32_t timeout = 5; + DistributedSchedService::GetInstance().SetContinuationTimeout(missionId, timeout); + DTEST_LOG << "DistributedSchedServiceTest SetContinuationTimeout_001 end" << std::endl; +} + +/** + * @tc.name: GetContinuaitonDevice_001 + * @tc.desc: call GetContinuaitonDevice + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, GetContinuaitonDevice_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedServiceTest GetContinuaitonDevice_001 start" << std::endl; + if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) { + DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared(); + } + int32_t missionId = MISSION_ID; + (void)DistributedSchedService::GetInstance().GetContinuaitonDevice(missionId); + DTEST_LOG << "DistributedSchedServiceTest GetContinuaitonDevice_001 end" << std::endl; +} + +/** + * @tc.name: ContinueMission_001 + * @tc.desc: call ContinueMission + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, ContinueMission_001, TestSize.Level1) +{ + DTEST_LOG << "DSchedContinuationTest ContinueMission_001 start" << std::endl; + WantParams wantParams; + auto callback = GetDSchedService(); + int32_t missionId = MISSION_ID; + std::string localDeviceId; + DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId); + int32_t result = DistributedSchedService::GetInstance().ContinueMission( + "string", localDeviceId, missionId, callback, wantParams); + EXPECT_EQ(static_cast(INVALID_REMOTE_PARAMETERS_ERR), result); + DTEST_LOG << "DSchedContinuationTest ContinueMission_001 end" << std::endl; +} + +/** + * @tc.name: ContinueMission_002 + * @tc.desc: call ContinueMission + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, ContinueMission_002, TestSize.Level1) +{ + DTEST_LOG << "DSchedContinuationTest ContinueMission_002 start" << std::endl; + WantParams wantParams; + auto callback = GetDSchedService(); + int32_t missionId = MISSION_ID; + std::string localDeviceId; + DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId); + int32_t result = DistributedSchedService::GetInstance().ContinueMission( + "string", "string", missionId, callback, wantParams); + EXPECT_EQ(static_cast(INVALID_PARAMETERS_ERR), result); + DTEST_LOG << "DSchedContinuationTest ContinueMission_002 end" << std::endl; +} + +/** + * @tc.name: StartContinuation_001 + * @tc.desc: call StartContinuation + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, StartContinuation_001, TestSize.Level1) +{ + DTEST_LOG << "DSchedContinuationTest StartContinuation_001 start" << std::endl; + AAFwk::Want want; + AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer", + "com.ohos.distributedmusicplayer.MainAbility"); + want.SetElement(element); + int32_t missionId = MISSION_ID; + int32_t callerUid = 0; + int32_t status = 1; + uint32_t accessToken = 0; + int32_t ret = DistributedSchedService::GetInstance().StartContinuation( + want, missionId, callerUid, status, accessToken); + EXPECT_EQ(static_cast(INVALID_REMOTE_PARAMETERS_ERR), ret); + DTEST_LOG << "DSchedContinuationTest StartContinuation_001 end" << std::endl; +} + +/** + * @tc.name: NotifyCompleteContinuation_001 + * @tc.desc: call NotifyCompleteContinuation + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, NotifyCompleteContinuation_001, TestSize.Level1) +{ + DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 start" << std::endl; + bool isSuccess = false; + DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID, SESSION_ID, isSuccess); + DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 end" << std::endl; +} + +/** + * @tc.name: NotifyContinuationCallbackResult_001 + * @tc.desc: call NotifyContinuationCallbackResult + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceTest, NotifyContinuationCallbackResult_001, TestSize.Level1) +{ + DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_001 start" << std::endl; + if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) { + DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared(); + } + int32_t missionId = MISSION_ID; + bool isSuccess = false; + DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, isSuccess); + DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_001 end" << std::endl; +} } // namespace DistributedSchedule } // namespace OHOS \ No newline at end of file