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 recvMgr->NotifyDeviceOffline("");
323 EXPECT_EQ(recvMgr->iconInfo_.senderNetworkId, NETWORKID_01);
324
325 DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline002 end" << std::endl;
326 }
327
328 /**
329 * @tc.name: testNotifyDeviceOffline003
330 * @tc.desc: test NotifyDeviceOffline networkId not match
331 * @tc.type: FUNC
332 */
333 HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline003, TestSize.Level1)
334 {
335 DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 start" << std::endl;
336 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
337 ASSERT_NE(nullptr, recvMgr);
338 recvMgr->iconInfo_.senderNetworkId = NETWORKID_01;
339 recvMgr->NotifyDeviceOffline(NETWORKID_02);
340 EXPECT_EQ(recvMgr->iconInfo_.senderNetworkId, NETWORKID_01);
341
342 DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 end" << std::endl;
343 }
344
345 /**
346 * @tc.name: NotifyPackageRemoved001
347 * @tc.desc: test NotifyPackageRemoved normal
348 * @tc.type: FUNC
349 */
350 HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved001, TestSize.Level1)
351 {
352 DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved001 start" << std::endl;
353 sptr<IRemoteObject> obj01(new RemoteOnListenerStubTest());
354 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
355 ASSERT_NE(nullptr, recvMgr);
356 recvMgr->RegisterOnListener(TYPE, obj01);
357 EXPECT_NE(recvMgr->registerOnListener_.size(), 0);
358
359 recvMgr->iconInfo_.bundleName = BUNDLENAME_01;
360 recvMgr->NotifyPackageRemoved(BUNDLENAME_01);
361 EXPECT_EQ(recvMgr->iconInfo_.bundleName, "");
362
363 DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved001 end" << std::endl;
364 }
365
366 /**
367 * @tc.name: NotifyPackageRemoved002
368 * @tc.desc: test NotifyPackageRemoved bundleName empty
369 * @tc.type: FUNC
370 */
371 HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved002, TestSize.Level1)
372 {
373 DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved002 start" << std::endl;
374 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
375 ASSERT_NE(nullptr, recvMgr);
376 recvMgr->iconInfo_.bundleName = BUNDLENAME_01;
377 recvMgr->NotifyPackageRemoved("");
378 EXPECT_EQ(recvMgr->iconInfo_.bundleName, BUNDLENAME_01);
379
380 DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved002 end" << std::endl;
381 }
382
383 /**
384 * @tc.name: NotifyPackageRemoved003
385 * @tc.desc: test NotifyPackageRemoved bundleName not match
386 * @tc.type: FUNC
387 */
388 HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved003, TestSize.Level1)
389 {
390 DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved003 start" << std::endl;
391 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
392 ASSERT_NE(nullptr, recvMgr);
393 recvMgr->iconInfo_.bundleName = BUNDLENAME_01;
394 recvMgr->NotifyPackageRemoved(BUNDLENAME_02);
395 EXPECT_EQ(recvMgr->iconInfo_.bundleName, BUNDLENAME_01);
396
397 DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved003 end" << std::endl;
398 }
399
400 /**
401 * @tc.name: testNotifyDataRecv001
402 * @tc.desc: NotifyDataRecv
403 * @tc.type: FUNC
404 */
405 HWTEST_F(DMSContinueManagerTest, testNotifyDataRecv001, TestSize.Level1)
406 {
407 DTEST_LOG << "DMSContinueManagerTest testNotifyDataRecv001 start" << std::endl;
408 std::string senderNetworkId = NETWORKID_01;
409 uint8_t payload[] = {0xf0};
410 uint32_t dataLen1 = DMS_SEND_LEN - 1;
411 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
412 ASSERT_NE(nullptr, recvMgr);
413 recvMgr->NotifyDataRecv(senderNetworkId, payload, dataLen1);
414
415 uint32_t dataLen2 = DMS_SEND_LEN;
416 recvMgr->NotifyDataRecv(senderNetworkId, payload, dataLen2);
417 EXPECT_NE(payload[0] & DMS_0X0F, sizeof(uint32_t));
418 DTEST_LOG << "DMSContinueManagerTest testNotifyDataRecv001 end" << std::endl;
419 }
420
421 /**
422 * @tc.name: testGetContinueType_001
423 * @tc.desc: test GetContinueType
424 * @tc.type: FUNC
425 */
426 HWTEST_F(DMSContinueManagerTest, testGetContinueType_001, TestSize.Level1)
427 {
428 DTEST_LOG << "DMSContinueManagerTest testGetContinueType_001 start" << std::endl;
429 int32_t state = ACTIVE;
430 std::string networkId = "test networkId";
431 std::string sourceBundleName = "test sourceBundleName";
432 std::string sinkBundleName = "test sinkBundleName";
433 std::string continueType = "test continueType";
434 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
435 ASSERT_NE(nullptr, recvMgr);
436 int32_t ret = recvMgr->VerifyBroadcastSource(networkId, sourceBundleName, sinkBundleName, continueType, state);
437 EXPECT_EQ(ret, ERR_OK);
438
439 EXPECT_FALSE(recvMgr->GetContinueType(sinkBundleName).empty());
440 DTEST_LOG << "DMSContinueManagerTest testGetContinueType_001 end" << std::endl;
441 }
442
443 /**
444 * @tc.name: testGetFinalBundleName_001
445 * @tc.desc: test GetFinalBundleName
446 * @tc.type: FUNC
447 */
448 HWTEST_F(DMSContinueManagerTest, testGetFinalBundleName_001, TestSize.Level1)
449 {
450 DTEST_LOG << "DMSContinueManagerTest testGetFinalBundleName_001 start" << std::endl;
451 DmsBundleInfo info;
452 std::string finalBundleName;
453 AppExecFwk::BundleInfo localBundleInfo;
454 std::string continueType;
455 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
456 ASSERT_NE(nullptr, recvMgr);
457 bool ret = recvMgr->GetFinalBundleName(info, finalBundleName, localBundleInfo, continueType);
458 EXPECT_EQ(ret, false);
459 DTEST_LOG << "DMSContinueManagerTest testGetFinalBundleName_001 end" << std::endl;
460 }
461
462 /**
463 * @tc.name: testIsBundleContinuable_001
464 * @tc.desc: all continuable = false => res = false
465 * @tc.type: FUNC
466 */
467 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_001, TestSize.Level1)
468 {
469 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_001 start" << std::endl;
470 std::string srcAbilityName = "abilityName";
471 std::string srcModuleName = "module1";
472 std::string srcContinueType = "continueType";
473
474 AppExecFwk::BundleInfo localBundleInfo;
475 std::vector<AppExecFwk::AbilityInfo> abilityInfos;
476 AppExecFwk::AbilityInfo abilityInfo;
477 std::vector<std::string> continueTypes;
478 continueTypes.push_back(srcContinueType);
479 abilityInfo.continueType = continueTypes;
480 abilityInfo.continuable = false;
481 abilityInfo.name = srcAbilityName;
482 abilityInfo.moduleName = srcModuleName;
483 abilityInfos.push_back(abilityInfo);
484
485 localBundleInfo.abilityInfos = abilityInfos;
486 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
487 ASSERT_NE(nullptr, recvMgr);
488 bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
489 EXPECT_EQ(ret, false);
490
491 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_001 end" << std::endl;
492 }
493
494 /**
495 * @tc.name: testIsBundleContinuable_002
496 * @tc.desc: continuable = true; same continueType => res = true
497 * @tc.type: FUNC
498 */
499 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_002, TestSize.Level1)
500 {
501 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 start" << std::endl;
502 std::string srcAbilityName = "abilityName";
503 std::string srcModuleName = "module1";
504 std::string srcContinueType = "continueType";
505
506 AppExecFwk::BundleInfo localBundleInfo;
507 std::vector<AppExecFwk::AbilityInfo> abilityInfos;
508 AppExecFwk::AbilityInfo abilityInfo;
509 std::vector<std::string> continueTypes;
510 continueTypes.push_back(srcContinueType + "_ContinueQuickStart");
511 abilityInfo.continueType = continueTypes;
512 abilityInfo.continuable = true;
513 abilityInfo.name = srcAbilityName;
514 abilityInfo.moduleName = srcModuleName;
515 abilityInfos.push_back(abilityInfo);
516
517 localBundleInfo.abilityInfos = abilityInfos;
518 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
519 ASSERT_NE(nullptr, recvMgr);
520 bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
521 EXPECT_EQ(ret, true);
522
523 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_002 end" << std::endl;
524 }
525
526 /**
527 * @tc.name: testIsBundleContinuable_003
528 * @tc.desc: continuable = true; diff continueType; diff BundleName => res = false;
529 * @tc.type: FUNC
530 */
531 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_003, TestSize.Level1)
532 {
533 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_003 start" << std::endl;
534 std::string srcAbilityName = "srcAbilityName";
535 std::string sinkAbilityName = "sinkAbilityName";
536 std::string srcModuleName = "module1";
537 std::string srcContinueType = "srcContinueType";
538 std::string sinkContinueType = "sinkContinueType";
539
540 AppExecFwk::BundleInfo localBundleInfo;
541 std::vector<AppExecFwk::AbilityInfo> abilityInfos;
542 AppExecFwk::AbilityInfo abilityInfo;
543 std::vector<std::string> continueTypes;
544 continueTypes.push_back(sinkContinueType + "_ContinueQuickStart");
545 abilityInfo.continueType = continueTypes;
546 abilityInfo.continuable = true;
547 abilityInfo.name = sinkAbilityName;
548 abilityInfo.moduleName = srcModuleName;
549 abilityInfos.push_back(abilityInfo);
550
551 localBundleInfo.abilityInfos = abilityInfos;
552 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
553 ASSERT_NE(nullptr, recvMgr);
554 bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
555 EXPECT_EQ(ret, false);
556 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_003 end" << std::endl;
557 }
558
559 /**
560 * @tc.name: testIsBundleContinuable_004
561 * @tc.desc: continuable = true; diff continueType; same abilityName; diff modulename => res = false;
562 * @tc.type: FUNC
563 */
564 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_004, TestSize.Level1)
565 {
566 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_004 start" << std::endl;
567 std::string srcAbilityName = "srcAbilityName";
568 std::string srcModuleName = "module1";
569 std::string sinkModuleName = "module2";
570 std::string srcContinueType = srcAbilityName;
571 std::string sinkContinueType = "sinkContinueType";
572
573 AppExecFwk::BundleInfo localBundleInfo;
574 std::vector<AppExecFwk::AbilityInfo> abilityInfos;
575 AppExecFwk::AbilityInfo abilityInfo;
576 std::vector<std::string> continueTypes;
577 continueTypes.push_back(sinkContinueType + "_ContinueQuickStart");
578 abilityInfo.continueType = continueTypes;
579 abilityInfo.continuable = true;
580 abilityInfo.name = srcAbilityName;
581 abilityInfo.moduleName = sinkModuleName;
582 abilityInfos.push_back(abilityInfo);
583
584 localBundleInfo.abilityInfos = abilityInfos;
585 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
586 ASSERT_NE(nullptr, recvMgr);
587 bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
588 EXPECT_EQ(ret, false);
589 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_004 end" << std::endl;
590 }
591
592 /**
593 * @tc.name: testIsBundleContinuable_004
594 * @tc.desc: continuable = true; diff continueType; same abilityName; same modulename => res = true;
595 * @tc.type: FUNC
596 */
597 HWTEST_F(DMSContinueManagerTest, testIsBundleContinuable_005, TestSize.Level1)
598 {
599 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_005 start" << std::endl;
600 std::string srcAbilityName = "srcAbilityName";
601 std::string srcModuleName = "module1";
602 std::string srcContinueType = srcAbilityName;
603 std::string sinkContinueType = "sinkContinueType";
604
605 AppExecFwk::BundleInfo localBundleInfo;
606 std::vector<AppExecFwk::AbilityInfo> abilityInfos;
607 AppExecFwk::AbilityInfo abilityInfo;
608 std::vector<std::string> continueTypes;
609 continueTypes.push_back(sinkContinueType + "_ContinueQuickStart");
610 abilityInfo.continueType = continueTypes;
611 abilityInfo.continuable = true;
612 abilityInfo.name = srcAbilityName;
613 abilityInfo.moduleName = srcModuleName;
614 abilityInfos.push_back(abilityInfo);
615
616 localBundleInfo.abilityInfos = abilityInfos;
617 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
618 ASSERT_NE(nullptr, recvMgr);
619 bool ret = recvMgr->IsBundleContinuable(localBundleInfo, srcAbilityName, srcModuleName, srcContinueType);
620 EXPECT_EQ(ret, true);
621 DTEST_LOG << "DMSContinueManagerTest testIsBundleContinuable_005 end" << std::endl;
622 }
623
624 /**
625 * @tc.name: OnContinueSwitchOff_001
626 * @tc.desc: test OnContinueSwitchOff
627 * @tc.type: FUNC
628 */
629 HWTEST_F(DMSContinueManagerTest, OnContinueSwitchOff_001, TestSize.Level1)
630 {
631 DTEST_LOG << "DMSContinueManagerTest OnContinueSwitchOff_001 start" << std::endl;
632 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
633 ASSERT_NE(nullptr, recvMgr);
634 recvMgr->iconInfo_.senderNetworkId = "";
635 recvMgr->iconInfo_.bundleName = "";
636 recvMgr->iconInfo_.continueType = "";
637 recvMgr->OnContinueSwitchOff();
638 EXPECT_EQ(recvMgr->iconInfo_.isEmpty(), true);
639
640 recvMgr->iconInfo_.senderNetworkId = "senderNetworkId";
641 recvMgr->iconInfo_.bundleName = "bundleName";
642 recvMgr->iconInfo_.continueType = "continueType";
643 recvMgr->registerOnListener_.clear();
644 recvMgr->OnContinueSwitchOff();
645 EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
646 DTEST_LOG << "DMSContinueManagerTest OnContinueSwitchOff_001 end" << std::endl;
647 }
648
649 /**
650 * @tc.name: OnUserSwitch_001
651 * @tc.desc: test OnUserSwitch
652 * @tc.type: FUNC
653 */
654 HWTEST_F(DMSContinueManagerTest, OnUserSwitch_001, TestSize.Level1)
655 {
656 DTEST_LOG << "DMSContinueManagerTest OnUserSwitch_001 start" << std::endl;
657 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
658 ASSERT_NE(nullptr, recvMgr);
659 recvMgr->iconInfo_.senderNetworkId = "";
660 recvMgr->iconInfo_.bundleName = "";
661 recvMgr->iconInfo_.continueType = "";
662 recvMgr->OnUserSwitch();
663 EXPECT_EQ(recvMgr->iconInfo_.isEmpty(), true);
664
665 recvMgr->iconInfo_.senderNetworkId = "senderNetworkId";
666 recvMgr->iconInfo_.bundleName = "bundleName";
667 recvMgr->iconInfo_.continueType = "continueType";
668 recvMgr->registerOnListener_.clear();
669 recvMgr->OnUserSwitch();
670 EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
671 DTEST_LOG << "DMSContinueManagerTest OnUserSwitch_001 end" << std::endl;
672 }
673
674 /**
675 * @tc.name: FindToNotifyRecvBroadcast_001
676 * @tc.desc: test FindToNotifyRecvBroadcast
677 * @tc.type: FUNC
678 */
679 HWTEST_F(DMSContinueManagerTest, FindToNotifyRecvBroadcast_001, TestSize.Level1)
680 {
681 DTEST_LOG << "DMSContinueManagerTest FindToNotifyRecvBroadcast_001 start" << std::endl;
682 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
683 ASSERT_NE(nullptr, recvMgr);
684 std::string senderNetworkId = "senderNetworkId";
685 std::string bundleName = "bundleName";
686 std::string continueType = "senderNetworkId";
687 recvMgr->iconInfo_.senderNetworkId = senderNetworkId;
688 recvMgr->iconInfo_.bundleName = bundleName;
689 recvMgr->iconInfo_.continueType = continueType;
690 recvMgr->registerOnListener_.clear();
691 recvMgr->FindToNotifyRecvBroadcast(senderNetworkId, bundleName, continueType);
692 EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
693 DTEST_LOG << "DMSContinueManagerTest FindToNotifyRecvBroadcast_001 end" << std::endl;
694 }
695
696 /**
697 * @tc.name: NotifyIconDisappear_001
698 * @tc.desc: test NotifyIconDisappear
699 * @tc.type: FUNC
700 */
701 HWTEST_F(DMSContinueManagerTest, NotifyIconDisappear_001, TestSize.Level1)
702 {
703 DTEST_LOG << "DMSContinueManagerTest NotifyIconDisappear_001 start" << std::endl;
704 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
705 ASSERT_NE(nullptr, recvMgr);
706 std::string senderNetworkId = "senderNetworkId";
707 std::string bundleName = "bundleName";
708 std::string continueType = "senderNetworkId";
709 uint16_t bundleNameId = 0;
710 std::string finalBundleName = "finalBundleName";
711 int32_t state = 0;
712 recvMgr->iconInfo_.senderNetworkId = senderNetworkId;
713 recvMgr->registerOnListener_.clear();
714 recvMgr->NotifyIconDisappear(bundleNameId, senderNetworkId, state);
715 EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
716 DTEST_LOG << "DMSContinueManagerTest NotifyIconDisappear_001 end" << std::endl;
717 }
718
719 /**
720 * @tc.name: NotifyDockDisplay_001
721 * @tc.desc: test NotifyDockDisplay
722 * @tc.type: FUNC
723 */
724 HWTEST_F(DMSContinueManagerTest, NotifyDockDisplay_001, TestSize.Level1)
725 {
726 DTEST_LOG << "DMSContinueManagerTest NotifyDockDisplay_001 start" << std::endl;
727 auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
728 ASSERT_NE(nullptr, recvMgr);
729 std::string senderNetworkId = "senderNetworkId";
730 std::string bundleName = "bundleName";
731 std::string continueType = "senderNetworkId";
732 uint16_t bundleNameId = 0;
733 std::string finalBundleName = "finalBundleName";
734 int32_t state = 0;
735 recvMgr->registerOnListener_.clear();
736 int32_t ret = recvMgr->NotifyDockDisplay(bundleNameId,
737 currentIconInfo(senderNetworkId, bundleName, finalBundleName, continueType), state);
738 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
739 std::vector<sptr<IRemoteObject>> objs;
740 {
741 std::lock_guard<std::mutex> registerOnListenerMapLock(recvMgr->eventMutex_);
742 recvMgr->registerOnListener_[TYPE] = objs;
743 }
744 ret = recvMgr->NotifyDockDisplay(bundleNameId,
745 currentIconInfo(senderNetworkId, bundleName, finalBundleName, continueType), state);
746 EXPECT_EQ(ret, ERR_OK);
747 DTEST_LOG << "DMSContinueManagerTest NotifyDockDisplay_001 end" << std::endl;
748 }
749 } // namespace DistributedSchedule
750 } // namespace OHOS
751