• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 
16 #include "dms_mission_manager_test.h"
17 
18 #include <thread>
19 
20 #include "if_system_ability_manager.h"
21 #include "ipc_skeleton.h"
22 #include "iservice_registry.h"
23 #include "string_ex.h"
24 #include "system_ability_definition.h"
25 
26 #define private public
27 #define protected public
28 #include "distributed_sched_adapter.h"
29 #include "distributed_sched_proxy.h"
30 #include "distributed_sched_service.h"
31 #include "distributed_sched_test_util.h"
32 #include "distributed_sched_utils.h"
33 #include "dtbschedmgr_device_info_storage.h"
34 #include "mission/distributed_sched_mission_manager.h"
35 #include "mission/mission_constant.h"
36 #include "mission/snapshot_converter.h"
37 #include "test_log.h"
38 #undef private
39 #undef protected
40 
41 using namespace std;
42 using namespace testing;
43 using namespace testing::ext;
44 using namespace OHOS::DistributedHardware;
45 
46 namespace OHOS {
47 namespace DistributedSchedule {
48 namespace {
49 const std::string DEVICE_NAME = "DEVICE_PHONE_001";
50 const std::string DEVICE_ID = "123456789ABCD";
51 const std::string DEVICE_ID_FALSE = "123456789ABCDF";
52 const std::string DEVICE_ID_FALSE_AGAIN = "123456789ABCDFA";
53 const std::u16string U16DEVICE_ID = u"123456789ABCD";
54 const std::string BUNDLE_NAME = "ohos.test.test";
55 constexpr int32_t TASK_ID = 11;
56 constexpr size_t BYTESTREAM_LENGTH = 100;
57 constexpr uint8_t ONE_BYTE = '6';
58 const int32_t NUM_MISSIONS = 100;
59 const int32_t NORMAL_NUM_MISSIONS = 10;
60 constexpr int32_t REQUEST_CODE_ERR = 305;
61 constexpr int32_t MAX_WAIT_TIME = 1000;
62 }
63 
64 bool DMSMissionManagerTest::isCaseDone_ = false;
65 std::mutex DMSMissionManagerTest::caseDoneLock_;
66 std::condition_variable DMSMissionManagerTest::caseDoneCondition_;
67 
GetLocalMissionSnapshotInfo(const std::string & networkId,int32_t missionId,AAFwk::MissionSnapshot & missionSnapshot)68 int32_t DistributedSchedAdapter::GetLocalMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
69     AAFwk::MissionSnapshot& missionSnapshot)
70 {
71     return -1;
72 }
73 
SetUpTestCase()74 void DMSMissionManagerTest::SetUpTestCase()
75 {
76     if (!DistributedSchedUtil::LoadDistributedSchedService()) {
77         DTEST_LOG << "DMSMissionManagerTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
78     }
79     const std::string pkgName = "DBinderBus_" + std::to_string(getprocpid());
80     std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
81     DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
82 }
83 
TearDownTestCase()84 void DMSMissionManagerTest::TearDownTestCase()
85 {
86 }
87 
SetUp()88 void DMSMissionManagerTest::SetUp()
89 {
90     DistributedSchedUtil::MockPermission();
91     string localDeviceId;
92     if (!DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId)) {
93         DTEST_LOG << "getLocalDevicesId failed!" << std::endl;
94         return;
95     }
96     localDeviceId_ = localDeviceId;
97     u16localDeviceId_ = Str8ToStr16(localDeviceId);
98 }
99 
TearDown()100 void DMSMissionManagerTest::TearDown()
101 {
102 }
103 
OnRemoteDied()104 void DMSMissionManagerTest::DeviceInitCallBack::OnRemoteDied()
105 {
106 }
107 
GetDms()108 sptr<IDistributedSched> DMSMissionManagerTest::GetDms()
109 {
110     if (proxy_ != nullptr) {
111         return proxy_;
112     }
113     auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
114     EXPECT_TRUE(sm != nullptr);
115     if (sm == nullptr) {
116         DTEST_LOG << "DMSMissionManagerTest sm is nullptr" << std::endl;
117         return nullptr;
118     }
119     DTEST_LOG << "DMSMissionManagerTest sm is not nullptr" << std::endl;
120     auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
121     proxy_ = iface_cast<IDistributedSched>(distributedObject);
122     if (proxy_ == nullptr) {
123         DTEST_LOG << "DMSMissionManagerTest DistributedSched is nullptr" << std::endl;
124     } else {
125         DTEST_LOG << "DMSMissionManagerTest DistributedSched is not nullptr" << std::endl;
126     }
127     return proxy_;
128 }
129 
NotifyMissionsChanged(const std::string & deviceId)130 void RemoteMissionListenerTest::NotifyMissionsChanged(const std::string& deviceId)
131 {
132     DTEST_LOG << "NotifyMissionsChanged" << std::endl;
133 }
134 
NotifySnapshot(const std::string & deviceId,int32_t missionId)135 void RemoteMissionListenerTest::NotifySnapshot(const std::string& deviceId, int32_t missionId)
136 {
137     DTEST_LOG << "NotifySnapshot" << std::endl;
138 }
139 
NotifyNetDisconnect(const std::string & deviceId,int32_t state)140 void RemoteMissionListenerTest::NotifyNetDisconnect(const std::string& deviceId, int32_t state)
141 {
142     DTEST_LOG << "NotifyNetDisconnect" << std::endl;
143 }
144 
145 /**
146  * @tc.name: testGetRemoteMissionInfo001
147  * @tc.desc: get remote mission info
148  * @tc.type: FUNC
149  */
150 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo001, TestSize.Level1)
151 {
152     std::vector<AAFwk::MissionInfo> infos;
153     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, 0, infos);
154     EXPECT_TRUE(ret != ERR_NONE);
155 
156     ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(localDeviceId_, 0, infos);
157     EXPECT_TRUE(ret != ERR_NONE);
158 
159     ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos("", 0, infos);
160     EXPECT_TRUE(ret != ERR_NONE);
161 
162     ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, -1, infos);
163     EXPECT_TRUE(ret != ERR_NONE);
164 
165     ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(localDeviceId_, -1, infos);
166     EXPECT_TRUE(ret != ERR_NONE);
167 }
168 
169 /**
170  * @tc.name: testGetRemoteMissionInfo002
171  * @tc.desc: get remote mission info
172  * @tc.type: FUNC
173  */
174 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo002, TestSize.Level1)
175 {
176     sptr<IDistributedSched> proxy = GetDms();
177     ASSERT_NE(nullptr, proxy);
178     std::vector<AAFwk::MissionInfo> infos;
179     auto ret = proxy->GetMissionInfos(DEVICE_ID, 0, infos);
180     EXPECT_TRUE(ret != ERR_NONE);
181 
182     ret = proxy->GetMissionInfos(localDeviceId_, 0, infos);
183     EXPECT_TRUE(ret != ERR_NONE);
184 
185     ret = proxy->GetMissionInfos("", 0, infos);
186     EXPECT_TRUE(ret != ERR_NONE);
187 
188     ret = proxy->GetMissionInfos(DEVICE_ID, -1, infos);
189     EXPECT_TRUE(ret != ERR_NONE);
190 
191     ret = proxy->GetMissionInfos(localDeviceId_, -1, infos);
192     EXPECT_TRUE(ret != ERR_NONE);
193 }
194 
195 /**
196  * @tc.name: testStartSyncRemoteMissions001
197  * @tc.desc: prepare and sync missions from remote
198  * @tc.type: FUNC
199  */
200 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions001, TestSize.Level1)
201 {
202     sptr<IDistributedSched> proxy = GetDms();
203     ASSERT_NE(nullptr, proxy);
204     int32_t callingUid = 0;
205     auto ret = proxy->StartSyncRemoteMissions(DEVICE_ID, false, 0, callingUid);
206     EXPECT_NE(ret, ERR_NONE);
207 }
208 
209 /**
210  * @tc.name: testStartSyncRemoteMissions002
211  * @tc.desc: prepare and sync missions from remote
212  * @tc.type: FUNC
213  */
214 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions002, TestSize.Level1)
215 {
216     sptr<IDistributedSched> proxy = GetDms();
217     ASSERT_NE(nullptr, proxy);
218     int32_t callingUid = 0;
219     auto ret = proxy->StartSyncRemoteMissions("", false, 0, callingUid);
220     EXPECT_NE(ret, ERR_NONE);
221 }
222 
223 /**
224  * @tc.name: testStartSyncRemoteMissions003
225  * @tc.desc: prepare and sync missions from remote
226  * @tc.type: FUNC
227  */
228 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions003, TestSize.Level1)
229 {
230     sptr<IDistributedSched> proxy = GetDms();
231     ASSERT_NE(nullptr, proxy);
232     int32_t callingUid = 0;
233     auto ret = proxy->StartSyncRemoteMissions(localDeviceId_, false, 0, callingUid);
234     EXPECT_NE(ret, ERR_NONE);
235 }
236 
237 /**
238  * @tc.name: testStartSyncRemoteMissions004
239  * @tc.desc: prepare and sync missions from remote
240  * @tc.type: FUNC
241  */
242 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions004, TestSize.Level3)
243 {
244     DTEST_LOG << "testStartSyncRemoteMissions004 begin" << std::endl;
245     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
246     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
247     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, false, 0);
248     EXPECT_EQ(ret, ERR_NONE);
249     DTEST_LOG << "testStartSyncRemoteMissions004 end" << std::endl;
250 }
251 /**
252  * @tc.name: testStartSyncRemoteMissions005
253  * @tc.desc: prepare and sync missions from remote
254  * @tc.type: FUNC
255  */
256 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions005, TestSize.Level3)
257 {
258     DTEST_LOG << "testStartSyncRemoteMissions005 begin" << std::endl;
259     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions("", false, 0);
260     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
261     DTEST_LOG << "testStartSyncRemoteMissions005 end" << std::endl;
262 }
263 
264 /**
265  * @tc.name: testStartSyncRemoteMissions006
266  * @tc.desc: prepare and sync missions from remote
267  * @tc.type: FUNC
268  */
269 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions006, TestSize.Level3)
270 {
271     DTEST_LOG << "testStartSyncRemoteMissions006 begin" << std::endl;
272     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(localDeviceId_, false, 0);
273     EXPECT_NE(ret, ERR_NONE);
274     DTEST_LOG << "testStartSyncRemoteMissions006 end" << std::endl;
275 }
276 
277 /**
278  * @tc.name: testStartSyncRemoteMissions007
279  * @tc.desc: prepare and sync missions from remote
280  * @tc.type: FUNC
281  */
282 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions007, TestSize.Level3)
283 {
284     DTEST_LOG << "testStartSyncRemoteMissions007 begin" << std::endl;
285     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
286     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
287     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, true, 0);
288     EXPECT_EQ(ret, ERR_NONE);
289     DTEST_LOG << "testStartSyncRemoteMissions007 end" << std::endl;
290 }
291 
292 /**
293  * @tc.name: testStartSyncRemoteMissions008
294  * @tc.desc: prepare and sync missions from remote
295  * @tc.type: FUNC
296  */
297 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions008, TestSize.Level3)
298 {
299     DTEST_LOG << "testStartSyncRemoteMissions008 begin" << std::endl;
300     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions("", true, 0);
301     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
302     DTEST_LOG << "testStartSyncRemoteMissions008 end" << std::endl;
303 }
304 
305 /**
306  * @tc.name: testStartSyncRemoteMissions009
307  * @tc.desc: prepare and sync missions from remote
308  * @tc.type: FUNC
309  */
310 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions009, TestSize.Level3)
311 {
312     DTEST_LOG << "testStartSyncRemoteMissions009 begin" << std::endl;
313     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(localDeviceId_, true, 0);
314     EXPECT_NE(ret, ERR_NONE);
315     DTEST_LOG << "testStartSyncRemoteMissions009 end" << std::endl;
316 }
317 
318 /**
319  * @tc.name: testStartSyncRemoteMissions010
320  * @tc.desc: prepare and sync missions from remote
321  * @tc.type: FUNC
322  */
323 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions010, TestSize.Level3)
324 {
325     DTEST_LOG << "testStartSyncRemoteMissions010 begin" << std::endl;
326     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
327     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
328     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, true, 1);
329     EXPECT_EQ(ret, ERR_NONE);
330     DTEST_LOG << "testStartSyncRemoteMissions010 end" << std::endl;
331 }
332 
333 /**
334  * @tc.name: testStartSyncRemoteMissions011
335  * @tc.desc: prepare and sync missions from remote
336  * @tc.type: FUNC
337  */
338 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions011, TestSize.Level3)
339 {
340     DTEST_LOG << "testStartSyncRemoteMissions011 begin" << std::endl;
341     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions("", true, 1);
342     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
343     DTEST_LOG << "testStartSyncRemoteMissions011 end" << std::endl;
344 }
345 
346 /**
347  * @tc.name: testStartSyncRemoteMissions012
348  * @tc.desc: prepare and sync missions from remote
349  * @tc.type: FUNC
350  */
351 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions012, TestSize.Level3)
352 {
353     DTEST_LOG << "testStartSyncRemoteMissions012 begin" << std::endl;
354     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(localDeviceId_, true, 1);
355     EXPECT_NE(ret, ERR_NONE);
356     DTEST_LOG << "testStartSyncRemoteMissions012 end" << std::endl;
357 }
358 
359 /**
360  * @tc.name: testStartSyncRemoteMissions013
361  * @tc.desc: prepare and sync missions from remote
362  * @tc.type: FUNC
363  */
364 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions013, TestSize.Level3)
365 {
366     DTEST_LOG << "testStartSyncRemoteMissions013 begin" << std::endl;
367     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, localDeviceId_);
368     EXPECT_EQ(ret, ERR_NONE);
369     DTEST_LOG << "testStartSyncRemoteMissions013 end" << std::endl;
370 }
371 
372 /**
373  * @tc.name: testStartSyncRemoteMissions014
374  * @tc.desc: prepare and sync missions from remote
375  * @tc.type: FUNC
376  */
377 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions014, TestSize.Level3)
378 {
379     DTEST_LOG << "testStartSyncRemoteMissions014 begin" << std::endl;
380     sptr<IDistributedSched> proxy = GetDms();
381     ASSERT_NE(nullptr, proxy);
382     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, proxy);
383     EXPECT_NE(ret, ERR_NONE);
384     DTEST_LOG << "testStartSyncRemoteMissions014 end" << std::endl;
385 }
386 
387 /**
388  * @tc.name: testNeedSyncDevice001
389  * @tc.desc: need sync device
390  * @tc.type: FUNC
391  */
392 HWTEST_F(DMSMissionManagerTest, testNeedSyncDevice001, TestSize.Level3)
393 {
394     DTEST_LOG << "testCleanMissionResources001 begin" << std::endl;
395     bool ret = DistributedSchedMissionManager::GetInstance().NeedSyncDevice(DEVICE_ID);
396     EXPECT_FALSE(ret);
397     DTEST_LOG << "testNeedSyncDevice001 end" << std::endl;
398 }
399 
400 /**
401  * @tc.name: testNeedSyncDevice002
402  * @tc.desc: need sync device
403  * @tc.type: FUNC
404  */
405 HWTEST_F(DMSMissionManagerTest, testNeedSyncDevice002, TestSize.Level3)
406 {
407     DTEST_LOG << "testNeedSyncDevice002 begin" << std::endl;
408     remoteSyncDeviceSet_.emplace(DEVICE_ID);
409     bool ret = DistributedSchedMissionManager::GetInstance().NeedSyncDevice(DEVICE_ID);
410     EXPECT_FALSE(ret);
411     DTEST_LOG << "testNeedSyncDevice002 end" << std::endl;
412 }
413 
414 /**
415  * @tc.name: testHasSyncListener001
416  * @tc.desc: need sync device
417  * @tc.type: FUNC
418  */
419 HWTEST_F(DMSMissionManagerTest, testHasSyncListener001, TestSize.Level3)
420 {
421     DTEST_LOG << "testHasSyncListener001 begin" << std::endl;
422     DistributedSchedMissionManager::GetInstance().CleanMissionResources(DEVICE_ID);
423     bool ret = DistributedSchedMissionManager::GetInstance().HasSyncListener(DEVICE_ID);
424     EXPECT_FALSE(ret);
425     DTEST_LOG << "testHasSyncListener001 end" << std::endl;
426 }
427 
428 /**
429  * @tc.name: testStopSyncRemoteMissions001
430  * @tc.desc: stop sync missions from remote with fake deviceId
431  * @tc.type: FUNC
432  */
433 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions001, TestSize.Level1)
434 {
435     sptr<IDistributedSched> proxy = GetDms();
436     ASSERT_NE(nullptr, proxy);
437     int32_t callingUid = 0;
438     auto ret = proxy->StopSyncRemoteMissions(DEVICE_ID, callingUid);
439     EXPECT_NE(ret, ERR_NONE);
440 }
441 
442 /**
443  * @tc.name: testStopSyncRemoteMissions002
444  * @tc.desc: stop sync missions from remote with local deviceId
445  * @tc.type: FUNC
446  */
447 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions002, TestSize.Level1)
448 {
449     sptr<IDistributedSched> proxy = GetDms();
450     ASSERT_NE(nullptr, proxy);
451     int32_t callingUid = 0;
452     auto ret = proxy->StopSyncRemoteMissions(localDeviceId_, callingUid);
453     EXPECT_NE(ret, ERR_NONE);
454 }
455 
456 /**
457  * @tc.name: testStopSyncRemoteMissions003
458  * @tc.desc: stop sync missions from remote with empty deviceId
459  * @tc.type: FUNC
460  */
461 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions003, TestSize.Level1)
462 {
463     sptr<IDistributedSched> proxy = GetDms();
464     ASSERT_NE(nullptr, proxy);
465     int32_t callingUid = 0;
466     auto ret = proxy->StopSyncRemoteMissions("", callingUid);
467     EXPECT_NE(ret, ERR_NONE);
468 }
469 
470 /**
471  * @tc.name: testStopSyncRemoteMissions004
472  * @tc.desc: stop sync missions from remote with empty deviceId
473  * @tc.type: FUNC
474  */
475 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions004, TestSize.Level3)
476 {
477     DTEST_LOG << "testStopSyncRemoteMissions004 begin" << std::endl;
478     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions("", false, true);
479     EXPECT_NE(ret, ERR_NONE);
480     DTEST_LOG << "testStopSyncRemoteMissions004 end" << std::endl;
481 }
482 
483 /**
484  * @tc.name: testStopSyncRemoteMissions005
485  * @tc.desc: stop sync missions from remote with local deviceId
486  * @tc.type: FUNC
487  */
488 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions005, TestSize.Level3)
489 {
490     DTEST_LOG << "testStopSyncRemoteMissions005 begin" << std::endl;
491     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(localDeviceId_, false, true);
492     EXPECT_NE(ret, ERR_NONE);
493     DTEST_LOG << "testStopSyncRemoteMissions005 end" << std::endl;
494 }
495 
496 /**
497  * @tc.name: testStopSyncRemoteMissions006
498  * @tc.desc: stop sync missions from remote with deviceId
499  * @tc.type: FUNC
500  */
501 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions006, TestSize.Level3)
502 {
503     DTEST_LOG << "testStopSyncRemoteMissions006 begin" << std::endl;
504     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(DEVICE_ID, false, true);
505     EXPECT_NE(ret, ERR_NONE);
506     DTEST_LOG << "testStopSyncRemoteMissions006 end" << std::endl;
507 }
508 
509 /**
510  * @tc.name: testStopSyncRemoteMissions007
511  * @tc.desc: stop sync missions from remote with empty deviceId
512  * @tc.type: FUNC
513  */
514 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions007, TestSize.Level3)
515 {
516     DTEST_LOG << "testStopSyncRemoteMissions007 begin" << std::endl;
517     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions("", true, true);
518     EXPECT_EQ(ret, ERR_NONE);
519     DTEST_LOG << "testStopSyncRemoteMissions007 end" << std::endl;
520 }
521 
522 /**
523  * @tc.name: testStopSyncRemoteMissions008
524  * @tc.desc: stop sync missions from remote with local deviceId
525  * @tc.type: FUNC
526  */
527 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions008, TestSize.Level3)
528 {
529     DTEST_LOG << "testStopSyncRemoteMissions008 begin" << std::endl;
530     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(localDeviceId_, true, true);
531     EXPECT_EQ(ret, ERR_NONE);
532     DTEST_LOG << "testStopSyncRemoteMissions008 end" << std::endl;
533 }
534 
535 /**
536  * @tc.name: testStopSyncRemoteMissions009
537  * @tc.desc: stop sync missions from remote with deviceId
538  * @tc.type: FUNC
539  */
540 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions009, TestSize.Level3)
541 {
542     DTEST_LOG << "testStopSyncRemoteMissions009 begin" << std::endl;
543     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(DEVICE_ID, true, true);
544     EXPECT_EQ(ret, ERR_NONE);
545     DTEST_LOG << "testStopSyncRemoteMissions009 end" << std::endl;
546 }
547 
548 /**
549  * @tc.name: testStopSyncRemoteMissions010
550  * @tc.desc: stop sync missions from remote with empty deviceId
551  * @tc.type: FUNC
552  */
553 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions010, TestSize.Level3)
554 {
555     DTEST_LOG << "testStopSyncRemoteMissions010 begin" << std::endl;
556     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions("", true, false);
557     EXPECT_EQ(ret, ERR_NONE);
558     DTEST_LOG << "testStopSyncRemoteMissions010 end" << std::endl;
559 }
560 
561 /**
562  * @tc.name: testStopSyncRemoteMissions011
563  * @tc.desc: stop sync missions from remote with local deviceId
564  * @tc.type: FUNC
565  */
566 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions011, TestSize.Level3)
567 {
568     DTEST_LOG << "testStopSyncRemoteMissions011 begin" << std::endl;
569     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(localDeviceId_, true, false);
570     EXPECT_EQ(ret, ERR_NONE);
571     DTEST_LOG << "testStopSyncRemoteMissions011 end" << std::endl;
572 }
573 
574 /**
575  * @tc.name: testStopSyncRemoteMissions012
576  * @tc.desc: stop sync missions from remote with deviceId
577  * @tc.type: FUNC
578  */
579 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions012, TestSize.Level3)
580 {
581     DTEST_LOG << "testStopSyncRemoteMissions012 begin" << std::endl;
582     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(DEVICE_ID, true, false);
583     EXPECT_EQ(ret, ERR_NONE);
584     DTEST_LOG << "testStopSyncRemoteMissions012 end" << std::endl;
585 }
586 
587 /**
588  * @tc.name: testRegisterMissionListener001
589  * @tc.desc: register mission listener
590  * @tc.type: FUNC
591  */
592 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener001, TestSize.Level1)
593 {
594     sptr<IDistributedSched> proxy = GetDms();
595     ASSERT_NE(nullptr, proxy);
596     int32_t callingUid = 0;
597     auto ret = proxy->RegisterMissionListener(U16DEVICE_ID, nullptr, callingUid);
598     EXPECT_TRUE(ret != ERR_NONE);
599 
600     ret = proxy->RegisterMissionListener(u16localDeviceId_, nullptr, callingUid);
601     EXPECT_TRUE(ret != ERR_NONE);
602 
603     ret = proxy->RegisterMissionListener(u"", nullptr, callingUid);
604     EXPECT_TRUE(ret != ERR_NONE);
605 }
606 
607 /**
608  * @tc.name: testRegisterMissionListener002
609  * @tc.desc: register mission listener
610  * @tc.type: FUNC
611  */
612 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener002, TestSize.Level1)
613 {
614     sptr<IDistributedSched> proxy = GetDms();
615     ASSERT_NE(nullptr, proxy);
616     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
617     int32_t callingUid = 0;
618     auto ret = proxy->RegisterMissionListener(U16DEVICE_ID, listener, callingUid);
619     EXPECT_TRUE(ret != ERR_NONE);
620 
621     ret = proxy->RegisterMissionListener(u16localDeviceId_, listener, callingUid);
622     EXPECT_TRUE(ret != ERR_NONE);
623 
624     ret = proxy->RegisterMissionListener(u"", listener, callingUid);
625     EXPECT_TRUE(ret != ERR_NONE);
626 
627     ret = proxy->UnRegisterMissionListener(U16DEVICE_ID, listener);
628     EXPECT_TRUE(ret != ERR_NONE);
629 
630     ret = proxy->UnRegisterMissionListener(u16localDeviceId_, listener);
631     EXPECT_TRUE(ret != ERR_NONE);
632 
633     ret = proxy->UnRegisterMissionListener(u"", listener);
634     EXPECT_TRUE(ret != ERR_NONE);
635 }
636 
637 /**
638  * @tc.name: testRegisterMissionListener003
639  * @tc.desc: test register mission listener
640  * @tc.type: FUNC
641  */
642 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener003, TestSize.Level3)
643 {
644     DTEST_LOG << "testRegisterMissionListener003 begin" << std::endl;
645     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
646     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(u"", listener);
647     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
648     DTEST_LOG << "testRegisterMissionListener003 end" << std::endl;
649 }
650 
651 /**
652  * @tc.name: testRegisterMissionListener004
653  * @tc.desc: test register mission listener
654  * @tc.type: FUNC
655  */
656 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener004, TestSize.Level3)
657 {
658     DTEST_LOG << "testRegisterMissionListener004 begin" << std::endl;
659     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
660     DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_["1234567"] = DEVICE_ID;
661     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(U16DEVICE_ID, listener);
662     EXPECT_EQ(ret, ERR_NONE);
663     DTEST_LOG << "testRegisterMissionListener004 end" << std::endl;
664 }
665 
666 /**
667  * @tc.name: testRegisterMissionListener005
668  * @tc.desc: test register mission listener
669  * @tc.type: FUNC
670  */
671 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener005, TestSize.Level3)
672 {
673     DTEST_LOG << "testRegisterMissionListener005 begin" << std::endl;
674     sptr<IRemoteObject> listener = nullptr;
675     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(u"", listener);
676     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
677     DTEST_LOG << "testRegisterMissionListener005 end" << std::endl;
678 }
679 
680 /**
681  * @tc.name: testRegisterMissionListener006
682  * @tc.desc: test register mission listener
683  * @tc.type: FUNC
684  */
685 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener006, TestSize.Level3)
686 {
687     DTEST_LOG << "testRegisterMissionListener006 begin" << std::endl;
688     sptr<IRemoteObject> listener = nullptr;
689     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(U16DEVICE_ID, listener);
690     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
691     DTEST_LOG << "testRegisterMissionListener006 end" << std::endl;
692 }
693 
694 /**
695  * @tc.name: testRegisterMissionListener007
696  * @tc.desc: test register mission listener
697  * @tc.type: FUNC
698  */
699 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener007, TestSize.Level3)
700 {
701     DTEST_LOG << "testRegisterMissionListener007 begin" << std::endl;
702     u16string deviceId = Str8ToStr16(localDeviceId_);
703     sptr<IRemoteObject> listener = nullptr;
704     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(deviceId, listener);
705     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
706     DTEST_LOG << "testRegisterMissionListener007 end" << std::endl;
707 }
708 
709 /**
710  * @tc.name: testRegisterMissionListener008
711  * @tc.desc: test register mission listener
712  * @tc.type: FUNC
713  */
714 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener008, TestSize.Level3)
715 {
716     DTEST_LOG << "testRegisterMissionListener008 begin" << std::endl;
717     u16string deviceId = Str8ToStr16(localDeviceId_);
718     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
719     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(deviceId, listener);
720     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
721     DTEST_LOG << "testRegisterMissionListener008 end" << std::endl;
722 }
723 
724 /**
725  * @tc.name: testUnRegisterMissionListener001
726  * @tc.desc: register mission listener
727  * @tc.type: FUNC
728  */
729 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener001, TestSize.Level1)
730 {
731     sptr<IDistributedSched> proxy = GetDms();
732     ASSERT_NE(nullptr, proxy);
733     auto ret = proxy->UnRegisterMissionListener(U16DEVICE_ID, nullptr);
734     EXPECT_TRUE(ret != ERR_NONE);
735 
736     ret = proxy->UnRegisterMissionListener(u16localDeviceId_, nullptr);
737     EXPECT_TRUE(ret != ERR_NONE);
738 
739     ret = proxy->UnRegisterMissionListener(u"", nullptr);
740     EXPECT_TRUE(ret != ERR_NONE);
741 }
742 
743 /**
744  * @tc.name: testUnRegisterMissionListener002
745  * @tc.desc: register mission listener
746  * @tc.type: FUNC
747  */
748 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener002, TestSize.Level3)
749 {
750     DTEST_LOG << "testUnRegisterMissionListener002 begin" << std::endl;
751     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
752     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(U16DEVICE_ID, listener);
753     EXPECT_EQ(ret, ERR_NONE);
754     DTEST_LOG << "testUnRegisterMissionListener002 end" << std::endl;
755 }
756 
757 /**
758  * @tc.name: testUnRegisterMissionListener003
759  * @tc.desc: register mission listener
760  * @tc.type: FUNC
761  */
762 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener003, TestSize.Level3)
763 {
764     DTEST_LOG << "testUnRegisterMissionListener003 begin" << std::endl;
765     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(U16DEVICE_ID, nullptr);
766     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
767     DTEST_LOG << "testUnRegisterMissionListener003 end" << std::endl;
768 }
769 
770 /**
771  * @tc.name: testUnRegisterMissionListener004
772  * @tc.desc: register mission listener
773  * @tc.type: FUNC
774  */
775 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener004, TestSize.Level3)
776 {
777     DTEST_LOG << "testUnRegisterMissionListener004 begin" << std::endl;
778     u16string deviceId = Str8ToStr16(localDeviceId_);
779     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, nullptr);
780     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
781     DTEST_LOG << "testUnRegisterMissionListener004 end" << std::endl;
782 }
783 
784 /**
785  * @tc.name: testUnRegisterMissionListener005
786  * @tc.desc: register mission listener
787  * @tc.type: FUNC
788  */
789 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener005, TestSize.Level3)
790 {
791     DTEST_LOG << "testUnRegisterMissionListener005 begin" << std::endl;
792     u16string deviceId = Str8ToStr16(localDeviceId_);
793     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
794     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, listener);
795     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
796     DTEST_LOG << "testUnRegisterMissionListener005 end" << std::endl;
797 }
798 
799 /**
800  * @tc.name: testIsDeviceIdValidated001
801  * @tc.desc: judging whether the deviceId is valid
802  * @tc.type: FUNC
803  */
804 HWTEST_F(DMSMissionManagerTest, testIsDeviceIdValidated001, TestSize.Level1)
805 {
806     std::string emptyDeviceId = "";
807     auto ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(emptyDeviceId);
808     EXPECT_FALSE(ret);
809 
810     ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(DEVICE_ID_FALSE);
811     EXPECT_FALSE(ret);
812 
813     ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(DEVICE_ID_FALSE_AGAIN);
814     EXPECT_FALSE(ret);
815 }
816 
817 /**
818  * @tc.name: testGetMissionInfos001
819  * @tc.desc: get missions
820  * @tc.type: FUNC
821  */
822 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos001, TestSize.Level1)
823 {
824     std::string deviceid = DEVICE_ID;
825     int32_t numMissions = NUM_MISSIONS;
826     std::vector<AAFwk::MissionInfo> missionInfos;
827 
828     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
829     EXPECT_TRUE(ret != ERR_NONE);
830 }
831 
832 /**
833  * @tc.name: testGetMissionInfos002
834  * @tc.desc: get missions
835  * @tc.type: FUNC
836  */
837 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos002, TestSize.Level3)
838 {
839     DTEST_LOG << "testGetMissionInfos002 begin" << std::endl;
840     std::string deviceid = localDeviceId_;
841     int32_t numMissions = NUM_MISSIONS;
842     std::vector<AAFwk::MissionInfo> missionInfos;
843 
844     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
845     EXPECT_TRUE(ret != ERR_NONE);
846     DTEST_LOG << "testGetMissionInfos002 end" << std::endl;
847 }
848 
849 /**
850  * @tc.name: testGetMissionInfos003
851  * @tc.desc: get missions
852  * @tc.type: FUNC
853  */
854 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos003, TestSize.Level3)
855 {
856     DTEST_LOG << "testGetMissionInfos003 begin" << std::endl;
857     std::string deviceid = "";
858     int32_t numMissions = NUM_MISSIONS;
859     std::vector<AAFwk::MissionInfo> missionInfos;
860 
861     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
862     EXPECT_TRUE(ret != ERR_NONE);
863     DTEST_LOG << "testGetMissionInfos003 end" << std::endl;
864 }
865 
866 /**
867  * @tc.name: testGetMissionInfos004
868  * @tc.desc: get missions
869  * @tc.type: FUNC
870  */
871 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos004, TestSize.Level3)
872 {
873     DTEST_LOG << "testGetMissionInfos004 begin" << std::endl;
874     std::string deviceid = DEVICE_ID;
875     int32_t numMissions = -1;
876     std::vector<AAFwk::MissionInfo> missionInfos;
877     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
878     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
879     DTEST_LOG << "testGetMissionInfos004 end" << std::endl;
880 }
881 
882 /**
883  * @tc.name: testGetMissionInfos005
884  * @tc.desc: get missions
885  * @tc.type: FUNC
886  */
887 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos005, TestSize.Level3)
888 {
889     DTEST_LOG << "testGetMissionInfos005 begin" << std::endl;
890     std::string deviceid = "";
891     int32_t numMissions = NUM_MISSIONS;
892     std::vector<AAFwk::MissionInfo> missionInfos;
893     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
894     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
895     DTEST_LOG << "testGetMissionInfos005 end" << std::endl;
896 }
897 
898 /**
899  * @tc.name: testGetMissionInfos006
900  * @tc.desc: get missions
901  * @tc.type: FUNC
902  */
903 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos006, TestSize.Level3)
904 {
905     DTEST_LOG << "testGetMissionInfos006 begin" << std::endl;
906     std::string deviceid = "";
907     int32_t numMissions = 0;
908     std::vector<AAFwk::MissionInfo> missionInfos;
909     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
910     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
911     DTEST_LOG << "testGetMissionInfos006 end" << std::endl;
912 }
913 
914 /**
915  * @tc.name: testFetchCachedRemoteMissions001
916  * @tc.desc: test stop fake device, return error code
917  * @tc.type: FUNC
918  */
919 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions001, TestSize.Level1)
920 {
921     std::vector<DstbMissionInfo> infos;
922     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(DEVICE_ID, 0, infos);
923     EXPECT_TRUE(ret != ERR_NONE);
924 }
925 
926 /**
927  * @tc.name: testFetchCachedRemoteMissions002
928  * @tc.desc: test empty deviceId, return error code
929  * @tc.type: FUNC
930  */
931 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions002, TestSize.Level3)
932 {
933     DTEST_LOG << "testFetchCachedRemoteMissions002 begin" << std::endl;
934     std::vector<DstbMissionInfo> infos;
935     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions("", 0, infos);
936     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
937     DTEST_LOG << "testFetchCachedRemoteMissions002 end" << std::endl;
938 }
939 
940 /**
941  * @tc.name: testFetchCachedRemoteMissions003
942  * @tc.desc: test local deviceId, return error code
943  * @tc.type: FUNC
944  */
945 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions003, TestSize.Level3)
946 {
947     DTEST_LOG << "testFetchCachedRemoteMissions003 begin" << std::endl;
948     std::vector<DstbMissionInfo> infos;
949     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(localDeviceId_, 0, infos);
950     EXPECT_TRUE(ret == ERR_NULL_OBJECT);
951     DTEST_LOG << "testFetchCachedRemoteMissions003 end" << std::endl;
952 }
953 
954 /**
955  * @tc.name: testFetchCachedRemoteMissions004
956  * @tc.desc: test stop fake device, return error code
957  * @tc.type: FUNC
958  */
959 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions004, TestSize.Level3)
960 {
961     DTEST_LOG << "testFetchCachedRemoteMissions004 begin" << std::endl;
962     std::vector<DstbMissionInfo> infos;
963     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(DEVICE_ID, NUM_MISSIONS, infos);
964     EXPECT_TRUE(ret != ERR_NONE);
965     DTEST_LOG << "testFetchCachedRemoteMissions004 end" << std::endl;
966 }
967 
968 /**
969  * @tc.name: testFetchCachedRemoteMissions005
970  * @tc.desc: test empty deviceId, return error code
971  * @tc.type: FUNC
972  */
973 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions005, TestSize.Level3)
974 {
975     DTEST_LOG << "testFetchCachedRemoteMissions005 begin" << std::endl;
976     std::vector<DstbMissionInfo> infos;
977     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions("", NUM_MISSIONS, infos);
978     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
979     DTEST_LOG << "testFetchCachedRemoteMissions005 end" << std::endl;
980 }
981 
982 /**
983  * @tc.name: testFetchCachedRemoteMissions006
984  * @tc.desc: test local deviceId, return error code
985  * @tc.type: FUNC
986  */
987 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions006, TestSize.Level3)
988 {
989     DTEST_LOG << "testFetchCachedRemoteMissions006 begin" << std::endl;
990     std::vector<DstbMissionInfo> infos;
991     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(localDeviceId_,
992         NUM_MISSIONS, infos);
993     EXPECT_TRUE(ret == ERR_NULL_OBJECT);
994     DTEST_LOG << "testFetchCachedRemoteMissions006 end" << std::endl;
995 }
996 
997 /**
998  * @tc.name: testFetchCachedRemoteMissions007
999  * @tc.desc: test stop fake device, return error code
1000  * @tc.type: FUNC
1001  */
1002 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions007, TestSize.Level3)
1003 {
1004     DTEST_LOG << "testFetchCachedRemoteMissions007 begin" << std::endl;
1005     std::vector<DstbMissionInfo> infos;
1006     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(DEVICE_ID,
1007         NORMAL_NUM_MISSIONS, infos);
1008     EXPECT_TRUE(ret != ERR_NONE);
1009     DTEST_LOG << "testFetchCachedRemoteMissions007 end" << std::endl;
1010 }
1011 
1012 /**
1013  * @tc.name: testFetchCachedRemoteMissions008
1014  * @tc.desc: test empty deviceId, return error code
1015  * @tc.type: FUNC
1016  */
1017 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions008, TestSize.Level3)
1018 {
1019     DTEST_LOG << "testFetchCachedRemoteMissions008 begin" << std::endl;
1020     std::vector<DstbMissionInfo> infos;
1021     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions("", NORMAL_NUM_MISSIONS, infos);
1022     EXPECT_TRUE(ret == INVALID_PARAMETERS_ERR);
1023     DTEST_LOG << "testFetchCachedRemoteMissions008 end" << std::endl;
1024 }
1025 
1026 /**
1027  * @tc.name: testFetchCachedRemoteMissions009
1028  * @tc.desc: test local deviceId, return error code
1029  * @tc.type: FUNC
1030  */
1031 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions009, TestSize.Level3)
1032 {
1033     DTEST_LOG << "testFetchCachedRemoteMissions009 begin" << std::endl;
1034     std::vector<DstbMissionInfo> infos;
1035     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(localDeviceId_,
1036         NORMAL_NUM_MISSIONS, infos);
1037     EXPECT_TRUE(ret == ERR_NULL_OBJECT);
1038     DTEST_LOG << "testFetchCachedRemoteMissions009 end" << std::endl;
1039 }
1040 
1041 /**
1042  * @tc.name: testStopDataStorage001
1043  * @tc.desc: test stop data storage
1044  * @tc.type: FUNC
1045  */
1046 HWTEST_F(DMSMissionManagerTest, testStopDataStorage001, TestSize.Level3)
1047 {
1048     DTEST_LOG << "testStopDataStorage001 begin" << std::endl;
1049     auto ret = DistributedSchedMissionManager::GetInstance().StopDataStorage();
1050     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1051     DTEST_LOG << "testStopDataStorage001 end" << std::endl;
1052 }
1053 
1054 /**
1055  * @tc.name: testStoreSnapshotInfo001
1056  * @tc.desc: test store snapshot info
1057  * @tc.type: FUNC
1058  */
1059 HWTEST_F(DMSMissionManagerTest, testStoreSnapshotInfo001, TestSize.Level3)
1060 {
1061     DTEST_LOG << "testStoreSnapshotInfo001 begin" << std::endl;
1062     auto ret = DistributedSchedMissionManager::GetInstance().StoreSnapshotInfo(DEVICE_ID, 0, 0, 0);
1063     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1064     DTEST_LOG << "testStoreSnapshotInfo001 end" << std::endl;
1065 }
1066 
1067 /**
1068  * @tc.name: testRemoveSnapshotInfo001
1069  * @tc.desc: test remove snapshot info
1070  * @tc.type: FUNC
1071  */
1072 HWTEST_F(DMSMissionManagerTest, testRemoveSnapshotInfo001, TestSize.Level3)
1073 {
1074     DTEST_LOG << "testRemoveSnapshotInfo001 begin" << std::endl;
1075     auto ret = DistributedSchedMissionManager::GetInstance().RemoveSnapshotInfo(DEVICE_ID, 0);
1076     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1077     DTEST_LOG << "testRemoveSnapshotInfo001 end" << std::endl;
1078 }
1079 
1080 /**
1081  * @tc.name: testInitDataStorage001
1082  * @tc.desc: test init data storage
1083  * @tc.type: FUNC
1084  */
1085 HWTEST_F(DMSMissionManagerTest, testInitDataStorage001, TestSize.Level3)
1086 {
1087     DTEST_LOG << "testInitDataStorage001 begin" << std::endl;
1088     auto ret = DistributedSchedMissionManager::GetInstance().InitDataStorage();
1089     EXPECT_EQ(ret, ERR_NONE);
1090     DTEST_LOG << "testInitDataStorage001 end" << std::endl;
1091 }
1092 
1093 /**
1094  * @tc.name: testInitDataStorage002
1095  * @tc.desc: test init data storage
1096  * @tc.type: FUNC
1097  */
1098 HWTEST_F(DMSMissionManagerTest, testInitDataStorage002, TestSize.Level3)
1099 {
1100     DTEST_LOG << "testInitDataStorage002 begin" << std::endl;
1101     auto ret = DistributedSchedMissionManager::GetInstance().InitDataStorage();
1102     EXPECT_EQ(ret, ERR_NONE);
1103     DTEST_LOG << "testInitDataStorage002 end" << std::endl;
1104 }
1105 
1106 /**
1107  * @tc.name: testStoreSnapshotInfo002
1108  * @tc.desc: test store snapshot info
1109  * @tc.type: FUNC
1110  */
1111 HWTEST_F(DMSMissionManagerTest, testStoreSnapshotInfo002, TestSize.Level3)
1112 {
1113     DTEST_LOG << "testStoreSnapshotInfo002 begin" << std::endl;
1114     auto ret = DistributedSchedMissionManager::GetInstance().StoreSnapshotInfo(DEVICE_ID_FALSE, 0, 0, 0);
1115     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1116     DTEST_LOG << "testStoreSnapshotInfo002 end" << std::endl;
1117 }
1118 
1119 /**
1120  * @tc.name: testRemoveSnapshotInfo002
1121  * @tc.desc: test remove snapshot info
1122  * @tc.type: FUNC
1123  */
1124 HWTEST_F(DMSMissionManagerTest, testRemoveSnapshotInfo002, TestSize.Level3)
1125 {
1126     DTEST_LOG << "testRemoveSnapshotInfo002 begin" << std::endl;
1127     auto ret = DistributedSchedMissionManager::GetInstance().RemoveSnapshotInfo(DEVICE_ID_FALSE, 0);
1128     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1129     DTEST_LOG << "testRemoveSnapshotInfo002 end" << std::endl;
1130 }
1131 
1132 /**
1133  * @tc.name: testGetRemoteMissionSnapshotInfo001
1134  * @tc.desc: test get remote mission snapshot info
1135  * @tc.type: FUNC
1136  */
1137 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionSnapshotInfo001, TestSize.Level3)
1138 {
1139     DTEST_LOG << "testGetRemoteMissionSnapshotInfo001 begin" << std::endl;
1140     DistributedSchedMissionManager::GetInstance().NotifySnapshotChanged(DEVICE_ID, 0);
1141     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1142     auto ret = DistributedSchedMissionManager::GetInstance().GetRemoteMissionSnapshotInfo("", 0, missionSnapshot);
1143     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1144     DTEST_LOG << "testGetRemoteMissionSnapshotInfo001 end" << std::endl;
1145 }
1146 
1147 /**
1148  * @tc.name: testDeviceOnlineNotify003
1149  * @tc.desc: test device online notify
1150  * @tc.type: FUNC
1151  */
1152 HWTEST_F(DMSMissionManagerTest, testDeviceOnlineNotify003, TestSize.Level3)
1153 {
1154     DTEST_LOG << "testDeviceOnlineNotify003 begin" << std::endl;
1155     DistributedSchedMissionManager::GetInstance().Init();
1156     DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify("");
1157     DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(DEVICE_ID);
1158     EXPECT_NE(DistributedSchedMissionManager::GetInstance().missionHandler_, nullptr);
1159     DTEST_LOG << "testDeviceOnlineNotify003 end" << std::endl;
1160 }
1161 
1162 /**
1163  * @tc.name: testOnRemoteDied001
1164  * @tc.desc: test on remote died
1165  * @tc.type: FUNC
1166  */
1167 HWTEST_F(DMSMissionManagerTest, testOnRemoteDied001, TestSize.Level3)
1168 {
1169     DTEST_LOG << "testOnRemoteDied001 begin" << std::endl;
1170     //DeviceOfflineNotify
1171     DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify("");
1172     std::set<std::string> remoteSyncDeviceSet_ = set<std::string>();
1173     DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify(DEVICE_ID);
1174 
1175     //OnRemoteDied
1176     wptr<IRemoteObject> remote = nullptr;
1177     DistributedSchedMissionManager::GetInstance().OnRemoteDied(remote);
1178     remote = new RemoteMissionListenerTest();
1179     DistributedSchedMissionManager::GetInstance().OnRemoteDied(remote);
1180     EXPECT_NE(remote.promote(), nullptr);
1181     DTEST_LOG << "testOnRemoteDied001 end" << std::endl;
1182 }
1183 
1184 /**
1185  * @tc.name: testStartSyncMissionsFromRemote001
1186  * @tc.desc: prepare and sync missions from remote
1187  * @tc.type: FUNC
1188  */
1189 HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote001, TestSize.Level3)
1190 {
1191     DTEST_LOG << "testStartSyncMissionsFromRemote001 begin" << std::endl;
1192     DistributedSchedUtil::MockManageMissions();
1193     std::vector<DstbMissionInfo> missionInfos;
1194     CallerInfo callerInfo;
1195     DistributedSchedMissionManager::GetInstance().Init();
1196     DistributedSchedMissionManager::GetInstance().GenerateCallerInfo(callerInfo);
1197     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncMissionsFromRemote(callerInfo, missionInfos);
1198     EXPECT_EQ(ret, ERR_NONE);
1199     DTEST_LOG << "testStartSyncMissionsFromRemote001 end" << std::endl;
1200 }
1201 
1202 /**
1203  * @tc.name: testStopSyncMissionsFromRemote001
1204  * @tc.desc: stop sync missions from remote
1205  * @tc.type: FUNC
1206  */
1207 HWTEST_F(DMSMissionManagerTest, testStopSyncMissionsFromRemote001, TestSize.Level3)
1208 {
1209     DTEST_LOG << "testStopSyncMissionsFromRemote001 begin" << std::endl;
1210     DistributedSchedMissionManager::GetInstance().Init();
1211     DistributedSchedMissionManager::GetInstance().StopSyncMissionsFromRemote("");
1212     DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.clear();
1213     DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.insert(DEVICE_ID);
1214     DistributedSchedMissionManager::GetInstance().StopSyncMissionsFromRemote(DEVICE_ID);
1215     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.empty(), true);
1216     DTEST_LOG << "testStopSyncMissionsFromRemote001 end" << std::endl;
1217 }
1218 
1219 /**
1220  * @tc.name: testNotifyMissionsChangedFromRemote001
1221  * @tc.desc: notify missions changed from remote
1222  * @tc.type: FUNC
1223  */
1224 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedFromRemote001, TestSize.Level3)
1225 {
1226     DTEST_LOG << "testNotifyMissionsChangedFromRemote001 begin" << std::endl;
1227     CallerInfo callerInfo;
1228     callerInfo.sourceDeviceId = DEVICE_ID;
1229     callerInfo.uid = 0;
1230     callerInfo.pid = 0;
1231     callerInfo.dmsVersion = 0;
1232     std::vector<DstbMissionInfo> missionInfos;
1233     DistributedSchedMissionManager::GetInstance().Init();
1234     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedFromRemote(callerInfo, missionInfos);
1235     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1236     DTEST_LOG << "testNotifyMissionsChangedFromRemote001 end" << std::endl;
1237 }
1238 
1239 /**
1240  * @tc.name: testNotifyMissionsChangedFromRemote002
1241  * @tc.desc: notify missions changed from remote
1242  * @tc.type: FUNC
1243  */
1244 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedFromRemote002, TestSize.Level3)
1245 {
1246     DTEST_LOG << "testNotifyMissionsChangedFromRemote002 begin" << std::endl;
1247     CallerInfo callerInfo;
1248     callerInfo.sourceDeviceId = DEVICE_ID;
1249     callerInfo.uid = 0;
1250     callerInfo.pid = 0;
1251     callerInfo.dmsVersion = 0;
1252     std::vector<DstbMissionInfo> missionInfos;
1253     DistributedSchedMissionManager::GetInstance().Init();
1254     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
1255     auto& listenerInfo = DistributedSchedMissionManager::GetInstance().listenDeviceMap_[U16DEVICE_ID];
1256     EXPECT_EQ(listenerInfo.Emplace(listener), true);
1257     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedFromRemote(callerInfo, missionInfos);
1258     EXPECT_EQ(ret, ERR_NONE);
1259     DTEST_LOG << "testNotifyMissionsChangedFromRemote002 end" << std::endl;
1260 }
1261 
1262 /**
1263  * @tc.name: testNotifyLocalMissionsChanged001
1264  * @tc.desc: notify local missions changed
1265  * @tc.type: FUNC
1266  */
1267 HWTEST_F(DMSMissionManagerTest, testNotifyLocalMissionsChanged001, TestSize.Level3)
1268 {
1269     DTEST_LOG << "testNotifyLocalMissionsChanged001 begin" << std::endl;
1270     DistributedSchedMissionManager::GetInstance().Init();
1271     DistributedSchedMissionManager::GetInstance().NotifyLocalMissionsChanged();
1272     EXPECT_NE(DistributedSchedMissionManager::GetInstance().missionChangeHandler_, nullptr);
1273     DTEST_LOG << "testNotifyLocalMissionsChanged001 end" << std::endl;
1274 }
1275 
1276 /**
1277  * @tc.name: testNotifyMissionSnapshotCreated001
1278  * @tc.desc: notify mission snapshot created
1279  * @tc.type: FUNC
1280  */
1281 HWTEST_F(DMSMissionManagerTest, testNotifyMissionSnapshotCreated001, TestSize.Level3)
1282 {
1283     DTEST_LOG << "testNotifyMissionSnapshotCreated001 begin" << std::endl;
1284     DistributedSchedMissionManager::GetInstance().missionChangeHandler_ = nullptr;
1285     DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotCreated(1);
1286     DistributedSchedMissionManager::GetInstance().Init();
1287     DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotCreated(1);
1288     EXPECT_NE(DistributedSchedMissionManager::GetInstance().missionChangeHandler_, nullptr);
1289     DTEST_LOG << "testNotifyMissionSnapshotCreated001 end" << std::endl;
1290 }
1291 
1292 /**
1293  * @tc.name: testNotifyMissionSnapshotChanged001
1294  * @tc.desc: notify mission snapshot changed
1295  * @tc.type: FUNC
1296  */
1297 HWTEST_F(DMSMissionManagerTest, testNotifyMissionSnapshotChanged001, TestSize.Level3)
1298 {
1299     DTEST_LOG << "testNotifyMissionSnapshotChanged001 begin" << std::endl;
1300     DistributedSchedMissionManager::GetInstance().Init();
1301     DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotChanged(1);
1302     EXPECT_NE(DistributedSchedMissionManager::GetInstance().missionChangeHandler_, nullptr);
1303     DTEST_LOG << "testNotifyMissionSnapshotChanged001 end" << std::endl;
1304 }
1305 
1306 /**
1307  * @tc.name: testNotifyMissionSnapshotDestroyed001
1308  * @tc.desc: notify mission snapshot destroyed
1309  * @tc.type: FUNC
1310  */
1311 HWTEST_F(DMSMissionManagerTest, testNotifyMissionSnapshotDestroyed001, TestSize.Level3)
1312 {
1313     DTEST_LOG << "testNotifyMissionSnapshotDestroyed001 begin" << std::endl;
1314     DistributedSchedMissionManager::GetInstance().Init();
1315     DistributedSchedMissionManager::GetInstance().NotifyMissionSnapshotDestroyed(1);
1316     EXPECT_NE(DistributedSchedMissionManager::GetInstance().missionChangeHandler_, nullptr);
1317     DTEST_LOG << "testNotifyMissionSnapshotDestroyed001 end" << std::endl;
1318 }
1319 
1320 /**
1321  * @tc.name: testNotifyMissionsChangedToRemote001
1322  * @tc.desc: notify missions changed to remote
1323  * @tc.type: FUNC
1324  */
1325 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedToRemote001, TestSize.Level3)
1326 {
1327     DTEST_LOG << "testNotifyMissionsChangedToRemote001 begin" << std::endl;
1328     std::vector<DstbMissionInfo> missionInfos;
1329     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemote(missionInfos);
1330     EXPECT_EQ(ret, ERR_NONE);
1331     DTEST_LOG << "testNotifyMissionsChangedToRemote001 end" << std::endl;
1332 }
1333 
1334 /**
1335  * @tc.name: testOnRemoteDmsDied001
1336  * @tc.desc: on remote dms died
1337  * @tc.type: FUNC
1338  */
1339 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied001, TestSize.Level3)
1340 {
1341     DTEST_LOG << "testOnRemoteDmsDied001 begin" << std::endl;
1342     //NotifyMissionsChangedToRemoteInner
1343     CallerInfo callerInfo;
1344     std::vector<DstbMissionInfo> missionInfos;
1345     DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemoteInner("", missionInfos, callerInfo);
1346     DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemoteInner(
1347         DEVICE_ID, missionInfos, callerInfo);
1348 
1349     wptr<IRemoteObject> remote = nullptr;
1350     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
1351     remote = wptr<IRemoteObject>();
1352     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
1353 
1354     DistributedSchedMissionManager::GetInstance().missionHandler_ = nullptr;
1355     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
1356     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().missionHandler_, nullptr);
1357     DTEST_LOG << "testOnRemoteDmsDied001 end" << std::endl;
1358 }
1359 
1360 /**
1361  * @tc.name: testRetryRegisterMissionChange001
1362  * @tc.desc: retry register mission change
1363  * @tc.type: FUNC
1364  */
1365 HWTEST_F(DMSMissionManagerTest, testRetryRegisterMissionChange001, TestSize.Level3)
1366 {
1367     DTEST_LOG << "testRetryRegisterMissionChange001 begin" << std::endl;
1368     //RetryStartSyncRemoteMissions
1369     DistributedSchedMissionManager::GetInstance().Init();
1370     DistributedSchedMissionManager::GetInstance().RetryStartSyncRemoteMissions("", localDeviceId_, 1);
1371     DistributedSchedMissionManager::GetInstance().RetryStartSyncRemoteMissions(DEVICE_ID, localDeviceId_, 1);
1372 
1373     //OnMissionListenerDied
1374     sptr<IRemoteObject> remote = nullptr;
1375     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(remote);
1376 
1377     remote = sptr<IRemoteObject>();
1378     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(remote);
1379 
1380     //RetryRegisterMissionChange
1381     DistributedSchedMissionManager::GetInstance().RetryRegisterMissionChange(1);
1382     EXPECT_NE(DistributedSchedMissionManager::GetInstance().missionHandler_, nullptr);
1383     DTEST_LOG << "testRetryRegisterMissionChange001 end" << std::endl;
1384 }
1385 
1386 /**
1387  * @tc.name: testMissionSnapshotChanged001
1388  * @tc.desc: mission snapshot changed
1389  * @tc.type: FUNC
1390  */
1391 HWTEST_F(DMSMissionManagerTest, testMissionSnapshotChanged001, TestSize.Level3)
1392 {
1393     DTEST_LOG << "testMissionSnapshotChanged001 begin" << std::endl;
1394     DistributedSchedMissionManager::GetInstance().NotifyDmsProxyProcessDied();
1395     std::vector<DstbMissionInfo> missionInfos;
1396     DistributedSchedMissionManager::GetInstance().InitAllSnapshots(missionInfos);
1397     auto ret = DistributedSchedMissionManager::GetInstance().MissionSnapshotChanged(NUM_MISSIONS);
1398     EXPECT_NE(ret, ERR_NONE);
1399     DTEST_LOG << "testMissionSnapshotChanged001 end" << std::endl;
1400 }
1401 
1402 /**
1403  * @tc.name: ProxyCallStopSyncMissionsFromRemote001
1404  * @tc.desc: call dms proxy StopSyncMissionsFromRemote
1405  * @tc.type: FUNC
1406  * @tc.require: I5XDDS
1407  */
1408 HWTEST_F(DMSMissionManagerTest, ProxyCallStopSyncMissionsFromRemote001, TestSize.Level3)
1409 {
1410     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStopSyncMissionsFromRemote001 start" << std::endl;
1411     //OnDnetDied
1412     DistributedSchedMissionManager::GetInstance().Init();
1413     DistributedSchedMissionManager::GetInstance().OnDnetDied();
1414     DistributedSchedMissionManager::GetInstance().isRegMissionChange_ = false;
1415     DistributedSchedMissionManager::GetInstance().OnDnetDied();
1416 
1417     //proxy StopSyncMissionsFromRemote
1418     sptr<IDistributedSched> proxy = GetDms();
1419     ASSERT_NE(nullptr, proxy);
1420     CallerInfo callerInfo;
1421     int32_t ret = proxy->StopSyncMissionsFromRemote(callerInfo);
1422     EXPECT_EQ(ret, REQUEST_CODE_ERR);
1423     DTEST_LOG << "DistributedSchedServiceTest ProxyCallStopSyncMissionsFromRemote001 end" << std::endl;
1424 }
1425 
1426 /**
1427  * @tc.name: ProxyCallNotifyMissionsChangedFromRemote001
1428  * @tc.desc: call dms proxy NotifyMissionsChangedFromRemote
1429  * @tc.type: FUNC
1430  * @tc.require: I5XDDS
1431  */
1432 HWTEST_F(DMSMissionManagerTest, ProxyCallNotifyMissionsChangedFromRemote001, TestSize.Level3)
1433 {
1434     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyMissionsChangedFromRemote001 start" << std::endl;
1435     sptr<IDistributedSched> proxy = GetDms();
1436     ASSERT_NE(nullptr, proxy);
1437     CallerInfo callerInfo;
1438     std::vector<DstbMissionInfo> missionInfos;
1439     int32_t ret = proxy->NotifyMissionsChangedFromRemote(missionInfos, callerInfo);
1440     EXPECT_EQ(ret, REQUEST_CODE_ERR);
1441     DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyMissionsChangedFromRemote001 end" << std::endl;
1442 }
1443 
1444 /**
1445  * @tc.name: ProxyCallGetRemoteMissionSnapshotInfo001
1446  * @tc.desc: call dms proxy GetRemoteMissionSnapshotInfo
1447  * @tc.type: FUNC
1448  * @tc.require: I5XDDS
1449  */
1450 HWTEST_F(DMSMissionManagerTest, ProxyCallGetRemoteMissionSnapshotInfo001, TestSize.Level3)
1451 {
1452     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo001 start" << std::endl;
1453     sptr<IDistributedSched> proxy = GetDms();
1454     ASSERT_NE(nullptr, proxy);
1455     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1456     int32_t ret = proxy->GetRemoteMissionSnapshotInfo("MockDevId", 1, missionSnapshot);
1457     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1458     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo001 end" << std::endl;
1459 }
1460 
1461 /**
1462  * @tc.name: ProxyCallGetRemoteMissionSnapshotInfo002
1463  * @tc.desc: call dms proxy GetRemoteMissionSnapshotInfo
1464  * @tc.type: FUNC
1465  * @tc.require: I5XDDS
1466  */
1467 HWTEST_F(DMSMissionManagerTest, ProxyCallGetRemoteMissionSnapshotInfo002, TestSize.Level3)
1468 {
1469     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo002 start" << std::endl;
1470     sptr<IDistributedSched> proxy = GetDms();
1471     ASSERT_NE(nullptr, proxy);
1472     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1473     int32_t ret = proxy->GetRemoteMissionSnapshotInfo("", 1, missionSnapshot);
1474     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1475     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo002 end" << std::endl;
1476 }
1477 
1478 /**
1479  * @tc.name: ProxyCallGetRemoteMissionSnapshotInfo003
1480  * @tc.desc: call dms proxy GetRemoteMissionSnapshotInfo
1481  * @tc.type: FUNC
1482  * @tc.require: I5XDDS
1483  */
1484 HWTEST_F(DMSMissionManagerTest, ProxyCallGetRemoteMissionSnapshotInfo003, TestSize.Level3)
1485 {
1486     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo003 start" << std::endl;
1487     sptr<IDistributedSched> proxy = GetDms();
1488     ASSERT_NE(nullptr, proxy);
1489     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1490     int32_t ret = proxy->GetRemoteMissionSnapshotInfo("MockDevId", -1, missionSnapshot);
1491     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1492     DTEST_LOG << "DistributedSchedServiceTest ProxyCallGetRemoteMissionSnapshotInfo003 end" << std::endl;
1493 }
1494 
1495 /**
1496  * @tc.name: testDeleteDataStorage005
1497  * @tc.desc: test DeleteDataStorage
1498  * @tc.type: FUNC
1499  */
1500 HWTEST_F(DMSMissionManagerTest, testDeleteDataStorage005, TestSize.Level3)
1501 {
1502     DTEST_LOG << "testDeleteDataStorage005 begin" << std::endl;
1503     std::string uuid = "uuid for GetUuidByNetworkId";
1504     {
1505         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1506         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1507     }
1508     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1509         std::make_shared<DistributedDataStorage>();
1510     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anonee97076e0202() 1511     auto initDoneTask = []() {
1512         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
1513         isCaseDone_ = true;
1514         caseDoneCondition_.notify_all();
1515     };
1516     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
1517         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
1518             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
1519         if (dmsDataStorageHandler != nullptr) {
1520             dmsDataStorageHandler->PostTask(initDoneTask);
1521         }
1522     }
1523     std::unique_lock<std::mutex> lock(caseDoneLock_);
1524     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anonee97076e0302() 1525         [&] () { return isCaseDone_; });
1526     EXPECT_TRUE(result);
1527     isCaseDone_ = false;
1528     uint8_t* byteStream = new uint8_t[BYTESTREAM_LENGTH];
1529     for (size_t i = 0; i < BYTESTREAM_LENGTH; ++i) {
1530         byteStream[i] = ONE_BYTE;
1531     }
1532     result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Insert(localDeviceId_,
1533         TASK_ID, byteStream, BYTESTREAM_LENGTH);
1534     EXPECT_TRUE(result);
1535     DistributedSchedMissionManager::GetInstance().missionHandler_ = nullptr;
1536     DistributedSchedMissionManager::GetInstance().DeleteDataStorage(localDeviceId_, false);
1537     DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Stop();
1538     DTEST_LOG << "testDeleteDataStorage005 end" << std::endl;
1539 }
1540 
1541 /**
1542  * @tc.name: testDeleteDataStorage006
1543  * @tc.desc: test DeleteDataStorage
1544  * @tc.type: FUNC
1545  */
1546 HWTEST_F(DMSMissionManagerTest, testDeleteDataStorage006, TestSize.Level3)
1547 {
1548     DTEST_LOG << "testDeleteDataStorage006 begin" << std::endl;
1549     std::string uuid = "uuid for GetUuidByNetworkId";
1550     {
1551         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1552         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1553     }
1554     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1555         std::make_shared<DistributedDataStorage>();
1556     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anonee97076e0402() 1557     auto initDoneTask = []() {
1558         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
1559         isCaseDone_ = true;
1560         caseDoneCondition_.notify_all();
1561     };
1562     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
1563         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
1564             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
1565         if (dmsDataStorageHandler != nullptr) {
1566             dmsDataStorageHandler->PostTask(initDoneTask);
1567         }
1568     }
1569     std::unique_lock<std::mutex> lock(caseDoneLock_);
1570     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anonee97076e0502() 1571         [&] () { return isCaseDone_; });
1572     EXPECT_TRUE(result);
1573     isCaseDone_ = false;
1574     uint8_t* byteStream = new uint8_t[BYTESTREAM_LENGTH];
1575     for (size_t i = 0; i < BYTESTREAM_LENGTH; ++i) {
1576         byteStream[i] = ONE_BYTE;
1577     }
1578     result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Insert(localDeviceId_,
1579         TASK_ID, byteStream, BYTESTREAM_LENGTH);
1580     EXPECT_TRUE(result);
1581     DistributedSchedMissionManager::GetInstance().missionHandler_ = nullptr;
1582     DistributedSchedMissionManager::GetInstance().DeleteDataStorage(localDeviceId_, true);
1583     DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Stop();
1584     DTEST_LOG << "testDeleteDataStorage006 end" << std::endl;
1585 }
1586 
1587 /**
1588  * @tc.name: testRegisterMissionListener009
1589  * @tc.desc: test register mission listener
1590  * @tc.type: FUNC
1591  */
1592 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener009, TestSize.Level3)
1593 {
1594     DTEST_LOG << "testRegisterMissionListener009 begin" << std::endl;
1595     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
1596     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
1597     u16string deviceId = Str8ToStr16(localDeviceId_);
1598     std::string uuid = "uuid for GetUuidByNetworkId";
1599     {
1600         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1601         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1602     }
1603     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
1604     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(deviceId, listener);
1605     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1606     DTEST_LOG << "testRegisterMissionListener009 end" << std::endl;
1607 }
1608 
1609 /**
1610  * @tc.name: testRegisterMissionListener010
1611  * @tc.desc: test register mission listener
1612  * @tc.type: FUNC
1613  */
1614 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener010, TestSize.Level3)
1615 {
1616     DTEST_LOG << "testRegisterMissionListener010 begin" << std::endl;
1617     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
1618     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
1619     u16string deviceId = Str8ToStr16(DEVICE_ID);
1620     std::string uuid = "uuid for GetUuidByNetworkId";
1621     {
1622         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1623         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
1624     }
1625     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
1626     {
1627         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
1628         ListenerInfo listenerInfo;
1629         listenerInfo.Emplace(listener);
1630         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
1631     }
1632     auto ret = DistributedSchedMissionManager::GetInstance().RegisterMissionListener(deviceId, listener);
1633     EXPECT_EQ(ret, ERR_NONE);
1634     DTEST_LOG << "testRegisterMissionListener010 end" << std::endl;
1635 }
1636 
1637 /**
1638  * @tc.name: testIsDeviceIdValidated002
1639  * @tc.desc: test IsDeviceIdValidated
1640  * @tc.type: FUNC
1641  */
1642 HWTEST_F(DMSMissionManagerTest, testIsDeviceIdValidated002, TestSize.Level1)
1643 {
1644     DTEST_LOG << "testIsDeviceIdValidated002 begin" << std::endl;
1645     {
1646         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1647         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
1648     }
1649 
1650     int32_t deviceType = 0;
1651     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
1652         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, localDeviceId_);
1653     {
1654         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1655         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[localDeviceId_] = dmsDeviceInfo;
1656     }
1657     auto ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(localDeviceId_);
1658     EXPECT_TRUE(ret);
1659     DTEST_LOG << "testIsDeviceIdValidated002 end" << std::endl;
1660 }
1661 
1662 
1663 /**
1664  * @tc.name: testGetMissionInfos007
1665  * @tc.desc: get missions
1666  * @tc.type: FUNC
1667  */
1668 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos007, TestSize.Level3)
1669 {
1670     DTEST_LOG << "testGetMissionInfos007 begin" << std::endl;
1671     {
1672         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1673         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
1674     }
1675 
1676     int32_t deviceType = 0;
1677     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
1678         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
1679     {
1680         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1681         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
1682     }
1683     int32_t numMissions = 0;
1684     std::vector<AAFwk::MissionInfo> missionInfos;
1685     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, numMissions, missionInfos);
1686     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1687     DTEST_LOG << "testGetMissionInfos007 end" << std::endl;
1688 }
1689 
1690 /**
1691  * @tc.name: testGetMissionInfos008
1692  * @tc.desc: get missions
1693  * @tc.type: FUNC
1694  */
1695 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos008, TestSize.Level3)
1696 {
1697     DTEST_LOG << "testGetMissionInfos008 begin" << std::endl;
1698     {
1699         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1700         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
1701     }
1702 
1703     int32_t deviceType = 0;
1704     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
1705         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
1706     {
1707         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1708         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
1709     }
1710     int32_t numMissions = NORMAL_NUM_MISSIONS;
1711     std::vector<AAFwk::MissionInfo> missionInfos;
1712     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, numMissions, missionInfos);
1713     EXPECT_EQ(ret, ERR_OK);
1714     DTEST_LOG << "testGetMissionInfos008 end" << std::endl;
1715 }
1716 
1717 /**
1718  * @tc.name: testGetMissionInfos009
1719  * @tc.desc: get missions
1720  * @tc.type: FUNC
1721  */
1722 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos009, TestSize.Level3)
1723 {
1724     DTEST_LOG << "testGetMissionInfos009 begin" << std::endl;
1725     {
1726         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1727         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
1728     }
1729 
1730     int32_t deviceType = 0;
1731     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
1732         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
1733     {
1734         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
1735         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[localDeviceId_] = dmsDeviceInfo;
1736     }
1737     int32_t numMissions = NORMAL_NUM_MISSIONS;
1738     std::vector<AAFwk::MissionInfo> missionInfos;
1739     std::string uuid = DtbschedmgrDeviceInfoStorage::GetInstance().GetUuidByNetworkId(localDeviceId_);
1740     {
1741         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteMissionInfosLock_);
1742         DistributedSchedMissionManager::GetInstance().deviceMissionInfos_.erase(uuid);
1743     }
1744     std::vector<DstbMissionInfo> dstbMissionInfos;
1745     {
1746         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteMissionInfosLock_);
1747         DistributedSchedMissionManager::GetInstance().deviceMissionInfos_[uuid] = dstbMissionInfos;
1748     }
1749     auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(localDeviceId_, numMissions, missionInfos);
1750     EXPECT_EQ(ret, ERR_OK);
1751     DTEST_LOG << "testGetMissionInfos009 end" << std::endl;
1752 }
1753 
1754 /**
1755  * @tc.name: testInitDataStorage003
1756  * @tc.desc: test init data storage
1757  * @tc.type: FUNC
1758  */
1759 HWTEST_F(DMSMissionManagerTest, testInitDataStorage003, TestSize.Level3)
1760 {
1761     DTEST_LOG << "testInitDataStorage003 begin" << std::endl;
1762     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ == nullptr) {
1763         DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1764             std::make_shared<DistributedDataStorage>();
1765     }
1766     auto ret = DistributedSchedMissionManager::GetInstance().InitDataStorage();
1767     EXPECT_EQ(ret, ERR_NONE);
1768     ret = DistributedSchedMissionManager::GetInstance().StopDataStorage();
1769     DTEST_LOG << "testInitDataStorage003 end" << std::endl;
1770 }
1771 
1772 /**
1773  * @tc.name: testStopDataStorage003
1774  * @tc.desc: test stop data storage
1775  * @tc.type: FUNC
1776  */
1777 HWTEST_F(DMSMissionManagerTest, testStopDataStorage003, TestSize.Level3)
1778 {
1779     DTEST_LOG << "testStopDataStorage003 begin" << std::endl;
1780     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1781         std::make_shared<DistributedDataStorage>();
1782     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anonee97076e0602() 1783     auto initDoneTask = []() {
1784         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
1785         isCaseDone_ = true;
1786         caseDoneCondition_.notify_all();
1787     };
1788     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
1789         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
1790             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
1791         if (dmsDataStorageHandler != nullptr) {
1792             dmsDataStorageHandler->PostTask(initDoneTask);
1793         }
1794     }
1795     std::unique_lock<std::mutex> lock(caseDoneLock_);
1796     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anonee97076e0702() 1797         [&] () { return isCaseDone_; });
1798     EXPECT_TRUE(result);
1799     isCaseDone_ = false;
1800     auto ret = DistributedSchedMissionManager::GetInstance().StopDataStorage();
1801     EXPECT_EQ(ret, ERR_NONE);
1802     DTEST_LOG << "testStopDataStorage003 end" << std::endl;
1803 }
1804 
1805 /**
1806  * @tc.name: testStoreSnapshotInfo004
1807  * @tc.desc: test store snapshot info
1808  * @tc.type: FUNC
1809  */
1810 HWTEST_F(DMSMissionManagerTest, testStoreSnapshotInfo004, TestSize.Level3)
1811 {
1812     DTEST_LOG << "testStoreSnapshotInfo004 begin" << std::endl;
1813     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1814             std::make_shared<DistributedDataStorage>();
1815     auto ret = DistributedSchedMissionManager::GetInstance().StoreSnapshotInfo(DEVICE_ID, 0, 0, 0);
1816     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1817     DTEST_LOG << "testStoreSnapshotInfo004 end" << std::endl;
1818 }
1819 
1820 /**
1821  * @tc.name: testStoreSnapshotInfo003
1822  * @tc.desc: test store snapshot info
1823  * @tc.type: FUNC
1824  */
1825 HWTEST_F(DMSMissionManagerTest, testStoreSnapshotInfo003, TestSize.Level3)
1826 {
1827     DTEST_LOG << "testStoreSnapshotInfo003 begin" << std::endl;
1828     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1829         std::make_shared<DistributedDataStorage>();
1830     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anonee97076e0802() 1831     auto initDoneTask = []() {
1832         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
1833         isCaseDone_ = true;
1834         caseDoneCondition_.notify_all();
1835     };
1836     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
1837         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
1838             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
1839         if (dmsDataStorageHandler != nullptr) {
1840             dmsDataStorageHandler->PostTask(initDoneTask);
1841         }
1842     }
1843     std::unique_lock<std::mutex> lock(caseDoneLock_);
1844     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anonee97076e0902() 1845         [&] () { return isCaseDone_; });
1846     EXPECT_TRUE(result);
1847     isCaseDone_ = false;
1848     std::string uuid = "uuid for GetUuidByNetworkId";
1849     {
1850         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1851         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1852     }
1853     uint8_t* byteStream = new uint8_t[BYTESTREAM_LENGTH];
1854     for (size_t i = 0; i < BYTESTREAM_LENGTH; ++i) {
1855         byteStream[i] = ONE_BYTE;
1856     }
1857     auto ret = DistributedSchedMissionManager::GetInstance().
1858         StoreSnapshotInfo(localDeviceId_, TASK_ID, byteStream, BYTESTREAM_LENGTH);
1859     EXPECT_EQ(ret, ERR_NONE);
1860     ret = DistributedSchedMissionManager::GetInstance().RemoveSnapshotInfo(localDeviceId_, TASK_ID);
1861     EXPECT_EQ(ret, ERR_NONE);
1862     DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Stop();
1863     DTEST_LOG << "testStoreSnapshotInfo003 end" << std::endl;
1864 }
1865 
1866 /**
1867  * @tc.name: testRemoveSnapshotInfo003
1868  * @tc.desc: test remove snapshot info
1869  * @tc.type: FUNC
1870  */
1871 HWTEST_F(DMSMissionManagerTest, testRemoveSnapshotInfo003, TestSize.Level3)
1872 {
1873     DTEST_LOG << "testRemoveSnapshotInfo003 begin" << std::endl;
1874     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1875             std::make_shared<DistributedDataStorage>();
1876     auto ret = DistributedSchedMissionManager::GetInstance().RemoveSnapshotInfo(DEVICE_ID, 0);
1877     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1878     DTEST_LOG << "testRemoveSnapshotInfo003 end" << std::endl;
1879 }
1880 
1881 /**
1882  * @tc.name: testGetRemoteMissionSnapshotInfo002
1883  * @tc.desc: test get remote mission snapshot info
1884  * @tc.type: FUNC
1885  */
1886 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionSnapshotInfo002, TestSize.Level3)
1887 {
1888     DTEST_LOG << "testGetRemoteMissionSnapshotInfo002 begin" << std::endl;
1889     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1890     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ = nullptr;
1891     std::string uuid = "uuid for GetUuidByNetworkId";
1892     {
1893         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1894         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1895     }
1896     auto ret = DistributedSchedMissionManager::GetInstance().GetRemoteMissionSnapshotInfo(localDeviceId_,
1897         0, missionSnapshot);
1898     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1899     DTEST_LOG << "testGetRemoteMissionSnapshotInfo002 end" << std::endl;
1900 }
1901 
1902 /**
1903  * @tc.name: testGetRemoteMissionSnapshotInfo004
1904  * @tc.desc: test get remote mission snapshot info
1905  * @tc.type: FUNC
1906  */
1907 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionSnapshotInfo004, TestSize.Level3)
1908 {
1909     DTEST_LOG << "testGetRemoteMissionSnapshotInfo004 begin" << std::endl;
1910     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1911     std::string uuid = "uuid for GetUuidByNetworkId";
1912     {
1913         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1914         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1915     }
1916     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1917         std::make_shared<DistributedDataStorage>();
1918     auto ret = DistributedSchedMissionManager::GetInstance().GetRemoteMissionSnapshotInfo(localDeviceId_,
1919         TASK_ID, missionSnapshot);
1920     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1921     DTEST_LOG << "testGetRemoteMissionSnapshotInfo004 end" << std::endl;
1922 }
1923 
1924 /**
1925  * @tc.name: testGetRemoteMissionSnapshotInfo005
1926  * @tc.desc: test get remote mission snapshot info
1927  * @tc.type: FUNC
1928  */
1929 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionSnapshotInfo005, TestSize.Level3)
1930 {
1931     DTEST_LOG << "testGetRemoteMissionSnapshotInfo005 begin" << std::endl;
1932     unique_ptr<AAFwk::MissionSnapshot> missionSnapshot = nullptr;
1933     std::string uuid = "uuid for GetUuidByNetworkId";
1934     {
1935         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
1936         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
1937     }
1938     DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
1939         std::make_shared<DistributedDataStorage>();
1940     auto result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Init();
__anonee97076e0a02() 1941     auto initDoneTask = []() {
1942         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
1943         isCaseDone_ = true;
1944         caseDoneCondition_.notify_all();
1945     };
1946     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
1947         std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
1948             DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
1949         if (dmsDataStorageHandler != nullptr) {
1950             dmsDataStorageHandler->PostTask(initDoneTask);
1951         }
1952     }
1953     std::unique_lock<std::mutex> lock(caseDoneLock_);
1954     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
__anonee97076e0b02() 1955         [&] () { return isCaseDone_; });
1956     EXPECT_TRUE(result);
1957     isCaseDone_ = false;
1958     uint8_t* byteStream = new uint8_t[BYTESTREAM_LENGTH];
1959     for (size_t i = 0; i < BYTESTREAM_LENGTH; ++i) {
1960         byteStream[i] = ONE_BYTE;
1961     }
1962     result = DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Insert(localDeviceId_,
1963         TASK_ID, byteStream, BYTESTREAM_LENGTH);
1964     EXPECT_TRUE(result);
1965     auto ret = DistributedSchedMissionManager::GetInstance().GetRemoteMissionSnapshotInfo(localDeviceId_,
1966         TASK_ID, missionSnapshot);
1967     EXPECT_EQ(ret, ERR_NULL_OBJECT);
1968     DistributedSchedMissionManager::GetInstance().distributedDataStorage_->Stop();
1969     DTEST_LOG << "testGetRemoteMissionSnapshotInfo005 end" << std::endl;
1970 }
1971 
1972 /**
1973  * @tc.name: testDeviceOfflineNotify003
1974  * @tc.desc: test device offline notify
1975  * @tc.type: FUNC
1976  */
1977 HWTEST_F(DMSMissionManagerTest, testDeviceOfflineNotify003, TestSize.Level3)
1978 {
1979     DTEST_LOG << "testDeviceOfflineNotify003 begin" << std::endl;
1980     DistributedSchedMissionManager::GetInstance().Init();
1981     DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(DEVICE_ID);
1982     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
1983     sptr<IDistributedSched> remoteDmsObj(new DistributedSchedProxy(listener));
1984     {
1985         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
1986         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
1987     }
1988     {
1989         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
1990         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = remoteDmsObj;
1991     }
1992     DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify(DEVICE_ID);
1993     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().remoteDmsMap_.empty(), true);
1994     DTEST_LOG << "testDeviceOfflineNotify003 end" << std::endl;
1995 }
1996 
1997 /**
1998  * @tc.name: testStartSyncRemoteMissions015
1999  * @tc.desc: prepare and sync missions from remote
2000  * @tc.type: FUNC
2001  */
2002 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions015, TestSize.Level3)
2003 {
2004     DTEST_LOG << "testStartSyncRemoteMissions015 begin" << std::endl;
2005     u16string deviceId = Str8ToStr16(DEVICE_ID);
2006     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2007     {
2008         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2009         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2010     }
2011     {
2012         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2013         ListenerInfo listenerInfo;
2014         listenerInfo.Emplace(listener);
2015         listenerInfo.called = true;
2016         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2017     }
2018     sptr<IDistributedSched> proxy = GetDms();
2019     ASSERT_NE(nullptr, proxy);
2020     {
2021         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2022         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2023     }
2024     {
2025         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2026         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
2027     }
2028     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, localDeviceId_);
2029     EXPECT_EQ(ret, ERR_NONE);
2030     DTEST_LOG << "testStartSyncRemoteMissions015 end" << std::endl;
2031 }
2032 
2033 /**
2034  * @tc.name: testStartSyncRemoteMissions016
2035  * @tc.desc: prepare and sync missions from remote
2036  * @tc.type: FUNC
2037  */
2038 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions016, TestSize.Level3)
2039 {
2040     DTEST_LOG << "testStartSyncRemoteMissions016 begin" << std::endl;
2041     u16string deviceId = Str8ToStr16(DEVICE_ID);
2042     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2043     {
2044         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2045         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2046     }
2047     {
2048         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2049         ListenerInfo listenerInfo;
2050         listenerInfo.Emplace(listener);
2051         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2052     }
2053     sptr<IDistributedSched> proxy = GetDms();
2054     ASSERT_NE(nullptr, proxy);
2055     {
2056         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2057         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2058     }
2059     {
2060         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2061         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
2062     }
2063     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncRemoteMissions(DEVICE_ID, localDeviceId_);
2064     EXPECT_NE(ret, ERR_NONE);
2065     DTEST_LOG << "testStartSyncRemoteMissions016 end" << std::endl;
2066 }
2067 
2068 /**
2069  * @tc.name: testUnRegisterMissionListener006
2070  * @tc.desc: register mission listener
2071  * @tc.type: FUNC
2072  */
2073 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener006, TestSize.Level3)
2074 {
2075     DTEST_LOG << "testUnRegisterMissionListener006 begin" << std::endl;
2076     /**
2077      * @tc.steps: step1. test device online notify
2078      */
2079     DTEST_LOG << "testDeviceOnlineNotify001 begin" << std::endl;
2080     DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify("");
2081     DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(DEVICE_ID);
2082     DTEST_LOG << "testDeviceOnlineNotify001 end" << std::endl;
2083 
2084     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2085     {
2086         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2087         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2088     }
2089     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
2090     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
2091     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(U16DEVICE_ID, listener);
2092     EXPECT_EQ(ret, ERR_NONE);
2093     DTEST_LOG << "testUnRegisterMissionListener006 end" << std::endl;
2094 }
2095 
2096 /**
2097  * @tc.name: testUnRegisterMissionListener007
2098  * @tc.desc: register mission listener
2099  * @tc.type: FUNC
2100  */
2101 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener007, TestSize.Level3)
2102 {
2103     DTEST_LOG << "testUnRegisterMissionListener007 begin" << std::endl;
2104     /**
2105      * @tc.steps: step1. test delete data storage
2106      */
2107     DTEST_LOG << "testDeleteDataStorage001 begin" << std::endl;
2108     DistributedSchedMissionManager::GetInstance().DeleteDataStorage("", false);
2109     DTEST_LOG << "testDeleteDataStorage001 end" << std::endl;
2110     DTEST_LOG << "testDeleteDataStorage002 begin" << std::endl;
2111     DistributedSchedMissionManager::GetInstance().DeleteDataStorage(DEVICE_ID, false);
2112     DTEST_LOG << "testDeleteDataStorage002 end" << std::endl;
2113     DTEST_LOG << "testDeleteDataStorage003 begin" << std::endl;
2114     DistributedSchedMissionManager::GetInstance().DeleteDataStorage("", true);
2115     DTEST_LOG << "testDeleteDataStorage003 end" << std::endl;
2116     DTEST_LOG << "testDeleteDataStorage004 begin" << std::endl;
2117     DistributedSchedMissionManager::GetInstance().DeleteDataStorage(DEVICE_ID, true);
2118     DTEST_LOG << "testDeleteDataStorage004 end" << std::endl;
2119 
2120     u16string deviceId = Str8ToStr16(DEVICE_ID);
2121     {
2122         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2123         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2124     }
2125     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2126     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
2127     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
2128     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, listener);
2129     EXPECT_EQ(ret, ERR_NONE);
2130     DTEST_LOG << "testUnRegisterMissionListener007 end" << std::endl;
2131 }
2132 
2133 /**
2134  * @tc.name: testUnRegisterMissionListener008
2135  * @tc.desc: register mission listener
2136  * @tc.type: FUNC
2137  */
2138 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener008, TestSize.Level3)
2139 {
2140     DTEST_LOG << "testUnRegisterMissionListener008 begin" << std::endl;
2141     /**
2142      * @tc.steps: step1. enqueue cached snapshot info
2143      */
2144     DTEST_LOG << "testEnqueueCachedSnapshotInfo001 begin" << std::endl;
2145     DistributedSchedMissionManager::GetInstance().EnqueueCachedSnapshotInfo("", 1, nullptr);
2146     DTEST_LOG << "testEnqueueCachedSnapshotInfo001 end" << std::endl;
2147     DTEST_LOG << "testEnqueueCachedSnapshotInfo002 begin" << std::endl;
2148     DistributedSchedMissionManager::GetInstance().EnqueueCachedSnapshotInfo(DEVICE_ID, 1, nullptr);
2149     DTEST_LOG << "testEnqueueCachedSnapshotInfo002 end" << std::endl;
2150     DTEST_LOG << "testEnqueueCachedSnapshotInfo003 begin" << std::endl;
2151     unique_ptr<Snapshot> snapshot = make_unique<Snapshot>();
2152     DistributedSchedMissionManager::GetInstance().EnqueueCachedSnapshotInfo("", 1, std::move(snapshot));
2153     DTEST_LOG << "testEnqueueCachedSnapshotInfo003 end" << std::endl;
2154     DTEST_LOG << "testDequeueCachedSnapshotInfo001 begin" << std::endl;
2155     DistributedSchedMissionManager::GetInstance().DequeueCachedSnapshotInfo("", 1);
2156     DTEST_LOG << "testDequeueCachedSnapshotInfo001 end" << std::endl;
2157     DTEST_LOG << "testDequeueCachedSnapshotInfo002 begin" << std::endl;
2158     DistributedSchedMissionManager::GetInstance().DequeueCachedSnapshotInfo(DEVICE_ID, 1);
2159     DTEST_LOG << "testDequeueCachedSnapshotInfo002 end" << std::endl;
2160     /**
2161      * @tc.steps: step2. reborn mission cache
2162      */
2163     DTEST_LOG << "testRebornMissionCache001 begin" << std::endl;
2164     std::vector<DstbMissionInfo> missionInfos;
2165     DistributedSchedMissionManager::GetInstance().RebornMissionCache("", missionInfos);
2166     DTEST_LOG << "testRebornMissionCache001 end" << std::endl;
2167     DTEST_LOG << "testRebornMissionCache002 begin" << std::endl;
2168     DistributedSchedMissionManager::GetInstance().RebornMissionCache(DEVICE_ID, missionInfos);
2169     DTEST_LOG << "testRebornMissionCache002 end" << std::endl;
2170 
2171     u16string deviceId = Str8ToStr16(DEVICE_ID);
2172     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2173     {
2174         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2175         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2176     }
2177     {
2178         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2179         ListenerInfo listenerInfo;
2180         listenerInfo.Emplace(listener);
2181         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2182     }
2183     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
2184     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
2185     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, listener);
2186     EXPECT_EQ(ret, ERR_NONE);
2187     DTEST_LOG << "testUnRegisterMissionListener008 end" << std::endl;
2188 }
2189 
2190 /**
2191  * @tc.name: testUnRegisterMissionListener009
2192  * @tc.desc: register mission listener
2193  * @tc.type: FUNC
2194  */
2195 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener009, TestSize.Level3)
2196 {
2197     DTEST_LOG << "testUnRegisterMissionListener009 begin" << std::endl;
2198     /**
2199      * @tc.steps: step1. fetch device handler
2200      */
2201     DTEST_LOG << "testFetchDeviceHandler001 begin" << std::endl;
2202     DistributedSchedMissionManager::GetInstance().FetchDeviceHandler("");
2203     DistributedSchedMissionManager::GetInstance().FetchDeviceHandler(DEVICE_ID);
2204     DTEST_LOG << "testFetchDeviceHandler001 end" << std::endl;
2205 
2206     u16string deviceId = Str8ToStr16(DEVICE_ID);
2207     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2208     sptr<IRemoteObject> nullListener = nullptr;
2209     {
2210         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2211         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2212     }
2213     {
2214         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2215         ListenerInfo listenerInfo;
2216         listenerInfo.Emplace(listener);
2217         listenerInfo.Emplace(nullListener);
2218         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2219     }
2220     auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
2221     DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = deviceInfo;
2222     auto ret = DistributedSchedMissionManager::GetInstance().UnRegisterMissionListener(deviceId, listener);
2223     EXPECT_EQ(ret, ERR_NONE);
2224     DTEST_LOG << "testUnRegisterMissionListener009 end" << std::endl;
2225 }
2226 
2227 /**
2228  * @tc.name: testCleanMissionResources002
2229  * @tc.desc: prepare and sync missions from remote
2230  * @tc.type: FUNC
2231  */
2232 HWTEST_F(DMSMissionManagerTest, testCleanMissionResources002, TestSize.Level3)
2233 {
2234     DTEST_LOG << "testCleanMissionResources002 begin" << std::endl;
2235     u16string deviceId = Str8ToStr16(DEVICE_ID);
2236     sptr<IRemoteObject> nullListener = nullptr;
2237     {
2238         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2239         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2240     }
2241     {
2242         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2243         ListenerInfo listenerInfo;
2244         listenerInfo.Emplace(nullListener);
2245         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2246     }
2247     DistributedSchedMissionManager::GetInstance().CleanMissionResources(DEVICE_ID);
2248     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().listenDeviceMap_.empty(), true);
2249     DTEST_LOG << "testCleanMissionResources002 end" << std::endl;
2250 }
2251 
2252 /**
2253  * @tc.name: testStopSyncRemoteMissions013
2254  * @tc.desc: stop sync missions from remote with deviceId
2255  * @tc.type: FUNC
2256  */
2257 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions013, TestSize.Level3)
2258 {
2259     DTEST_LOG << "testStopSyncRemoteMissions013 begin" << std::endl;
2260     /**
2261      * @tc.steps: step1. test GetRemoteDms
2262      */
2263     DTEST_LOG << "testGetRemoteDms001 begin" << std::endl;
2264     sptr<IDistributedSched> proxy = GetDms();
2265     ASSERT_NE(nullptr, proxy);
2266     {
2267         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2268         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2269     }
2270     {
2271         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2272         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[localDeviceId_] = proxy;
2273     }
2274 
2275     DistributedSchedMissionManager::GetInstance().GetRemoteDms(localDeviceId_);
2276     DTEST_LOG << "testGetRemoteDms001 end" << std::endl;
2277 
2278     {
2279         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2280         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2281     }
2282     {
2283         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2284         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
2285     }
2286     auto ret = DistributedSchedMissionManager::GetInstance().StopSyncRemoteMissions(DEVICE_ID, false, false);
2287     EXPECT_NE(ret, ERR_NONE);
2288     DTEST_LOG << "testStopSyncRemoteMissions013 end" << std::endl;
2289 }
2290 
2291 /**
2292  * @tc.name: testStartSyncMissionsFromRemote002
2293  * @tc.desc: prepare and sync missions from remote
2294  * @tc.type: FUNC
2295  */
2296 HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote002, TestSize.Level3)
2297 {
2298     DTEST_LOG << "testStartSyncMissionsFromRemote002 begin" << std::endl;
2299     DistributedSchedUtil::MockManageMissions();
2300     /**
2301      * @tc.steps: step1. test GetRemoteDms
2302      */
2303     DTEST_LOG << "testGetRemoteDms002 begin" << std::endl;
2304     {
2305         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2306         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2307     }
2308     {
2309         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2310         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[localDeviceId_] = nullptr;
2311     }
2312 
2313     DistributedSchedMissionManager::GetInstance().GetRemoteDms(localDeviceId_);
2314     DTEST_LOG << "testGetRemoteDms002 end" << std::endl;
2315 
2316     std::vector<DstbMissionInfo> missionInfos;
2317     CallerInfo callerInfo;
2318     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2319     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2320     DistributedSchedMissionManager::GetInstance().missonChangeListener_ = new DistributedMissionChangeListener();
2321     DistributedSchedMissionManager::GetInstance().GenerateCallerInfo(callerInfo);
2322     DistributedSchedMissionManager::GetInstance().isRegMissionChange_ = true;
2323     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncMissionsFromRemote(callerInfo, missionInfos);
2324     EXPECT_EQ(ret, ERR_NONE);
2325     DTEST_LOG << "testStartSyncMissionsFromRemote002 end" << std::endl;
2326 }
2327 
2328 /**
2329  * @tc.name: testStartSyncMissionsFromRemote003
2330  * @tc.desc: prepare and sync missions from remote
2331  * @tc.type: FUNC
2332  */
2333 HWTEST_F(DMSMissionManagerTest, testStartSyncMissionsFromRemote003, TestSize.Level3)
2334 {
2335     DTEST_LOG << "testStartSyncMissionsFromRemote003 begin" << std::endl;
2336     DistributedSchedUtil::MockManageMissions();
2337     /**
2338      * @tc.steps: step1. test notify remote died
2339      */
2340     DTEST_LOG << "testNotifyRemoteDied002 begin" << std::endl;
2341     wptr<IRemoteObject> remote = new RemoteMissionListenerTest();
2342     if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ == nullptr) {
2343         DistributedSchedMissionManager::GetInstance().distributedDataStorage_ =
2344             std::make_shared<DistributedDataStorage>();
2345     }
2346     DistributedSchedMissionManager::GetInstance().NotifyRemoteDied(remote);
2347     DTEST_LOG << "testNotifyRemoteDied002 end" << std::endl;
2348 
2349     std::vector<DstbMissionInfo> missionInfos;
2350     CallerInfo callerInfo;
2351     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2352     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2353     DistributedSchedMissionManager::GetInstance().missonChangeListener_ = nullptr;
2354     DistributedSchedMissionManager::GetInstance().GenerateCallerInfo(callerInfo);
2355     DistributedSchedMissionManager::GetInstance().isRegMissionChange_ = false;
2356     auto ret = DistributedSchedMissionManager::GetInstance().StartSyncMissionsFromRemote(callerInfo, missionInfos);
2357     DistributedSchedMissionManager::GetInstance().StopSyncMissionsFromRemote(DEVICE_ID);
2358     EXPECT_EQ(ret, ERR_NONE);
2359     DTEST_LOG << "testStartSyncMissionsFromRemote003 end" << std::endl;
2360 }
2361 
2362 /**
2363  * @tc.name: testNeedSyncDevice003
2364  * @tc.desc: need sync device
2365  * @tc.type: FUNC
2366  */
2367 HWTEST_F(DMSMissionManagerTest, testNeedSyncDevice003, TestSize.Level3)
2368 {
2369     DTEST_LOG << "testNeedSyncDevice003 begin" << std::endl;
2370     /**
2371      * @tc.steps: step1. delete cached snapshot info
2372      */
2373     DTEST_LOG << "testDeleteCachedSnapshotInfo001 begin" << std::endl;
2374     u16string deviceId = Str8ToStr16(DEVICE_ID);
2375     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2376     {
2377         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2378         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2379     }
2380     {
2381         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2382         ListenerInfo listenerInfo;
2383         listenerInfo.Emplace(listener);
2384         listenerInfo.called = true;
2385         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2386     }
2387     DistributedSchedMissionManager::GetInstance().NotifySnapshotChanged(DEVICE_ID, 0);
2388     std::string uuid = "uuid for GetUuidByNetworkId";
2389     {
2390         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2391         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2392     }
2393     {
2394         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2395         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2396     }
2397     std::unique_ptr<Snapshot> snapshot = make_unique<Snapshot>();
2398     std::string key = DistributedSchedMissionManager::GetInstance().GenerateKeyInfo(DEVICE_ID, 1);
2399     {
2400         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2401         DistributedSchedMissionManager::GetInstance().cachedSnapshotInfos_.clear();
2402     }
2403     {
2404         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2405         DistributedSchedMissionManager::GetInstance().cachedSnapshotInfos_[key] = std::move(snapshot);
2406     }
2407     DistributedSchedMissionManager::GetInstance().DeleteCachedSnapshotInfo(DEVICE_ID);
2408     DTEST_LOG << "testDeleteCachedSnapshotInfo001 end" << std::endl;
2409 
2410     {
2411         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2412         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.clear();
2413     }
2414     {
2415         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2416         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.emplace(DEVICE_ID);
2417     }
2418     bool ret = DistributedSchedMissionManager::GetInstance().NeedSyncDevice(DEVICE_ID);
2419     EXPECT_TRUE(ret);
2420     DTEST_LOG << "testNeedSyncDevice003 end" << std::endl;
2421 }
2422 
2423 /**
2424  * @tc.name: testHasSyncListener002
2425  * @tc.desc: need sync device
2426  * @tc.type: FUNC
2427  */
2428 HWTEST_F(DMSMissionManagerTest, testHasSyncListener002, TestSize.Level3)
2429 {
2430     DTEST_LOG << "testHasSyncListener002 begin" << std::endl;
2431     /**
2432      * @tc.steps: step1. reborn mission cache
2433      */
2434     DTEST_LOG << "testRebornMissionCache003 begin" << std::endl;
2435     std::string uuid = "uuid for GetUuidByNetworkId";
2436     {
2437         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2438         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2439     }
2440     {
2441         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2442         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2443     }
2444     std::vector<DstbMissionInfo> missionInfos;
2445     DistributedSchedMissionManager::GetInstance().RebornMissionCache(DEVICE_ID, missionInfos);
2446     DTEST_LOG << "testRebornMissionCache003 end" << std::endl;
2447 
2448     u16string deviceId = Str8ToStr16(DEVICE_ID);
2449     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2450     {
2451         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2452         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2453     }
2454     {
2455         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2456         ListenerInfo listenerInfo;
2457         listenerInfo.Emplace(listener);
2458         listenerInfo.called = true;
2459         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2460     }
2461     bool ret = DistributedSchedMissionManager::GetInstance().HasSyncListener(DEVICE_ID);
2462     EXPECT_TRUE(ret);
2463     DTEST_LOG << "testHasSyncListener002 end" << std::endl;
2464 }
2465 
2466 /**
2467  * @tc.name: testDequeueCachedSnapshotInfo003
2468  * @tc.desc: enqueue cached snapshot info
2469  * @tc.type: FUNC
2470  */
2471 HWTEST_F(DMSMissionManagerTest, testDequeueCachedSnapshotInfo003, TestSize.Level3)
2472 {
2473     DTEST_LOG << "testDequeueCachedSnapshotInfo003 begin" << std::endl;
2474     u16string deviceId = Str8ToStr16(DEVICE_ID);
2475     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2476     {
2477         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2478         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2479     }
2480     {
2481         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2482         ListenerInfo listenerInfo;
2483         listenerInfo.called = false;
2484         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2485     }
2486     DistributedSchedMissionManager::GetInstance().NotifySnapshotChanged(DEVICE_ID, 0);
2487     std::unique_ptr<Snapshot> snapshot = make_unique<Snapshot>();
2488     std::string key = DistributedSchedMissionManager::GetInstance().GenerateKeyInfo(DEVICE_ID, 1);
2489     {
2490         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2491         DistributedSchedMissionManager::GetInstance().cachedSnapshotInfos_.clear();
2492     }
2493     {
2494         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2495         DistributedSchedMissionManager::GetInstance().cachedSnapshotInfos_[key] = std::move(snapshot);
2496     }
2497     auto ret = DistributedSchedMissionManager::GetInstance().DequeueCachedSnapshotInfo(DEVICE_ID, 1);
2498     EXPECT_NE(ret, nullptr);
2499     DTEST_LOG << "testDequeueCachedSnapshotInfo003 end" << std::endl;
2500 }
2501 
2502 /**
2503  * @tc.name: testFetchCachedRemoteMissions010
2504  * @tc.desc: test FetchCachedRemoteMissions
2505  * @tc.type: FUNC
2506  */
2507 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions010, TestSize.Level3)
2508 {
2509     DTEST_LOG << "testFetchCachedRemoteMissions010 begin" << std::endl;
2510     std::string uuid = "uuid for GetUuidByNetworkId";
2511     {
2512         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2513         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2514     }
2515     {
2516         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2517         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2518     }
2519     {
2520         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteMissionInfosLock_);
2521         DistributedSchedMissionManager::GetInstance().deviceMissionInfos_.clear();
2522     }
2523     std::vector<DstbMissionInfo> dstbMissionInfos;
2524     {
2525         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteMissionInfosLock_);
2526         DistributedSchedMissionManager::GetInstance().deviceMissionInfos_[uuid] = dstbMissionInfos;
2527     }
2528     auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(DEVICE_ID,
2529         0, dstbMissionInfos);
2530     EXPECT_EQ(ret, ERR_NONE);
2531     DTEST_LOG << "testFetchCachedRemoteMissions010 end" << std::endl;
2532 }
2533 
2534 /**
2535  * @tc.name: testNotifyMissionsChangedFromRemote003
2536  * @tc.desc: notify missions changed from remote
2537  * @tc.type: FUNC
2538  */
2539 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedFromRemote003, TestSize.Level3)
2540 {
2541     DTEST_LOG << "testNotifyMissionsChangedFromRemote003 begin" << std::endl;
2542     CallerInfo callerInfo;
2543     callerInfo.sourceDeviceId = DEVICE_ID;
2544     callerInfo.uid = 0;
2545     callerInfo.pid = 0;
2546     callerInfo.dmsVersion = 0;
2547     std::vector<DstbMissionInfo> missionInfos;
2548     u16string deviceId = Str8ToStr16(DEVICE_ID);
2549     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2550     {
2551         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2552         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2553     }
2554     {
2555         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2556         ListenerInfo listenerInfo;
2557         listenerInfo.Emplace(listener);
2558         listenerInfo.called = true;
2559         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2560     }
2561     DistributedSchedMissionManager::GetInstance().missionHandler_ = nullptr;
2562     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedFromRemote(callerInfo, missionInfos);
2563     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2564     DTEST_LOG << "testNotifyMissionsChangedFromRemote003 end" << std::endl;
2565 }
2566 
2567 /**
2568  * @tc.name: testNotifyMissionsChangedToRemote002
2569  * @tc.desc: notify missions changed to remote
2570  * @tc.type: FUNC
2571  */
2572 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedToRemote002, TestSize.Level3)
2573 {
2574     DTEST_LOG << "testNotifyMissionsChangedToRemote002 begin" << std::endl;
2575     {
2576         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2577         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.clear();
2578     }
2579     std::vector<DstbMissionInfo> missionInfos;
2580     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemote(missionInfos);
2581     EXPECT_EQ(ret, ERR_NONE);
2582     DTEST_LOG << "testNotifyMissionsChangedToRemote002 end" << std::endl;
2583 }
2584 
2585 /**
2586  * @tc.name: testNotifyMissionsChangedToRemote003
2587  * @tc.desc: notify missions changed to remote
2588  * @tc.type: FUNC
2589  */
2590 HWTEST_F(DMSMissionManagerTest, testNotifyMissionsChangedToRemote003, TestSize.Level3)
2591 {
2592     DTEST_LOG << "testNotifyMissionsChangedToRemote003 begin" << std::endl;
2593     {
2594         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2595         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.clear();
2596     }
2597     {
2598         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteSyncDeviceLock_);
2599         DistributedSchedMissionManager::GetInstance().remoteSyncDeviceSet_.emplace(localDeviceId_);
2600     }
2601     {
2602         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2603         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
2604     }
2605     int32_t deviceType = 0;
2606     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
2607         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
2608     {
2609         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2610         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[localDeviceId_] = dmsDeviceInfo;
2611     }
2612     std::string uuid = "uuid for GetUuidByNetworkId";
2613     {
2614         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2615         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2616     }
2617     {
2618         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2619         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = localDeviceId_;
2620     }
2621     std::vector<DstbMissionInfo> missionInfos;
2622     auto ret = DistributedSchedMissionManager::GetInstance().NotifyMissionsChangedToRemote(missionInfos);
2623     EXPECT_EQ(ret, ERR_NONE);
2624     DTEST_LOG << "testNotifyMissionsChangedToRemote003 end" << std::endl;
2625 }
2626 
2627 /**
2628  * @tc.name: testFetchDeviceHandler003
2629  * @tc.desc: fetch device handler
2630  * @tc.type: FUNC
2631  */
2632 HWTEST_F(DMSMissionManagerTest, testFetchDeviceHandler003, TestSize.Level3)
2633 {
2634     DTEST_LOG << "testFetchDeviceHandler003 begin" << std::endl;
2635     {
2636         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2637         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
2638     }
2639 
2640     int32_t deviceType = 0;
2641     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
2642         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
2643     {
2644         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2645         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
2646     }
2647     auto ret = DistributedSchedMissionManager::GetInstance().FetchDeviceHandler(DEVICE_ID);
2648     EXPECT_EQ(ret, nullptr);
2649     DTEST_LOG << "testFetchDeviceHandler003 end" << std::endl;
2650 }
2651 
2652 /**
2653  * @tc.name: testFetchDeviceHandler004
2654  * @tc.desc: fetch device handler
2655  * @tc.type: FUNC
2656  */
2657 HWTEST_F(DMSMissionManagerTest, testFetchDeviceHandler004, TestSize.Level3)
2658 {
2659     DTEST_LOG << "testFetchDeviceHandler004 begin" << std::endl;
2660     {
2661         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2662         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
2663     }
2664     int32_t deviceType = 0;
2665     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
2666         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
2667     {
2668         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2669         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
2670     }
2671 
2672     std::string uuid = "uuid for GetUuidByNetworkId";
2673     {
2674         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2675         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2676     }
2677     {
2678         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2679         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2680     }
2681     auto ret = DistributedSchedMissionManager::GetInstance().FetchDeviceHandler(DEVICE_ID);
2682     EXPECT_NE(ret, nullptr);
2683     DTEST_LOG << "testFetchDeviceHandler004 end" << std::endl;
2684 }
2685 
2686 /**
2687  * @tc.name: testFetchDeviceHandler005
2688  * @tc.desc: fetch device handler
2689  * @tc.type: FUNC
2690  */
2691 HWTEST_F(DMSMissionManagerTest, testFetchDeviceHandler005, TestSize.Level3)
2692 {
2693     DTEST_LOG << "testFetchDeviceHandler005 begin" << std::endl;
2694     DistributedSchedMissionManager::GetInstance().isRegMissionChange_ = false;
2695     DistributedSchedMissionManager::GetInstance().NotifyDmsProxyProcessDied();
2696     {
2697         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2698         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
2699     }
2700     int32_t deviceType = 0;
2701     std::shared_ptr<DmsDeviceInfo> dmsDeviceInfo =
2702         make_shared<DmsDeviceInfo>(DEVICE_NAME, deviceType, DEVICE_ID);
2703     {
2704         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().deviceLock_);
2705         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[DEVICE_ID] = dmsDeviceInfo;
2706     }
2707 
2708     std::string uuid = "uuid for GetUuidByNetworkId";
2709     {
2710         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2711         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_.clear();
2712     }
2713     {
2714         lock_guard<mutex> autoLock(DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdLock_);
2715         DtbschedmgrDeviceInfoStorage::GetInstance().uuidNetworkIdMap_[uuid] = DEVICE_ID;
2716     }
2717     auto anonyUuid = GetAnonymStr(uuid);
2718     auto runner = AppExecFwk::EventRunner::Create(anonyUuid + "_MissionN");
2719     auto handler = std::make_shared<AppExecFwk::EventHandler>(runner);
2720     DistributedSchedMissionManager::GetInstance().deviceHandle_.emplace(uuid, handler);
2721     auto ret = DistributedSchedMissionManager::GetInstance().FetchDeviceHandler(DEVICE_ID);
2722     EXPECT_NE(ret, nullptr);
2723     DTEST_LOG << "testFetchDeviceHandler005 end" << std::endl;
2724 }
2725 
2726 /**
2727  * @tc.name: testRetryStartSyncRemoteMissions004
2728  * @tc.desc: retry start sync remote missions
2729  * @tc.type: FUNC
2730  */
2731 HWTEST_F(DMSMissionManagerTest, testRetryStartSyncRemoteMissions004, TestSize.Level3)
2732 {
2733     DTEST_LOG << "testRetryStartSyncRemoteMissions004 begin" << std::endl;
2734     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2735     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2736     u16string deviceId = Str8ToStr16(DEVICE_ID);
2737     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2738     {
2739         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2740         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2741     }
2742     {
2743         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2744         ListenerInfo listenerInfo;
2745         listenerInfo.Emplace(listener);
2746         listenerInfo.called = true;
2747         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2748     }
2749     DistributedSchedMissionManager::GetInstance().RetryStartSyncRemoteMissions(DEVICE_ID, localDeviceId_, 1);
2750     EXPECT_NE(DistributedSchedMissionManager::GetInstance().missionHandler_, nullptr);
2751     DTEST_LOG << "testRetryStartSyncRemoteMissions004 end" << std::endl;
2752 }
2753 
2754 /**
2755  * @tc.name: testRetryStartSyncRemoteMissions005
2756  * @tc.desc: retry start sync remote missions
2757  * @tc.type: FUNC
2758  */
2759 HWTEST_F(DMSMissionManagerTest, testRetryStartSyncRemoteMissions005, TestSize.Level3)
2760 {
2761     DTEST_LOG << "testRetryStartSyncRemoteMissions005 begin" << std::endl;
2762     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2763     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2764     u16string deviceId = Str8ToStr16(DEVICE_ID);
2765     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2766     {
2767         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2768         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2769     }
2770     {
2771         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2772         ListenerInfo listenerInfo;
2773         listenerInfo.Emplace(listener);
2774         listenerInfo.called = true;
2775         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2776     }
2777     sptr<IDistributedSched> proxy = GetDms();
2778     ASSERT_NE(nullptr, proxy);
2779     {
2780         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2781         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2782     }
2783     {
2784         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2785         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
2786     }
2787     DistributedSchedMissionManager::GetInstance().RetryStartSyncRemoteMissions(DEVICE_ID, localDeviceId_, 1);
2788     EXPECT_NE(DistributedSchedMissionManager::GetInstance().missionHandler_, nullptr);
2789     DTEST_LOG << "testRetryStartSyncRemoteMissions005 end" << std::endl;
2790 }
2791 
2792 /**
2793  * @tc.name: testOnMissionListenerDied003
2794  * @tc.desc: on mission listener died
2795  * @tc.type: FUNC
2796  */
2797 HWTEST_F(DMSMissionManagerTest, testOnMissionListenerDied003, TestSize.Level3)
2798 {
2799     DTEST_LOG << "testOnMissionListenerDied003 begin" << std::endl;
2800     u16string deviceId = Str8ToStr16(DEVICE_ID);
2801     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2802     {
2803         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2804         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2805     }
2806     {
2807         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2808         ListenerInfo listenerInfo;
2809         listenerInfo.Emplace(listener);
2810         listenerInfo.called = true;
2811         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2812     }
2813     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(listener);
2814     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().listenDeviceMap_.empty(), true);
2815     DTEST_LOG << "testOnMissionListenerDied003 end" << std::endl;
2816 }
2817 
2818 /**
2819  * @tc.name: testOnMissionListenerDied004
2820  * @tc.desc: on mission listener died
2821  * @tc.type: FUNC
2822  */
2823 HWTEST_F(DMSMissionManagerTest, testOnMissionListenerDied004, TestSize.Level3)
2824 {
2825     DTEST_LOG << "testOnMissionListenerDied004 begin" << std::endl;
2826     u16string deviceId = Str8ToStr16(DEVICE_ID);
2827     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2828     {
2829         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2830         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2831     }
2832     sptr<IRemoteObject> remote = sptr<IRemoteObject>();
2833     {
2834         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2835         ListenerInfo listenerInfo;
2836         listenerInfo.Emplace(listener);
2837         listenerInfo.called = true;
2838         listenerInfo.Emplace(remote);
2839         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2840     }
2841     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(listener);
2842     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().listenDeviceMap_.empty(), false);
2843     DTEST_LOG << "testOnMissionListenerDied004 end" << std::endl;
2844 }
2845 
2846 /**
2847  * @tc.name: testOnMissionListenerDied005
2848  * @tc.desc: on mission listener died
2849  * @tc.type: FUNC
2850  */
2851 HWTEST_F(DMSMissionManagerTest, testOnMissionListenerDied005, TestSize.Level3)
2852 {
2853     DTEST_LOG << "testOnMissionListenerDied005 begin" << std::endl;
2854     u16string deviceId = Str8ToStr16(DEVICE_ID);
2855     sptr<IRemoteObject> listener(new RemoteMissionListenerTest());
2856     {
2857         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2858         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2859     }
2860     {
2861         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2862         ListenerInfo listenerInfo;
2863         listenerInfo.Emplace(listener);
2864         listenerInfo.called = false;
2865         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2866     }
2867     DistributedSchedMissionManager::GetInstance().OnMissionListenerDied(listener);
2868     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().listenDeviceMap_.empty(), true);
2869     DTEST_LOG << "testOnMissionListenerDied005 end" << std::endl;
2870 }
2871 
2872 /**
2873  * @tc.name: testOnRemoteDmsDied006
2874  * @tc.desc: on remote dms died
2875  * @tc.type: FUNC
2876  */
2877 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied006, TestSize.Level3)
2878 {
2879     DTEST_LOG << "testOnRemoteDmsDied006 begin" << std::endl;
2880     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2881     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2882     sptr<IRemoteObject> remote(new RemoteMissionListenerTest());
2883     sptr<IDistributedSched> remoteDmsObj(new DistributedSchedProxy(remote));
2884     {
2885         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2886         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2887     }
2888     {
2889         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2890         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = remoteDmsObj;
2891     }
2892     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
2893     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().listenDeviceMap_.empty(), true);
2894     DTEST_LOG << "testOnRemoteDmsDied006 end" << std::endl;
2895 }
2896 
2897 /**
2898  * @tc.name: testOnRemoteDmsDied007
2899  * @tc.desc: on remote dms died
2900  * @tc.type: FUNC
2901  */
2902 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied007, TestSize.Level3)
2903 {
2904     DTEST_LOG << "testOnRemoteDmsDied007 begin" << std::endl;
2905     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2906     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2907     sptr<IRemoteObject> remote(new RemoteMissionListenerTest());
2908     sptr<IDistributedSched> proxy = GetDms();
2909     ASSERT_NE(nullptr, proxy);
2910     {
2911         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2912         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2913     }
2914     {
2915         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2916         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = proxy;
2917     }
2918     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
2919     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().listenDeviceMap_.empty(), true);
2920     DTEST_LOG << "testOnRemoteDmsDied007 end" << std::endl;
2921 }
2922 
2923 /**
2924  * @tc.name: testOnRemoteDmsDied008
2925  * @tc.desc: on remote dms died
2926  * @tc.type: FUNC
2927  */
2928 HWTEST_F(DMSMissionManagerTest, testOnRemoteDmsDied008, TestSize.Level3)
2929 {
2930     DTEST_LOG << "testOnRemoteDmsDied008 begin" << std::endl;
2931     auto runner = AppExecFwk::EventRunner::Create("MissionManagerHandler");
2932     DistributedSchedMissionManager::GetInstance().missionHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
2933     sptr<IRemoteObject> remote(new RemoteMissionListenerTest());
2934     sptr<IDistributedSched> remoteDmsObj(new DistributedSchedProxy(remote));
2935     {
2936         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2937         DistributedSchedMissionManager::GetInstance().remoteDmsMap_.clear();
2938     }
2939     {
2940         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().remoteDmsLock_);
2941         DistributedSchedMissionManager::GetInstance().remoteDmsMap_[DEVICE_ID] = remoteDmsObj;
2942     }
2943     u16string deviceId = Str8ToStr16(DEVICE_ID);
2944     {
2945         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2946         DistributedSchedMissionManager::GetInstance().listenDeviceMap_.clear();
2947     }
2948     {
2949         std::lock_guard<std::mutex> autoLock(DistributedSchedMissionManager::GetInstance().listenDeviceLock_);
2950         ListenerInfo listenerInfo;
2951         listenerInfo.Emplace(remote);
2952         listenerInfo.called = true;
2953         DistributedSchedMissionManager::GetInstance().listenDeviceMap_[deviceId] = listenerInfo;
2954     }
2955     DistributedSchedMissionManager::GetInstance().OnRemoteDmsDied(remote);
2956     EXPECT_EQ(DistributedSchedMissionManager::GetInstance().listenDeviceMap_.empty(), false);
2957     DTEST_LOG << "testOnRemoteDmsDied008 end" << std::endl;
2958 }
2959 } // namespace DistributedSchedule
2960 } // namespace OHOS
2961