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