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_test_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 ABILITY_NAME_01 = "abilityName01";
39 const std::string CANCEL_FOCUSED_TASK = "cancel_mission_focused_task";
40 constexpr static int32_t DMS_SEND_LEN = 5;
41 constexpr static uint8_t DMS_0X0F = 0x0f;
42 constexpr int32_t MISSIONID_01 = 1;
43 constexpr int32_t MISSIONID_02 = 2;
44 constexpr int32_t ACTIVE = 0;
45 constexpr int32_t INACTIVE = 1;
46 constexpr int32_t CANCEL_FOCUSED_DELAYED = 10000;
47 constexpr int32_t DBMS_RETRY_MAX_TIME = 5;
48 constexpr uint8_t DMS_FOCUSED_TYPE = 0x00;
49 }
50 
SetUpTestCase()51 void DMSContinueManagerTest::SetUpTestCase()
52 {
53 }
54 
TearDownTestCase()55 void DMSContinueManagerTest::TearDownTestCase()
56 {
57 }
58 
SetUp()59 void DMSContinueManagerTest::SetUp()
60 {
61 }
62 
TearDown()63 void DMSContinueManagerTest::TearDown()
64 {
65 }
66 
OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId, const std::string &bundleName, const std::string &continueType, const std::string &srcBundleName)67 void RemoteOnListenerStubTest::OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId,
68     const std::string &bundleName, const std::string &continueType, const std::string &srcBundleName)
69 {
70 }
71 
72 /**
73  * @tc.name: testUnInit001
74  * @tc.desc: test UnInit
75  * @tc.type: FUNC
76  * @tc.require: I7F8KH
77  */
HWTEST_F(DMSContinueManagerTest, testUnInit001, TestSize.Level3)78 HWTEST_F(DMSContinueManagerTest, testUnInit001, TestSize.Level3)
79 {
80     DTEST_LOG << "DMSContinueManagerTest testUnInit001 begin" << std::endl;
81 
82     DistributedSchedUtil::MockManageMissions();
83     DMSContinueSendMgr::GetInstance().Init();
84     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
85 
86     /**
87      * @tc.steps: step1. test UnInit when eventHandler is not nullptr;
88      */
89     DMSContinueSendMgr::GetInstance().UnInit();
90     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
91 
92     /**
93      * @tc.steps: step2. test UnInit when eventHandler is nullptr;
94      */
95     DMSContinueSendMgr::GetInstance().UnInit();
96     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
97 
98     DTEST_LOG << "DMSContinueManagerTest testUnInit001 end" << std::endl;
99 }
100 
101 /**
102  * @tc.name: testUnInit002
103  * @tc.desc: test UnInit
104  * @tc.type: FUNC
105  * @tc.require: I7F8KH
106  */
HWTEST_F(DMSContinueManagerTest, testUnInit002, TestSize.Level3)107 HWTEST_F(DMSContinueManagerTest, testUnInit002, TestSize.Level3)
108 {
109     DTEST_LOG << "DMSContinueManagerTest testUnInit002 begin" << std::endl;
110 
111     DistributedSchedUtil::MockManageMissions();
112     DMSContinueSendMgr::GetInstance().Init();
113     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
114 
115     DMSContinueSendMgr::GetInstance().UnInit();
116     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
117     DTEST_LOG << "DMSContinueManagerTest testUnInit002 end" << std::endl;
118 }
119 
120 /**
121  * @tc.name: testPostUnfocusedTaskWithDelay001
122  * @tc.desc: test PostUnfocusedTaskWithDelay
123  * @tc.type: FUNC
124  */
HWTEST_F(DMSContinueManagerTest, testPostUnfocusedTaskWithDelay001, TestSize.Level3)125 HWTEST_F(DMSContinueManagerTest, testPostUnfocusedTaskWithDelay001, TestSize.Level3)
126 {
127     DTEST_LOG << "DMSContinueManagerTest testPostUnfocusedTaskWithDelay001 begin" << std::endl;
128 
129     DistributedSchedUtil::MockManageMissions();
130     DMSContinueSendMgr::GetInstance().Init();
131 
132     /**
133      * @tc.steps: step1. test PostUnfocusedTaskWithDelay when eventHandler is not nullptr;
134      */
135     DMSContinueSendMgr::GetInstance().PostUnfocusedTaskWithDelay(0, UnfocusedReason::TIMEOUT);
136     DMSContinueSendMgr::GetInstance().PostUnfocusedTaskWithDelay(0, UnfocusedReason::SCREENOFF);
137     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
138 
139     /**
140      * @tc.steps: step2. test PostUnfocusedTaskWithDelay when eventHandler is nullptr;
141      */
142     DMSContinueSendMgr::GetInstance().UnInit();
143     DMSContinueSendMgr::GetInstance().PostUnfocusedTaskWithDelay(0, UnfocusedReason::TIMEOUT);
144     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
145     DTEST_LOG << "DMSContinueManagerTest testPostUnfocusedTaskWithDelay001 end" << std::endl;
146 }
147 
148 /**
149  * @tc.name: testNotifyMissionFocused001
150  * @tc.desc: test NotifyMissionFocused
151  * @tc.type: FUNC
152  * @tc.require: I7F8KH
153  */
HWTEST_F(DMSContinueManagerTest, testNotifyMissionFocused001, TestSize.Level3)154 HWTEST_F(DMSContinueManagerTest, testNotifyMissionFocused001, TestSize.Level3)
155 {
156     DTEST_LOG << "DMSContinueManagerTest testNotifyMissionFocused001 begin" << std::endl;
157 
158     DistributedSchedUtil::MockManageMissions();
159     DMSContinueSendMgr::GetInstance().Init();
160 
161     /**
162      * @tc.steps: step1. test NotifyMissionFocused when eventHandler is not nullptr;
163      */
164     DMSContinueSendMgr::GetInstance().NotifyMissionFocused(0, FocusedReason::NORMAL);
165     DMSContinueSendMgr::GetInstance().NotifyMissionFocused(0, FocusedReason::SCREENOFF);
166     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
167 
168     /**
169      * @tc.steps: step2. test NotifyMissionFocused when eventHandler is nullptr;
170      */
171     DMSContinueSendMgr::GetInstance().UnInit();
172     DMSContinueSendMgr::GetInstance().NotifyMissionFocused(0, FocusedReason::NORMAL);
173     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
174     DTEST_LOG << "DMSContinueManagerTest testNotifyMissionFocused001 end" << std::endl;
175 }
176 
177 /**
178  * @tc.name: testNotifyMissionUnfocused001
179  * @tc.desc: test NotifyMissionUnfocused
180  * @tc.type: FUNC
181  * @tc.require: I7F8KH
182  */
HWTEST_F(DMSContinueManagerTest, testNotifyMissionUnfocused001, TestSize.Level3)183 HWTEST_F(DMSContinueManagerTest, testNotifyMissionUnfocused001, TestSize.Level3)
184 {
185     DTEST_LOG << "DMSContinueManagerTest testNotifyMissionUnfocused001 begin" << std::endl;
186 
187     DistributedSchedUtil::MockManageMissions();
188     DMSContinueSendMgr::GetInstance().Init();
189     /**
190      * @tc.steps: step1. test NotifyMissionUnfocused when eventHandler is not nullptr;
191      */
192     DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(0, UnfocusedReason::NORMAL);
193     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
194 
195     /**
196      * @tc.steps: step2. test NotifyMissionUnfocused when eventHandler is nullptr;
197      */
198     DMSContinueSendMgr::GetInstance().UnInit();
199     DMSContinueSendMgr::GetInstance().NotifyMissionUnfocused(0, UnfocusedReason::NORMAL);
200     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
201     DTEST_LOG << "DMSContinueManagerTest testNotifyMissionUnfocused001 end" << std::endl;
202 }
203 
204 /**
205  * @tc.name: testRegisterOnListener001
206  * @tc.desc: test RegisterOnListener
207  * @tc.type: FUNC
208  */
HWTEST_F(DMSContinueManagerTest, testRegisterOnListener001, TestSize.Level1)209 HWTEST_F(DMSContinueManagerTest, testRegisterOnListener001, TestSize.Level1)
210 {
211     DTEST_LOG << "DMSContinueManagerTest testRegisterOnListener001 start" << std::endl;
212     DMSContinueRecvMgr::GetInstance().Init();
213     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
214     int32_t ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
215     EXPECT_EQ(ret, ERR_OK);
216 
217     ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
218     EXPECT_EQ(ret, NO_MISSION_INFO_FOR_MISSION_ID);
219 
220     sptr<IRemoteObject> obj02(new RemoteOnListenerStubTest());
221     ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj02);
222     EXPECT_EQ(ret, ERR_OK);
223     DMSContinueRecvMgr::GetInstance().UnInit();
224     DTEST_LOG << "DMSContinueManagerTest testRegisterOnListener001 end" << std::endl;
225 }
226 
227 /**
228  * @tc.name: testRegisterOffListener001
229  * @tc.desc: test RegisterOffListener
230  * @tc.type: FUNC
231  */
HWTEST_F(DMSContinueManagerTest, testRegisterOffListener001, TestSize.Level1)232 HWTEST_F(DMSContinueManagerTest, testRegisterOffListener001, TestSize.Level1)
233 {
234     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener001 start" << std::endl;
235     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
236     int32_t ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
237     ret = DMSContinueRecvMgr::GetInstance().RegisterOffListener(TYPE, obj01);
238     EXPECT_EQ(ret, ERR_OK);
239 
240     ret = DMSContinueRecvMgr::GetInstance().RegisterOffListener(TYPE, nullptr);
241     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
242     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener001 end" << std::endl;
243 }
244 
245 /**
246  * @tc.name: testRegisterOffListener002
247  * @tc.desc: test RegisterOffListener when iterItem->second is empty.
248  * @tc.type: FUNC
249  * @tc.require: I7F8KH
250  */
HWTEST_F(DMSContinueManagerTest, testRegisterOffListener002, TestSize.Level3)251 HWTEST_F(DMSContinueManagerTest, testRegisterOffListener002, TestSize.Level3)
252 {
253     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener002 start" << std::endl;
254     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
255     int32_t ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
256     EXPECT_EQ(ret, ERR_OK);
257 
258     {
259         std::lock_guard<std::mutex> registerOnListenerMapLock(
260             DMSContinueRecvMgr::GetInstance().eventMutex_);
261         DMSContinueRecvMgr::GetInstance().registerOnListener_[TYPE].clear();
262     }
263     ret = DMSContinueRecvMgr::GetInstance().RegisterOffListener(TYPE, obj01);
264     EXPECT_EQ(ret, ERR_OK);
265     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener002 end" << std::endl;
266 }
267 
268 /**
269  * @tc.name: testGetMissionId001
270  * @tc.desc: test GetMissionId
271  * @tc.type: FUNC
272  */
HWTEST_F(DMSContinueManagerTest, testGetMissionId001, TestSize.Level1)273 HWTEST_F(DMSContinueManagerTest, testGetMissionId001, TestSize.Level1)
274 {
275     DTEST_LOG << "DMSContinueManagerTest testGetMissionId001 start" << std::endl;
276     DMSContinueSendMgr::GetInstance().focusedMission_[BUNDLENAME_01] = MISSIONID_01;
277     int32_t missionId;
278     int32_t ret = DMSContinueSendMgr::GetInstance().GetMissionIdByBundleName(BUNDLENAME_01, missionId);
279     EXPECT_EQ(missionId, MISSIONID_01);
280     EXPECT_EQ(ret, ERR_OK);
281 
282     ret = DMSContinueSendMgr::GetInstance().GetMissionIdByBundleName(BUNDLENAME_02, missionId);
283     EXPECT_EQ(ret, MISSION_NOT_FOCUSED);
284     DTEST_LOG << "DMSContinueManagerTest testGetMissionId001 end" << std::endl;
285 }
286 
287 /**
288  * @tc.name: testDealFocusedBusiness001
289  * @tc.desc: test DealFocusedBusiness.
290  * @tc.type: FUNC
291  * @tc.require: I7F8KH
292  */
HWTEST_F(DMSContinueManagerTest, testDealFocusedBusiness001, TestSize.Level3)293 HWTEST_F(DMSContinueManagerTest, testDealFocusedBusiness001, TestSize.Level3)
294 {
295     DTEST_LOG << "DMSContinueManagerTest testDealFocusedBusiness001 start" << std::endl;
296 
297     /**
298      * @tc.steps: step1. test DealFocusedBusiness when missionId is invalid;
299      */
300     int32_t ret = DMSContinueSendMgr::GetInstance().DealFocusedBusiness(-1, FocusedReason::MIN);
301     EXPECT_NE(ret, ERR_OK);
302 
303     DTEST_LOG << "DMSContinueManagerTest testDealFocusedBusiness001 end" << std::endl;
304 }
305 
306 /**
307  * @tc.name: testDealUnfocusedBusiness001
308  * @tc.desc: test DealUnfocusedBusiness.
309  * @tc.type: FUNC
310  * @tc.require: I7F8KH
311  */
HWTEST_F(DMSContinueManagerTest, testDealUnfocusedBusiness001, TestSize.Level3)312 HWTEST_F(DMSContinueManagerTest, testDealUnfocusedBusiness001, TestSize.Level3)
313 {
314     DTEST_LOG << "DMSContinueManagerTest testDealUnfocusedBusiness001 start" << std::endl;
315 
316     /**
317      * @tc.steps: step1. test DealUnfocusedBusiness when missionId is invalid;
318      */
319     int32_t ret = DMSContinueSendMgr::GetInstance().DealUnfocusedBusiness(-1, UnfocusedReason::NORMAL);
320     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
321 
322     /**
323      * @tc.steps: step2. test DealUnfocusedBusiness when missionId is not invalid;
324      */
325     DMSContinueSendMgr::GetInstance().focusedMission_[BUNDLENAME_01] = MISSIONID_01;
326     DMSContinueSendMgr::GetInstance().focusedMissionAbility_[MISSIONID_01] = ABILITY_NAME_01;
327     ret = DMSContinueSendMgr::GetInstance().DealUnfocusedBusiness(MISSIONID_01, UnfocusedReason::NORMAL);
328     EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR);
329 
330     /**
331      * @tc.steps: step3. test NotifyDied when obj is nullptr;
332      */
333     sptr<IRemoteObject> obj01 = nullptr;
334     DMSContinueRecvMgr::GetInstance().NotifyDied(obj01);
335 
336     /**
337      * @tc.steps: step4. test NotifyDied when iterItem->second is empty;
338      */
339     std::vector<sptr<IRemoteObject>> objs;
340     {
341         std::lock_guard<std::mutex> registerOnListenerMapLock(
342             DMSContinueRecvMgr::GetInstance().eventMutex_);
343         DMSContinueRecvMgr::GetInstance().registerOnListener_[TYPE] = objs;
344     }
345     obj01 = new RemoteOnListenerStubTest();
346     DMSContinueRecvMgr::GetInstance().NotifyDied(obj01);
347 
348     DTEST_LOG << "DMSContinueManagerTest testDealUnfocusedBusiness001 end" << std::endl;
349 }
350 
351 /**
352  * @tc.name: testVerifyBroadcastSource001
353  * @tc.desc: test testVerifyBroadcastSource001.
354  * @tc.type: FUNC
355  */
HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource001, TestSize.Level3)356 HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource001, TestSize.Level3)
357 {
358     DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource001 start" << std::endl;
359 
360     int32_t state = ACTIVE;
361     std::string networkId = "test networkId";
362     std::string sourceBundleName = "test sourceBundleName";
363     std::string sinkBundleName = "test sinkBundleName";
364     std::string continueType = "test continueType";
365     int32_t ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
366         sourceBundleName, sinkBundleName, continueType, state);
367     EXPECT_EQ(ret, ERR_OK);
368 
369     state = INACTIVE;
370     ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(
371         networkId, sourceBundleName, sinkBundleName, continueType, state);
372     EXPECT_EQ(ret, ERR_OK);
373 }
374 
375 /**
376  * @tc.name: testVerifyBroadcastSource002
377  * @tc.desc: test testVerifyBroadcastSource002.
378  * @tc.type: FUNC
379  */
HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource002, TestSize.Level3)380 HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource002, TestSize.Level3)
381 {
382     DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource002 start" << std::endl;
383 
384     int32_t state = ACTIVE;
385     std::string networkId = "test networkId";
386     std::string sourceBundleName = "test sourceBundleName";
387     std::string sinkBundleName = "test sinkBundleName";
388     std::string continueType = "test continueType";
389     int32_t ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
390         sourceBundleName, sinkBundleName, continueType, state);
391     EXPECT_EQ(ret, ERR_OK);
392 
393     state = INACTIVE;
394     networkId = "invalid networkId";
395     ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
396         sourceBundleName, sinkBundleName, continueType, state);
397     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
398 }
399 
400 /**
401  * @tc.name: testVerifyBroadcastSource003
402  * @tc.desc: test testVerifyBroadcastSource003.
403  * @tc.type: FUNC
404  */
HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource003, TestSize.Level3)405 HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource003, TestSize.Level3)
406 {
407     DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource003 start" << std::endl;
408 
409     int32_t state = ACTIVE;
410     std::string networkId = "test networkId";
411     std::string sourceBundleName = "test sourceBundleName";
412     std::string sinkBundleName = "test sinkBundleName";
413     std::string continueType = "test continueType";
414     int32_t ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
415         sourceBundleName, sinkBundleName, continueType, state);
416     EXPECT_EQ(ret, ERR_OK);
417 
418     state = INACTIVE;
419     sourceBundleName = "invalid sourceBundleName";
420     sinkBundleName = "invalid sinkBundleName";
421     ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
422         sourceBundleName, sinkBundleName, continueType, state);
423     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
424 }
425 
426 /**
427  * @tc.name: testDealOnBroadcastBusiness001
428  * @tc.desc: test DealOnBroadcastBusiness.
429  * @tc.type: FUNC
430  * @tc.require: I7F8KH
431  */
HWTEST_F(DMSContinueManagerTest, testDealOnBroadcastBusiness001, TestSize.Level3)432 HWTEST_F(DMSContinueManagerTest, testDealOnBroadcastBusiness001, TestSize.Level3)
433 {
434     DTEST_LOG << "DMSContinueManagerTest testDealOnBroadcastBusiness001 start" << std::endl;
435 
436     /**
437      * @tc.steps: step1. test DealOnBroadcastBusiness when senderNetworkId is invalid;
438      */
439     std::string senderNetworkId = "invalid senderNetworkId";
440     uint16_t bundleNameId = 0;
441     uint8_t continueTypeId = 0;
442     int32_t state = 0;
443 
444     DMSContinueRecvMgr::GetInstance().PostOnBroadcastBusiness(senderNetworkId, bundleNameId, continueTypeId, state);
445 
446     int32_t ret = DMSContinueRecvMgr::GetInstance().DealOnBroadcastBusiness(senderNetworkId, bundleNameId,
447         continueTypeId, state, 0);
448     EXPECT_EQ(ret, ERR_OK);
449 
450     ret = DMSContinueRecvMgr::GetInstance().DealOnBroadcastBusiness(senderNetworkId, bundleNameId, continueTypeId,
451         state, DBMS_RETRY_MAX_TIME);
452     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
453 
454     /**
455      * @tc.steps: step2. test NotifyRecvBroadcast when obj is nullptr;
456      */
457     sptr<IRemoteObject> obj = nullptr;
458     std::string networkId = "invalid networkId";
459     std::string sourceBundleName = "invalid sourceBundleName";
460     std::string sinkBundleName = "invalid sinkBundleName";
461     std::string continueType = "invalid continueType";
462     DMSContinueRecvMgr::GetInstance().NotifyRecvBroadcast(obj,
463         currentIconInfo(networkId, sourceBundleName, sinkBundleName, continueType), state);
464 
465     /**
466      * @tc.steps: step3. test NotifyRecvBroadcast when missionId is invalid;
467      */
468     obj =  new RemoteOnListenerStubTest();
469     DMSContinueRecvMgr::GetInstance().NotifyRecvBroadcast(obj,
470         currentIconInfo(networkId, sourceBundleName, sinkBundleName, continueType), state);
471 
472     DTEST_LOG << "DMSContinueManagerTest testDealOnBroadcastBusiness001 end" << std::endl;
473 }
474 
475 /**
476  * @tc.name: testGetBundleName001
477  * @tc.desc: test GetBundleName
478  * @tc.type: FUNC
479  */
HWTEST_F(DMSContinueManagerTest, testGetBundleName001, TestSize.Level1)480 HWTEST_F(DMSContinueManagerTest, testGetBundleName001, TestSize.Level1)
481 {
482     DTEST_LOG << "DMSContinueManagerTest testGetBundleName001 start" << std::endl;
483     DMSContinueSendMgr::GetInstance().focusedMission_[BUNDLENAME_01] = MISSIONID_01;
484     std::string bundleName;
485     int32_t ret = DMSContinueSendMgr::GetInstance().GetBundleNameByMissionId(MISSIONID_01, bundleName);
486     EXPECT_EQ(bundleName, BUNDLENAME_01);
487     EXPECT_EQ(ret, ERR_OK);
488 
489     ret = DMSContinueSendMgr::GetInstance().GetBundleNameByMissionId(MISSIONID_02, bundleName);
490     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
491     DTEST_LOG << "DMSContinueManagerTest testGetBundleName001 end" << std::endl;
492 }
493 
494 /**
495  * @tc.name: testIsContinue001
496  * @tc.desc: test IsContinue
497  * @tc.type: FUNC
498  */
HWTEST_F(DMSContinueManagerTest, testIsContinue001, TestSize.Level1)499 HWTEST_F(DMSContinueManagerTest, testIsContinue001, TestSize.Level1)
500 {
501     DTEST_LOG << "DMSContinueManagerTest testIsContinue001 start" << std::endl;
502     DMSContinueSendMgr::GetInstance().focusedMission_[BUNDLENAME_02] = MISSIONID_02;
503     DMSContinueSendMgr::GetInstance().info_.currentMissionId = MISSIONID_01;
504     DMSContinueSendMgr::GetInstance().info_.currentIsContinuable = true;
505     bool ret = DMSContinueSendMgr::GetInstance().IsContinue(MISSIONID_02, BUNDLENAME_02);
506     EXPECT_EQ(ret, false);
507 
508     ret = DMSContinueSendMgr::GetInstance().IsContinue(MISSIONID_01, BUNDLENAME_01);
509     EXPECT_EQ(ret, true);
510 
511     DMSContinueSendMgr::GetInstance().info_.currentIsContinuable = false;
512     ret = DMSContinueSendMgr::GetInstance().IsContinue(MISSIONID_01, BUNDLENAME_01);
513     EXPECT_EQ(ret, true);
514     DTEST_LOG << "DMSContinueManagerTest testIsContinue001 end" << std::endl;
515 }
516 
517 /**
518  * @tc.name: testNotifyDied001
519  * @tc.desc: test NotifyDied
520  * @tc.type: FUNC
521  */
HWTEST_F(DMSContinueManagerTest, testNotifyDied001, TestSize.Level1)522 HWTEST_F(DMSContinueManagerTest, testNotifyDied001, TestSize.Level1)
523 {
524     DTEST_LOG << "DMSContinueManagerTest testNotifyDied001 start" << std::endl;
525     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
526     int32_t ret = DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
527     EXPECT_EQ(false, DMSContinueRecvMgr::GetInstance().registerOnListener_.empty());
528     DMSContinueRecvMgr::GetInstance().NotifyDied(obj01);
529     DTEST_LOG << "DMSContinueManagerTest testNotifyDied001 end" << std::endl;
530 }
531 
532 /**
533  * @tc.name: testSetMissionContinueState001
534  * @tc.desc: test SetMissionContinueState
535  * @tc.type: FUNC
536  */
HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState001, TestSize.Level3)537 HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState001, TestSize.Level3)
538 {
539     DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState001 start" << std::endl;
540     DistributedSchedUtil::MockManageMissions();
541     DMSContinueSendMgr::GetInstance().Init();
542     OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
543 
544      /**
545      * @tc.steps: step1. test SetMissionContinueState when eventHandler is not nullptr;
546      */
547     DMSContinueSendMgr::GetInstance().SetMissionContinueState(0, state);
548     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
549 
550     /**
551      * @tc.steps: step2. test SetMissionContinueState when eventHandler is nullptr;
552      */
553     DMSContinueSendMgr::GetInstance().UnInit();
554     DMSContinueSendMgr::GetInstance().SetMissionContinueState(0, state);
555     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
556     DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState001 end" << std::endl;
557 }
558 
559 /**
560  * @tc.name: testSetMissionContinueState002
561  * @tc.desc: test SetMissionContinueState
562  * @tc.type: FUNC
563  */
HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState002, TestSize.Level3)564 HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState002, TestSize.Level3)
565 {
566     DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState002 start" << std::endl;
567     DistributedSchedUtil::MockManageMissions();
568     DMSContinueSendMgr::GetInstance().Init();
569     OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_INACTIVE;
570 
571      /**
572      * @tc.steps: step1. test SetMissionContinueState when eventHandler is not nullptr;
573      */
574     DMSContinueSendMgr::GetInstance().SetMissionContinueState(0, state);
575     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
576 
577     /**
578      * @tc.steps: step2. test SetMissionContinueState when eventHandler is nullptr;
579      */
580     DMSContinueSendMgr::GetInstance().UnInit();
581     DMSContinueSendMgr::GetInstance().SetMissionContinueState(0, state);
582     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
583     DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState002 end" << std::endl;
584 }
585 
586 /**
587  * @tc.name: testDealSetMissionContinueStateBusiness001
588  * @tc.desc: test DealSetMissionContinueStateBusiness.
589  * @tc.type: FUNC
590  */
HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness001, TestSize.Level3)591 HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness001, TestSize.Level3)
592 {
593     DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness001 start" << std::endl;
594     OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
595     DMSContinueSendMgr::GetInstance().info_.currentMissionId = MISSIONID_01;
596 
597     /**
598      * @tc.steps: step1. test DealSetMissionContinueStateBusiness when missionId is invalid;
599      */
600     int32_t ret = DMSContinueSendMgr::GetInstance().DealSetMissionContinueStateBusiness(MISSIONID_02,
601         state);
602     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
603 
604     /**
605      * @tc.steps: step2. test DealUnfocusedBusiness when mission is not continueable;
606      */
607     DMSContinueSendMgr::GetInstance().info_.currentIsContinuable = false;
608     ret = DMSContinueSendMgr::GetInstance().DealSetMissionContinueStateBusiness(MISSIONID_01, state);
609     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
610 
611     DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness001 end" << std::endl;
612 }
613 
614 /**
615  * @tc.name: testDealSetMissionContinueStateBusiness002
616  * @tc.desc: test DealSetMissionContinueStateBusiness.
617  * @tc.type: FUNC
618  */
HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness002, TestSize.Level3)619 HWTEST_F(DMSContinueManagerTest, testDealSetMissionContinueStateBusiness002, TestSize.Level3)
620 {
621     DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness002 start" << std::endl;
622     DMSContinueSendMgr::GetInstance().info_.currentIsContinuable = true;
623     OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
624     int32_t ret = DMSContinueSendMgr::GetInstance().DealSetMissionContinueStateBusiness(MISSIONID_01, state);
625     EXPECT_NE(ret, ERR_OK);
626     DTEST_LOG << "DMSContinueManagerTest testDealSetMissionContinueStateBusiness002 end" << std::endl;
627 }
628 
629 #ifdef SUPPORT_COMMON_EVENT_SERVICE
630 /**
631  * @tc.name: testOnDeviceScreenOff001
632  * @tc.desc: test OnDeviceScreenOff normal
633  * @tc.type: FUNC
634  */
HWTEST_F(DMSContinueManagerTest, testOnDeviceScreenOff001, TestSize.Level1)635 HWTEST_F(DMSContinueManagerTest, testOnDeviceScreenOff001, TestSize.Level1)
636 {
637     DTEST_LOG << "DMSContinueManagerTest testOnDeviceScreenOff001 start" << std::endl;
638 
639     DistributedSchedUtil::MockManageMissions();
640      /**
641      * @tc.steps: step1. test OnDeviceScreenOff when eventHandler is not nullptr;
642      */
643     DMSContinueSendMgr::GetInstance().Init();
644     DMSContinueSendMgr::GetInstance().OnDeviceScreenOff();
645     EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
646 
647     /**
648      * @tc.steps: step2. test OnDeviceScreenOff when eventHandler is nullptr;
649      */
650     DMSContinueSendMgr::GetInstance().UnInit();
651     DMSContinueSendMgr::GetInstance().OnDeviceScreenOff();
652     EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
653     DTEST_LOG << "DMSContinueManagerTest testOnDeviceScreenOff001 end" << std::endl;
654 }
655 #endif
656 
657 /**
658  * @tc.name: testNotifyDeviceOffline001
659  * @tc.desc: test NotifyDeviceOffline normal
660  * @tc.type: FUNC
661  */
HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline001, TestSize.Level1)662 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline001, TestSize.Level1)
663 {
664     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline001 start" << std::endl;
665     DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId = NETWORKID_01;
666     DMSContinueRecvMgr::GetInstance().NotifyDeviceOffline(NETWORKID_01);
667 
668     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
669     DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
670     EXPECT_NE(DMSContinueRecvMgr::GetInstance().registerOnListener_.size(), 0);
671     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline001 end" << std::endl;
672 }
673 
674 /**
675  * @tc.name: testNotifyDeviceOffline002
676  * @tc.desc: test NotifyDeviceOffline networkId empty
677  * @tc.type: FUNC
678  */
HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline002, TestSize.Level1)679 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline002, TestSize.Level1)
680 {
681     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline002 start" << std::endl;
682     DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId = NETWORKID_01;
683     DMSContinueRecvMgr::GetInstance().NotifyDeviceOffline("");
684     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId, NETWORKID_01);
685 
686     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline002 end" << std::endl;
687 }
688 
689 /**
690  * @tc.name: testNotifyDeviceOffline003
691  * @tc.desc: test NotifyDeviceOffline networkId not match
692  * @tc.type: FUNC
693  */
HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline003, TestSize.Level1)694 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline003, TestSize.Level1)
695 {
696     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 start" << std::endl;
697     DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId = NETWORKID_01;
698     DMSContinueRecvMgr::GetInstance().NotifyDeviceOffline(NETWORKID_02);
699     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId, NETWORKID_01);
700 
701     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 end" << std::endl;
702 }
703 
704 /**
705  * @tc.name: NotifyPackageRemoved001
706  * @tc.desc: test NotifyPackageRemoved normal
707  * @tc.type: FUNC
708  */
HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved001, TestSize.Level1)709 HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved001, TestSize.Level1)
710 {
711     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved001 start" << std::endl;
712     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
713     DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01);
714     EXPECT_NE(DMSContinueRecvMgr::GetInstance().registerOnListener_.size(), 0);
715 
716     DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName = BUNDLENAME_01;
717     DMSContinueRecvMgr::GetInstance().NotifyPackageRemoved(BUNDLENAME_01);
718     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName, "");
719 
720     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved001 end" << std::endl;
721 }
722 
723 /**
724  * @tc.name: NotifyPackageRemoved002
725  * @tc.desc: test NotifyPackageRemoved bundleName empty
726  * @tc.type: FUNC
727  */
HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved002, TestSize.Level1)728 HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved002, TestSize.Level1)
729 {
730     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved002 start" << std::endl;
731     DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName = BUNDLENAME_01;
732     DMSContinueRecvMgr::GetInstance().NotifyPackageRemoved("");
733     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName, BUNDLENAME_01);
734 
735     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved002 end" << std::endl;
736 }
737 
738 /**
739  * @tc.name: NotifyPackageRemoved003
740  * @tc.desc: test NotifyPackageRemoved bundleName not match
741  * @tc.type: FUNC
742  */
HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved003, TestSize.Level1)743 HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved003, TestSize.Level1)
744 {
745     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved003 start" << std::endl;
746     DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName = BUNDLENAME_01;
747     DMSContinueRecvMgr::GetInstance().NotifyPackageRemoved(BUNDLENAME_02);
748     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName, BUNDLENAME_01);
749 
750     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved003 end" << std::endl;
751 }
752 
753 /**
754  * @tc.name: testNotifyDataRecv001
755  * @tc.desc: NotifyDataRecv
756  * @tc.type: FUNC
757  */
HWTEST_F(DMSContinueManagerTest, testNotifyDataRecv001, TestSize.Level1)758 HWTEST_F(DMSContinueManagerTest, testNotifyDataRecv001, TestSize.Level1)
759 {
760     DTEST_LOG << "DMSContinueManagerTest testNotifyDataRecv001 start" << std::endl;
761     std::string senderNetworkId = NETWORKID_01;
762     uint8_t payload[] = {0xf0};
763     uint32_t dataLen1 = DMS_SEND_LEN - 1;
764     DMSContinueRecvMgr::GetInstance().NotifyDataRecv(senderNetworkId, payload, dataLen1);
765 
766     uint32_t dataLen2 = DMS_SEND_LEN;
767     DMSContinueRecvMgr::GetInstance().NotifyDataRecv(senderNetworkId, payload, dataLen2);
768     EXPECT_NE(payload[0] & DMS_0X0F, sizeof(uint32_t));
769     DTEST_LOG << "DMSContinueManagerTest testNotifyDataRecv001 end" << std::endl;
770 }
771 
772 /**
773  * @tc.name: testSendSoftbusEvent001
774  * @tc.desc: SendSoftbusEvent
775  * @tc.type: FUNC
776  */
HWTEST_F(DMSContinueManagerTest, testSendSoftbusEvent001, TestSize.Level1)777 HWTEST_F(DMSContinueManagerTest, testSendSoftbusEvent001, TestSize.Level1)
778 {
779     DTEST_LOG << "DMSContinueManagerTest testSendSoftbusEvent001 start" << std::endl;
780     uint16_t bundleNameId = 0;
781     uint8_t continueType = 1;
782     uint8_t type = 0;
783     bool ret = DMSContinueSendMgr::GetInstance().SendSoftbusEvent(bundleNameId, continueType, type);
784     EXPECT_NE(ret, CAN_NOT_FOUND_ABILITY_ERR);
785     DTEST_LOG << "DMSContinueManagerTest testSendSoftbusEvent001 end" << std::endl;
786 }
787 
788 /**
789  * @tc.name: testNotifyDeviceOnline001
790  * @tc.desc: NotifyDeviceOnline
791  * @tc.type: FUNC
792  */
HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOnline001, TestSize.Level1)793 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOnline001, TestSize.Level1)
794 {
795     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOnline001 start" << std::endl;
796     int32_t ret = DMSContinueSendMgr::GetInstance().NotifyDeviceOnline();
797     EXPECT_EQ(ret, ERR_OK);
798     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOnline001 end" << std::endl;
799 }
800 
801 /**
802  * @tc.name: testGetAbilityNameByMissionId_001
803  * @tc.desc: test GetAbilityNameByMissionId
804  * @tc.type: FUNC
805  */
HWTEST_F(DMSContinueManagerTest, testGetAbilityNameByMissionId_001, TestSize.Level1)806 HWTEST_F(DMSContinueManagerTest, testGetAbilityNameByMissionId_001, TestSize.Level1)
807 {
808     DTEST_LOG << "DMSContinueManagerTest testGetAbilityNameByMissionId_001 start" << std::endl;
809     DMSContinueSendMgr::GetInstance().focusedMissionAbility_[MISSIONID_01] = ABILITY_NAME_01;
810     std::string abilityName;
811     int32_t ret = DMSContinueSendMgr::GetInstance().GetAbilityNameByMissionId(MISSIONID_01, abilityName);
812     EXPECT_EQ(abilityName, ABILITY_NAME_01);
813     EXPECT_EQ(ret, ERR_OK);
814     DTEST_LOG << "DMSContinueManagerTest testGetAbilityNameByMissionId_001 end" << std::endl;
815 }
816 
817 /**
818  * @tc.name: testFocusedBusinessSendEvent_001
819  * @tc.desc: test FocusedBusinessSendEvent
820  * @tc.type: FUNC
821  */
HWTEST_F(DMSContinueManagerTest, testFocusedBusinessSendEvent_001, TestSize.Level1)822 HWTEST_F(DMSContinueManagerTest, testFocusedBusinessSendEvent_001, TestSize.Level1)
823 {
824     DTEST_LOG << "DMSContinueManagerTest testFocusedBusinessSendEvent_001 start" << std::endl;
825     int32_t ret = DMSContinueSendMgr::GetInstance().FocusedBusinessSendEvent(BUNDLENAME_01, ABILITY_NAME_01);
826 
827     EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR);
828     DTEST_LOG << "DMSContinueManagerTest testFocusedBusinessSendEvent_001 end" << std::endl;
829 }
830 
831 /**
832  * @tc.name: testGetBundleNameIdAndContinueTypeId_001
833  * @tc.desc: test GetBundleNameIdAndContinueTypeId
834  * @tc.type: FUNC
835  */
HWTEST_F(DMSContinueManagerTest, testGetBundleNameIdAndContinueTypeId_001, TestSize.Level1)836 HWTEST_F(DMSContinueManagerTest, testGetBundleNameIdAndContinueTypeId_001, TestSize.Level1)
837 {
838     DTEST_LOG << "DMSContinueManagerTest testGetBundleNameIdAndContinueTypeId_001 start" << std::endl;
839     DMSContinueSendMgr::GetInstance().focusedMission_[BUNDLENAME_01] = MISSIONID_01;
840     DMSContinueSendMgr::GetInstance().focusedMissionAbility_[MISSIONID_01] = ABILITY_NAME_01;
841     uint16_t bundleNameId = 0;
842     uint8_t continueTypeId = 0;
843     OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_ACTIVE;
844     int32_t ret = DMSContinueSendMgr::GetInstance().GetBundleNameIdAndContinueTypeId(MISSIONID_01, state,
845         bundleNameId, continueTypeId);
846 
847     EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR);
848     DTEST_LOG << "DMSContinueManagerTest testGetBundleNameIdAndContinueTypeId_001 end" << std::endl;
849 }
850 
851 /**
852  * @tc.name: testGetContinueType_001
853  * @tc.desc: test GetContinueType
854  * @tc.type: FUNC
855  */
HWTEST_F(DMSContinueManagerTest, testGetContinueType_001, TestSize.Level1)856 HWTEST_F(DMSContinueManagerTest, testGetContinueType_001, TestSize.Level1)
857 {
858     DTEST_LOG << "DMSContinueManagerTest testGetContinueType_001 start" << std::endl;
859     int32_t state = ACTIVE;
860     std::string networkId = "test networkId";
861     std::string sourceBundleName = "test sourceBundleName";
862     std::string sinkBundleName = "test sinkBundleName";
863     std::string continueType = "test continueType";
864     int32_t ret = DMSContinueRecvMgr::GetInstance().VerifyBroadcastSource(networkId,
865         sourceBundleName, sinkBundleName, continueType, state);
866     EXPECT_EQ(ret, ERR_OK);
867 
868     EXPECT_FALSE(DMSContinueRecvMgr::GetInstance().GetContinueType(sinkBundleName).empty());
869     DTEST_LOG << "DMSContinueManagerTest testGetContinueType_001 end" << std::endl;
870 }
871 
872 /**
873  * @tc.name: testSetScreenOffInfo_001
874  * @tc.desc: test SetScreenOffInfo
875  * @tc.type: FUNC
876  */
HWTEST_F(DMSContinueManagerTest, testSetScreenOffInfo_001, TestSize.Level1)877 HWTEST_F(DMSContinueManagerTest, testSetScreenOffInfo_001, TestSize.Level1)
878 {
879     DTEST_LOG << "DMSContinueManagerTest testSetScreenOffInfo_001 start" << std::endl;
880     int32_t missionId = 0;
881     std::string bundleName = "bundleName";
882     uint16_t bundleNameId = 0;
883     std::string abilityName = "abilityName";
884     DMSContinueSendMgr::GetInstance().screenOffHandler_ = std::make_shared<DMSContinueSendMgr::ScreenOffHandler>();
885     DMSContinueSendMgr::GetInstance().screenOffHandler_->SetScreenOffInfo(missionId, bundleName,
886         bundleNameId, abilityName);
887     EXPECT_EQ(DMSContinueSendMgr::GetInstance().screenOffHandler_->unfoInfo_.abilityName.empty(), false);
888 
889     DMSContinueSendMgr::GetInstance().screenOffHandler_->ClearScreenOffInfo();
890     EXPECT_EQ(DMSContinueSendMgr::GetInstance().screenOffHandler_->unfoInfo_.abilityName.empty(), true);
891     DTEST_LOG << "DMSContinueManagerTest testSetScreenOffInfo_001 end" << std::endl;
892 }
893 
894 /**
895  * @tc.name: testSetStateSendEvent_001
896  * @tc.desc: test SetStateSendEvent
897  * @tc.type: FUNC
898  */
HWTEST_F(DMSContinueManagerTest, testSetStateSendEvent_001, TestSize.Level1)899 HWTEST_F(DMSContinueManagerTest, testSetStateSendEvent_001, TestSize.Level1)
900 {
901     DTEST_LOG << "DMSContinueManagerTest testSetStateSendEvent_001 start" << std::endl;
902     int32_t ret = DMSContinueSendMgr::GetInstance().SetStateSendEvent(0, 0,
903         AAFwk::ContinueState::CONTINUESTATE_INACTIVE);
904     EXPECT_NE(ret, DMS_PERMISSION_DENIED);
905 
906     ret = DMSContinueSendMgr::GetInstance().SetStateSendEvent(0, 0, AAFwk::ContinueState::CONTINUESTATE_ACTIVE);
907     EXPECT_NE(ret, DMS_PERMISSION_DENIED);
908     DTEST_LOG << "DMSContinueManagerTest testSetStateSendEvent_001 end" << std::endl;
909 }
910 
911 /**
912  * @tc.name: testGetContinueLaunchMissionInfo_001
913  * @tc.desc: test GetContinueLaunchMissionInfo
914  * @tc.type: FUNC
915  */
HWTEST_F(DMSContinueManagerTest, testGetContinueLaunchMissionInfo_001, TestSize.Level1)916 HWTEST_F(DMSContinueManagerTest, testGetContinueLaunchMissionInfo_001, TestSize.Level1)
917 {
918     DTEST_LOG << "DMSContinueManagerTest testGetContinueLaunchMissionInfo_001 start" << std::endl;
919     ContinueLaunchMissionInfo missionInfo = {"com.test.missionInfo", "MainAbility"};
920     DMSContinueSendMgr::GetInstance().continueLaunchMission_.clear();
921     int32_t ret = DMSContinueSendMgr::GetInstance().GetContinueLaunchMissionInfo(MISSIONID_01, missionInfo);
922     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
923 
924     DMSContinueSendMgr::GetInstance().continueLaunchMission_[missionInfo] = MISSIONID_01;
925     ret = DMSContinueSendMgr::GetInstance().GetContinueLaunchMissionInfo(MISSIONID_01, missionInfo);
926     EXPECT_EQ(ret, ERR_OK);
927     DTEST_LOG << "DMSContinueManagerTest testGetContinueLaunchMissionInfo_001 end" << std::endl;
928 }
929 
930 /**
931  * @tc.name: testUpdateContinueLaunchMission_001
932  * @tc.desc: test UpdateContinueLaunchMission
933  * @tc.type: FUNC
934  */
HWTEST_F(DMSContinueManagerTest, testUpdateContinueLaunchMission_001, TestSize.Level1)935 HWTEST_F(DMSContinueManagerTest, testUpdateContinueLaunchMission_001, TestSize.Level1)
936 {
937     DTEST_LOG << "DMSContinueManagerTest testUpdateContinueLaunchMission_001 start" << std::endl;
938     AAFwk::Want want;
939     AppExecFwk::ElementName element("", "com.test.demo", "MainAbility", "");
940     want.SetElement(element);
941 
942     AAFwk::MissionInfo info;
943     info.id = MISSIONID_01;
944     info.want = want;
945     EXPECT_FALSE(DMSContinueSendMgr::GetInstance().UpdateContinueLaunchMission(info));
946 
947     info.want.SetFlags(AAFwk::Want::FLAG_ABILITY_CONTINUATION);
948     EXPECT_TRUE(DMSContinueSendMgr::GetInstance().UpdateContinueLaunchMission(info));
949 
950     info.id = MISSIONID_02;
951     EXPECT_TRUE(DMSContinueSendMgr::GetInstance().UpdateContinueLaunchMission(info));
952     DTEST_LOG << "DMSContinueManagerTest testUpdateContinueLaunchMission_001 end" << std::endl;
953 }
954 
955 /**
956  * @tc.name: testGetFinalBundleName_001
957  * @tc.desc: test GetFinalBundleName
958  * @tc.type: FUNC
959  */
HWTEST_F(DMSContinueManagerTest, testGetFinalBundleName_001, TestSize.Level1)960 HWTEST_F(DMSContinueManagerTest, testGetFinalBundleName_001, TestSize.Level1)
961 {
962     DTEST_LOG << "DMSContinueManagerTest testGetFinalBundleName_001 start" << std::endl;
963     DmsBundleInfo info;
964     std::string finalBundleName;
965     AppExecFwk::BundleInfo localBundleInfo;
966     std::string continueType;
967     bool ret = DMSContinueRecvMgr::GetInstance().GetFinalBundleName(info, finalBundleName,
968         localBundleInfo, continueType);
969     EXPECT_EQ(ret, false);
970     DTEST_LOG << "DMSContinueManagerTest testGetFinalBundleName_001 end" << std::endl;
971 }
972 
973 /**
974  * @tc.name: GetBundleNameByScreenOffInfo_001
975  * @tc.desc: test GetBundleNameByScreenOffInfo
976  * @tc.type: FUNC
977  */
HWTEST_F(DMSContinueManagerTest, GetBundleNameByScreenOffInfo_001, TestSize.Level1)978 HWTEST_F(DMSContinueManagerTest, GetBundleNameByScreenOffInfo_001, TestSize.Level1)
979 {
980     DTEST_LOG << "DMSContinueManagerTest GetBundleNameByScreenOffInfo_001 start" << std::endl;
981     DMSContinueSendMgr::GetInstance().screenOffHandler_ = nullptr;
982     int32_t missionId = 0;
983     std::string bundleName;
984     int32_t ret = DMSContinueSendMgr::GetInstance().GetBundleNameByScreenOffInfo(missionId, bundleName);
985     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
986 
987     DMSContinueSendMgr::GetInstance().screenOffHandler_ = std::make_shared<DMSContinueSendMgr::ScreenOffHandler>();
988     ret = DMSContinueSendMgr::GetInstance().GetBundleNameByScreenOffInfo(missionId, bundleName);
989     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
990 
991     DMSContinueSendMgr::GetInstance().screenOffHandler_->SetScreenOffInfo(0, "", 0, "");
992     ret = DMSContinueSendMgr::GetInstance().GetBundleNameByScreenOffInfo(missionId, bundleName);
993     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
994 
995     DMSContinueSendMgr::GetInstance().screenOffHandler_->SetScreenOffInfo(0, "bundleName", 0, "");
996     ret = DMSContinueSendMgr::GetInstance().GetBundleNameByScreenOffInfo(missionId, bundleName);
997     EXPECT_EQ(ret, ERR_OK);
998     DTEST_LOG << "DMSContinueManagerTest GetBundleNameByScreenOffInfo_001 end" << std::endl;
999 }
1000 
1001 /**
1002  * @tc.name: SendScreenOffEvent_001
1003  * @tc.desc: test SendScreenOffEvent
1004  * @tc.type: FUNC
1005  */
HWTEST_F(DMSContinueManagerTest, SendScreenOffEvent_001, TestSize.Level1)1006 HWTEST_F(DMSContinueManagerTest, SendScreenOffEvent_001, TestSize.Level1)
1007 {
1008     DTEST_LOG << "DMSContinueManagerTest SendScreenOffEvent_001 start" << std::endl;
1009     DMSContinueSendMgr::GetInstance().screenOffHandler_ = nullptr;
1010     int32_t ret = DMSContinueSendMgr::GetInstance().SendScreenOffEvent(DMS_FOCUSED_TYPE);
1011     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1012 
1013     DMSContinueSendMgr::GetInstance().screenOffHandler_ = std::make_shared<DMSContinueSendMgr::ScreenOffHandler>();
1014     ret = DMSContinueSendMgr::GetInstance().SendScreenOffEvent(DMS_FOCUSED_TYPE);
1015     EXPECT_NE(ret, ERR_OK);
1016     DTEST_LOG << "DMSContinueManagerTest SendScreenOffEvent_001 end" << std::endl;
1017 }
1018 
1019 /**
1020  * @tc.name: DeleteContinueLaunchMissionInfo_001
1021  * @tc.desc: test DeleteContinueLaunchMissionInfo
1022  * @tc.type: FUNC
1023  */
HWTEST_F(DMSContinueManagerTest, DeleteContinueLaunchMissionInfo_001, TestSize.Level1)1024 HWTEST_F(DMSContinueManagerTest, DeleteContinueLaunchMissionInfo_001, TestSize.Level1)
1025 {
1026     DTEST_LOG << "DMSContinueManagerTest DeleteContinueLaunchMissionInfo_001 start" << std::endl;
1027     int32_t missionId = 0;
1028     DMSContinueSendMgr::GetInstance().continueLaunchMission_.clear();
1029     DMSContinueSendMgr::GetInstance().DeleteContinueLaunchMissionInfo(missionId);
1030 
1031     ContinueLaunchMissionInfo info { "bundleName", "abilityName" };
1032     DMSContinueSendMgr::GetInstance().continueLaunchMission_[info] = 0;
1033     DMSContinueSendMgr::GetInstance().DeleteContinueLaunchMissionInfo(missionId);
1034     EXPECT_EQ(DMSContinueSendMgr::GetInstance().continueLaunchMission_.empty(), true);
1035     DTEST_LOG << "DMSContinueManagerTest DeleteContinueLaunchMissionInfo_001 end" << std::endl;
1036 }
1037 
1038 /**
1039  * @tc.name: CheckContinueState_001
1040  * @tc.desc: test CheckContinueState
1041  * @tc.type: FUNC
1042  */
HWTEST_F(DMSContinueManagerTest, CheckContinueState_001, TestSize.Level1)1043 HWTEST_F(DMSContinueManagerTest, CheckContinueState_001, TestSize.Level1)
1044 {
1045     DTEST_LOG << "DMSContinueManagerTest CheckContinueState_001 start" << std::endl;
1046     int32_t missionId = 0;
1047     int32_t ret = DMSContinueSendMgr::GetInstance().CheckContinueState(missionId);
1048     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1049     DTEST_LOG << "DMSContinueManagerTest CheckContinueState_001 end" << std::endl;
1050 }
1051 
1052 /**
1053  * @tc.name: OnContinueSwitchOff_001
1054  * @tc.desc: test OnContinueSwitchOff
1055  * @tc.type: FUNC
1056  */
HWTEST_F(DMSContinueManagerTest, OnContinueSwitchOff_001, TestSize.Level1)1057 HWTEST_F(DMSContinueManagerTest, OnContinueSwitchOff_001, TestSize.Level1)
1058 {
1059     DTEST_LOG << "DMSContinueManagerTest OnContinueSwitchOff_001 start" << std::endl;
1060     DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId = "";
1061     DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName = "";
1062     DMSContinueRecvMgr::GetInstance().iconInfo_.continueType = "";
1063     DMSContinueRecvMgr::GetInstance().OnContinueSwitchOff();
1064     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.isEmpty(), true);
1065 
1066     DMSContinueRecvMgr::GetInstance().iconInfo_.senderNetworkId = "senderNetworkId";
1067     DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName = "bundleName";
1068     DMSContinueRecvMgr::GetInstance().iconInfo_.continueType = "continueType";
1069     DMSContinueRecvMgr::GetInstance().registerOnListener_.clear();
1070     DMSContinueRecvMgr::GetInstance().OnContinueSwitchOff();
1071     EXPECT_EQ(DMSContinueRecvMgr::GetInstance().registerOnListener_.empty(), true);
1072     DTEST_LOG << "DMSContinueManagerTest OnContinueSwitchOff_001 end" << std::endl;
1073 }
1074 } // namespace DistributedSchedule
1075 } // namespace OHOS
1076