• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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/notification/dms_continue_recv_manager.h"
23 #undef private
24 #include "multi_user_manager.h"
25 #include "softbus_adapter/softbus_adapter.h"
26 #include "test_log.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace DistributedSchedule {
33 namespace {
34 const std::string TYPE = "type";
35 const std::string BUNDLENAME_01 = "bundleName01";
36 const std::string BUNDLENAME_02 = "bundleName02";
37 const std::string NETWORKID_01 = "networkId01";
38 const std::string NETWORKID_02 = "networkId02";
39 const std::string ABILITY_NAME_01 = "abilityName01";
40 const std::string CANCEL_FOCUSED_TASK = "cancel_mission_focused_task";
41 const int32_t WAITTIME = 2000;
42 constexpr static int32_t DMS_SEND_LEN = 5;
43 constexpr static uint8_t DMS_0X0F = 0x0f;
44 constexpr int32_t MISSIONID_01 = 1;
45 constexpr int32_t MISSIONID_02 = 2;
46 constexpr int32_t ACTIVE = 0;
47 constexpr int32_t INACTIVE = 1;
48 constexpr int32_t CANCEL_FOCUSED_DELAYED = 10000;
49 constexpr int32_t DBMS_RETRY_MAX_TIME = 5;
50 constexpr uint8_t DMS_FOCUSED_TYPE = 0x00;
51 }
52 
SendSoftbusEvent(std::shared_ptr<DSchedDataBuffer> buffer)53 int32_t SoftbusAdapter::SendSoftbusEvent(std::shared_ptr<DSchedDataBuffer> buffer)
54 {
55     return CAN_NOT_FOUND_ABILITY_ERR;
56 }
57 
SetUpTestCase()58 void DMSContinueManagerTest::SetUpTestCase()
59 {
60 }
61 
TearDownTestCase()62 void DMSContinueManagerTest::TearDownTestCase()
63 {
64 }
65 
SetUp()66 void DMSContinueManagerTest::SetUp()
67 {
68     MultiUserManager::GetInstance().Init();
69 }
70 
TearDown()71 void DMSContinueManagerTest::TearDown()
72 {
73 }
74 
OnCallback(const uint32_t ContinueState,const std::string & srcDeviceId,const std::string & bundleName,const std::string & continueType,const std::string & srcBundleName)75 void RemoteOnListenerStubTest::OnCallback(const uint32_t ContinueState, const std::string& srcDeviceId,
76     const std::string &bundleName, const std::string &continueType, const std::string &srcBundleName)
77 {
78 }
79 
80 /**
81  * @tc.name: testRegisterOnListener001
82  * @tc.desc: test RegisterOnListener
83  * @tc.type: FUNC
84  */
85 HWTEST_F(DMSContinueManagerTest, testRegisterOnListener001, TestSize.Level1)
86 {
87     DTEST_LOG << "DMSContinueManagerTest testRegisterOnListener001 start" << std::endl;
88     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
89     ASSERT_NE(nullptr, recvMgr);
90     int32_t accountId = 100;
91     recvMgr->Init(accountId);
92     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
93     int32_t ret = recvMgr->RegisterOnListener(TYPE, obj01);
94     EXPECT_EQ(ret, ERR_OK);
95 
96     ret = recvMgr->RegisterOnListener(TYPE, obj01);
97     EXPECT_EQ(ret, NO_MISSION_INFO_FOR_MISSION_ID);
98 
99     sptr<IRemoteObject> obj02(new RemoteOnListenerStubTest());
100     ret = recvMgr->RegisterOnListener(TYPE, obj02);
101     EXPECT_EQ(ret, ERR_OK);
102     recvMgr->UnInit();
103     DTEST_LOG << "DMSContinueManagerTest testRegisterOnListener001 end" << std::endl;
104 }
105 
106 /**
107  * @tc.name: testRegisterOffListener001
108  * @tc.desc: test RegisterOffListener
109  * @tc.type: FUNC
110  */
111 HWTEST_F(DMSContinueManagerTest, testRegisterOffListener001, TestSize.Level1)
112 {
113     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener001 start" << std::endl;
114     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
115     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
116     ASSERT_NE(nullptr, recvMgr);
117     int32_t ret = recvMgr->RegisterOnListener(TYPE, obj01);
118     ret = recvMgr->RegisterOffListener(TYPE, obj01);
119     EXPECT_EQ(ret, ERR_OK);
120 
121     ret = recvMgr->RegisterOffListener(TYPE, nullptr);
122     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
123     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener001 end" << std::endl;
124 }
125 
126 /**
127  * @tc.name: testRegisterOffListener002
128  * @tc.desc: test RegisterOffListener when iterItem->second is empty.
129  * @tc.type: FUNC
130  * @tc.require: I7F8KH
131  */
132 HWTEST_F(DMSContinueManagerTest, testRegisterOffListener002, TestSize.Level3)
133 {
134     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener002 start" << std::endl;
135     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
136     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
137     ASSERT_NE(nullptr, recvMgr);
138     int32_t ret = recvMgr->RegisterOnListener(TYPE, obj01);
139     EXPECT_EQ(ret, ERR_OK);
140 
141     {
142         std::lock_guard<std::mutex> registerOnListenerMapLock(recvMgr->eventMutex_);
143         recvMgr->registerOnListener_[TYPE].clear();
144     }
145     ret = recvMgr->RegisterOffListener(TYPE, obj01);
146     EXPECT_EQ(ret, ERR_OK);
147     DTEST_LOG << "DMSContinueManagerTest testRegisterOffListener002 end" << std::endl;
148 }
149 
150 /**
151  * @tc.name: testVerifyBroadcastSource001
152  * @tc.desc: test testVerifyBroadcastSource001.
153  * @tc.type: FUNC
154  */
155 HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource001, TestSize.Level3)
156 {
157     DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource001 start" << std::endl;
158 
159     int32_t state = ACTIVE;
160     std::string networkId = "test networkId";
161     std::string sourceBundleName = "test sourceBundleName";
162     std::string sinkBundleName = "test sinkBundleName";
163     std::string continueType = "test continueType";
164     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
165     ASSERT_NE(nullptr, recvMgr);
166     int32_t ret = recvMgr->VerifyBroadcastSource(networkId,
167         sourceBundleName, sinkBundleName, continueType, state);
168     EXPECT_EQ(ret, ERR_OK);
169 
170     state = INACTIVE;
171     ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state);
172     EXPECT_EQ(ret, ERR_OK);
173 }
174 
175 /**
176  * @tc.name: testVerifyBroadcastSource002
177  * @tc.desc: test testVerifyBroadcastSource002.
178  * @tc.type: FUNC
179  */
180 HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource002, TestSize.Level3)
181 {
182     DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource002 start" << std::endl;
183 
184     int32_t state = ACTIVE;
185     std::string networkId = "test networkId";
186     std::string sourceBundleName = "test sourceBundleName";
187     std::string sinkBundleName = "test sinkBundleName";
188     std::string continueType = "test continueType";
189     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
190     ASSERT_NE(nullptr, recvMgr);
191     int32_t ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state);
192     EXPECT_EQ(ret, ERR_OK);
193 
194     state = INACTIVE;
195     networkId = "invalid networkId";
196     ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state);
197     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
198 }
199 
200 /**
201  * @tc.name: testVerifyBroadcastSource003
202  * @tc.desc: test testVerifyBroadcastSource003.
203  * @tc.type: FUNC
204  */
205 HWTEST_F(DMSContinueManagerTest, testVerifyBroadcastSource003, TestSize.Level3)
206 {
207     DTEST_LOG << "DMSContinueManagerTest testVerifyBroadcastSource003 start" << std::endl;
208 
209     int32_t state = ACTIVE;
210     std::string networkId = "test networkId";
211     std::string sourceBundleName = "test sourceBundleName";
212     std::string sinkBundleName = "test sinkBundleName";
213     std::string continueType = "test continueType";
214     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
215     ASSERT_NE(nullptr, recvMgr);
216     int32_t ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state);
217     EXPECT_EQ(ret, ERR_OK);
218 
219     state = INACTIVE;
220     sourceBundleName = "invalid sourceBundleName";
221     sinkBundleName = "invalid sinkBundleName";
222     ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state);
223     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
224 }
225 
226 /**
227  * @tc.name: testDealOnBroadcastBusiness001
228  * @tc.desc: test DealOnBroadcastBusiness.
229  * @tc.type: FUNC
230  * @tc.require: I7F8KH
231  */
232 HWTEST_F(DMSContinueManagerTest, testDealOnBroadcastBusiness001, TestSize.Level3)
233 {
234     DTEST_LOG << "DMSContinueManagerTest testDealOnBroadcastBusiness001 start" << std::endl;
235 
236     /**
237      * @tc.steps: step1. test DealOnBroadcastBusiness when senderNetworkId is invalid;
238      */
239     std::string senderNetworkId = "invalid senderNetworkId";
240     uint16_t bundleNameId = 0;
241     uint8_t continueTypeId = 0;
242     int32_t state = 0;
243 
244     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
245     ASSERT_NE(nullptr, recvMgr);
246     recvMgr->PostOnBroadcastBusiness(senderNetworkId, bundleNameId, continueTypeId, state);
247 
248     int32_t ret = recvMgr->DealOnBroadcastBusiness(senderNetworkId, bundleNameId, continueTypeId, state, 0);
249     EXPECT_EQ(ret, ERR_OK);
250 
251     ret = recvMgr->DealOnBroadcastBusiness(senderNetworkId, bundleNameId, continueTypeId, state, DBMS_RETRY_MAX_TIME);
252     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
253 
254     /**
255      * @tc.steps: step2. test NotifyRecvBroadcast when obj is nullptr;
256      */
257     sptr<IRemoteObject> obj = nullptr;
258     std::string networkId = "invalid networkId";
259     std::string sourceBundleName = "invalid sourceBundleName";
260     std::string sinkBundleName = "invalid sinkBundleName";
261     std::string continueType = "invalid continueType";
262     recvMgr->NotifyRecvBroadcast(obj,
263         currentIconInfo(networkId, sourceBundleName, sinkBundleName, continueType), state);
264 
265     /**
266      * @tc.steps: step3. test NotifyRecvBroadcast when missionId is invalid;
267      */
268     obj =  new RemoteOnListenerStubTest();
269     recvMgr->NotifyRecvBroadcast(obj,
270         currentIconInfo(networkId, sourceBundleName, sinkBundleName, continueType), state);
271 
272     DTEST_LOG << "DMSContinueManagerTest testDealOnBroadcastBusiness001 end" << std::endl;
273 }
274 
275 /**
276  * @tc.name: testNotifyDied001
277  * @tc.desc: test NotifyDied
278  * @tc.type: FUNC
279  */
280 HWTEST_F(DMSContinueManagerTest, testNotifyDied001, TestSize.Level1)
281 {
282     DTEST_LOG << "DMSContinueManagerTest testNotifyDied001 start" << std::endl;
283     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
284     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
285     ASSERT_NE(nullptr, recvMgr);
286     int32_t ret = recvMgr->RegisterOnListener(TYPE, obj01);
287     EXPECT_EQ(false, recvMgr->registerOnListener_.empty());
288     recvMgr->NotifyDied(obj01);
289     DTEST_LOG << "DMSContinueManagerTest testNotifyDied001 end" << std::endl;
290 }
291 
292 /**
293  * @tc.name: testNotifyDeviceOffline001
294  * @tc.desc: test NotifyDeviceOffline normal
295  * @tc.type: FUNC
296  */
297 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline001, TestSize.Level1)
298 {
299     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline001 start" << std::endl;
300     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
301     ASSERT_NE(nullptr, recvMgr);
302     recvMgr->iconInfo_.senderNetworkId = NETWORKID_01;
303     recvMgr->NotifyDeviceOffline(NETWORKID_01);
304 
305     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
306     recvMgr->RegisterOnListener(TYPE, obj01);
307     EXPECT_NE(recvMgr->registerOnListener_.size(), 0);
308     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline001 end" << std::endl;
309 }
310 
311 /**
312  * @tc.name: testNotifyDeviceOffline002
313  * @tc.desc: test NotifyDeviceOffline networkId empty
314  * @tc.type: FUNC
315  */
316 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline002, TestSize.Level1)
317 {
318     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline002 start" << std::endl;
319     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
320     ASSERT_NE(nullptr, recvMgr);
321     recvMgr->iconInfo_.senderNetworkId = NETWORKID_01;
322     EXPECT_NO_FATAL_FAILURE(recvMgr->NotifyDeviceOffline(""));
323 
324     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline002 end" << std::endl;
325 }
326 
327 /**
328  * @tc.name: testNotifyDeviceOffline003
329  * @tc.desc: test NotifyDeviceOffline networkId not match
330  * @tc.type: FUNC
331  */
332 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline003, TestSize.Level1)
333 {
334     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 start" << std::endl;
335     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
336     ASSERT_NE(nullptr, recvMgr);
337     recvMgr->iconInfo_.senderNetworkId = NETWORKID_01;
338     EXPECT_NO_FATAL_FAILURE(recvMgr->NotifyDeviceOffline(NETWORKID_02));
339 
340     DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 end" << std::endl;
341 }
342 
343 /**
344  * @tc.name: NotifyPackageRemoved001
345  * @tc.desc: test NotifyPackageRemoved normal
346  * @tc.type: FUNC
347  */
348 HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved001, TestSize.Level1)
349 {
350     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved001 start" << std::endl;
351     sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
352     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
353     ASSERT_NE(nullptr, recvMgr);
354     recvMgr->RegisterOnListener(TYPE, obj01);
355     EXPECT_NE(recvMgr->registerOnListener_.size(), 0);
356 
357     recvMgr->iconInfo_.bundleName = BUNDLENAME_01;
358     recvMgr->NotifyPackageRemoved(BUNDLENAME_01);
359     EXPECT_EQ(recvMgr->iconInfo_.bundleName, "");
360 
361     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved001 end" << std::endl;
362 }
363 
364 /**
365  * @tc.name: NotifyPackageRemoved002
366  * @tc.desc: test NotifyPackageRemoved bundleName empty
367  * @tc.type: FUNC
368  */
369 HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved002, TestSize.Level1)
370 {
371     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved002 start" << std::endl;
372     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
373     ASSERT_NE(nullptr, recvMgr);
374     recvMgr->iconInfo_.bundleName = BUNDLENAME_01;
375     EXPECT_NO_FATAL_FAILURE(recvMgr->NotifyPackageRemoved(""));
376 
377     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved002 end" << std::endl;
378 }
379 
380 /**
381  * @tc.name: NotifyPackageRemoved003
382  * @tc.desc: test NotifyPackageRemoved bundleName not match
383  * @tc.type: FUNC
384  */
385 HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved003, TestSize.Level1)
386 {
387     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved003 start" << std::endl;
388     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
389     ASSERT_NE(nullptr, recvMgr);
390     recvMgr->iconInfo_.bundleName = BUNDLENAME_01;
391     EXPECT_NO_FATAL_FAILURE(recvMgr->NotifyPackageRemoved(BUNDLENAME_02));
392 
393     DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved003 end" << std::endl;
394 }
395 
396 /**
397  * @tc.name: testNotifyDataRecv001
398  * @tc.desc: NotifyDataRecv
399  * @tc.type: FUNC
400  */
401 HWTEST_F(DMSContinueManagerTest, testNotifyDataRecv001, TestSize.Level1)
402 {
403     DTEST_LOG << "DMSContinueManagerTest testNotifyDataRecv001 start" << std::endl;
404     std::string senderNetworkId = NETWORKID_01;
405     uint8_t payload[] = {0xf0};
406     uint32_t dataLen1 = DMS_SEND_LEN - 1;
407     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
408     ASSERT_NE(nullptr, recvMgr);
409     recvMgr->NotifyDataRecv(senderNetworkId, payload, dataLen1);
410 
411     uint32_t dataLen2 = DMS_SEND_LEN;
412     recvMgr->NotifyDataRecv(senderNetworkId, payload, dataLen2);
413     EXPECT_NE(payload[0] & DMS_0X0F, sizeof(uint32_t));
414     DTEST_LOG << "DMSContinueManagerTest testNotifyDataRecv001 end" << std::endl;
415 }
416 
417 /**
418  * @tc.name: testGetContinueType_001
419  * @tc.desc: test GetContinueType
420  * @tc.type: FUNC
421  */
422 HWTEST_F(DMSContinueManagerTest, testGetContinueType_001, TestSize.Level1)
423 {
424     DTEST_LOG << "DMSContinueManagerTest testGetContinueType_001 start" << std::endl;
425     int32_t state = ACTIVE;
426     std::string networkId = "test networkId";
427     std::string sourceBundleName = "test sourceBundleName";
428     std::string sinkBundleName = "test sinkBundleName";
429     std::string continueType = "test continueType";
430     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
431     ASSERT_NE(nullptr, recvMgr);
432     int32_t ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state);
433     EXPECT_EQ(ret, ERR_OK);
434 
435     EXPECT_FALSE(recvMgr->GetContinueType(sinkBundleName).empty());
436     DTEST_LOG << "DMSContinueManagerTest testGetContinueType_001 end" << std::endl;
437 }
438 
439 /**
440  * @tc.name: testGetFinalBundleName_001
441  * @tc.desc: test GetFinalBundleName
442  * @tc.type: FUNC
443  */
444 HWTEST_F(DMSContinueManagerTest, testGetFinalBundleName_001, TestSize.Level1)
445 {
446     DTEST_LOG << "DMSContinueManagerTest testGetFinalBundleName_001 start" << std::endl;
447     DmsBundleInfo info;
448     std::string finalBundleName;
449     AppExecFwk::BundleInfo localBundleInfo;
450     std::string continueType;
451     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
452     ASSERT_NE(nullptr, recvMgr);
453     bool ret = recvMgr->GetFinalBundleName(info, finalBundleName, localBundleInfo, continueType);
454     EXPECT_EQ(ret, false);
455     DTEST_LOG << "DMSContinueManagerTest testGetFinalBundleName_001 end" << std::endl;
456 }
457 
458 /**
459  * @tc.name: testIsBundleContinuable_001
460  * @tc.desc: all continuable = false  => res = false
461  * @tc.type: FUNC
462  */
463 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_001, TestSize.Level1)
464 {
465     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_001 start" << std::endl;
466     std::string srcAbilityName = "abilityName";
467     std::string srcModuleName = "module1";
468     std::string srcContinueType = "continueType";
469 
470     AppExecFwk::BundleInfo localBundleInfo;
471     std::vector<AppExecFwk::AbilityInfo> abilityInfos;
472     AppExecFwk::AbilityInfo abilityInfo;
473     std::vector<std::string> continueTypes;
474     continueTypes.push_back(srcContinueType);
475     abilityInfo.continueType = continueTypes;
476     abilityInfo.continuable = false;
477     abilityInfo.name = srcAbilityName;
478     abilityInfo.moduleName = srcModuleName;
479     abilityInfos.push_back(abilityInfo);
480 
481     localBundleInfo.abilityInfos = abilityInfos;
482     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
483     ASSERT_NE(nullptr, recvMgr);
484     bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
485     EXPECT_EQ(ret, false);
486 
487     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_001 end" << std::endl;
488 }
489 
490 /**
491  * @tc.name: testIsBundleContinuable_002
492  * @tc.desc: continuable = true; same continueType  => res = true
493  * @tc.type: FUNC
494  */
495 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_002, TestSize.Level1)
496 {
497     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 start" << std::endl;
498     std::string srcAbilityName = "abilityName";
499     std::string srcModuleName = "module1";
500     std::string srcContinueType = "continueType";
501 
502     AppExecFwk::BundleInfo localBundleInfo;
503     std::vector<AppExecFwk::AbilityInfo> abilityInfos;
504     AppExecFwk::AbilityInfo abilityInfo;
505     std::vector<std::string> continueTypes;
506     continueTypes.push_back(srcContinueType + "_ContinueQuickStart");
507     abilityInfo.continueType = continueTypes;
508     abilityInfo.continuable = true;
509     abilityInfo.name = srcAbilityName;
510     abilityInfo.moduleName = srcModuleName;
511     abilityInfos.push_back(abilityInfo);
512 
513     localBundleInfo.abilityInfos = abilityInfos;
514     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
515     ASSERT_NE(nullptr, recvMgr);
516     bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
517     EXPECT_EQ(ret, true);
518 
519     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 end" << std::endl;
520 }
521 
522 /**
523  * @tc.name: testIsBundleContinuable_003
524  * @tc.desc: continuable = true; diff continueType; diff BundleName  => res = false;
525  * @tc.type: FUNC
526  */
527 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_003, TestSize.Level1)
528 {
529     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_003 start" << std::endl;
530     std::string srcAbilityName = "srcAbilityName";
531     std::string sinkAbilityName = "sinkAbilityName";
532     std::string srcModuleName = "module1";
533     std::string srcContinueType = "srcContinueType";
534     std::string sinkContinueType = "sinkContinueType";
535 
536     AppExecFwk::BundleInfo localBundleInfo;
537     std::vector<AppExecFwk::AbilityInfo> abilityInfos;
538     AppExecFwk::AbilityInfo abilityInfo;
539     std::vector<std::string> continueTypes;
540     continueTypes.push_back(sinkContinueType + "_ContinueQuickStart");
541     abilityInfo.continueType = continueTypes;
542     abilityInfo.continuable = true;
543     abilityInfo.name = sinkAbilityName;
544     abilityInfo.moduleName = srcModuleName;
545     abilityInfos.push_back(abilityInfo);
546 
547     localBundleInfo.abilityInfos = abilityInfos;
548     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
549     ASSERT_NE(nullptr, recvMgr);
550     bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
551     EXPECT_EQ(ret, false);
552     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_003 end" << std::endl;
553 }
554 
555 /**
556  * @tc.name: testIsBundleContinuable_004
557  * @tc.desc: continuable = true; diff continueType; same abilityName; diff modulename  => res = false;
558  * @tc.type: FUNC
559  */
560 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_004, TestSize.Level1)
561 {
562     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_004 start" << std::endl;
563     std::string srcAbilityName = "srcAbilityName";
564     std::string srcModuleName = "module1";
565     std::string sinkModuleName = "module2";
566     std::string srcContinueType = srcAbilityName;
567     std::string sinkContinueType = "sinkContinueType";
568 
569     AppExecFwk::BundleInfo localBundleInfo;
570     std::vector<AppExecFwk::AbilityInfo> abilityInfos;
571     AppExecFwk::AbilityInfo abilityInfo;
572     std::vector<std::string> continueTypes;
573     continueTypes.push_back(sinkContinueType + "_ContinueQuickStart");
574     abilityInfo.continueType = continueTypes;
575     abilityInfo.continuable = true;
576     abilityInfo.name = srcAbilityName;
577     abilityInfo.moduleName = sinkModuleName;
578     abilityInfos.push_back(abilityInfo);
579 
580     localBundleInfo.abilityInfos = abilityInfos;
581     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
582     ASSERT_NE(nullptr, recvMgr);
583     bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
584     EXPECT_EQ(ret, false);
585     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_004 end" << std::endl;
586 }
587 
588 /**
589  * @tc.name: testIsBundleContinuable_004
590  * @tc.desc: continuable = true; diff continueType; same abilityName; same modulename  => res = true;
591  * @tc.type: FUNC
592  */
593 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_005, TestSize.Level1)
594 {
595     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_005 start" << std::endl;
596     std::string srcAbilityName = "srcAbilityName";
597     std::string srcModuleName = "module1";
598     std::string srcContinueType = srcAbilityName;
599     std::string sinkContinueType = "sinkContinueType";
600 
601     AppExecFwk::BundleInfo localBundleInfo;
602     std::vector<AppExecFwk::AbilityInfo> abilityInfos;
603     AppExecFwk::AbilityInfo abilityInfo;
604     std::vector<std::string> continueTypes;
605     continueTypes.push_back(sinkContinueType + "_ContinueQuickStart");
606     abilityInfo.continueType = continueTypes;
607     abilityInfo.continuable = true;
608     abilityInfo.name = srcAbilityName;
609     abilityInfo.moduleName = srcModuleName;
610     abilityInfos.push_back(abilityInfo);
611 
612     localBundleInfo.abilityInfos = abilityInfos;
613     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
614     ASSERT_NE(nullptr, recvMgr);
615     bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
616     EXPECT_EQ(ret, true);
617     DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_005 end" << std::endl;
618 }
619 
620 /**
621  * @tc.name: OnContinueSwitchOff_001
622  * @tc.desc: test OnContinueSwitchOff
623  * @tc.type: FUNC
624  */
625 HWTEST_F(DMSContinueManagerTest, OnContinueSwitchOff_001, TestSize.Level1)
626 {
627     DTEST_LOG << "DMSContinueManagerTest OnContinueSwitchOff_001 start" << std::endl;
628     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
629     ASSERT_NE(nullptr, recvMgr);
630     recvMgr->iconInfo_.senderNetworkId = "";
631     recvMgr->iconInfo_.bundleName = "";
632     recvMgr->iconInfo_.continueType = "";
633     recvMgr->OnContinueSwitchOff();
634     EXPECT_EQ(recvMgr->iconInfo_.isEmpty(), true);
635 
636     recvMgr->iconInfo_.senderNetworkId = "senderNetworkId";
637     recvMgr->iconInfo_.bundleName = "bundleName";
638     recvMgr->iconInfo_.continueType = "continueType";
639     recvMgr->registerOnListener_.clear();
640     recvMgr->OnContinueSwitchOff();
641     EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
642     DTEST_LOG << "DMSContinueManagerTest OnContinueSwitchOff_001 end" << std::endl;
643 }
644 
645 /**
646  * @tc.name: OnUserSwitch_001
647  * @tc.desc: test OnUserSwitch
648  * @tc.type: FUNC
649  */
650 HWTEST_F(DMSContinueManagerTest, OnUserSwitch_001, TestSize.Level1)
651 {
652     DTEST_LOG << "DMSContinueManagerTest OnUserSwitch_001 start" << std::endl;
653     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
654     ASSERT_NE(nullptr, recvMgr);
655     recvMgr->iconInfo_.senderNetworkId = "";
656     recvMgr->iconInfo_.bundleName = "";
657     recvMgr->iconInfo_.continueType = "";
658     recvMgr->OnUserSwitch();
659     EXPECT_EQ(recvMgr->iconInfo_.isEmpty(), true);
660 
661     recvMgr->iconInfo_.senderNetworkId = "senderNetworkId";
662     recvMgr->iconInfo_.bundleName = "bundleName";
663     recvMgr->iconInfo_.continueType = "continueType";
664     recvMgr->registerOnListener_.clear();
665     recvMgr->OnUserSwitch();
666     EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
667     DTEST_LOG << "DMSContinueManagerTest OnUserSwitch_001 end" << std::endl;
668 }
669 
670 /**
671  * @tc.name: FindToNotifyRecvBroadcast_001
672  * @tc.desc: test FindToNotifyRecvBroadcast
673  * @tc.type: FUNC
674  */
675 HWTEST_F(DMSContinueManagerTest, FindToNotifyRecvBroadcast_001, TestSize.Level1)
676 {
677     DTEST_LOG << "DMSContinueManagerTest FindToNotifyRecvBroadcast_001 start" << std::endl;
678     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
679     ASSERT_NE(nullptr, recvMgr);
680     std::string senderNetworkId = "senderNetworkId";
681     std::string bundleName = "bundleName";
682     std::string continueType = "senderNetworkId";
683     recvMgr->iconInfo_.senderNetworkId = senderNetworkId;
684     recvMgr->iconInfo_.bundleName = bundleName;
685     recvMgr->iconInfo_.continueType = continueType;
686     recvMgr->registerOnListener_.clear();
687     recvMgr->FindToNotifyRecvBroadcast(senderNetworkId, bundleName, continueType);
688     EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
689     DTEST_LOG << "DMSContinueManagerTest FindToNotifyRecvBroadcast_001 end" << std::endl;
690 }
691 
692 /**
693  * @tc.name: NotifyIconDisappear_001
694  * @tc.desc: test NotifyIconDisappear
695  * @tc.type: FUNC
696  */
697 HWTEST_F(DMSContinueManagerTest, NotifyIconDisappear_001, TestSize.Level1)
698 {
699     DTEST_LOG << "DMSContinueManagerTest NotifyIconDisappear_001 start" << std::endl;
700     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
701     ASSERT_NE(nullptr, recvMgr);
702     std::string senderNetworkId = "senderNetworkId";
703     std::string bundleName = "bundleName";
704     std::string continueType = "senderNetworkId";
705     uint16_t bundleNameId = 0;
706     std::string finalBundleName = "finalBundleName";
707     int32_t state = 0;
708     recvMgr->iconInfo_.senderNetworkId = senderNetworkId;
709     recvMgr->registerOnListener_.clear();
710     recvMgr->NotifyIconDisappear(bundleNameId, senderNetworkId, state);
711     EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
712     DTEST_LOG << "DMSContinueManagerTest NotifyIconDisappear_001 end" << std::endl;
713 }
714 
715 /**
716  * @tc.name: NotifyDockDisplay_001
717  * @tc.desc: test NotifyDockDisplay
718  * @tc.type: FUNC
719  */
720 HWTEST_F(DMSContinueManagerTest, NotifyDockDisplay_001, TestSize.Level1)
721 {
722     DTEST_LOG << "DMSContinueManagerTest NotifyDockDisplay_001 start" << std::endl;
723     auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
724     ASSERT_NE(nullptr, recvMgr);
725     std::string senderNetworkId = "senderNetworkId";
726     std::string bundleName = "bundleName";
727     std::string continueType = "senderNetworkId";
728     uint16_t bundleNameId = 0;
729     std::string finalBundleName = "finalBundleName";
730     int32_t state = 0;
731     recvMgr->registerOnListener_.clear();
732     int32_t ret = recvMgr->NotifyDockDisplay(bundleNameId,
733         currentIconInfo(senderNetworkId, bundleName, finalBundleName, continueType), state);
734     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
735     std::vector<sptr<IRemoteObject>> objs;
736     {
737         std::lock_guard<std::mutex> registerOnListenerMapLock(recvMgr->eventMutex_);
738         recvMgr->registerOnListener_[TYPE] = objs;
739     }
740     ret = recvMgr->NotifyDockDisplay(bundleNameId,
741         currentIconInfo(senderNetworkId, bundleName, finalBundleName, continueType), state);
742     EXPECT_EQ(ret, ERR_OK);
743     DTEST_LOG << "DMSContinueManagerTest NotifyDockDisplay_001 end" << std::endl;
744 }
745 } // namespace DistributedSchedule
746 } // namespace OHOS
747