• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 "client_trans_session_callback.h"
19 #include "client_trans_session_manager.h"
20 #include "client_trans_socket_manager.h"
21 #include "client_trans_udp_manager.h"
22 #include "client_trans_udp_manager.c"
23 #include "securec.h"
24 #include "session.h"
25 #include "softbus_def.h"
26 #include "softbus_error_code.h"
27 #include "trans_udp_channel_manager.h"
28 
29 using namespace std;
30 using namespace testing::ext;
31 
32 const char *g_sessionName = "ohos.distributedschedule.dms.test";
33 const char *g_networkid = "ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00ABCDEF00";
34 const char *g_groupid = "TEST_GROUP_ID";
35 
36 namespace OHOS {
37 #define TEST_ERR_PID (-1)
38 #define TEST_LEN 10
39 #define TEST_DATA_TYPE 2
40 #define TEST_PID 2
41 #define TEST_STATE 1
42 #define TEST_ERR_CODE 1
43 #define TEST_CHANNELID 5
44 #define TEST_SESSIONID 100
45 #define TEST_CHANNELTYPE 2
46 #define TEST_REMOTE_TYPE 0
47 #define TEST_EVENT_ID 2
48 #define TEST_COUNT 2
49 #define TEST_ERR_COUNT (-2)
50 #define TEST_ERRCODE 0
51 #define TEST_FILE_NAME "test.filename.01"
52 #define STREAM_DATA_LENGTH 10
53 #define TEST_ERR_CHANNELID (-1)
54 #define TEST_ERR_SESSIONID (-1)
55 #define FILE_PRIORITY_TEST 0x06
56 
57 class ClientTransUdpManagerTest : public testing::Test {
58 public:
ClientTransUdpManagerTest()59     ClientTransUdpManagerTest() {}
~ClientTransUdpManagerTest()60     ~ClientTransUdpManagerTest() {}
61     static void SetUpTestCase(void);
62     static void TearDownTestCase(void);
SetUp()63     void SetUp() override {}
TearDown()64     void TearDown() override {}
65 };
66 
OnSessionOpened(const char * sessionName,const ChannelInfo * channel,SessionType flag,SocketAccessInfo * accessInfo)67 static int32_t OnSessionOpened(
68     const char *sessionName, const ChannelInfo *channel, SessionType flag, SocketAccessInfo *accessInfo)
69 {
70     return SOFTBUS_OK;
71 }
72 
OnSessionClosed(int32_t channelId,int32_t channelType,ShutdownReason reason)73 static int32_t OnSessionClosed(int32_t channelId, int32_t channelType, ShutdownReason reason)
74 {
75     return SOFTBUS_OK;
76 }
77 
OnSessionOpenFailed(int32_t channelId,int32_t channelType,int32_t errCode)78 static int32_t OnSessionOpenFailed(int32_t channelId, int32_t channelType, int32_t errCode)
79 {
80     return SOFTBUS_OK;
81 }
82 
OnDataReceived(int32_t channelId,int32_t channelType,const void * data,uint32_t len,SessionPktType type)83 static int32_t OnDataReceived(int32_t channelId, int32_t channelType, const void *data,
84     uint32_t len, SessionPktType type)
85 {
86     return SOFTBUS_OK;
87 }
88 static IClientSessionCallBack g_sessionCb = {
89     .OnSessionOpened = OnSessionOpened,
90     .OnSessionClosed = OnSessionClosed,
91     .OnSessionOpenFailed = OnSessionOpenFailed,
92     .OnDataReceived = OnDataReceived,
93 };
94 
SetUpTestCase(void)95 void ClientTransUdpManagerTest::SetUpTestCase(void)
96 {
97     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
98     EXPECT_EQ(SOFTBUS_OK, ret);
99     ret = TransClientInit();
100     EXPECT_EQ(ret, SOFTBUS_OK);
101 }
102 
TearDownTestCase(void)103 void ClientTransUdpManagerTest::TearDownTestCase(void) {}
104 
InitChannelInfo()105 static ChannelInfo InitChannelInfo()
106 {
107     ChannelInfo channel;
108     char strTmp[] = "ABCDEFG";
109     char strSessionName[] = "ohos.distributedschedule.dms.test";
110     channel.channelId = TEST_CHANNELID;
111     channel.businessType = BUSINESS_TYPE_STREAM;
112     channel.channelType = TEST_CHANNELTYPE;
113     channel.fd = TEST_DATA_TYPE;
114     channel.isServer = true;
115     channel.isEnabled = true;
116     channel.peerUid = TEST_CHANNELID;
117     channel.peerPid = TEST_CHANNELID;
118     channel.groupId = strTmp;
119     channel.sessionKey = strTmp;
120     channel.keyLen = sizeof(channel.sessionKey);
121     channel.peerSessionName = strSessionName;
122     channel.peerDeviceId = strTmp;
123     channel.myIp = strTmp;
124     channel.streamType = TEST_COUNT;
125     channel.isUdpFile = true;
126     channel.peerPort = TEST_COUNT;
127     channel.peerIp = strTmp;
128     channel.routeType = TEST_DATA_TYPE;
129     return channel;
130 }
131 
132 /**
133  * @tc.name: TransOnUdpChannelOpenedTest001
134  * @tc.desc: trans on udp channel opened test, use the wrong parameter.
135  * @tc.type: FUNC
136  * @tc.require:
137  */
138 HWTEST_F(ClientTransUdpManagerTest, TransOnUdpChannelOpenedTest001, TestSize.Level1)
139 {
140     int32_t ret;
141     ChannelInfo channel = InitChannelInfo();
142     int32_t udpPort;
143 
144     ret = TransOnUdpChannelOpened(nullptr, &channel, &udpPort, nullptr);
145     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
146 
147     ret = TransOnUdpChannelOpened(g_sessionName, nullptr, &udpPort, nullptr);
148     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
149 
150     ret = TransOnUdpChannelOpened(g_sessionName, &channel, nullptr, nullptr);
151     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
152 }
153 
154 /**
155  * @tc.name: TransOnUdpChannelOpenedTest002
156  * @tc.desc: trans on udp channel opened test, use the wrong or normal parameter.
157  * @tc.type: FUNC
158  * @tc.require:
159  */
160 HWTEST_F(ClientTransUdpManagerTest, TransOnUdpChannelOpenedTest002, TestSize.Level1)
161 {
162     int32_t ret;
163     ChannelInfo channel = InitChannelInfo();
164     int32_t udpPort;
165     char strSessionName[] = "ohos.distributedschedule.dms.test";
166     SocketAccessInfo accessInfo = { 0 };
167     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
168     EXPECT_EQ(SOFTBUS_NO_INIT, ret);
169 
170     ret = TransOnUdpChannelClosed(channel.channelId, SHUTDOWN_REASON_UNKNOWN);
171     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
172 
173     channel.businessType = BUSINESS_TYPE_FILE;
174     ret = TransOnUdpChannelOpened(strSessionName, &channel, &udpPort, &accessInfo);
175     EXPECT_EQ(SOFTBUS_TRANS_NODE_NOT_FOUND, ret);
176 
177     channel.businessType = BUSINESS_TYPE_FILE;
178     channel.channelId = TEST_CHANNELID + 1;
179     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
180     EXPECT_EQ(SOFTBUS_TRANS_NODE_NOT_FOUND, ret);
181 
182     channel.businessType = TEST_COUNT;
183     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
184     EXPECT_EQ(SOFTBUS_TRANS_BUSINESS_TYPE_NOT_MATCH, ret);
185 }
186 
187 /**
188  * @tc.name: TransOnUdpChannelOpenedTest003
189  * @tc.desc: trans on udp channel opened test, use the wrong or normal parameter.
190  * @tc.type: FUNC
191  * @tc.require:
192  */
193 HWTEST_F(ClientTransUdpManagerTest, TransOnUdpChannelOpenedTest003, TestSize.Level1)
194 {
195     int32_t ret;
196     ChannelInfo channel = InitChannelInfo();
197     int32_t udpPort;
198     QosTv tvList;
199     SocketAccessInfo accessInfo = { 0 };
200     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
201     EXPECT_EQ(SOFTBUS_NO_INIT, ret);
202 
203     ret = TransOnUdpChannelQosEvent(TEST_CHANNELID, TEST_EVENT_ID, TEST_COUNT, &tvList);
204     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
205 
206     channel.businessType = BUSINESS_TYPE_BUTT;
207     ret = TransOnUdpChannelOpenFailed(TEST_CHANNELID, TEST_ERRCODE);
208     EXPECT_EQ(SOFTBUS_OK, ret);
209 }
210 
211 /**
212  * @tc.name: TransOnUdpChannelOpenFailedTest001
213  * @tc.desc: trans on udp channel opened test, use the wrong or normal parameter.
214  * @tc.type: FUNC
215  * @tc.require:
216  */
217 HWTEST_F(ClientTransUdpManagerTest, TransOnUdpChannelOpenFailedTest001, TestSize.Level1)
218 {
219     int32_t ret;
220     ret = TransOnUdpChannelOpenFailed(TEST_CHANNELID, TEST_ERRCODE);
221     EXPECT_EQ(SOFTBUS_OK, ret);
222 
223     ret = TransOnUdpChannelOpenFailed(0, TEST_ERRCODE);
224     EXPECT_EQ(SOFTBUS_OK, ret);
225 }
226 
227 /**
228  * @tc.name: TransOnUdpChannelClosedTest001
229  * @tc.desc: trans on udp channel closed test, use the wrong or normal parameter.
230  * @tc.type: FUNC
231  * @tc.require:
232  */
233 HWTEST_F(ClientTransUdpManagerTest, TransOnUdpChannelClosedTest001, TestSize.Level1)
234 {
235     int32_t ret;
236     ret = TransOnUdpChannelClosed(TEST_CHANNELID, SHUTDOWN_REASON_UNKNOWN);
237     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
238 }
239 
240 /**
241  * @tc.name: TransOnUdpChannelClosedTest002
242  * @tc.desc: trans on udp channel closed test, use the wrong or normal parameter.
243  * @tc.type: FUNC
244  * @tc.require:
245  */
246 HWTEST_F(ClientTransUdpManagerTest, TransOnUdpChannelClosedTest002, TestSize.Level1)
247 {
248     int32_t ret;
249     ChannelInfo channel = InitChannelInfo();
250     int32_t udpPort;
251     channel.businessType = BUSINESS_TYPE_FILE;
252     SocketAccessInfo accessInfo = { 0 };
253     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
254     EXPECT_EQ(SOFTBUS_TRANS_NODE_NOT_FOUND, ret);
255 
256     ret = ClientTransUdpMgrInit(&g_sessionCb);
257     EXPECT_EQ(SOFTBUS_OK, ret);
258 
259     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
260     EXPECT_EQ(SOFTBUS_TRANS_NODE_NOT_FOUND, ret);
261 
262     ret = TransOnUdpChannelClosed(channel.channelId, SHUTDOWN_REASON_UNKNOWN);
263     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
264 
265     ret = TransOnUdpChannelClosed(channel.channelId, SHUTDOWN_REASON_PEER);
266     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
267 
268     ret = TransOnUdpChannelClosed(channel.channelId, SHUTDOWN_REASON_SEND_FILE_ERR);
269     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
270 
271     ret = TransOnUdpChannelClosed(TEST_CHANNELID + TEST_CHANNELID, SHUTDOWN_REASON_SEND_FILE_ERR);
272     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
273 }
274 
275 /**
276  * @tc.name: TransOnUdpChannelQosEventTest001
277  * @tc.desc: trans on udp channel qos event test, use the wrong or normal parameter.
278  * @tc.type: FUNC
279  * @tc.require:
280  */
281 HWTEST_F(ClientTransUdpManagerTest, TransOnUdpChannelQosEventTest001, TestSize.Level1)
282 {
283     int32_t ret;
284     QosTv tvList;
285     ret = TransOnUdpChannelQosEvent(TEST_CHANNELID, TEST_EVENT_ID, TEST_COUNT, &tvList);
286     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
287 }
288 
289 /**
290  * @tc.name: ClientTransCloseUdpChannelTest001
291  * @tc.desc: client trans close udp channel test, use the wrong or normal parameter.
292  * @tc.type: FUNC
293  * @tc.require:
294  */
295 HWTEST_F(ClientTransUdpManagerTest, ClientTransCloseUdpChannelTest001, TestSize.Level1)
296 {
297     int32_t ret;
298     ret = ClientTransCloseUdpChannel(TEST_CHANNELID, SHUTDOWN_REASON_UNKNOWN);
299     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
300 }
301 
302 /**
303  * @tc.name: TransUdpChannelSendStreamTest001
304  * @tc.desc: trans udp channel send stream test, use the wrong or normal parameter.
305  * @tc.type: FUNC
306  * @tc.require:
307  */
308 HWTEST_F(ClientTransUdpManagerTest, TransUdpChannelSendStreamTest001, TestSize.Level1)
309 {
310     int32_t ret;
311     ChannelInfo channel = InitChannelInfo();
312     int32_t udpPort;
313 
314     char sendStringData[STREAM_DATA_LENGTH] = "diudiudiu";
315     StreamData tmpData = {
316         sendStringData,
317         STREAM_DATA_LENGTH,
318     };
319     char str[STREAM_DATA_LENGTH] = "oohoohooh";
320     StreamData tmpData2 = {
321         str,
322         STREAM_DATA_LENGTH,
323     };
324 
325     StreamFrameInfo tmpf = {};
326     SocketAccessInfo accessInfo = { 0 };
327     ret = TransUdpChannelSendStream(TEST_CHANNELID, &tmpData, &tmpData2, &tmpf);
328     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
329 
330     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
331     EXPECT_EQ(SOFTBUS_NO_INIT, ret);
332 
333     ret = TransUdpChannelSendStream(TEST_CHANNELID, &tmpData, &tmpData2, &tmpf);
334     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
335 
336     ret = TransUdpChannelSetStreamMultiLayer(TEST_CHANNELID, nullptr);
337     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
338 }
339 
340 /**
341  * @tc.name: TransUdpChannelSendFileTest001
342  * @tc.desc: trans udp channel send file test, use the wrong or normal parameter.
343  * @tc.type: FUNC
344  * @tc.require:
345  */
346 HWTEST_F(ClientTransUdpManagerTest, TransUdpChannelSendFileTest001, TestSize.Level1)
347 {
348     int32_t ret;
349     const char *sFileList[] = {
350         "/data/big.tar",
351         "/data/richu.jpg",
352         "/data/richu-002.jpg",
353         "/data/richu-003.jpg",
354     };
355     ret = TransUdpChannelSendFile(TEST_CHANNELID, nullptr, nullptr, 1);
356     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
357 
358     ret = TransUdpChannelSendFile(TEST_CHANNELID, sFileList, nullptr, 0);
359     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
360 
361     ret = TransUdpChannelSendFile(TEST_CHANNELID, sFileList, nullptr, 1);
362     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
363 }
364 
365 /**
366  * @tc.name: TransGetUdpChannelByFileIdTest001
367  * @tc.desc: trans get udp channel by fileid test, use the wrong or normal parameter.
368  * @tc.type: FUNC
369  * @tc.require:
370  */
371 HWTEST_F(ClientTransUdpManagerTest, TransGetUdpChannelByFileIdTest001, TestSize.Level1)
372 {
373     int32_t ret;
374     UdpChannel udpChannel;
375     (void)memset_s(&udpChannel, sizeof(UdpChannel), 0, sizeof(UdpChannel));
376     ret = TransGetUdpChannelByFileId(TEST_DATA_TYPE, &udpChannel);
377     EXPECT_EQ(SOFTBUS_TRANS_UDP_CHANNEL_NOT_FOUND, ret);
378 
379     ClientTransUdpMgrDeinit();
380     ret = TransGetUdpChannelByFileId(TEST_DATA_TYPE, &udpChannel);
381     EXPECT_EQ(SOFTBUS_NO_INIT, ret);
382 }
383 
384 /**
385  * @tc.name: ClientTransAddUdpChannelTest001
386  * @tc.desc: client trans add udp channel test, use the wrong or normal parameter.
387  * @tc.type: FUNC
388  * @tc.require:
389  */
390 HWTEST_F(ClientTransUdpManagerTest, ClientTransAddUdpChannelTest001, TestSize.Level1)
391 {
392     int32_t ret;
393     ChannelInfo channel = InitChannelInfo();
394     int32_t udpPort;
395     SocketAccessInfo accessInfo = { 0 };
396     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
397     EXPECT_EQ(SOFTBUS_TRANS_UDP_CLIENT_ADD_CHANNEL_FAILED, ret);
398 
399     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
400     EXPECT_EQ(SOFTBUS_TRANS_UDP_CLIENT_ADD_CHANNEL_FAILED, ret);
401 
402     ClientTransUdpMgrDeinit();
403     ret = TransOnUdpChannelOpened(g_sessionName, &channel, &udpPort, &accessInfo);
404     EXPECT_EQ(SOFTBUS_TRANS_UDP_CLIENT_ADD_CHANNEL_FAILED, ret);
405 }
406 
407 /**
408  * @tc.name: ClientTransUdpManagerTest001
409  * @tc.desc: client trans udp manager test, use the normal parameter.
410  * @tc.type: FUNC
411  * @tc.require:
412  */
413 HWTEST_F(ClientTransUdpManagerTest, ClientTransUdpManagerTest001, TestSize.Level1)
414 {
415     int32_t ret;
416 
417     IClientSessionCallBack *cb = GetClientSessionCb();
418     ret = ClientTransUdpMgrInit(cb);
419     EXPECT_EQ(SOFTBUS_OK, ret);
420 }
421 
422 /**
423  * @tc.name: ClientEmitFileEventTest001
424  * @tc.desc: client emit file event test, use the invalid parameter.
425  * @tc.type: FUNC
426  * @tc.require:
427  */
428 HWTEST_F(ClientTransUdpManagerTest, ClientEmitFileEventTest001, TestSize.Level1)
429 {
430     int32_t channelId = TEST_ERR_CHANNELID;
431     int32_t ret = ClientEmitFileEvent(channelId);
432     EXPECT_NE(SOFTBUS_OK, ret);
433 }
434 
435 /**
436  * @tc.name: ClientEmitFileEventTest002
437  * @tc.desc: client emit file event test, use the invalid parameter.
438  * @tc.type: FUNC
439  * @tc.require:
440  */
441 HWTEST_F(ClientTransUdpManagerTest, ClientEmitFileEventTest002, TestSize.Level1)
442 {
443     int32_t channelId = TEST_CHANNELID;
444     int32_t ret = ClientEmitFileEvent(channelId);
445     EXPECT_NE(SOFTBUS_OK, ret);
446 
447     ret = TransSetUdpChannelSessionId(TEST_CHANNELID, TEST_SESSIONID);
448     EXPECT_NE(SOFTBUS_NO_INIT, ret);
449 
450     ret = TransSetUdpChannelRenameHook(TEST_CHANNELID, nullptr);
451     EXPECT_NE(SOFTBUS_OK, ret);
452 }
453 
454 /**
455  * @tc.name: TransLimitChangeTest
456  * @tc.desc: trans limit change test, use the invalid parameter.
457  * @tc.type: FUNC
458  * @tc.require:
459  */
460 HWTEST_F(ClientTransUdpManagerTest, TransLimitChangeTest, TestSize.Level1)
461 {
462     int32_t channelId = TEST_ERR_CHANNELID;
463     int32_t ret = TransLimitChange(channelId, FILE_PRIORITY_BK);
464     EXPECT_EQ(SOFTBUS_TRANS_UDP_CHANNEL_NOT_FOUND, ret);
465 
466     channelId = TEST_CHANNELID;
467     ret = TransLimitChange(channelId, FILE_PRIORITY_BE);
468     EXPECT_EQ(SOFTBUS_TRANS_UDP_CHANNEL_NOT_FOUND, ret);
469 
470     ret = TransLimitChange(channelId, FILE_PRIORITY_TEST);
471     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
472 }
473 
474 /**
475  * @tc.name: TransSetUdpChannelTosTest
476  * @tc.desc: trans set udp channel tos test.
477  * @tc.type: FUNC
478  * @tc.require:
479  */
480 HWTEST_F(ClientTransUdpManagerTest, TransSetUdpChannelTosTest, TestSize.Level1)
481 {
482     int32_t channelId = TEST_ERR_CHANNELID;
483     int32_t ret = TransSetUdpChannelTos(channelId);
484     EXPECT_EQ(ret, SOFTBUS_TRANS_UDP_CHANNEL_NOT_FOUND);
485 }
486 
487 /**
488  * @tc.name: TransGetUdpChannelTosTest001
489  * @tc.desc: trans get udp channel tos test.
490  * @tc.type: FUNC
491  * @tc.require:
492  */
493 HWTEST_F(ClientTransUdpManagerTest, TransGetUdpChannelTosTest001, TestSize.Level1)
494 {
495     int32_t channelId = TEST_ERR_CHANNELID;
496     bool isTosSet = false;
497     int32_t ret = TransGetUdpChannelTos(channelId, &isTosSet);
498     EXPECT_EQ(ret, SOFTBUS_TRANS_UDP_CHANNEL_NOT_FOUND);
499     EXPECT_FALSE(isTosSet);
500     ret = TransGetUdpChannelTos(TEST_CHANNELID, nullptr);
501     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
502 }
503 
504 /**
505  * @tc.name: TransUdpChannelSendStreamTest002
506  * @tc.desc: trans udp channel sendstream test, use the wrong or normal parameter.
507  * @tc.type: FUNC
508  * @tc.require:
509  */
510 HWTEST_F(ClientTransUdpManagerTest, TransUdpChannelSendStreamTest002, TestSize.Level1)
511 {
512     int32_t channelId = TEST_CHANNELID;
513 
514     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
515     EXPECT_EQ(SOFTBUS_OK, ret);
516 
517     UdpChannel *newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
518     ASSERT_NE(newChannel, nullptr);
519     newChannel->channelId = channelId;
520     newChannel->isEnable = false;
521     ret = ClientTransAddUdpChannel(newChannel);
522     EXPECT_EQ(SOFTBUS_OK, ret);
523     StreamFrameInfo tmpf = {};
524     char sendStringData[STREAM_DATA_LENGTH] = "diudiudiu";
525     StreamData tmpData1 = {
526         sendStringData,
527         STREAM_DATA_LENGTH,
528     };
529     char str[STREAM_DATA_LENGTH] = "ooooooood";
530     StreamData tmpData2 = {
531         str,
532         STREAM_DATA_LENGTH,
533     };
534     ret = TransUdpChannelSendStream(channelId, &tmpData1, &tmpData2, &tmpf);
535     EXPECT_EQ(SOFTBUS_TRANS_UDP_CHANNEL_DISABLE, ret);
536 
537     newChannel->isEnable = true;
538     ret = TransUdpChannelSendStream(channelId, nullptr, nullptr, &tmpf);
539     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
540 
541     ret = TransDeleteUdpChannel(channelId);
542     EXPECT_EQ(SOFTBUS_OK, ret);
543     ClientTransUdpMgrDeinit();
544 }
545 
546 /**
547  * @tc.name: TransUdpChannelSendFileTest002
548  * @tc.desc: trans udp channel sendfile test, use the wrong or normal parameter.
549  * @tc.type: FUNC
550  * @tc.require:
551  */
552 HWTEST_F(ClientTransUdpManagerTest, TransUdpChannelSendFileTest002, TestSize.Level1)
553 {
554     int32_t channelId = TEST_CHANNELID;
555     const char *sFileList[] = {
556         "/data/big.tar",
557         "/data/richu.jpg",
558         "/data/richu-002.jpg",
559         "/data/richu-003.jpg",
560     };
561     const char *dFileList[] = {
562         "/data/big.tar",
563         "/data/richu.jpg",
564         "/data/richu-002.jpg",
565         "/data/richu-003.jpg",
566     };
567     uint32_t fileCnt = 0;
568 
569     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
570     EXPECT_EQ(SOFTBUS_OK, ret);
571 
572     UdpChannel *newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
573     ASSERT_NE(newChannel, nullptr);
574     newChannel->channelId = channelId;
575     newChannel->isEnable = false;
576     newChannel->dfileId = TEST_ERR_SESSIONID;
577     ret = ClientTransAddUdpChannel(newChannel);
578     EXPECT_EQ(SOFTBUS_OK, ret);
579 
580     ret = TransUdpChannelSendFile(channelId, sFileList, dFileList, fileCnt);
581     EXPECT_EQ(SOFTBUS_TRANS_UDP_CHANNEL_DISABLE, ret);
582     ret = TransDeleteUdpChannel(channelId);
583     EXPECT_EQ(SOFTBUS_OK, ret);
584 
585     newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
586     ASSERT_NE(newChannel, nullptr);
587     newChannel->channelId = channelId;
588     newChannel->isEnable = true;
589     newChannel->dfileId = TEST_SESSIONID;
590     ret = ClientTransAddUdpChannel(newChannel);
591     EXPECT_EQ(SOFTBUS_OK, ret);
592 
593     ret = TransUdpChannelSendFile(channelId, sFileList, dFileList, fileCnt);
594     EXPECT_NE(SOFTBUS_OK, ret);
595 
596     ret = TransDeleteUdpChannel(channelId);
597     EXPECT_EQ(SOFTBUS_OK, ret);
598     ClientTransUdpMgrDeinit();
599 }
600 
601 /**
602  * @tc.name: TransLimitChangeTest002
603  * @tc.desc: trans limit change test, use the wrong or normal parameter.
604  * @tc.type: FUNC
605  * @tc.require:
606  */
607 HWTEST_F(ClientTransUdpManagerTest, TransLimitChangeTest002, TestSize.Level1)
608 {
609     int32_t channelId = TEST_CHANNELID;
610 
611     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
612     EXPECT_EQ(SOFTBUS_OK, ret);
613 
614     UdpChannel *newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
615     ASSERT_NE(newChannel, nullptr);
616     newChannel->channelId = channelId;
617     newChannel->businessType = BUSINESS_TYPE_FILE;
618     newChannel->info.isServer = true;
619     ret = ClientTransAddUdpChannel(newChannel);
620     EXPECT_EQ(SOFTBUS_OK, ret);
621 
622     ret = TransLimitChange(channelId, FILE_PRIORITY_BK);
623     EXPECT_EQ(SOFTBUS_NOT_NEED_UPDATE, ret);
624     ret = TransDeleteUdpChannel(channelId);
625     EXPECT_EQ(SOFTBUS_OK, ret);
626 
627     newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
628     ASSERT_NE(newChannel, nullptr);
629     newChannel->channelId = channelId;
630     newChannel->businessType = BUSINESS_TYPE_BYTE;
631     newChannel->info.isServer = false;
632     ret = ClientTransAddUdpChannel(newChannel);
633     EXPECT_EQ(SOFTBUS_OK, ret);
634 
635     ret = TransLimitChange(channelId, FILE_PRIORITY_BK);
636     EXPECT_EQ(SOFTBUS_NOT_NEED_UPDATE, ret);
637 
638     ret = TransDeleteUdpChannel(channelId);
639     EXPECT_EQ(SOFTBUS_OK, ret);
640     ClientTransUdpMgrDeinit();
641 }
642 
643 /**
644  * @tc.name: TransLimitChangeTest003
645  * @tc.desc: trans limit change test, use the wrong or normal parameter.
646  * @tc.type: FUNC
647  * @tc.require:
648  */
649 HWTEST_F(ClientTransUdpManagerTest, TransLimitChangeTest003, TestSize.Level1)
650 {
651     int32_t channelId = TEST_CHANNELID;
652 
653     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
654     EXPECT_EQ(SOFTBUS_OK, ret);
655 
656     UdpChannel *newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
657     ASSERT_NE(newChannel, nullptr);
658     newChannel->channelId = channelId;
659     newChannel->businessType = BUSINESS_TYPE_FILE;
660     newChannel->info.isServer = false;
661     newChannel->isTosSet = false;
662     newChannel->dfileId = TEST_ERR_SESSIONID;
663     ret = ClientTransAddUdpChannel(newChannel);
664     EXPECT_EQ(SOFTBUS_OK, ret);
665 
666     ret = TransLimitChange(channelId, FILE_PRIORITY_BK);
667     EXPECT_EQ(SOFTBUS_OK, ret);
668     ret = TransDeleteUdpChannel(channelId);
669     EXPECT_EQ(SOFTBUS_OK, ret);
670 
671     newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
672     ASSERT_NE(newChannel, nullptr);
673     newChannel->channelId = channelId;
674     newChannel->businessType = BUSINESS_TYPE_FILE;
675     newChannel->info.isServer = false;
676     newChannel->isTosSet = true;
677     newChannel->dfileId = TEST_ERR_SESSIONID;
678     ret = ClientTransAddUdpChannel(newChannel);
679     EXPECT_EQ(SOFTBUS_OK, ret);
680 
681     ret = TransLimitChange(channelId, FILE_PRIORITY_BK);
682     EXPECT_EQ(SOFTBUS_NOT_NEED_UPDATE, ret);
683 
684     ret = TransDeleteUdpChannel(channelId);
685     EXPECT_EQ(SOFTBUS_OK, ret);
686     ClientTransUdpMgrDeinit();
687 }
688 
689 /**
690  * @tc.name: ClientEmitFileEventTest003
691  * @tc.desc: client emit file event test, use the wrong or normal parameter.
692  * @tc.type: FUNC
693  * @tc.require:
694  */
695 HWTEST_F(ClientTransUdpManagerTest, ClientEmitFileEventTest003, TestSize.Level1)
696 {
697     int32_t channelId = TEST_CHANNELID;
698 
699     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
700     EXPECT_EQ(SOFTBUS_OK, ret);
701 
702     UdpChannel *newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
703     ASSERT_NE(newChannel, nullptr);
704     newChannel->channelId = channelId;
705     newChannel->businessType = BUSINESS_TYPE_FILE;
706     newChannel->dfileId = TEST_ERR_SESSIONID;
707     ret = ClientTransAddUdpChannel(newChannel);
708     EXPECT_EQ(SOFTBUS_OK, ret);
709 
710     ret = ClientEmitFileEvent(channelId);
711     EXPECT_NE(SOFTBUS_NO_INIT, ret);
712 
713     ret = TransDeleteUdpChannel(channelId);
714     EXPECT_EQ(SOFTBUS_OK, ret);
715     ClientTransUdpMgrDeinit();
716 }
717 
718 /**
719  * @tc.name: TransSetUdpChannelSessionIdTest001
720  * @tc.desc: trans set udpchannel sessionid test, use the wrong or normal parameter.
721  * @tc.type: FUNC
722  * @tc.require:
723  */
724 HWTEST_F(ClientTransUdpManagerTest, TransSetUdpChannelSessionId001, TestSize.Level1)
725 {
726     int32_t channelId = TEST_CHANNELID;
727     int32_t sessionId = TEST_SESSIONID;
728     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
729     EXPECT_EQ(SOFTBUS_OK, ret);
730     ClientTransUdpMgrDeinit();
731 
732     ret = TransSetUdpChannelSessionId(channelId, sessionId);
733     EXPECT_EQ(SOFTBUS_NO_INIT, ret);
734 
735     ret = ClientTransUdpMgrInit(&g_sessionCb);
736     EXPECT_EQ(SOFTBUS_OK, ret);
737     UdpChannel *newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
738     ASSERT_NE(newChannel, nullptr);
739     newChannel->channelId = channelId;
740     ret = ClientTransAddUdpChannel(newChannel);
741     EXPECT_EQ(SOFTBUS_OK, ret);
742 
743     ret = TransSetUdpChannelSessionId(channelId, sessionId);
744     EXPECT_EQ(SOFTBUS_OK, ret);
745 
746     ret = TransDeleteUdpChannel(channelId);
747     EXPECT_EQ(SOFTBUS_OK, ret);
748     ClientTransUdpMgrDeinit();
749 }
750 
OnRenameFileCb(RenameParam * renameParam)751 static void OnRenameFileCb(RenameParam *renameParam)
752 {
753     return;
754 }
755 
756 /**
757  * @tc.name: TransSetUdpChannelRenameHookTest001
758  * @tc.desc: trans set udpchannel rename hook test, use the wrong or normal parameter.
759  * @tc.type: FUNC
760  * @tc.require:
761  */
762 HWTEST_F(ClientTransUdpManagerTest, TransSetUdpChannelRenameHookTest001, TestSize.Level1)
763 {
764     int32_t channelId = TEST_CHANNELID;
765     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
766     EXPECT_EQ(SOFTBUS_OK, ret);
767     ClientTransUdpMgrDeinit();
768     OnRenameFileCallback onRenameFile = OnRenameFileCb;
769 
770     ret = TransSetUdpChannelRenameHook(channelId, onRenameFile);
771     EXPECT_EQ(SOFTBUS_NO_INIT, ret);
772 
773     ret = ClientTransUdpMgrInit(&g_sessionCb);
774     EXPECT_EQ(SOFTBUS_OK, ret);
775     UdpChannel *newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
776     ASSERT_NE(newChannel, nullptr);
777     newChannel->channelId = channelId;
778     newChannel->businessType = BUSINESS_TYPE_FILE;
779     ret = TransSetUdpChannelRenameHook(channelId, onRenameFile);
780     EXPECT_EQ(SOFTBUS_TRANS_UDP_CHANNEL_NOT_FOUND, ret);
781 
782     ret = ClientTransAddUdpChannel(newChannel);
783     EXPECT_EQ(SOFTBUS_OK, ret);
784 
785     ret = TransSetUdpChannelRenameHook(channelId, onRenameFile);
786     EXPECT_EQ(SOFTBUS_OK, ret);
787 
788     ret = TransDeleteUdpChannel(channelId);
789     EXPECT_EQ(SOFTBUS_OK, ret);
790     ClientTransUdpMgrDeinit();
791 }
792 
793 /**
794  * @tc.name: TransSetUdpChannelTosTest001
795  * @tc.desc: trans set udpchannel tos test, use the wrong or normal parameter.
796  * @tc.type: FUNC
797  * @tc.require:
798  */
799 HWTEST_F(ClientTransUdpManagerTest, TransSetUdpChannelTosTest001, TestSize.Level1)
800 {
801     int32_t channelId = TEST_CHANNELID;
802     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
803     EXPECT_EQ(SOFTBUS_OK, ret);
804     ClientTransUdpMgrDeinit();
805 
806     ret = TransSetUdpChannelTos(channelId);
807     EXPECT_EQ(SOFTBUS_NO_INIT, ret);
808 
809     ret = ClientTransUdpMgrInit(&g_sessionCb);
810     EXPECT_EQ(SOFTBUS_OK, ret);
811     UdpChannel *newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
812     ASSERT_NE(newChannel, nullptr);
813     newChannel->channelId = channelId;
814 
815     ret = ClientTransAddUdpChannel(newChannel);
816     EXPECT_EQ(SOFTBUS_OK, ret);
817 
818     ret = TransSetUdpChannelTos(channelId);
819     EXPECT_EQ(SOFTBUS_OK, ret);
820 
821     ret = TransDeleteUdpChannel(channelId);
822     EXPECT_EQ(SOFTBUS_OK, ret);
823     ClientTransUdpMgrDeinit();
824 }
825 
826 /**
827  * @tc.name: TransGetUdpChannelTosTest002
828  * @tc.desc: trans get udpchannel tos test, use the wrong or normal parameter.
829  * @tc.type: FUNC
830  * @tc.require:
831  */
832 HWTEST_F(ClientTransUdpManagerTest, TransGetUdpChannelTosTest002, TestSize.Level1)
833 {
834     int32_t channelId = TEST_CHANNELID;
835     bool isTosSet = false;
836     int32_t ret = ClientTransUdpMgrInit(&g_sessionCb);
837     EXPECT_EQ(SOFTBUS_OK, ret);
838     ClientTransUdpMgrDeinit();
839 
840     ret = TransGetUdpChannelTos(channelId, &isTosSet);
841     EXPECT_EQ(SOFTBUS_NO_INIT, ret);
842 
843     ret = ClientTransUdpMgrInit(&g_sessionCb);
844     EXPECT_EQ(SOFTBUS_OK, ret);
845     UdpChannel *newChannel = reinterpret_cast<UdpChannel *>(SoftBusCalloc(sizeof(UdpChannel)));
846     ASSERT_NE(newChannel, nullptr);
847     newChannel->channelId = channelId;
848 
849     ret = ClientTransAddUdpChannel(newChannel);
850     EXPECT_EQ(SOFTBUS_OK, ret);
851 
852     ret = TransGetUdpChannelTos(channelId, &isTosSet);
853     EXPECT_EQ(SOFTBUS_OK, ret);
854 
855     ret = TransDeleteUdpChannel(channelId);
856     EXPECT_EQ(SOFTBUS_OK, ret);
857     ClientTransUdpMgrDeinit();
858 }
859 } // namespace OHOS
860