1 /*
2 * Copyright (c) 2024 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 "network/softbus/softbus_agent.h"
16
17 #include "gtest/gtest.h"
18 #include <memory>
19 #include <unistd.h>
20
21 #include "device_manager_impl.h"
22 #include "dm_constants.h"
23 #include "softbus_error_code.h"
24
25 #include "network/softbus/softbus_session_dispatcher.h"
26 #include "network/softbus/softbus_session.h"
27 #include "utils_log.h"
28 #include "socket_mock.h"
29
30 using namespace std;
31 namespace {
32 bool g_mockGetTrustedDeviceList = true;
33 bool g_mockGetNetworkTypeByNetworkId = true;
34 bool g_mockNetworkTypWIFI = true;
35 const string NETWORKID_ONE = "45656596896323231";
36 const string NETWORKID_TWO = "45656596896323232";
37 const string NETWORKID_THREE = "45656596896323233";
38 constexpr int32_t NETWORKTYPE_WITH_WIFI = 2;
39 constexpr int32_t NETWORKTYPE_NONE_WIFI = 4;
40 }
41
42 namespace OHOS {
43 namespace DistributedHardware {
GetTrustedDeviceList(const std::string & pkgName,const std::string & extra,std::vector<DmDeviceInfo> & deviceList)44 int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
45 std::vector<DmDeviceInfo> &deviceList)
46 {
47 if (!g_mockGetTrustedDeviceList) {
48 return ERR_DM_INPUT_PARA_INVALID;
49 }
50
51 DmDeviceInfo testInfo;
52 (void)memcpy_s(testInfo.networkId, DM_MAX_DEVICE_ID_LEN - 1,
53 NETWORKID_ONE.c_str(), NETWORKID_ONE.size());
54 testInfo.authForm = DmAuthForm::IDENTICAL_ACCOUNT;
55 deviceList.push_back(testInfo);
56
57 DmDeviceInfo testInfo1;
58 (void)memcpy_s(testInfo1.networkId, DM_MAX_DEVICE_ID_LEN - 1,
59 NETWORKID_TWO.c_str(), NETWORKID_TWO.size());
60 testInfo1.authForm = DmAuthForm::PEER_TO_PEER;
61 deviceList.push_back(testInfo1);
62 return DM_OK;
63 }
64
GetNetworkTypeByNetworkId(const std::string & pkgName,const std::string & netWorkId,int32_t & netWorkType)65 int32_t DeviceManagerImpl::GetNetworkTypeByNetworkId(const std::string &pkgName, const std::string &netWorkId,
66 int32_t &netWorkType)
67 {
68 if (!g_mockGetNetworkTypeByNetworkId) {
69 return ERR_DM_INPUT_PARA_INVALID;
70 }
71
72 if (g_mockNetworkTypWIFI) {
73 netWorkType = NETWORKTYPE_WITH_WIFI;
74 return DM_OK;
75 }
76
77 netWorkType = NETWORKTYPE_NONE_WIFI;
78 return DM_OK;
79 }
80 }
81 }
82 namespace OHOS {
83 namespace Storage {
84 namespace DistributedFile {
85 namespace Test {
86 using namespace testing;
87 using namespace testing::ext;
88 constexpr int USER_ID = 100;
89 constexpr int MAX_RETRY_COUNT = 7;
90 static const string SAME_ACCOUNT = "account";
91 const string SESSION_NAME = "DistributedFileService/mnt/hmdfs/100/account";
92
93 class SoftbusAgentTest : public testing::Test {
94 public:
95 static void SetUpTestCase(void);
96 static void TearDownTestCase(void);
SetUp()97 void SetUp() {};
TearDown()98 void TearDown() {};
99 static inline shared_ptr<SocketMock> socketMock_ = nullptr;
100 };
101
SetUpTestCase(void)102 void SoftbusAgentTest::SetUpTestCase(void)
103 {
104 GTEST_LOG_(INFO) << "SetUpTestCase";
105 socketMock_ = make_shared<SocketMock>();
106 SocketMock::dfsSocket = socketMock_;
107 }
108
TearDownTestCase(void)109 void SoftbusAgentTest::TearDownTestCase(void)
110 {
111 GTEST_LOG_(INFO) << "TearDownTestCase";
112 SocketMock::dfsSocket = nullptr;
113 socketMock_ = nullptr;
114 }
115
116 /**
117 * @tc.name: SoftbusAgentTest_SoftbusAgent_0100
118 * @tc.desc: Verify the SoftbusAgent function.
119 * @tc.type: FUNC
120 * @tc.require: I9JXPR
121 */
122 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_SoftbusAgent_0100, TestSize.Level1)
123 {
124 GTEST_LOG_(INFO) << "SoftbusAgentTest_SoftbusAgent_0100 start";
125 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
126 shared_ptr<MountPoint> smp = move(mp);
127 weak_ptr<MountPoint> wmp(smp);
128 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
129 EXPECT_EQ(agent->sessionName_, SESSION_NAME);
130
131 weak_ptr<MountPoint> nullwmp;
132 std::shared_ptr<SoftbusAgent> agent2 = std::make_shared<SoftbusAgent>(nullwmp);
133 EXPECT_EQ(agent2->sessionName_, SESSION_NAME);
134 GTEST_LOG_(INFO) << "SoftbusAgentTest_SoftbusAgent_0100 end";
135 }
136
137 /**
138 * @tc.name: SoftbusAgentTest_IsSameAccount_0100
139 * @tc.desc: Verify the IsSameAccount.
140 * @tc.type: FUNC
141 * @tc.require: I9JXPR
142 */
143 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_IsSameAccount_0100, TestSize.Level1)
144 {
145 GTEST_LOG_(INFO) << "SoftbusAgentTest_IsSameAccount_0100 start";
146 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
147 shared_ptr<MountPoint> smp = move(mp);
148 weak_ptr<MountPoint> wmp(smp);
149 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
150 bool flag = agent->IsSameAccount(NETWORKID_ONE);
151 EXPECT_EQ(flag, true);
152 #ifdef SUPPORT_SAME_ACCOUNT
153 flag = agent->IsSameAccount(NETWORKID_TWO);
154 EXPECT_EQ(flag, false);
155 flag = agent->IsSameAccount(NETWORKID_THREE);
156 EXPECT_EQ(flag, false);
157 g_mockGetTrustedDeviceList = false;
158 flag = agent->IsSameAccount(NETWORKID_ONE);
159 EXPECT_EQ(flag, false);
160 #endif
161 g_mockGetTrustedDeviceList = true;
162 GTEST_LOG_(INFO) << "SoftbusAgentTest_IsSameAccount_0100 end";
163 }
164
165 /**
166 * @tc.name: SoftbusAgentTest_QuitDomain_0100
167 * @tc.desc: Verify the QuitDomain.
168 * @tc.type: FUNC
169 * @tc.require: I9JXPR
170 */
171 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_QuitDomain_0100, TestSize.Level1)
172 {
173 GTEST_LOG_(INFO) << "SoftbusAgentTest_QuitDomain_0100 start";
174 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
175 shared_ptr<MountPoint> smp = move(mp);
176 weak_ptr<MountPoint> wmp(smp);
177 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
178 bool res = true;
179 try {
180 agent->QuitDomain();
181 } catch (const exception &e) {
182 res = false;
183 GTEST_LOG_(INFO) << e.what();
184 }
185 EXPECT_TRUE(res == false);
186 GTEST_LOG_(INFO) << "SoftbusAgentTest_QuitDomain_0100 end";
187 }
188
189 /**
190 * @tc.name: SoftbusAgentTest_QuitDomain_0200
191 * @tc.desc: Verify the QuitDomain.
192 * @tc.type: FUNC
193 * @tc.require: I9JXPR
194 */
195 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_QuitDomain_0200, TestSize.Level1)
196 {
197 GTEST_LOG_(INFO) << "SoftbusAgentTest_QuitDomain_0200 start";
198 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
199 shared_ptr<MountPoint> smp = move(mp);
200 weak_ptr<MountPoint> wmp(smp);
201 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
202 weak_ptr<SoftbusAgent> wsba(agent);
203 string busName = "test";
204 bool res = true;
205 try {
206 agent->serverIdMap_.insert(std::make_pair(busName, 1));
207 agent->QuitDomain();
208 agent->serverIdMap_.erase(busName);
209 } catch (const exception &e) {
210 res = false;
211 GTEST_LOG_(INFO) << e.what();
212 }
213 EXPECT_TRUE(res == false);
214 GTEST_LOG_(INFO) << "SoftbusAgentTest_QuitDomain_0200 end";
215 }
216
217 /**
218 * @tc.name: SoftbusAgentTest_QuitDomain_0300
219 * @tc.desc: Verify the QuitDomain.
220 * @tc.type: FUNC
221 * @tc.require: I9JXPR
222 */
223 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_QuitDomain_0300, TestSize.Level1)
224 {
225 GTEST_LOG_(INFO) << "SoftbusAgentTest_QuitDomain_0300 start";
226 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
227 shared_ptr<MountPoint> smp = move(mp);
228 weak_ptr<MountPoint> wmp(smp);
229 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
230 bool res = true;
231 weak_ptr<SoftbusAgent> wsba(agent);
232 string busName = agent->sessionName_;
233 try {
234 SoftbusSessionDispatcher::RegisterSessionListener(busName, wsba);
235 agent->serverIdMap_.insert(std::make_pair(busName, 1));
236 agent->QuitDomain();
237 auto agentRlt = SoftbusSessionDispatcher::busNameToAgent_.find(busName);
238 if (agentRlt != SoftbusSessionDispatcher::busNameToAgent_.end()) {
239 EXPECT_TRUE(false);
240 } else {
241 EXPECT_TRUE(true);
242 }
243 agent->serverIdMap_.erase(busName);
244 } catch (const exception &e) {
245 res = false;
246 GTEST_LOG_(INFO) << e.what();
247 }
248 EXPECT_TRUE(res);
249 GTEST_LOG_(INFO) << "SoftbusAgentTest_QuitDomain_0300 end";
250 }
251
252 /**
253 * @tc.name: SoftbusAgentTest_OnSessionClosed_0100
254 * @tc.desc: Verify the OnSessionClosed function.
255 * @tc.type: FUNC
256 * @tc.require: SR000H0387
257 */
258 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_OnSessionClosed_0100, TestSize.Level1)
259 {
260 GTEST_LOG_(INFO) << "SoftbusAgentTest_OnSessionClosed_0100 start";
261 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
262 shared_ptr<MountPoint> smp = move(mp);
263 weak_ptr<MountPoint> wmp(smp);
264 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
265 const int sessionId = 1;
266 bool res = true;
267 std::string peerDeviceId = "f6d4c0864707aefte7a78f09473aa122ff57fc8";
268 try {
269 agent->OnSessionClosed(sessionId, peerDeviceId);
270 } catch (const exception &e) {
271 res = false;
272 LOGE("%{public}s", e.what());
273 }
274 EXPECT_TRUE(res == true);
275 GTEST_LOG_(INFO) << "SoftbusAgentTest_OnSessionClosed_0100 end";
276 }
277
278 /**
279 * @tc.name: SoftbusAgentTest_JoinDomain_0100
280 * @tc.desc: Verify the Start function.
281 * @tc.type: FUNC
282 * @tc.require: I9JXPR
283 */
284 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_JoinDomain_0100, TestSize.Level1)
285 {
286 GTEST_LOG_(INFO) << "SoftbusAgentTest_JoinDomain_0100 start";
287 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
288 shared_ptr<MountPoint> smp = move(mp);
289 weak_ptr<MountPoint> wmp(smp);
290 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
291 bool res = true;
292 try {
293 EXPECT_CALL(*socketMock_, Socket(_)).WillOnce(Return(-1));
294 agent->JoinDomain();
295 EXPECT_NE(SoftbusSessionDispatcher::busNameToAgent_.find(agent->sessionName_),
296 SoftbusSessionDispatcher::busNameToAgent_.end());
297 EXPECT_EQ(agent->serverIdMap_.find(agent->sessionName_),
298 agent->serverIdMap_.end());
299 SoftbusSessionDispatcher::busNameToAgent_.erase(agent->sessionName_);
300
301 EXPECT_CALL(*socketMock_, Socket(_)).WillOnce(Return(1));
302 EXPECT_CALL(*socketMock_, Listen(_, _, _, _)).WillOnce(Return(0));
303 agent->JoinDomain();
304 EXPECT_NE(agent->serverIdMap_.find(agent->sessionName_),
305 agent->serverIdMap_.end());
306 agent->serverIdMap_.erase(agent->sessionName_);
307 SoftbusSessionDispatcher::busNameToAgent_.erase(agent->sessionName_);
308 GTEST_LOG_(INFO) << "3";
309 } catch (const exception &e) {
310 res = false;
311 LOGE("%{public}s", e.what());
312 }
313 EXPECT_TRUE(res);
314 GTEST_LOG_(INFO) << "SoftbusAgentTest_JoinDomain_0100 end";
315 }
316
317 /**
318 * @tc.name: SoftbusAgentTest_JoinDomain_0200
319 * @tc.desc: Verify the Start function.
320 * @tc.type: FUNC
321 * @tc.require: I9JXPR
322 */
323 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_JoinDomain_0200, TestSize.Level1)
324 {
325 GTEST_LOG_(INFO) << "SoftbusAgentTest_JoinDomain_0200 start";
326 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
327 shared_ptr<MountPoint> smp = move(mp);
328 weak_ptr<MountPoint> wmp(smp);
329 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
330 bool res = true;
331 try {
332 EXPECT_CALL(*socketMock_, Socket(_)).WillOnce(Return(1));
333 EXPECT_CALL(*socketMock_, Listen(_, _, _, _)).WillOnce(Return(-1));
334 agent->JoinDomain();
335 } catch (...) {
336 res = false;
337 EXPECT_NE(SoftbusSessionDispatcher::busNameToAgent_.find(agent->sessionName_),
338 SoftbusSessionDispatcher::busNameToAgent_.end());
339 SoftbusSessionDispatcher::busNameToAgent_.erase(agent->sessionName_);
340 }
341 EXPECT_FALSE(res);
342 GTEST_LOG_(INFO) << "SoftbusAgentTest_JoinDomain_0200 end";
343 }
344
345 /**
346 * @tc.name: SoftbusAgentTest_Stop_0100
347 * @tc.desc: Verify the Stop function.
348 * @tc.type: FUNC
349 * @tc.require: SR000H0387
350 */
351 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_Stop_0100, TestSize.Level1)
352 {
353 GTEST_LOG_(INFO) << "SoftbusAgentTest_Stop_0100 start";
354 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
355 shared_ptr<MountPoint> smp = move(mp);
356 weak_ptr<MountPoint> wmp(smp);
357 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
358 bool res = true;
359 try {
360 SoftbusSessionDispatcher::busNameToAgent_.erase(agent->sessionName_);
361 agent->Stop();
362 } catch (const exception &e) {
363 res = false;
364 LOGE("%{public}s", e.what());
365 }
366 EXPECT_FALSE(res);
367 GTEST_LOG_(INFO) << "SoftbusAgentTest_Stop_0100 end";
368 }
369
370 /**
371 * @tc.name: SoftbusAgentTest_ConnectOnlineDevices_0100
372 * @tc.desc: Verify the ConnectOnlineDevices function.
373 * @tc.type: FUNC
374 * @tc.require: SR000H0387
375 */
376 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_ConnectOnlineDevices_0100, TestSize.Level1)
377 {
378 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectOnlineDevices_0100 start";
379 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
380 shared_ptr<MountPoint> smp = move(mp);
381 weak_ptr<MountPoint> wmp(smp);
382 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
383 bool res = true;
384 g_mockGetTrustedDeviceList = true;
385 g_mockGetNetworkTypeByNetworkId = false;
386 try {
387 agent->ConnectOnlineDevices();
388 } catch (const exception &e) {
389 res = false;
390 LOGE("%{public}s", e.what());
391 }
392 EXPECT_TRUE(res);
393 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectOnlineDevices_0100 end";
394 }
395
396 /**
397 * @tc.name: SoftbusAgentTest_ConnectOnlineDevices_0200
398 * @tc.desc: Verify the ConnectOnlineDevices function.
399 * @tc.type: FUNC
400 * @tc.require: I9JXPR
401 */
402 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_ConnectOnlineDevices_0200, TestSize.Level1)
403 {
404 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectOnlineDevices_0200 start";
405 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
406 shared_ptr<MountPoint> smp = move(mp);
407 weak_ptr<MountPoint> wmp(smp);
408 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
409 bool res = true;
410 g_mockGetTrustedDeviceList = true;
411 g_mockGetNetworkTypeByNetworkId = true;
412 g_mockNetworkTypWIFI = true;
413 try {
414 agent->ConnectOnlineDevices();
415 } catch (const exception &e) {
416 res = false;
417 LOGE("%{public}s", e.what());
418 }
419 EXPECT_TRUE(res);
420 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectOnlineDevices_0200 end";
421 }
422
423 /**
424 * @tc.name: SoftbusAgentTest_ConnectOnlineDevices_0300
425 * @tc.desc: Verify the ConnectOnlineDevices function.
426 * @tc.type: FUNC
427 * @tc.require: I9JXPR
428 */
429 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_ConnectOnlineDevices_0300, TestSize.Level1)
430 {
431 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectOnlineDevices_0300 start";
432 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
433 shared_ptr<MountPoint> smp = move(mp);
434 weak_ptr<MountPoint> wmp(smp);
435 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
436 bool res = true;
437 g_mockGetTrustedDeviceList = true;
438 g_mockGetNetworkTypeByNetworkId = true;
439 g_mockNetworkTypWIFI = false;
440 try {
441 agent->ConnectOnlineDevices();
442 } catch (const exception &e) {
443 res = false;
444 LOGE("%{public}s", e.what());
445 }
446 EXPECT_TRUE(res);
447 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectOnlineDevices_0100 end";
448 }
449
450 /**
451 * @tc.name: SoftbusAgentTest_ConnectOnlineDevices_0400
452 * @tc.desc: Verify the ConnectOnlineDevices function.
453 * @tc.type: FUNC
454 * @tc.require: I9JXPR
455 */
456 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_ConnectOnlineDevices_0400, TestSize.Level1)
457 {
458 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectOnlineDevices_0400 start";
459 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
460 shared_ptr<MountPoint> smp = move(mp);
461 weak_ptr<MountPoint> wmp(smp);
462 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
463 bool res = true;
464 g_mockGetTrustedDeviceList = false;
465 try {
466 agent->ConnectOnlineDevices();
467 } catch (const exception &e) {
468 res = false;
469 LOGE("%{public}s", e.what());
470 }
471 EXPECT_TRUE(res == false);
472 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectOnlineDevices_0400 end";
473 }
474
475 /**
476 * @tc.name: SoftbusAgentTest_DisconnectAllDevices_0100
477 * @tc.desc: Verify the DisconnectAllDevices function.
478 * @tc.type: FUNC
479 * @tc.require: SR000H0387
480 */
481 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_DisconnectAllDevices_0100, TestSize.Level1)
482 {
483 GTEST_LOG_(INFO) << "SoftbusAgentTest_DisconnectAllDevices_0100 start";
484 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
485 shared_ptr<MountPoint> smp = move(mp);
486 weak_ptr<MountPoint> wmp(smp);
487 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
488 bool res = true;
489 try {
490 agent->DisconnectAllDevices();
491 } catch (const exception &e) {
492 res = false;
493 LOGE("%{public}s", e.what());
494 }
495 EXPECT_TRUE(res == true);
496 GTEST_LOG_(INFO) << "SoftbusAgentTest_DisconnectAllDevices_0100 end";
497 }
498
499 /**
500 * @tc.name: SoftbusAgentTest_AcceptSession_0100
501 * @tc.desc: Verify the AcceptSession function.
502 * @tc.type: FUNC
503 * @tc.require: SR000H0387
504 */
505 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_AcceptSession_0100, TestSize.Level1)
506 {
507 GTEST_LOG_(INFO) << "SoftbusAgentTest_AcceptSession_0100 start";
508 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
509 shared_ptr<MountPoint> smp = move(mp);
510 weak_ptr<MountPoint> wmp(smp);
511 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
512 const int testSessionId = 99;
513 std::string peerDeviceId = "f6d4c0864707aefte7a78f09473aa122ff57fc8";
514 auto session = make_shared<SoftbusSession>(testSessionId, peerDeviceId);
515 bool res = true;
516 try {
517 agent->AcceptSession(session, "Server");
518 } catch (const exception &e) {
519 res = false;
520 LOGE("%{public}s", e.what());
521 }
522 EXPECT_TRUE(res);
523 GTEST_LOG_(INFO) << "SoftbusAgentTest_AcceptSession_0100 end";
524 }
525
526 /**
527 * @tc.name: SoftbusAgentTest_GetMountPoint_0100
528 * @tc.desc: Verify the GetMountPoint function.
529 * @tc.type: FUNC
530 * @tc.require: SR000H0387
531 */
532 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_GetMountPoint_0100, TestSize.Level1)
533 {
534 GTEST_LOG_(INFO) << "SoftbusAgentTest_GetMountPoint_0100 start";
535 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
536 shared_ptr<MountPoint> smp = move(mp);
537 weak_ptr<MountPoint> wmp(smp);
538 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
539 bool res = true;
540 try {
541 agent->GetMountPoint();
542 } catch (const exception &e) {
543 res = false;
544 LOGE("%{public}s", e.what());
545 }
546 EXPECT_TRUE(res);
547 GTEST_LOG_(INFO) << "SoftbusAgentTest_GetMountPoint_0100 end";
548 }
549
550 /**
551 * @tc.name: SoftbusAgentTest_CloseSession_0100
552 * @tc.desc: Verify the CloseSession function.
553 * @tc.type: FUNC
554 * @tc.require: issueI7SP3A
555 */
556 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_CloseSession_0100, TestSize.Level1)
557 {
558 GTEST_LOG_(INFO) << "SoftbusAgentTest_CloseSession_0100 start";
559 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
560 shared_ptr<MountPoint> smp = move(mp);
561 weak_ptr<MountPoint> wmp(smp);
562 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
563 try {
564 agent->CloseSession(nullptr);
565 EXPECT_TRUE(true);
566 } catch (const exception &e) {
567 LOGE("%{public}s", e.what());
568 EXPECT_TRUE(false);
569 }
570 GTEST_LOG_(INFO) << "SoftbusAgentTest_CloseSession_0100 end";
571 }
572
573 /**
574 * @tc.name: SoftbusAgentTest_IsContinueRetry_0100
575 * @tc.desc: Verify the IsContinueRetry function.
576 * @tc.type: FUNC
577 * @tc.require: issueI7SP3A
578 */
579 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_IsContinueRetry_0100, TestSize.Level1)
580 {
581 GTEST_LOG_(INFO) << "SoftbusAgentTest_IsContinueRetry_0100 start";
582 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
583 shared_ptr<MountPoint> smp = move(mp);
584 weak_ptr<MountPoint> wmp(smp);
585 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
586 string cid = "notExitCid";
587 try {
588 bool ret = agent->IsContinueRetry(cid);
589 EXPECT_EQ(agent->OpenSessionRetriedTimesMap_[cid], 1);
590 ret = agent->IsContinueRetry(cid);
591 EXPECT_EQ(ret, true);
592 agent->OpenSessionRetriedTimesMap_[cid] = MAX_RETRY_COUNT;
593 ret = agent->IsContinueRetry(cid);
594 EXPECT_EQ(ret, false);
595 } catch (const exception &e) {
596 LOGE("%{public}s", e.what());
597 EXPECT_TRUE(false);
598 }
599 GTEST_LOG_(INFO) << "SoftbusAgentTest_IsContinueRetry_0100 end";
600 }
601 } // namespace Test
602 } // namespace DistributedFile
603 } // namespace Storage
604 } // namespace OHOS
605