1 /*
2  * Copyright (c) 2021 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 "gtest/gtest.h"
17 
18 #include <cstdio>
19 #include <cstdlib>
20 #include <cstring>
21 #include <ctime>
22 #include <cinttypes>
23 #include <iostream>
24 #include <semaphore.h>
25 #include <string>
26 #include <unistd.h>
27 #include <unordered_map>
28 #include <unordered_set>
29 
30 #include "common_list.h"
31 #include "inner_session.h"
32 #include "securec.h"
33 #include "session.h"
34 #include "softbus_adapter_mem.h"
35 #include "softbus_adapter_timer.h"
36 #include "softbus_bus_center.h"
37 #include "softbus_common.h"
38 #include "softbus_def.h"
39 #include "softbus_errcode.h"
40 #include "softbus_feature_config.h"
41 #include "softbus_file_test_entry.h"
42 #include "softbus_utils.h"
43 
44 using namespace testing::ext;
45 using namespace std;
46 namespace OHOS {
47 
48 const int SEND_DATA_SIZE_1K = 1024;
49 const int SEND_DATA_SIZE_4K = 4 * 1024;
50 const int SEND_DATA_SIZE_1M = 1024 * 1024;
51 const char *g_testData = "{\"data\":\"open session test!!!\"}";
52 
53 const char *SFILE_NAME_1K = "/data/file1K.tar";
54 const char *SFILE_NAME_5M = "/data/file5M.tar";
55 
56 const char *DFILE_NAME_1K = "file1K.tar";
57 const char *DFILE_NAME_5M = "file5M.tar";
58 const char *RECV_ROOT_PATH = "/data/recv/";
59 
60 typedef struct {
61     string mySessionName;
62     string peerSessionName;
63     int32_t testCnt;
64     int32_t sendNum;
65     int32_t dataType;
66     const char **sfileList;
67     const char **dfileList;
68     int32_t sfileCnt;
69 } TransTestInfo;
70 
71 unordered_set<string> networkIdSet_;
72 unordered_set<int32_t> sessionSet_;
73 sem_t localSem_;
74 int32_t openSessionSuccessCnt_ = 0;
75 const SoftbusTestEntry *testEntryArgs_ = nullptr;
76 
WaitDeviceOnline(const char * pkgName)77 int32_t WaitDeviceOnline(const char *pkgName)
78 {
79 #define GET_LNN_RETRY_COUNT 5
80     int32_t onlineRetryCount = 0;
81     int32_t ret;
82     while (true) {
83         NodeBasicInfo *onlineDevices = nullptr;
84         int32_t onlineNum = 0;
85         ret = GetAllNodeDeviceInfo(pkgName, &onlineDevices, &onlineNum);
86         onlineRetryCount++;
87         if (onlineRetryCount < GET_LNN_RETRY_COUNT && (ret != SOFTBUS_OK || onlineNum <= 0)) {
88             FreeNodeInfo(onlineDevices);
89             sleep(5);
90             continue;
91         }
92         cout << "online device num: " << onlineNum << endl;
93         for (int32_t i = 0; i < onlineNum; i++) {
94             networkIdSet_.insert(string(onlineDevices[i].networkId));
95             cout << "online idex " << i << " : " << string(onlineDevices[i].networkId) << endl;
96         }
97         FreeNodeInfo(onlineDevices);
98         break;
99     }
100     if (!networkIdSet_.empty()) {
101         return SOFTBUS_OK;
102     }
103     return SOFTBUS_TIMOUT;
104 }
105 
OnSessionOpened(int sessionId,int result)106 int OnSessionOpened(int sessionId, int result)
107 {
108     cout << "session opened, sesison id = " << sessionId << ", result = " << result << endl;
109     if (result == SOFTBUS_OK) {
110         sessionSet_.insert(sessionId);
111         openSessionSuccessCnt_++;
112     }
113     sem_post(&localSem_);
114     return SOFTBUS_OK;
115 }
116 
OnSessionClosed(int sessionId)117 void OnSessionClosed(int sessionId)
118 {
119     cout << "session closed, sesison id = " << sessionId << endl;
120     sessionSet_.erase(sessionId);
121 }
122 
OnStreamReceived(int sessionId,const StreamData * data,const StreamData * ext,const StreamFrameInfo * param)123 void OnStreamReceived(int sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *param)
124 {
125     if (data == nullptr) {
126         printf("StreamData is null, stream received fail\n");
127         return;
128     }
129     printf("stream received, sessionid[%d], data = %.*s\n", sessionId, data->bufLen, data->buf);
130     if (ext == nullptr || ext->buf == nullptr || data->bufLen <= 0) {
131         printf("parameters invalid, stream received fail\n");
132         return;
133     }
134     printf("stream received, sessionid[%d], extdata = %.*s\n", sessionId, ext->bufLen, ext->buf);
135 }
136 
OnBytesReceived(int sessionId,const void * data,unsigned int len)137 void OnBytesReceived(int sessionId, const void *data, unsigned int len)
138 {
139     if (testEntryArgs_->testSide_ == PASSIVE_OPENSESSION_WAY) {
140         SendBytes(sessionId, "{\"received ok\"}", strlen("{\"received ok\"}"));
141     }
142     printf("bytes received, sessionid[%d], data[%s], dataLen[%u]\n", sessionId, data, len);
143 }
144 
OnMessageReceived(int sessionId,const void * data,unsigned int len)145 void OnMessageReceived(int sessionId, const void *data, unsigned int len)
146 {
147     printf("msg received, sessionid[%d], data[%s], dataLen[%u]\n", sessionId, data, len);
148 }
149 
150 static ISessionListener g_listener = {
151     .OnSessionOpened = OnSessionOpened,
152     .OnSessionClosed = OnSessionClosed,
153     .OnStreamReceived = OnStreamReceived,
154     .OnBytesReceived = OnBytesReceived,
155     .OnMessageReceived = OnMessageReceived
156 };
157 
OnSendFileProcess(int sessionId,uint64_t bytesUpload,uint64_t bytesTotal)158 int OnSendFileProcess(int sessionId, uint64_t bytesUpload, uint64_t bytesTotal)
159 {
160     cout << "OnSendFileProcess sessionId = " << sessionId << ", bytesUpload = " <<
161         bytesUpload << ", total = " << bytesTotal << endl;
162     return 0;
163 }
164 
OnSendFileFinished(int sessionId,const char * firstFile)165 int OnSendFileFinished(int sessionId, const char *firstFile)
166 {
167     printf("OnSendFileFinished sessionId = %d, first file = %s\n", sessionId, firstFile);
168     return 0;
169 }
170 
OnFileTransError(int sessionId)171 void OnFileTransError(int sessionId)
172 {
173     printf("OnFileTransError sessionId = %d\n", sessionId);
174 }
175 
176 static IFileSendListener g_fileSendListener = {
177     .OnSendFileProcess = OnSendFileProcess,
178     .OnSendFileFinished = OnSendFileFinished,
179     .OnFileTransError = OnFileTransError,
180 };
181 
OnReceiveFileStarted(int sessionId,const char * files,int fileCnt)182 int OnReceiveFileStarted(int sessionId, const char *files, int fileCnt)
183 {
184     printf("File receive start sessionId = %d, first file = %s, fileCnt = %d\n", sessionId, files, fileCnt);
185     return 0;
186 }
187 
OnReceiveFileFinished(int sessionId,const char * files,int fileCnt)188 void OnReceiveFileFinished(int sessionId, const char *files, int fileCnt)
189 {
190     printf("File receive finished sessionId = %d, first file = %s, fileCnt = %d\n", sessionId, files, fileCnt);
191 }
192 
OnReceiveFileProcess(int sessionId,const char * firstFile,uint64_t bytesUpload,uint64_t bytesTotal)193 int OnReceiveFileProcess(int sessionId, const char *firstFile, uint64_t bytesUpload, uint64_t bytesTotal)
194 {
195     printf("File receive process sessionId = %d, first file = %s, upload = %" PRIu64 ", total = %" PRIu64 "\n",
196         sessionId, firstFile, bytesUpload, bytesTotal);
197     return 0;
198 }
199 static IFileReceiveListener g_fileRecvListener = {
200     .OnReceiveFileStarted = OnReceiveFileStarted,
201     .OnReceiveFileFinished = OnReceiveFileFinished,
202     .OnReceiveFileProcess = OnReceiveFileProcess,
203     .OnFileTransError = OnFileTransError,
204 };
205 
206 class AuthSessionTest : public testing::Test {
207 public:
AuthSessionTest()208     AuthSessionTest()
209     {}
~AuthSessionTest()210     ~AuthSessionTest()
211     {}
212     static void SetUpTestCase(void);
213     static void TearDownTestCase(void);
214     void SetUp();
215     void TearDown();
216 
217     static void Wsleep(uint32_t count, int32_t usl);
218     static void ServerWait(int32_t waitTime, int32_t testCase);
219     static void OpenAllSession(int32_t dataType, const string &mySessionName, const string &peerSessionName);
220     static void TestServerSide(void);
221 
222     static void CloseAllSession(void);
223     static void TestSendMessage(int32_t sendCnt, const char *data, uint32_t len, bool ex = false);
224     static void TestSendBytes(int32_t sendCnt, const char *data, uint32_t len, bool ex = false);
225 
226     static void TestSendFile(int32_t sendCnt, const char *sfileList[], const char *dfileList[],
227         int32_t cnt, bool ex = false);
228 
229     static void TransTestCase001(TransTestInfo &transInfo);
230     static void TransTest(TransTestInfo &transInfo, int32_t testDataType, bool ex = false);
231     static void *TestSendFileThread(void *arg);
232 };
233 
SetUpTestCase(void)234 void AuthSessionTest::SetUpTestCase(void)
235 {
236     SoftbusConfigInit();
237     int32_t ret = sem_init(&localSem_, 0, 0);
238     ASSERT_EQ(ret, 0);
239     testEntryArgs_ = GetTestEntry();
240     ASSERT_NE(testEntryArgs_, nullptr);
241 
242     networkIdSet_.clear();
243     ret = SOFTBUS_TIMOUT;
244     if (testEntryArgs_->testSide_ == PASSIVE_OPENSESSION_WAY) {
245         ret = WaitDeviceOnline(FILE_TEST_PKG_NAME.c_str());
246         ASSERT_EQ(ret, SOFTBUS_OK);
247     } else if (testEntryArgs_->testSide_ == ACTIVE_OPENSESSION_WAY) {
248         ret = WaitDeviceOnline(FILE_TEST_PKG_NAME.c_str());
249         ASSERT_EQ(ret, SOFTBUS_OK);
250     } else if (testEntryArgs_->testSide_ == ACTIVE_ANOTHER_OPENSESSION_WAY) {
251         ret = WaitDeviceOnline(FILE_TEST_PKG_NAME_DEMO.c_str());
252         ASSERT_EQ(ret, SOFTBUS_OK);
253     } else {
254         ASSERT_EQ(ret, SOFTBUS_OK);
255     }
256 }
257 
TearDownTestCase(void)258 void AuthSessionTest::TearDownTestCase(void)
259 {
260     sessionSet_.clear();
261     int32_t ret = sem_destroy(&localSem_);
262     ASSERT_EQ(ret, 0);
263     Wsleep(2, 1);
264 }
265 
SetUp(void)266 void AuthSessionTest::SetUp(void)
267 {
268     sessionSet_.clear();
269     openSessionSuccessCnt_ = 0;
270 }
271 
TearDown(void)272 void AuthSessionTest::TearDown(void)
273 {
274     sessionSet_.clear();
275     openSessionSuccessCnt_ = 0;
276 }
277 
Wsleep(uint32_t count,int32_t usl)278 void AuthSessionTest::Wsleep(uint32_t count, int32_t usl)
279 {
280     while (count) {
281         if (usl == 1) {
282             sleep(1);
283         } else {
284             usleep(1000);
285         }
286         count--;
287     }
288 }
ServerWait(int32_t waitTime,int32_t testCase)289 void AuthSessionTest::ServerWait(int32_t waitTime, int32_t testCase)
290 {
291     cout << "waitTime = " << waitTime << endl;
292     int32_t ret = sem_wait(&localSem_);
293     EXPECT_EQ(ret, 0);
294     int32_t i = 0;
295     while (i++ < waitTime) {
296         Wsleep(4, 1);
297         if (testCase == 3 && sessionSet_.empty()) {
298             break;
299         }
300     }
301     if (i >= waitTime) {
302         ADD_FAILURE();
303     }
304 }
305 
OpenAllSession(int32_t dataType,const string & mySessionName,const string & peerSessionName)306 void AuthSessionTest::OpenAllSession(int32_t dataType, const string &mySessionName, const string &peerSessionName)
307 {
308     for (auto networkId : networkIdSet_) {
309         SessionAttribute attribute;
310         (void)memset_s(&attribute, sizeof(attribute), 0, sizeof(attribute));
311         attribute.dataType = dataType;
312         int32_t ret = OpenSession(mySessionName.c_str(), peerSessionName.c_str(), networkId.c_str(), "", &attribute);
313         ASSERT_GT(ret, 0);
314         struct timespec timeout;
315         clock_gettime(CLOCK_REALTIME, &timeout);
316         timeout.tv_sec += 10;
317         while ((ret = sem_timedwait(&localSem_, &timeout)) == -1 && errno == EINTR) {
318             cout << "wait interrupted system call" << endl;
319             continue;
320         }
321         ASSERT_EQ(ret, 0);
322         if (ret == -1 && errno == ETIMEDOUT) {
323             cout << "wait time out" << endl;
324         }
325     }
326 }
CloseAllSession(void)327 void AuthSessionTest::CloseAllSession(void)
328 {
329     for (auto session : sessionSet_) {
330         CloseSession(session);
331         sessionSet_.erase(session);
332     }
333     Wsleep(2, 1);
334 }
335 
TestServerSide(void)336 void AuthSessionTest::TestServerSide(void)
337 {
338     int32_t ret = CreateSessionServer(FILE_TEST_PKG_NAME.c_str(), FILE_SESSION_NAME.c_str(), &g_listener);
339     ASSERT_EQ(ret, SOFTBUS_OK);
340     ret = CreateSessionServer(FILE_TEST_PKG_NAME.c_str(), FILE_SESSION_NAME_DEMO.c_str(), &g_listener);
341     ASSERT_EQ(ret, SOFTBUS_OK);
342     ret = SetFileReceiveListener(FILE_TEST_PKG_NAME.c_str(), FILE_SESSION_NAME.c_str(),
343         &g_fileRecvListener, RECV_ROOT_PATH);
344     ASSERT_EQ(ret, SOFTBUS_OK);
345     ret = SetFileReceiveListener(FILE_TEST_PKG_NAME.c_str(), FILE_SESSION_NAME_DEMO.c_str(),
346         &g_fileRecvListener, RECV_ROOT_PATH);
347     ASSERT_EQ(ret, SOFTBUS_OK);
348     ServerWait(3600, 1);
349     ret = RemoveSessionServer(FILE_TEST_PKG_NAME.c_str(), FILE_SESSION_NAME.c_str());
350     EXPECT_EQ(ret, SOFTBUS_OK);
351     ret = RemoveSessionServer(FILE_TEST_PKG_NAME.c_str(), FILE_SESSION_NAME_DEMO.c_str());
352     EXPECT_EQ(ret, SOFTBUS_OK);
353 }
354 
TestSendMessage(int32_t sendCnt,const char * data,uint32_t len,bool ex)355 void AuthSessionTest::TestSendMessage(int32_t sendCnt, const char *data, uint32_t len, bool ex)
356 {
357     for (auto session : sessionSet_) {
358         cout << "send message, session id = " << session << endl;
359         int32_t ret;
360         for (int32_t i = 0; i < sendCnt; i++) {
361             ret = SendMessage(session, data, len);
362             if (ex) {
363                 ASSERT_NE(ret, SOFTBUS_OK);
364             } else {
365                 if (ret != SOFTBUS_OK && ret != SOFTBUS_TIMOUT) {
366                     EXPECT_EQ(ret, SOFTBUS_OK);
367                 }
368                 Wsleep(10, 2);
369             }
370         }
371     }
372     Wsleep(1, 1);
373 }
TestSendBytes(int32_t sendCnt,const char * data,uint32_t len,bool ex)374 void AuthSessionTest::TestSendBytes(int32_t sendCnt, const char *data, uint32_t len, bool ex)
375 {
376     for (auto session : sessionSet_) {
377         cout << "send bytes, session id = " << session << endl;
378         int32_t ret;
379         for (int32_t i = 0; i < sendCnt; i++) {
380             ret = SendBytes(session, data, len);
381             if (ex) {
382                 ASSERT_NE(ret, SOFTBUS_OK);
383             } else {
384                 EXPECT_EQ(ret, SOFTBUS_OK);
385                 Wsleep(10, 2);
386             }
387         }
388     }
389     Wsleep(1, 1);
390 }
TestSendFile(int32_t sendCnt,const char * sfileList[],const char * dfileList[],int32_t cnt,bool ex)391 void AuthSessionTest::TestSendFile(int32_t sendCnt, const char *sfileList[], const char *dfileList[],
392     int32_t cnt, bool ex)
393 {
394     for (auto session : sessionSet_) {
395         cout << "send file, session id = " << session << endl;
396         int32_t ret;
397         for (int32_t i = 0; i < sendCnt; i++) {
398             ret = SendFile(session, sfileList, dfileList, cnt);
399             if (ex) {
400                 ASSERT_NE(ret, SOFTBUS_OK);
401             } else {
402                 EXPECT_EQ(ret, SOFTBUS_OK);
403             }
404             Wsleep(1, 1);
405         }
406     }
407     Wsleep(5, 1);
408 }
409 
TransTest(TransTestInfo & transInfo,int32_t testDataType,bool ex)410 void AuthSessionTest::TransTest(TransTestInfo &transInfo, int32_t testDataType, bool ex)
411 {
412     cout << "testCnt = " << transInfo.sendNum << endl;
413     OpenAllSession(transInfo.dataType, transInfo.mySessionName, transInfo.peerSessionName);
414     if (testDataType == TYPE_BYTES) {
415         char *data = (char *)malloc(SEND_DATA_SIZE_1M);
416         ASSERT_NE(data, nullptr);
417         (void)memset_s(data, SEND_DATA_SIZE_1M, 0, SEND_DATA_SIZE_1M);
418         ASSERT_NE(data, nullptr);
419         int32_t ret = memcpy_s(data, SEND_DATA_SIZE_1M, g_testData, strlen(g_testData));
420         EXPECT_EQ(ret, EOK);
421         TestSendBytes(transInfo.sendNum, data, ex ? SEND_DATA_SIZE_1M : SEND_DATA_SIZE_4K, ex);
422         free(data);
423     } else if (testDataType == TYPE_MESSAGE) {
424         char *data = (char *)malloc(SEND_DATA_SIZE_1M);
425         ASSERT_NE(data, nullptr);
426         (void)memset_s(data, SEND_DATA_SIZE_1M, 0, SEND_DATA_SIZE_1M);
427         ASSERT_NE(data, nullptr);
428         int32_t ret = memcpy_s(data, SEND_DATA_SIZE_1M, g_testData, strlen(g_testData));
429         EXPECT_EQ(ret, EOK);
430         TestSendMessage(transInfo.sendNum, data, ex ? SEND_DATA_SIZE_1M : SEND_DATA_SIZE_1K, ex);
431         free(data);
432     } else if (testDataType == TYPE_FILE) {
433         TestSendFile(transInfo.sendNum, transInfo.sfileList, transInfo.dfileList, transInfo.sfileCnt, ex);
434     } else if (testDataType == TYPE_STREAM) {
435         Wsleep(100, 2);
436         CloseAllSession();
437         return;
438     }
439     Wsleep(2, 1);
440     CloseAllSession();
441 }
442 
TransTestCase001(TransTestInfo & transInfo)443 void AuthSessionTest::TransTestCase001(TransTestInfo &transInfo)
444 {
445     cout << "testCnt = " << transInfo.testCnt << endl;
446     char *data = (char *)malloc(SEND_DATA_SIZE_1M);
447     ASSERT_NE(data, nullptr);
448     (void)memset_s(data, SEND_DATA_SIZE_1M, 0, SEND_DATA_SIZE_1M);
449     ASSERT_NE(data, nullptr);
450     int32_t ret = memcpy_s(data, SEND_DATA_SIZE_1M, g_testData, strlen(g_testData));
451     int32_t ret2;
452     EXPECT_EQ(ret, EOK);
453     OpenAllSession(transInfo.dataType, transInfo.mySessionName, transInfo.peerSessionName);
454     for (int32_t i = 0; i < transInfo.testCnt; i++) {
455         for (auto session : sessionSet_) {
456             cout << "send bytes, session id = " << session << endl;
457             for (int32_t j = 0; j < transInfo.sendNum; j++) {
458                 ret = SendBytes(session, data, SEND_DATA_SIZE_4K);
459                 ret2 = SendMessage(session, data, SEND_DATA_SIZE_1K);
460                 EXPECT_EQ(ret, 0);
461                 if (ret2 != SOFTBUS_OK && ret2 != SOFTBUS_TIMOUT) {
462                     EXPECT_EQ(ret2, 0);
463                 }
464             }
465         }
466     }
467     free(data);
468     data = nullptr;
469     Wsleep(2, 1);
470     CloseAllSession();
471 }
472 
473 /*
474 * @tc.name: testSendBytesMessage001
475 * @tc.desc: test send bytes message, use different session name.
476 * @tc.type: FUNC
477 * @tc.require:
478 */
479 HWTEST_F(AuthSessionTest, testSendBytesMessage001, TestSize.Level1)
480 {
481     if (testEntryArgs_->testSide_ == PASSIVE_OPENSESSION_WAY) {
482         TestServerSide();
483         return;
484     }
485     if (testEntryArgs_->testSide_ != ACTIVE_OPENSESSION_WAY) {
486         return;
487     }
488     TransTestInfo transInfo = {
489         .mySessionName = FILE_SESSION_NAME,
490         .peerSessionName = FILE_SESSION_NAME,
491         .testCnt = 1,
492         .sendNum = testEntryArgs_->transNums_,
493         .dataType = TYPE_FILE,
494     };
495     int32_t ret = CreateSessionServer(FILE_TEST_PKG_NAME.c_str(), transInfo.mySessionName.c_str(), &g_listener);
496     ASSERT_EQ(ret, SOFTBUS_OK);
497     TransTestCase001(transInfo);
498     Wsleep(1, 1);
499     ret = RemoveSessionServer(FILE_TEST_PKG_NAME.c_str(), transInfo.mySessionName.c_str());
500     EXPECT_EQ(ret, SOFTBUS_OK);
501 };
502 
503 /*
504 * @tc.name: testSendBytesMessage002
505 * @tc.desc: test send bytes 2 message, use different session name.
506 * @tc.type: FUNC
507 * @tc.require:
508 */
509 HWTEST_F(AuthSessionTest, testSendBytesMessage002, TestSize.Level1)
510 {
511     if (testEntryArgs_->testSide_ == PASSIVE_OPENSESSION_WAY) {
512         TestServerSide();
513         return;
514     }
515     if (testEntryArgs_->testSide_ != ACTIVE_ANOTHER_OPENSESSION_WAY) {
516         return;
517     }
518     TransTestInfo transInfo = {
519         .mySessionName = FILE_SESSION_NAME_DEMO,
520         .peerSessionName = FILE_SESSION_NAME_DEMO,
521         .testCnt = 1,
522         .sendNum = testEntryArgs_->transNums_,
523         .dataType = TYPE_FILE,
524     };
525     int32_t ret = CreateSessionServer(FILE_TEST_PKG_NAME_DEMO.c_str(), transInfo.mySessionName.c_str(), &g_listener);
526     ASSERT_EQ(ret, SOFTBUS_OK);
527     TransTestCase001(transInfo);
528     Wsleep(1, 1);
529     ret = RemoveSessionServer(FILE_TEST_PKG_NAME_DEMO.c_str(), transInfo.mySessionName.c_str());
530     EXPECT_EQ(ret, SOFTBUS_OK);
531 };
532 
533 /*
534 * @tc.name: testSendFile001
535 * @tc.desc: test send file, use different pkgname.
536 * @tc.type: FUNC
537 * @tc.require:
538 */
539 HWTEST_F(AuthSessionTest, testSendFile001, TestSize.Level1)
540 {
541     if (testEntryArgs_->testSide_ == PASSIVE_OPENSESSION_WAY) {
542         TestServerSide();
543         return;
544     }
545     const char *sfileList[10] = {0};
546     const char *dfileList[10] = {0};
547     sfileList[0] = SFILE_NAME_1K;
548     sfileList[1] = SFILE_NAME_5M;
549     dfileList[0] = DFILE_NAME_1K;
550     dfileList[1] = DFILE_NAME_5M;
551     TransTestInfo transInfo = {
552         .testCnt = 1,
553         .sendNum = 1,
554         .dataType = TYPE_FILE,
555         .sfileList = sfileList,
556         .dfileList = dfileList,
557         .sfileCnt = 1,
558     };
559     std::string pkgName;
560     if (testEntryArgs_->testSide_ == ACTIVE_OPENSESSION_WAY) {
561         pkgName = FILE_TEST_PKG_NAME;
562         transInfo.mySessionName = FILE_SESSION_NAME;
563         transInfo.peerSessionName = FILE_SESSION_NAME;
564     } else if (testEntryArgs_->testSide_ == ACTIVE_ANOTHER_OPENSESSION_WAY) {
565         pkgName = FILE_TEST_PKG_NAME_DEMO;
566         transInfo.mySessionName = FILE_SESSION_NAME_DEMO;
567         transInfo.peerSessionName = FILE_SESSION_NAME_DEMO;
568     } else {
569         return;
570     }
571 
572     int32_t ret = CreateSessionServer(pkgName.c_str(), transInfo.mySessionName.c_str(), &g_listener);
573     ASSERT_EQ(ret, SOFTBUS_OK);
574     ret = SetFileSendListener(pkgName.c_str(), transInfo.mySessionName.c_str(), &g_fileSendListener);
575     ASSERT_EQ(ret, SOFTBUS_OK);
576     TransTest(transInfo, TYPE_FILE);
577     Wsleep(1, 1);
578     ret = RemoveSessionServer(pkgName.c_str(), transInfo.mySessionName.c_str());
579     EXPECT_EQ(ret, SOFTBUS_OK);
580 };
581 
582 } // namespace OHOS