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