1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "gtest/gtest.h"
16
17 #define private public
18 #define protected public
19 #include "ability_connect_callback_interface.h"
20 #include "ability_connect_callback_stub.h"
21 #include "ability_connection_wrapper_stub.h"
22 #include "device_manager.h"
23 #include "distributed_sched_service.h"
24 #include "distributed_sched_util.h"
25 #include "dtbschedmgr_device_info_storage.h"
26 #include "dtbschedmgr_log.h"
27 #include "if_system_ability_manager.h"
28 #include "ipc_skeleton.h"
29 #include "iservice_registry.h"
30 #include "parcel_helper.h"
31 #include "system_ability_definition.h"
32 #include "test_log.h"
33 #undef private
34 #undef protected
35
36 namespace OHOS {
37 namespace DistributedSchedule {
38 using namespace AAFwk;
39 using namespace testing;
40 using namespace testing::ext;
41 using namespace OHOS::DistributedHardware;
42
43 namespace {
44 const std::string TAG = "DistributedSchedConnectTest";
45 const std::u16string CONNECTION_CALLBACK_INTERFACE_TOKEN = u"ohos.abilityshell.DistributedConnection";
46 constexpr int32_t STDOUT_FD = 1;
47 constexpr int32_t REQUEST_CODE_ERR = 305;
48 constexpr int32_t ERROR_CONNECT_CODE = 1000;
49 }
50
51 class AbilityConnectCallbackTest : public AAFwk::AbilityConnectionStub {
52 public:
53 AbilityConnectCallbackTest() = default;
54 ~AbilityConnectCallbackTest() = default;
55
56 void OnAbilityConnectDone(const AppExecFwk::ElementName& element,
57 const sptr<IRemoteObject>& remoteObject, int32_t resultCode) override;
58 void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
59 int32_t resultCode) override;
60 };
61
62 class AbilityConnectionWrapperStubTest : public AAFwk::AbilityConnectionStub {
63 public:
AbilityConnectionWrapperStubTest(sptr<IRemoteObject> connection)64 explicit AbilityConnectionWrapperStubTest(sptr<IRemoteObject> connection) : distributedConnection_(connection) {}
65 ~AbilityConnectionWrapperStubTest() = default;
66
67 void OnAbilityConnectDone(const AppExecFwk::ElementName& element,
68 const sptr<IRemoteObject>& remoteObject, int32_t resultCode) override;
69 void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
70 int32_t resultCode) override;
71
72 private:
73 sptr<IRemoteObject> distributedConnection_;
74 };
75
76 class DistributedSchedConnectTest : public testing::Test {
77 public:
78 static void SetUpTestCase();
79 static void TearDownTestCase();
80 void SetUp();
81 void TearDown();
82
83 void AddSession(const sptr<IRemoteObject>& connect, const std::string& localDeviceId,
84 const std::string& remoteDeviceId, const AAFwk::Want& want) const;
85 void RemoveSession(const sptr<IRemoteObject>& connect) const;
86
87 void AddConnectInfo(const sptr<IRemoteObject>& connect, const std::string& localDeviceId,
88 const std::string& remoteDeviceId) const;
89 void RemoveConnectInfo(const sptr<IRemoteObject>& connect) const;
90
91 void AddConnectCount(int32_t uid) const;
92 void DecreaseConnectCount(int32_t uid) const;
93 sptr<IDistributedSched> GetDms();
94
95 class DeviceInitCallBack : public DmInitCallback {
96 void OnRemoteDied() override;
97 };
98 };
99
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)100 void AbilityConnectCallbackTest::OnAbilityConnectDone(const AppExecFwk::ElementName& element,
101 const sptr<IRemoteObject>& remoteObject, int32_t resultCode)
102 {
103 }
104
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)105 void AbilityConnectCallbackTest::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
106 int32_t resultCode)
107 {
108 }
109
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)110 void AbilityConnectionWrapperStubTest::OnAbilityConnectDone(const AppExecFwk::ElementName& element,
111 const sptr<IRemoteObject>& remoteObject, int32_t resultCode)
112 {
113 }
114
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int32_t resultCode)115 void AbilityConnectionWrapperStubTest::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
116 int32_t resultCode)
117 {
118 }
119
SetUpTestCase()120 void DistributedSchedConnectTest::SetUpTestCase()
121 {
122 const std::string pkgName = "DBinderBus_" + std::to_string(getpid());
123 std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
124 DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
125 }
126
TearDownTestCase()127 void DistributedSchedConnectTest::TearDownTestCase()
128 {
129 }
130
SetUp()131 void DistributedSchedConnectTest::SetUp()
132 {
133 DistributedSchedUtil::MockPermission();
134 }
135
TearDown()136 void DistributedSchedConnectTest::TearDown()
137 {
138 }
139
OnRemoteDied()140 void DistributedSchedConnectTest::DeviceInitCallBack::OnRemoteDied()
141 {
142 }
143
AddSession(const sptr<IRemoteObject> & connect,const std::string & localDeviceId,const std::string & remoteDeviceId,const AAFwk::Want & want) const144 void DistributedSchedConnectTest::AddSession(const sptr<IRemoteObject>& connect,
145 const std::string& localDeviceId, const std::string& remoteDeviceId, const AAFwk::Want& want) const
146 {
147 if (connect == nullptr) {
148 return;
149 }
150
151 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
152 CallerInfo callerInfo;
153 callerInfo.uid = IPCSkeleton::GetCallingUid();
154 callerInfo.pid = IPCSkeleton::GetCallingPid();
155 callerInfo.sourceDeviceId = localDeviceId;
156 callerInfo.callerType = CALLER_TYPE_HARMONY;
157 DistributedSchedService::GetInstance().RemoteConnectAbilityMappingLocked(connect, localDeviceId,
158 remoteDeviceId, want.GetElement(), callerInfo, TargetComponent::HARMONY_COMPONENT);
159 }
160
RemoveSession(const sptr<IRemoteObject> & connect) const161 void DistributedSchedConnectTest::RemoveSession(const sptr<IRemoteObject>& connect) const
162 {
163 if (connect == nullptr) {
164 return;
165 }
166
167 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
168 DistributedSchedService::GetInstance().distributedConnectAbilityMap_.erase(connect);
169 }
170
AddConnectInfo(const sptr<IRemoteObject> & connect,const std::string & localDeviceId,const std::string & remoteDeviceId) const171 void DistributedSchedConnectTest::AddConnectInfo(const sptr<IRemoteObject>& connect,
172 const std::string& localDeviceId, const std::string& remoteDeviceId) const
173 {
174 if (connect == nullptr) {
175 return;
176 }
177
178 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
179 CallerInfo callerInfo;
180 callerInfo.uid = IPCSkeleton::GetCallingUid();
181 callerInfo.pid = IPCSkeleton::GetCallingPid();
182 callerInfo.sourceDeviceId = localDeviceId;
183 callerInfo.callerType = CALLER_TYPE_HARMONY;
184
185 sptr<IRemoteObject> callbackWrapper = new AbilityConnectionWrapperStubTest(connect);
186 ConnectInfo connectInfo {callerInfo, callbackWrapper};
187 DistributedSchedService::GetInstance().connectAbilityMap_.emplace(connect, connectInfo);
188 }
189
RemoveConnectInfo(const sptr<IRemoteObject> & connect) const190 void DistributedSchedConnectTest::RemoveConnectInfo(const sptr<IRemoteObject>& connect) const
191 {
192 if (connect == nullptr) {
193 return;
194 }
195
196 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
197 DistributedSchedService::GetInstance().connectAbilityMap_.erase(connect);
198 }
199
AddConnectCount(int32_t uid) const200 void DistributedSchedConnectTest::AddConnectCount(int32_t uid) const
201 {
202 if (uid < 0) {
203 return;
204 }
205
206 auto& trackingUidMap = DistributedSchedService::GetInstance().trackingUidMap_;
207 ++trackingUidMap[uid];
208 }
209
DecreaseConnectCount(int32_t uid) const210 void DistributedSchedConnectTest::DecreaseConnectCount(int32_t uid) const
211 {
212 if (uid < 0) {
213 return;
214 }
215
216 DistributedSchedService::GetInstance().DecreaseConnectLocked(uid);
217 }
218
GetDms()219 sptr<IDistributedSched> DistributedSchedConnectTest::GetDms()
220 {
221 auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
222 if (sm == nullptr) {
223 DTEST_LOG << "DistributedSchedConnectTest sm is nullptr" << std::endl;
224 return nullptr;
225 }
226 auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
227 if (distributedObject == nullptr) {
228 DTEST_LOG << "distributedObject sm is nullptr" << std::endl;
229 return nullptr;
230 }
231 EXPECT_TRUE(distributedObject != nullptr);
232 return iface_cast<IDistributedSched>(distributedObject);
233 }
234
235 /**
236 * @tc.name: DumpConnectInfo_001
237 * @tc.desc: dump connect ability info by call Dump
238 * @tc.type: FUNC
239 */
240 HWTEST_F(DistributedSchedConnectTest, DumpConnectInfo_001, TestSize.Level1)
241 {
242 DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_001 start " << std::endl;
243 sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
244 if (samgr == nullptr) {
245 DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_001 samgr null" << std::endl;
246 } else {
247 DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_001 available" << std::endl;
248 }
249
250 auto dms = samgr->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
251 std::vector<std::u16string> args;
252 args.push_back(u"-connect");
253 int32_t result = dms->Dump(STDOUT_FD, args);
254 DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_001 dump result: " << result << std::endl;
255 }
256
257 /**
258 * @tc.name: DumpConnectInfo_002
259 * @tc.desc: dump connect ability info by call DumpConnectInfo
260 * @tc.type: FUNC
261 */
262 HWTEST_F(DistributedSchedConnectTest, DumpConnectInfo_002, TestSize.Level0)
263 {
264 DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_002 start" << std::endl;
265 OHOS::AAFwk::Want want;
266 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
267
268 /**
269 * @tc.steps: step1. add one session
270 */
271 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
272 AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
273 /**
274 * @tc.steps: step2. and then dump connection info
275 * @tc.expected: step2. can find the newly-added connect session
276 */
277 std::string dumpInfo;
278 DistributedSchedService::GetInstance().DumpConnectInfo(dumpInfo);
279 DTEST_LOG << "DistributedSchedServiceTest DumpConnectInfo_002 dumpInfo " << dumpInfo << std::endl;
280 std::string::size_type pos = dumpInfo.find("123_remote_device_id");
281 EXPECT_NE(pos, std::string::npos);
282
283 RemoveSession(connect);
284 }
285
286 /**
287 * @tc.name: ProcessConnectDied001
288 * @tc.desc: process connect died
289 * @tc.type: FUNC
290 */
291 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied001, TestSize.Level1)
292 {
293 DTEST_LOG << "DistributedSchedServiceTest ProcessConnectDied001 start" << std::endl;
294 OHOS::AAFwk::Want want;
295 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
296 auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
297 auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
298
299 /**
300 * @tc.steps: step1. add one session and check the map
301 * @tc.expected: step1. can find the newly-added connect session
302 */
303 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
304 AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
305 {
306 std::lock_guard<std::mutex> autoLock(distributedLock);
307 EXPECT_EQ(connectionMap.size(), static_cast<size_t>(1));
308 }
309
310 /**
311 * @tc.steps: step2. process connect died and then check the map
312 * @tc.expected: step2. the connect session is removed
313 */
314 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
315 {
316 std::lock_guard<std::mutex> autoLock(distributedLock);
317 EXPECT_EQ(connectionMap.size(), static_cast<size_t>(0));
318 }
319
320 RemoveSession(connect);
321 }
322
323 /**
324 * @tc.name: ProcessConnectDied002
325 * @tc.desc: process connect died which is not exist
326 * @tc.type: FUNC
327 */
328 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied002, TestSize.Level0)
329 {
330 DTEST_LOG << "DistributedSchedServiceTest ProcessConnectDied002 start" << std::endl;
331 OHOS::AAFwk::Want want;
332 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
333 auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
334 auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
335
336 /**
337 * @tc.steps: step1. add one session
338 * @tc.expected: step1. can find the newly-added connect session
339 */
340 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
341 AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
342 {
343 std::lock_guard<std::mutex> autoLock(distributedLock);
344 EXPECT_EQ(connectionMap.size(), static_cast<size_t>(1));
345 }
346
347 /**
348 * @tc.steps: step2. process connect died which is not exist
349 * @tc.expected: step2. still can find the newly-added connect session
350 */
351 DistributedSchedService::GetInstance().ProcessConnectDied(new AbilityConnectCallbackTest());
352 {
353 std::lock_guard<std::mutex> autoLock(distributedLock);
354 EXPECT_EQ(connectionMap.size(), static_cast<size_t>(1));
355 }
356
357 RemoveSession(connect);
358 }
359
360 /**
361 * @tc.name: ProcessConnectDied003
362 * @tc.desc: process connect died and check the trackingUidMap_
363 * @tc.type: FUNC
364 */
365 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied003, TestSize.Level1)
366 {
367 DTEST_LOG << "DistributedSchedServiceTest ProcessConnectDied003 start" << std::endl;
368 OHOS::AAFwk::Want want;
369 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
370 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
371 AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
372
373 auto& trackingUidMap = DistributedSchedService::GetInstance().trackingUidMap_;
374 /**
375 * @tc.steps: step1. Increase connect count
376 * @tc.expected: step1. connect count increase one
377 */
378
379 int32_t uid = IPCSkeleton::GetCallingUid();
380 uint32_t oldCount = trackingUidMap[uid];
381 AddConnectCount(uid);
382 EXPECT_EQ(trackingUidMap[uid] - oldCount, static_cast<uint32_t>(1));
383
384 /**
385 * @tc.steps: step2. process connect died and then check the trackingUidMap_
386 * @tc.expected: step2. the connect count is decrease
387 */
388 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
389 auto iter = trackingUidMap.find(uid);
390 if (iter != trackingUidMap.end()) {
391 EXPECT_EQ(trackingUidMap[uid], oldCount);
392 }
393
394 RemoveConnectInfo(connect);
395 }
396
397 /**
398 * @tc.name: ProcessConnectDied004
399 * @tc.desc: process connect died and check the connectAbilityMap_
400 * @tc.type: FUNC
401 */
402 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied004, TestSize.Level1)
403 {
404 DTEST_LOG << "DistributedSchedServiceTest ProcessConnectDied004 start" << std::endl;
405 auto& connectAbilityMap = DistributedSchedService::GetInstance().connectAbilityMap_;
406 auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
407
408 /**
409 * @tc.steps: step1. add one connectInfo
410 * @tc.expected: step1. can find the newly-added connectInfo
411 */
412 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
413 AddConnectInfo(connect, "123_local_device_id", "123_remote_device_id");
414 {
415 std::lock_guard<std::mutex> autoLock(distributedLock);
416 EXPECT_EQ(connectAbilityMap.size(), static_cast<size_t>(1));
417 }
418
419 /**
420 * @tc.steps: step2. process connect died and then check the connectAbilityMap_
421 * @tc.expected: step2. the connectInfo is removed
422 */
423 DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(connect,
424 IPCSkeleton::GetCallingUid(), "123_local_device_id");
425 {
426 std::lock_guard<std::mutex> autoLock(distributedLock);
427 EXPECT_EQ(connectAbilityMap.size(), static_cast<size_t>(0));
428 }
429
430 RemoveConnectInfo(connect);
431 }
432
433 /**
434 * @tc.name: ProcessDeviceOffline001
435 * @tc.desc: process device offline with only one connection
436 * @tc.type: FUNC
437 */
438 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline001, TestSize.Level0)
439 {
440 DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline001 start" << std::endl;
441 OHOS::AAFwk::Want want;
442 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
443 auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
444 auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
445
446 /**
447 * @tc.steps: step1. add one session
448 */
449 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
450 AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
451 /**
452 * @tc.steps: step2. process device offline and check the map
453 * @tc.expected: step2. the connect session is removed
454 */
455 DistributedSchedService::GetInstance().ProcessDeviceOffline("123_remote_device_id");
456 {
457 std::lock_guard<std::mutex> autoLock(distributedLock);
458 EXPECT_EQ(connectionMap.size(), static_cast<size_t>(0));
459 }
460
461 RemoveSession(connect);
462 }
463
464 /**
465 * @tc.name: ProcessDeviceOffline002
466 * @tc.desc: process device offline with multiple connections
467 * @tc.type: FUNC
468 */
469 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline002, TestSize.Level0)
470 {
471 DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline002 start" << std::endl;
472 OHOS::AAFwk::Want want;
473 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
474 auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
475 auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
476
477 /**
478 * @tc.steps: step1. add one session
479 * @tc.expected: step1. can find the two newly-added connect sessions
480 */
481 sptr<AbilityConnectCallbackTest> connect1 = new AbilityConnectCallbackTest();
482 AddSession(connect1, "123_local_device_id", "123_remote_device_id", want);
483 sptr<AbilityConnectCallbackTest> connect2 = new AbilityConnectCallbackTest();
484 AddSession(connect2, "123_local_device_id", "123_remote_device_id", want);
485 {
486 std::lock_guard<std::mutex> autoLock(distributedLock);
487 EXPECT_EQ(connectionMap.size(), static_cast<size_t>(2));
488 }
489
490 /**
491 * @tc.steps: step2. process device offline
492 * @tc.expected: step2. the connect sessions are removed
493 */
494 DistributedSchedService::GetInstance().ProcessDeviceOffline("123_remote_device_id");
495 {
496 std::lock_guard<std::mutex> autoLock(distributedLock);
497 EXPECT_EQ(connectionMap.size(), static_cast<size_t>(0));
498 }
499
500 RemoveSession(connect1);
501 RemoveSession(connect2);
502 }
503
504 /**
505 * @tc.name: ProcessDeviceOffline003
506 * @tc.desc: process device offline with multiple online devices
507 * @tc.type: FUNC
508 */
509 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline003, TestSize.Level0)
510 {
511 DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline003 start" << std::endl;
512 OHOS::AAFwk::Want want;
513 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
514 auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
515 auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
516
517 /**
518 * @tc.steps: step1. add one session
519 */
520 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
521 AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
522 /**
523 * @tc.steps: step2. process other device offline and check the map
524 * @tc.expected: step2. still can find the newly-added connect session
525 */
526 DistributedSchedService::GetInstance().ProcessDeviceOffline("456_remote_device_id");
527 {
528 std::lock_guard<std::mutex> autoLock(distributedLock);
529 auto iter = connectionMap.find(connect);
530 EXPECT_NE(iter, connectionMap.end());
531 EXPECT_EQ(connectionMap.size(), static_cast<size_t>(1));
532 }
533
534 RemoveSession(connect);
535 }
536
537 /**
538 * @tc.name: ProcessDeviceOffline004
539 * @tc.desc: process device offline and check the trackingUidMap_
540 * @tc.type: FUNC
541 */
542 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline004, TestSize.Level1)
543 {
544 DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline004 start" << std::endl;
545 OHOS::AAFwk::Want want;
546 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
547 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
548 AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
549
550 auto& trackingUidMap = DistributedSchedService::GetInstance().trackingUidMap_;
551 /**
552 * @tc.steps: step1. Increase connect count
553 * @tc.expected: step1. connect count increase one
554 */
555 int32_t uid = IPCSkeleton::GetCallingUid();
556 uint32_t oldCount = trackingUidMap[uid];
557 AddConnectCount(uid);
558 EXPECT_EQ(trackingUidMap[uid] - oldCount, static_cast<uint32_t>(1));
559
560 /**
561 * @tc.steps: step2. process device offline and then check the trackingUidMap_
562 * @tc.expected: step2. the connect count is decrease
563 */
564 DistributedSchedService::GetInstance().ProcessDeviceOffline("123_remote_device_id");
565 auto iter = trackingUidMap.find(uid);
566 if (iter != trackingUidMap.end()) {
567 EXPECT_EQ(trackingUidMap[uid], oldCount);
568 }
569
570 RemoveConnectInfo(connect);
571 }
572
573 /**
574 * @tc.name: ProcessDeviceOffline005
575 * @tc.desc: process device offline and check the connectAbilityMap_
576 * @tc.type: FUNC
577 */
578 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline005, TestSize.Level1)
579 {
580 DTEST_LOG << "DistributedSchedServiceTest ProcessDeviceOffline005 start" << std::endl;
581 auto& connectAbilityMap = DistributedSchedService::GetInstance().connectAbilityMap_;
582 auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
583
584 /**
585 * @tc.steps: step1. add one connectInfo
586 * @tc.expected: step1. can find the newly-added connectInfo
587 */
588 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
589 AddConnectInfo(connect, "123_local_device_id", "123_remote_device_id");
590 {
591 std::lock_guard<std::mutex> autoLock(distributedLock);
592 EXPECT_EQ(connectAbilityMap.size(), static_cast<size_t>(1));
593 }
594
595 /**
596 * @tc.steps: step2. process device offline and then check the connectAbilityMap_
597 * @tc.expected: step2. the connectInfo is removed
598 */
599 DistributedSchedService::GetInstance().ProcessDeviceOffline("123_local_device_id");
600 {
601 std::lock_guard<std::mutex> autoLock(distributedLock);
602 EXPECT_EQ(connectAbilityMap.size(), static_cast<size_t>(0));
603 }
604
605 RemoveConnectInfo(connect);
606 }
607
608 /**
609 * @tc.name: DisconnectRemoteAbility001
610 * @tc.desc: disconnect remote ability
611 * @tc.type: FUNC
612 */
613 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility001, TestSize.Level0)
614 {
615 DTEST_LOG << "DistributedSchedServiceTest DisconnectRemoteAbility001 start" << std::endl;
616 OHOS::AAFwk::Want want;
617 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
618 auto& connectionMap = DistributedSchedService::GetInstance().distributedConnectAbilityMap_;
619 auto& distributedLock = DistributedSchedService::GetInstance().distributedLock_;
620
621 /**
622 * @tc.steps: step1. add one session
623 */
624 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
625 AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
626 /**
627 * @tc.steps: step2. disconnect the ability and check the map
628 * @tc.expected: step2. the connect session is removed
629 */
630 DistributedSchedService::GetInstance().DisconnectRemoteAbility(connect, 0, 0);
631 {
632 std::lock_guard<std::mutex> autoLock(distributedLock);
633 EXPECT_EQ(connectionMap.size(), static_cast<size_t>(0));
634 }
635
636 RemoveSession(connect);
637 }
638
639 /**
640 * @tc.name: DisconnectRemoteAbility002
641 * @tc.desc: disconnect remote ability and check the trackingUidMap_
642 * @tc.type: FUNC
643 */
644 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility002, TestSize.Level1)
645 {
646 DTEST_LOG << "DistributedSchedServiceTest DisconnectRemoteAbility002 start" << std::endl;
647 OHOS::AAFwk::Want want;
648 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
649 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
650 AddSession(connect, "123_local_device_id", "123_remote_device_id", want);
651
652 auto& trackingUidMap = DistributedSchedService::GetInstance().trackingUidMap_;
653 /**
654 * @tc.steps: step1. Increase connect count
655 * @tc.expected: step1. connect count increase one
656 */
657 int32_t uid = IPCSkeleton::GetCallingUid();
658 uint32_t oldCount = trackingUidMap[uid];
659 AddConnectCount(uid);
660 uint32_t newCount = trackingUidMap[uid];
661 EXPECT_EQ(newCount - oldCount, static_cast<uint32_t>(1));
662
663 /**
664 * @tc.steps: step2. disconnect remote ability and then check the trackingUidMap_
665 * @tc.expected: step2. the connect count is decrease
666 */
667 DistributedSchedService::GetInstance().DisconnectRemoteAbility(connect, 0, 0);
668 auto iter = trackingUidMap.find(uid);
669 if (iter != trackingUidMap.end()) {
670 EXPECT_EQ(trackingUidMap[uid], oldCount);
671 }
672
673 RemoveConnectInfo(connect);
674 }
675
676 /**
677 * @tc.name: DisconnectRemoteAbility003
678 * @tc.desc: disconnect remote ability whith error callback
679 * @tc.type: FUNC
680 * @tc.require: I5OOKG
681 */
682 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility003, TestSize.Level4)
683 {
684 DTEST_LOG << "DistributedSchedServiceTest DisconnectRemoteAbility003 start" << std::endl;
685 int32_t ret = DistributedSchedService::GetInstance().DisconnectRemoteAbility(nullptr, 0, 0);
686 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
687 DTEST_LOG << "DistributedSchedServiceTest DisconnectRemoteAbility003 end" << std::endl;
688 }
689
690 /**
691 * @tc.name: ConnectRemoteAbility
692 * @tc.desc: connect remote ability whith error uid and pid
693 * @tc.type: FUNC
694 * @tc.require: I5OOKG
695 */
696 HWTEST_F(DistributedSchedConnectTest, ConnectRemoteAbility001, TestSize.Level4)
697 {
698 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility001 start" << std::endl;
699 OHOS::AAFwk::Want want;
700 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
701 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
702 int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, -1, -1, -1);
703 EXPECT_EQ(ret, BIND_ABILITY_UID_INVALID_ERR);
704 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility001 end" << std::endl;
705 }
706
707 /**
708 * @tc.name: ConnectRemoteAbility
709 * @tc.desc: connect remote ability whith empty deviceId.
710 * @tc.type: FUNC
711 * @tc.require: I5OOKG
712 */
713 HWTEST_F(DistributedSchedConnectTest, ConnectRemoteAbility002, TestSize.Level4)
714 {
715 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility002 start" << std::endl;
716 OHOS::AAFwk::Want want;
717 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
718 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
719 int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, -1, -1, -1);
720 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
721 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility002 end" << std::endl;
722 }
723
724 /**
725 * @tc.name: ConnectAbilityFromRemote
726 * @tc.desc: connect remote ability whith fake deviceId.
727 * @tc.type: FUNC
728 * @tc.require: I5OOKG
729 */
730 HWTEST_F(DistributedSchedConnectTest, ConnectAbilityFromRemote001, TestSize.Level3)
731 {
732 DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote001 start" << std::endl;
733 OHOS::AAFwk::Want want;
734 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
735 AppExecFwk::AbilityInfo abilityInfo;
736 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
737 CallerInfo callerInfo;
738 IDistributedSched::AccountInfo accountInfo;
739 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
740 abilityInfo, connect, callerInfo, accountInfo);
741 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
742 DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote001 end" << std::endl;
743 }
744
745 /**
746 * @tc.name: ConnectAbilityFromRemote
747 * @tc.desc: connect remote ability whith error callback.
748 * @tc.type: FUNC
749 * @tc.require: I5OOKG
750 */
751 HWTEST_F(DistributedSchedConnectTest, ConnectAbilityFromRemote002, TestSize.Level4)
752 {
753 DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote002 start" << std::endl;
754 OHOS::AAFwk::Want want;
755 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
756 AppExecFwk::AbilityInfo abilityInfo;
757 CallerInfo callerInfo;
758 IDistributedSched::AccountInfo accountInfo;
759 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
760 abilityInfo, nullptr, callerInfo, accountInfo);
761 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
762 DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote002 end" << std::endl;
763 }
764
765 /**
766 * @tc.name: ConnectAbilityFromRemote
767 * @tc.desc: connect remote ability whith error param
768 * @tc.type: FUNC
769 * @tc.require: I5OOKG
770 */
771 HWTEST_F(DistributedSchedConnectTest, ConnectAbilityFromRemote003, TestSize.Level4)
772 {
773 DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote003 start" << std::endl;
774 OHOS::AAFwk::Want want;
775 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
776 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
777 AppExecFwk::AbilityInfo abilityInfo;
778 CallerInfo callerInfo;
779 IDistributedSched::AccountInfo accountInfo;
780 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
781 abilityInfo, connect, callerInfo, accountInfo);
782 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
783 DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote003 end" << std::endl;
784 }
785
786 /**
787 * @tc.name: ConnectAbilityFromRemote
788 * @tc.desc: connect remote ability whith null callback
789 * @tc.type: FUNC
790 * @tc.require: I5OOKG
791 */
792 HWTEST_F(DistributedSchedConnectTest, ConnectAbilityFromRemote004, TestSize.Level4)
793 {
794 DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote004 start" << std::endl;
795 OHOS::AAFwk::Want want;
796 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
797 AppExecFwk::AbilityInfo abilityInfo;
798 CallerInfo callerInfo;
799 IDistributedSched::AccountInfo accountInfo;
800 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
801 abilityInfo, nullptr, callerInfo, accountInfo);
802 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
803 DTEST_LOG << "DistributedSchedConnectTest ConnectAbilityFromRemote004 end" << std::endl;
804 }
805
806 /**
807 * @tc.name: DisconnectEachRemoteAbilityLocked
808 * @tc.desc: disconnect remote ability.
809 * @tc.type: FUNC
810 * @tc.require: I5OOKG
811 */
812 HWTEST_F(DistributedSchedConnectTest, DisconnectEachRemoteAbilityLocked001, TestSize.Level4)
813 {
814 DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked001 start" << std::endl;
815 int32_t ret = DistributedSchedService::GetInstance().DisconnectEachRemoteAbilityLocked("", "", nullptr);
816 EXPECT_NE(ret, ERR_OK);
817 DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked001 end" << std::endl;
818 }
819
820 /**
821 * @tc.name: DisconnectEachRemoteAbilityLocked
822 * @tc.desc: disconnect remote ability.
823 * @tc.type: FUNC
824 * @tc.require: I5OOKG
825 */
826 HWTEST_F(DistributedSchedConnectTest, DisconnectEachRemoteAbilityLocked002, TestSize.Level4)
827 {
828 DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked002 start" << std::endl;
829 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
830 int32_t ret = DistributedSchedService::GetInstance().DisconnectEachRemoteAbilityLocked("", "", connect);
831 EXPECT_NE(ret, ERR_OK);
832 DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked002 end" << std::endl;
833 }
834
835 /**
836 * @tc.name: DisconnectEachRemoteAbilityLocked
837 * @tc.desc: disconnect remote ability.
838 * @tc.type: FUNC
839 * @tc.require: I5OOKG
840 */
841 HWTEST_F(DistributedSchedConnectTest, DisconnectEachRemoteAbilityLocked003, TestSize.Level3)
842 {
843 DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked003 start" << std::endl;
844 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
845 int32_t ret = DistributedSchedService::GetInstance().DisconnectEachRemoteAbilityLocked(
846 "123_remote_device_id", "123_remote_device_id", connect);
847 EXPECT_NE(ret, ERR_OK);
848 DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked003 end" << std::endl;
849 }
850
851 /**
852 * @tc.name: DisconnectEachRemoteAbilityLocked
853 * @tc.desc: disconnect remote ability.
854 * @tc.type: FUNC
855 * @tc.require: I5OOKG
856 */
857 HWTEST_F(DistributedSchedConnectTest, DisconnectEachRemoteAbilityLocked004, TestSize.Level3)
858 {
859 DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked004 start" << std::endl;
860 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
861 std::string deviceId;
862 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
863 int32_t ret = DistributedSchedService::GetInstance().DisconnectEachRemoteAbilityLocked(
864 deviceId, deviceId, connect);
865 EXPECT_NE(ret, ERR_OK);
866 DTEST_LOG << "DistributedSchedConnectTest DisconnectEachRemoteAbilityLocked004 end" << std::endl;
867 }
868
869 /**
870 * @tc.name: DisconnectRemoteAbility
871 * @tc.desc: disconnect remote ability.
872 * @tc.type: FUNC
873 * @tc.require: I5OOKG
874 */
875 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility004, TestSize.Level4)
876 {
877 DTEST_LOG << "DistributedSchedConnectTest DisconnectRemoteAbility004 start" << std::endl;
878 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
879 int32_t ret = DistributedSchedService::GetInstance().DisconnectRemoteAbility(connect, 0, 0);
880 EXPECT_NE(ret, ERR_OK);
881 DTEST_LOG << "DistributedSchedConnectTest DisconnectRemoteAbility004 end" << std::endl;
882 }
883
884 /**
885 * @tc.name: DisconnectRemoteAbility
886 * @tc.desc: disconnect remote ability.
887 * @tc.type: FUNC
888 * @tc.require: I5OOKG
889 */
890 HWTEST_F(DistributedSchedConnectTest, DisconnectRemoteAbility005, TestSize.Level4)
891 {
892 DTEST_LOG << "DistributedSchedConnectTest DisconnectRemoteAbility005 start" << std::endl;
893 int32_t ret = DistributedSchedService::GetInstance().DisconnectRemoteAbility(nullptr, 0, 0);
894 EXPECT_NE(ret, ERR_OK);
895 DTEST_LOG << "DistributedSchedConnectTest DisconnectRemoteAbility005 end" << std::endl;
896 }
897
898 /**
899 * @tc.name: DisconnectAbilityFromRemote
900 * @tc.desc: disconnect ability from remote.
901 * @tc.type: FUNC
902 * @tc.require: I5OOKG
903 */
904 HWTEST_F(DistributedSchedConnectTest, DisconnectAbilityFromRemote001, TestSize.Level4)
905 {
906 DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote001 start" << std::endl;
907 int32_t ret = DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(nullptr, 0, "");
908 EXPECT_NE(ret, ERR_OK);
909 DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote001 end" << std::endl;
910 }
911
912 /**
913 * @tc.name: DisconnectAbilityFromRemote
914 * @tc.desc: disconnect ability from remote.
915 * @tc.type: FUNC
916 * @tc.require: I5OOKG
917 */
918 HWTEST_F(DistributedSchedConnectTest, DisconnectAbilityFromRemote002, TestSize.Level4)
919 {
920 DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote002 start" << std::endl;
921 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
922 int32_t ret = DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(connect, 0, "");
923 EXPECT_NE(ret, ERR_OK);
924 DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote002 end" << std::endl;
925 }
926
927 /**
928 * @tc.name: DisconnectAbilityFromRemote
929 * @tc.desc: disconnect ability from remote.
930 * @tc.type: FUNC
931 * @tc.require: I5OOKG
932 */
933 HWTEST_F(DistributedSchedConnectTest, DisconnectAbilityFromRemote003, TestSize.Level4)
934 {
935 DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote003 start" << std::endl;
936 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
937 std::string deviceId;
938 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
939 int32_t ret = DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(connect, 0, deviceId);
940 EXPECT_NE(ret, ERR_OK);
941 DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote003 end" << std::endl;
942 }
943
944 /**
945 * @tc.name: DisconnectAbilityFromRemote
946 * @tc.desc: disconnect ability from remote.
947 * @tc.type: FUNC
948 * @tc.require: I5OOKG
949 */
950 HWTEST_F(DistributedSchedConnectTest, DisconnectAbilityFromRemote004, TestSize.Level4)
951 {
952 DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote004 start" << std::endl;
953 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
954 int32_t ret = DistributedSchedService::GetInstance().DisconnectAbilityFromRemote(
955 connect, 0, "123_remote_device_id");
956 EXPECT_EQ(ret, ERR_OK);
957 DTEST_LOG << "DistributedSchedConnectTest DisconnectAbilityFromRemote004 end" << std::endl;
958 }
959
960 /**
961 * @tc.name: ProcessDeviceOffline
962 * @tc.desc: device offline, clear the connect info using fake deviceId.
963 * @tc.type: FUNC
964 * @tc.require: I5OOKG
965 */
966 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline006, TestSize.Level3)
967 {
968 DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline006 start" << std::endl;
969 DistributedSchedService::GetInstance().ProcessDeviceOffline("123_remote_device_id");
970 DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline006 end" << std::endl;
971 }
972
973 /**
974 * @tc.name: ProcessDeviceOffline
975 * @tc.desc: device offline, clear connect info using empty deviceId.
976 * @tc.type: FUNC
977 * @tc.require: I5OOKG
978 */
979 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline007, TestSize.Level4)
980 {
981 DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline007 start" << std::endl;
982 DistributedSchedService::GetInstance().ProcessDeviceOffline("");
983 DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline007 end" << std::endl;
984 }
985
986 /**
987 * @tc.name: ProcessDeviceOffline
988 * @tc.desc: device offline, clear connect info using local deviceId.
989 * @tc.type: FUNC
990 * @tc.require: I5OOKG
991 */
992 HWTEST_F(DistributedSchedConnectTest, ProcessDeviceOffline008, TestSize.Level3)
993 {
994 DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline008 start" << std::endl;
995 std::string deviceId;
996 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
997 DistributedSchedService::GetInstance().ProcessDeviceOffline(deviceId);
998 DTEST_LOG << "DistributedSchedConnectTest ProcessDeviceOffline008 end" << std::endl;
999 }
1000
1001 /**
1002 * @tc.name: NotifyApp
1003 * @tc.desc: notify app to dealwith the offline message.
1004 * @tc.type: FUNC
1005 * @tc.require: I5OOKG
1006 */
1007 HWTEST_F(DistributedSchedConnectTest, NotifyApp001, TestSize.Level3)
1008 {
1009 DTEST_LOG << "DistributedSchedConnectTest NotifyApp001 start" << std::endl;
1010 AppExecFwk::ElementName element;
1011 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1012 int32_t ret = DistributedSchedService::GetInstance().NotifyApp(connect, element, 0);
1013 EXPECT_EQ(ret, ERR_OK);
1014 DTEST_LOG << "DistributedSchedConnectTest NotifyApp001 end" << std::endl;
1015 }
1016
1017 /**
1018 * @tc.name: NotifyApp
1019 * @tc.desc: notify app to dealwith the offline message.
1020 * @tc.type: FUNC
1021 * @tc.require: I5OOKG
1022 */
1023 HWTEST_F(DistributedSchedConnectTest, NotifyApp002, TestSize.Level4)
1024 {
1025 DTEST_LOG << "DistributedSchedConnectTest NotifyApp002 start" << std::endl;
1026 AppExecFwk::ElementName element;
1027 int32_t ret = DistributedSchedService::GetInstance().NotifyApp(nullptr, element, 0);
1028 EXPECT_NE(ret, ERR_OK);
1029 DTEST_LOG << "DistributedSchedConnectTest NotifyApp002 end" << std::endl;
1030 }
1031
1032 /**
1033 * @tc.name: ProcessConnectDied
1034 * @tc.desc: dealwith the app died message.
1035 * @tc.type: FUNC
1036 * @tc.require: I5OOKG
1037 */
1038 HWTEST_F(DistributedSchedConnectTest, ProcessConnectDied005, TestSize.Level4)
1039 {
1040 DTEST_LOG << "DistributedSchedConnectTest ProcessConnectDied005 start" << std::endl;
1041 DistributedSchedService::GetInstance().ProcessConnectDied(nullptr);
1042 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1043 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
1044 DTEST_LOG << "DistributedSchedConnectTest ProcessConnectDied005 end" << std::endl;
1045 }
1046
1047 /**
1048 * @tc.name: NotifyProcessDied001
1049 * @tc.desc: notify process died message to remote.
1050 * @tc.type: FUNC
1051 * @tc.require: I5OOKG
1052 */
1053 HWTEST_F(DistributedSchedConnectTest, NotifyProcessDied001, TestSize.Level4)
1054 {
1055 DTEST_LOG << "DistributedSchedConnectTest NotifyProcessDied001 start" << std::endl;
1056 TargetComponent targetComponent {TargetComponent::HARMONY_COMPONENT};
1057 CallerInfo callerInfo;
1058 DistributedSchedService::GetInstance().NotifyProcessDied("", callerInfo, targetComponent);
1059 DistributedSchedService::GetInstance().NotifyProcessDied("123_remote_device_id", callerInfo, targetComponent);
1060 DTEST_LOG << "DistributedSchedConnectTest NotifyProcessDied001 end" << std::endl;
1061 }
1062
1063 /**
1064 * @tc.name: ProxyCallDisconnectRemoteAbility001
1065 * @tc.desc: call dms proxy DisconnectRemoteAbility
1066 * @tc.type: FUNC
1067 * @tc.require: I5OOKG
1068 */
1069 HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectRemoteAbility001, TestSize.Level3)
1070 {
1071 DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility001 start" << std::endl;
1072 sptr<IDistributedSched> proxy = GetDms();
1073 if (proxy == nullptr) {
1074 return;
1075 }
1076 int32_t ret = proxy->DisconnectRemoteAbility(nullptr, 0, 0);
1077 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1078 DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility001 end" << std::endl;
1079 }
1080
1081 /**
1082 * @tc.name: ProxyCallDisconnectRemoteAbility002
1083 * @tc.desc: call dms proxy DisconnectRemoteAbility
1084 * @tc.type: FUNC
1085 * @tc.require: I5OOKG
1086 */
1087 HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectRemoteAbility002, TestSize.Level3)
1088 {
1089 DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility002 start" << std::endl;
1090 sptr<IDistributedSched> proxy = GetDms();
1091 if (proxy == nullptr) {
1092 return;
1093 }
1094 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1095 int32_t ret = proxy->DisconnectRemoteAbility(connect, 0, 0);
1096 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1097 DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectRemoteAbility002 end" << std::endl;
1098 }
1099
1100 /**
1101 * @tc.name: ProxyCallConnectRemoteAbility001
1102 * @tc.desc: call dms proxy ConnectRemoteAbility
1103 * @tc.type: FUNC
1104 * @tc.require: I5OOKG
1105 */
1106 HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectRemoteAbility001, TestSize.Level3)
1107 {
1108 DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility001 start" << std::endl;
1109 sptr<IDistributedSched> proxy = GetDms();
1110 if (proxy == nullptr) {
1111 return;
1112 }
1113 OHOS::AAFwk::Want want;
1114 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1115 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1116 int32_t ret = proxy->ConnectRemoteAbility(want, connect, 0, 0, 0);
1117 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1118 DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility001 end" << std::endl;
1119 }
1120
1121 /**
1122 * @tc.name: ProxyCallConnectRemoteAbility002
1123 * @tc.desc: call dms proxy ConnectRemoteAbility
1124 * @tc.type: FUNC
1125 * @tc.require: I5OOKG
1126 */
1127 HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectRemoteAbility002, TestSize.Level3)
1128 {
1129 DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility002 start" << std::endl;
1130 sptr<IDistributedSched> proxy = GetDms();
1131 if (proxy == nullptr) {
1132 return;
1133 }
1134 OHOS::AAFwk::Want want;
1135 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1136 int32_t ret = proxy->ConnectRemoteAbility(want, nullptr, 0, 0, 0);
1137 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1138 DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectRemoteAbility002 end" << std::endl;
1139 }
1140
1141 /**
1142 * @tc.name: ProxyCallConnectAbilityFromRemote001
1143 * @tc.desc: call dms proxy ConnectAbilityFromRemote
1144 * @tc.type: FUNC
1145 * @tc.require: I5OOKG
1146 */
1147 HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectAbilityFromRemote001, TestSize.Level3)
1148 {
1149 DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote001 start" << std::endl;
1150 sptr<IDistributedSched> proxy = GetDms();
1151 if (proxy == nullptr) {
1152 return;
1153 }
1154 OHOS::AAFwk::Want want;
1155 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1156 AppExecFwk::AbilityInfo abilityInfo;
1157 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1158 CallerInfo callerInfo;
1159 IDistributedSched::AccountInfo accountInfo;
1160 int32_t ret = proxy->ConnectAbilityFromRemote(want, abilityInfo,
1161 connect, callerInfo, accountInfo);
1162 EXPECT_EQ(ret, REQUEST_CODE_ERR);
1163 DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote001 end" << std::endl;
1164 }
1165
1166 /**
1167 * @tc.name: ProxyCallConnectAbilityFromRemote002
1168 * @tc.desc: call dms proxy ConnectAbilityFromRemote
1169 * @tc.type: FUNC
1170 * @tc.require: I5OOKG
1171 */
1172 HWTEST_F(DistributedSchedConnectTest, ProxyCallConnectAbilityFromRemote002, TestSize.Level3)
1173 {
1174 DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote002 start" << std::endl;
1175 sptr<IDistributedSched> proxy = GetDms();
1176 if (proxy == nullptr) {
1177 return;
1178 }
1179 OHOS::AAFwk::Want want;
1180 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1181 AppExecFwk::AbilityInfo abilityInfo;
1182 CallerInfo callerInfo;
1183 IDistributedSched::AccountInfo accountInfo;
1184 int32_t ret = proxy->ConnectAbilityFromRemote(want, abilityInfo,
1185 nullptr, callerInfo, accountInfo);
1186 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1187 DTEST_LOG << "DistributedSchedServiceTest ProxyCallConnectAbilityFromRemote002 end" << std::endl;
1188 }
1189
1190 /**
1191 * @tc.name: ProxyCallDisconnectAbilityFromRemote001
1192 * @tc.desc: call dms proxy DisconnectAbilityFromRemote
1193 * @tc.type: FUNC
1194 * @tc.require: I5OOKG
1195 */
1196 HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectAbilityFromRemote001, TestSize.Level3)
1197 {
1198 DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote001 start" << std::endl;
1199 sptr<IDistributedSched> proxy = GetDms();
1200 if (proxy == nullptr) {
1201 return;
1202 }
1203 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1204 int32_t ret = proxy->DisconnectAbilityFromRemote(connect, 0, "");
1205 EXPECT_EQ(ret, REQUEST_CODE_ERR);
1206 DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote001 end" << std::endl;
1207 }
1208
1209 /**
1210 * @tc.name: ProxyCallDisconnectAbilityFromRemote002
1211 * @tc.desc: call dms proxy DisconnectAbilityFromRemote
1212 * @tc.type: FUNC
1213 * @tc.require: I5OOKG
1214 */
1215 HWTEST_F(DistributedSchedConnectTest, ProxyCallDisconnectAbilityFromRemote002, TestSize.Level3)
1216 {
1217 DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote002 start" << std::endl;
1218 sptr<IDistributedSched> proxy = GetDms();
1219 if (proxy == nullptr) {
1220 return;
1221 }
1222 int32_t ret = proxy->DisconnectAbilityFromRemote(nullptr, 0, "");
1223 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1224 DTEST_LOG << "DistributedSchedServiceTest ProxyCallDisconnectAbilityFromRemote002 end" << std::endl;
1225 }
1226
1227 /**
1228 * @tc.name: RemoteConnectAbilityMappingLocked001
1229 * @tc.desc: call RemoteConnectAbilityMappingLocked
1230 * @tc.type: FUNC
1231 */
1232 HWTEST_F(DistributedSchedConnectTest, RemoteConnectAbilityMappingLocked001, TestSize.Level4)
1233 {
1234 DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked001 start" << std::endl;
1235 OHOS::AAFwk::Want want;
1236 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
1237 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1238 std::string localDeviceId = "123_local_device_id";
1239 std::string remoteDeviceId = "123_remote_device_id";
1240 CallerInfo callerInfo;
1241 AddSession(connect, localDeviceId, remoteDeviceId, want);
1242 DistributedSchedService::GetInstance().RemoteConnectAbilityMappingLocked(connect, localDeviceId,
1243 remoteDeviceId, want.GetElement(), callerInfo, TargetComponent::HARMONY_COMPONENT);
1244 DTEST_LOG << "DistributedSchedConnectTest RemoteConnectAbilityMappingLocked001 end" << std::endl;
1245 }
1246
1247 /**
1248 * @tc.name: CheckDistributedConnectLocked001
1249 * @tc.desc: call CheckDistributedConnectLocked
1250 * @tc.type: FUNC
1251 */
1252 HWTEST_F(DistributedSchedConnectTest, CheckDistributedConnectLocked001, TestSize.Level4)
1253 {
1254 DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked001 start" << std::endl;
1255 int32_t uid = IPCSkeleton::GetCallingUid();
1256 CallerInfo callerInfo;
1257 callerInfo.uid = uid;
1258 AddConnectCount(uid);
1259 DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
1260 DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked001 end" << std::endl;
1261 }
1262
1263 /**
1264 * @tc.name: CheckDistributedConnectLocked002
1265 * @tc.desc: call CheckDistributedConnectLocked
1266 * @tc.type: FUNC
1267 */
1268 HWTEST_F(DistributedSchedConnectTest, CheckDistributedConnectLocked002, TestSize.Level4)
1269 {
1270 DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked002 start" << std::endl;
1271 int32_t uid = IPCSkeleton::GetCallingUid();
1272 CallerInfo callerInfo;
1273 callerInfo.uid = uid;
1274 DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
1275 DTEST_LOG << "DistributedSchedConnectTest CheckDistributedConnectLocked002 end" << std::endl;
1276 }
1277
1278 /**
1279 * @tc.name: DecreaseConnectLocked001
1280 * @tc.desc: call DecreaseConnectLocked
1281 * @tc.type: FUNC
1282 */
1283 HWTEST_F(DistributedSchedConnectTest, DecreaseConnectLocked001, TestSize.Level4)
1284 {
1285 DTEST_LOG << "DistributedSchedConnectTest DecreaseConnectLocked001 start" << std::endl;
1286 int32_t uid = -1;
1287 DistributedSchedService::GetInstance().DecreaseConnectLocked(uid);
1288 DTEST_LOG << "DistributedSchedConnectTest DecreaseConnectLocked001 end" << std::endl;
1289 }
1290
1291 /**
1292 * @tc.name: DecreaseConnectLocked002
1293 * @tc.desc: call DecreaseConnectLocked
1294 * @tc.type: FUNC
1295 */
1296 HWTEST_F(DistributedSchedConnectTest, DecreaseConnectLocked002, TestSize.Level4)
1297 {
1298 DTEST_LOG << "DistributedSchedConnectTest DecreaseConnectLocked002 start" << std::endl;
1299 int32_t uid = 1000;
1300 AddConnectCount(uid);
1301 DistributedSchedService::GetInstance().DecreaseConnectLocked(uid);
1302 DTEST_LOG << "DistributedSchedConnectTest DecreaseConnectLocked002 end" << std::endl;
1303 }
1304
1305 /**
1306 * @tc.name: GetUidLocked001
1307 * @tc.desc: call GetUidLocked
1308 * @tc.type: FUNC
1309 */
1310 HWTEST_F(DistributedSchedConnectTest, GetUidLocked001, TestSize.Level4)
1311 {
1312 DTEST_LOG << "DistributedSchedConnectTest GetUidLocked001 start" << std::endl;
1313 std::list<ConnectAbilitySession> sessionsList;
1314 DistributedSchedService::GetInstance().GetUidLocked(sessionsList);
1315 DTEST_LOG << "DistributedSchedConnectTest GetUidLocked001 end" << std::endl;
1316 }
1317
1318 /**
1319 * @tc.name: ConnectRemoteAbility003
1320 * @tc.desc: call ConnectRemoteAbility
1321 * @tc.type: FUNC
1322 */
1323 HWTEST_F(DistributedSchedConnectTest, ConnectRemoteAbility003, TestSize.Level4)
1324 {
1325 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility003 start" << std::endl;
1326 std::string remoteDeviceId = "remoteDeviceId";
1327 OHOS::AAFwk::Want want;
1328 want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
1329 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1330 int32_t uid = IPCSkeleton::GetCallingUid();
1331 int32_t pid = IPCSkeleton::GetCallingPid();
1332 int32_t accessToken = IPCSkeleton::GetCallingTokenID();
1333 int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, uid, pid, accessToken);
1334 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1335 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility003 end" << std::endl;
1336 }
1337
1338 /**
1339 * @tc.name: TryConnectRemoteAbility001
1340 * @tc.desc: call TryConnectRemoteAbility
1341 * @tc.type: FUNC
1342 */
1343 HWTEST_F(DistributedSchedConnectTest, TryConnectRemoteAbility001, TestSize.Level4)
1344 {
1345 DTEST_LOG << "DistributedSchedServiceTest TryConnectRemoteAbility001 start" << std::endl;
1346 std::string remoteDeviceId = "remoteDeviceId";
1347 OHOS::AAFwk::Want want;
1348 want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
1349 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1350 CallerInfo callerInfo;
1351 int32_t ret = DistributedSchedService::GetInstance().TryConnectRemoteAbility(want, connect, callerInfo);
1352 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1353 DTEST_LOG << "DistributedSchedServiceTest TryConnectRemoteAbility001 end" << std::endl;
1354 }
1355
1356 /**
1357 * @tc.name: ProcessCallerDied001
1358 * @tc.desc: call ProcessCallerDied
1359 * @tc.type: FUNC
1360 */
1361 HWTEST_F(DistributedSchedConnectTest, ProcessCallerDied001, TestSize.Level4)
1362 {
1363 DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied001 start" << std::endl;
1364 int32_t deviceType = IDistributedSched::CALLER;
1365 DistributedSchedService::GetInstance().ProcessCallerDied(nullptr, deviceType);
1366 DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied001 end" << std::endl;
1367 }
1368
1369 /**
1370 * @tc.name: ProcessCallerDied002
1371 * @tc.desc: call ProcessCallerDied
1372 * @tc.type: FUNC
1373 */
1374 HWTEST_F(DistributedSchedConnectTest, ProcessCallerDied002, TestSize.Level4)
1375 {
1376 DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied002 start" << std::endl;
1377 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1378 int32_t deviceType = IDistributedSched::CALLER;
1379 DistributedSchedService::GetInstance().ProcessCallerDied(connect, deviceType);
1380 DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied002 end" << std::endl;
1381 }
1382
1383 /**
1384 * @tc.name: ProcessCallerDied003
1385 * @tc.desc: call ProcessCallerDied
1386 * @tc.type: FUNC
1387 */
1388 HWTEST_F(DistributedSchedConnectTest, ProcessCallerDied003, TestSize.Level4)
1389 {
1390 DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied003 start" << std::endl;
1391 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1392 int32_t deviceType = IDistributedSched::CALLEE;
1393 CallerInfo callerInfo;
1394 sptr<IRemoteObject> callbackWrapper = new AbilityConnectionWrapperStubTest(connect);
1395 ConnectInfo connectInfo {callerInfo, callbackWrapper};
1396 DistributedSchedService::GetInstance().calleeMap_.emplace(connect, connectInfo);
1397 DistributedSchedService::GetInstance().ProcessCallerDied(connect, deviceType);
1398 DTEST_LOG << "DistributedSchedServiceTest ProcessCallerDied003 end" << std::endl;
1399 }
1400
1401 /**
1402 * @tc.name: HandleLocalCallerDied001
1403 * @tc.desc: call HandleLocalCallerDied
1404 * @tc.type: FUNC
1405 */
1406 HWTEST_F(DistributedSchedConnectTest, HandleLocalCallerDied001, TestSize.Level4)
1407 {
1408 DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied001 start" << std::endl;
1409 OHOS::AAFwk::Want want;
1410 std::string localDeviceId = "123_local_device_id";
1411 std::string remoteDeviceId = "123_remote_device_id";
1412 want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
1413 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1414 CallerInfo callerInfo;
1415 callerInfo.uid = IPCSkeleton::GetCallingUid();
1416 callerInfo.pid = IPCSkeleton::GetCallingPid();
1417 callerInfo.sourceDeviceId = localDeviceId;
1418 callerInfo.callerType = CALLER_TYPE_HARMONY;
1419 DistributedSchedService::GetInstance().SaveCallerComponent(want, connect, callerInfo);
1420 DistributedSchedService::GetInstance().HandleLocalCallerDied(connect);
1421 DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied001 end" << std::endl;
1422 }
1423
1424 /**
1425 * @tc.name: HandleLocalCallerDied002
1426 * @tc.desc: call HandleLocalCallerDied
1427 * @tc.type: FUNC
1428 */
1429 HWTEST_F(DistributedSchedConnectTest, HandleLocalCallerDied002, TestSize.Level4)
1430 {
1431 DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied002 start" << std::endl;
1432 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1433 DistributedSchedService::GetInstance().RemoveCallerComponent(connect);
1434 DistributedSchedService::GetInstance().HandleLocalCallerDied(connect);
1435 DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied002 end" << std::endl;
1436 }
1437
1438 /**
1439 * @tc.name: ProcessCalleeDied001
1440 * @tc.desc: call ProcessCalleeDied
1441 * @tc.type: FUNC
1442 */
1443 HWTEST_F(DistributedSchedConnectTest, ProcessCalleeDied001, TestSize.Level4)
1444 {
1445 DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied001 start" << std::endl;
1446 DistributedSchedService::GetInstance().ProcessCalleeDied(nullptr);
1447 DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied001 end" << std::endl;
1448 }
1449
1450 /**
1451 * @tc.name: ProcessCalleeDied002
1452 * @tc.desc: call ProcessCalleeDied
1453 * @tc.type: FUNC
1454 */
1455 HWTEST_F(DistributedSchedConnectTest, ProcessCalleeDied002, TestSize.Level4)
1456 {
1457 DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied002 start" << std::endl;
1458 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1459 sptr<IRemoteObject> callbackWrapper = new AbilityConnectionWrapperStubTest(connect);
1460 CallerInfo callerInfo;
1461 ConnectInfo connectInfo {callerInfo, callbackWrapper};
1462 DistributedSchedService::GetInstance().calleeMap_.emplace(connect, connectInfo);
1463 DistributedSchedService::GetInstance().ProcessCalleeDied(connect);
1464 DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied002 end" << std::endl;
1465 }
1466
1467 /**
1468 * @tc.name: SaveCallerComponent001
1469 * @tc.desc: call SaveCallerComponent
1470 * @tc.type: FUNC
1471 */
1472 HWTEST_F(DistributedSchedConnectTest, SaveCallerComponent001, TestSize.Level4)
1473 {
1474 DTEST_LOG << "DistributedSchedServiceTest SaveCallerComponent001 start" << std::endl;
1475 OHOS::AAFwk::Want want;
1476 std::string localDeviceId = "123_local_device_id";
1477 std::string remoteDeviceId = "123_remote_device_id";
1478 want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
1479 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1480 CallerInfo callerInfo;
1481 callerInfo.uid = IPCSkeleton::GetCallingUid();
1482 callerInfo.pid = IPCSkeleton::GetCallingPid();
1483 callerInfo.sourceDeviceId = localDeviceId;
1484 callerInfo.callerType = CALLER_TYPE_HARMONY;
1485 DistributedSchedService::GetInstance().SaveCallerComponent(want, connect, callerInfo);
1486 DTEST_LOG << "DistributedSchedServiceTest SaveCallerComponent001 end" << std::endl;
1487 }
1488
1489 /**
1490 * @tc.name: SaveCallerComponent002
1491 * @tc.desc: call SaveCallerComponent
1492 * @tc.type: FUNC
1493 */
1494 HWTEST_F(DistributedSchedConnectTest, SaveCallerComponent002, TestSize.Level4)
1495 {
1496 DTEST_LOG << "DistributedSchedServiceTest SaveCallerComponent002 start" << std::endl;
1497 std::string localDeviceId = "123_local_device_id";
1498 std::string remoteDeviceId = "123_remote_device_id";
1499 OHOS::AAFwk::Want want1;
1500 want1.SetElementName(remoteDeviceId, "ohos.demo.bundleName1", "abilityName1");
1501 OHOS::AAFwk::Want want2;
1502 want2.SetElementName(remoteDeviceId, "ohos.demo.bundleName2", "abilityName2");
1503 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1504 CallerInfo callerInfo;
1505 callerInfo.uid = IPCSkeleton::GetCallingUid();
1506 callerInfo.pid = IPCSkeleton::GetCallingPid();
1507 callerInfo.sourceDeviceId = localDeviceId;
1508 callerInfo.callerType = CALLER_TYPE_HARMONY;
1509 DistributedSchedService::GetInstance().SaveCallerComponent(want1, connect, callerInfo);
1510 DistributedSchedService::GetInstance().SaveCallerComponent(want2, connect, callerInfo);
1511 DTEST_LOG << "DistributedSchedServiceTest SaveCallerComponent002 end" << std::endl;
1512 }
1513
1514 /**
1515 * @tc.name: RemoveCallerComponent001
1516 * @tc.desc: call RemoveCallerComponent
1517 * @tc.type: FUNC
1518 */
1519 HWTEST_F(DistributedSchedConnectTest, RemoveCallerComponent001, TestSize.Level4)
1520 {
1521 DTEST_LOG << "DistributedSchedServiceTest RemoveCallerComponent001 start" << std::endl;
1522 OHOS::AAFwk::Want want;
1523 std::string localDeviceId = "123_local_device_id";
1524 std::string remoteDeviceId = "123_remote_device_id";
1525 want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
1526 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1527 CallerInfo callerInfo;
1528 callerInfo.uid = IPCSkeleton::GetCallingUid();
1529 callerInfo.pid = IPCSkeleton::GetCallingPid();
1530 callerInfo.sourceDeviceId = localDeviceId;
1531 callerInfo.callerType = CALLER_TYPE_HARMONY;
1532 DistributedSchedService::GetInstance().SaveCallerComponent(want, connect, callerInfo);
1533 DistributedSchedService::GetInstance().RemoveCallerComponent(connect);
1534 DTEST_LOG << "DistributedSchedServiceTest RemoveCallerComponent001 end" << std::endl;
1535 }
1536
1537 /**
1538 * @tc.name: AbilityConnectionWrapperStub001
1539 * @tc.desc: receive connect message
1540 * @tc.type: FUNC
1541 */
1542 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub001, TestSize.Level3)
1543 {
1544 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub001 start" << std::endl;
1545 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1546 sptr<AbilityConnectionWrapperStub> connectStub = new AbilityConnectionWrapperStub(connect);
1547 MessageParcel data;
1548 if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
1549 return;
1550 }
1551 MessageParcel reply;
1552 MessageOption option;
1553 AppExecFwk::ElementName element;
1554 PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1555 PARCEL_WRITE_HELPER_NORET(data, RemoteObject, connect);
1556 PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1557 int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
1558 EXPECT_EQ(result, ERR_NONE);
1559 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub001 end" << std::endl;
1560 }
1561
1562 /**
1563 * @tc.name: AbilityConnectionWrapperStub002
1564 * @tc.desc: receive oncall message
1565 * @tc.type: FUNC
1566 */
1567 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub002, TestSize.Level3)
1568 {
1569 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub002 start" << std::endl;
1570 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1571 sptr<AbilityConnectionWrapperStub> connectStub = new AbilityConnectionWrapperStub(connect, "localDeviceId");
1572 MessageParcel data;
1573 if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
1574 return;
1575 }
1576 MessageParcel reply;
1577 MessageOption option;
1578 AppExecFwk::ElementName element;
1579 PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1580 PARCEL_WRITE_HELPER_NORET(data, RemoteObject, connect);
1581 PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1582 int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
1583 EXPECT_EQ(result, ERR_NONE);
1584 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub002 end" << std::endl;
1585 }
1586
1587 /**
1588 * @tc.name: AbilityConnectionWrapperStub003
1589 * @tc.desc: receive disconnect message
1590 * @tc.type: FUNC
1591 */
1592 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub003, TestSize.Level3)
1593 {
1594 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub003 start" << std::endl;
1595 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1596 sptr<AbilityConnectionWrapperStub> connectStub = new AbilityConnectionWrapperStub(connect);
1597 MessageParcel data;
1598 if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
1599 return;
1600 }
1601 MessageParcel reply;
1602 MessageOption option;
1603 AppExecFwk::ElementName element;
1604 PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1605 PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1606 int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
1607 EXPECT_EQ(result, ERR_NONE);
1608 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub003 end" << std::endl;
1609 }
1610
1611 /**
1612 * @tc.name: AbilityConnectionWrapperStub004
1613 * @tc.desc: receive oncall disconnect message
1614 * @tc.type: FUNC
1615 */
1616 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub004, TestSize.Level3)
1617 {
1618 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub004 start" << std::endl;
1619 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1620 sptr<AbilityConnectionWrapperStub> connectStub = new AbilityConnectionWrapperStub(connect, "localDeviceId");
1621 MessageParcel data;
1622 if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
1623 return;
1624 }
1625 MessageParcel reply;
1626 MessageOption option;
1627 AppExecFwk::ElementName element;
1628 PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1629 PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1630 int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
1631 EXPECT_EQ(result, ERR_NONE);
1632 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub004 end" << std::endl;
1633 }
1634
1635 /**
1636 * @tc.name: AbilityConnectionWrapperStub005
1637 * @tc.desc: receive error connect message
1638 * @tc.type: FUNC
1639 */
1640 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub005, TestSize.Level3)
1641 {
1642 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub005 start" << std::endl;
1643 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1644 sptr<AbilityConnectionWrapperStub> connectStub = new AbilityConnectionWrapperStub(connect, "localDeviceId");
1645 MessageParcel data;
1646 MessageParcel reply;
1647 MessageOption option;
1648 // no interface token
1649 AppExecFwk::ElementName element;
1650 PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1651 PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1652 int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
1653 EXPECT_EQ(result, ERR_INVALID_STATE);
1654 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub005 end" << std::endl;
1655 }
1656
1657 /**
1658 * @tc.name: AbilityConnectionWrapperStub006
1659 * @tc.desc: receive error connect message
1660 * @tc.type: FUNC
1661 */
1662 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub006, TestSize.Level3)
1663 {
1664 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub006 start" << std::endl;
1665 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1666 sptr<AbilityConnectionWrapperStub> connectStub = new AbilityConnectionWrapperStub(connect, "localDeviceId");
1667 MessageParcel data;
1668 MessageParcel reply;
1669 MessageOption option;
1670 if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
1671 return;
1672 }
1673 // no element
1674 int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_DISCONNECT_DONE, data, reply, option);
1675 EXPECT_EQ(result, ERR_INVALID_VALUE);
1676 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub006 end" << std::endl;
1677 }
1678
1679 /**
1680 * @tc.name: AbilityConnectionWrapperStub007
1681 * @tc.desc: receive disconnect message
1682 * @tc.type: FUNC
1683 */
1684 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub007, TestSize.Level3)
1685 {
1686 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub007 start" << std::endl;
1687 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1688 sptr<AbilityConnectionWrapperStub> connectStub = new AbilityConnectionWrapperStub(connect, "localDeviceId");
1689 MessageParcel data;
1690 if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
1691 return;
1692 }
1693 MessageParcel reply;
1694 MessageOption option;
1695 AppExecFwk::ElementName element;
1696 PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1697 PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1698 // using error code
1699 int32_t result = connectStub->OnRemoteRequest(ERROR_CONNECT_CODE, data, reply, option);
1700 EXPECT_NE(result, ERR_NONE);
1701 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub007 end" << std::endl;
1702 }
1703
1704 /**
1705 * @tc.name: AbilityConnectionWrapperStub008
1706 * @tc.desc: receive error connect message
1707 * @tc.type: FUNC
1708 */
1709 HWTEST_F(DistributedSchedConnectTest, AbilityConnectionWrapperStub008, TestSize.Level3)
1710 {
1711 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub008 start" << std::endl;
1712 sptr<AbilityConnectCallbackTest> connect = new AbilityConnectCallbackTest();
1713 sptr<AbilityConnectionWrapperStub> connectStub = new AbilityConnectionWrapperStub(connect, "localDeviceId");
1714 MessageParcel data;
1715 if (!data.WriteInterfaceToken(CONNECTION_CALLBACK_INTERFACE_TOKEN)) {
1716 return;
1717 }
1718 MessageParcel reply;
1719 MessageOption option;
1720 // no remoteObject
1721 AppExecFwk::ElementName element;
1722 PARCEL_WRITE_HELPER_NORET(data, Parcelable, &element);
1723 PARCEL_WRITE_HELPER_NORET(data, Int32, 1);
1724 int32_t result = connectStub->OnRemoteRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option);
1725 EXPECT_NE(result, ERR_NONE);
1726 DTEST_LOG << "DistributedSchedServiceTest AbilityConnectionWrapperStub008 end" << std::endl;
1727 }
1728 }
1729 }
1730