1 /*
2 * Copyright (c) 2021 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 "distributed_sched_proxy.h"
19 #include "distributed_sched_service.h"
20 #include "dtbschedmgr_device_info_storage.h"
21 #include "if_system_ability_manager.h"
22 #include "ipc_skeleton.h"
23 #include "iservice_registry.h"
24 #include "mission/mission_constant.h"
25 #include "string_ex.h"
26 #include "system_ability_definition.h"
27 #include "test_log.h"
28
29 #define private public
30 #include "mission/distributed_sched_mission_manager.h"
31
32 using namespace std;
33 using namespace testing;
34 using namespace testing::ext;
35
36 namespace OHOS {
37 namespace DistributedSchedule {
38 namespace {
39 const std::string DEVICE_NAME = "DEVICE_PHONE_001";
40 const std::string DEVICE_ID = "123456789ABCD";
41 const std::u16string U16DEVICE_ID = u"123456789ABCD";
42 const std::string BUNDLE_NAME = "ohos.test.test";
43 const int32_t NUM_MISSIONS = 100;
44 }
SetUpTestCase()45 void DMSMissionManagerTest::SetUpTestCase()
46 {
47 }
48
TearDownTestCase()49 void DMSMissionManagerTest::TearDownTestCase()
50 {
51 }
52
SetUp()53 void DMSMissionManagerTest::SetUp()
54 {
55 string localDeviceId;
56 if (!DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId)) {
57 DTEST_LOG << "getLocalDevicesId failed!" << std::endl;
58 return;
59 }
60 localDeviceId_ = localDeviceId;
61 u16localDeviceId_ = Str8ToStr16(localDeviceId);
62 }
63
TearDown()64 void DMSMissionManagerTest::TearDown()
65 {
66 }
67
GetDms()68 sptr<IDistributedSched> DMSMissionManagerTest::GetDms()
69 {
70 if (proxy_ != nullptr) {
71 return proxy_;
72 }
73 auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
74 EXPECT_TRUE(sm != nullptr);
75 if (sm == nullptr) {
76 DTEST_LOG << "DMSMissionManagerTest sm is nullptr" << std::endl;
77 return nullptr;
78 }
79 DTEST_LOG << "DMSMissionManagerTest sm is not nullptr" << std::endl;
80 auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
81 EXPECT_TRUE(distributedObject != nullptr);
82 proxy_ = iface_cast<IDistributedSched>(distributedObject);
83 if (proxy_ == nullptr) {
84 DTEST_LOG << "DMSMissionManagerTest DistributedSched is nullptr" << std::endl;
85 }
86 DTEST_LOG << "DMSMissionManagerTest DistributedSched is not nullptr" << std::endl;
87 return proxy_;
88 }
89
NotifyMissionsChanged(const std::string & deviceId)90 void RemoteMissionListenerTest::NotifyMissionsChanged(const std::string& deviceId)
91 {
92 DTEST_LOG << "NotifyMissionsChanged" << std::endl;
93 }
94
NotifySnapshot(const std::string & deviceId,int32_t missionId)95 void RemoteMissionListenerTest::NotifySnapshot(const std::string& deviceId, int32_t missionId)
96 {
97 DTEST_LOG << "NotifySnapshot" << std::endl;
98 }
99
NotifyNetDisconnect(const std::string & deviceId,int32_t state)100 void RemoteMissionListenerTest::NotifyNetDisconnect(const std::string& deviceId, int32_t state)
101 {
102 DTEST_LOG << "NotifyNetDisconnect" << std::endl;
103 }
104
105 /**
106 * @tc.name: testGetRemoteMissionInfo001
107 * @tc.desc: get remote mission info
108 * @tc.type: FUNC
109 * @tc.require:AR000GK66R
110 */
111 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo001, TestSize.Level1)
112 {
113 std::vector<AAFwk::MissionInfo> infos;
114 auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, 0, infos);
115 EXPECT_TRUE(ret != ERR_NONE);
116
117 ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(localDeviceId_, 0, infos);
118 EXPECT_TRUE(ret != ERR_NONE);
119
120 ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos("", 0, infos);
121 EXPECT_TRUE(ret != ERR_NONE);
122
123 ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, -1, infos);
124 EXPECT_TRUE(ret != ERR_NONE);
125
126 ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(localDeviceId_, -1, infos);
127 EXPECT_TRUE(ret != ERR_NONE);
128 }
129
130 /**
131 * @tc.name: testGetRemoteMissionInfo002
132 * @tc.desc: get remote mission info
133 * @tc.type: FUNC
134 * @tc.require:AR000GK66R
135 */
136 HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo002, TestSize.Level1)
137 {
138 sptr<IDistributedSched> proxy = GetDms();
139 if (proxy == nullptr) {
140 return;
141 }
142 std::vector<AAFwk::MissionInfo> infos;
143 auto ret = proxy->GetMissionInfos(DEVICE_ID, 0, infos);
144 EXPECT_TRUE(ret != ERR_NONE);
145
146 ret = proxy->GetMissionInfos(localDeviceId_, 0, infos);
147 EXPECT_TRUE(ret != ERR_NONE);
148
149 ret = proxy->GetMissionInfos("", 0, infos);
150 EXPECT_TRUE(ret != ERR_NONE);
151
152 ret = proxy->GetMissionInfos(DEVICE_ID, -1, infos);
153 EXPECT_TRUE(ret != ERR_NONE);
154
155 ret = proxy->GetMissionInfos(localDeviceId_, -1, infos);
156 EXPECT_TRUE(ret != ERR_NONE);
157 }
158
159 /**
160 * @tc.name: testStartSyncRemoteMissions001
161 * @tc.desc: prepare and sync missions from remote
162 * @tc.type: FUNC
163 * @tc.require:AR000GK67A
164 */
165 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions001, TestSize.Level1)
166 {
167 sptr<IDistributedSched> proxy = GetDms();
168 if (proxy == nullptr) {
169 return;
170 }
171 auto ret = proxy->StartSyncRemoteMissions(DEVICE_ID, false, 0);
172 EXPECT_TRUE(ret != ERR_NONE);
173 }
174
175 /**
176 * @tc.name: testStartSyncRemoteMissions002
177 * @tc.desc: prepare and sync missions from remote
178 * @tc.type: FUNC
179 * @tc.require:SR000GK679
180 */
181 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions002, TestSize.Level1)
182 {
183 sptr<IDistributedSched> proxy = GetDms();
184 if (proxy == nullptr) {
185 return;
186 }
187 auto ret = proxy->StartSyncRemoteMissions("", false, 0);
188 EXPECT_TRUE(ret != ERR_NONE);
189 }
190
191 /**
192 * @tc.name: testStartSyncRemoteMissions003
193 * @tc.desc: prepare and sync missions from remote
194 * @tc.type: FUNC
195 * @tc.require:AR000GK67A
196 */
197 HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions003, TestSize.Level1)
198 {
199 sptr<IDistributedSched> proxy = GetDms();
200 if (proxy == nullptr) {
201 return;
202 }
203 auto ret = proxy->StartSyncRemoteMissions(localDeviceId_, false, 0);
204 EXPECT_TRUE(ret != ERR_NONE);
205 }
206
207 /**
208 * @tc.name: testStopSyncRemoteMissions001
209 * @tc.desc: stop sync missions from remote with fake deviceId
210 * @tc.type: FUNC
211 * @tc.require:AR000GK672
212 */
213 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions001, TestSize.Level1)
214 {
215 sptr<IDistributedSched> proxy = GetDms();
216 if (proxy == nullptr) {
217 return;
218 }
219 auto ret = proxy->StopSyncRemoteMissions(DEVICE_ID);
220 EXPECT_TRUE(ret != ERR_NONE);
221 }
222
223 /**
224 * @tc.name: testStopSyncRemoteMissions002
225 * @tc.desc: stop sync missions from remote with local deviceId
226 * @tc.type: FUNC
227 * @tc.require:SR000GK671
228 */
229 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions002, TestSize.Level1)
230 {
231 sptr<IDistributedSched> proxy = GetDms();
232 if (proxy == nullptr) {
233 return;
234 }
235 auto ret = proxy->StopSyncRemoteMissions(localDeviceId_);
236 EXPECT_TRUE(ret != ERR_NONE);
237 }
238
239 /**
240 * @tc.name: testStopSyncRemoteMissions003
241 * @tc.desc: stop sync missions from remote with empty deviceId
242 * @tc.type: FUNC
243 * @tc.require:SR000GK671
244 */
245 HWTEST_F(DMSMissionManagerTest, testStopSyncRemoteMissions003, TestSize.Level1)
246 {
247 sptr<IDistributedSched> proxy = GetDms();
248 if (proxy == nullptr) {
249 return;
250 }
251 auto ret = proxy->StopSyncRemoteMissions("");
252 EXPECT_TRUE(ret != ERR_NONE);
253 }
254
255 /**
256 * @tc.name: testRegisterMissionListener001
257 * @tc.desc: register mission listener
258 * @tc.type: FUNC
259 * @tc.require:AR000GK5N7
260 */
261 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener001, TestSize.Level1)
262 {
263 sptr<IDistributedSched> proxy = GetDms();
264 if (proxy == nullptr) {
265 return;
266 }
267 auto ret = proxy->RegisterMissionListener(U16DEVICE_ID, nullptr);
268 EXPECT_TRUE(ret != ERR_NONE);
269
270 ret = proxy->RegisterMissionListener(u16localDeviceId_, nullptr);
271 EXPECT_TRUE(ret != ERR_NONE);
272
273 ret = proxy->RegisterMissionListener(u"", nullptr);
274 EXPECT_TRUE(ret != ERR_NONE);
275 }
276
277 /**
278 * @tc.name: testRegisterMissionListener002
279 * @tc.desc: register mission listener
280 * @tc.type: FUNC
281 * @tc.require:SR000GK5N6
282 */
283 HWTEST_F(DMSMissionManagerTest, testRegisterMissionListener002, TestSize.Level1)
284 {
285 sptr<IDistributedSched> proxy = GetDms();
286 if (proxy == nullptr) {
287 return;
288 }
289 sptr<IRemoteObject> listener = new RemoteMissionListenerTest();
290 auto ret = proxy->RegisterMissionListener(U16DEVICE_ID, listener);
291 EXPECT_TRUE(ret != ERR_NONE);
292
293 ret = proxy->RegisterMissionListener(u16localDeviceId_, listener);
294 EXPECT_TRUE(ret != ERR_NONE);
295
296 ret = proxy->RegisterMissionListener(u"", listener);
297 EXPECT_TRUE(ret != ERR_NONE);
298
299 ret = proxy->UnRegisterMissionListener(U16DEVICE_ID, listener);
300 EXPECT_TRUE(ret == ERR_NONE);
301
302 ret = proxy->UnRegisterMissionListener(u16localDeviceId_, listener);
303 EXPECT_TRUE(ret != ERR_NONE);
304
305 ret = proxy->UnRegisterMissionListener(u"", listener);
306 EXPECT_TRUE(ret != ERR_NONE);
307 }
308
309 /**
310 * @tc.name: testUnRegisterMissionListener001
311 * @tc.desc: register mission listener
312 * @tc.type: FUNC
313 * @tc.require:AR000GK5N7
314 */
315 HWTEST_F(DMSMissionManagerTest, testUnRegisterMissionListener001, TestSize.Level1)
316 {
317 sptr<IDistributedSched> proxy = GetDms();
318 if (proxy == nullptr) {
319 return;
320 }
321 auto ret = proxy->UnRegisterMissionListener(U16DEVICE_ID, nullptr);
322 EXPECT_TRUE(ret != ERR_NONE);
323
324 ret = proxy->UnRegisterMissionListener(u16localDeviceId_, nullptr);
325 EXPECT_TRUE(ret != ERR_NONE);
326
327 ret = proxy->UnRegisterMissionListener(u"", nullptr);
328 EXPECT_TRUE(ret != ERR_NONE);
329 }
330
331 /**
332 * @tc.name: testIsDeviceIdValidated001
333 * @tc.desc: judging whether the deviceId is valid
334 * @tc.type: FUNC
335 * @tc.require:AR000GK66R
336 */
337 HWTEST_F(DMSMissionManagerTest, testIsDeviceIdValidated001, TestSize.Level1)
338 {
339 std::string emptyDeviceId = "";
340 auto ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(emptyDeviceId);
341 EXPECT_FALSE(ret);
342
343 ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(DEVICE_ID);
344 EXPECT_FALSE(ret);
345
346 ret = DistributedSchedMissionManager::GetInstance().IsDeviceIdValidated(localDeviceId_);
347 EXPECT_FALSE(ret);
348 }
349
350 /**
351 * @tc.name: testGetMissionInfos003
352 * @tc.desc: get remote missions
353 * @tc.type: FUNC
354 * @tc.require:AR000GK67M
355 */
356 HWTEST_F(DMSMissionManagerTest, testGetMissionInfos001, TestSize.Level1)
357 {
358 std::string deviceid = DEVICE_ID;
359 int32_t numMissions = NUM_MISSIONS;
360 std::vector<AAFwk::MissionInfo> missionInfos;
361
362 auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
363 EXPECT_TRUE(ret != ERR_NONE);
364 }
365
366 /**
367 * @tc.name: testFetchCachedRemoteMissions001
368 * @tc.desc: test stop fake device, return error code
369 * @tc.type: FUNC
370 * @tc.require:AR000GK67M
371 */
372 HWTEST_F(DMSMissionManagerTest, testFetchCachedRemoteMissions001, TestSize.Level1)
373 {
374 std::vector<DstbMissionInfo> infos;
375 auto ret = DistributedSchedMissionManager::GetInstance().FetchCachedRemoteMissions(DEVICE_ID, 0, infos);
376 EXPECT_TRUE(ret != ERR_NONE);
377 }
378
379 /**
380 * @tc.name: testFetchCachedRemoteMissions001
381 * @tc.desc: test check support osd fake device, return error code
382 * @tc.type: FUNC
383 * @tc.require:AR000GK67M
384 */
385 HWTEST_F(DMSMissionManagerTest, testCheckSupportOsd001, TestSize.Level1)
386 {
387 auto ret = DistributedSchedMissionManager::GetInstance().CheckSupportOsd(DEVICE_ID);
388 EXPECT_TRUE(ret != ERR_NONE);
389 }
390
391 /**
392 * @tc.name: testFetchCachedRemoteMissions002
393 * @tc.desc: test check support osd fake device, return error code
394 * @tc.type: FUNC
395 * @tc.require:AR000GK67M
396 */
397 HWTEST_F(DMSMissionManagerTest, testCheckSupportOsd002, TestSize.Level1)
398 {
399 auto ret = DistributedSchedMissionManager::GetInstance().CheckSupportOsd(DEVICE_ID);
400 EXPECT_TRUE(ret != ERR_NONE);
401 ret = DistributedSchedMissionManager::GetInstance().CheckSupportOsd("");
402 EXPECT_TRUE(ret != ERR_NONE);
403 }
404
405 /**
406 * @tc.name: GetOsdSwitchValueFromRemote001
407 * @tc.desc: test GetOsdSwitchValueFromRemote, return error code
408 * @tc.type: FUNC
409 * @tc.require:AR000GK67M
410 */
411 HWTEST_F(DMSMissionManagerTest, GetOsdSwitchValueFromRemote001, TestSize.Level1)
412 {
413 auto ret = DistributedSchedMissionManager::GetInstance().GetOsdSwitchValueFromRemote();
414 EXPECT_TRUE(ret != ERR_NONE);
415 }
416
417 /**
418 * @tc.name: testUpdateOsdSwitchValueFromRemote001
419 * @tc.desc: test UpdateOsdSwitchValueFromRemote fake device, return error code
420 * @tc.type: FUNC
421 * @tc.require:AR000GK67M
422 */
423 HWTEST_F(DMSMissionManagerTest, testUpdateOsdSwitchValueFromRemote001, TestSize.Level1)
424 {
425 auto ret = DistributedSchedMissionManager::GetInstance().UpdateOsdSwitchValueFromRemote(0, DEVICE_ID);
426 EXPECT_TRUE(ret == ERR_NONE);
427 }
428
429 /**
430 * @tc.name: testUpdateOsdSwitchValueFromRemote002
431 * @tc.desc: test UpdateOsdSwitchValueFromRemote fake device, return error code
432 * @tc.type: FUNC
433 * @tc.require:AR000GK67M
434 */
435 HWTEST_F(DMSMissionManagerTest, testUpdateOsdSwitchValueFromRemote002, TestSize.Level1)
436 {
437 auto ret = DistributedSchedMissionManager::GetInstance().UpdateOsdSwitchValueFromRemote(0, DEVICE_ID);
438 EXPECT_TRUE(ret == ERR_NONE);
439 ret = DistributedSchedMissionManager::GetInstance().UpdateOsdSwitchValueFromRemote(1, DEVICE_ID);
440 EXPECT_TRUE(ret == ERR_NONE);
441 }
442
443 /**
444 * @tc.name: testUpdateOsdSwitchValueFromRemote003
445 * @tc.desc: test UpdateOsdSwitchValueFromRemote fake device, return error code
446 * @tc.type: FUNC
447 * @tc.require:AR000GK67M
448 */
449 HWTEST_F(DMSMissionManagerTest, testUpdateOsdSwitchValueFromRemote003, TestSize.Level1)
450 {
451 auto ret = DistributedSchedMissionManager::GetInstance().UpdateOsdSwitchValueFromRemote(0, "");
452 EXPECT_TRUE(ret == ERR_NONE);
453 ret = DistributedSchedMissionManager::GetInstance().UpdateOsdSwitchValueFromRemote(1, "");
454 EXPECT_TRUE(ret == ERR_NONE);
455 }
456
457 /**
458 * @tc.name: testUpdateSwitchValueToRemote001
459 * @tc.desc: test UpdateSwitchValueToRemote, return error code
460 * @tc.type: FUNC
461 * @tc.require:AR000GK67M
462 */
463 HWTEST_F(DMSMissionManagerTest, testUpdateSwitchValueToRemote001, TestSize.Level1)
464 {
465 auto ret = DistributedSchedMissionManager::GetInstance().UpdateSwitchValueToRemote();
466 EXPECT_TRUE(ret != ERR_NONE);
467 }
468
469 /**
470 * @tc.name: testUpdateSwitchValueToRemote002
471 * @tc.desc: test check support osd fake device, return error code
472 * @tc.type: FUNC
473 * @tc.require:AR000GK67M
474 */
475 HWTEST_F(DMSMissionManagerTest, testUpdateSwitchValueToRemote002, TestSize.Level1)
476 {
477 auto ret = DistributedSchedMissionManager::GetInstance().UpdateSwitchValueToRemote();
478 EXPECT_TRUE(ret != ERR_NONE);
479 ret = DistributedSchedMissionManager::GetInstance().UpdateSwitchValueToRemote();
480 EXPECT_TRUE(ret != ERR_NONE);
481 }
482 } // namespace DistributedSchedule
483 } // namespace OHOS
484