• 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 "net_trans_common.h"
19 #include "wifi_utils.h"
20 #include "accesstoken_kit.h"
21 
22 static int g_waitFlag = WAIT_DEF_VALUE;
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 ISessionListener g_fileSessionListener = {
66     .OnSessionOpened = FileSessionOpened,
67     .OnSessionClosed = FileSessionClosed,
68     .OnBytesReceived = FileBytesReceived,
69     .OnMessageReceived = FileMessageReceived,
70 };
71 
72 using namespace testing::ext;
73 
74 class TransSessionFuncTest : public testing::Test {
75 public:
76     // 测试套前置和后置操作
77     static void SetUpTestCase();
78     static void TearDownTestCase();
79 
80     // 测试用例前置和后置操作
81     void SetUp();
82     void TearDown();
83 };
84 
SetUp()85 void TransSessionFuncTest::SetUp() {}
86 
TearDown()87 void TransSessionFuncTest::TearDown() {}
88 
SetUpTestCase()89 void TransSessionFuncTest::SetUpTestCase()
90 {
91     LOG("SetUp begin");
92     AddPermission();
93     sleep(1);
94     system("pidof accesstoken_ser | xargs kill -9");
95     sleep(1);
96     TestSetUp();
97     int ret = RegisterDeviceStateDefCallback();
98     EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
99     ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
100     ASSERT_EQ(SOFTBUS_OK, ret) << "get node fail,please check network";
101     system(" truncate -s 8M /data/8M.tar");
102     LOG("SetUp end");
103 }
104 
TearDownTestCase()105 void TransSessionFuncTest::TearDownTestCase()
106 {
107     int ret = UnRegisterDeviceStateDefCallback();
108     EXPECT_EQ(SOFTBUS_OK, ret) << "call unReg node state callback fail";
109     TestTearDown();
110 }
111 
112 /**
113  * @tc.number  : SUB_DSoftbus_Spec_DCTS_OpenSession_0100
114  * @tc.name    : one Client creates SessionServer + 1, Max succeeds, 1 fails
115  * @tc.desc    : Test session management
116  * @tc.type    : FUNC
117  * @tc.size    : MediumTest
118  */
119 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_0100, TestSize.Level3)
120 {
121     int ret;
122     char sessionNames[][SESSION_NAME_SIZE_MAX] = { "com.communication.demo1.1", "com.communication.demo1.2",
123         "com.communication.demo1.3", "com.communication.demo1.4", "com.communication.demo1.5",
124         "com.communication.demo1.6", "com.communication.demo1.7", "com.communication.demo1.8" };
125     for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
126         ret = CreateSessionServer(DEF_PKG_NAME, sessionNames[i], GetSessionListenser4Data());
127         EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS fail,i=" << i;
128     }
129     string sessionName = "max+1";
130     ret = CreateSessionServer(DEF_PKG_NAME, sessionName.c_str(), GetSessionListenser4Data());
131     printf("CreateSS max+1, ret:%d \n", ret);
132     EXPECT_NE(SOFTBUS_OK, ret) << "CreateSS max+1 success, expect fail";
133 
134     for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
135         ret = RemoveSessionServer(DEF_PKG_NAME, sessionNames[i]);
136         EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS fail,i=" << i;
137     }
138     ret = RemoveSessionServer(DEF_PKG_NAME, sessionName.c_str());
139     printf("RemoveSS max+1, ret:%d \n", ret);
140     EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS max+1 success, expect fail";
141 }
142 
143 /**
144  * @tc.number : SUB_DSoftbus_Spec_DCTS_OpenSession_0200
145  * @tc.name   : OpenSession + 1, Max succeeds, 1 fails
146  * @tc.desc   : Test session management
147  * @tc.type   : FUNC
148  * @tc.size   : MediumTest
149  */
150 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_0200, TestSize.Level3)
151 {
152     int ret;
153     ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
154     EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[data] fail";
155     ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL, GetSessionListenser4Ctl());
156     EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[ctrl] fail";
157 
158     int count = MAX_SESSION_NUM / 2;
159     int sessionId4Data[count];
160     int sessionId4Ctrl[count];
161     char groupId[][4] = { "g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8" };
162     ret = OpenSessionBatch4Data(groupId, sessionId4Data, count);
163     EXPECT_EQ(SOFTBUS_OK, ret) << "OpenSessionWithDiffGroupId4Data fail";
164     ret = OpenSessionBatch4Ctl(groupId, sessionId4Ctrl, count);
165     EXPECT_EQ(SOFTBUS_OK, ret) << "OpenSessionWithDiffGroupId4Ctl fail";
166 
167     // open max+1, expect fail
168     int sessionId;
169     sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
170     EXPECT_FALSE(sessionId >= SESSION_ID_MIN) << "call OpenSession[data] success,sid=" << sessionId;
171 
172     // close session
173     ret = CloseSessionBatch4Data(sessionId4Data, count);
174     EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionBatch4Data fail";
175     ret = CloseSessionBatch4Ctl(sessionId4Ctrl, count);
176     EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionBatch4Ctl fail";
177 
178     // remove  session server
179     ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
180     EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[data] fail";
181     ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL);
182     EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[ctrl] fail";
183 }
184 
185 /**
186  * @tc.number : SUB_DSoftbus_Spec_DCTS_OpenSession_0300
187  * @tc.name   : Obtain DevicedName based on Sessionid
188  * @tc.desc   : Test session management
189  * @tc.type   : FUNC
190  * @tc.size   : MediumTest
191  */
192 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_0300, TestSize.Level3)
193 {
194     int ret;
195     ret = CreateSsAndOpenSession4Data();
196     ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
197 
198     int sessionId = GetCurrentSessionId4Data();
199     char mySessionName[SESSION_NAME_SIZE_MAX] = { 0 };
200     ret = GetMySessionName(sessionId, mySessionName, SESSION_NAME_SIZE_MAX);
201     EXPECT_EQ(SOFTBUS_OK, ret) << "call GetMySessionName fail, sid:" << sessionId;
202     EXPECT_STREQ(SESSION_NAME_DATA, mySessionName) << "my session name cmp fail";
203 
204     char peerSessionName[SESSION_NAME_SIZE_MAX] = { 0 };
205     ret = GetPeerSessionName(sessionId, peerSessionName, SESSION_NAME_SIZE_MAX);
206     EXPECT_EQ(SOFTBUS_OK, ret) << "call GetPeerSessionName fail";
207     EXPECT_STREQ(SESSION_NAME_DATA, peerSessionName) << "peer session name cmp fail";
208 
209     ret = CloseSessionAndRemoveSs4Data();
210     EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
211 }
212 
213 /**
214  * @tc.number : SUB_DSoftbus_Spec_DCTS_OpenSession_0400
215  * @tc.name   : Obtain DevicedId based on Sessionid
216  * @tc.desc   : Test session management
217  * @tc.type   : FUNC
218  * @tc.size   : MediumTest
219  */
220 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_0400, TestSize.Level3)
221 {
222     int ret;
223     ret = CreateSsAndOpenSession4Ctl();
224     ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[ctl] fail";
225 
226     char deviceId[SESSION_NAME_SIZE_MAX] = { 0 };
227     ret = GetPeerDeviceId(GetCurrentSessionId4Ctl(), deviceId, SESSION_NAME_SIZE_MAX);
228     EXPECT_EQ(SOFTBUS_OK, ret) << "call GetPeerDeviceId fail";
229     EXPECT_STREQ(GetNetworkId(), deviceId) << "peer device id cmp fail";
230 
231     ret = CloseSessionAndRemoveSs4Ctl();
232     EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
233 }
234 
235 /**
236  * @tc.number : SUB_DSoftbus_Spec_DCTS_OpenSession_0500
237  * @tc.name   : OpenSession Type is TYPE_BYTES sendfile fail
238  * @tc.desc   : 【G-DISTRIBUTED-0205】禁止修改Openharmony分布式软总线设备间传输通道管理协议。
239  * @tc.type   : FUNC
240  * @tc.size   : MediumTest
241  */
242 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_0500, TestSize.Level3)
243 {
244     int ret;
245     int sessionId;
246     int timeout = 10;
247 
248     static const char* g_file[] = {
249         "/data/8M.tar",
250     };
251 
252     static const char *recv_file[] = {
253         "/data/datatype_8M.tar",
254     };
255 
256     ret = SetFileSendListener(DEF_PKG_NAME, SESSION_NAME_FILE, GetSendFileListener());
257     EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
258     ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_FILE, GetRecvFileListener(), RECV_FILE_PATH);
259     EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
260 
261     ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
262     EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
263 
264     sessionId = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
265     if (sessionId < SESSION_ID_MIN)
266     {
267         LOG("call opensession[file] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
268     }
269     ret = Wait4Session(timeout, SESSION_4DATA);
270     if (ret != SOFTBUS_OK)
271     {
272         LOG("call opensession[file] fail");
273     }
274 
275     ret = SendFile(sessionId, g_file, recv_file, 1);
276     EXPECT_NE(SOFTBUS_OK, ret) << "sendfile succees";
277 
278     CloseSession(sessionId);
279 
280     ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
281     EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
282 }
283 
284 /**
285  * @tc.number : SUB_DSoftbus_Spec_DCTS_OpenSession_0600
286  * @tc.name   : OpenSession Type is TYPE_MESSAGE sendfile fail
287  * @tc.desc   : Test session management
288  * @tc.type   : FUNC
289  * @tc.size   : MediumTest
290  */
291 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_0600, TestSize.Level3)
292 {
293     int ret;
294     int sessionId;
295     int timeout = 10;
296 
297     static const char* g_file[] = {
298         "/data/8M.tar",
299     };
300 
301     static const char *recv_file[] = {
302         "/data/messagetype_8M.tar",
303     };
304 
305     ret = SetFileSendListener(DEF_PKG_NAME, SESSION_NAME_PROXY, GetSendFileListener());
306     EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
307     ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_PROXY, GetRecvFileListener(), RECV_FILE_PATH);
308     EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
309 
310     ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY, GetSessionListenser4Proxy());
311     EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
312 
313     sessionId = OpenSession(SESSION_NAME_PROXY, SESSION_NAME_PROXY, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Proxy());
314     if (sessionId < SESSION_ID_MIN)
315     {
316         LOG("call opensession[message] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
317     }
318     ret = Wait4Session(timeout, SESSION_4PROXY);
319     if (ret != SOFTBUS_OK)
320     {
321         LOG("call opensession[message] fail");
322     }
323 
324     ret = SendFile(sessionId, g_file, recv_file, 1);
325     EXPECT_NE(SOFTBUS_OK, ret) << "sendfile succees";
326 
327     CloseSession(sessionId);
328 
329     ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY);
330     EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
331 }
332 
333 /**
334  * @tc.number : SUB_DSoftbus_Spec_DCTS_OpenSession_0700
335  * @tc.name   : OpenSession Type is TYPE_STREAM sendfile fail
336  * @tc.desc   : Test session management
337  * @tc.type   : FUNC
338  * @tc.size   : MediumTest
339  */
340 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_0700, TestSize.Level3)
341 {
342     int ret;
343     int sessionId;
344     int timeout = 10;
345 
346     static const char* g_file[] = {
347         "/data/8M.tar",
348     };
349 
350     static const char *recv_file[] = {
351         "/data/streamtype_8M.tar",
352     };
353 
354     ret = SetFileSendListener(DEF_PKG_NAME, SESSION_NAME_STREAM, GetSendFileListener());
355     EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
356     ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_STREAM, GetRecvFileListener(), RECV_FILE_PATH);
357     EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
358 
359     ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM, GetSessionListenser4Stream());
360     EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
361 
362     SessionAttribute attr;
363     (void)memset_s(&attr, sizeof(attr), 0, sizeof(attr));
364     attr.dataType = TYPE_STREAM;
365     sessionId = OpenSession(SESSION_NAME_STREAM, SESSION_NAME_STREAM, GetNetworkId(), DEF_GROUP_ID, &attr);
366     if (sessionId < SESSION_ID_MIN)
367     {
368         LOG("call opensession[stream] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
369     }
370     ret = Wait4Session(timeout, SESSION_4STREAM);
371     if (ret != SOFTBUS_OK)
372     {
373         LOG("call opensession[stream] fail");
374     }
375 
376     ret = SendFile(sessionId, g_file, recv_file, 1);
377     EXPECT_NE(SOFTBUS_OK, ret) << "sendfile succees";
378 
379     CloseSession(sessionId);
380 
381     ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM);
382     EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
383 }
384 
385 /**
386  * @tc.number : SUB_DSoftbus_Spec_DCTS_OpenSession_0800
387  * @tc.name   : OpenSession Type is TYPE_BYTES sendstream fail
388  * @tc.desc   : Test session management
389  * @tc.type   : FUNC
390  * @tc.size   : MediumTest
391  */
392 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_0800, TestSize.Level3)
393 {
394     int ret;
395     int sessionId;
396     int timeout = 10;
397 
398     string data = "send stream transmission test!!!!";
399     char *sendData = (char *)malloc(data.length() + 1);
400     EXPECT_NE(sendData, nullptr);
401     ret = strcpy_s(sendData, data.length() + 1, data.c_str());
402     EXPECT_EQ(ret, SOFTBUS_OK);
403     StreamData extStreamData {0};
404     StreamData streamData {
405         .buf = sendData,
406         .bufLen = data.length() + 1,
407     };
408     StreamFrameInfo  frame = {0};
409 
410     ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM, &g_fileSessionListener);
411     EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
412 
413     sessionId = OpenSession(SESSION_NAME_STREAM, SESSION_NAME_STREAM, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
414     if (sessionId < SESSION_ID_MIN)
415     {
416         LOG("call opensession[file] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
417     }
418     ret = Wait4Session(timeout, SESSION_4DATA);
419     if (ret != SOFTBUS_OK)
420     {
421         LOG("call opensession[file] fail");
422     }
423 
424     ret = SendStream(sessionId, &streamData, &extStreamData, &frame);
425     EXPECT_NE(SOFTBUS_OK, ret) << "sendstream succees";
426 
427     CloseSession(sessionId);
428 
429     ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
430     EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
431 }
432 
433 /**
434  * @tc.number : SUB_DSoftbus_Spec_DCTS_OpenSession_0900
435  * @tc.name   : OpenSession Type is TYPE_MESSAGE sendstream fail
436  * @tc.desc   : Test session management
437  * @tc.type   : FUNC
438  * @tc.size   : MediumTest
439  */
440 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_0900, TestSize.Level3)
441 {
442     int ret;
443     int sessionId;
444     int timeout = 10;
445 
446     string data = "send stream transmission test!!!!";
447     char *sendData = (char *)malloc(data.length() + 1);
448     EXPECT_NE(sendData, nullptr);
449     ret = strcpy_s(sendData, data.length() + 1, data.c_str());
450     EXPECT_EQ(ret, SOFTBUS_OK);
451     StreamData extStreamData {0};
452     StreamData streamData {
453         .buf = sendData,
454         .bufLen = data.length() + 1,
455     };
456     StreamFrameInfo  frame = {0};
457 
458     ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY, GetSessionListenser4Proxy());
459     EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
460 
461     sessionId = OpenSession(SESSION_NAME_PROXY, SESSION_NAME_PROXY, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Proxy());
462     if (sessionId < SESSION_ID_MIN)
463     {
464         LOG("call opensession[message] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
465     }
466     ret = Wait4Session(timeout, SESSION_4PROXY);
467     if (ret != SOFTBUS_OK)
468     {
469         LOG("call opensession[message] fail");
470     }
471 
472     ret = SendStream(sessionId, &streamData, &extStreamData, &frame);
473     EXPECT_NE(SOFTBUS_OK, ret) << "sendstream succees";
474 
475     CloseSession(sessionId);
476 
477     ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY);
478     EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
479 }
480 
481 /**
482  * @tc.number : SUB_DSoftbus_Spec_DCTS_OpenSession_1000
483  * @tc.name   : OpenSession Type is TYPE_FILE sendstream fail
484  * @tc.desc   : Test session management
485  * @tc.type   : FUNC
486  * @tc.size   : MediumTest
487  */
488 HWTEST_F(TransSessionFuncTest, SUB_DSoftbus_Spec_DCTS_OpenSession_1000, TestSize.Level3)
489 {
490     int ret;
491     int sessionId;
492     int timeout = 10;
493 
494     string data = "send stream transmission test!!!!";
495     char *sendData = (char *)malloc(data.length() + 1);
496     EXPECT_NE(sendData, nullptr);
497     ret = strcpy_s(sendData, data.length() + 1, data.c_str());
498     EXPECT_EQ(ret, SOFTBUS_OK);
499     StreamData extStreamData {0};
500     StreamData streamData {
501         .buf = sendData,
502         .bufLen = data.length() + 1,
503     };
504     StreamFrameInfo  frame = {0};
505 
506     ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
507     EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
508 
509     sessionId = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
510     if (sessionId < SESSION_ID_MIN)
511     {
512         LOG("call opensession[stream] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
513     }
514     ret = Wait4Session(timeout, SESSION_4STREAM);
515     if (ret != SOFTBUS_OK)
516     {
517         LOG("call opensession[stream] fail");
518     }
519 
520     ret = SendStream(sessionId, &streamData, &extStreamData, &frame);
521     EXPECT_NE(SOFTBUS_OK, ret) << "sendstream succees";
522 
523     CloseSession(sessionId);
524 
525     ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM);
526     EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
527 }