• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "dms_continue_manager_test.h"
17 
18 #include "datetime_ex.h"
19 #include "distributed_sched_util.h"
20 #include "dtbschedmgr_log.h"
21 #define private public
22 #include "mission/dms_continue_send_manager.h"
23 #include "mission/dms_continue_recv_manager.h"
24 #undef private
25 #include "test_log.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace DistributedSchedule {
32 namespace {
33 const std::string TYPE = "type";
34 const std::string BUNDLENAME_01 = "bundleName01";
35 const std::string BUNDLENAME_02 = "bundleName02";
36 const std::string NETWORKID_01 = "networkId01";
37 const std::string NETWORKID_02 = "networkId02";
38 const std::string CANCEL_FOCUSED_TASK = "cancel_mission_focused_task";
39 constexpr static int32_t DMS_SEND_LEN = 5;
40 constexpr static uint8_t DMS_0X0F = 0x0f;
41 constexpr int32_t MISSIONID_01 = 1;
42 constexpr int32_t MISSIONID_02 = 2;
43 constexpr int32_t ACTIVE = 0;
44 constexpr int32_t INACTIVE = 1;
45 constexpr int32_t CANCEL_FOCUSED_DELAYED = 10000;
46 }
47 
SetUpTestCase()48 void DMSContinueManagerTest::SetUpTestCase()
49 {
50 }
51 
TearDownTestCase()52 void DMSContinueManagerTest::TearDownTestCase()
53 {
54 }
55 
SetUp()56 void DMSContinueManagerTest::SetUp()
57 {
58 }
59 
TearDown()60 void DMSContinueManagerTest::TearDown()
61 {
62 }
63 
OnCallback(const uint32_t ContinueState,const std::string & srcDeviceId,const std::string & bundleName)64 void RemoteOnListenerStubTest::OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId,
65     const std::string& bundleName)
66 {
67 }
68 
69 /**
70  * @tc.name: testUnInit001
71  * @tc.desc: test UnInit
72  * @tc.type: FUNC
73  * @tc.require: I7F8KH
74  */
75 HWTEST_F(DMSContinueManagerTest, testUnInit001, TestSize.Level3)
76 {
77     DTEST_LOG << "DMSContinueManagerTest testUnInit001 begin" << std::endl;
78 
79     DistributedSchedUtil::MockManageMissions();
80     DMSContinueSendMgr::GetInstance().Init();
81     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
82 
83     /**
84      * @tc.steps: step1. test UnInit when eventHandler is not nullptr;
85      */
86     DMSContinueSendMgr::GetInstance().UnInit();
87     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
88 
89     /**
90      * @tc.steps: step2. test UnInit when eventHandler is nullptr;
91      */
92     DMSContinueSendMgr::GetInstance().UnInit();
93     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
94 
95     DTEST_LOG << "DMSContinueManagerTest testUnInit001 end" << std::endl;
96 }
97 
98 /**
99  * @tc.name: testPostUnfocusedTaskWithDelay001
100  * @tc.desc: test PostUnfocusedTaskWithDelay
101  * @tc.type: FUNC
102  */
103 HWTEST_F(DMSContinueManagerTest, testPostUnfocusedTaskWithDelay001, TestSize.Level3)
104 {
105     DTEST_LOG << "DMSContinueManagerTest testPostUnfocusedTaskWithDelay001 begin" << std::endl;
106 
107     DistributedSchedUtil::MockManageMissions();
108     DMSContinueSendMgr::GetInstance().Init();
109 
110     /**
111      * @tc.steps: step1. test PostUnfocusedTaskWithDelay when eventHandler is not nullptr;
112      */
113     DMSContinueSendMgr::GetInstance().PostUnfocusedTaskWithDelay(0, UnfocusedReason::TIMEOUT);
114     DMSContinueSendMgr::GetInstance().PostUnfocusedTaskWithDelay(0, UnfocusedReason::SCREENOFF);
115     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
116 
117     /**
118      * @tc.steps: step2. test PostUnfocusedTaskWithDelay when eventHandler is nullptr;
119      */
120     DMSContinueSendMgr::GetInstance().UnInit();
121     DMSContinueSendMgr::GetInstance().PostUnfocusedTaskWithDelay(0, UnfocusedReason::TIMEOUT);
122     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
123     DTEST_LOG << "DMSContinueManagerTest testPostUnfocusedTaskWithDelay001 end" << std::endl;
124 }
125 
126 /**
127  * @tc.name: testNotifyMissionFocused001
128  * @tc.desc: test NotifyMissionFocused
129  * @tc.type: FUNC
130  * @tc.require: I7F8KH
131  */
132 HWTEST_F(DMSContinueManagerTest, testNotifyMissionFocused001, TestSize.Level3)
133 {
134     DTEST_LOG << "DMSContinueManagerTest testNotifyMissionFocused001 begin" << std::endl;
135 
136     DistributedSchedUtil::MockManageMissions();
137     DMSContinueSendMgr::GetInstance().Init();
138 
139     /**
140      * @tc.steps: step1. test NotifyMissionFocused when eventHandler is not nullptr;
141      */
142     DMSContinueSendMgr::GetInstance().NotifyMissionFocused(0, FocusedReason::NORMAL);
143     DMSContinueSendMgr::GetInstance().NotifyMissionFocused(0, FocusedReason::SCREENOFF);
144     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
145 
146     /**
147      * @tc.steps: step2. test NotifyMissionFocused when eventHandler is nullptr;
148      */
149     DMSContinueSendMgr::GetInstance().UnInit();
150     DMSContinueSendMgr::GetInstance().NotifyMissionFocused(0, FocusedReason::NORMAL);
151     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
152     DTEST_LOG << "DMSContinueManagerTest testNotifyMissionFocused001 end" << std::endl;
153 }
154 
155 /**
156  * @tc.name: testNotifyMissionUnfocused001
157  * @tc.desc: test NotifyMissionUnfocused
158  * @tc.type: FUNC
159  * @tc.require: I7F8KH
160  */
161 HWTEST_F(DMSContinueManagerTest, testNotifyMissionUnfocused001, TestSize.Level3)
162 {
163     DTEST_LOG << "DMSContinueManagerTest testNotifyMissionUnfocused001 begin" << std::endl;
164 
165     DistributedSchedUtil::MockManageMissions();
166     DMSContinueSendMgr::GetInstance().Init();
167     /**
168      * @tc.steps: step1. test NotifyMissionUnfocused when eventHandler is not nullptr;
169      */
170     DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(0, UnfocusedReason::NORMAL);
171     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
172 
173     /**
174      * @tc.steps: step2. test NotifyMissionUnfocused when eventHandler is nullptr;
175      */
176     DMSContinueSendMgr::GetInstance().UnInit();
177     DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(0, UnfocusedReason::NORMAL);
178     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
179     DTEST_LOG << "DMSContinueManagerTest testNotifyMissionUnfocused001 end" << std::endl;
180 }
181 
182 /**
183  * @tc.name: testRegisterOnListener001
184  * @tc.desc: test RegisterOnListener
185  * @tc.type: FUNC
186  */
187 HWTEST_F(DMSContinueManagerTest, testRegisterOnListener001, TestSize.Level1)
188 {
189     DTEST_LOG << "DMSContinueManagerTest testRegisterOnListener001 start" << std::endl;
190     DMSContinueRecvMgr::GetInstance().Init();
191     sptr<IRemoteObject> obj01 = new RemoteOnListenerStubTest();
192     int32_t ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
193     EXPECT_EQ(ret, ERR_OK);
194 
195     ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
196     EXPECT_EQ(ret, NO_MISSION_INFO_FOR_MISSION_ID);
197 
198     sptr<IRemoteObject> obj02 = new RemoteOnListenerStubTest();
199     ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj02);
200     EXPECT_EQ(ret, ERR_OK);
201     DTEST_LOG << "DMSContinueManagerTest testRegisterOnListener001 end" << std::endl;
202 }
203 
204 /**
205  * @tc.name: testRegisterOffListener001
206  * @tc.desc: test RegisterOffListener
207  * @tc.type: FUNC
208  */
209 HWTEST_F(DMSContinueManagerTest, testRegisterOffListener001, TestSize.Level1)
210 {
211     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener001 start" << std::endl;
212     sptr<IRemoteObject> obj01 = new RemoteOnListenerStubTest();
213     int32_t ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
214     ret = DMSContinueRecvMgr::GetInstance().RegisterOffListener(TYPE, obj01);
215     EXPECT_EQ(ret, ERR_OK);
216 
217     ret = DMSContinueRecvMgr::GetInstance().RegisterOffListener(TYPE, nullptr);
218     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
219     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener001 end" << std::endl;
220 }
221 
222 /**
223  * @tc.name: testRegisterOffListener002
224  * @tc.desc: test RegisterOffListener when iterItem->second is empty.
225  * @tc.type: FUNC
226  * @tc.require: I7F8KH
227  */
228 HWTEST_F(DMSContinueManagerTest, testRegisterOffListener002, TestSize.Level3)
229 {
230     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener002 start" << std::endl;
231     sptr<IRemoteObject> obj01 = new RemoteOnListenerStubTest();
232     int32_t ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
233     EXPECT_EQ(ret, ERR_OK);
234 
235     {
236         std::lock_guard<std::mutex> registerOnListenerMapLock(
237             DMSContinueRecvMgr::GetInstance().eventMutex_);
238         DMSContinueRecvMgr::GetInstance().registerOnListener_[TYPE].clear();
239     }
240     ret = DMSContinueRecvMgr::GetInstance().RegisterOffListener(TYPE, obj01);
241     EXPECT_EQ(ret, ERR_OK);
242     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener002 end" << std::endl;
243 }
244 
245 /**
246  * @tc.name: testGetMissionId001
247  * @tc.desc: test GetMissionId
248  * @tc.type: FUNC
249  */
250 HWTEST_F(DMSContinueManagerTest, testGetMissionId001, TestSize.Level1)
251 {
252     DTEST_LOG << "DMSContinueManagerTest testGetMissionId001 start" << std::endl;
253     DMSContinueSendMgr::GetInstance().focusedMission_[BUNDLENAME_01] = MISSIONID_01;
254     int32_t missionId;
255     int32_t ret = DMSContinueSendMgr::GetInstance().GetMissionIdByBundleName(BUNDLENAME_01, missionId);
256     EXPECT_EQ(missionId, MISSIONID_01);
257     EXPECT_EQ(ret, ERR_OK);
258 
259     ret = DMSContinueSendMgr::GetInstance().GetMissionIdByBundleName(BUNDLENAME_02, missionId);
260     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
261     DTEST_LOG << "DMSContinueManagerTest testGetMissionId001 end" << std::endl;
262 }
263 
264 /**
265  * @tc.name: testDealFocusedBusiness001
266  * @tc.desc: test DealFocusedBusiness.
267  * @tc.type: FUNC
268  * @tc.require: I7F8KH
269  */
270 HWTEST_F(DMSContinueManagerTest, testDealFocusedBusiness001, TestSize.Level3)
271 {
272     DTEST_LOG << "DMSContinueManagerTest testDealFocusedBusiness001 start" << std::endl;
273 
274     /**
275      * @tc.steps: step1. test DealFocusedBusiness when missionId is invalid;
276      */
277     int32_t ret = DMSContinueSendMgr::GetInstance().DealFocusedBusiness(-1);
278     EXPECT_NE(ret, ERR_OK);
279 
280     DTEST_LOG << "DMSContinueManagerTest testDealFocusedBusiness001 end" << std::endl;
281 }
282 
283 /**
284  * @tc.name: testDealUnfocusedBusiness001
285  * @tc.desc: test DealUnfocusedBusiness.
286  * @tc.type: FUNC
287  * @tc.require: I7F8KH
288  */
289 HWTEST_F(DMSContinueManagerTest, testDealUnfocusedBusiness001, TestSize.Level3)
290 {
291     DTEST_LOG << "DMSContinueManagerTest testDealUnfocusedBusiness001 start" << std::endl;
292 
293     /**
294      * @tc.steps: step1. test DealUnfocusedBusiness when missionId is invalid;
295      */
296     int32_t ret = DMSContinueSendMgr::GetInstance().DealUnfocusedBusiness(-1, UnfocusedReason::NORMAL);
297     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
298 
299     /**
300      * @tc.steps: step2. test DealUnfocusedBusiness when missionId is not invalid;
301      */
302     DMSContinueSendMgr::GetInstance().focusedMission_[BUNDLENAME_01] = MISSIONID_01;
303     ret = DMSContinueSendMgr::GetInstance().DealUnfocusedBusiness(MISSIONID_01, UnfocusedReason::NORMAL);
304     EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR);
305 
306     /**
307      * @tc.steps: step3. test NotifyDied when obj is nullptr;
308      */
309     sptr<IRemoteObject> obj01 = nullptr;
310     DMSContinueRecvMgr::GetInstance().NotifyDied(obj01);
311 
312     /**
313      * @tc.steps: step4. test NotifyDied when iterItem->second is empty;
314      */
315     std::vector<sptr<IRemoteObject>> objs;
316     {
317         std::lock_guard<std::mutex> registerOnListenerMapLock(
318             DMSContinueRecvMgr::GetInstance().eventMutex_);
319         DMSContinueRecvMgr::GetInstance().registerOnListener_[TYPE] = objs;
320     }
321     obj01 = new RemoteOnListenerStubTest();
322     DMSContinueRecvMgr::GetInstance().NotifyDied(obj01);
323 
324     DTEST_LOG << "DMSContinueManagerTest testDealUnfocusedBusiness001 end" << std::endl;
325 }
326 
327 /**
328  * @tc.name: testVerifyBroadcastSource001
329  * @tc.desc: test testVerifyBroadcastSource001.
330  * @tc.type: FUNC
331  */
332 HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource001, TestSize.Level3)
333 {
334     DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource001 start" << std::endl;
335 
336     int32_t state = ACTIVE;
337     std::string networkId = "test networkId";
338     std::string bundleName = "test bundleName";
339     int32_t ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
340         bundleName, state);
341     EXPECT_EQ(ret, ERR_OK);
342 
343     state = INACTIVE;
344     ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId, bundleName, state);
345     EXPECT_EQ(ret, ERR_OK);
346 }
347 
348 /**
349  * @tc.name: testVerifyBroadcastSource002
350  * @tc.desc: test testVerifyBroadcastSource002.
351  * @tc.type: FUNC
352  */
353 HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource002, TestSize.Level3)
354 {
355     DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource002 start" << std::endl;
356 
357     int32_t state = ACTIVE;
358     std::string networkId = "test networkId";
359     std::string bundleName = "test bundleName";
360     int32_t ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
361         bundleName, state);
362     EXPECT_EQ(ret, ERR_OK);
363 
364     state = INACTIVE;
365     networkId = "invalid networkId";
366     ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
367         bundleName, state);
368     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
369 }
370 
371 /**
372  * @tc.name: testVerifyBroadcastSource003
373  * @tc.desc: test testVerifyBroadcastSource003.
374  * @tc.type: FUNC
375  */
376 HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource003, TestSize.Level3)
377 {
378     DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource003 start" << std::endl;
379 
380     int32_t state = ACTIVE;
381     std::string networkId = "test networkId";
382     std::string bundleName = "test bundleName";
383     int32_t ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
384         bundleName, state);
385     EXPECT_EQ(ret, ERR_OK);
386 
387     state = INACTIVE;
388     bundleName = "invalid bundleName";
389     ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId, bundleName, state);
390     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
391 }
392 
393 /**
394  * @tc.name: testDealOnBroadcastBusiness001
395  * @tc.desc: test DealOnBroadcastBusiness.
396  * @tc.type: FUNC
397  * @tc.require: I7F8KH
398  */
399 HWTEST_F(DMSContinueManagerTest, testDealOnBroadcastBusiness001, TestSize.Level3)
400 {
401     DTEST_LOG << "DMSContinueManagerTest testDealOnBroadcastBusiness001 start" << std::endl;
402 
403     /**
404      * @tc.steps: step1. test DealOnBroadcastBusiness when senderNetworkId is invalid;
405      */
406     std::string senderNetworkId = "invalid senderNetworkId";
407     uint32_t accessTokenId = 0;
408     int32_t state = 0;
409     int32_t ret = DMSContinueRecvMgr::GetInstance().DealOnBroadcastBusiness(
410         senderNetworkId, accessTokenId, state);
411     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
412 
413     /**
414      * @tc.steps: step2. test NotifyRecvBroadcast when obj is nullptr;
415      */
416     sptr<IRemoteObject> obj = nullptr;
417     std::string networkId = "invalid networkId";
418     std::string bundleName = "invalid bundleName";
419     DMSContinueRecvMgr::GetInstance().NotifyRecvBroadcast(obj, networkId, bundleName, state);
420 
421     /**
422      * @tc.steps: step3. test NotifyRecvBroadcast when missionId is invalid;
423      */
424     obj =  new RemoteOnListenerStubTest();
425     DMSContinueRecvMgr::GetInstance().NotifyRecvBroadcast(obj, networkId, bundleName, state);
426 
427     DTEST_LOG << "DMSContinueManagerTest testDealOnBroadcastBusiness001 end" << std::endl;
428 }
429 
430 /**
431  * @tc.name: testGetBundleName001
432  * @tc.desc: test GetBundleName
433  * @tc.type: FUNC
434  */
435 HWTEST_F(DMSContinueManagerTest, testGetBundleName001, TestSize.Level1)
436 {
437     DTEST_LOG << "DMSContinueManagerTest testGetBundleName001 start" << std::endl;
438     DMSContinueSendMgr::GetInstance().focusedMission_[BUNDLENAME_01] = MISSIONID_01;
439     std::string bundleName;
440     int32_t ret = DMSContinueSendMgr::GetInstance().GetBundleNameByMissionId(MISSIONID_01, bundleName);
441     EXPECT_EQ(bundleName, BUNDLENAME_01);
442     EXPECT_EQ(ret, ERR_OK);
443 
444     ret = DMSContinueSendMgr::GetInstance().GetBundleNameByMissionId(MISSIONID_02, bundleName);
445     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
446     DTEST_LOG << "DMSContinueManagerTest testGetBundleName001 end" << std::endl;
447 }
448 
449 /**
450  * @tc.name: testIsContinue001
451  * @tc.desc: test IsContinue
452  * @tc.type: FUNC
453  */
454 HWTEST_F(DMSContinueManagerTest, testIsContinue001, TestSize.Level1)
455 {
456     DTEST_LOG << "DMSContinueManagerTest testIsContinue001 start" << std::endl;
457     DMSContinueSendMgr::GetInstance().focusedMission_[BUNDLENAME_02] = MISSIONID_02;
458     DMSContinueSendMgr::GetInstance().info_.currentMissionId = MISSIONID_01;
459     DMSContinueSendMgr::GetInstance().info_.currentIsContinuable = true;
460     bool ret = DMSContinueSendMgr::GetInstance().IsContinue(MISSIONID_02, BUNDLENAME_02);
461     EXPECT_EQ(ret, false);
462 
463     ret = DMSContinueSendMgr::GetInstance().IsContinue(MISSIONID_01, BUNDLENAME_01);
464     EXPECT_EQ(ret, true);
465 
466     DMSContinueSendMgr::GetInstance().info_.currentIsContinuable = false;
467     ret = DMSContinueSendMgr::GetInstance().IsContinue(MISSIONID_01, BUNDLENAME_01);
468     EXPECT_EQ(ret, true);
469     DTEST_LOG << "DMSContinueManagerTest testIsContinue001 end" << std::endl;
470 }
471 
472 /**
473  * @tc.name: testNotifyDied001
474  * @tc.desc: test NotifyDied
475  * @tc.type: FUNC
476  */
477 HWTEST_F(DMSContinueManagerTest, testNotifyDied001, TestSize.Level1)
478 {
479     DTEST_LOG << "DMSContinueManagerTest testNotifyDied001 start" << std::endl;
480     sptr<IRemoteObject> obj01 = new RemoteOnListenerStubTest();
481     int32_t ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
482     EXPECT_EQ(false, DMSContinueRecvMgr::GetInstance().registerOnListener_.empty());
483     DMSContinueRecvMgr::GetInstance().NotifyDied(obj01);
484     DTEST_LOG << "DMSContinueManagerTest testNotifyDied001 end" << std::endl;
485 }
486 
487 /**
488  * @tc.name: testSetMissionContinueState001
489  * @tc.desc: test SetMissionContinueState
490  * @tc.type: FUNC
491  */
492 HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState001, TestSize.Level3)
493 {
494     DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState001 start" << std::endl;
495     DistributedSchedUtil::MockManageMissions();
496     DMSContinueSendMgr::GetInstance().Init();
497     OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
498 
499      /**
500      * @tc.steps: step1. test SetMissionContinueState when eventHandler is not nullptr;
501      */
502     DMSContinueSendMgr::GetInstance().SetMissionContinueState(0, state);
503     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
504 
505     /**
506      * @tc.steps: step2. test SetMissionContinueState when eventHandler is nullptr;
507      */
508     DMSContinueSendMgr::GetInstance().UnInit();
509     DMSContinueSendMgr::GetInstance().SetMissionContinueState(0, state);
510     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
511     DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState001 end" << std::endl;
512 }
513 
514 /**
515  * @tc.name: testDealSetMissionContinueStateBusiness001
516  * @tc.desc: test DealSetMissionContinueStateBusiness.
517  * @tc.type: FUNC
518  */
519 HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness001, TestSize.Level3)
520 {
521     DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness001 start" << std::endl;
522     OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
523     DMSContinueSendMgr::GetInstance().info_.currentMissionId = MISSIONID_01;
524 
525     /**
526      * @tc.steps: step1. test DealSetMissionContinueStateBusiness when missionId is invalid;
527      */
528     int32_t ret = DMSContinueSendMgr::GetInstance().DealSetMissionContinueStateBusiness(MISSIONID_02,
529         state);
530     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
531 
532     /**
533      * @tc.steps: step2. test DealUnfocusedBusiness when mission is not continueable;
534      */
535     DMSContinueSendMgr::GetInstance().info_.currentIsContinuable = false;
536     ret = DMSContinueSendMgr::GetInstance().DealSetMissionContinueStateBusiness(MISSIONID_01, state);
537     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
538 
539     DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness001 end" << std::endl;
540 }
541 
542 #ifdef SUPPORT_COMMON_EVENT_SERVICE
543 /**
544  * @tc.name: testOnDeviceScreenOff001
545  * @tc.desc: test OnDeviceScreenOff normal
546  * @tc.type: FUNC
547  */
548 HWTEST_F(DMSContinueManagerTest, testOnDeviceScreenOff001, TestSize.Level1)
549 {
550     DTEST_LOG << "DMSContinueManagerTest testOnDeviceScreenOff001 start" << std::endl;
551 
552     DistributedSchedUtil::MockManageMissions();
553      /**
554      * @tc.steps: step1. test OnDeviceScreenOff when eventHandler is not nullptr;
555      */
556     DMSContinueSendMgr::GetInstance().Init();
557     DMSContinueSendMgr::GetInstance().OnDeviceScreenOff();
558     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
559 
560     /**
561      * @tc.steps: step2. test OnDeviceScreenOff when eventHandler is nullptr;
562      */
563     DMSContinueSendMgr::GetInstance().UnInit();
564     DMSContinueSendMgr::GetInstance().OnDeviceScreenOff();
565     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
566     DTEST_LOG << "DMSContinueManagerTest testOnDeviceScreenOff001 end" << std::endl;
567 }
568 #endif
569 
570 /**
571  * @tc.name: testNotifyDeviceOffline001
572  * @tc.desc: test NotifyDeviceOffline normal
573  * @tc.type: FUNC
574  */
575 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline001, TestSize.Level1)
576 {
577     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline001 start" << std::endl;
578     sptr<IRemoteObject> obj01 = new RemoteOnListenerStubTest();
579     DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
580     EXPECT_NE(DMSContinueRecvMgr::GetInstance().registerOnListener_.size(), 0);
581 
582     DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId = NETWORKID_01;
583     DMSContinueRecvMgr::GetInstance().NotifyDeviceOffline(NETWORKID_01);
584     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId, "");
585 
586     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline001 end" << std::endl;
587 }
588 
589 /**
590  * @tc.name: testNotifyDeviceOffline002
591  * @tc.desc: test NotifyDeviceOffline networkId empty
592  * @tc.type: FUNC
593  */
594 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline002, TestSize.Level1)
595 {
596     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline002 start" << std::endl;
597     DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId = NETWORKID_01;
598     DMSContinueRecvMgr::GetInstance().NotifyDeviceOffline("");
599     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId, NETWORKID_01);
600 
601     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline002 end" << std::endl;
602 }
603 
604 /**
605  * @tc.name: testNotifyDeviceOffline003
606  * @tc.desc: test NotifyDeviceOffline networkId not match
607  * @tc.type: FUNC
608  */
609 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline003, TestSize.Level1)
610 {
611     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 start" << std::endl;
612     DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId = NETWORKID_01;
613     DMSContinueRecvMgr::GetInstance().NotifyDeviceOffline(NETWORKID_02);
614     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId, NETWORKID_01);
615 
616     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 end" << std::endl;
617 }
618 
619 /**
620  * @tc.name: testNotifyDataRecv001
621  * @tc.desc: NotifyDataRecv
622  * @tc.type: FUNC
623  */
624 HWTEST_F(DMSContinueManagerTest, testNotifyDataRecv001, TestSize.Level1)
625 {
626     DTEST_LOG << "DMSContinueManagerTest testNotifyDataRecv001 start" << std::endl;
627     std::string senderNetworkId = NETWORKID_01;
628     uint8_t payload[] = {0xf0};
629     uint32_t dataLen1 = DMS_SEND_LEN - 1;
630     DMSContinueRecvMgr::GetInstance().NotifyDataRecv(senderNetworkId, payload, dataLen1);
631 
632     uint32_t dataLen2 = DMS_SEND_LEN;
633     DMSContinueRecvMgr::GetInstance().NotifyDataRecv(senderNetworkId, payload, dataLen2);
634     EXPECT_NE(payload[0] & DMS_0X0F, sizeof(uint32_t));
635     DTEST_LOG << "DMSContinueManagerTest testNotifyDataRecv001 end" << std::endl;
636 }
637 
638 /**
639  * @tc.name: testSendSoftbusEvent001
640  * @tc.desc: SendSoftbusEvent
641  * @tc.type: FUNC
642  */
643 HWTEST_F(DMSContinueManagerTest, testSendSoftbusEvent001, TestSize.Level1)
644 {
645     DTEST_LOG << "DMSContinueManagerTest testSendSoftbusEvent001 start" << std::endl;
646     uint32_t accessTokenId = 0;
647     uint8_t type = 0;
648     bool ret = DMSContinueSendMgr::GetInstance().SendSoftbusEvent(accessTokenId, type);
649     EXPECT_EQ(ret, ERR_OK);
650     DTEST_LOG << "DMSContinueManagerTest testSendSoftbusEvent001 end" << std::endl;
651 }
652 } // namespace DistributedSchedule
653 } // namespace OHOS