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