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