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 "net_trans_common.h"
19 #include "wifi_utils.h"
20
21 static int g_waitFlag = WAIT_DEF_VALUE;
22
FileSessionOpened(int sessionId,int result)23 static int FileSessionOpened(int sessionId, int result)
24 {
25 LOG("[cb][file]open session sid[%d],rst[%d]", sessionId, result);
26 if (result == SOFTBUS_OK) {
27 g_waitFlag = WAIT_SUCCESS_VALUE;
28 } else {
29 g_waitFlag = WAIT_FAIL_VALUE;
30 }
31 return SOFTBUS_OK;
32 }
33
FileSessionClosed(int sessionId)34 static void FileSessionClosed(int sessionId)
35 {
36 LOG("[cb][file]close session sid[%d]", sessionId);
37 }
38
FileBytesReceived(int sessionId,const void * data,unsigned int dataLen)39 static void FileBytesReceived(int sessionId, const void* data, unsigned int dataLen)
40 {
41 LOG("[cb][file]ByteRec sid:%d, data len:%d", sessionId, dataLen);
42 if (data == NULL) {
43 LOG("[cb][file]ByteRec invalid data=null sid[%d]", sessionId);
44 g_waitFlag = WAIT_FAIL_VALUE;
45 } else {
46 g_waitFlag = WAIT_SUCCESS_VALUE;
47 }
48 }
49
FileMessageReceived(int sessionId,const void * data,unsigned int dataLen)50 static void FileMessageReceived(int sessionId, const void* data, unsigned int dataLen)
51 {
52 LOG("[cb][file]MessageRec sid:%d, data len:%d", sessionId, dataLen);
53 if (data == NULL) {
54 LOG("[cb][file]MessageRec invalid data=null sid[%d]", sessionId);
55 g_waitFlag = WAIT_FAIL_VALUE;
56 } else {
57 g_waitFlag = WAIT_SUCCESS_VALUE;
58 }
59 }
60
61 static SessionAttribute g_fileSessionAttr = {
62 .dataType = TYPE_FILE,
63 };
64
65 static SessionAttribute g_fileSessionAttrP2P = {
66 .dataType = TYPE_FILE,
67 .linkTypeNum = 1,
68 .linkType[0] = LINK_TYPE_WIFI_P2P,
69 };
70
71 static ISessionListener g_fileSessionListener = {
72 .OnSessionOpened = FileSessionOpened,
73 .OnSessionClosed = FileSessionClosed,
74 .OnBytesReceived = FileBytesReceived,
75 .OnMessageReceived = FileMessageReceived,
76 };
77
78
79 using namespace testing::ext;
80
81 class TransFileFuncTest : public testing::Test {
82 public:
83 // 测试套前置和后置操作
84 static void SetUpTestCase();
85 static void TearDownTestCase();
86
87 // 测试用例前置和后置操作
88 void SetUp();
89 void TearDown();
90 };
91
SetUp()92 void TransFileFuncTest::SetUp() {
93 // set listener
94 int ret = SetFileSendListener(DEF_PKG_NAME, SESSION_NAME_FILE, GetSendFileListener());
95 EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
96 ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_FILE, GetRecvFileListener(), RECV_FILE_PATH);
97 EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
98 }
99
TearDown()100 void TransFileFuncTest::TearDown() {}
101
SetUpTestCase()102 void TransFileFuncTest::SetUpTestCase()
103 {
104 LOG("SetUp begin");
105 AddPermission();
106 sleep(1);
107 system("pidof accesstoken_ser | xargs kill -9");
108 sleep(1);
109 TestSetUp();
110 int ret = RegisterDeviceStateDefCallback();
111 EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
112
113 ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
114 ASSERT_EQ(SOFTBUS_OK, ret) << "get node fail,please check network";
115
116 system(" truncate -s 0M /data/A.tar");
117 system(" truncate -s 8M /data/8M.tar");
118 system(" truncate -s 8M /data/8M_DNull.tar");
119 system(" truncate -s 400M /data/big.tar");
120 sleepn(5);
121 system(" truncate -s 8M /data/richu.jpg");
122 system(" truncate -s 3M /data/richu-002.jpg");
123 system(" truncate -s 10M /data/richu-003.jpg");
124
125 LOG("SetUp end");
126 }
127
TearDownTestCase()128 void TransFileFuncTest::TearDownTestCase()
129 {
130 int ret = UnRegisterDeviceStateDefCallback();
131 EXPECT_EQ(SOFTBUS_OK, ret) << "call unReg node state callback fail";
132
133 TestTearDown();
134 }
135
WaitFile(int timeout)136 static int WaitFile(int timeout)
137 {
138 LOG("start waitfile,timeout:%d", timeout);
139 int count = 0;
140 int t = timeout;
141 while (t > 0) {
142 sleep(1);
143 if (g_waitFlag != WAIT_DEF_VALUE) {
144 LOG("waitfile success[flag:%d][time:%d]", g_waitFlag, count);
145 break;
146 }
147 t--;
148 count++;
149 }
150 if (g_waitFlag != WAIT_SUCCESS_VALUE) {
151 LOG("waitfile fail[exp:%d, real:%d][used time:%d]", WAIT_SUCCESS_VALUE, g_waitFlag, count);
152 return SOFTBUS_ERR;
153 }
154 return SOFTBUS_OK;
155 }
156
157 /**
158 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_Fun_0100
159 * @tc.name : test SendFile 8M
160 * @tc.desc : [G-DISTRIBUTED-0208] 必须支持蓝牙 WiFi或以太网等软总线依赖的通信能力中的一种或者多种
161 * @tc.type : FUNC
162 * @tc.size : MediumTest
163 */
164 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_Fun_0100, TestSize.Level2)
165 {
166 int ret;
167 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
168 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
169
170 g_waitFlag = WAIT_DEF_VALUE;
171 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
172 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
173 if (sid >= SESSION_ID_MIN) {
174 ret = WaitFile(10);
175 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
176 }
177
178 static const char* g_fileOne[] = {
179 "/data/8M.tar",
180 };
181
182 static const char *dfileList[] = {
183 "/data/8M.tar",
184 };
185
186 ResetWaitFlag();
187 ret = SendFile(sid, g_fileOne, dfileList, 1);
188 EXPECT_EQ(SOFTBUS_OK, ret) << "call SendFile fail";
189 ret = Wait(10);
190 EXPECT_EQ(SOFTBUS_OK, ret) << "wait send fail rst fail";
191
192 CloseSession(sid);
193 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
194 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
195 }
196
197 /**
198 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_Fun_0200
199 * @tc.name : test SendFile 0M
200 * @tc.desc : Test send file function
201 * @tc.type : FUNC
202 * @tc.size : MediumTest
203 */
204 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_Fun_0200, TestSize.Level2)
205 {
206 int ret;
207 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
208 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
209
210 g_waitFlag = WAIT_DEF_VALUE;
211 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
212 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
213 if (sid >= SESSION_ID_MIN) {
214 ret = WaitFile(10);
215 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
216 }
217
218 static const char* g_fileOne[] = {
219 "/data/A.tar",
220 };
221
222 static const char *dfileList[] = {
223 "/data/A_recv.tar",
224 };
225
226 ResetWaitFlag();
227 ret = SendFile(sid, g_fileOne, dfileList, 1);
228 EXPECT_EQ(SOFTBUS_OK, ret) << "call SendFile fail";
229 ret = Wait(10);
230 EXPECT_EQ(SOFTBUS_OK, ret) << "wait send fail rst fail";
231
232 CloseSession(sid);
233 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
234 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
235 }
236
237 /**
238 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_Fun_0300
239 * @tc.name : SendFile the sender address is empty ,send failed
240 * @tc.desc : Test send file function
241 * @tc.type : FUNC
242 * @tc.size : MediumTest
243 */
244 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_Fun_0300, TestSize.Level2)
245 {
246 int ret;
247 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
248 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
249
250 g_waitFlag = WAIT_DEF_VALUE;
251 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
252 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
253 if (sid >= SESSION_ID_MIN) {
254 ret = WaitFile(10);
255 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
256 }
257
258 static const char *dfileList[] = {
259 "/data/SNULL.tar",
260 };
261
262 ResetWaitFlag();
263 ret = SendFile(sid, NULL, dfileList, 1);
264 EXPECT_NE(SOFTBUS_OK, ret) << "call SendFile successful";
265
266 CloseSession(sid);
267 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
268 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
269 }
270
271 /**
272 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_Fun_0400
273 * @tc.name : SendFile the sender address is invalid ,send failed
274 * @tc.desc : Test send file function
275 * @tc.type : FUNC
276 * @tc.size : MediumTest
277 */
278 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_Fun_0400, TestSize.Level2)
279 {
280 int ret;
281 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
282 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
283
284 g_waitFlag = WAIT_DEF_VALUE;
285 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
286 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
287 if (sid >= SESSION_ID_MIN) {
288 ret = WaitFile(10);
289 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
290 }
291
292 static const char *g_fileOne[] = {
293 "/data/sendfile/8M.tar",
294 };
295
296 static const char *dfileList[] = {
297 "/data/8M_invalid.tar",
298 };
299
300 ResetWaitFlag();
301 ret = SendFile(sid, g_fileOne, dfileList, 1);
302 EXPECT_NE(SOFTBUS_OK, ret) << "call SendFile successful";
303
304 CloseSession(sid);
305 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
306 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
307 }
308
309 /**
310 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_Fun_0500
311 * @tc.name : SendFile the receiving address is null ,send successful
312 * @tc.desc : Test send file function
313 * @tc.type : FUNC
314 * @tc.size : MediumTest
315 */
316 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_Fun_0500, TestSize.Level2)
317 {
318 int ret;
319 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
320 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
321
322 g_waitFlag = WAIT_DEF_VALUE;
323 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
324 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
325 if (sid >= SESSION_ID_MIN) {
326 ret = WaitFile(10);
327 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
328 }
329
330 static const char* g_fileOne[] = {
331 "/data/8M_DNull.tar",
332 };
333
334 ResetWaitFlag();
335 ret = SendFile(sid, g_fileOne, NULL, 1);
336 EXPECT_EQ(SOFTBUS_OK, ret) << "call SendFile fail";
337 ret = Wait(15);
338 EXPECT_EQ(SOFTBUS_OK, ret) << "wait send fail rst fail";
339
340 CloseSession(sid);
341 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
342 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
343 }
344
345 /**
346 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_Fun_0600
347 * @tc.name : SendFile the receiving address is invalid ,send successful
348 * @tc.desc : Test send file function
349 * @tc.type : FUNC
350 * @tc.size : MediumTest
351 */
352 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_Fun_0600, TestSize.Level2)
353 {
354 int ret;
355 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
356 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
357
358 g_waitFlag = WAIT_DEF_VALUE;
359 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
360 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
361 if (sid >= SESSION_ID_MIN) {
362 ret = WaitFile(10);
363 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
364 }
365
366 static const char* g_fileOne[] = {
367 "/data/8M.tar",
368 };
369
370 static const char *dfileList[] = {
371 "/sendfile/8M_invalid.tar",
372 };
373
374 ResetWaitFlag();
375 ret = SendFile(sid, g_fileOne, dfileList, 1);
376 EXPECT_EQ(SOFTBUS_OK, ret) << "call SendFile fail";
377 ret = Wait(15);
378 EXPECT_EQ(SOFTBUS_OK, ret) << "wait send fail rst fail";
379
380 CloseSession(sid);
381 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
382 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
383 }
384
385 /**
386 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_Fun_0700
387 * @tc.name : SendFile close session ,send failed
388 * @tc.desc : Test send file function
389 * @tc.type : FUNC
390 * @tc.size : MediumTest
391 */
392 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_Fun_0700, TestSize.Level2)
393 {
394 int ret;
395 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
396 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
397
398 g_waitFlag = WAIT_DEF_VALUE;
399 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
400 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
401 if (sid >= SESSION_ID_MIN) {
402 ret = WaitFile(10);
403 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
404 }
405
406 static const char* g_fileOne[] = {
407 "/data/big.tar",
408 };
409
410 static const char *dfileList[] = {
411 "/sendfile/big.tar",
412 };
413
414 ResetWaitFlag();
415 ret = SendFile(sid, g_fileOne, dfileList, 1);
416 EXPECT_EQ(SOFTBUS_OK, ret) << "call SendFile fail";
417
418 CloseSession(sid);
419 ret = Wait(15);
420 EXPECT_NE(SOFTBUS_OK, ret) << "wait send success ,expect fail";
421
422 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
423 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
424 }
425
426 /**
427 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_Fun_0800
428 * @tc.name : SendFile set recev listening address to be null or invalid
429 * @tc.desc : Test send file function
430 * @tc.type : FUNC
431 * @tc.size : MediumTest
432 */
433 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_Fun_0800, TestSize.Level2)
434 {
435 int ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_FILE, GetRecvFileListener(), NULL);
436 EXPECT_NE(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
437 }
438
439 /**
440 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_Fun_0900
441 * @tc.name : Send 4 files once
442 * @tc.desc : [G-DISTRIBUTED-0206]禁止修改传输的默认协议,新增或者变更默认传输协议必须通过协商机制来实现
443 * @tc.type : FUNC
444 * @tc.size : MediumTest
445 */
446 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_Fun_0900, TestSize.Level2)
447 {
448 int ret;
449 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
450 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
451
452 g_waitFlag = WAIT_DEF_VALUE;
453 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
454 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
455 if (sid >= SESSION_ID_MIN) {
456 ret = WaitFile(10);
457 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
458 }
459
460 static const char* g_fileOne[] = {
461 "/data/big.tar",
462 "/data/richu.jpg",
463 "/data/richu-002.jpg",
464 "/data/richu-003.jpg",
465 };
466
467 ResetWaitFlag();
468 ret = SendFile(sid, g_fileOne, NULL, 4);
469 EXPECT_EQ(SOFTBUS_OK, ret) << "call SendFile fail";
470 ret = Wait(350);
471 EXPECT_EQ(SOFTBUS_OK, ret) << "wait send fail rst fail";
472
473 CloseSession(sid);
474 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
475 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
476 }
477
478 /**
479 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_P2P_Fun_0100
480 * @tc.name : test SendFile 8M By P2P
481 * @tc.desc : [G-DISTRIBUTED-0206]禁止修改传输的默认协议,新增或者变更默认传输协议必须通过协商机制来实现
482 * @tc.type : FUNC
483 * @tc.size : MediumTest
484 */
485 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_P2P_Fun_0100, TestSize.Level2)
486 {
487 int ret;
488 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
489 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
490
491 g_waitFlag = WAIT_DEF_VALUE;
492 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttrP2P);
493 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
494 if (sid >= SESSION_ID_MIN) {
495 ret = WaitFile(10);
496 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
497 }
498
499 static const char* g_fileOne[] = {
500 "/data/8M.tar",
501 };
502
503 static const char *dfileList[] = {
504 "/data/P2P/8M.tar",
505 };
506
507 ResetWaitFlag();
508 ret = SendFile(sid, g_fileOne, dfileList, 1);
509 EXPECT_EQ(SOFTBUS_OK, ret) << "call SendFile fail";
510 ret = Wait(10);
511 EXPECT_EQ(SOFTBUS_OK, ret) << "wait send fail rst fail";
512
513 CloseSession(sid);
514 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
515 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
516 }
517
518 /**
519 * @tc.number : SUB_Softbus_Trans_Comp_SendFile_P2P_Fun_0200
520 * @tc.name : test SendFile 0M By P2P
521 * @tc.desc : Test send file function
522 * @tc.type : FUNC
523 * @tc.size : MediumTest
524 */
525 HWTEST_F(TransFileFuncTest, SUB_Softbus_Trans_Comp_SendFile_P2P_Fun_0200, TestSize.Level2)
526 {
527 int ret;
528 ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
529 EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
530
531 g_waitFlag = WAIT_DEF_VALUE;
532 int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttrP2P);
533 EXPECT_TRUE(sid >= SESSION_ID_MIN) << "call OpenSession[file] fail, sid=" << sid;
534 if (sid >= SESSION_ID_MIN) {
535 ret = WaitFile(10);
536 EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
537 }
538
539 static const char* g_fileOne[] = {
540 "/data/A.tar",
541 };
542
543 static const char *dfileList[] = {
544 "/data/P2P/A_recv.tar",
545 };
546
547 ResetWaitFlag();
548 ret = SendFile(sid, g_fileOne, dfileList, 1);
549 EXPECT_EQ(SOFTBUS_OK, ret) << "call SendFile fail";
550 ret = Wait(10);
551 EXPECT_EQ(SOFTBUS_OK, ret) << "wait send fail rst fail";
552
553 CloseSession(sid);
554 ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
555 EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
556 }
557