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