• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "dsched_collab_manager_test.h"
17 
18 #include "dtbschedmgr_device_info_storage.h"
19 #include "distributed_sched_test_util.h"
20 #include "dtbcollabmgr_log.h"
21 #include "test_log.h"
22 #include "mock_distributed_sched.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace OHOS::DistributedHardware;
27 
28 namespace OHOS {
29 namespace DistributedSchedule {
30 
31 static std::shared_ptr<DmsDeviceInfo> g_mockDeviceInfoPtr = nullptr;
32 static bool g_mockDbs = false;
33 
34 namespace {
35     const std::string LOCAL_DEVICEID = "localdeviceid";
36     const std::string REMOTE_DEVICEID = "remotedeviceid";
37     const std::string CONTINUETYPE = "continueType";
38     const std::string BASEDIR = "/data/service/el1/public/database/DistributedSchedule";
39     constexpr int32_t MISSION_ID = 1;
40     constexpr size_t SIZE = 10;
41     const int32_t WAITTIME = 2000;
42     const std::string BUNDLE_NAME = "com.ohos.permissionmanager";
43 }
44 
GetDeviceInfoById(const std::string & networkId)45 std::shared_ptr<DmsDeviceInfo> DtbschedmgrDeviceInfoStorage::GetDeviceInfoById(const std::string& networkId)
46 {
47     return g_mockDeviceInfoPtr;
48 }
49 
GetDistributedBundleInfo(const std::string & networkId,const uint16_t & bundleNameId,DmsBundleInfo & distributeBundleInfo)50 bool DmsBmStorage::GetDistributedBundleInfo(const std::string &networkId,
51     const uint16_t &bundleNameId, DmsBundleInfo &distributeBundleInfo)
52 {
53     return g_mockDbs;
54 }
55 
SetUpTestCase()56 void DSchedCollabManagerTest::SetUpTestCase()
57 {
58     DTEST_LOG << "DSchedCollabManagerTest::SetUpTestCase" << std::endl;
59     mkdir(BASEDIR.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
60     DSchedCollabManager::GetInstance().Init();
61     multiUserMgrMock_ = std::make_shared<MultiUserManagerMock>();
62     MultiUserManagerMock::multiUserMgrMock = multiUserMgrMock_;
63 }
64 
TearDownTestCase()65 void DSchedCollabManagerTest::TearDownTestCase()
66 {
67     DTEST_LOG << "DSchedCollabManagerTest::TearDownTestCase" << std::endl;
68     (void)remove(BASEDIR.c_str());
69     MultiUserManagerMock::multiUserMgrMock = nullptr;
70     multiUserMgrMock_ = nullptr;
71 }
72 
TearDown()73 void DSchedCollabManagerTest::TearDown()
74 {
75     DTEST_LOG << "DSchedCollabManagerTest::TearDown" << std::endl;
76     usleep(WAITTIME);
77     g_mockDeviceInfoPtr = nullptr;
78     g_mockDbs = false;
79     DSchedCollabManager::GetInstance().collabs_.clear();
80 }
81 
SetUp()82 void DSchedCollabManagerTest::SetUp()
83 {
84     usleep(WAITTIME);
85     DSchedCollabManager::GetInstance().collabs_.clear();
86     DTEST_LOG << "DSchedCollabManagerTest::SetUp" << std::endl;
87 }
88 
OnRemoteDied()89 void DSchedCollabManagerTest::DeviceInitCallBack::OnRemoteDied()
90 {
91 }
92 
GetDSchedService() const93 sptr<IRemoteObject> DSchedCollabManagerTest::GetDSchedService() const
94 {
95     sptr<IRemoteObject> dsched(new MockDistributedSched());
96     return dsched;
97 }
98 
CreateObject()99 std::shared_ptr<DSchedCollab> DSchedCollabManagerTest::CreateObject()
100 {
101     const std::string collabToken = "";
102     DSchedCollabInfo info;
103     std::shared_ptr<DSchedCollab> dCollab = std::make_shared<DSchedCollab>(collabToken, info);
104     dCollab->Init();
105     return dCollab;
106 }
107 
108 /**
109  * @tc.name: Init_001
110  * @tc.desc: test Init func
111  * @tc.type: FUNC
112  */
113 HWTEST_F(DSchedCollabManagerTest, Init_001, TestSize.Level3)
114 {
115     DTEST_LOG << "DSchedCollabManagerTest Init_001 begin" << std::endl;
116     DSchedCollabManager::GetInstance().Init();
117     std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler =
118         DSchedCollabManager::GetInstance().eventHandler_;
119     EXPECT_NE(eventHandler, nullptr);
120     DTEST_LOG << "DSchedCollabManagerTest Init_001 end" << std::endl;
121 }
122 
123 /**
124  * @tc.name: CollabMission_001
125  * @tc.desc: test CollabMission func
126  * @tc.type: FUNC
127  */
128 HWTEST_F(DSchedCollabManagerTest, CollabMission_001, TestSize.Level3)
129 {
130     DTEST_LOG << "DSchedCollabManagerTest CollabMission_001 begin" << std::endl;
131     DSchedCollabInfo info;
132     EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(false));
133     int32_t ret = DSchedCollabManager::GetInstance().CollabMission(info);
134     EXPECT_EQ(ret, DMS_NOT_FOREGROUND_USER);
135 
136     EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(true));
137     ret = DSchedCollabManager::GetInstance().CollabMission(info);
138     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
139     DTEST_LOG << "DSchedCollabManagerTest CollabMission_001 end" << std::endl;
140 }
141 
142 /**
143  * @tc.name: CollabMission_002
144  * @tc.desc: test CollabMission func
145  * @tc.type: FUNC
146  */
147 HWTEST_F(DSchedCollabManagerTest, CollabMission_002, TestSize.Level3)
148 {
149     DTEST_LOG << "DSchedCollabManagerTest CollabMission_002 begin" << std::endl;
150     DSchedCollabInfo info;
151     info.srcClientCB_ = sptr<DistributedSchedService>(new DistributedSchedService());
152     EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(true));
153     int32_t ret = DSchedCollabManager::GetInstance().CollabMission(info);
154     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
155 
156     info.srcInfo_.bundleName_ = "srcBundle";
157     EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(true));
158     ret = DSchedCollabManager::GetInstance().CollabMission(info);
159     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
160 
161     info.sinkInfo_.bundleName_ = "sinkBundle";
162     EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(true));
163     ret = DSchedCollabManager::GetInstance().CollabMission(info);
164     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
165 
166     info.srcInfo_.moduleName_ = "srcModule";
167     EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(true));
168     ret = DSchedCollabManager::GetInstance().CollabMission(info);
169     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
170 
171     info.sinkInfo_.moduleName_ = "sinkModule";
172     EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(true));
173     ret = DSchedCollabManager::GetInstance().CollabMission(info);
174     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
175 
176     info.srcInfo_.abilityName_ = "srcAbility";
177     EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(true));
178     ret = DSchedCollabManager::GetInstance().CollabMission(info);
179     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
180 
181     info.sinkInfo_.abilityName_ = "sinkAbility";
182     EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(true));
183     ret = DSchedCollabManager::GetInstance().CollabMission(info);
184     EXPECT_EQ(ret, FIND_LOCAL_DEVICEID_ERR);
185     DTEST_LOG << "DSchedCollabManagerTest CollabMission_002 end" << std::endl;
186 }
187 
188 /**
189  * @tc.name: SetTimeOut_001
190  * @tc.desc: test SetTimeOut func
191  * @tc.type: FUNC
192  */
193 HWTEST_F(DSchedCollabManagerTest, SetTimeOut_001, TestSize.Level3)
194 {
195     DTEST_LOG << "DSchedCollabManagerTest SetTimeOut_001 begin" << std::endl;
196     const std::string collabToken = "testToken";
197     int32_t timeout = 0;
198     DSchedCollabManager::GetInstance().collabs_.clear();
199     DSchedCollabManager::GetInstance().SetTimeOut(collabToken, timeout);
200     EXPECT_EQ(DSchedCollabManager::GetInstance().collabs_.empty(), true);
201     DTEST_LOG << "DSchedCollabManagerTest SetTimeOut_001 end" << std::endl;
202 }
203 
204 /**
205  * @tc.name: SetTimeOut_002
206  * @tc.desc: test SetTimeOut func
207  * @tc.type: FUNC
208  */
209 HWTEST_F(DSchedCollabManagerTest, SetTimeOut_002, TestSize.Level3)
210 {
211     DTEST_LOG << "DSchedCollabManagerTest SetTimeOut_002 begin" << std::endl;
212     const std::string collabToken = "testToken";
213     int32_t timeout = 10;
214     DSchedCollabManager::GetInstance().collabs_.clear();
215     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair(collabToken, nullptr));
216     DSchedCollabManager::GetInstance().SetTimeOut(collabToken, timeout);
217     EXPECT_NE(DSchedCollabManager::GetInstance().collabs_.empty(), true);
218     DSchedCollabManager::GetInstance().collabs_.clear();
219     DTEST_LOG << "DSchedCollabManagerTest SetTimeOut_002 end" << std::endl;
220 }
221 
222 /**
223  * @tc.name: SetTimeOut_003
224  * @tc.desc: test SetTimeOut func
225  * @tc.type: FUNC
226  */
227 HWTEST_F(DSchedCollabManagerTest, SetTimeOut_003, TestSize.Level3)
228 {
229     DTEST_LOG << "DSchedCollabManagerTest SetTimeOut_003 begin" << std::endl;
230     const std::string collabToken = "testToken";
231     int32_t timeout = 10;
232     DSchedCollabInfo info;
233     info.srcInfo_.pid_ = 100;
234     info.srcCollabSessionId_ = 1;
235     auto collab = std::make_shared<DSchedCollab>("test1", info);
236     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair(collabToken, collab));
237     DSchedCollabManager::GetInstance().SetTimeOut(collabToken, timeout);
238     EXPECT_NE(DSchedCollabManager::GetInstance().collabs_.empty(), true);
239     DTEST_LOG << "DSchedCollabManagerTest SetTimeOut_003 end" << std::endl;
240 }
241 
242 /**
243  * @tc.name: RemoveTimeout_001
244  * @tc.desc: test RemoveTimeout func
245  * @tc.type: FUNC
246  */
247 HWTEST_F(DSchedCollabManagerTest, RemoveTimeout_001, TestSize.Level3)
248 {
249     DTEST_LOG << "DSchedCollabManagerTest RemoveTimeout_001 begin" << std::endl;
250     const std::string collabToken = "testToken";
251     DSchedCollabManager::GetInstance().collabs_.clear();
252     DSchedCollabManager::GetInstance().RemoveTimeout(collabToken);
253     EXPECT_EQ(DSchedCollabManager::GetInstance().collabs_.empty(), true);
254     DTEST_LOG << "DSchedCollabManagerTest RemoveTimeout_001 end" << std::endl;
255 }
256 
257 /**
258  * @tc.name: NotifyStartAbilityResult_001
259  * @tc.desc: test NotifyStartAbilityResult func
260  * @tc.type: FUNC
261  */
262 HWTEST_F(DSchedCollabManagerTest, NotifyStartAbilityResult_001, TestSize.Level3)
263 {
264     DTEST_LOG << "DSchedCollabManagerTest NotifyStartAbilityResult_001 begin" << std::endl;
265     const std::string collabToken = "";
266     const int32_t result = 0;
267     const int32_t sinkPid = 0;
268     const int32_t sinkUid = 0;
269     const int32_t sinkAccessTokenId = 0;
270     int32_t ret1 = DSchedCollabManager::GetInstance().NotifyStartAbilityResult(collabToken, result,
271         sinkPid, sinkUid, sinkAccessTokenId);
272     EXPECT_EQ(ret1, INVALID_PARAMETERS_ERR);
273     DTEST_LOG << "DSchedCollabManagerTest NotifyStartAbilityResult_001 end" << std::endl;
274 }
275 
276 /**
277  * @tc.name: NotifySinkPrepareResult_001
278  * @tc.desc: test NotifySinkPrepareResult func
279  * @tc.type: FUNC
280  */
281 HWTEST_F(DSchedCollabManagerTest, NotifySinkPrepareResult_001, TestSize.Level3)
282 {
283     DTEST_LOG << "DSchedCollabManagerTest NotifySinkPrepareResult_001 begin" << std::endl;
284     int32_t direction = 0;
285     const std::string collabToken = "";
286     const int32_t result = 0;
287     const int32_t collabSessionId = 0;
288     const std::string socketName = "";
289     const sptr<IRemoteObject> clientCB;
290     int32_t ret = DSchedCollabManager::GetInstance().NotifySinkPrepareResult(collabToken, result,
291         collabSessionId, socketName, clientCB);
292     EXPECT_EQ(ret, ERR_OK);
293     DTEST_LOG << "DSchedCollabManagerTest NotifySinkPrepareResult_001 end" << std::endl;
294 }
295 
296 /**
297  * @tc.name: NotifySinkRejectReason_001
298  * @tc.desc: test NotifySinkRejectReason func
299  * @tc.type: FUNC
300  */
301 HWTEST_F(DSchedCollabManagerTest, NotifySinkRejectReason_001, TestSize.Level3)
302 {
303     DTEST_LOG << "DSchedCollabManagerTest NotifySinkRejectReason_001 begin" << std::endl;
304     const std::string collabToken = "";
305     const std::string reason = "";
306     int32_t ret = DSchedCollabManager::GetInstance().NotifySinkRejectReason(collabToken, reason);
307     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
308     DTEST_LOG << "DSchedCollabManagerTest NotifySinkRejectReason_001 end" << std::endl;
309 }
310 
311 /**
312  * @tc.name: NotifyAbilityDied_002
313  * @tc.desc: test NotifyAbilityDied func
314  * @tc.type: FUNC
315  */
316 HWTEST_F(DSchedCollabManagerTest, NotifyAbilityDied_002, TestSize.Level3)
317 {
318     DTEST_LOG << "DSchedCollabManagerTest NotifyAbilityDied_002 begin" << std::endl;
319     const std::string bundleName = "";
320     const int32_t pid = 0;
321     int32_t ret = DSchedCollabManager::GetInstance().NotifyAbilityDied(bundleName, pid);
322     EXPECT_EQ(ret, ERR_OK);
323     DTEST_LOG << "DSchedCollabManagerTest NotifyAbilityDied_002 end" << std::endl;
324 }
325 
326 /**
327  * @tc.name: ReleaseAbilityLink_001
328  * @tc.desc: test ReleaseAbilityLink func
329  * @tc.type: FUNC
330  */
331 HWTEST_F(DSchedCollabManagerTest, ReleaseAbilityLink_001, TestSize.Level3)
332 {
333     DTEST_LOG << "DSchedCollabManagerTest ReleaseAbilityLink_001 begin" << std::endl;
334     const std::string bundleName = "";
335     const int32_t pid = 0;
336     int32_t ret = DSchedCollabManager::GetInstance().ReleaseAbilityLink(bundleName, pid);
337     EXPECT_EQ(ret, ERR_OK);
338     DTEST_LOG << "DSchedCollabManagerTest ReleaseAbilityLink_001 end" << std::endl;
339 }
340 
341 /**
342  * @tc.name: CancleReleaseAbilityLink_001
343  * @tc.desc: test CancleReleaseAbilityLink func
344  * @tc.type: FUNC
345  */
346 HWTEST_F(DSchedCollabManagerTest, CancleReleaseAbilityLink_001, TestSize.Level3)
347 {
348     DTEST_LOG << "DSchedCollabManagerTest CancleReleaseAbilityLink_001 begin" << std::endl;
349     const std::string bundleName = "";
350     const int32_t pid = 0;
351     int32_t ret = DSchedCollabManager::GetInstance().CancleReleaseAbilityLink(bundleName, pid);
352     EXPECT_EQ(ret, ERR_OK);
353     DTEST_LOG << "DSchedCollabManagerTest CancleReleaseAbilityLink_001 end" << std::endl;
354 }
355 
356 /**
357  * @tc.name: CleanUpSession_001
358  * @tc.desc: test CleanUpSession func
359  * @tc.type: FUNC
360  */
361 HWTEST_F(DSchedCollabManagerTest, CleanUpSession_001, TestSize.Level3)
362 {
363     DTEST_LOG << "DSchedCollabManagerTest CleanUpSession_001 begin" << std::endl;
364     const std::string collabToken = "";
365     int32_t ret = DSchedCollabManager::GetInstance().CleanUpSession(collabToken);
366     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
367     DTEST_LOG << "DSchedCollabManagerTest CleanUpSession_001 end" << std::endl;
368 }
369 
370 /**
371  * @tc.name: GetDSchedCollabByTokenId_001
372  * @tc.desc: test GetDSchedCollabByTokenId func
373  * @tc.type: FUNC
374  */
375 HWTEST_F(DSchedCollabManagerTest, GetDSchedCollabByTokenId_001, TestSize.Level3)
376 {
377     DTEST_LOG << "DSchedCollabManagerTest GetDSchedCollabByTokenId_001 begin" << std::endl;
378     const std::string collabToken = "";
379     auto collab = DSchedCollabManager::GetInstance().GetDSchedCollabByTokenId(collabToken);
380     EXPECT_EQ(collab, nullptr);
381     DTEST_LOG << "DSchedCollabManagerTest GetDSchedCollabByTokenId_001 end" << std::endl;
382 }
383 
384 /**
385  * @tc.name: OnDataRecv_001
386  * @tc.desc: test OnDataRecv func
387  * @tc.type: FUNC
388  */
389 HWTEST_F(DSchedCollabManagerTest, OnDataRecv_001, TestSize.Level3)
390 {
391     DTEST_LOG << "DSchedCollabManagerTest OnDataRecv_001 begin" << std::endl;
392     const int32_t softbusSessionId = 0;
393     std::shared_ptr<DSchedDataBuffer> dataBuffer;
394     DSchedCollabManager::GetInstance().OnDataRecv(softbusSessionId, dataBuffer);
395     EXPECT_EQ(DSchedCollabManager::GetInstance().collabs_.empty(), true);
396     DTEST_LOG << "DSchedCollabManagerTest OnDataRecv_001 end" << std::endl;
397 }
398 
399 /**
400  * @tc.name: OnDataRecv_002
401  * @tc.desc: test OnDataRecv func
402  * @tc.type: FUNC
403  */
404 HWTEST_F(DSchedCollabManagerTest, OnDataRecv_002, TestSize.Level3)
405 {
406     DTEST_LOG << "DSchedCollabManagerTest OnDataRecv_002 begin" << std::endl;
407     int32_t softbusSessionId = 0;
408     size_t sizeL = 20;
409     std::shared_ptr<DSchedDataBuffer> dataBuffer = std::make_shared<DSchedDataBuffer>(sizeL);
410     DSchedCollabManager::GetInstance().OnDataRecv(softbusSessionId, dataBuffer);
411     EXPECT_EQ(DSchedCollabManager::GetInstance().collabs_.empty(), true);
412     DTEST_LOG << "DSchedCollabManagerTest OnDataRecv_002 end" << std::endl;
413 }
414 
415 /**
416  * @tc.name: OnShutdown_001
417  * @tc.desc: test OnShutdown func
418  * @tc.type: FUNC
419  */
420 HWTEST_F(DSchedCollabManagerTest, OnShutdown_001, TestSize.Level3)
421 {
422     DTEST_LOG << "DSchedCollabManagerTest OnShutdown_001 begin" << std::endl;
423     int32_t softbusSessionId = 0;
424     DSchedCollabManager::GetInstance().OnShutdown(softbusSessionId, true);
425     EXPECT_EQ(DSchedCollabManager::GetInstance().collabs_.empty(), true);
426     DSchedCollabManager::GetInstance().OnShutdown(softbusSessionId, false);
427     EXPECT_EQ(DSchedCollabManager::GetInstance().collabs_.empty(), true);
428     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test1", nullptr));
429     const std::string collabToken = "";
430     DSchedCollabInfo info;
431     auto newCollab = std::make_shared<DSchedCollab>(collabToken, info);
432     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test2", newCollab));
433     int32_t sessionId = 1;
434     auto dCollab = std::make_shared<DSchedCollab>(collabToken, info);
435     newCollab->softbusSessionId_ = softbusSessionId;
436     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test3", dCollab));
437     DSchedCollabManager::GetInstance().OnShutdown(softbusSessionId, false);
438     EXPECT_NE(DSchedCollabManager::GetInstance().collabs_.empty(), true);
439     DSchedCollabManager::GetInstance().collabs_.erase("test1");
440     DSchedCollabManager::GetInstance().collabs_.erase("test2");
441     DSchedCollabManager::GetInstance().collabs_.erase("test3");
442     EXPECT_EQ(DSchedCollabManager::GetInstance().collabs_.empty(), true);
443     DSchedCollabManager::GetInstance().collabs_.clear();
444     DTEST_LOG << "DSchedCollabManagerTest OnShutdown_001 end" << std::endl;
445 }
446 
447 /**
448  * @tc.name: CheckCollabRelation_001
449  * @tc.desc: test CheckCollabRelation func
450  * @tc.type: FUNC
451  */
452 HWTEST_F(DSchedCollabManagerTest, CheckCollabRelation_001, TestSize.Level3)
453 {
454     DTEST_LOG << "DSchedCollabManagerTest CheckCollabRelation_001 begin" << std::endl;
455     DSchedCollabManager::GetInstance().collabs_.clear();
456     CollabInfo sourceInfo{.deviceId = "srcUdid", .pid = 100, .tokenId = 100, .userId = 100};
457     CollabInfo sinkInfo{.deviceId = "sinkUdid", .pid = 200, .tokenId = 200, .userId = 101};
458     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), INVALID_PARAMETERS_ERR);
459 
460     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test1", nullptr));
461     const std::string collabToken = "";
462     DSchedCollabInfo info;
463     info.srcUdid_ = sourceInfo.deviceId;
464     info.sinkUdid_ = sinkInfo.deviceId;
465     info.sinkUserId_ = sinkInfo.userId;
466     info.srcInfo_.pid_ = sourceInfo.pid;
467     info.srcInfo_.accessToken_ = sourceInfo.tokenId;
468     info.sinkInfo_.pid_ = sinkInfo.pid;
469     info.sinkInfo_.accessToken_ = sinkInfo.tokenId;
470     info.srcAccountInfo_.userId = sourceInfo.userId;
471     auto newCollab = std::make_shared<DSchedCollab>(collabToken, info);
472     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test2", newCollab));
473     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), ERR_OK);
474 
475     sinkInfo.userId = info.sinkUserId_ + 1;
476     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), INVALID_PARAMETERS_ERR);
477     sinkInfo.userId = info.sinkUserId_;
478     sourceInfo.userId = info.srcAccountInfo_.userId + 1;
479     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), INVALID_PARAMETERS_ERR);
480     sourceInfo.userId = info.srcAccountInfo_.userId;
481     sinkInfo.tokenId = info.sinkInfo_.accessToken_ + 1;
482     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), INVALID_PARAMETERS_ERR);
483     sinkInfo.tokenId = info.sinkInfo_.accessToken_;
484     sourceInfo.tokenId = info.srcInfo_.accessToken_ + 1;
485     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), INVALID_PARAMETERS_ERR);
486     sourceInfo.tokenId = info.srcInfo_.accessToken_;
487     sinkInfo.pid = info.sinkInfo_.pid_ + 1;
488     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), INVALID_PARAMETERS_ERR);
489     sinkInfo.pid = info.sinkInfo_.pid_;
490     sourceInfo.pid = info.srcInfo_.pid_ + 1;
491     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), INVALID_PARAMETERS_ERR);
492     sourceInfo.pid = info.srcInfo_.pid_;
493     int len = sprintf_s(sinkInfo.deviceId, sizeof(sinkInfo.deviceId), "%s", "test");
494     ASSERT_GT(len, 0);
495     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), INVALID_PARAMETERS_ERR);
496     len = sprintf_s(sinkInfo.deviceId, sizeof(sinkInfo.deviceId), "%s", info.srcUdid_.c_str());
497     ASSERT_GT(len, 0);
498     len = sprintf_s(sourceInfo.deviceId, sizeof(sourceInfo.deviceId), "%s", "test");
499     ASSERT_GT(len, 0);
500     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckCollabRelation(&sourceInfo, &sinkInfo), INVALID_PARAMETERS_ERR);
501     DSchedCollabManager::GetInstance().collabs_.clear();
502     DTEST_LOG << "DSchedCollabManagerTest CheckCollabRelation_001 end" << std::endl;
503 }
504 
505 /**
506  * @tc.name: CheckSrcCollabRelation_001
507  * @tc.desc: test CheckSrcCollabRelation func
508  * @tc.type: FUNC
509  */
510 HWTEST_F(DSchedCollabManagerTest, CheckSrcCollabRelation_001, TestSize.Level3)
511 {
512     DTEST_LOG << "DSchedCollabManagerTest CheckSrcCollabRelation_001 begin" << std::endl;
513     CollabInfo *nullSourceInfo;
514     DSchedCollabInfo *collabInfo;
515     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckSrcCollabRelation(nullSourceInfo, collabInfo),
516         INVALID_PARAMETERS_ERR);
517 
518     CollabInfo sourceInfo{.deviceId = "srcUdid", .pid = 100, .tokenId = 100, .userId = 100};
519     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckSrcCollabRelation(&sourceInfo, collabInfo),
520         INVALID_PARAMETERS_ERR);
521     DTEST_LOG << "DSchedCollabManagerTest CheckSrcCollabRelation_001 end" << std::endl;
522 }
523 
524 /**
525  * @tc.name: CheckSinkCollabRelation_001
526  * @tc.desc: test CheckSinkCollabRelation func
527  * @tc.type: FUNC
528  */
529 HWTEST_F(DSchedCollabManagerTest, CheckSinkCollabRelation_001, TestSize.Level3)
530 {
531     DTEST_LOG << "DSchedCollabManagerTest CheckSinkCollabRelation_001 begin" << std::endl;
532     CollabInfo *nullSinkInfo;
533     DSchedCollabInfo *collabInfo;
534     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckSinkCollabRelation(nullSinkInfo, collabInfo),
535         INVALID_PARAMETERS_ERR);
536 
537     CollabInfo sinkInfo{.deviceId = "sinkUdid", .pid = 200, .tokenId = 200, .userId = 101};
538     EXPECT_EQ(DSchedCollabManager::GetInstance().CheckSinkCollabRelation(&sinkInfo, collabInfo),
539         INVALID_PARAMETERS_ERR);
540     DTEST_LOG << "DSchedCollabManagerTest CheckSinkCollabRelation_001 end" << std::endl;
541 }
542 
543 /**
544  * @tc.name: IsSessionExists_001
545  * @tc.desc: test IsSessionExists func
546  * @tc.type: FUNC
547  */
548 HWTEST_F(DSchedCollabManagerTest, IsSessionExists_001, TestSize.Level3)
549 {
550     DTEST_LOG << "DSchedCollabManagerTest IsSessionExists_001 begin" << std::endl;
551     DSchedCollabManager::GetInstance().collabs_.clear();
552     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", nullptr));
553     DSchedCollabInfo info;
554     info.srcInfo_.pid_ = 100;
555     info.srcCollabSessionId_ = 1;
556 
557     DSchedCollabInfo info2;
558     info2.srcInfo_.pid_ = 100;
559     info2.srcCollabSessionId_ = 2;
560     auto collab2 = std::make_shared<DSchedCollab>("test2", info2);
561     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test2", collab2));
562 
563     DSchedCollabInfo info3;
564     info3.srcInfo_.pid_ = 101;
565     info3.srcCollabSessionId_ = 2;
566     auto collab3 = std::make_shared<DSchedCollab>("test3", info3);
567     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test3", collab3));
568 
569     DSchedCollabInfo info4;
570     info4.srcInfo_.pid_ = 101;
571     info4.srcCollabSessionId_ = 1;
572     auto collab4 = std::make_shared<DSchedCollab>("test4", info4);
573     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test4", collab4));
574     EXPECT_FALSE(DSchedCollabManager::GetInstance().IsSessionExists(info));
575 
576     auto collab = std::make_shared<DSchedCollab>("test1", info);
577     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test1", collab));
578     EXPECT_TRUE(DSchedCollabManager::GetInstance().IsSessionExists(info));
579     DTEST_LOG << "DSchedCollabManagerTest IsSessionExists_001 end" << std::endl;
580 }
581 
582 
583 /**
584  * @tc.name: NotifyDataRecv_001
585  * @tc.desc: test NotifyDataRecv func
586  * @tc.type: FUNC
587  */
588 HWTEST_F(DSchedCollabManagerTest, NotifyDataRecv_001, TestSize.Level3)
589 {
590     DTEST_LOG << "DSchedCollabManagerTest NotifyDataRecv_001 begin" << std::endl;
591     int32_t softbusSessionId = 1;
592     int32_t command = NOTIFY_RESULT_CMD;
593     std::string collabToken = "token";
594     std::string jsonStr = "test";
595     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
596     EXPECT_TRUE(DSchedCollabManager::GetInstance().collabs_.empty());
597 
598     DSchedCollabInfo info;
599     auto dCollab = std::make_shared<DSchedCollab>(collabToken, info);
600     dCollab->softbusSessionId_ = 0;
601     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", nullptr));
602     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
603     EXPECT_FALSE(DSchedCollabManager::GetInstance().collabs_.empty());
604 
605     DSchedCollabManager::GetInstance().collabs_.erase("test");
606     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", dCollab));
607     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
608     EXPECT_FALSE(DSchedCollabManager::GetInstance().collabs_.empty());
609 
610     DSchedCollabManager::GetInstance().collabs_.erase("test");
611     dCollab->softbusSessionId_ = softbusSessionId;
612     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", dCollab));
613     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
614     EXPECT_FALSE(DSchedCollabManager::GetInstance().collabs_.empty());
615 
616     collabToken = "diffToken";
617     DSchedCollabManager::GetInstance().collabs_.erase("test");
618     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", dCollab));
619     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
620     EXPECT_FALSE(DSchedCollabManager::GetInstance().collabs_.empty());
621     DTEST_LOG << "DSchedCollabManagerTest NotifyDataRecv_001 end" << std::endl;
622 }
623 
624 /**
625  * @tc.name: NotifyDataRecv_002
626  * @tc.desc: test NotifyDataRecv func
627  * @tc.type: FUNC
628  */
629 HWTEST_F(DSchedCollabManagerTest, NotifyDataRecv_002, TestSize.Level3)
630 {
631     DTEST_LOG << "DSchedCollabManagerTest NotifyDataRecv_002 begin" << std::endl;
632     int32_t softbusSessionId = 1;
633     int32_t command = SINK_START_CMD;
634     std::string collabToken = "token";
635     std::string jsonStr;
636     auto startCmd = std::make_shared<SinkStartCmd>();
637     startCmd->Marshal(jsonStr);
638     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
639     EXPECT_TRUE(DSchedCollabManager::GetInstance().collabs_.empty());
640 
641     DSchedCollabInfo info;
642     auto dCollab = std::make_shared<DSchedCollab>(collabToken, info);
643     dCollab->softbusSessionId_ = 0;
644     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", nullptr));
645     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
646     EXPECT_FALSE(DSchedCollabManager::GetInstance().collabs_.empty());
647 
648     DSchedCollabManager::GetInstance().collabs_.erase("test");
649     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", dCollab));
650     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
651     EXPECT_FALSE(DSchedCollabManager::GetInstance().collabs_.empty());
652 
653     DSchedCollabManager::GetInstance().collabs_.erase("test");
654     dCollab->softbusSessionId_ = softbusSessionId;
655     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", dCollab));
656     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
657     EXPECT_FALSE(DSchedCollabManager::GetInstance().collabs_.empty());
658 
659     collabToken = "diffToken";
660     DSchedCollabManager::GetInstance().collabs_.erase("test");
661     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", dCollab));
662     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
663     DSchedCollabManager::GetInstance().NotifyDataRecv(softbusSessionId, command, jsonStr, nullptr, collabToken);
664     EXPECT_FALSE(DSchedCollabManager::GetInstance().collabs_.empty());
665     DTEST_LOG << "DSchedCollabManagerTest NotifyDataRecv_002 end" << std::endl;
666 }
667 
668 /**
669  * @tc.name: HandleReleaseAbilityLink_001
670  * @tc.desc: test HandleReleaseAbilityLink func
671  * @tc.type: FUNC
672  */
673 HWTEST_F(DSchedCollabManagerTest, HandleReleaseAbilityLink_001, TestSize.Level3)
674 {
675     DTEST_LOG << "DSchedCollabManagerTest HandleReleaseAbilityLink_001 begin" << std::endl;
676     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", nullptr));
677 
678     DSchedCollabInfo info;
679     info.srcInfo_.bundleName_ = "bundleName";
680     info.srcInfo_.pid_ = 1;
681     info.sinkInfo_.pid_ = 2;
682 
683     std::string collabToken = "token";
684     auto dCollab = std::make_shared<DSchedCollab>(collabToken, info);
685 
686     std::string bundleName = "test";
687     int32_t pid = 0;
688     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test1", dCollab));
689     EXPECT_NO_FATAL_FAILURE(DSchedCollabManager::GetInstance().HandleReleaseAbilityLink(bundleName, pid, ""));
690 
691     bundleName = info.srcInfo_.bundleName_;
692     pid = info.srcInfo_.pid_;
693     EXPECT_NO_FATAL_FAILURE(DSchedCollabManager::GetInstance().HandleReleaseAbilityLink(bundleName, pid, ""));
694 
695     pid = info.sinkInfo_.pid_;
696     EXPECT_NO_FATAL_FAILURE(DSchedCollabManager::GetInstance().HandleReleaseAbilityLink(bundleName, pid, ""));
697     DTEST_LOG << "DSchedCollabManagerTest HandleReleaseAbilityLink_001 end" << std::endl;
698 }
699 
700 /**
701  * @tc.name: NotifyWifiOpen_001
702  * @tc.desc: test NotifyWifiOpen func
703  * @tc.type: FUNC
704  */
705 HWTEST_F(DSchedCollabManagerTest, NotifyWifiOpen_001, TestSize.Level3)
706 {
707     DTEST_LOG << "DSchedCollabManagerTest NotifyWifiOpen_001 begin" << std::endl;
708     DSchedCollabManager::GetInstance().collabs_.insert(std::make_pair("test", nullptr));
709 
710     DSchedCollabInfo info;
711     std::string collabToken = "token";
712     auto dCollab = std::make_shared<DSchedCollab>(collabToken, info);
713     EXPECT_NO_FATAL_FAILURE(DSchedCollabManager::GetInstance().NotifyWifiOpen());
714     DTEST_LOG << "DSchedCollabManagerTest NotifyWifiOpen_001 end" << std::endl;
715 }
716 
717 /**
718  * @tc.name: ConvertCollaborateResult_001
719  * @tc.desc: test ConvertCollaborateResult func
720  * @tc.type: FUNC
721  */
722 HWTEST_F(DSchedCollabManagerTest, ConvertCollaborateResult_001, TestSize.Level3)
723 {
724     DTEST_LOG << "DSchedCollabManagerTest ConvertCollaborateResult_001 begin" << std::endl;
725     int32_t result = REJECT;
726     int32_t ret = DSchedCollabManager::GetInstance().ConvertCollaborateResult(result);
727     EXPECT_EQ(ret, DistributedCollab::PEER_APP_REJECTED);
728 
729     result = ON_COLLABORATE_ERR;
730     ret = DSchedCollabManager::GetInstance().ConvertCollaborateResult(result);
731     EXPECT_EQ(ret, DistributedCollab::PEER_ABILITY_NO_ONCOLLABORATE);
732 
733     result = ACCEPT;
734     ret = DSchedCollabManager::GetInstance().ConvertCollaborateResult(result);
735     EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
736     DTEST_LOG << "DSchedCollabManagerTest ConvertCollaborateResult_001 end" << std::endl;
737 }
738 }
739 }
740