1 /*
2 * Copyright (c) 2021-2023 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 #include <pthread.h>
18 #include <securec.h>
19
20 #include "common_list.h"
21 #include "softbus_base_listener.h"
22 #include "softbus_def.h"
23 #include "softbus_errcode.h"
24 #include "softbus_tcp_socket.h"
25 #include "softbus_utils.h"
26 #include "softbus_conn_manager.h"
27
28 using namespace testing::ext;
29
30 static const int INVALID_FD = -1;
31 static const int TEST_FD = 1;
32 static pthread_mutex_t g_isInitedLock;
33 static int g_count = 0;
34 static int g_port = 6666;
35
36 namespace OHOS {
37 class SoftbusConnCommonTest : public testing::Test {
38 public:
SoftbusConnCommonTest()39 SoftbusConnCommonTest()
40 {}
~SoftbusConnCommonTest()41 ~SoftbusConnCommonTest()
42 {}
43 static void SetUpTestCase(void);
44 static void TearDownTestCase(void);
45 void SetUp();
46 void TearDown();
47 };
48
ThreadPoolTask(void * arg)49 int ThreadPoolTask(void* arg)
50 {
51 pthread_mutex_lock(&g_isInitedLock);
52 g_count++;
53 pthread_mutex_unlock(&g_isInitedLock);
54 return SOFTBUS_OK;
55 }
56
SetUpTestCase(void)57 void SoftbusConnCommonTest::SetUpTestCase(void)
58 {
59 pthread_mutex_init(&g_isInitedLock, nullptr);
60 GTEST_LOG_(INFO) << "SoftbusConnCommonTestSetUp";
61 ConnServerInit();
62 }
63
TearDownTestCase(void)64 void SoftbusConnCommonTest::TearDownTestCase(void)
65 {
66 g_count = 0;
67 g_port++;
68 GTEST_LOG_(INFO) << "+-------------------------------------------+";
69 }
70
SetUp(void)71 void SoftbusConnCommonTest::SetUp(void)
72 {
73 g_count = 0;
74 }
75
TearDown(void)76 void SoftbusConnCommonTest::TearDown(void)
77 {
78 g_count = 0;
79 }
80
ConnectEvent(ListenerModule module,int32_t cfd,const ConnectOption * clientAddr)81 int32_t ConnectEvent(ListenerModule module, int32_t cfd, const ConnectOption *clientAddr)
82 {
83 return 0;
84 }
85
DataEvent(ListenerModule module,int32_t events,int32_t fd)86 int32_t DataEvent(ListenerModule module, int32_t events, int32_t fd)
87 {
88 return 0;
89 }
90
91 SocketAddr g_socketAddr = {
92 .addr = "127.0.0.1",
93 .port = g_port,
94 };
95
96 /*
97 * @tc.name: testBaseListener002
98 * @tc.desc: test GetSoftbusBaseListener and set
99 * @tc.type: FUNC
100 * @tc.require: I5HSOL
101 */
102 HWTEST_F(SoftbusConnCommonTest, testBaseListener002, TestSize.Level1)
103 {
104 int i;
105 int port = 6666;
106 SoftbusBaseListener *setListener = (SoftbusBaseListener *)malloc(sizeof(SoftbusBaseListener));
107 ASSERT_TRUE(setListener != nullptr);
108 setListener->onConnectEvent = ConnectEvent;
109 setListener->onDataEvent = DataEvent;
110 for (i = PROXY; i < LISTENER_MODULE_DYNAMIC_START; i++) {
111 LocalListenerInfo info = {
112 .type = CONNECT_TCP,
113 .socketOption = {
114 .addr = "127.0.0.1",
115 .port = port,
116 .moduleId = static_cast<ListenerModule>(i),
117 .protocol = LNN_PROTOCOL_IP
118 }
119 };
120 EXPECT_EQ(port, StartBaseListener(&info, setListener));
121 ASSERT_EQ(SOFTBUS_OK, StopBaseListener(static_cast<ListenerModule>(i)));
122 ++port;
123 }
124 free(setListener);
125 };
126
127 /*
128 * @tc.name: testBaseListener006
129 * @tc.desc: test Invalid trigger param
130 * @tc.type: FUNC
131 * @tc.require:
132 */
133 HWTEST_F(SoftbusConnCommonTest, testBaseListener006, TestSize.Level1)
134 {
135 int module;
136 int triggerType;
137 int fd = 1;
138 for (triggerType = READ_TRIGGER; triggerType <= RW_TRIGGER; triggerType++) {
139 EXPECT_EQ(SOFTBUS_INVALID_PARAM, AddTrigger(UNUSE_BUTT, fd, static_cast<TriggerType>(triggerType)));
140 EXPECT_EQ(SOFTBUS_INVALID_PARAM, DelTrigger(UNUSE_BUTT, fd, static_cast<TriggerType>(triggerType)));
141 }
142 for (module = PROXY; module < LISTENER_MODULE_DYNAMIC_START; module++) {
143 for (triggerType = READ_TRIGGER; triggerType <= RW_TRIGGER; triggerType++) {
144 EXPECT_EQ(SOFTBUS_INVALID_PARAM, AddTrigger(static_cast<ListenerModule>(module), INVALID_FD,
145 static_cast<TriggerType>(triggerType)));
146 EXPECT_EQ(SOFTBUS_INVALID_PARAM, DelTrigger(static_cast<ListenerModule>(module), INVALID_FD,
147 static_cast<TriggerType>(triggerType)));
148 }
149 }
150 };
151
152 /*
153 * @tc.name: testBaseListener007
154 * @tc.desc: test Not set baselistener
155 * @tc.type: FUNC
156 * @tc.require:
157 */
158 HWTEST_F(SoftbusConnCommonTest, testBaseListener007, TestSize.Level1)
159 {
160 int module;
161 int triggerType;
162 int fd = 1;
163 for (module = PROXY; module < LISTENER_MODULE_DYNAMIC_START; module++) {
164 for (triggerType = READ_TRIGGER; triggerType <= RW_TRIGGER; triggerType++) {
165 EXPECT_EQ(SOFTBUS_CONN_FAIL, AddTrigger(static_cast<ListenerModule>(module),
166 fd, static_cast<TriggerType>(triggerType)));
167 EXPECT_EQ(SOFTBUS_OK, DelTrigger(static_cast<ListenerModule>(module),
168 fd, static_cast<TriggerType>(triggerType)));
169 }
170 }
171 };
172
173 /*
174 * @tc.name: testBaseListener008
175 * @tc.desc: test add del trigger
176 * @tc.type: FUNC
177 * @tc.require:
178 */
179 HWTEST_F(SoftbusConnCommonTest, testBaseListener008, TestSize.Level1)
180 {
181 int module;
182 int triggerType;
183 int fd = 1;
184 int port = 6666;
185
186 for (module = PROXY; module < LISTENER_MODULE_DYNAMIC_START; module++) {
187 SoftbusBaseListener* listener = (SoftbusBaseListener*)malloc(sizeof(SoftbusBaseListener));
188 ASSERT_TRUE(listener != nullptr);
189 listener->onConnectEvent = ConnectEvent;
190 listener->onDataEvent = DataEvent;
191
192 LocalListenerInfo info = {
193 .type = CONNECT_TCP,
194 .socketOption = {.addr = "127.0.0.1",
195 .port = port,
196 .moduleId = static_cast<ListenerModule>(module),
197 .protocol = LNN_PROTOCOL_IP}
198 };
199 EXPECT_EQ(port, StartBaseListener(&info, listener));
200 for (triggerType = READ_TRIGGER; triggerType <= RW_TRIGGER; triggerType++) {
201 EXPECT_EQ(SOFTBUS_OK, AddTrigger(static_cast<ListenerModule>(module),
202 fd, static_cast<TriggerType>(triggerType)));
203 EXPECT_EQ(SOFTBUS_OK, AddTrigger(static_cast<ListenerModule>(module),
204 fd, static_cast<TriggerType>(triggerType)));
205 EXPECT_EQ(SOFTBUS_OK, DelTrigger(static_cast<ListenerModule>(module),
206 fd, static_cast<TriggerType>(triggerType)));
207 EXPECT_EQ(SOFTBUS_OK, DelTrigger(static_cast<ListenerModule>(module),
208 fd, static_cast<TriggerType>(triggerType)));
209 }
210 EXPECT_EQ(SOFTBUS_OK, StopBaseListener(static_cast<ListenerModule>(module)));
211 free(listener);
212 }
213 };
214
215 /*
216 * @tc.name: testBaseListener009
217 * @tc.desc: test GetSoftbusBaseListener and set
218 * @tc.type: FUNC
219 * @tc.require: I5HSOL
220 */
221 HWTEST_F(SoftbusConnCommonTest, testBaseListener009, TestSize.Level1)
222 {
223 int i;
224 int port = 6666;
225 SoftbusBaseListener *setListener = (SoftbusBaseListener *)malloc(sizeof(SoftbusBaseListener));
226 ASSERT_TRUE(setListener != nullptr);
227 setListener->onConnectEvent = ConnectEvent;
228 setListener->onDataEvent = DataEvent;
229 for (i = PROXY; i < LISTENER_MODULE_DYNAMIC_START; i++) {
230 LocalListenerInfo info = {
231 .type = CONNECT_TCP,
232 .socketOption = {
233 .addr = "::1%lo",
234 .port = port,
235 .moduleId = static_cast<ListenerModule>(i),
236 .protocol = LNN_PROTOCOL_IP
237 }
238 };
239 EXPECT_EQ(port, StartBaseListener(&info, setListener));
240 ASSERT_EQ(SOFTBUS_OK, StopBaseListener(static_cast<ListenerModule>(i)));
241 ++port;
242 }
243 free(setListener);
244 };
245
246 /*
247 * @tc.name: testBaseListener016
248 * @tc.desc: Test StartBaseClient invalid input param ListenerModule module.
249 * @tc.in: Test module, Test number, Test Levels.
250 * @tc.out: NonZero
251 * @tc.type: FUNC
252 * @tc.require: The StartBaseClient operates normally.
253 */
254 HWTEST_F(SoftbusConnCommonTest, testBaseListener016, TestSize.Level1)
255 {
256 EXPECT_EQ(SOFTBUS_INVALID_PARAM, StartBaseClient(static_cast<ListenerModule>(PROXY - 1), NULL));
257 EXPECT_EQ(SOFTBUS_INVALID_PARAM,
258 StartBaseClient(static_cast<ListenerModule>(DIRECT_CHANNEL_SERVER_WIFI + 1), NULL));
259 };
260
261 /*
262 * @tc.name: testBaseListener017
263 * @tc.desc: Test StartBaseClient, BaseListener not set, start failed.
264 * @tc.in: Test module, Test number, Test Levels.
265 * @tc.out: NonZero
266 * @tc.type: FUNC
267 * @tc.require: The StartBaseClient operates normally.
268 */
269 HWTEST_F(SoftbusConnCommonTest, testBaseListener017, TestSize.Level1)
270 {
271 SoftbusBaseListener* listener = (SoftbusBaseListener*)malloc(sizeof(SoftbusBaseListener));
272 ASSERT_TRUE(listener != nullptr);
273 listener->onConnectEvent = ConnectEvent;
274 listener->onDataEvent = DataEvent;
275 int i;
276 for (i = PROXY; i < LISTENER_MODULE_DYNAMIC_START; i++) {
277 EXPECT_EQ(SOFTBUS_OK, StartBaseClient(static_cast<ListenerModule>(i), listener));
278 }
279 free(listener);
280 };
281
282 /*
283 * @tc.name: testBaseListener021
284 * @tc.desc: Test StartBaseListener invalid input param const char *ip.
285 * @tc.in: Test module, Test number, Test Levels.
286 * @tc.out: NonZero
287 * @tc.type: FUNC
288 * @tc.require: The StartBaseListener operates normally.
289 */
290 HWTEST_F(SoftbusConnCommonTest, testBaseListener021, TestSize.Level1)
291 {
292 SoftbusBaseListener* listener = (SoftbusBaseListener*)malloc(sizeof(SoftbusBaseListener));
293 ASSERT_TRUE(listener != nullptr);
294 listener->onConnectEvent = ConnectEvent;
295 listener->onDataEvent = DataEvent;
296 LocalListenerInfo info = {
297 .type = CONNECT_TCP,
298 .socketOption = {.addr = "",
299 .port = 666,
300 .moduleId = PROXY,
301 .protocol = LNN_PROTOCOL_IP}
302 };
303 int i;
304 for (i = PROXY; i < LISTENER_MODULE_DYNAMIC_START; i++) {
305 info.socketOption.moduleId = static_cast<ListenerModule>(i);
306 EXPECT_EQ(SOFTBUS_CONN_LISTENER_NOT_IDLE, StartBaseListener(&info, listener));
307 }
308 free(listener);
309 };
310
311 /*
312 * @tc.name: testBaseListener022
313 * @tc.desc: Test StartBaseListener invalid input param int32_t port < 0.
314 * @tc.in: Test module, Test number, Test Levels.
315 * @tc.out: NonZero
316 * @tc.type: FUNC
317 * @tc.require: The StartBaseListener operates normally.
318 */
319 HWTEST_F(SoftbusConnCommonTest, testBaseListener022, TestSize.Level1)
320 {
321 SoftbusBaseListener* listener = (SoftbusBaseListener*)malloc(sizeof(SoftbusBaseListener));
322 ASSERT_TRUE(listener != nullptr);
323 listener->onConnectEvent = ConnectEvent;
324 listener->onDataEvent = DataEvent;
325 LocalListenerInfo info = {
326 .type = CONNECT_TCP,
327 .socketOption = {.addr = "127.0.0.1",
328 .port = -1,
329 .moduleId = PROXY,
330 .protocol = LNN_PROTOCOL_IP}
331 };
332 int i;
333 for (i = PROXY; i <= LISTENER_MODULE_DYNAMIC_START; i++) {
334 info.socketOption.moduleId = static_cast<ListenerModule>(i);
335 EXPECT_EQ(SOFTBUS_INVALID_PARAM, StartBaseListener(&info, listener));
336 }
337 free(listener);
338 };
339
340 /*
341 * @tc.name: testBaseListener026
342 * @tc.desc: Test StopBaseListener invalid input param ListenerModule module.
343 * @tc.in: Test module, Test number, Test Levels.
344 * @tc.out: NonZero
345 * @tc.type: FUNC
346 * @tc.require: The StopBaseListener operates normally.
347 */
348 HWTEST_F(SoftbusConnCommonTest, testBaseListener026, TestSize.Level1)
349 {
350 EXPECT_EQ(SOFTBUS_INVALID_PARAM, StopBaseListener(static_cast<ListenerModule>(PROXY - 1)));
351 EXPECT_EQ(SOFTBUS_INVALID_PARAM, StopBaseListener(static_cast<ListenerModule>(UNUSE_BUTT)));
352 };
353
354 /*
355 * @tc.name: testBaseListener027
356 * @tc.desc: Test StopBaseListener failed g_listenerList[module].info = NULL.
357 * @tc.in: Test module, Test number, Test Levels.
358 * @tc.out: NonZero
359 * @tc.type: FUNC
360 * @tc.require: The StopBaseListener operates normally.
361 */
362 HWTEST_F(SoftbusConnCommonTest, testBaseListener027, TestSize.Level1)
363 {
364 int i;
365 for (i = PROXY; i < LISTENER_MODULE_DYNAMIC_START; i++) {
366 EXPECT_EQ(SOFTBUS_OK, StopBaseListener(static_cast<ListenerModule>(i)));
367 }
368 EXPECT_EQ(SOFTBUS_INVALID_PARAM, StopBaseListener(UNUSE_BUTT));
369 };
370
371 /*
372 * @tc.name: testTcpSocket001
373 * @tc.desc: test OpenTcpServerSocket
374 * @tc.type: FUNC
375 * @tc.require:
376 */
377 HWTEST_F(SoftbusConnCommonTest, testTcpSocket001, TestSize.Level1)
378 {
379 const SocketInterface *tcp = GetTcpProtocol();
380 ASSERT_NE(tcp, nullptr);
381
382 LocalListenerInfo info = {
383 .type = CONNECT_TCP,
384 .socketOption = {
385 .addr = "127.0.0.1",
386 .port = g_port,
387 .moduleId = DIRECT_CHANNEL_SERVER_WIFI,
388 .protocol = LNN_PROTOCOL_IP
389 }
390 };
391
392 int fd = tcp->OpenServerSocket(&info);
393 int ret = (fd <= 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
394 ASSERT_TRUE(ret == SOFTBUS_OK);
395 int port = tcp->GetSockPort(fd);
396 EXPECT_EQ(port, g_port);
397 ConnCloseSocket(fd);
398
399 fd = tcp->OpenServerSocket(nullptr);
400 ret = (fd <= 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
401 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
402 ConnCloseSocket(fd);
403
404 info.socketOption.port = -1;
405 fd = tcp->OpenServerSocket(&info);
406 ret = (fd <= 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
407 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
408 ConnCloseSocket(fd);
409 };
410
411 /*
412 * @tc.name: testTcpSocket002
413 * @tc.desc: test OpenTcpClientSocket
414 * @tc.type: FUNC
415 * @tc.require:
416 */
417 HWTEST_F(SoftbusConnCommonTest, testTcpSocket002, TestSize.Level1)
418 {
419 const SocketInterface *tcp = GetTcpProtocol();
420 ASSERT_NE(tcp, nullptr);
421
422 ConnectOption option = {
423 .type = CONNECT_TCP,
424 .socketOption = {
425 .addr = "127.0.0.1",
426 .port = g_port,
427 .moduleId = DIRECT_CHANNEL_SERVER_WIFI,
428 .protocol = LNN_PROTOCOL_IP
429 }
430 };
431
432 int fd = tcp->OpenClientSocket(nullptr, "127.0.0.1", false);
433 int ret = (fd < 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
434 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
435 ConnCloseSocket(fd);
436 fd = tcp->OpenClientSocket(nullptr, nullptr, false);
437 ret = (fd < 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
438 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
439 ConnCloseSocket(fd);
440
441 option.socketOption.port = -1;
442 fd = tcp->OpenClientSocket(&option, "127.0.0.1", false);
443 ret = (fd < 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
444 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
445 ConnCloseSocket(fd);
446 };
447
448 /*
449 * @tc.name: testBaseListener003
450 * @tc.desc: test GetTcpSockPort invalid fd
451 * @tc.type: FUNC
452 * @tc.require:
453 */
454 HWTEST_F(SoftbusConnCommonTest, testTcpSocket003, TestSize.Level1)
455 {
456 const SocketInterface *tcp = GetTcpProtocol();
457 ASSERT_NE(tcp, nullptr);
458 int invalidFd = 1;
459 int port = tcp->GetSockPort(invalidFd);
460 int ret = (port <= 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
461 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
462 };
463
464 /*
465 * @tc.name: testTcpSocket004
466 * @tc.desc: test ConnSendSocketData invalid fd
467 * @tc.type: FUNC
468 * @tc.require:
469 */
470 HWTEST_F(SoftbusConnCommonTest, testTcpSocket004, TestSize.Level1)
471 {
472 const SocketInterface *tcp = GetTcpProtocol();
473 ASSERT_NE(tcp, nullptr);
474
475 int clientFd = tcp->OpenClientSocket(nullptr, "127.5.0.1", false);
476 int ret = (clientFd < 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
477 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
478 ssize_t bytes = ConnSendSocketData(clientFd, "Hello world", 11, 0);
479 EXPECT_EQ(bytes, -1);
480 ConnShutdownSocket(clientFd);
481 };
482
483 /*
484 * @tc.name: testTcpSocket005
485 * @tc.desc: test OpenTcpServerSocket
486 * @tc.type: FUNC
487 * @tc.require:
488 */
489 HWTEST_F(SoftbusConnCommonTest, testTcpSocket006, TestSize.Level1)
490 {
491 const SocketInterface *tcp = GetTcpProtocol();
492 ASSERT_NE(tcp, nullptr);
493
494 LocalListenerInfo info = {
495 .type = CONNECT_TCP,
496 .socketOption = {
497 .addr = "::1%lo",
498 .port = g_port,
499 .moduleId = DIRECT_CHANNEL_SERVER_WIFI,
500 .protocol = LNN_PROTOCOL_IP
501 }
502 };
503
504 int fd = tcp->OpenServerSocket(&info);
505 int ret = (fd <= 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
506 ASSERT_TRUE(ret == SOFTBUS_OK);
507 int port = tcp->GetSockPort(fd);
508 EXPECT_EQ(port, g_port);
509 ConnCloseSocket(fd);
510
511 fd = tcp->OpenServerSocket(nullptr);
512 ret = (fd <= 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
513 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
514 ConnCloseSocket(fd);
515
516 info.socketOption.port = -1;
517 fd = tcp->OpenServerSocket(&info);
518 ret = (fd <= 0) ? SOFTBUS_INVALID_PARAM : SOFTBUS_OK;
519 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
520 ConnCloseSocket(fd);
521 };
522
523 /*
524 * @tc.name: testSocket001
525 * @tc.desc: test ConnGetLocalSocketPort port
526 * @tc.type: FUNC
527 * @tc.require: I5PC1B
528 */
529 HWTEST_F(SoftbusConnCommonTest, testSocket001, TestSize.Level1)
530 {
531 int ret;
532 ret = ConnGetLocalSocketPort(INVALID_FD);
533 EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
534
535 ret = ConnGetLocalSocketPort(TEST_FD);
536 EXPECT_TRUE(ret < 0);
537 };
538
539 /*
540 * @tc.name: testSocket002
541 * @tc.desc: test ConnGetPeerSocketAddr param is invalid
542 * @tc.type: FUNC
543 * @tc.require: I5PC1B
544 */
545 HWTEST_F(SoftbusConnCommonTest, testSocket002, TestSize.Level1)
546 {
547 int ret;
548 ret = ConnGetPeerSocketAddr(INVALID_FD, &g_socketAddr);
549 EXPECT_EQ(SOFTBUS_TCP_SOCKET_ERR, ret);
550
551 ret = ConnGetPeerSocketAddr(TEST_FD, NULL);
552 EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
553
554 ret = ConnGetPeerSocketAddr(TEST_FD, &g_socketAddr);
555 EXPECT_EQ(SOFTBUS_TCP_SOCKET_ERR, ret);
556 };
557
558 /*
559 * @tc.name: testConnSetTcpUserTimeOut001
560 * @tc.desc: Test ConnSetTcpUserTimeOut param is invalid
561 * @tc.in: test module, test number,test levels.
562 * @tc.out: Zero
563 * @tc.type: FUNC
564 * @tc.require: The ThreadPoolDestroy operates normally.
565 */
566 HWTEST_F(SoftbusConnCommonTest, testConnSetTcpUserTimeOut001, TestSize.Level1)
567 {
568 int32_t fd = -1;
569 uint32_t millSec= 1;
570 int ret = ConnSetTcpUserTimeOut(fd, millSec);
571 EXPECT_NE(SOFTBUS_OK, ret);
572 }
573
574 /*
575 * @tc.name: testConnSetTcpUserTimeOut002
576 * @tc.desc: Test ConnSetTcpUserTimeOut param is invalid
577 * @tc.in: test module, test number,test levels.
578 * @tc.out: Zero
579 * @tc.type: FUNC
580 * @tc.require: The ThreadPoolDestroy operates normally.
581 */
582 HWTEST_F(SoftbusConnCommonTest, testConnSetTcpUserTimeOut002, TestSize.Level1)
583 {
584 int32_t fd = 1;
585 uint32_t millSec= 321;
586 int ret = ConnSetTcpUserTimeOut(fd, millSec);
587 EXPECT_NE(SOFTBUS_OK, ret);
588 }
589
590 /*
591 * @tc.name: testSocket003
592 * @tc.desc: test ConnGetPeerSocketAddr param is invalid
593 * @tc.type: FUNC
594 * @tc.require:
595 */
596 HWTEST_F(SoftbusConnCommonTest, testSocket003, TestSize.Level1)
597 {
598 int ret;
599 SocketAddr socketAddr;
600 ret = ConnGetPeerSocketAddr(INVALID_FD, &socketAddr);
601 EXPECT_NE(SOFTBUS_OK, ret);
602 }
603
604 /*
605 * @tc.name: testSocket004
606 * @tc.desc: test ConnGetLocalSocketPort port
607 * @tc.type: FUNC
608 * @tc.require:
609 */
610 HWTEST_F(SoftbusConnCommonTest, testSocket004, TestSize.Level1)
611 {
612 int ret;
613 ret = ConnGetLocalSocketPort(INVALID_FD);
614 EXPECT_NE(SOFTBUS_OK, ret);
615 }
616 }
617