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