1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <thread>
16 
17 #include "dfx/dms_continue_time_dumper.h"
18 #include "distributed_sched_continuation_test.h"
19 #include "distributed_sched_test_util.h"
20 #include "dms_constant.h"
21 #include "dtbschedmgr_device_info_storage.h"
22 #include "ipc_skeleton.h"
23 #include "mock_distributed_sched.h"
24 #include "mock_remote_stub.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS::AAFwk;
29 using namespace OHOS::AppExecFwk;
30 using namespace OHOS::DistributedHardware;
31 
32 namespace OHOS {
33 namespace DistributedSchedule {
34 using namespace Constants;
35 namespace {
36 const std::u16string MOCK_DEVICE_ID = u"MOCK_DEVICE_ID";
37 constexpr int32_t MOCK_SESSION_ID = 123;
38 constexpr int32_t MOCK_TASK_ID = 456;
39 const std::string LOCAL_DEVICE_ID = "192.168.43.100";
40 const string DMS_VERSION_ID = "dmsVersion";
41 constexpr int32_t SLEEP_TIME = 1000;
42 constexpr int64_t FREE_INSTALL_TIMEOUT = 50000;
43 constexpr int32_t REQUEST_CODE_ERR = 305;
44 }
45 
SetUpTestCase()46 void DSchedContinuationTest::SetUpTestCase()
47 {
48     if (!DistributedSchedUtil::LoadDistributedSchedService()) {
49         DTEST_LOG << "DSchedContinuationTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
50     }
51     const std::string pkgName = "DBinderBus_" + std::to_string(getprocpid());
52     std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
53     DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
54     std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
55 }
56 
TearDownTestCase()57 void DSchedContinuationTest::TearDownTestCase()
58 {
59 }
60 
SetUp()61 void DSchedContinuationTest::SetUp()
62 {
63     DistributedSchedUtil::MockPermission();
64     dschedContinuation_ = std::make_shared<DSchedContinuation>();
65 }
66 
TearDown()67 void DSchedContinuationTest::TearDown()
68 {
69     dschedContinuation_ = nullptr;
70 }
71 
OnRemoteDied()72 void DSchedContinuationTest::DeviceInitCallBack::OnRemoteDied()
73 {
74 }
75 
GetDSchedService() const76 sptr<IRemoteObject> DSchedContinuationTest::GetDSchedService() const
77 {
78     sptr<IRemoteObject> dsched(new MockDistributedSched());
79     if (dsched == nullptr) {
80         DTEST_LOG << "GetDSchedService dsched is null" << std::endl;
81         return nullptr;
82     }
83     return dsched;
84 }
85 
PushAbilityToken()86 int32_t DSchedContinuationTest::PushAbilityToken()
87 {
88     if (dschedContinuation_ == nullptr) {
89         DTEST_LOG << "dschedContinuation_ is null" << std::endl;
90         return -1;
91     }
92     FuncContinuationCallback continuationCallback = [this] (int32_t missionId) {
93         timeoutFlag_ = true;
94     };
95     dschedContinuation_->Init(continuationCallback);
96     int32_t sessionId = dschedContinuation_->GenerateSessionId();
97     dschedContinuation_->PushAbilityToken(sessionId, GetDSchedService());
98     return sessionId;
99 }
100 
MockWant(const std::string & bundleName,const std::string & ability,int32_t flags)101 std::shared_ptr<Want> DSchedContinuationTest::MockWant(const std::string& bundleName,
102     const std::string& ability, int32_t flags)
103 {
104     ElementName element("", bundleName, ability);
105     std::shared_ptr<Want> spWant = std::make_shared<Want>();
106     if (spWant == nullptr) {
107         DTEST_LOG << "spWant is null" << std::endl;
108         return nullptr;
109     }
110     spWant->SetElement(element);
111     spWant->SetFlags(flags);
112     return spWant;
113 }
114 
MockOnStart()115 void DSchedContinuationTest::MockOnStart()
116 {
117     DTEST_LOG << "mock on start" << std::endl;
118     if (!DistributedSchedService::GetInstance().Init()) {
119         DTEST_LOG << "init failed" << std::endl;
120         return;
121     }
122     FuncContinuationCallback continuationCallback = [this] (int32_t missionId) {
123         DistributedSchedService::GetInstance().
124             NotifyContinuationCallbackResult(missionId, CONTINUE_ABILITY_TIMEOUT_ERR);
125     };
126 
127     DmsCallbackTaskInitCallbackFunc freeCallback = [this] (int64_t taskId) {
128         DistributedSchedService::GetInstance().
129             NotifyCompleteFreeInstallFromRemote(taskId, FREE_INSTALL_TIMEOUT);
130     };
131     DistributedSchedService::GetInstance().dschedContinuation_ =
132         std::make_shared<DSchedContinuation>();
133     DistributedSchedService::GetInstance().dmsCallbackTask_ =
134         std::make_shared<DmsCallbackTask>();
135     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
136         DTEST_LOG << "MockOnStart dschedContinuation_ is nullptr" << std::endl;
137         return;
138     }
139     if (DistributedSchedService::GetInstance().dmsCallbackTask_ == nullptr) {
140         DTEST_LOG << "MockOnStart dmsCallbackTask_ is nullptr" << std::endl;
141         return;
142     }
143     DistributedSchedService::GetInstance().dschedContinuation_->Init(continuationCallback);
144     DistributedSchedService::GetInstance().dmsCallbackTask_->Init(freeCallback);
145 }
146 
GetDms()147 sptr<IDistributedSched> DSchedContinuationTest::GetDms()
148 {
149     if (proxy_ != nullptr) {
150         return proxy_;
151     }
152     auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
153     EXPECT_TRUE(sm != nullptr);
154     if (sm == nullptr) {
155         DTEST_LOG << "DSchedContinuationTest sm is nullptr" << std::endl;
156         return nullptr;
157     }
158     DTEST_LOG << "DSchedContinuationTest sm is not nullptr" << std::endl;
159     auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
160     proxy_ = iface_cast<IDistributedSched>(distributedObject);
161     if (proxy_ == nullptr) {
162         DTEST_LOG << "DSchedContinuationTest DistributedSched is nullptr" << std::endl;
163         return nullptr;
164     } else {
165         DTEST_LOG << "DSchedContinuationTest DistributedSched is not nullptr" << std::endl;
166     }
167     return proxy_;
168 }
169 
StartContinuation(int32_t missionId,int32_t flags)170 int32_t DSchedContinuationTest::StartContinuation(int32_t missionId, int32_t flags)
171 {
172     std::string bundleName = "bundleName";
173     std::string abilityName = "abilityName";
174     std::string devId = "devId";
175     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, flags);
176     int callerUid = 0;
177     if (spWant == nullptr) {
178         DTEST_LOG << "StartContinuation spWant is nullptr" << std::endl;
179         return -1;
180     }
181     return DistributedSchedService::GetInstance().StartContinuation(*spWant, missionId, callerUid, 0, 0);
182 }
183 
StartRemoteFreeInstall(int32_t flags,const sptr<IRemoteObject> & callback)184 int32_t DSchedContinuationTest::StartRemoteFreeInstall(int32_t flags, const sptr<IRemoteObject>& callback)
185 {
186     std::string bundleName = "bundleName";
187     std::string abilityName = "abilityName";
188     std::string devId = "devId";
189     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, flags);
190     int callerUid = 0;
191     if (spWant == nullptr) {
192         DTEST_LOG << "StartRemoteFreeInstall spWant is nullptr" << std::endl;
193         return -1;
194     }
195     return DistributedSchedService::GetInstance().StartRemoteFreeInstall(*spWant, callerUid, 0, 0, callback);
196 }
197 
198 /**
199  * @tc.name: StartContinuation_001
200  * @tc.desc: input invalid params.
201  * @tc.type: FUNC
202  */
203 HWTEST_F(DSchedContinuationTest, StartContinuation_001, TestSize.Level1)
204 {
205     DTEST_LOG << "DSchedContinuationTest StartContinuation_001 start" << std::endl;
206     /**
207      * @tc.steps: step1. want not set continuation flags.
208      * @tc.expected: step1. return false.
209      */
210     int32_t ret = StartContinuation(0, 0);
211     EXPECT_TRUE(ret != ERR_OK);
212     DTEST_LOG << "DSchedContinuationTest StartContinuation002 end" << std::endl;
213 }
214 
215 /**
216  * @tc.name: StartContinuation_002
217  * @tc.desc: get remote dms failed.
218  * @tc.type: FUNC
219  */
220 HWTEST_F(DSchedContinuationTest, StartContinuation_002, TestSize.Level1)
221 {
222     DTEST_LOG << "DSchedContinuationTest StartContinuation_002 start" << std::endl;
223     /**
224      * @tc.steps: step1. get remote dms failed.
225      * @tc.expected: step1. return false.
226      */
227     int32_t ret = StartContinuation(0, Want::FLAG_ABILITY_CONTINUATION);
228     EXPECT_TRUE(ret != ERR_OK);
229     DTEST_LOG << "DSchedContinuationTest StartContinuation003 end" << std::endl;
230 }
231 
232 /**
233  * @tc.name: StartContinuation_003
234  * @tc.desc: call StartContinuation
235  * @tc.type: FUNC
236  */
237 HWTEST_F(DSchedContinuationTest, StartContinuation_003, TestSize.Level1)
238 {
239     DTEST_LOG << "DSchedContinuationTest StartContinuation_003 start" << std::endl;
240     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
241         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
242     }
243     ASSERT_NE(DistributedSchedService::GetInstance().dschedContinuation_, nullptr);
244     std::string bundleName = "bundleName";
245     std::string abilityName = "abilityName";
246     int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
247     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, flags);
248     int32_t missionId = 0;
249     auto callback = GetDSchedService();
250     std::string deviceId = "123456";
251     DistributedSchedService::GetInstance().dschedContinuation_->PushCallback(missionId, callback, deviceId, false);
252     int32_t status = ERR_OK;
253     int32_t uid = IPCSkeleton::GetCallingUid();
254     int32_t accessToken = IPCSkeleton::GetCallingTokenID();
255     int32_t ret = DistributedSchedService::GetInstance().StartContinuation(*spWant,
256         missionId, uid, status, accessToken);
257     EXPECT_TRUE(ret != ERR_OK);
258     DTEST_LOG << "DSchedContinuationTest StartContinuation_003 end" << std::endl;
259 }
260 
261 /**
262  * @tc.name: StartContinuation_004
263  * @tc.desc: call StartContinuation
264  * @tc.type: FUNC
265  */
266 HWTEST_F(DSchedContinuationTest, StartContinuation_004, TestSize.Level1)
267 {
268     DTEST_LOG << "DSchedContinuationTest StartContinuation_004 start" << std::endl;
269     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
270         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
271     }
272     ASSERT_NE(DistributedSchedService::GetInstance().dschedContinuation_, nullptr);
273     std::string bundleName = "bundleName";
274     std::string abilityName = "abilityName";
275     int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
276     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, flags);
277     int32_t missionId = 0;
278     auto callback = GetDSchedService();
279     std::string deviceId = "123456";
280     DistributedSchedService::GetInstance().dschedContinuation_->PushCallback(missionId, callback, deviceId, true);
281     int32_t status = ERR_OK;
282     int32_t uid = IPCSkeleton::GetCallingUid();
283     int32_t accessToken = IPCSkeleton::GetCallingTokenID();
284     int32_t ret = DistributedSchedService::GetInstance().StartContinuation(*spWant,
285         missionId, uid, status, accessToken);
286     EXPECT_TRUE(ret != ERR_OK);
287     DTEST_LOG << "DSchedContinuationTest StartContinuation_004 end" << std::endl;
288 }
289 
290 /**
291  * @tc.name: NotifyCompleteContinuation_001
292  * @tc.desc: input invalid session.
293  * @tc.type: FUNC
294  */
295 HWTEST_F(DSchedContinuationTest, NotifyCompleteContinuation_001, TestSize.Level1)
296 {
297     DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 start" << std::endl;
298     /**
299      * @tc.steps: step1. input invalid session.
300      * @tc.expected: step1. return false.
301      */
302     DistributedSchedService::GetInstance().NotifyCompleteContinuation(MOCK_DEVICE_ID, -1, true);
303     EXPECT_TRUE(!timeoutFlag_);
304     DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 end" << std::endl;
305 }
306 
307 /**
308  * @tc.name: NotifyCompleteContinuation_002
309  * @tc.desc: get remote dms failed.
310  * @tc.type: FUNC
311  */
312 HWTEST_F(DSchedContinuationTest, NotifyCompleteContinuation_002, TestSize.Level1)
313 {
314     DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_002 start" << std::endl;
315     /**
316      * @tc.steps: step1. get remote dms failed.
317      * @tc.expected: step1. return false.
318      */
319     DistributedSchedService::GetInstance().NotifyCompleteContinuation(MOCK_DEVICE_ID, MOCK_SESSION_ID, true);
320     EXPECT_TRUE(!timeoutFlag_);
321     DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_002 end" << std::endl;
322 }
323 
324 /**
325  * @tc.name: NotifyContinuationResultFromRemote_001
326  * @tc.desc: input invalid session.
327  * @tc.type: FUNC
328  */
329 HWTEST_F(DSchedContinuationTest, NotifyContinuationResultFromRemote_001, TestSize.Level1)
330 {
331     DTEST_LOG << "DSchedContinuationTest NotifyContinuationResultFromRemote_001 start" << std::endl;
332     /**
333      * @tc.steps: step1. input invalid session.
334      * @tc.expected: step1. return false.
335      */
336     std::string info;
337     DmsContinueTime::GetInstance().Init();
338     DistributedSchedService::GetInstance().NotifyContinuationResultFromRemote(-1, true, info);
339     EXPECT_TRUE(!timeoutFlag_);
340     DTEST_LOG << "DSchedContinuationTest NotifyContinuationResultFromRemote_001 end" << std::endl;
341 }
342 
343 /**
344  * @tc.name: NotifyContinuationResultFromRemote_002
345  * @tc.desc: get remote dms failed.
346  * @tc.type: FUNC
347  */
348 HWTEST_F(DSchedContinuationTest, NotifyContinuationResultFromRemote_002, TestSize.Level1)
349 {
350     DTEST_LOG << "DSchedContinuationTest NotifyContinuationResultFromRemote_002 start" << std::endl;
351     /**
352      * @tc.steps: step1. get remote dms failed.
353      * @tc.expected: step1. return false.
354      */
355     std::string info;
356     DmsContinueTime::GetInstance().Init();
357     DistributedSchedService::GetInstance().NotifyContinuationResultFromRemote(MOCK_SESSION_ID, true, info);
358     EXPECT_TRUE(!timeoutFlag_);
359     DTEST_LOG << "DSchedContinuationTest NotifyContinuationResultFromRemote_002 end" << std::endl;
360 }
361 
362 /**
363  * @tc.name: SetWantForContinuation_001
364  * @tc.desc: input invalid params.
365  * @tc.type: FUNC
366  */
367 HWTEST_F(DSchedContinuationTest, SetWantForContinuation_001, TestSize.Level1)
368 {
369     DTEST_LOG << "DSchedContinuationTest SetWantForContinuation_001 start" << std::endl;
370     /**
371      * @tc.steps: step1. input invalid bundleName.
372      * @tc.expected: step1. return err.
373      */
374     std::string bundleName = "bundleName";
375     std::string abilityName = "abilityName";
376     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
377     int32_t missionId = 0;
378     ASSERT_NE(spWant, nullptr);
379     int32_t ret = DistributedSchedService::GetInstance().SetWantForContinuation(*spWant, missionId);
380     EXPECT_TRUE(INVALID_PARAMETERS_ERR == ret);
381     DTEST_LOG << "DSchedContinuationTest SetWantForContinuation_001 end" << std::endl;
382 }
383 
384 /**
385  * @tc.name: ContinueLocalMission_001
386  * @tc.desc: input invalid params.
387  * @tc.type: FUNC
388  */
389 HWTEST_F(DSchedContinuationTest, ContinueLocalMission_001, TestSize.Level1)
390 {
391     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_001 start" << std::endl;
392     /**
393      * @tc.steps: step1. input invalid missionId.
394      * @tc.expected: step1. return err.
395      */
396     std::string deviceId = "123456";
397     int32_t missionId = 0;
398     auto callback = GetDSchedService();
399     WantParams wantParams;
400     int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMission(deviceId,
401         missionId, callback, wantParams);
402     EXPECT_NE(ret, ERR_OK);
403     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_001 end" << std::endl;
404 }
405 
406 /**
407  * @tc.name: ContinueLocalMission_002
408  * @tc.desc: input invalid params.
409  * @tc.type: FUNC
410  */
411 HWTEST_F(DSchedContinuationTest, ContinueLocalMission_002, TestSize.Level1)
412 {
413     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_002 start" << std::endl;
414     /**
415      * @tc.steps: step1. input invalid mission.
416      * @tc.expected: step1. return err.
417      */
418     std::string deviceId = "123456";
419     int32_t missionId = 0;
420     auto callback = GetDSchedService();
421     WantParams wantParams;
422     MockOnStart();
423     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
424         return;
425     }
426     ASSERT_NE(DistributedSchedService::GetInstance().dschedContinuation_, nullptr);
427     DistributedSchedService::GetInstance().dschedContinuation_->PushCallback(missionId, callback, deviceId, false);
428     int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMission(
429         deviceId, missionId, callback, wantParams);
430     EXPECT_EQ(CONTINUE_ALREADY_IN_PROGRESS, ret);
431     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_002 end" << std::endl;
432 }
433 
434 /**
435  * @tc.name: ContinueLocalMission_003
436  * @tc.desc: input invalid params.
437  * @tc.type: FUNC
438  * @tc.require: I5RWKZ
439  */
440 HWTEST_F(DSchedContinuationTest, ContinueLocalMission_003, TestSize.Level1)
441 {
442     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_003 start" << std::endl;
443     std::string deviceId = "123456";
444     int32_t missionId = -1;
445     auto callback = GetDSchedService();
446     WantParams wantParams;
447     DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
448     int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMission(
449         deviceId, missionId, callback, wantParams);
450     EXPECT_NE(ret, ERR_OK);
451     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_003 end" << std::endl;
452 }
453 
454 /**
455  * @tc.name: ContinueLocalMission_004
456  * @tc.desc: input invalid params.
457  * @tc.type: FUNC
458  * @tc.require: I5RWKZ
459  */
460 HWTEST_F(DSchedContinuationTest, ContinueLocalMission_004, TestSize.Level1)
461 {
462     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_004 start" << std::endl;
463     std::string deviceId;
464     int32_t missionId = -1;
465     auto callback = GetDSchedService();
466     WantParams wantParams;
467     DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
468     int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMission(
469         deviceId, missionId, callback, wantParams);
470     EXPECT_NE(ret, ERR_OK);
471     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_004 end" << std::endl;
472 }
473 
474 /**
475  * @tc.name: ContinueLocalMission_005
476  * @tc.desc: input invalid params.
477  * @tc.type: FUNC
478  * @tc.require: I5RWKZ
479  */
480 HWTEST_F(DSchedContinuationTest, ContinueLocalMission_005, TestSize.Level1)
481 {
482     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_005 start" << std::endl;
483     /**
484      * @tc.steps: step1. input invalid mission.
485      * @tc.expected: step1. return err.
486      */
487     std::string deviceId = "123456";
488     int32_t missionId = 0;
489     auto callback = GetDSchedService();
490     WantParams wantParams;
491     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
492         return;
493     }
494     DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
495     ASSERT_NE(DistributedSchedService::GetInstance().dschedContinuation_, nullptr);
496     DistributedSchedService::GetInstance().dschedContinuation_->PushCallback(missionId, callback, deviceId, false);
497     int32_t ret = DistributedSchedService::GetInstance().ContinueAbilityWithTimeout(deviceId, missionId, callback);
498     EXPECT_EQ(CONTINUE_ALREADY_IN_PROGRESS, ret);
499     DTEST_LOG << "DSchedContinuationTest ContinueLocalMission_005 end" << std::endl;
500 }
501 
502 /**
503  * @tc.name: ContinueLocalMissionDealFreeInstall_001
504  * @tc.desc: input invalid params.
505  * @tc.type: FUNC
506  */
507 HWTEST_F(DSchedContinuationTest, ContinueLocalMissionDealFreeInstall_001, TestSize.Level1)
508 {
509     DTEST_LOG << "DSchedContinuationTest ContinueLocalMissionDealFreeInstall_001 start" << std::endl;
510     std::string bundleName = "bundleName";
511     std::string abilityName = "abilityName";
512     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
513     spWant->SetParam("isFreeInstall", false);
514 
515     int32_t missionId = 0;
516     std::string deviceId = "123456";
517     auto callback = GetDSchedService();
518     int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMissionDealFreeInstall(*spWant,
519         missionId, deviceId, callback);
520     EXPECT_NE(ret, ERR_OK);
521     DTEST_LOG << "DSchedContinuationTest ContinueLocalMissionDealFreeInstall_001 end" << std::endl;
522 }
523 
524 /**
525  * @tc.name: ContinueRemoteMission_001
526  * @tc.desc: input invalid params.
527  * @tc.type: FUNC
528  */
529 HWTEST_F(DSchedContinuationTest, ContinueRemoteMission_001, TestSize.Level1)
530 {
531     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_001 start" << std::endl;
532     /**
533      * @tc.steps: step1. input invalid deviceId.
534      * @tc.expected: step1. return err.
535      */
536     std::string srcDeviceId = "123456";
537     std::string dstDeviceid = "123456";
538     int32_t missionId = 0;
539     auto callback = GetDSchedService();
540     WantParams wantParams;
541     int32_t ret = DistributedSchedService::GetInstance().ContinueRemoteMission(
542         srcDeviceId, dstDeviceid, missionId, callback, wantParams);
543     EXPECT_TRUE(INVALID_REMOTE_PARAMETERS_ERR == ret);
544     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_001 end" << std::endl;
545 }
546 
547 /**
548  * @tc.name: ContinueRemoteMission_002
549  * @tc.desc: input invalid params.
550  * @tc.type: FUNC
551  */
552 HWTEST_F(DSchedContinuationTest, ContinueRemoteMission_002, TestSize.Level1)
553 {
554     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_002 start" << std::endl;
555     /**
556      * @tc.steps: step1. input invalid param.
557      * @tc.expected: step1. return err.
558      */
559     std::string srcDeviceId;
560     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
561     std::string dstDeviceid = "123456";
562     int32_t missionId = 0;
563     auto callback = GetDSchedService();
564     WantParams wantParams;
565     int32_t ret = DistributedSchedService::GetInstance().ContinueRemoteMission(
566         srcDeviceId, dstDeviceid, missionId, callback, wantParams);
567     EXPECT_TRUE(ERR_OK != ret);
568     DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_002 end" << std::endl;
569 }
570 
571 /**
572  * @tc.name: PushAbilityToken_001
573  * @tc.desc: input invalid params.
574  * @tc.type: FUNC
575  */
576 HWTEST_F(DSchedContinuationTest, PushAbilityToken_001, TestSize.Level1)
577 {
578     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_001 start" << std::endl;
579     /**
580      * @tc.steps: step1. input invalid abilityToken.
581      * @tc.expected: step1. return false.
582      */
583 
584     ASSERT_NE(dschedContinuation_, nullptr);
585     auto sessionId = dschedContinuation_->GenerateSessionId();
586     bool ret = dschedContinuation_->PushAbilityToken(sessionId, nullptr);
587     EXPECT_TRUE(!ret);
588     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_001 end" << std::endl;
589 }
590 
591 /**
592  * @tc.name: PushAbilityToken_002
593  * @tc.desc: input invalid params.
594  * @tc.type: FUNC
595  */
596 HWTEST_F(DSchedContinuationTest, PushAbilityToken_002, TestSize.Level1)
597 {
598     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_002 start" << std::endl;
599     /**
600      * @tc.steps: step1. input invalid sessionId.
601      * @tc.expected: step1. return false.
602      */
603     ASSERT_NE(dschedContinuation_, nullptr);
604     bool ret = dschedContinuation_->PushAbilityToken(-1, GetDSchedService());
605     EXPECT_TRUE(!ret);
606     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_002 end" << std::endl;
607 }
608 
609 /**
610  * @tc.name: PushAbilityToken_003
611  * @tc.desc: init not call.
612  * @tc.type: FUNC
613  */
614 HWTEST_F(DSchedContinuationTest, PushAbilityToken_003, TestSize.Level1)
615 {
616     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_003 start" << std::endl;
617     /**
618      * @tc.steps: step1. input valid abilityToken and valid sessionId.
619      * @tc.expected: step1. return false.
620      */
621     ASSERT_NE(dschedContinuation_, nullptr);
622     auto sessionId = dschedContinuation_->GenerateSessionId();
623     bool ret = dschedContinuation_->PushAbilityToken(sessionId, GetDSchedService());
624     EXPECT_TRUE(!ret);
625     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_003 end" << std::endl;
626 }
627 
628 /**
629  * @tc.name: PushAbilityToken_004
630  * @tc.desc: Push AbilityToken OK.
631  * @tc.type: FUNC
632  */
633 HWTEST_F(DSchedContinuationTest, PushAbilityToken_004, TestSize.Level1)
634 {
635     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_004 start" << std::endl;
636     /**
637      * @tc.steps: step1. input valid params and init.
638      * @tc.expected: step1. return true.
639      */
640     ASSERT_NE(dschedContinuation_, nullptr);
641     dschedContinuation_->Init(nullptr);
642     auto sessionId = dschedContinuation_->GenerateSessionId();
643     bool ret = dschedContinuation_->PushAbilityToken(sessionId, GetDSchedService());
644     EXPECT_TRUE(ret);
645     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_004 end" << std::endl;
646 }
647 
648 /**
649  * @tc.name: PushAbilityToken_005
650  * @tc.desc: AbilityToken is exist.
651  * @tc.type: FUNC
652  * @tc.require: I60TOK
653  */
654 HWTEST_F(DSchedContinuationTest, PushAbilityToken_005, TestSize.Level1)
655 {
656     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_005 start" << std::endl;
657     ASSERT_NE(dschedContinuation_, nullptr);
658     dschedContinuation_->Init(nullptr);
659     auto sessionId = 1;
660     bool ret = dschedContinuation_->PushAbilityToken(sessionId, GetDSchedService());
661     ret = dschedContinuation_->PushAbilityToken(sessionId, GetDSchedService());
662     EXPECT_EQ(ret, false);
663     DTEST_LOG << "DSchedContinuationTest PushAbilityToken_005 end" << std::endl;
664 }
665 
666 /**
667  * @tc.name: PopAbilityToken_001
668  * @tc.desc: input invalid params.
669  * @tc.type: FUNC
670  */
671 HWTEST_F(DSchedContinuationTest, PopAbilityToken_001, TestSize.Level1)
672 {
673     DTEST_LOG << "DSchedContinuationTest PopAbilityToken_001 start" << std::endl;
674     /**
675      * @tc.steps: step1. input invalid sessionId.
676      * @tc.expected: step1. return false.
677      */
678     ASSERT_NE(dschedContinuation_, nullptr);
679     sptr<IRemoteObject> abilityToken = dschedContinuation_->PopAbilityToken(-1);
680     EXPECT_TRUE(abilityToken == nullptr);
681     DTEST_LOG << "DSchedContinuationTest PopAbilityToken_001 end" << std::endl;
682 }
683 
684 /**
685  * @tc.name: PopAbilityToken_002
686  * @tc.desc: input invalid params.
687  * @tc.type: FUNC
688  */
689 HWTEST_F(DSchedContinuationTest, PopAbilityToken_002, TestSize.Level1)
690 {
691     DTEST_LOG << "DSchedContinuationTest PopAbilityToken_002 start" << std::endl;
692     /**
693      * @tc.steps: step1. pop not exist sessionId.
694      * @tc.expected: step1. return false.
695      */
696     ASSERT_NE(dschedContinuation_, nullptr);
697     int32_t sessionId = dschedContinuation_->GenerateSessionId() + 1;
698     sptr<IRemoteObject> abilityToken = dschedContinuation_->PopAbilityToken(sessionId);
699     EXPECT_TRUE(abilityToken == nullptr);
700     DTEST_LOG << "DSchedContinuationTest PopAbilityToken_002 end" << std::endl;
701 }
702 
703 /**
704  * @tc.name: PopAbilityToken_003
705  * @tc.desc: pop abilityToken success.
706  * @tc.type: FUNC
707  */
708 HWTEST_F(DSchedContinuationTest, PopAbilityToken_003, TestSize.Level1)
709 {
710     DTEST_LOG << "DSchedContinuationTest PopAbilityToken_003 start" << std::endl;
711     /**
712      * @tc.steps: step1. pop exist sessionId.
713      * @tc.expected: step1. return true.
714      */
715     ASSERT_NE(dschedContinuation_, nullptr);
716     int32_t sessionId = PushAbilityToken();
717     sptr<IRemoteObject> abilityToken = dschedContinuation_->PopAbilityToken(sessionId);
718     EXPECT_TRUE(abilityToken != nullptr);
719 
720     /**
721      * @tc.steps: step2. duplicate pop abilityToken.
722      * @tc.expected: step1. return false.
723      */
724     abilityToken = dschedContinuation_->PopAbilityToken(sessionId);
725     EXPECT_TRUE(abilityToken == nullptr);
726     DTEST_LOG << "DSchedContinuationTest PopAbilityToken_003 end" << std::endl;
727 }
728 
729 /**
730  * @tc.name: PopAbilityToken_004
731  * @tc.desc: pop abilityToken success.
732  * @tc.type: FUNC
733  * @tc.require: I60TOK
734  */
735 HWTEST_F(DSchedContinuationTest, PopAbilityToken_004, TestSize.Level1)
736 {
737     DTEST_LOG << "DSchedContinuationTest PopAbilityToken_004 start" << std::endl;
738     ASSERT_NE(dschedContinuation_, nullptr);
739     dschedContinuation_->continuationHandler_ = nullptr;
740 
741     int32_t sessionId = PushAbilityToken();
742     sptr<IRemoteObject> abilityToken = dschedContinuation_->PopAbilityToken(sessionId);
743     EXPECT_TRUE(abilityToken != nullptr);
744     DTEST_LOG << "DSchedContinuationTest PopAbilityToken_004 end" << std::endl;
745 }
746 
747 /**
748  * @tc.name: GenerateSessionId_001
749  * @tc.desc: test GenerateSessionId when currSessionId is less than zero.
750  * @tc.type: FUNC
751  * @tc.require: I60TOK
752  */
753 HWTEST_F(DSchedContinuationTest, GenerateSessionId_001, TestSize.Level4)
754 {
755     DTEST_LOG << "DSchedContinuationTest GenerateSessionId_001 start" << std::endl;
756     ASSERT_NE(dschedContinuation_, nullptr);
757     int32_t sessionId =  dschedContinuation_->currSessionId_;
758     dschedContinuation_->currSessionId_ = -100;
759     dschedContinuation_->GenerateSessionId();
760     EXPECT_EQ(dschedContinuation_->currSessionId_, 1);
761     dschedContinuation_->currSessionId_ = sessionId;
762     DTEST_LOG << "DSchedContinuationTest GenerateSessionId_001 end" << std::endl;
763 }
764 
765 /**
766  * @tc.name: SetTimeOut_001
767  * @tc.desc: test SetTimeOut.
768  * @tc.type: FUNC
769  * @tc.require: I60TOK
770  */
771 HWTEST_F(DSchedContinuationTest, SetTimeOut_001, TestSize.Level3)
772 {
773     DTEST_LOG << "DSchedContinuationTest SetTimeOut_001 start" << std::endl;
774     ASSERT_NE(dschedContinuation_, nullptr);
775     dschedContinuation_->Init(nullptr);
776 
777     int32_t missionId = 0;
778     int32_t timeout = 1000;
779     dschedContinuation_->SetTimeOut(missionId, timeout);
780     EXPECT_NE(dschedContinuation_->continuationHandler_, nullptr);
781     DTEST_LOG << "DSchedContinuationTest SetTimeOut_001 end" << std::endl;
782 }
783 
784 /**
785  * @tc.name: RemoveTimeOut_001
786  * @tc.desc: test RemoveTimeOut.
787  * @tc.type: FUNC
788  * @tc.require: I60TOK
789  */
790 HWTEST_F(DSchedContinuationTest, RemoveTimeOut_001, TestSize.Level3)
791 {
792     DTEST_LOG << "DSchedContinuationTest RemoveTimeOut_001 start" << std::endl;
793     ASSERT_NE(dschedContinuation_, nullptr);
794     dschedContinuation_->Init(nullptr);
795 
796     int32_t missionId = 0;
797     int32_t timeout = 1000;
798     dschedContinuation_->SetTimeOut(missionId, timeout);
799     EXPECT_NE(dschedContinuation_->continuationHandler_, nullptr);
800     DTEST_LOG << "DSchedContinuationTest RemoveTimeOut_001 end" << std::endl;
801 }
802 
803 /**
804  * @tc.name: GetTargetDevice_001
805  * @tc.desc: test GetTargetDevice.
806  * @tc.type: FUNC
807  * @tc.require: I60TOK
808  */
809 HWTEST_F(DSchedContinuationTest, GetTargetDevice_001, TestSize.Level3)
810 {
811     DTEST_LOG << "DSchedContinuationTest GetTargetDevice_001 start" << std::endl;
812     ASSERT_NE(dschedContinuation_, nullptr);
813     dschedContinuation_->Init(nullptr);
814 
815     int32_t missionId = 0;
816     std::string mockDevice = "mockDevice";
817     dschedContinuation_->continuationDevices_[missionId] = mockDevice;
818     std::string result = dschedContinuation_->GetTargetDevice(missionId);
819     EXPECT_EQ(result, mockDevice);
820     DTEST_LOG << "DSchedContinuationTest GetTargetDevice_001 end" << std::endl;
821 }
822 
823 /**
824  * @tc.name: PushCallback_001
825  * @tc.desc: test PushCallback when callback is nullptr.
826  * @tc.type: FUNC
827  * @tc.require: I60TOK
828  */
829 HWTEST_F(DSchedContinuationTest, PushCallback_001, TestSize.Level3)
830 {
831     DTEST_LOG << "DSchedContinuationTest PushCallback_001 start" << std::endl;
832     ASSERT_NE(dschedContinuation_, nullptr);
833     dschedContinuation_->Init(nullptr);
834 
835     int32_t missionId = 0;
836     const sptr<IRemoteObject> callback = nullptr;
837     std::string deviceId = "";
838     bool isFreeInstall = true;
839     bool result = dschedContinuation_->PushCallback(missionId, callback, deviceId, isFreeInstall);
840     EXPECT_EQ(result, false);
841     DTEST_LOG << "DSchedContinuationTest PushCallback_001 end" << std::endl;
842 }
843 
844 /**
845  * @tc.name: PushCallback_002
846  * @tc.desc: test PushCallback when callback is exist.
847  * @tc.type: FUNC
848  * @tc.require: I60TOK
849  */
850 HWTEST_F(DSchedContinuationTest, PushCallback_002, TestSize.Level3)
851 {
852     DTEST_LOG << "DSchedContinuationTest PushCallback_002 start" << std::endl;
853     ASSERT_NE(dschedContinuation_, nullptr);
854     dschedContinuation_->Init(nullptr);
855 
856     int32_t missionId = 0;
857     const sptr<IRemoteObject> callback(new MockRemoteStub());
858     std::string deviceId = "";
859     bool isFreeInstall = true;
860     dschedContinuation_->callbackMap_[missionId] = callback;
861     bool result = dschedContinuation_->PushCallback(missionId, callback, deviceId, isFreeInstall);
862     EXPECT_EQ(result, false);
863     DTEST_LOG << "DSchedContinuationTest PushCallback_002 end" << std::endl;
864 }
865 
866 /**
867  * @tc.name: PushCallback_003
868  * @tc.desc: test PushCallback when isFreeInstall is true.
869  * @tc.type: FUNC
870  * @tc.require: I60TOK
871  */
872 HWTEST_F(DSchedContinuationTest, PushCallback_003, TestSize.Level3)
873 {
874     DTEST_LOG << "DSchedContinuationTest PushCallback_003 start" << std::endl;
875     ASSERT_NE(dschedContinuation_, nullptr);
876     dschedContinuation_->Init(nullptr);
877 
878     int32_t missionId = 0;
879     const sptr<IRemoteObject> callback(new MockRemoteStub());
880     std::string deviceId = "";
881     bool isFreeInstall = true;
882     dschedContinuation_->callbackMap_.clear();
883     bool result = dschedContinuation_->PushCallback(missionId, callback, deviceId, isFreeInstall);
884     EXPECT_EQ(result, true);
885     DTEST_LOG << "DSchedContinuationTest PushCallback_003 end" << std::endl;
886 }
887 
888 /**
889  * @tc.name: PushCallback_004
890  * @tc.desc: test PushCallback
891  * @tc.type: FUNC
892  * @tc.require: I60TOK
893  */
894 HWTEST_F(DSchedContinuationTest, PushCallback_004, TestSize.Level3)
895 {
896     DTEST_LOG << "DSchedContinuationTest PushCallback_004 start" << std::endl;
897     ASSERT_NE(dschedContinuation_, nullptr);
898     const sptr<IRemoteObject> callback = nullptr;
899     dschedContinuation_->PushCallback(callback);
900 
901     dschedContinuation_->Init(nullptr);
902     bool result = dschedContinuation_->PushCallback(callback);
903     EXPECT_EQ(result, false);
904     DTEST_LOG << "DSchedContinuationTest PushCallback_004 end" << std::endl;
905 }
906 
907 /**
908  * @tc.name: PushCallback_005
909  * @tc.desc: test PushCallback
910  * @tc.type: FUNC
911  * @tc.require: I60TOK
912  */
913 HWTEST_F(DSchedContinuationTest, PushCallback_005, TestSize.Level3)
914 {
915     DTEST_LOG << "DSchedContinuationTest PushCallback_005 start" << std::endl;
916     ASSERT_NE(dschedContinuation_, nullptr);
917     const sptr<IRemoteObject> callback(new MockRemoteStub());
918     dschedContinuation_->Init(nullptr);
919     dschedContinuation_->continuationCallbackArr_.clear();
920     dschedContinuation_->PushCallback(callback);
921 
922     dschedContinuation_->continuationCallbackArr_.push_back(callback);
923     bool result = dschedContinuation_->PushCallback(callback);
924     EXPECT_EQ(result, false);
925     DTEST_LOG << "DSchedContinuationTest PushCallback_005 end" << std::endl;
926 }
927 
928 /**
929  * @tc.name: CleanupCallback_001
930  * @tc.desc: test CleanupCallback
931  * @tc.type: FUNC
932  * @tc.require: I60TOK
933  */
934 HWTEST_F(DSchedContinuationTest, CleanupCallback_001, TestSize.Level3)
935 {
936     DTEST_LOG << "DSchedContinuationTest CleanupCallback_001 start" << std::endl;
937     ASSERT_NE(dschedContinuation_, nullptr);
938     const sptr<IRemoteObject> callback(new MockRemoteStub());
939 
940     dschedContinuation_->continuationCallbackArr_.push_back(callback);
941     dschedContinuation_->CleanupCallback(callback);
942 
943     dschedContinuation_->continuationCallbackArr_.clear();
944     bool result = dschedContinuation_->CleanupCallback(callback);
945     EXPECT_EQ(result, false);
946     DTEST_LOG << "DSchedContinuationTest CleanupCallback_001 end" << std::endl;
947 }
948 
949 /**
950  * @tc.name: NotifyDSchedEventForOneCB_001
951  * @tc.desc: test NotifyDSchedEventForOneCB
952  * @tc.type: FUNC
953  * @tc.require: I60TOK
954  */
955 HWTEST_F(DSchedContinuationTest, NotifyDSchedEventForOneCB_001, TestSize.Level3)
956 {
957     DTEST_LOG << "DSchedContinuationTest NotifyDSchedEventForOneCB_001 start" << std::endl;
958     ASSERT_NE(dschedContinuation_, nullptr);
959     const sptr<IRemoteObject> cb(new MockRemoteStub());
960     int32_t resultCode = 0;
961     dschedContinuation_->NotifyDSchedEventForOneCB(cb, resultCode);
962     int32_t result = dschedContinuation_->NotifyDSchedEventForOneCB(nullptr, resultCode);
963     EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
964     DTEST_LOG << "DSchedContinuationTest NotifyDSchedEventForOneCB_001 end" << std::endl;
965 }
966 
967 /**
968  * @tc.name: NotifyDSchedEventResult_001
969  * @tc.desc: test NotifyDSchedEventResult
970  * @tc.type: FUNC
971  * @tc.require: I60TOK
972  */
973 HWTEST_F(DSchedContinuationTest, NotifyDSchedEventResult_001, TestSize.Level3)
974 {
975     DTEST_LOG << "DSchedContinuationTest NotifyDSchedEventResult_001 start" << std::endl;
976     ASSERT_NE(dschedContinuation_, nullptr);
977     const sptr<IRemoteObject> callback(new MockRemoteStub());
978     int32_t resultCode = 0;
979     dschedContinuation_->continuationCallbackArr_.push_back(callback);
980     dschedContinuation_->NotifyDSchedEventResult(resultCode);
981 
982     dschedContinuation_->continuationCallbackArr_.clear();
983     int32_t result = dschedContinuation_->NotifyDSchedEventResult(resultCode);
984     EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
985     DTEST_LOG << "DSchedContinuationTest NotifyDSchedEventResult_001 end" << std::endl;
986 }
987 
988 /**
989  * @tc.name: IsCleanMission_001
990  * @tc.desc: test IsCleanMission
991  * @tc.type: FUNC
992  * @tc.require: I60TOK
993  */
994 HWTEST_F(DSchedContinuationTest, IsCleanMission_001, TestSize.Level3)
995 {
996     DTEST_LOG << "DSchedContinuationTest IsCleanMission_001 start" << std::endl;
997     ASSERT_NE(dschedContinuation_, nullptr);
998     int32_t missionId = 0;
999     dschedContinuation_->SetCleanMissionFlag(1, true);
1000     dschedContinuation_->IsCleanMission(missionId);
1001 
1002     dschedContinuation_->SetCleanMissionFlag(missionId, false);
1003     bool result = dschedContinuation_->IsCleanMission(missionId);
1004     EXPECT_EQ(result, false);
1005     DTEST_LOG << "DSchedContinuationTest IsCleanMission_001 end" << std::endl;
1006 }
1007 
1008 /**
1009  * @tc.name: ContinueMission_001
1010  * @tc.desc: test ContinueMission when srcDeviceId is empty.
1011  * @tc.type: FUNC
1012  */
1013 HWTEST_F(DSchedContinuationTest, ContinueMission_001, TestSize.Level1)
1014 {
1015     DTEST_LOG << "DSchedContinuationTest ContinueMission_001 start" << std::endl;
1016     WantParams wantParams;
1017     int32_t ret = DistributedSchedService::GetInstance().ContinueMission("",
1018         "string", 1, GetDSchedService(), wantParams);
1019     EXPECT_TRUE(ret != ERR_OK);
1020     DTEST_LOG << "DSchedContinuationTest ContinueMission_001 end" << std::endl;
1021 }
1022 
1023 /**
1024  * @tc.name: ContinueMission_002
1025  * @tc.desc: test ContinueMission when dstDeviceId is empty.
1026  * @tc.type: FUNC
1027  */
1028 HWTEST_F(DSchedContinuationTest, ContinueMission_002, TestSize.Level1)
1029 {
1030     DTEST_LOG << "DSchedContinuationTest ContinueMission_002 start" << std::endl;
1031     WantParams wantParams;
1032     int32_t ret = DistributedSchedService::GetInstance().ContinueMission("string",
1033         "", 1, GetDSchedService(), wantParams);
1034     EXPECT_TRUE(ret != ERR_OK);
1035     DTEST_LOG << "DSchedContinuationTest ContinueMission_002 end" << std::endl;
1036 }
1037 
1038 /**
1039  * @tc.name: ContinueMission_003
1040  * @tc.desc: test ContinueMission when callback is nullptr.
1041  * @tc.type: FUNC
1042  */
1043 HWTEST_F(DSchedContinuationTest, ContinueMission_003, TestSize.Level1)
1044 {
1045     DTEST_LOG << "DSchedContinuationTest ContinueMission_003 start" << std::endl;
1046     WantParams wantParams;
1047     int32_t ret = DistributedSchedService::GetInstance().ContinueMission("string", "string", 1, nullptr, wantParams);
1048     EXPECT_TRUE(ret != ERR_OK);
1049     DTEST_LOG << "DSchedContinuationTest ContinueMission_003 end" << std::endl;
1050 }
1051 
1052 /**
1053  * @tc.name: ContinueMission_004
1054  * @tc.desc: test ContinueMission when srcDeviceId == localDevId.
1055  * @tc.type: FUNC
1056  */
1057 HWTEST_F(DSchedContinuationTest, ContinueMission_004, TestSize.Level1)
1058 {
1059     DTEST_LOG << "DSchedContinuationTest ContinueMission_004 start" << std::endl;
1060     WantParams wantParams;
1061 
1062     std::string srcDeviceId;
1063     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
1064     int32_t ret = DistributedSchedService::GetInstance().ContinueMission(srcDeviceId,
1065         "string", -1, GetDSchedService(), wantParams);
1066     EXPECT_TRUE(ret != ERR_OK);
1067     DTEST_LOG << "DSchedContinuationTest ContinueMission_004 end" << std::endl;
1068 }
1069 
1070 /**
1071  * @tc.name: StartRemoteFreeInstall_001
1072  * @tc.desc: input invalid params.
1073  * @tc.type: FUNC
1074  */
1075 HWTEST_F(DSchedContinuationTest, StartRemoteFreeInstall_001, TestSize.Level1)
1076 {
1077     DTEST_LOG << "DSchedContinuationTest StartRemoteFreeInstall_001 start" << std::endl;
1078     /**
1079      * @tc.steps: step1. want not set continuation flags.
1080      * @tc.expected: step1. return false.
1081      */
1082     int32_t ret = StartRemoteFreeInstall(0, GetDSchedService());
1083     EXPECT_TRUE(ret != ERR_OK);
1084     DTEST_LOG << "DSchedContinuationTest StartRemoteFreeInstall_001 end" << std::endl;
1085 }
1086 
1087 /**
1088  * @tc.name: StartRemoteFreeInstall_002
1089  * @tc.desc: get remote dms failed.
1090  * @tc.type: FUNC
1091  */
1092 HWTEST_F(DSchedContinuationTest, StartRemoteFreeInstall_002, TestSize.Level1)
1093 {
1094     DTEST_LOG << "DSchedContinuationTest StartRemoteFreeInstall_002 start" << std::endl;
1095     /**
1096      * @tc.steps: step1. get remote dms failed.
1097      * @tc.expected: step1. return false.
1098      */
1099     int32_t ret = StartRemoteFreeInstall(Want::FLAG_ABILITY_CONTINUATION, GetDSchedService());
1100     EXPECT_TRUE(ret != ERR_OK);
1101     DTEST_LOG << "DSchedContinuationTest StartRemoteFreeInstall_002 end" << std::endl;
1102 }
1103 
1104 /**
1105  * @tc.name: StartFreeInstallFromRemote_001
1106  * @tc.desc: call StartFreeInstallFromRemote with illegal param
1107  * @tc.type: FUNC
1108  */
1109 HWTEST_F(DSchedContinuationTest, StartFreeInstallFromRemote_001, TestSize.Level0)
1110 {
1111     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_001 start" << std::endl;
1112     sptr<IDistributedSched> proxy = GetDms();
1113     if (proxy == nullptr) {
1114         return;
1115     }
1116     AAFwk::Want want;
1117     CallerInfo callerInfo;
1118     callerInfo.uid = 0;
1119     callerInfo.sourceDeviceId = "255.255.255.255";
1120     IDistributedSched::AccountInfo accountInfo;
1121     IDistributedSched::FreeInstallInfo info = {.want = want,
1122         .requestCode = 0,
1123         .callerInfo = callerInfo,
1124         .accountInfo = accountInfo
1125     };
1126     /**
1127      * @tc.steps: step1. StartFreeInstallFromRemote with uninitialized params
1128      * @tc.expected: step1. StartFreeInstallFromRemote return INVALID_REMOTE_PARAMETERS_ERR
1129      */
1130     int result1 = proxy->StartFreeInstallFromRemote(info, 0);
1131     DTEST_LOG << "result1:" << result1 << std::endl;
1132     /**
1133      * @tc.steps: step1. StartFreeInstallFromRemote with with empty deviceId
1134      * @tc.expected: step1. StartFreeInstallFromRemote return INVALID_REMOTE_PARAMETERS_ERR
1135      */
1136     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1137         "com.ohos.distributedmusicplayer.MainAbility");
1138     want.SetElement(element);
1139     int result2 = proxy->StartFreeInstallFromRemote(info, 0);
1140     DTEST_LOG << "result2:" << result2 << std::endl;
1141     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_001 end" << std::endl;
1142 }
1143 
1144 /**
1145  * @tc.name: StartFreeInstallFromRemote_002
1146  * @tc.desc: call StartFreeInstallFromRemote
1147  * @tc.type: FUNC
1148  */
1149 HWTEST_F(DSchedContinuationTest, StartFreeInstallFromRemote_002, TestSize.Level1)
1150 {
1151     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_002 start" << std::endl;
1152     sptr<IDistributedSched> proxy = GetDms();
1153     if (proxy == nullptr) {
1154         return;
1155     }
1156 
1157     AAFwk::Want want;
1158     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1159         "com.ohos.distributedmusicplayer.MainAbility");
1160     want.SetElement(element);
1161     CallerInfo callerInfo;
1162     callerInfo.uid = 0;
1163     callerInfo.sourceDeviceId = "255.255.255.255";
1164     IDistributedSched::AccountInfo accountInfo;
1165     IDistributedSched::FreeInstallInfo info = {.want = want,
1166         .requestCode = 0,
1167         .callerInfo = callerInfo,
1168         .accountInfo = accountInfo
1169     };
1170 
1171     int result1 = proxy->StartFreeInstallFromRemote(info, 0);
1172     DTEST_LOG << "result1 is" << result1 << std::endl;
1173 
1174     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
1175         "com.ohos.distributedmusicplayer.MainAbilityService");
1176     want.SetElement(element2);
1177     int result2 = proxy->StartFreeInstallFromRemote(info, 0);
1178     DTEST_LOG << "result2:" << result2 << std::endl;
1179     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_002 end" << std::endl;
1180 }
1181 
1182 /**
1183  * @tc.name: StartFreeInstallFromRemote_003
1184  * @tc.desc: call StartFreeInstallFromRemote for pressure test
1185  * @tc.type: FUNC
1186  */
1187 HWTEST_F(DSchedContinuationTest, StartFreeInstallFromRemote_003, TestSize.Level1)
1188 {
1189     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_003 start" << std::endl;
1190     sptr<IDistributedSched> proxy = GetDms();
1191     if (proxy == nullptr) {
1192         return;
1193     }
1194     /**
1195      * @tc.steps: step1. set want and abilityInfo
1196      */
1197     AAFwk::Want want;
1198     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1199         "com.ohos.distributedmusicplayer.MainAbility");
1200     want.SetElement(element);
1201     CallerInfo callerInfo;
1202     callerInfo.uid = 0;
1203     callerInfo.sourceDeviceId = "255.255.255.255";
1204     IDistributedSched::AccountInfo accountInfo;
1205     IDistributedSched::FreeInstallInfo info = {.want = want,
1206         .requestCode = 0,
1207         .callerInfo = callerInfo,
1208         .accountInfo = accountInfo
1209     };
1210     /**
1211      * @tc.steps: step2. StartFreeInstallFromRemote for pressure test
1212      * @tc.expected: step2. StartFreeInstallFromRemote for result
1213      */
1214     for (int index = 0; index < static_cast<int32_t>(LoopTime::LOOP_TIME); index++) {
1215         int result = proxy->StartFreeInstallFromRemote(info, 0);
1216         DTEST_LOG << "pressure" + std::to_string(index) + " result is " << result << std::endl;
1217     }
1218     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_003 end" << std::endl;
1219 }
1220 
1221 /**
1222  * @tc.name: StartFreeInstallFromRemote_004
1223  * @tc.desc: call StartFreeInstallFromRemote with dms
1224  * @tc.type: FUNC
1225  */
1226 HWTEST_F(DSchedContinuationTest, StartFreeInstallFromRemote_004, TestSize.Level0)
1227 {
1228     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_004 start" << std::endl;
1229     sptr<IDistributedSched> proxy = GetDms();
1230 
1231     AAFwk::Want want;
1232     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1233         "com.ohos.distributedmusicplayer.MainAbility");
1234     want.SetElement(element);
1235     CallerInfo callerInfo;
1236     callerInfo.uid = 0;
1237     callerInfo.sourceDeviceId = "255.255.255.255";
1238     IDistributedSched::AccountInfo accountInfo;
1239     IDistributedSched::FreeInstallInfo info = {.want = want,
1240         .requestCode = 0,
1241         .callerInfo = callerInfo,
1242         .accountInfo = accountInfo
1243     };
1244 
1245     int result1 = DistributedSchedService::GetInstance().StartFreeInstallFromRemote(info, 0);
1246     DTEST_LOG << "result1:" << result1 << std::endl;
1247 
1248     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
1249         "com.ohos.distributedmusicplayer.MainAbilityService");
1250     want.SetElement(element2);
1251     int result2 = DistributedSchedService::GetInstance().StartFreeInstallFromRemote(info, 0);
1252     DTEST_LOG << "result2:" << result2 << std::endl;
1253     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result1);
1254     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result2);
1255     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_004 end" << std::endl;
1256 }
1257 
1258 /**
1259  * @tc.name: StartFreeInstallFromRemote_005
1260  * @tc.desc: call StartFreeInstallFromRemote with dms
1261  * @tc.type: FUNC
1262  */
1263 HWTEST_F(DSchedContinuationTest, StartFreeInstallFromRemote_005, TestSize.Level1)
1264 {
1265     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_005 start" << std::endl;
1266     sptr<IDistributedSched> proxy = GetDms();
1267 
1268     AAFwk::Want want;
1269     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1270         "com.ohos.distributedmusicplayer.MainAbility");
1271     want.SetElement(element);
1272     CallerInfo callerInfo;
1273     callerInfo.uid = 0;
1274     callerInfo.sourceDeviceId = "255.255.255.255";
1275     IDistributedSched::AccountInfo accountInfo;
1276     accountInfo.accountType = 1;
1277     accountInfo.groupIdList.push_back("123456");
1278     IDistributedSched::FreeInstallInfo info = {.want = want,
1279         .requestCode = 0,
1280         .callerInfo = callerInfo,
1281         .accountInfo = accountInfo
1282     };
1283 
1284     int result1 = DistributedSchedService::GetInstance().StartFreeInstallFromRemote(info, 0);
1285     DTEST_LOG << "result1:" << result1 << std::endl;
1286 
1287     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
1288         "com.ohos.distributedmusicplayer.MainAbilityService");
1289     want.SetElement(element2);
1290     int result2 = DistributedSchedService::GetInstance().StartFreeInstallFromRemote(info, 0);
1291     DTEST_LOG << "result2:" << result2 << std::endl;
1292     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_005 end" << std::endl;
1293 }
1294 
1295 /**
1296  * @tc.name: StartFreeInstallFromRemote_006
1297  * @tc.desc: call StartFreeInstallFromRemote
1298  * @tc.type: FUNC
1299  */
1300 HWTEST_F(DSchedContinuationTest, StartFreeInstallFromRemote_006, TestSize.Level1)
1301 {
1302     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_006 start" << std::endl;
1303     sptr<IDistributedSched> proxy = GetDms();
1304     if (proxy == nullptr) {
1305         return;
1306     }
1307 
1308     AAFwk::Want want;
1309     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1310         "com.ohos.distributedmusicplayer.MainAbility");
1311     want.SetElement(element);
1312     CallerInfo callerInfo;
1313     callerInfo.uid = 0;
1314     callerInfo.sourceDeviceId = "255.255.255.255";
1315     callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1316     IDistributedSched::AccountInfo accountInfo;
1317     IDistributedSched::FreeInstallInfo info = {.want = want,
1318         .requestCode = 0,
1319         .callerInfo = callerInfo,
1320         .accountInfo = accountInfo
1321     };
1322 
1323     int result1 = proxy->StartFreeInstallFromRemote(info, 0);
1324     DTEST_LOG << "result1 is" << result1 << std::endl;
1325 
1326     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
1327         "com.ohos.distributedmusicplayer.MainAbilityService");
1328     want.SetElement(element2);
1329     int result2 = proxy->StartFreeInstallFromRemote(info, 0);
1330     DTEST_LOG << "result2:" << result2 << std::endl;
1331     DTEST_LOG << "DSchedContinuationTest StartFreeInstallFromRemote_006 end" << std::endl;
1332 }
1333 
1334 /**
1335  * @tc.name: NotifyCompleteFreeInstall_001
1336  * @tc.desc: input invalid taskId.
1337  * @tc.type: FUNC
1338  */
1339 HWTEST_F(DSchedContinuationTest, NotifyCompleteFreeInstall_001, TestSize.Level1)
1340 {
1341     DTEST_LOG << "DSchedContinuationTest NotifyCompleteFreeInstall_001 start" << std::endl;
1342     /**
1343      * @tc.steps: step1. input invalid taskId.
1344      * @tc.expected: step1. return false.
1345      */
1346     IDistributedSched::FreeInstallInfo info;
1347     DistributedSchedService::GetInstance().NotifyCompleteFreeInstall(info, -1, 0);
1348     EXPECT_TRUE(!freeInstallTimeoutFlag_);
1349     DTEST_LOG << "DSchedContinuationTest NotifyCompleteFreeInstall_001 end" << std::endl;
1350 }
1351 
1352 /**
1353  * @tc.name: NotifyCompleteFreeInstall_002
1354  * @tc.desc: get remote dms failed.
1355  * @tc.type: FUNC
1356  */
1357 HWTEST_F(DSchedContinuationTest, NotifyCompleteFreeInstall_002, TestSize.Level1)
1358 {
1359     DTEST_LOG << "DSchedContinuationTest NotifyCompleteFreeInstall_002 start" << std::endl;
1360     /**
1361      * @tc.steps: step1. get remote dms failed.
1362      * @tc.expected: step1. return false.
1363      */
1364     IDistributedSched::FreeInstallInfo info;
1365     DistributedSchedService::GetInstance().NotifyCompleteFreeInstall(info, MOCK_TASK_ID, 0);
1366     EXPECT_TRUE(!freeInstallTimeoutFlag_);
1367     DTEST_LOG << "DSchedContinuationTest NotifyCompleteFreeInstall_002 end" << std::endl;
1368 }
1369 
1370 /**
1371  * @tc.name: NotifyCompleteFreeInstallFromRemote_001
1372  * @tc.desc: input invalid taskId.
1373  * @tc.type: FUNC
1374  */
1375 HWTEST_F(DSchedContinuationTest, NotifyCompleteFreeInstallFromRemote_001, TestSize.Level1)
1376 {
1377     DTEST_LOG << "DSchedContinuationTest NotifyCompleteFreeInstallFromRemote_001 start" << std::endl;
1378     /**
1379      * @tc.steps: step1. input invalid taskId.
1380      * @tc.expected: step1. return false.
1381      */
1382     DistributedSchedService::GetInstance().NotifyCompleteFreeInstallFromRemote(-1, 0);
1383     EXPECT_TRUE(!freeInstallTimeoutFlag_);
1384     DTEST_LOG << "DSchedContinuationTest NotifyCompleteFreeInstallFromRemote_001 end" << std::endl;
1385 }
1386 
1387 /**
1388  * @tc.name: NotifyCompleteFreeInstallFromRemote_002
1389  * @tc.desc: dmsCallbackTask_ or dschedContinuation_ is nullptr.
1390  * @tc.type: FUNC
1391  */
1392 HWTEST_F(DSchedContinuationTest, NotifyCompleteFreeInstallFromRemote_002, TestSize.Level1)
1393 {
1394     DTEST_LOG << "DSchedContinuationTest NotifyCompleteFreeInstallFromRemote_002 start" << std::endl;
1395     /**
1396      * @tc.steps: step1. dmsCallbackTask_ or dschedContinuation_ is nullptr.
1397      * @tc.expected: step1. return false.
1398      */
1399     DistributedSchedService::GetInstance().NotifyCompleteFreeInstallFromRemote(MOCK_TASK_ID, 0);
1400     EXPECT_TRUE(!freeInstallTimeoutFlag_);
1401     DTEST_LOG << "DSchedContinuationTest NotifyCompleteFreeInstallFromRemote_002 end" << std::endl;
1402 }
1403 
1404 /**
1405  * @tc.name: IsFreeInstall_001
1406  * @tc.desc: missionId is not exist.
1407  * @tc.type: FUNC
1408  * @tc.require: I5WKCK
1409  */
1410 HWTEST_F(DSchedContinuationTest, IsFreeInstall_001, TestSize.Level1)
1411 {
1412     DTEST_LOG << "DSchedContinuationTest IsFreeInstall_001 start" << std::endl;
1413     ASSERT_NE(dschedContinuation_, nullptr);
1414     int32_t missionId = -1;
1415     bool result = dschedContinuation_->IsFreeInstall(missionId);
1416     EXPECT_EQ(result, false);
1417     DTEST_LOG << "DSchedContinuationTest IsFreeInstall_001 end" << std::endl;
1418 }
1419 
1420 /**
1421  * @tc.name: IsFreeInstall_002
1422  * @tc.desc: missionId is exist.
1423  * @tc.type: FUNC
1424  * @tc.require: I5WKCK
1425  */
1426 HWTEST_F(DSchedContinuationTest, IsFreeInstall_002, TestSize.Level1)
1427 {
1428     DTEST_LOG << "DSchedContinuationTest IsFreeInstall_002 start" << std::endl;
1429     ASSERT_NE(dschedContinuation_, nullptr);
1430     int32_t missionId = 1;
1431     dschedContinuation_->freeInstall_[missionId] = true;
1432     bool result = dschedContinuation_->IsFreeInstall(missionId);
1433     EXPECT_EQ(result, true);
1434     DTEST_LOG << "DSchedContinuationTest IsFreeInstall_002 end" << std::endl;
1435 }
1436 
1437 /**
1438  * @tc.name: IsFreeInstall_003
1439  * @tc.desc: missionId is exist.
1440  * @tc.type: FUNC
1441  * @tc.require: I5WKCK
1442  */
1443 HWTEST_F(DSchedContinuationTest, IsFreeInstall_003, TestSize.Level1)
1444 {
1445     DTEST_LOG << "DSchedContinuationTest IsFreeInstall_003 start" << std::endl;
1446     ASSERT_NE(dschedContinuation_, nullptr);
1447     int32_t missionId = 1;
1448     dschedContinuation_->freeInstall_[missionId] = false;
1449     bool result = dschedContinuation_->IsFreeInstall(missionId);
1450     EXPECT_EQ(result, false);
1451     DTEST_LOG << "DSchedContinuationTest IsFreeInstall_003 end" << std::endl;
1452 }
1453 
1454 /**
1455  * @tc.name: PopCallback_001
1456  * @tc.desc: missionId is not exist in callbackMap_.
1457  * @tc.type: FUNC
1458  * @tc.require: I5WKCK
1459  */
1460 HWTEST_F(DSchedContinuationTest, PopCallback_001, TestSize.Level1)
1461 {
1462     DTEST_LOG << "DSchedContinuationTest PopCallback_001 start" << std::endl;
1463     ASSERT_NE(dschedContinuation_, nullptr);
1464     int32_t missionId = -1;
1465     dschedContinuation_->callbackMap_.erase(missionId);
1466     sptr<IRemoteObject> result = dschedContinuation_->PopCallback(missionId);
1467     EXPECT_EQ(result, nullptr);
1468     DTEST_LOG << "DSchedContinuationTest PopCallback_001 end" << std::endl;
1469 }
1470 
1471 /**
1472  * @tc.name: PopCallback_002
1473  * @tc.desc: missionId is not exist in continuationDevices_.
1474  * @tc.type: FUNC
1475  * @tc.require: I5WKCK
1476  */
1477 HWTEST_F(DSchedContinuationTest, PopCallback_002, TestSize.Level1)
1478 {
1479     DTEST_LOG << "DSchedContinuationTest PopCallback_002 start" << std::endl;
1480     ASSERT_NE(dschedContinuation_, nullptr);
1481     int32_t missionId = -1;
1482     dschedContinuation_->callbackMap_[missionId] = GetDSchedService();
1483     dschedContinuation_->continuationDevices_.erase(missionId);
1484     sptr<IRemoteObject> result = dschedContinuation_->PopCallback(missionId);
1485     EXPECT_NE(result, nullptr);
1486     DTEST_LOG << "DSchedContinuationTest PopCallback_002 end" << std::endl;
1487 }
1488 
1489 /**
1490  * @tc.name: PopCallback_003
1491  * @tc.desc: missionId is not exist in freeInstall_.
1492  * @tc.type: FUNC
1493  * @tc.require: I5WKCK
1494  */
1495 HWTEST_F(DSchedContinuationTest, PopCallback_003, TestSize.Level1)
1496 {
1497     DTEST_LOG << "DSchedContinuationTest PopCallback_003 start" << std::endl;
1498     ASSERT_NE(dschedContinuation_, nullptr);
1499     int32_t missionId = -1;
1500     dschedContinuation_->callbackMap_[missionId] = GetDSchedService();
1501     dschedContinuation_->continuationDevices_[missionId] = "mockDevices";
1502     dschedContinuation_->freeInstall_.erase(missionId);
1503     sptr<IRemoteObject> result = dschedContinuation_->PopCallback(missionId);
1504     EXPECT_NE(result, nullptr);
1505     DTEST_LOG << "DSchedContinuationTest PopCallback_003 end" << std::endl;
1506 }
1507 
1508 /**
1509  * @tc.name: PopCallback_004
1510  * @tc.desc: missionId is exist.
1511  * @tc.type: FUNC
1512  * @tc.require: I5WKCK
1513  */
1514 HWTEST_F(DSchedContinuationTest, PopCallback_004, TestSize.Level1)
1515 {
1516     DTEST_LOG << "DSchedContinuationTest PopCallback_004 start" << std::endl;
1517     ASSERT_NE(dschedContinuation_, nullptr);
1518     int32_t missionId = -1;
1519     dschedContinuation_->callbackMap_[missionId] = GetDSchedService();
1520     dschedContinuation_->continuationDevices_[missionId] = "mockDevices";
1521     dschedContinuation_->freeInstall_[missionId] = true;
1522     sptr<IRemoteObject> result = dschedContinuation_->PopCallback(missionId);
1523     EXPECT_NE(result, nullptr);
1524     DTEST_LOG << "DSchedContinuationTest PopCallback_004 end" << std::endl;
1525 }
1526 
1527 /**
1528  * @tc.name: NotifyMissionCenterResult_001
1529  * @tc.desc: missionId is not exist in callbackMap_.
1530  * @tc.type: FUNC
1531  * @tc.require: I5WKCK
1532  */
1533 HWTEST_F(DSchedContinuationTest, NotifyMissionCenterResult_001, TestSize.Level1)
1534 {
1535     DTEST_LOG << "DSchedContinuationTest NotifyMissionCenterResult_001 start" << std::endl;
1536     ASSERT_NE(dschedContinuation_, nullptr);
1537     int32_t missionId = -1;
1538     int32_t resultCode = 0;
1539     dschedContinuation_->callbackMap_[missionId] = nullptr;
1540     int32_t result = dschedContinuation_->NotifyMissionCenterResult(missionId, resultCode);
1541     EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1542     DTEST_LOG << "DSchedContinuationTest NotifyMissionCenterResult_001 end" << std::endl;
1543 }
1544 
1545 /**
1546  * @tc.name: NotifyMissionCenterResult_002
1547  * @tc.desc: missionId is exist.
1548  * @tc.type: FUNC
1549  * @tc.require: I5WKCK
1550  */
1551 HWTEST_F(DSchedContinuationTest, NotifyMissionCenterResult_002, TestSize.Level1)
1552 {
1553     DTEST_LOG << "DSchedContinuationTest NotifyMissionCenterResult_002 start" << std::endl;
1554     ASSERT_NE(dschedContinuation_, nullptr);
1555     int32_t missionId = -1;
1556     int32_t resultCode = 0;
1557     dschedContinuation_->callbackMap_[missionId] = GetDSchedService();
1558     dschedContinuation_->NotifyMissionCenterResult(missionId, resultCode);
1559     EXPECT_EQ(dschedContinuation_->callbackMap_.size(), 0);
1560     DTEST_LOG << "DSchedContinuationTest NotifyMissionCenterResult_002 end" << std::endl;
1561 }
1562 
1563 /**
1564  * @tc.name: ProxyCallContinueMission001
1565  * @tc.desc: call dms proxy ContinueMission
1566  * @tc.type: FUNC
1567  * @tc.require: I5X9O4
1568  */
1569 HWTEST_F(DSchedContinuationTest, ProxyCallContinueMission001, TestSize.Level3)
1570 {
1571     DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission001 start" << std::endl;
1572     sptr<IDistributedSched> proxy = GetDms();
1573     EXPECT_NE(proxy, nullptr);
1574     std::string srcDeviceId;
1575     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
1576     WantParams wantParams;
1577     int32_t ret = proxy->ContinueMission(srcDeviceId, "MockdevId", 0, GetDSchedService(), wantParams);
1578     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1579     DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission001 end" << std::endl;
1580 }
1581 
1582 /**
1583  * @tc.name: ProxyCallContinueMission002
1584  * @tc.desc: call dms proxy ContinueMission
1585  * @tc.type: FUNC
1586  * @tc.require: I5X9O4
1587  */
1588 HWTEST_F(DSchedContinuationTest, ProxyCallContinueMission002, TestSize.Level3)
1589 {
1590     DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission002 start" << std::endl;
1591     sptr<IDistributedSched> proxy = GetDms();
1592     EXPECT_NE(proxy, nullptr);
1593     std::string srcDeviceId;
1594     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
1595     WantParams wantParams;
1596     int32_t ret = proxy->ContinueMission(srcDeviceId, "MockdevId", 0, nullptr, wantParams);
1597     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1598     DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission002 end" << std::endl;
1599 }
1600 
1601 /**
1602  * @tc.name: ProxyCallStartContinuation001
1603  * @tc.desc: call dms proxy StartContinuation
1604  * @tc.type: FUNC
1605  * @tc.require: I5X9O4
1606  */
1607 HWTEST_F(DSchedContinuationTest, ProxyCallStartContinuation001, TestSize.Level3)
1608 {
1609     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartContinuation001 start" << std::endl;
1610     sptr<IDistributedSched> proxy = GetDms();
1611     EXPECT_NE(proxy, nullptr);
1612     OHOS::AAFwk::Want want;
1613     want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1614     int32_t ret = proxy->StartContinuation(want, 0, 0, 0, 0);
1615     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1616     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartContinuation001 end" << std::endl;
1617 }
1618 
1619 /**
1620  * @tc.name: ProxyCallNotifyContinuationResultFromRemote001
1621  * @tc.desc: call dms proxy NotifyContinuationResultFromRemote
1622  * @tc.type: FUNC
1623  * @tc.require: I5X9O4
1624  */
1625 HWTEST_F(DSchedContinuationTest, ProxyCallNotifyContinuationResultFromRemote001, TestSize.Level3)
1626 {
1627     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyContinuationResultFromRemote001 start" << std::endl;
1628     sptr<IDistributedSched> proxy = GetDms();
1629     EXPECT_NE(proxy, nullptr);
1630     std::string srcDeviceId;
1631     std::string info;
1632     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
1633     proxy->NotifyCompleteContinuation(Str8ToStr16(srcDeviceId), 0, true);
1634     int32_t ret = proxy->NotifyContinuationResultFromRemote(0, true, info);
1635     EXPECT_EQ(ret, REQUEST_CODE_ERR);
1636     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyContinuationResultFromRemote001 end" << std::endl;
1637 }
1638 
1639 /**
1640  * @tc.name: NotifyProcessDiedFromRemote001
1641  * @tc.desc: call dms proxy NotifyProcessDiedFromRemote
1642  * @tc.type: FUNC
1643  * @tc.require: I5X9O4
1644  */
1645 HWTEST_F(DSchedContinuationTest, ProxyCallNotifyProcessDiedFromRemote001, TestSize.Level3)
1646 {
1647     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyProcessDiedFromRemote001 start" << std::endl;
1648     sptr<IDistributedSched> proxy = GetDms();
1649     if (proxy == nullptr) {
1650         return;
1651     }
1652     CallerInfo callerInfo;
1653     callerInfo.sourceDeviceId = "255.255.255.255";
1654     callerInfo.uid = 0;
1655     callerInfo.sourceDeviceId = "123456";
1656     int32_t ret = proxy->NotifyProcessDiedFromRemote(callerInfo);
1657     EXPECT_NE(ret, ERR_NULL_OBJECT);
1658     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyProcessDiedFromRemote001 end" << std::endl;
1659 }
1660 
1661 /**
1662  * @tc.name: StartRemoteAbilityByCall001
1663  * @tc.desc: call dms proxy StartRemoteAbilityByCall
1664  * @tc.type: FUNC
1665  * @tc.require: I5X9O4
1666  */
1667 HWTEST_F(DSchedContinuationTest, ProxyCallStartRemoteAbilityByCall001, TestSize.Level3)
1668 {
1669     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteAbilityByCall001 start" << std::endl;
1670     sptr<IDistributedSched> proxy = GetDms();
1671     EXPECT_NE(proxy, nullptr);
1672     std::string bundleName = "bundleName";
1673     std::string abilityName = "abilityName";
1674     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
1675     int32_t ret = proxy->StartRemoteAbilityByCall(*spWant, nullptr, 0, 0, 1);
1676     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1677     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteAbilityByCall001 end" << std::endl;
1678 }
1679 
1680 /**
1681  * @tc.name: StartRemoteAbilityByCall001
1682  * @tc.desc: call dms proxy StartRemoteAbilityByCall
1683  * @tc.type: FUNC
1684  * @tc.require: I5X9O4
1685  */
1686 HWTEST_F(DSchedContinuationTest, ProxyCallStartRemoteAbilityByCall002, TestSize.Level3)
1687 {
1688     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteAbilityByCall002 start" << std::endl;
1689     sptr<IDistributedSched> proxy = GetDms();
1690     if (proxy == nullptr) {
1691         return;
1692     }
1693     std::string bundleName = "bundleName";
1694     std::string abilityName = "abilityName";
1695     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
1696     int32_t ret = proxy->StartRemoteAbilityByCall(*spWant, GetDSchedService(), 0, 0, 1);
1697     EXPECT_NE(ret, ERR_NULL_OBJECT);
1698     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteAbilityByCall002 end" << std::endl;
1699 }
1700 
1701 /**
1702  * @tc.name: ReleaseRemoteAbility001
1703  * @tc.desc: call dms proxy ReleaseRemoteAbility
1704  * @tc.type: FUNC
1705  * @tc.require: I5X9O4
1706  */
1707 HWTEST_F(DSchedContinuationTest, ProxyCallReleaseRemoteAbility001, TestSize.Level3)
1708 {
1709     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility001 start" << std::endl;
1710     sptr<IDistributedSched> proxy = GetDms();
1711     EXPECT_NE(proxy, nullptr);
1712     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1713         "com.ohos.distributedmusicplayer.MainAbility");
1714     int32_t ret = proxy->ReleaseRemoteAbility(nullptr, element);
1715     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1716     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility001 end" << std::endl;
1717 }
1718 
1719 /**
1720  * @tc.name: ReleaseRemoteAbility002
1721  * @tc.desc: call dms proxy ReleaseRemoteAbility
1722  * @tc.type: FUNC
1723  * @tc.require: I5X9O4
1724  */
1725 HWTEST_F(DSchedContinuationTest, ProxyCallReleaseRemoteAbility002, TestSize.Level3)
1726 {
1727     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility002 start" << std::endl;
1728     sptr<IDistributedSched> proxy = GetDms();
1729     if (proxy == nullptr) {
1730         return;
1731     }
1732     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1733         "com.ohos.distributedmusicplayer.MainAbility");
1734     int32_t ret = proxy->ReleaseRemoteAbility(GetDSchedService(), element);
1735     EXPECT_NE(ret, ERR_NULL_OBJECT);
1736     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility002 end" << std::endl;
1737 }
1738 
1739 /**
1740  * @tc.name: ProxyCallStartAbilityByCallFromRemote001
1741  * @tc.desc: call dms proxy StartAbilityByCallFromRemote
1742  * @tc.type: FUNC
1743  * @tc.require: I5X9O4
1744  */
1745 HWTEST_F(DSchedContinuationTest, ProxyCallStartAbilityByCallFromRemote001, TestSize.Level3)
1746 {
1747     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility001 start" << std::endl;
1748     sptr<IDistributedSched> proxy = GetDms();
1749     EXPECT_NE(proxy, nullptr);
1750     // mock want
1751     std::string bundleName = "bundleName";
1752     std::string abilityName = "abilityName";
1753     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
1754     // mock callerinfo
1755     CallerInfo callerInfo;
1756     callerInfo.sourceDeviceId = "255.255.255.255";
1757     callerInfo.uid = 0;
1758     callerInfo.sourceDeviceId = "123456";
1759     // mock accountInfo
1760     IDistributedSched::AccountInfo accountInfo;
1761     accountInfo.accountType = 1;
1762     accountInfo.groupIdList.push_back("123456");
1763 
1764     int32_t ret = proxy->StartAbilityByCallFromRemote(*spWant, nullptr, callerInfo, accountInfo);
1765     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1766     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility001 end" << std::endl;
1767 }
1768 
1769 /**
1770  * @tc.name: StartAbilityByCallFromRemote002
1771  * @tc.desc: call dms proxy StartAbilityByCallFromRemote
1772  * @tc.type: FUNC
1773  * @tc.require: I5X9O4
1774  */
1775 HWTEST_F(DSchedContinuationTest, ProxyCallStartAbilityByCallFromRemote002, TestSize.Level3)
1776 {
1777     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility002 start" << std::endl;
1778     sptr<IDistributedSched> proxy = GetDms();
1779     if (proxy == nullptr) {
1780         return;
1781     }
1782     // mock want
1783     std::string bundleName = "bundleName";
1784     std::string abilityName = "abilityName";
1785     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
1786     // mock callerinfo
1787     CallerInfo callerInfo;
1788     callerInfo.sourceDeviceId = "255.255.255.255";
1789     callerInfo.uid = 0;
1790     callerInfo.sourceDeviceId = "123456";
1791     // mock accountInfo
1792     IDistributedSched::AccountInfo accountInfo;
1793     accountInfo.accountType = 1;
1794     accountInfo.groupIdList.push_back("123456");
1795 
1796     int32_t ret = proxy->StartAbilityByCallFromRemote(*spWant, GetDSchedService(), callerInfo, accountInfo);
1797     EXPECT_NE(ret, ERR_NULL_OBJECT);
1798     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility002 end" << std::endl;
1799 }
1800 
1801 /**
1802  * @tc.name: ReleaseAbilityFromRemote001
1803  * @tc.desc: call dms proxy ReleaseAbilityFromRemote
1804  * @tc.type: FUNC
1805  * @tc.require: I5X9O4
1806  */
1807 HWTEST_F(DSchedContinuationTest, ProxyCallReleaseAbilityFromRemote001, TestSize.Level3)
1808 {
1809     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseAbilityFromRemote001 start" << std::endl;
1810     sptr<IDistributedSched> proxy = GetDms();
1811     EXPECT_NE(proxy, nullptr);
1812     // mock callerinfo
1813     CallerInfo callerInfo;
1814     callerInfo.sourceDeviceId = "255.255.255.255";
1815     callerInfo.uid = 0;
1816     callerInfo.sourceDeviceId = "123456";
1817 
1818     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1819         "com.ohos.distributedmusicplayer.MainAbility");
1820     int32_t ret = proxy->ReleaseAbilityFromRemote(nullptr, element, callerInfo);
1821     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1822     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseAbilityFromRemote001 end" << std::endl;
1823 }
1824 
1825 /**
1826  * @tc.name: ReleaseAbilityFromRemote002
1827  * @tc.desc: call dms proxy ReleaseAbilityFromRemote
1828  * @tc.type: FUNC
1829  * @tc.require: I5X9O4
1830  */
1831 HWTEST_F(DSchedContinuationTest, ProxyCallReleaseAbilityFromRemote002, TestSize.Level3)
1832 {
1833     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseAbilityFromRemote002 start" << std::endl;
1834     sptr<IDistributedSched> proxy = GetDms();
1835     if (proxy == nullptr) {
1836         return;
1837     }
1838     // mock callerinfo
1839     CallerInfo callerInfo;
1840     callerInfo.sourceDeviceId = "255.255.255.255";
1841     callerInfo.uid = 0;
1842     callerInfo.sourceDeviceId = "123456";
1843 
1844     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1845         "com.ohos.distributedmusicplayer.MainAbility");
1846     int32_t ret = proxy->ReleaseAbilityFromRemote(GetDSchedService(), element, callerInfo);
1847     EXPECT_NE(ret, ERR_NULL_OBJECT);
1848     DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseAbilityFromRemote002 end" << std::endl;
1849 }
1850 
1851 /**
1852  * @tc.name: StartRemoteFreeInstall001
1853  * @tc.desc: call dms proxy StartRemoteFreeInstall
1854  * @tc.type: FUNC
1855  * @tc.require: I5X9O4
1856  */
1857 HWTEST_F(DSchedContinuationTest, ProxyCallStartRemoteFreeInstall001, TestSize.Level3)
1858 {
1859     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteFreeInstall001 start" << std::endl;
1860     sptr<IDistributedSched> proxy = GetDms();
1861     if (proxy == nullptr) {
1862         return;
1863     }
1864     // mock want
1865     std::string bundleName = "bundleName";
1866     std::string abilityName = "abilityName";
1867     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
1868 
1869     int32_t ret = proxy->StartRemoteFreeInstall(*spWant, 0, 1, 1, GetDSchedService());
1870     EXPECT_NE(ret, ERR_NULL_OBJECT);
1871     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteFreeInstall001 end" << std::endl;
1872 }
1873 
1874 /**
1875  * @tc.name: StartRemoteFreeInstall002
1876  * @tc.desc: call dms proxy StartRemoteFreeInstall
1877  * @tc.type: FUNC
1878  * @tc.require: I5X9O4
1879  */
1880 HWTEST_F(DSchedContinuationTest, ProxyCallStartRemoteFreeInstall002, TestSize.Level3)
1881 {
1882     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteFreeInstall002 start" << std::endl;
1883     sptr<IDistributedSched> proxy = GetDms();
1884     EXPECT_NE(proxy, nullptr);
1885     // mock want
1886     std::string bundleName = "bundleName";
1887     std::string abilityName = "abilityName";
1888     std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
1889 
1890     int32_t ret = proxy->StartRemoteFreeInstall(*spWant, 0, 1, 1, nullptr);
1891     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1892     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteFreeInstall002 end" << std::endl;
1893 }
1894 
1895 /**
1896  * @tc.name: NotifyCompleteFreeInstallFromRemote001
1897  * @tc.desc: call dms proxy NotifyCompleteFreeInstallFromRemote
1898  * @tc.type: FUNC
1899  * @tc.require: I5X9O4
1900  */
1901 HWTEST_F(DSchedContinuationTest, ProxyCallNotifyCompleteFreeInstallFromRemote001, TestSize.Level3)
1902 {
1903     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyCompleteFreeInstallFromRemote001 start" << std::endl;
1904     sptr<IDistributedSched> proxy = GetDms();
1905     if (proxy == nullptr) {
1906         return;
1907     }
1908     int32_t ret = proxy->NotifyCompleteFreeInstallFromRemote(1, 1);
1909     EXPECT_NE(ret, ERR_NULL_OBJECT);
1910     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyCompleteFreeInstallFromRemote001 end" << std::endl;
1911 }
1912 
1913 /**
1914  * @tc.name: GetDistributedComponentList001
1915  * @tc.desc: call dms proxy GetDistributedComponentList
1916  * @tc.type: FUNC
1917  * @tc.require: I5X9O4
1918  */
1919 HWTEST_F(DSchedContinuationTest, ProxyCallGetDistributedComponentList001, TestSize.Level3)
1920 {
1921     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetDistributedComponentList001 start" << std::endl;
1922     sptr<IDistributedSched> proxy = GetDms();
1923     if (proxy == nullptr) {
1924         return;
1925     }
1926     vector<string> distributedComponents = { "test "};
1927     int32_t ret = proxy->GetDistributedComponentList(distributedComponents);
1928     EXPECT_NE(ret, ERR_NULL_OBJECT);
1929     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetDistributedComponentList001 end" << std::endl;
1930 }
1931 
1932 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
1933 /**
1934  * @tc.name: StartShareFormFromRemote001
1935  * @tc.desc: call dms proxy StartShareFormFromRemote
1936  * @tc.type: FUNC
1937  * @tc.require: I5X9O4
1938  */
1939 HWTEST_F(DSchedContinuationTest, ProxyCallStartShareFormFromRemote001, TestSize.Level3)
1940 {
1941     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartShareFormFromRemote001 start" << std::endl;
1942     sptr<IDistributedSched> proxy = GetDms();
1943     EXPECT_NE(proxy, nullptr);
1944     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
1945     int32_t ret = proxy->StartShareFormFromRemote("", formShareInfo);
1946     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1947     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartShareFormFromRemote001 end" << std::endl;
1948 }
1949 
1950 /**
1951  * @tc.name: StartShareFormFromRemote002
1952  * @tc.desc: call dms proxy StartShareFormFromRemote
1953  * @tc.type: FUNC
1954  * @tc.require: I5X9O4
1955  */
1956 HWTEST_F(DSchedContinuationTest, ProxyCallStartShareFormFromRemote002, TestSize.Level3)
1957 {
1958     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartShareFormFromRemote002 start" << std::endl;
1959     sptr<IDistributedSched> proxy = GetDms();
1960     if (proxy == nullptr) {
1961         return;
1962     }
1963     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
1964     int32_t ret = proxy->StartShareFormFromRemote("111", formShareInfo);
1965     EXPECT_NE(ret, ERR_NULL_OBJECT);
1966     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartShareFormFromRemote002 end" << std::endl;
1967 }
1968 #endif
1969 } // DistributedSchedule
1970 } // namespace OHOS
1971