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_ConnectDeviceAsync_0100
439 * @tc.desc: Verify the ConnectDeviceAsync function.
440 * @tc.type: FUNC
441 * @tc.require: SR000H0387
442 */
443 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_ConnectDeviceAsync_0100, TestSize.Level1)
444 {
445 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectDeviceAsync_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 DistributedHardware::DmDeviceInfo info = {
451 .deviceId = "testdevid",
452 .deviceName = "testdevname",
453 .deviceTypeId = 1,
454 };
455 DeviceInfo devInfo(info);
456
457 bool res = true;
458 try {
459 agent->ConnectDeviceAsync(devInfo);
460 } catch (const exception &e) {
461 res = false;
462 LOGE("%{public}s", e.what());
463 }
464 EXPECT_TRUE(res);
465 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectDeviceAsync_0100 end";
466 }
467
468 /**
469 * @tc.name: SoftbusAgentTest_DisconnectDevice_0100
470 * @tc.desc: Verify the DisconnectDevice function.
471 * @tc.type: FUNC
472 * @tc.require: SR000H0387
473 */
474 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_DisconnectDevice_0100, TestSize.Level1)
475 {
476 GTEST_LOG_(INFO) << "SoftbusAgentTest_DisconnectDevice_0100 start";
477 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
478 shared_ptr<MountPoint> smp = move(mp);
479 weak_ptr<MountPoint> wmp(smp);
480 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
481 DistributedHardware::DmDeviceInfo info = {
482 .deviceId = "testdevid",
483 .deviceName = "testdevname",
484 .deviceTypeId = 1,
485 };
486 DeviceInfo devInfo(info);
487
488 bool res = true;
489 try {
490 agent->DisconnectDevice(devInfo);
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_DisconnectDevice_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_ConnectDeviceByP2PAsync_0100
552 * @tc.desc: Verify the ConnectDeviceByP2PAsync function.
553 * @tc.type: FUNC
554 * @tc.require: I7M6L1
555 */
556 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_ConnectDeviceByP2PAsync_0100, TestSize.Level1)
557 {
558 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectDeviceByP2PAsync_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 DistributedHardware::DmDeviceInfo info = {
564 .deviceId = "testdevid",
565 .deviceName = "testdevname",
566 .deviceTypeId = 1,
567 };
568 DeviceInfo devInfo(info);
569
570 bool res = true;
571 try {
572 agent->ConnectDeviceByP2PAsync(devInfo);
573 } catch (const exception &e) {
574 res = false;
575 LOGE("%{public}s", e.what());
576 }
577 EXPECT_TRUE(res);
578 GTEST_LOG_(INFO) << "SoftbusAgentTest_ConnectDeviceByP2PAsync_0100 end";
579 }
580
581 /**
582 * @tc.name: SoftbusAgentTest_CloseSession_0100
583 * @tc.desc: Verify the CloseSession function.
584 * @tc.type: FUNC
585 * @tc.require: issueI7SP3A
586 */
587 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_CloseSession_0100, TestSize.Level1)
588 {
589 GTEST_LOG_(INFO) << "SoftbusAgentTest_CloseSession_0100 start";
590 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
591 shared_ptr<MountPoint> smp = move(mp);
592 weak_ptr<MountPoint> wmp(smp);
593 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
594 try {
595 agent->CloseSession(nullptr);
596 EXPECT_TRUE(true);
597 } catch (const exception &e) {
598 LOGE("%{public}s", e.what());
599 EXPECT_TRUE(false);
600 }
601 GTEST_LOG_(INFO) << "SoftbusAgentTest_CloseSession_0100 end";
602 }
603
604 /**
605 * @tc.name: SoftbusAgentTest_IsContinueRetry_0100
606 * @tc.desc: Verify the IsContinueRetry function.
607 * @tc.type: FUNC
608 * @tc.require: issueI7SP3A
609 */
610 HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_IsContinueRetry_0100, TestSize.Level1)
611 {
612 GTEST_LOG_(INFO) << "SoftbusAgentTest_IsContinueRetry_0100 start";
613 auto mp = make_unique<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(USER_ID, SAME_ACCOUNT));
614 shared_ptr<MountPoint> smp = move(mp);
615 weak_ptr<MountPoint> wmp(smp);
616 std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
617 string cid = "notExitCid";
618 try {
619 bool ret = agent->IsContinueRetry(cid);
620 EXPECT_EQ(agent->OpenSessionRetriedTimesMap_[cid], 1);
621 ret = agent->IsContinueRetry(cid);
622 EXPECT_EQ(ret, true);
623 agent->OpenSessionRetriedTimesMap_[cid] = MAX_RETRY_COUNT;
624 ret = agent->IsContinueRetry(cid);
625 EXPECT_EQ(ret, false);
626 } catch (const exception &e) {
627 LOGE("%{public}s", e.what());
628 EXPECT_TRUE(false);
629 }
630 GTEST_LOG_(INFO) << "SoftbusAgentTest_IsContinueRetry_0100 end";
631 }
632 } // namespace Test
633 } // namespace DistributedFile
634 } // namespace Storage
635 } // namespace OHOS
636