1060ff233Sopenharmony_ci/*
2060ff233Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License.
5060ff233Sopenharmony_ci * You may obtain a copy of the License at
6060ff233Sopenharmony_ci *
7060ff233Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8060ff233Sopenharmony_ci *
9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and
13060ff233Sopenharmony_ci * limitations under the License.
14060ff233Sopenharmony_ci */
15060ff233Sopenharmony_ci
16060ff233Sopenharmony_ci#include <unistd.h>
17060ff233Sopenharmony_ci#include <securec.h>
18060ff233Sopenharmony_ci#include <fcntl.h>
19060ff233Sopenharmony_ci#include "gtest/gtest.h"
20060ff233Sopenharmony_ci#include "softbus_adapter_socket.h"
21060ff233Sopenharmony_ci#include "softbus_adapter_errcode.h"
22060ff233Sopenharmony_ci#include "softbus_errcode.h"
23060ff233Sopenharmony_ci
24060ff233Sopenharmony_ciusing namespace std;
25060ff233Sopenharmony_ciusing namespace testing::ext;
26060ff233Sopenharmony_ci
27060ff233Sopenharmony_cinamespace OHOS {
28060ff233Sopenharmony_ciconst int32_t PROTOCOL_MAXLEN = 100;
29060ff233Sopenharmony_ciconst int32_t TEST_BUF_SIZE = 10;
30060ff233Sopenharmony_ciconst int32_t TEST_PORT = 8888;
31060ff233Sopenharmony_ciconst int32_t TEST_IPV6_PORT = 8089;
32060ff233Sopenharmony_ciconst int32_t LOCAL_HOST_VALUE = 16777343;
33060ff233Sopenharmony_ciconst int32_t CMD_EXIT = 0x11001100;
34060ff233Sopenharmony_ciconst int32_t CMD_RECV = 0x22002200;
35060ff233Sopenharmony_ciconst int32_t CMD_REPLY = 0x33003300;
36060ff233Sopenharmony_ciconst int32_t SET_SIZE = 100;
37060ff233Sopenharmony_ciconst int32_t WLAN_INDEX = 4;
38060ff233Sopenharmony_ci
39060ff233Sopenharmony_ciSoftBusSockAddrIn g_serAddr = {
40060ff233Sopenharmony_ci    .sinFamily = SOFTBUS_AF_INET,
41060ff233Sopenharmony_ci    .sinPort = SoftBusHtoNs(TEST_PORT),
42060ff233Sopenharmony_ci    .sinAddr = {
43060ff233Sopenharmony_ci        .sAddr = SoftBusInetAddr("127.0.0.1")
44060ff233Sopenharmony_ci    }
45060ff233Sopenharmony_ci};
46060ff233Sopenharmony_ci
47060ff233Sopenharmony_cistruct SocketProtocol {
48060ff233Sopenharmony_ci    unsigned int cmd;
49060ff233Sopenharmony_ci    char data[PROTOCOL_MAXLEN];
50060ff233Sopenharmony_ci};
51060ff233Sopenharmony_ci
52060ff233Sopenharmony_ciclass AdapterDsoftbusSocketTest : public testing::Test {
53060ff233Sopenharmony_ciprotected:
54060ff233Sopenharmony_ci    static void SetUpTestCase(void);
55060ff233Sopenharmony_ci    static void TearDownTestCase(void);
56060ff233Sopenharmony_ci    void SetUp();
57060ff233Sopenharmony_ci    void TearDown();
58060ff233Sopenharmony_ci};
59060ff233Sopenharmony_ci
60060ff233Sopenharmony_civoid AdapterDsoftbusSocketTest::SetUpTestCase(void)
61060ff233Sopenharmony_ci{
62060ff233Sopenharmony_ci}
63060ff233Sopenharmony_ci
64060ff233Sopenharmony_civoid AdapterDsoftbusSocketTest::TearDownTestCase(void)
65060ff233Sopenharmony_ci{
66060ff233Sopenharmony_ci}
67060ff233Sopenharmony_ci
68060ff233Sopenharmony_civoid AdapterDsoftbusSocketTest::SetUp()
69060ff233Sopenharmony_ci{
70060ff233Sopenharmony_ci}
71060ff233Sopenharmony_ci
72060ff233Sopenharmony_civoid AdapterDsoftbusSocketTest::TearDown()
73060ff233Sopenharmony_ci{
74060ff233Sopenharmony_ci}
75060ff233Sopenharmony_ci
76060ff233Sopenharmony_cistatic void SocketServiceStart(int32_t localFlag)
77060ff233Sopenharmony_ci{
78060ff233Sopenharmony_ci    int32_t socketFd = -1;
79060ff233Sopenharmony_ci    int32_t optVal = 1;
80060ff233Sopenharmony_ci    int32_t backLog = 2;
81060ff233Sopenharmony_ci    SoftBusSockAddrIn cliAddr = {0};
82060ff233Sopenharmony_ci    int32_t acceptFd = -1;
83060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
84060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
85060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
86060ff233Sopenharmony_ci
87060ff233Sopenharmony_ci    ret = SoftBusSocketSetOpt(socketFd, SOFTBUS_SOL_SOCKET, SOFTBUS_SO_REUSEADDR, &optVal, sizeof(optVal));
88060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
89060ff233Sopenharmony_ci
90060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, (SoftBusSockAddr *)&g_serAddr, sizeof(SoftBusSockAddrIn));
91060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
92060ff233Sopenharmony_ci
93060ff233Sopenharmony_ci    ret = SoftBusSocketListen(socketFd, backLog);
94060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
95060ff233Sopenharmony_ci    ret = SoftBusSocketAccept(socketFd, (SoftBusSockAddr *)&cliAddr, &acceptFd);
96060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
97060ff233Sopenharmony_ci
98060ff233Sopenharmony_ci    if (localFlag) {
99060ff233Sopenharmony_ci        char serviceIP[20];
100060ff233Sopenharmony_ci        SoftBusSockAddrIn serviceAddr;
101060ff233Sopenharmony_ci        SoftBusSocketGetLocalName(acceptFd, (SoftBusSockAddr *)&serviceAddr);
102060ff233Sopenharmony_ci        SoftBusInetNtoP(SOFTBUS_AF_INET, &serviceAddr.sinAddr, serviceIP, sizeof(serviceIP));
103060ff233Sopenharmony_ci        uint16_t port = SoftBusNtoHs(serviceAddr.sinPort);
104060ff233Sopenharmony_ci        EXPECT_EQ(port, TEST_PORT);
105060ff233Sopenharmony_ci    }
106060ff233Sopenharmony_ci
107060ff233Sopenharmony_ci    while (1) {
108060ff233Sopenharmony_ci        (void)memset_s(&buf, sizeof(struct SocketProtocol), 0, sizeof(struct SocketProtocol));
109060ff233Sopenharmony_ci        ret = SoftBusSocketRecv(acceptFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
110060ff233Sopenharmony_ci        EXPECT_TRUE(ret != -1);
111060ff233Sopenharmony_ci        if (buf.cmd == CMD_EXIT) {
112060ff233Sopenharmony_ci            break;
113060ff233Sopenharmony_ci        } else if (buf.cmd == CMD_RECV) {
114060ff233Sopenharmony_ci            (void)memset_s(&buf, sizeof(struct SocketProtocol), 0, sizeof(struct SocketProtocol));
115060ff233Sopenharmony_ci            buf.cmd = CMD_REPLY;
116060ff233Sopenharmony_ci            (void)strcpy_s(buf.data, sizeof(buf.data), "Beautiful World!");
117060ff233Sopenharmony_ci            ret = SoftBusSocketSend(acceptFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
118060ff233Sopenharmony_ci            EXPECT_TRUE(ret != -1);
119060ff233Sopenharmony_ci        } else {
120060ff233Sopenharmony_ci            printf("unknown cmd\n");
121060ff233Sopenharmony_ci        }
122060ff233Sopenharmony_ci    }
123060ff233Sopenharmony_ci
124060ff233Sopenharmony_ci    ret = SoftBusSocketClose(acceptFd);
125060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
126060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
127060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
128060ff233Sopenharmony_ci    printf("socket service will exit\n");
129060ff233Sopenharmony_ci    _exit(0);
130060ff233Sopenharmony_ci}
131060ff233Sopenharmony_ci
132060ff233Sopenharmony_cistatic void SocketIpv6ServiceStart(int localFlag)
133060ff233Sopenharmony_ci{
134060ff233Sopenharmony_ci    int32_t socketFd = -1;
135060ff233Sopenharmony_ci    int32_t optVal = 1;
136060ff233Sopenharmony_ci    int32_t backLog = 2;
137060ff233Sopenharmony_ci    SoftBusSockAddrIn cliAddr = {0};
138060ff233Sopenharmony_ci    int32_t acceptFd = -1;
139060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
140060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET6, SOFTBUS_SOCK_STREAM, 0, &socketFd);
141060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
142060ff233Sopenharmony_ci
143060ff233Sopenharmony_ci    ret = SoftBusSocketSetOpt(socketFd, SOFTBUS_SOL_SOCKET, SOFTBUS_SO_REUSEADDR, &optVal, sizeof(optVal));
144060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
145060ff233Sopenharmony_ci    SoftBusSockAddrIn6 addrIn6 = {0};
146060ff233Sopenharmony_ci    addrIn6.sin6Family = SOFTBUS_AF_INET6;
147060ff233Sopenharmony_ci    addrIn6.sin6Port = SoftBusHtoNs(TEST_IPV6_PORT);
148060ff233Sopenharmony_ci    const char *srcAddr = "::1";
149060ff233Sopenharmony_ci    SoftBusInetPtoN(SOFTBUS_AF_INET6, srcAddr, &addrIn6.sin6Addr);
150060ff233Sopenharmony_ci    addrIn6.sin6ScopeId = SoftBusIfNameToIndex("lo");
151060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, (SoftBusSockAddr *)&addrIn6, sizeof(SoftBusSockAddrIn6));
152060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
153060ff233Sopenharmony_ci
154060ff233Sopenharmony_ci    ret = SoftBusSocketListen(socketFd, backLog);
155060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
156060ff233Sopenharmony_ci    ret = SoftBusSocketAccept(socketFd, (SoftBusSockAddr *)&cliAddr, &acceptFd);
157060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
158060ff233Sopenharmony_ci
159060ff233Sopenharmony_ci    if (localFlag) {
160060ff233Sopenharmony_ci        char serviceIP[46];
161060ff233Sopenharmony_ci        SoftBusSockAddrIn6 serviceAddr6 = {0};
162060ff233Sopenharmony_ci        SoftBusSocketGetLocalName(acceptFd, (SoftBusSockAddr *)&serviceAddr6);
163060ff233Sopenharmony_ci        SoftBusInetNtoP(SOFTBUS_AF_INET6, &serviceAddr6.sin6Addr, serviceIP, sizeof(serviceIP));
164060ff233Sopenharmony_ci        uint16_t port = SoftBusNtoHs(serviceAddr6.sin6Port);
165060ff233Sopenharmony_ci        EXPECT_EQ(port, TEST_IPV6_PORT);
166060ff233Sopenharmony_ci    }
167060ff233Sopenharmony_ci
168060ff233Sopenharmony_ci    while (1) {
169060ff233Sopenharmony_ci        (void)memset_s(&buf, sizeof(struct SocketProtocol), 0, sizeof(struct SocketProtocol));
170060ff233Sopenharmony_ci        ret = SoftBusSocketRecv(acceptFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
171060ff233Sopenharmony_ci        EXPECT_TRUE(ret != -1);
172060ff233Sopenharmony_ci        if (buf.cmd == CMD_EXIT) {
173060ff233Sopenharmony_ci            break;
174060ff233Sopenharmony_ci        } else if (buf.cmd == CMD_RECV) {
175060ff233Sopenharmony_ci            (void)memset_s(&buf, sizeof(struct SocketProtocol), 0, sizeof(struct SocketProtocol));
176060ff233Sopenharmony_ci            buf.cmd = CMD_REPLY;
177060ff233Sopenharmony_ci            (void)strcpy_s(buf.data, sizeof(buf.data), "Beautiful World!");
178060ff233Sopenharmony_ci            ret = SoftBusSocketSend(acceptFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
179060ff233Sopenharmony_ci            EXPECT_TRUE(ret != -1);
180060ff233Sopenharmony_ci        } else {
181060ff233Sopenharmony_ci            printf("unknown cmd\n");
182060ff233Sopenharmony_ci        }
183060ff233Sopenharmony_ci    }
184060ff233Sopenharmony_ci
185060ff233Sopenharmony_ci    ret = SoftBusSocketClose(acceptFd);
186060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
187060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
188060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
189060ff233Sopenharmony_ci    printf("socket ipv6 service will exit\n");
190060ff233Sopenharmony_ci    _exit(0);
191060ff233Sopenharmony_ci}
192060ff233Sopenharmony_ci
193060ff233Sopenharmony_cistatic void ClientConnect(int32_t *socketFd)
194060ff233Sopenharmony_ci{
195060ff233Sopenharmony_ci    EXPECT_TRUE(socketFd != nullptr);
196060ff233Sopenharmony_ci    SoftBusSockAddrIn serAddr = {
197060ff233Sopenharmony_ci        .sinFamily = SOFTBUS_AF_INET,
198060ff233Sopenharmony_ci        .sinPort = SoftBusHtoNs(8888),
199060ff233Sopenharmony_ci        .sinAddr = {
200060ff233Sopenharmony_ci            .sAddr = SoftBusInetAddr("127.0.0.1")
201060ff233Sopenharmony_ci        }
202060ff233Sopenharmony_ci    };
203060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, socketFd);
204060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
205060ff233Sopenharmony_ci    ret = SoftBusSocketConnect(*socketFd, (SoftBusSockAddr *)&serAddr, sizeof(SoftBusSockAddrIn));
206060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
207060ff233Sopenharmony_ci}
208060ff233Sopenharmony_ci
209060ff233Sopenharmony_cistatic void ClientIpv6Connect(int32_t *socketFd)
210060ff233Sopenharmony_ci{
211060ff233Sopenharmony_ci    EXPECT_TRUE(socketFd != nullptr);
212060ff233Sopenharmony_ci    SoftBusSockAddrIn6 addrIn6 = {0};
213060ff233Sopenharmony_ci    addrIn6.sin6Family = SOFTBUS_AF_INET6;
214060ff233Sopenharmony_ci    addrIn6.sin6Port = SoftBusHtoNs(TEST_IPV6_PORT);
215060ff233Sopenharmony_ci    const char *srcAddr = "::1";
216060ff233Sopenharmony_ci    SoftBusInetPtoN(SOFTBUS_AF_INET6, srcAddr, &addrIn6.sin6Addr);
217060ff233Sopenharmony_ci    addrIn6.sin6ScopeId = SoftBusIfNameToIndex("lo");
218060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET6, SOFTBUS_SOCK_STREAM, 0, socketFd);
219060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
220060ff233Sopenharmony_ci    ret = SoftBusSocketConnect(*socketFd, (SoftBusSockAddr *)&addrIn6, sizeof(SoftBusSockAddrIn6));
221060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
222060ff233Sopenharmony_ci}
223060ff233Sopenharmony_ci
224060ff233Sopenharmony_cistatic void ClientExit(int32_t socketFd)
225060ff233Sopenharmony_ci{
226060ff233Sopenharmony_ci    struct SocketProtocol buf = {
227060ff233Sopenharmony_ci        .cmd = CMD_EXIT,
228060ff233Sopenharmony_ci    };
229060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSend(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
230060ff233Sopenharmony_ci    EXPECT_TRUE(ret != -1);
231060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
232060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
233060ff233Sopenharmony_ci    sleep(1);
234060ff233Sopenharmony_ci}
235060ff233Sopenharmony_ci
236060ff233Sopenharmony_ci/*
237060ff233Sopenharmony_ci* @tc.name: SoftBusSocketCreate001
238060ff233Sopenharmony_ci* @tc.desc: Create Socket Success
239060ff233Sopenharmony_ci* @tc.type: FUNC
240060ff233Sopenharmony_ci* @tc.require:
241060ff233Sopenharmony_ci*/
242060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketCreate001, TestSize.Level0)
243060ff233Sopenharmony_ci{
244060ff233Sopenharmony_ci    int32_t socketFd = -1;
245060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
246060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
247060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
248060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
249060ff233Sopenharmony_ci
250060ff233Sopenharmony_ci    ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM | SOFTBUS_SOCK_NONBLOCK |
251060ff233Sopenharmony_ci        SOFTBUS_SOCK_CLOEXEC, 0, &socketFd);
252060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
253060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
254060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
255060ff233Sopenharmony_ci}
256060ff233Sopenharmony_ci
257060ff233Sopenharmony_ci/*
258060ff233Sopenharmony_ci* @tc.name: SoftBusSocketCreate002
259060ff233Sopenharmony_ci* @tc.desc: Error Domain
260060ff233Sopenharmony_ci* @tc.type: FUNC
261060ff233Sopenharmony_ci* @tc.require:
262060ff233Sopenharmony_ci*/
263060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketCreate002, TestSize.Level0)
264060ff233Sopenharmony_ci{
265060ff233Sopenharmony_ci    int32_t socketFd = -1;
266060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(-1, SOFTBUS_SOCK_STREAM, 0, &socketFd);
267060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
268060ff233Sopenharmony_ci}
269060ff233Sopenharmony_ci
270060ff233Sopenharmony_ci/*
271060ff233Sopenharmony_ci* @tc.name: SoftBusSocketCreate003
272060ff233Sopenharmony_ci* @tc.desc: Error type
273060ff233Sopenharmony_ci* @tc.type: FUNC
274060ff233Sopenharmony_ci* @tc.require:
275060ff233Sopenharmony_ci*/
276060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketCreate003, TestSize.Level0)
277060ff233Sopenharmony_ci{
278060ff233Sopenharmony_ci    int32_t socketFd = -1;
279060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, 0, 0, &socketFd);
280060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
281060ff233Sopenharmony_ci    ret = SoftBusSocketCreate(SOFTBUS_AF_INET, 0xFFFFFFFF, 0, &socketFd);
282060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
283060ff233Sopenharmony_ci}
284060ff233Sopenharmony_ci
285060ff233Sopenharmony_ci/*
286060ff233Sopenharmony_ci* @tc.name: SoftBusSocketCreate004
287060ff233Sopenharmony_ci* @tc.desc: Error protocol
288060ff233Sopenharmony_ci* @tc.type: FUNC
289060ff233Sopenharmony_ci* @tc.require:
290060ff233Sopenharmony_ci*/
291060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketCreate004, TestSize.Level0)
292060ff233Sopenharmony_ci{
293060ff233Sopenharmony_ci    int32_t socketFd = -1;
294060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, 0, -1, &socketFd);
295060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
296060ff233Sopenharmony_ci}
297060ff233Sopenharmony_ci
298060ff233Sopenharmony_ci/*
299060ff233Sopenharmony_ci* @tc.name: SoftBusSocketCreate005
300060ff233Sopenharmony_ci* @tc.desc: Error socketFd
301060ff233Sopenharmony_ci* @tc.type: FUNC
302060ff233Sopenharmony_ci* @tc.require:
303060ff233Sopenharmony_ci*/
304060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketCreate005, TestSize.Level0)
305060ff233Sopenharmony_ci{
306060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, NULL);
307060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_INVALID_PARAM, ret);
308060ff233Sopenharmony_ci}
309060ff233Sopenharmony_ci
310060ff233Sopenharmony_ci/*
311060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSetOptTest001
312060ff233Sopenharmony_ci* @tc.desc: opt set success
313060ff233Sopenharmony_ci* @tc.type: FUNC
314060ff233Sopenharmony_ci* @tc.require: 1
315060ff233Sopenharmony_ci*/
316060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSetOptTest001, TestSize.Level0)
317060ff233Sopenharmony_ci{
318060ff233Sopenharmony_ci    int32_t socketFd = -1;
319060ff233Sopenharmony_ci    int32_t optVal = 1;
320060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
321060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
322060ff233Sopenharmony_ci
323060ff233Sopenharmony_ci    SoftBusSocketSetOpt(socketFd, SOFTBUS_SOL_SOCKET, SOFTBUS_SO_REUSEADDR, &optVal, sizeof(optVal));
324060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
325060ff233Sopenharmony_ci
326060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
327060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
328060ff233Sopenharmony_ci}
329060ff233Sopenharmony_ci
330060ff233Sopenharmony_ci/*
331060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSetOptTest002
332060ff233Sopenharmony_ci* @tc.desc: select SOFTBUS_IPPROTO_IP Protocol
333060ff233Sopenharmony_ci* @tc.type: FUNC
334060ff233Sopenharmony_ci* @tc.require: 1
335060ff233Sopenharmony_ci*/
336060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSetOptTest002, TestSize.Level0)
337060ff233Sopenharmony_ci{
338060ff233Sopenharmony_ci    int32_t socketFd;
339060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
340060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
341060ff233Sopenharmony_ci    int32_t optVal = 1;
342060ff233Sopenharmony_ci    int32_t optValLen = sizeof(int);
343060ff233Sopenharmony_ci    ret = SoftBusSocketSetOpt(socketFd, SOFTBUS_IPPROTO_IP, SOFTBUS_IP_TOS, &optVal, optValLen);
344060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
345060ff233Sopenharmony_ci
346060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
347060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
348060ff233Sopenharmony_ci}
349060ff233Sopenharmony_ci
350060ff233Sopenharmony_ci/*
351060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSetOptTest003
352060ff233Sopenharmony_ci* @tc.desc: select SOFTBUS_SO_KEEPALIVE Protocol
353060ff233Sopenharmony_ci* @tc.type: FUNC
354060ff233Sopenharmony_ci* @tc.require: 1
355060ff233Sopenharmony_ci*/
356060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSetOptTest003, TestSize.Level0)
357060ff233Sopenharmony_ci{
358060ff233Sopenharmony_ci    int32_t socketFd;
359060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
360060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
361060ff233Sopenharmony_ci
362060ff233Sopenharmony_ci    int32_t optVal = 1;
363060ff233Sopenharmony_ci    int32_t optValLen = sizeof(int);
364060ff233Sopenharmony_ci    ret = SoftBusSocketSetOpt(socketFd, SOFTBUS_SOL_SOCKET, SOFTBUS_SO_KEEPALIVE, &optVal, optValLen);
365060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
366060ff233Sopenharmony_ci
367060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
368060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
369060ff233Sopenharmony_ci}
370060ff233Sopenharmony_ci
371060ff233Sopenharmony_ci/*
372060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSetOptTest004
373060ff233Sopenharmony_ci* @tc.desc: socketFd illegal
374060ff233Sopenharmony_ci* @tc.type: FUNC
375060ff233Sopenharmony_ci* @tc.require: 1
376060ff233Sopenharmony_ci*/
377060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSetOptTest004, TestSize.Level0)
378060ff233Sopenharmony_ci{
379060ff233Sopenharmony_ci    int32_t optVal = 1;
380060ff233Sopenharmony_ci    int32_t optValLen = sizeof(int);
381060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSetOpt(-1, SOFTBUS_SOL_SOCKET, SOFTBUS_SO_REUSEADDR, &optVal, optValLen);
382060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
383060ff233Sopenharmony_ci}
384060ff233Sopenharmony_ci
385060ff233Sopenharmony_ci/*
386060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSetOptTest005
387060ff233Sopenharmony_ci* @tc.desc: Protocol is illegal
388060ff233Sopenharmony_ci* @tc.type: FUNC
389060ff233Sopenharmony_ci* @tc.require: 1
390060ff233Sopenharmony_ci*/
391060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSetOptTest005, TestSize.Level0)
392060ff233Sopenharmony_ci{
393060ff233Sopenharmony_ci    int32_t socketFd;
394060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
395060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
396060ff233Sopenharmony_ci    int32_t optVal = 10;
397060ff233Sopenharmony_ci    int32_t optValLen = sizeof(int);
398060ff233Sopenharmony_ci    ret = SoftBusSocketSetOpt(socketFd, SOFTBUS_IPPROTO_IP, -1, &optVal, optValLen);
399060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
400060ff233Sopenharmony_ci
401060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
402060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
403060ff233Sopenharmony_ci}
404060ff233Sopenharmony_ci
405060ff233Sopenharmony_ci/*
406060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSetOptTest006
407060ff233Sopenharmony_ci* @tc.desc: optVal is illegal
408060ff233Sopenharmony_ci* @tc.type: FUNC
409060ff233Sopenharmony_ci* @tc.require: 1
410060ff233Sopenharmony_ci*/
411060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSetOptTest006, TestSize.Level0)
412060ff233Sopenharmony_ci{
413060ff233Sopenharmony_ci    int32_t socketFd;
414060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
415060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
416060ff233Sopenharmony_ci    int32_t optValLen = sizeof(int);
417060ff233Sopenharmony_ci    ret = SoftBusSocketSetOpt(socketFd, SOFTBUS_IPPROTO_IP, SOFTBUS_IP_TOS, NULL, optValLen);
418060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
419060ff233Sopenharmony_ci
420060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
421060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
422060ff233Sopenharmony_ci}
423060ff233Sopenharmony_ci
424060ff233Sopenharmony_ci#if HAVE_PRO
425060ff233Sopenharmony_ci/*
426060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSetOptTest007
427060ff233Sopenharmony_ci* @tc.desc: optValLen is illegal
428060ff233Sopenharmony_ci* @tc.type: FUNC
429060ff233Sopenharmony_ci* @tc.require: 1
430060ff233Sopenharmony_ci*/
431060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSetOptTest007, TestSize.Level0)
432060ff233Sopenharmony_ci{
433060ff233Sopenharmony_ci    int32_t socketFd;
434060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
435060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
436060ff233Sopenharmony_ci    int32_t optVal = 1;
437060ff233Sopenharmony_ci    ret = SoftBusSocketSetOpt(socketFd, SOFTBUS_IPPROTO_IP, SOFTBUS_IP_TOS, &optVal, -1);
438060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
439060ff233Sopenharmony_ci
440060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
441060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
442060ff233Sopenharmony_ci}
443060ff233Sopenharmony_ci#endif
444060ff233Sopenharmony_ci
445060ff233Sopenharmony_ci/*
446060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetOptTest001
447060ff233Sopenharmony_ci* @tc.desc: positive
448060ff233Sopenharmony_ci* @tc.type: FUNC
449060ff233Sopenharmony_ci* @tc.require: 1
450060ff233Sopenharmony_ci*/
451060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetOptTest001, TestSize.Level0)
452060ff233Sopenharmony_ci{
453060ff233Sopenharmony_ci    int32_t socketFd;
454060ff233Sopenharmony_ci    int32_t on = 1;
455060ff233Sopenharmony_ci    int32_t onLen = sizeof(on);
456060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
457060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
458060ff233Sopenharmony_ci    ret = SoftBusSocketGetOpt(socketFd, SOFTBUS_SOL_SOCKET, SOFTBUS_SO_REUSEADDR, &on, &onLen);
459060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
460060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
461060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
462060ff233Sopenharmony_ci}
463060ff233Sopenharmony_ci
464060ff233Sopenharmony_ci/*
465060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetOptTest002
466060ff233Sopenharmony_ci* @tc.desc: socketFd illegal
467060ff233Sopenharmony_ci* @tc.type: FUNC
468060ff233Sopenharmony_ci* @tc.require: 1
469060ff233Sopenharmony_ci*/
470060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetOptTest002, TestSize.Level0)
471060ff233Sopenharmony_ci{
472060ff233Sopenharmony_ci    int32_t on = 1;
473060ff233Sopenharmony_ci    int32_t onLen = sizeof(on);
474060ff233Sopenharmony_ci    int32_t rc = SoftBusSocketGetOpt(-1, SOFTBUS_SOL_SOCKET, SOFTBUS_SO_REUSEADDR, &on, &onLen);
475060ff233Sopenharmony_ci    EXPECT_TRUE(rc == -1);
476060ff233Sopenharmony_ci}
477060ff233Sopenharmony_ci
478060ff233Sopenharmony_ci/*
479060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetLocalNameTest001
480060ff233Sopenharmony_ci* @tc.desc: test in service get port
481060ff233Sopenharmony_ci* @tc.type: FUNC
482060ff233Sopenharmony_ci* @tc.require: 1
483060ff233Sopenharmony_ci*/
484060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetLocalNameTest001, TestSize.Level0)
485060ff233Sopenharmony_ci{
486060ff233Sopenharmony_ci    sleep(1);
487060ff233Sopenharmony_ci    int32_t pid = -1;
488060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
489060ff233Sopenharmony_ci        SocketServiceStart(1);
490060ff233Sopenharmony_ci        return;
491060ff233Sopenharmony_ci    }
492060ff233Sopenharmony_ci    sleep(1);
493060ff233Sopenharmony_ci    int32_t socketFd = -1;
494060ff233Sopenharmony_ci
495060ff233Sopenharmony_ci    ClientConnect(&socketFd);
496060ff233Sopenharmony_ci
497060ff233Sopenharmony_ci    ClientExit(socketFd);
498060ff233Sopenharmony_ci    return;
499060ff233Sopenharmony_ci}
500060ff233Sopenharmony_ci
501060ff233Sopenharmony_ci/*
502060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetLocalNameTest002
503060ff233Sopenharmony_ci* @tc.desc: socketFd illegal
504060ff233Sopenharmony_ci* @tc.type: FUNC
505060ff233Sopenharmony_ci* @tc.require: 1
506060ff233Sopenharmony_ci*/
507060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetLocalNameTest002, TestSize.Level0)
508060ff233Sopenharmony_ci{
509060ff233Sopenharmony_ci    int32_t socketFd = -1;
510060ff233Sopenharmony_ci    SoftBusSockAddrIn clientAddr;
511060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketGetLocalName(socketFd, (SoftBusSockAddr *)&clientAddr);
512060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
513060ff233Sopenharmony_ci}
514060ff233Sopenharmony_ci
515060ff233Sopenharmony_ci/*
516060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetLocalNameTest003
517060ff233Sopenharmony_ci* @tc.desc: addr is null
518060ff233Sopenharmony_ci* @tc.type: FUNC
519060ff233Sopenharmony_ci* @tc.require: 1
520060ff233Sopenharmony_ci*/
521060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetLocalNameTest003, TestSize.Level0)
522060ff233Sopenharmony_ci{
523060ff233Sopenharmony_ci    sleep(1);
524060ff233Sopenharmony_ci    int32_t pid = -1;
525060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
526060ff233Sopenharmony_ci        SocketServiceStart(0);
527060ff233Sopenharmony_ci        return;
528060ff233Sopenharmony_ci    }
529060ff233Sopenharmony_ci    sleep(1);
530060ff233Sopenharmony_ci    int32_t ret;
531060ff233Sopenharmony_ci    int32_t socketFd = -1;
532060ff233Sopenharmony_ci
533060ff233Sopenharmony_ci    ClientConnect(&socketFd);
534060ff233Sopenharmony_ci
535060ff233Sopenharmony_ci    ret = SoftBusSocketGetLocalName(socketFd, NULL);
536060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
537060ff233Sopenharmony_ci
538060ff233Sopenharmony_ci    ClientExit(socketFd);
539060ff233Sopenharmony_ci}
540060ff233Sopenharmony_ci
541060ff233Sopenharmony_ci/*
542060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetLocalNameTest004
543060ff233Sopenharmony_ci* @tc.desc: addrLen is null
544060ff233Sopenharmony_ci* @tc.type: FUNC
545060ff233Sopenharmony_ci* @tc.require: 1
546060ff233Sopenharmony_ci*/
547060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetLocalNameTest004, TestSize.Level0)
548060ff233Sopenharmony_ci{
549060ff233Sopenharmony_ci    sleep(1);
550060ff233Sopenharmony_ci    int32_t pid = -1;
551060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
552060ff233Sopenharmony_ci        SocketServiceStart(0);
553060ff233Sopenharmony_ci        return;
554060ff233Sopenharmony_ci    }
555060ff233Sopenharmony_ci    sleep(1);
556060ff233Sopenharmony_ci    int32_t ret;
557060ff233Sopenharmony_ci    int32_t socketFd = -1;
558060ff233Sopenharmony_ci
559060ff233Sopenharmony_ci    ClientConnect(&socketFd);
560060ff233Sopenharmony_ci
561060ff233Sopenharmony_ci    SoftBusSockAddrIn clientAddr;
562060ff233Sopenharmony_ci    ret = SoftBusSocketGetLocalName(socketFd, (SoftBusSockAddr *)&clientAddr);
563060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
564060ff233Sopenharmony_ci
565060ff233Sopenharmony_ci    ClientExit(socketFd);
566060ff233Sopenharmony_ci}
567060ff233Sopenharmony_ci
568060ff233Sopenharmony_ci/*
569060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetLocalNameTest005
570060ff233Sopenharmony_ci* @tc.desc: socketFd is service fd
571060ff233Sopenharmony_ci* @tc.type: FUNC
572060ff233Sopenharmony_ci* @tc.require: 1
573060ff233Sopenharmony_ci*/
574060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetLocalNameTest005, TestSize.Level0)
575060ff233Sopenharmony_ci{
576060ff233Sopenharmony_ci    int32_t socketFd;
577060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
578060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
579060ff233Sopenharmony_ci    SoftBusSockAddrIn clientAddr;
580060ff233Sopenharmony_ci    ret = SoftBusSocketGetLocalName(socketFd, (SoftBusSockAddr *)&clientAddr);
581060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
582060ff233Sopenharmony_ci
583060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
584060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
585060ff233Sopenharmony_ci}
586060ff233Sopenharmony_ci
587060ff233Sopenharmony_ci/*
588060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetLocalNameTest006
589060ff233Sopenharmony_ci* @tc.desc: socketFd illegal
590060ff233Sopenharmony_ci* @tc.type: FUNC
591060ff233Sopenharmony_ci* @tc.require: 1
592060ff233Sopenharmony_ci*/
593060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetLocalNameTest006, TestSize.Level0)
594060ff233Sopenharmony_ci{
595060ff233Sopenharmony_ci    int32_t socketFd = -1;
596060ff233Sopenharmony_ci    SoftBusSockAddrIn6 clientAddr6 = {0};
597060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketGetLocalName(socketFd, (SoftBusSockAddr *)&clientAddr6);
598060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
599060ff233Sopenharmony_ci}
600060ff233Sopenharmony_ci
601060ff233Sopenharmony_ci/*
602060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetLocalNameTest007
603060ff233Sopenharmony_ci* @tc.desc: addrLen is null
604060ff233Sopenharmony_ci* @tc.type: FUNC
605060ff233Sopenharmony_ci* @tc.require: 1
606060ff233Sopenharmony_ci*/
607060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetLocalNameTest007, TestSize.Level0)
608060ff233Sopenharmony_ci{
609060ff233Sopenharmony_ci    sleep(1);
610060ff233Sopenharmony_ci    int32_t pid = -1;
611060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
612060ff233Sopenharmony_ci        SocketIpv6ServiceStart(0);
613060ff233Sopenharmony_ci        return;
614060ff233Sopenharmony_ci    }
615060ff233Sopenharmony_ci    sleep(1);
616060ff233Sopenharmony_ci    int32_t ret;
617060ff233Sopenharmony_ci    int32_t socketFd = -1;
618060ff233Sopenharmony_ci
619060ff233Sopenharmony_ci    ClientIpv6Connect(&socketFd);
620060ff233Sopenharmony_ci
621060ff233Sopenharmony_ci    SoftBusSockAddrIn6 clientAddr6 = {0};
622060ff233Sopenharmony_ci    ret = SoftBusSocketGetLocalName(socketFd, (SoftBusSockAddr *)&clientAddr6);
623060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
624060ff233Sopenharmony_ci
625060ff233Sopenharmony_ci    ClientExit(socketFd);
626060ff233Sopenharmony_ci}
627060ff233Sopenharmony_ci
628060ff233Sopenharmony_ci/*
629060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetPeerNameTest001
630060ff233Sopenharmony_ci* @tc.desc: get service port success
631060ff233Sopenharmony_ci* @tc.type: FUNC
632060ff233Sopenharmony_ci* @tc.require: 1
633060ff233Sopenharmony_ci*/
634060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetPeerNameTest001, TestSize.Level0)
635060ff233Sopenharmony_ci{
636060ff233Sopenharmony_ci    sleep(1);
637060ff233Sopenharmony_ci    int32_t pid = -1;
638060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
639060ff233Sopenharmony_ci        SocketServiceStart(0);
640060ff233Sopenharmony_ci        return;
641060ff233Sopenharmony_ci    }
642060ff233Sopenharmony_ci    sleep(1);
643060ff233Sopenharmony_ci    int32_t ret;
644060ff233Sopenharmony_ci    int32_t socketFd = -1;
645060ff233Sopenharmony_ci
646060ff233Sopenharmony_ci    ClientConnect(&socketFd);
647060ff233Sopenharmony_ci
648060ff233Sopenharmony_ci    char serviceIP[20];
649060ff233Sopenharmony_ci    SoftBusSockAddrIn serviceAddr;
650060ff233Sopenharmony_ci
651060ff233Sopenharmony_ci    ret = SoftBusSocketGetPeerName(socketFd, (SoftBusSockAddr *)&serviceAddr);
652060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
653060ff233Sopenharmony_ci    SoftBusInetNtoP(SOFTBUS_AF_INET, &serviceAddr.sinAddr, serviceIP, sizeof(serviceIP));
654060ff233Sopenharmony_ci    uint16_t port = SoftBusNtoHs(serviceAddr.sinPort);
655060ff233Sopenharmony_ci    EXPECT_EQ(TEST_PORT, port);
656060ff233Sopenharmony_ci
657060ff233Sopenharmony_ci    ClientExit(socketFd);
658060ff233Sopenharmony_ci}
659060ff233Sopenharmony_ci
660060ff233Sopenharmony_ci/*
661060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetPeerNameTest002
662060ff233Sopenharmony_ci* @tc.desc: socketFd illegal
663060ff233Sopenharmony_ci* @tc.type: FUNC
664060ff233Sopenharmony_ci* @tc.require: 1
665060ff233Sopenharmony_ci*/
666060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetPeerNameTest002, TestSize.Level0)
667060ff233Sopenharmony_ci{
668060ff233Sopenharmony_ci    SoftBusSockAddr addr;
669060ff233Sopenharmony_ci    int32_t rc = SoftBusSocketGetPeerName(-1, &addr);
670060ff233Sopenharmony_ci    EXPECT_TRUE(rc == -1);
671060ff233Sopenharmony_ci}
672060ff233Sopenharmony_ci
673060ff233Sopenharmony_ci/*
674060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetPeerNameTest003
675060ff233Sopenharmony_ci* @tc.desc: get service port success
676060ff233Sopenharmony_ci* @tc.type: FUNC
677060ff233Sopenharmony_ci* @tc.require: 1
678060ff233Sopenharmony_ci*/
679060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetPeerNameTest003, TestSize.Level0)
680060ff233Sopenharmony_ci{
681060ff233Sopenharmony_ci    sleep(1);
682060ff233Sopenharmony_ci    int32_t pid = -1;
683060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
684060ff233Sopenharmony_ci        SocketServiceStart(0);
685060ff233Sopenharmony_ci        return;
686060ff233Sopenharmony_ci    }
687060ff233Sopenharmony_ci    sleep(1);
688060ff233Sopenharmony_ci    int32_t ret;
689060ff233Sopenharmony_ci    int32_t socketFd = -1;
690060ff233Sopenharmony_ci
691060ff233Sopenharmony_ci    ClientConnect(&socketFd);
692060ff233Sopenharmony_ci
693060ff233Sopenharmony_ci    ret = SoftBusSocketGetPeerName(socketFd, NULL);
694060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
695060ff233Sopenharmony_ci
696060ff233Sopenharmony_ci    ClientExit(socketFd);
697060ff233Sopenharmony_ci}
698060ff233Sopenharmony_ci
699060ff233Sopenharmony_ci/*
700060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetPeerNameTest004
701060ff233Sopenharmony_ci* @tc.desc: get service port success
702060ff233Sopenharmony_ci* @tc.type: FUNC
703060ff233Sopenharmony_ci* @tc.require: 1
704060ff233Sopenharmony_ci*/
705060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetPeerNameTest004, TestSize.Level0)
706060ff233Sopenharmony_ci{
707060ff233Sopenharmony_ci    sleep(1);
708060ff233Sopenharmony_ci    int32_t pid = -1;
709060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
710060ff233Sopenharmony_ci        SocketServiceStart(0);
711060ff233Sopenharmony_ci        return;
712060ff233Sopenharmony_ci    }
713060ff233Sopenharmony_ci    sleep(1);
714060ff233Sopenharmony_ci    int32_t ret;
715060ff233Sopenharmony_ci    int32_t socketFd = -1;
716060ff233Sopenharmony_ci
717060ff233Sopenharmony_ci    ClientConnect(&socketFd);
718060ff233Sopenharmony_ci
719060ff233Sopenharmony_ci    SoftBusSockAddrIn serviceAddr;
720060ff233Sopenharmony_ci
721060ff233Sopenharmony_ci    ret = SoftBusSocketGetPeerName(socketFd, (SoftBusSockAddr *)&serviceAddr);
722060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
723060ff233Sopenharmony_ci
724060ff233Sopenharmony_ci    ClientExit(socketFd);
725060ff233Sopenharmony_ci}
726060ff233Sopenharmony_ci
727060ff233Sopenharmony_ci/*
728060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetPeerNameTest005
729060ff233Sopenharmony_ci* @tc.desc: socketFd is illegal
730060ff233Sopenharmony_ci* @tc.type: FUNC
731060ff233Sopenharmony_ci* @tc.require: 1
732060ff233Sopenharmony_ci*/
733060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetPeerNameTest005, TestSize.Level0)
734060ff233Sopenharmony_ci{
735060ff233Sopenharmony_ci    int32_t socketFd;
736060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
737060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
738060ff233Sopenharmony_ci    SoftBusSockAddrIn serviceAddr;
739060ff233Sopenharmony_ci    ret = SoftBusSocketGetPeerName(socketFd, (SoftBusSockAddr *)&serviceAddr);
740060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
741060ff233Sopenharmony_ci
742060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
743060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
744060ff233Sopenharmony_ci}
745060ff233Sopenharmony_ci
746060ff233Sopenharmony_ci/*
747060ff233Sopenharmony_ci* @tc.name: SoftBusSocketGetPeerNameTest006
748060ff233Sopenharmony_ci* @tc.desc: get service port success
749060ff233Sopenharmony_ci* @tc.type: FUNC
750060ff233Sopenharmony_ci* @tc.require: 1
751060ff233Sopenharmony_ci*/
752060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketGetPeerNameTest006, TestSize.Level0)
753060ff233Sopenharmony_ci{
754060ff233Sopenharmony_ci    sleep(1);
755060ff233Sopenharmony_ci    int32_t pid = -1;
756060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
757060ff233Sopenharmony_ci        SocketIpv6ServiceStart(0);
758060ff233Sopenharmony_ci        return;
759060ff233Sopenharmony_ci    }
760060ff233Sopenharmony_ci    sleep(1);
761060ff233Sopenharmony_ci    int32_t ret;
762060ff233Sopenharmony_ci    int32_t socketFd = -1;
763060ff233Sopenharmony_ci
764060ff233Sopenharmony_ci    ClientIpv6Connect(&socketFd);
765060ff233Sopenharmony_ci
766060ff233Sopenharmony_ci    char serviceIP[46];
767060ff233Sopenharmony_ci    SoftBusSockAddrIn6 serviceAddr6 {0};
768060ff233Sopenharmony_ci
769060ff233Sopenharmony_ci    ret = SoftBusSocketGetPeerName(socketFd, (SoftBusSockAddr *)&serviceAddr6);
770060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
771060ff233Sopenharmony_ci    SoftBusInetNtoP(SOFTBUS_AF_INET6, &serviceAddr6.sin6Addr, serviceIP, sizeof(serviceIP));
772060ff233Sopenharmony_ci    uint16_t port = SoftBusNtoHs(serviceAddr6.sin6Port);
773060ff233Sopenharmony_ci    EXPECT_EQ(TEST_IPV6_PORT, port);
774060ff233Sopenharmony_ci
775060ff233Sopenharmony_ci    ClientExit(socketFd);
776060ff233Sopenharmony_ci}
777060ff233Sopenharmony_ci
778060ff233Sopenharmony_ci/*
779060ff233Sopenharmony_ci* @tc.name: SoftBusSocketBind001
780060ff233Sopenharmony_ci* @tc.desc: Bind Socket Success
781060ff233Sopenharmony_ci* @tc.type: FUNC
782060ff233Sopenharmony_ci* @tc.require:
783060ff233Sopenharmony_ci*/
784060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketBind001, TestSize.Level0)
785060ff233Sopenharmony_ci{
786060ff233Sopenharmony_ci    int32_t socketFd = -1;
787060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
788060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
789060ff233Sopenharmony_ci    };
790060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
791060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
792060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, &addr, sizeof(SoftBusSockAddrIn));
793060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
794060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
795060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
796060ff233Sopenharmony_ci}
797060ff233Sopenharmony_ci
798060ff233Sopenharmony_ci/*
799060ff233Sopenharmony_ci* @tc.name: SoftBusSocketBind002
800060ff233Sopenharmony_ci* @tc.desc: addrLen is illegal
801060ff233Sopenharmony_ci* @tc.type: FUNC
802060ff233Sopenharmony_ci* @tc.require:
803060ff233Sopenharmony_ci*/
804060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketBind002, TestSize.Level0)
805060ff233Sopenharmony_ci{
806060ff233Sopenharmony_ci    int32_t socketFd = -1;
807060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
808060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
809060ff233Sopenharmony_ci    };
810060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
811060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
812060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, &addr, sizeof(SoftBusSockAddrIn) - 1);
813060ff233Sopenharmony_ci    EXPECT_NE(0, ret);
814060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
815060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
816060ff233Sopenharmony_ci}
817060ff233Sopenharmony_ci
818060ff233Sopenharmony_ci/*
819060ff233Sopenharmony_ci* @tc.name: SoftBusSocketBind003
820060ff233Sopenharmony_ci* @tc.desc: socketFd is illegal
821060ff233Sopenharmony_ci* @tc.type: FUNC
822060ff233Sopenharmony_ci* @tc.require:
823060ff233Sopenharmony_ci*/
824060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketBind003, TestSize.Level0)
825060ff233Sopenharmony_ci{
826060ff233Sopenharmony_ci    int32_t socketFd = -1;
827060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
828060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
829060ff233Sopenharmony_ci    };
830060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketBind(socketFd, &addr, sizeof(SoftBusSockAddrIn));
831060ff233Sopenharmony_ci    EXPECT_NE(0, ret);
832060ff233Sopenharmony_ci}
833060ff233Sopenharmony_ci
834060ff233Sopenharmony_ci/*
835060ff233Sopenharmony_ci* @tc.name: SoftBusSocketBind004
836060ff233Sopenharmony_ci* @tc.desc: addr is illegal
837060ff233Sopenharmony_ci* @tc.type: FUNC
838060ff233Sopenharmony_ci* @tc.require:
839060ff233Sopenharmony_ci*/
840060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketBind004, TestSize.Level0)
841060ff233Sopenharmony_ci{
842060ff233Sopenharmony_ci    int32_t socketFd = -1;
843060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
844060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
845060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, NULL, sizeof(SoftBusSockAddrIn));
846060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
847060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
848060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
849060ff233Sopenharmony_ci}
850060ff233Sopenharmony_ci
851060ff233Sopenharmony_ci/*
852060ff233Sopenharmony_ci* @tc.name: SoftBusSocketBind005
853060ff233Sopenharmony_ci* @tc.desc: Bind Socket Success
854060ff233Sopenharmony_ci* @tc.type: FUNC
855060ff233Sopenharmony_ci* @tc.require:
856060ff233Sopenharmony_ci*/
857060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketBind005, TestSize.Level0)
858060ff233Sopenharmony_ci{
859060ff233Sopenharmony_ci    int32_t socketFd = -1;
860060ff233Sopenharmony_ci    SoftBusSockAddrIn6 addrIn6 = {0};
861060ff233Sopenharmony_ci    addrIn6.sin6Family = SOFTBUS_AF_INET6;
862060ff233Sopenharmony_ci    addrIn6.sin6Port = SoftBusHtoNs(TEST_IPV6_PORT);
863060ff233Sopenharmony_ci    const char *srcAddr = "::1";
864060ff233Sopenharmony_ci    SoftBusInetPtoN(SOFTBUS_AF_INET6, srcAddr, &addrIn6.sin6Addr);
865060ff233Sopenharmony_ci    addrIn6.sin6ScopeId = SoftBusIfNameToIndex("lo");
866060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET6, SOFTBUS_SOCK_STREAM, 0, &socketFd);
867060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
868060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, (SoftBusSockAddr *)&addrIn6, sizeof(SoftBusSockAddrIn6));
869060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
870060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
871060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
872060ff233Sopenharmony_ci}
873060ff233Sopenharmony_ci
874060ff233Sopenharmony_ci/*
875060ff233Sopenharmony_ci* @tc.name: SoftBusSocketListen001
876060ff233Sopenharmony_ci* @tc.desc: Listen Socket Success
877060ff233Sopenharmony_ci* @tc.type: FUNC
878060ff233Sopenharmony_ci* @tc.require:
879060ff233Sopenharmony_ci*/
880060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketListen001, TestSize.Level0)
881060ff233Sopenharmony_ci{
882060ff233Sopenharmony_ci    int32_t socketFd = -1;
883060ff233Sopenharmony_ci    int32_t backLog = 2;
884060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
885060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
886060ff233Sopenharmony_ci    };
887060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
888060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
889060ff233Sopenharmony_ci
890060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, &addr, sizeof(SoftBusSockAddrIn));
891060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
892060ff233Sopenharmony_ci
893060ff233Sopenharmony_ci    ret = SoftBusSocketListen(socketFd, backLog);
894060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
895060ff233Sopenharmony_ci
896060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
897060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
898060ff233Sopenharmony_ci}
899060ff233Sopenharmony_ci
900060ff233Sopenharmony_ci/*
901060ff233Sopenharmony_ci* @tc.name: SoftBusSocketListen002
902060ff233Sopenharmony_ci* @tc.desc: backlog is illegal
903060ff233Sopenharmony_ci* @tc.type: FUNC
904060ff233Sopenharmony_ci* @tc.require:
905060ff233Sopenharmony_ci*/
906060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketListen002, TestSize.Level0)
907060ff233Sopenharmony_ci{
908060ff233Sopenharmony_ci    int32_t socketFd = -1;
909060ff233Sopenharmony_ci    int32_t backLog = -1;
910060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
911060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
912060ff233Sopenharmony_ci    };
913060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
914060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
915060ff233Sopenharmony_ci
916060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, &addr, sizeof(SoftBusSockAddrIn));
917060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
918060ff233Sopenharmony_ci
919060ff233Sopenharmony_ci    ret = SoftBusSocketListen(socketFd, backLog);
920060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
921060ff233Sopenharmony_ci
922060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
923060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
924060ff233Sopenharmony_ci}
925060ff233Sopenharmony_ci
926060ff233Sopenharmony_ci/*
927060ff233Sopenharmony_ci* @tc.name: SoftBusSocketListen003
928060ff233Sopenharmony_ci* @tc.desc: socketFd is illegal
929060ff233Sopenharmony_ci* @tc.type: FUNC
930060ff233Sopenharmony_ci* @tc.require:
931060ff233Sopenharmony_ci*/
932060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketListen003, TestSize.Level0)
933060ff233Sopenharmony_ci{
934060ff233Sopenharmony_ci    int32_t socketFd = -1;
935060ff233Sopenharmony_ci    int32_t backLog = 2;
936060ff233Sopenharmony_ci
937060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketListen(socketFd, backLog);
938060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
939060ff233Sopenharmony_ci}
940060ff233Sopenharmony_ci
941060ff233Sopenharmony_ci/*
942060ff233Sopenharmony_ci* @tc.name: SoftBusSocketListen004
943060ff233Sopenharmony_ci* @tc.desc: Listen Socket Success
944060ff233Sopenharmony_ci* @tc.type: FUNC
945060ff233Sopenharmony_ci* @tc.require:
946060ff233Sopenharmony_ci*/
947060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketListen004, TestSize.Level0)
948060ff233Sopenharmony_ci{
949060ff233Sopenharmony_ci    int32_t socketFd = -1;
950060ff233Sopenharmony_ci    int32_t backLog = 2;
951060ff233Sopenharmony_ci    SoftBusSockAddrIn6 addrIn6 = {0};
952060ff233Sopenharmony_ci    addrIn6.sin6Family = SOFTBUS_AF_INET6;
953060ff233Sopenharmony_ci    addrIn6.sin6Port = SoftBusHtoNs(TEST_IPV6_PORT);
954060ff233Sopenharmony_ci    const char *srcAddr = "::1";
955060ff233Sopenharmony_ci    SoftBusInetPtoN(SOFTBUS_AF_INET6, srcAddr, &addrIn6.sin6Addr);
956060ff233Sopenharmony_ci    addrIn6.sin6ScopeId = SoftBusIfNameToIndex("lo");
957060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET6, SOFTBUS_SOCK_STREAM, 0, &socketFd);
958060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
959060ff233Sopenharmony_ci
960060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, (SoftBusSockAddr *)&addrIn6, sizeof(SoftBusSockAddrIn6));
961060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
962060ff233Sopenharmony_ci
963060ff233Sopenharmony_ci    ret = SoftBusSocketListen(socketFd, backLog);
964060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
965060ff233Sopenharmony_ci
966060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
967060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
968060ff233Sopenharmony_ci}
969060ff233Sopenharmony_ci
970060ff233Sopenharmony_ci/*
971060ff233Sopenharmony_ci* @tc.name: SoftBusSocketAccept001
972060ff233Sopenharmony_ci* @tc.desc: Accept Socket Success
973060ff233Sopenharmony_ci* @tc.type: FUNC
974060ff233Sopenharmony_ci* @tc.require:
975060ff233Sopenharmony_ci*/
976060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketAccept001, TestSize.Level0)
977060ff233Sopenharmony_ci{
978060ff233Sopenharmony_ci    sleep(1);
979060ff233Sopenharmony_ci    int32_t pid = -1;
980060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
981060ff233Sopenharmony_ci        SocketServiceStart(0);
982060ff233Sopenharmony_ci        return;
983060ff233Sopenharmony_ci    }
984060ff233Sopenharmony_ci    sleep(1);
985060ff233Sopenharmony_ci    int32_t socketFd = -1;
986060ff233Sopenharmony_ci
987060ff233Sopenharmony_ci    ClientConnect(&socketFd);
988060ff233Sopenharmony_ci    EXPECT_TRUE(socketFd != -1);
989060ff233Sopenharmony_ci
990060ff233Sopenharmony_ci    ClientExit(socketFd);
991060ff233Sopenharmony_ci}
992060ff233Sopenharmony_ci
993060ff233Sopenharmony_ci/*
994060ff233Sopenharmony_ci* @tc.name: SoftBusSocketAccept002
995060ff233Sopenharmony_ci* @tc.desc: socketFd is illegal
996060ff233Sopenharmony_ci* @tc.type: FUNC
997060ff233Sopenharmony_ci* @tc.require:
998060ff233Sopenharmony_ci*/
999060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketAccept002, TestSize.Level0)
1000060ff233Sopenharmony_ci{
1001060ff233Sopenharmony_ci    int32_t socketFd = -1;
1002060ff233Sopenharmony_ci    int32_t acceptFd = -1;
1003060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
1004060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
1005060ff233Sopenharmony_ci    };
1006060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketAccept(socketFd, &addr, &acceptFd);
1007060ff233Sopenharmony_ci    EXPECT_NE(0, ret);
1008060ff233Sopenharmony_ci}
1009060ff233Sopenharmony_ci
1010060ff233Sopenharmony_ci/*
1011060ff233Sopenharmony_ci* @tc.name: SoftBusSocketAccept003
1012060ff233Sopenharmony_ci* @tc.desc: acceptFd is illegal
1013060ff233Sopenharmony_ci* @tc.type: FUNC
1014060ff233Sopenharmony_ci* @tc.require:
1015060ff233Sopenharmony_ci*/
1016060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketAccept003, TestSize.Level0)
1017060ff233Sopenharmony_ci{
1018060ff233Sopenharmony_ci    int32_t socketFd = -1;
1019060ff233Sopenharmony_ci    int32_t optVal = 1;
1020060ff233Sopenharmony_ci    int32_t backLog = 2;
1021060ff233Sopenharmony_ci    SoftBusSockAddrIn serAddr = {
1022060ff233Sopenharmony_ci        .sinFamily = SOFTBUS_AF_INET,
1023060ff233Sopenharmony_ci        .sinPort = SoftBusHtoNs(TEST_PORT),
1024060ff233Sopenharmony_ci        .sinAddr = {
1025060ff233Sopenharmony_ci            .sAddr = SoftBusInetAddr("127.0.0.1")
1026060ff233Sopenharmony_ci        }
1027060ff233Sopenharmony_ci    };
1028060ff233Sopenharmony_ci    SoftBusSockAddrIn cliAddr = {0};
1029060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1030060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1031060ff233Sopenharmony_ci
1032060ff233Sopenharmony_ci    SoftBusSocketSetOpt(socketFd, SOFTBUS_SOL_SOCKET, SOFTBUS_SO_REUSEADDR, &optVal, sizeof(optVal));
1033060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1034060ff233Sopenharmony_ci    ret = SoftBusSocketBind(socketFd, (SoftBusSockAddr *)&serAddr, sizeof(SoftBusSockAddrIn));
1035060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1036060ff233Sopenharmony_ci
1037060ff233Sopenharmony_ci    ret = SoftBusSocketListen(socketFd, backLog);
1038060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1039060ff233Sopenharmony_ci    ret = SoftBusSocketAccept(socketFd, (SoftBusSockAddr *)&cliAddr, NULL);
1040060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_INVALID_PARAM, ret);
1041060ff233Sopenharmony_ci
1042060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1043060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1044060ff233Sopenharmony_ci}
1045060ff233Sopenharmony_ci
1046060ff233Sopenharmony_ci/*
1047060ff233Sopenharmony_ci* @tc.name: SoftBusSocketConnect001
1048060ff233Sopenharmony_ci* @tc.desc: connect success
1049060ff233Sopenharmony_ci* @tc.type: FUNC
1050060ff233Sopenharmony_ci* @tc.require:
1051060ff233Sopenharmony_ci*/
1052060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketConnect001, TestSize.Level0)
1053060ff233Sopenharmony_ci{
1054060ff233Sopenharmony_ci    sleep(1);
1055060ff233Sopenharmony_ci    int32_t pid = -1;
1056060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1057060ff233Sopenharmony_ci        SocketServiceStart(1);
1058060ff233Sopenharmony_ci        return;
1059060ff233Sopenharmony_ci    }
1060060ff233Sopenharmony_ci    sleep(1);
1061060ff233Sopenharmony_ci    int32_t socketFd = -1;
1062060ff233Sopenharmony_ci
1063060ff233Sopenharmony_ci    ClientConnect(&socketFd);
1064060ff233Sopenharmony_ci    EXPECT_TRUE(socketFd != -1);
1065060ff233Sopenharmony_ci
1066060ff233Sopenharmony_ci    ClientExit(socketFd);
1067060ff233Sopenharmony_ci}
1068060ff233Sopenharmony_ci
1069060ff233Sopenharmony_ci/*
1070060ff233Sopenharmony_ci* @tc.name: SoftBusSocketConnect002
1071060ff233Sopenharmony_ci* @tc.desc: socketFd is illegal
1072060ff233Sopenharmony_ci* @tc.type: FUNC
1073060ff233Sopenharmony_ci* @tc.require:
1074060ff233Sopenharmony_ci*/
1075060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketConnect002, TestSize.Level0)
1076060ff233Sopenharmony_ci{
1077060ff233Sopenharmony_ci    int32_t socketFd = -1;
1078060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
1079060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
1080060ff233Sopenharmony_ci    };
1081060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketConnect(socketFd, &addr, sizeof(SoftBusSockAddrIn));
1082060ff233Sopenharmony_ci    EXPECT_NE(0, ret);
1083060ff233Sopenharmony_ci}
1084060ff233Sopenharmony_ci
1085060ff233Sopenharmony_ci/*
1086060ff233Sopenharmony_ci* @tc.name: SoftBusSocketConnect003
1087060ff233Sopenharmony_ci* @tc.desc: addr is illegal
1088060ff233Sopenharmony_ci* @tc.type: FUNC
1089060ff233Sopenharmony_ci* @tc.require:
1090060ff233Sopenharmony_ci*/
1091060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketConnect003, TestSize.Level0)
1092060ff233Sopenharmony_ci{
1093060ff233Sopenharmony_ci    int32_t socketFd = -1;
1094060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1095060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1096060ff233Sopenharmony_ci    ret = SoftBusSocketConnect(socketFd, NULL, -1);
1097060ff233Sopenharmony_ci    EXPECT_TRUE(ret < 0);
1098060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1099060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1100060ff233Sopenharmony_ci}
1101060ff233Sopenharmony_ci
1102060ff233Sopenharmony_ci/*
1103060ff233Sopenharmony_ci* @tc.name: SoftBusSocketConnect004
1104060ff233Sopenharmony_ci* @tc.desc: addrLen is illegal
1105060ff233Sopenharmony_ci* @tc.type: FUNC
1106060ff233Sopenharmony_ci* @tc.require:
1107060ff233Sopenharmony_ci*/
1108060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketConnect004, TestSize.Level0)
1109060ff233Sopenharmony_ci{
1110060ff233Sopenharmony_ci    int32_t socketFd = -1;
1111060ff233Sopenharmony_ci    SoftBusSockAddrIn serAddr = {
1112060ff233Sopenharmony_ci        .sinFamily = SOFTBUS_AF_INET,
1113060ff233Sopenharmony_ci        .sinPort = SoftBusHtoNs(8888),
1114060ff233Sopenharmony_ci        .sinAddr = {
1115060ff233Sopenharmony_ci            .sAddr = SoftBusInetAddr("127.0.0.1")
1116060ff233Sopenharmony_ci        }
1117060ff233Sopenharmony_ci    };
1118060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1119060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1120060ff233Sopenharmony_ci    ret = SoftBusSocketConnect(socketFd, (SoftBusSockAddr *)&serAddr, sizeof(SoftBusSockAddrIn));
1121060ff233Sopenharmony_ci    EXPECT_NE(0, ret);
1122060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1123060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1124060ff233Sopenharmony_ci}
1125060ff233Sopenharmony_ci
1126060ff233Sopenharmony_ci/*
1127060ff233Sopenharmony_ci* @tc.name: SoftBusSocketConnect005
1128060ff233Sopenharmony_ci* @tc.desc: addrLen is illegal
1129060ff233Sopenharmony_ci* @tc.type: FUNC
1130060ff233Sopenharmony_ci* @tc.require:
1131060ff233Sopenharmony_ci*/
1132060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketConnect005, TestSize.Level0)
1133060ff233Sopenharmony_ci{
1134060ff233Sopenharmony_ci    int32_t socketFd = -1;
1135060ff233Sopenharmony_ci    SoftBusSockAddrIn6 addrIn6 = {0};
1136060ff233Sopenharmony_ci    addrIn6.sin6Family = SOFTBUS_AF_INET6;
1137060ff233Sopenharmony_ci    addrIn6.sin6Port = SoftBusHtoNs(TEST_PORT);
1138060ff233Sopenharmony_ci    const char *srcAddr = "::1";
1139060ff233Sopenharmony_ci    SoftBusInetPtoN(SOFTBUS_AF_INET6, srcAddr, &addrIn6.sin6Addr);
1140060ff233Sopenharmony_ci    addrIn6.sin6ScopeId = SoftBusIfNameToIndex("lo");
1141060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET6, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1142060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1143060ff233Sopenharmony_ci    ret = SoftBusSocketConnect(socketFd, (SoftBusSockAddr *)&addrIn6, sizeof(SoftBusSockAddrIn6));
1144060ff233Sopenharmony_ci    EXPECT_NE(0, ret);
1145060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1146060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1147060ff233Sopenharmony_ci}
1148060ff233Sopenharmony_ci
1149060ff233Sopenharmony_ci/*
1150060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFdZeroTest001
1151060ff233Sopenharmony_ci* @tc.desc: set fdsBits zero success
1152060ff233Sopenharmony_ci* @tc.type: FUNC
1153060ff233Sopenharmony_ci* @tc.require: 1
1154060ff233Sopenharmony_ci*/
1155060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFdZeroTest001, TestSize.Level0)
1156060ff233Sopenharmony_ci{
1157060ff233Sopenharmony_ci    SoftBusFdSet set = {0};
1158060ff233Sopenharmony_ci    set.fdsBits[0] = 1;
1159060ff233Sopenharmony_ci    SoftBusSocketFdZero(&set);
1160060ff233Sopenharmony_ci    EXPECT_TRUE(set.fdsBits[0] == 0);
1161060ff233Sopenharmony_ci}
1162060ff233Sopenharmony_ci
1163060ff233Sopenharmony_ci/*
1164060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFdSetTest001
1165060ff233Sopenharmony_ci* @tc.desc: socketFd set success
1166060ff233Sopenharmony_ci* @tc.type: FUNC
1167060ff233Sopenharmony_ci* @tc.require: 1
1168060ff233Sopenharmony_ci*/
1169060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFdSetTest001, TestSize.Level0)
1170060ff233Sopenharmony_ci{
1171060ff233Sopenharmony_ci    int32_t socketFd;
1172060ff233Sopenharmony_ci    SoftBusFdSet set = {0};
1173060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1174060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1175060ff233Sopenharmony_ci    SoftBusSocketFdSet(socketFd, &set);
1176060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1177060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1178060ff233Sopenharmony_ci}
1179060ff233Sopenharmony_ci
1180060ff233Sopenharmony_ci/*
1181060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFdSetTest003
1182060ff233Sopenharmony_ci* @tc.desc: set is NULL
1183060ff233Sopenharmony_ci* @tc.type: FUNC
1184060ff233Sopenharmony_ci* @tc.require: 1
1185060ff233Sopenharmony_ci*/
1186060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFdSetTest003, TestSize.Level0)
1187060ff233Sopenharmony_ci{
1188060ff233Sopenharmony_ci    int32_t socketFd;
1189060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1190060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1191060ff233Sopenharmony_ci    SoftBusSocketFdSet(socketFd, NULL);
1192060ff233Sopenharmony_ci
1193060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1194060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1195060ff233Sopenharmony_ci}
1196060ff233Sopenharmony_ci
1197060ff233Sopenharmony_ci/*
1198060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFdClrTest001
1199060ff233Sopenharmony_ci* @tc.desc: fd clr success
1200060ff233Sopenharmony_ci* @tc.type: FUNC
1201060ff233Sopenharmony_ci* @tc.require: 1
1202060ff233Sopenharmony_ci*/
1203060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFdClrTest001, TestSize.Level0)
1204060ff233Sopenharmony_ci{
1205060ff233Sopenharmony_ci    SoftBusFdSet set;
1206060ff233Sopenharmony_ci    SoftBusSocketFdZero(&set);
1207060ff233Sopenharmony_ci    SoftBusSocketFdSet(1, &set);
1208060ff233Sopenharmony_ci    SoftBusSocketFdClr(1, &set);
1209060ff233Sopenharmony_ci    EXPECT_TRUE(set.fdsBits[0] == 0);
1210060ff233Sopenharmony_ci}
1211060ff233Sopenharmony_ci
1212060ff233Sopenharmony_ci/*
1213060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFdIssetTest001
1214060ff233Sopenharmony_ci* @tc.desc: FdIsset success
1215060ff233Sopenharmony_ci* @tc.type: FUNC
1216060ff233Sopenharmony_ci* @tc.require: 1
1217060ff233Sopenharmony_ci*/
1218060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFdIssetTest001, TestSize.Level0)
1219060ff233Sopenharmony_ci{
1220060ff233Sopenharmony_ci    SoftBusFdSet set;
1221060ff233Sopenharmony_ci    SoftBusSocketFdSet(1, &set);
1222060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketFdIsset(1, &set);
1223060ff233Sopenharmony_ci    EXPECT_TRUE(ret == 1);
1224060ff233Sopenharmony_ci}
1225060ff233Sopenharmony_ci
1226060ff233Sopenharmony_ci/*
1227060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFdIssetTest002
1228060ff233Sopenharmony_ci* @tc.desc: fd not in set
1229060ff233Sopenharmony_ci* @tc.type: FUNC
1230060ff233Sopenharmony_ci* @tc.require: 1
1231060ff233Sopenharmony_ci*/
1232060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFdIssetTest002, TestSize.Level0)
1233060ff233Sopenharmony_ci{
1234060ff233Sopenharmony_ci    SoftBusFdSet set = {0};
1235060ff233Sopenharmony_ci    SoftBusSocketFdClr(1, &set);
1236060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketFdIsset(1, &set);
1237060ff233Sopenharmony_ci    EXPECT_TRUE(ret == 0);
1238060ff233Sopenharmony_ci}
1239060ff233Sopenharmony_ci
1240060ff233Sopenharmony_ci/*
1241060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFdIssetTest003
1242060ff233Sopenharmony_ci* @tc.desc: set is null
1243060ff233Sopenharmony_ci* @tc.type: FUNC
1244060ff233Sopenharmony_ci* @tc.require: 1
1245060ff233Sopenharmony_ci*/
1246060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFdIssetTest003, TestSize.Level0)
1247060ff233Sopenharmony_ci{
1248060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketFdIsset(1, NULL);
1249060ff233Sopenharmony_ci    EXPECT_TRUE(ret == 0);
1250060ff233Sopenharmony_ci}
1251060ff233Sopenharmony_ci
1252060ff233Sopenharmony_ci/*
1253060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSelectTest001
1254060ff233Sopenharmony_ci* @tc.desc: select read fds
1255060ff233Sopenharmony_ci* @tc.type: FUNC
1256060ff233Sopenharmony_ci* @tc.require: 1
1257060ff233Sopenharmony_ci*/
1258060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSelectTest001, TestSize.Level0)
1259060ff233Sopenharmony_ci{
1260060ff233Sopenharmony_ci    int32_t socketFd;
1261060ff233Sopenharmony_ci    SoftBusFdSet readFds;
1262060ff233Sopenharmony_ci    SoftBusSockTimeOut tv = {
1263060ff233Sopenharmony_ci        .sec = 5,
1264060ff233Sopenharmony_ci        .usec = 1
1265060ff233Sopenharmony_ci    };
1266060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1267060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1268060ff233Sopenharmony_ci
1269060ff233Sopenharmony_ci    SoftBusSocketFdZero(&readFds);
1270060ff233Sopenharmony_ci    SoftBusSocketFdSet(socketFd, &readFds);
1271060ff233Sopenharmony_ci    ret = SoftBusSocketSelect(SET_SIZE, &readFds, NULL, NULL, &tv);
1272060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
1273060ff233Sopenharmony_ci
1274060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1275060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1276060ff233Sopenharmony_ci}
1277060ff233Sopenharmony_ci
1278060ff233Sopenharmony_ci/*
1279060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSelectTest002
1280060ff233Sopenharmony_ci* @tc.desc: select write fds
1281060ff233Sopenharmony_ci* @tc.type: FUNC
1282060ff233Sopenharmony_ci* @tc.require: 1
1283060ff233Sopenharmony_ci*/
1284060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSelectTest002, TestSize.Level0)
1285060ff233Sopenharmony_ci{
1286060ff233Sopenharmony_ci    int32_t socketFd;
1287060ff233Sopenharmony_ci    SoftBusFdSet writeFds;
1288060ff233Sopenharmony_ci    SoftBusFdSet fdSelect;
1289060ff233Sopenharmony_ci    SoftBusSockTimeOut tv = {
1290060ff233Sopenharmony_ci        .sec = 5,
1291060ff233Sopenharmony_ci        .usec = 1
1292060ff233Sopenharmony_ci    };
1293060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1294060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1295060ff233Sopenharmony_ci
1296060ff233Sopenharmony_ci    SoftBusSocketFdZero(&writeFds);
1297060ff233Sopenharmony_ci    SoftBusSocketFdSet(socketFd, &writeFds);
1298060ff233Sopenharmony_ci    fdSelect = writeFds;
1299060ff233Sopenharmony_ci    ret = SoftBusSocketSelect(SET_SIZE, NULL, &fdSelect, NULL, &tv);
1300060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
1301060ff233Sopenharmony_ci
1302060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1303060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1304060ff233Sopenharmony_ci}
1305060ff233Sopenharmony_ci
1306060ff233Sopenharmony_ci/*
1307060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSelectTest003
1308060ff233Sopenharmony_ci* @tc.desc: select expcept fds
1309060ff233Sopenharmony_ci* @tc.type: FUNC
1310060ff233Sopenharmony_ci* @tc.require: 1
1311060ff233Sopenharmony_ci*/
1312060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSelectTest003, TestSize.Level0)
1313060ff233Sopenharmony_ci{
1314060ff233Sopenharmony_ci    int32_t socketFd;
1315060ff233Sopenharmony_ci    SoftBusFdSet exceptFds;
1316060ff233Sopenharmony_ci    SoftBusFdSet fdSelect;
1317060ff233Sopenharmony_ci    SoftBusSockTimeOut tv = {
1318060ff233Sopenharmony_ci        .sec = 5,
1319060ff233Sopenharmony_ci        .usec = 1
1320060ff233Sopenharmony_ci    };
1321060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1322060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1323060ff233Sopenharmony_ci
1324060ff233Sopenharmony_ci    SoftBusSocketFdZero(&exceptFds);
1325060ff233Sopenharmony_ci    SoftBusSocketFdSet(socketFd, &exceptFds);
1326060ff233Sopenharmony_ci    fdSelect = exceptFds;
1327060ff233Sopenharmony_ci    ret = SoftBusSocketSelect(SET_SIZE, NULL, NULL, &fdSelect, &tv);
1328060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
1329060ff233Sopenharmony_ci
1330060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1331060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1332060ff233Sopenharmony_ci}
1333060ff233Sopenharmony_ci
1334060ff233Sopenharmony_ci/*
1335060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSelectTest004
1336060ff233Sopenharmony_ci* @tc.desc: select all fds
1337060ff233Sopenharmony_ci* @tc.type: FUNC
1338060ff233Sopenharmony_ci* @tc.require: 1
1339060ff233Sopenharmony_ci*/
1340060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSelectTest004, TestSize.Level0)
1341060ff233Sopenharmony_ci{
1342060ff233Sopenharmony_ci    SoftBusFdSet readFds, writeFds, exceptFds;
1343060ff233Sopenharmony_ci    SoftBusSockTimeOut tv = {
1344060ff233Sopenharmony_ci        .sec = 5,
1345060ff233Sopenharmony_ci        .usec = 1
1346060ff233Sopenharmony_ci    };
1347060ff233Sopenharmony_ci    SoftBusSocketFdZero(&readFds);
1348060ff233Sopenharmony_ci    SoftBusSocketFdZero(&writeFds);
1349060ff233Sopenharmony_ci    SoftBusSocketFdZero(&exceptFds);
1350060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSelect(SET_SIZE, &readFds, &writeFds, &exceptFds, &tv);
1351060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
1352060ff233Sopenharmony_ci}
1353060ff233Sopenharmony_ci
1354060ff233Sopenharmony_ci/*
1355060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSelectTest005
1356060ff233Sopenharmony_ci* @tc.desc: nfds is illegal
1357060ff233Sopenharmony_ci* @tc.type: FUNC
1358060ff233Sopenharmony_ci* @tc.require: 1
1359060ff233Sopenharmony_ci*/
1360060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSelectTest005, TestSize.Level0)
1361060ff233Sopenharmony_ci{
1362060ff233Sopenharmony_ci    SoftBusSockTimeOut tv = {
1363060ff233Sopenharmony_ci        .sec = 5,
1364060ff233Sopenharmony_ci        .usec = 1
1365060ff233Sopenharmony_ci    };
1366060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSelect(SET_SIZE, NULL, NULL, NULL, &tv);
1367060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
1368060ff233Sopenharmony_ci}
1369060ff233Sopenharmony_ci
1370060ff233Sopenharmony_ci/*
1371060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSelectTest006
1372060ff233Sopenharmony_ci* @tc.desc: The value of timeOut is 0
1373060ff233Sopenharmony_ci* @tc.type: FUNC
1374060ff233Sopenharmony_ci* @tc.require: 1
1375060ff233Sopenharmony_ci*/
1376060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSelectTest006, TestSize.Level0)
1377060ff233Sopenharmony_ci{
1378060ff233Sopenharmony_ci    SoftBusSockTimeOut tv = {
1379060ff233Sopenharmony_ci        .sec = 0,
1380060ff233Sopenharmony_ci        .usec = 0
1381060ff233Sopenharmony_ci    };
1382060ff233Sopenharmony_ci    SoftBusFdSet readFds, writeFds, exceptFds;
1383060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSelect(SET_SIZE, &readFds, &writeFds, &exceptFds, &tv);
1384060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
1385060ff233Sopenharmony_ci}
1386060ff233Sopenharmony_ci
1387060ff233Sopenharmony_ci/*
1388060ff233Sopenharmony_ci* @tc.name: SoftBusSocketIoctlTest001
1389060ff233Sopenharmony_ci* @tc.desc:fd is illegal
1390060ff233Sopenharmony_ci* @tc.type: FUNC
1391060ff233Sopenharmony_ci* @tc.require: 1
1392060ff233Sopenharmony_ci*/
1393060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketIoctlTest001, TestSize.Level0)
1394060ff233Sopenharmony_ci{
1395060ff233Sopenharmony_ci    int32_t nread = 0;
1396060ff233Sopenharmony_ci    long cmd = 1;
1397060ff233Sopenharmony_ci    int32_t socketFd = -1;
1398060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketIoctl(socketFd, cmd, &nread);
1399060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
1400060ff233Sopenharmony_ci}
1401060ff233Sopenharmony_ci
1402060ff233Sopenharmony_ci/*
1403060ff233Sopenharmony_ci* @tc.name: SoftBusSocketIoctlTest002
1404060ff233Sopenharmony_ci* @tc.desc: cmd is illegal
1405060ff233Sopenharmony_ci* @tc.type: FUNC
1406060ff233Sopenharmony_ci* @tc.require: 1
1407060ff233Sopenharmony_ci*/
1408060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketIoctlTest002, TestSize.Level0)
1409060ff233Sopenharmony_ci{
1410060ff233Sopenharmony_ci    int32_t nread;
1411060ff233Sopenharmony_ci    long cmd = -1;
1412060ff233Sopenharmony_ci    int32_t socketFd;
1413060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1414060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1415060ff233Sopenharmony_ci
1416060ff233Sopenharmony_ci    ret = SoftBusSocketIoctl(socketFd, cmd, &nread);
1417060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
1418060ff233Sopenharmony_ci
1419060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1420060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1421060ff233Sopenharmony_ci}
1422060ff233Sopenharmony_ci
1423060ff233Sopenharmony_ci/*
1424060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFcntlTest001
1425060ff233Sopenharmony_ci* @tc.desc: Fcntl is success
1426060ff233Sopenharmony_ci* @tc.type: FUNC
1427060ff233Sopenharmony_ci* @tc.require: 1
1428060ff233Sopenharmony_ci*/
1429060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFcntlTest001, TestSize.Level0)
1430060ff233Sopenharmony_ci{
1431060ff233Sopenharmony_ci    int32_t socketFd;
1432060ff233Sopenharmony_ci    long cmd = 1;
1433060ff233Sopenharmony_ci    long flag = 0;
1434060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1435060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1436060ff233Sopenharmony_ci
1437060ff233Sopenharmony_ci    ret = SoftBusSocketFcntl(socketFd, cmd, flag);
1438060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1439060ff233Sopenharmony_ci
1440060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1441060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1442060ff233Sopenharmony_ci}
1443060ff233Sopenharmony_ci
1444060ff233Sopenharmony_ci/*
1445060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFcntlTest002
1446060ff233Sopenharmony_ci* @tc.desc: socketFd is illegal
1447060ff233Sopenharmony_ci* @tc.type: FUNC
1448060ff233Sopenharmony_ci* @tc.require: 1
1449060ff233Sopenharmony_ci*/
1450060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFcntlTest002, TestSize.Level0)
1451060ff233Sopenharmony_ci{
1452060ff233Sopenharmony_ci    int32_t socketFd = -1;
1453060ff233Sopenharmony_ci    long cmd = F_DUPFD;
1454060ff233Sopenharmony_ci    long flag = 0;
1455060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketFcntl(socketFd, cmd, flag);
1456060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
1457060ff233Sopenharmony_ci}
1458060ff233Sopenharmony_ci
1459060ff233Sopenharmony_ci#if HAVE_PRO
1460060ff233Sopenharmony_ci/*
1461060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendTest001
1462060ff233Sopenharmony_ci* @tc.desc: socketFd is invalid
1463060ff233Sopenharmony_ci* @tc.type: FUNC
1464060ff233Sopenharmony_ci* @tc.require: 1
1465060ff233Sopenharmony_ci*/
1466060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendTest001, TestSize.Level0)
1467060ff233Sopenharmony_ci{
1468060ff233Sopenharmony_ci    int32_t socketFd = -1;
1469060ff233Sopenharmony_ci    char buf[TEST_BUF_SIZE] = {0};
1470060ff233Sopenharmony_ci
1471060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSend(socketFd, buf, TEST_BUF_SIZE, 0);
1472060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
1473060ff233Sopenharmony_ci}
1474060ff233Sopenharmony_ci#endif
1475060ff233Sopenharmony_ci
1476060ff233Sopenharmony_ci/*
1477060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendTest002
1478060ff233Sopenharmony_ci* @tc.desc: buf is invalid
1479060ff233Sopenharmony_ci* @tc.type: FUNC
1480060ff233Sopenharmony_ci* @tc.require: 1
1481060ff233Sopenharmony_ci*/
1482060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendTest002, TestSize.Level0)
1483060ff233Sopenharmony_ci{
1484060ff233Sopenharmony_ci    sleep(1);
1485060ff233Sopenharmony_ci    int32_t pid = -1;
1486060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1487060ff233Sopenharmony_ci        SocketServiceStart(0);
1488060ff233Sopenharmony_ci        return;
1489060ff233Sopenharmony_ci    }
1490060ff233Sopenharmony_ci    sleep(1);
1491060ff233Sopenharmony_ci    int32_t socketFd = -1;
1492060ff233Sopenharmony_ci    SoftBusSockAddrIn serAddr = {
1493060ff233Sopenharmony_ci        .sinFamily = SOFTBUS_AF_INET,
1494060ff233Sopenharmony_ci        .sinPort = SoftBusHtoNs(8888),
1495060ff233Sopenharmony_ci        .sinAddr = {
1496060ff233Sopenharmony_ci            .sAddr = SoftBusInetAddr("127.0.0.1")
1497060ff233Sopenharmony_ci        }
1498060ff233Sopenharmony_ci    };
1499060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1500060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1501060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1502060ff233Sopenharmony_ci    ret = SoftBusSocketConnect(socketFd, (SoftBusSockAddr *)&serAddr, sizeof(SoftBusSockAddrIn));
1503060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1504060ff233Sopenharmony_ci    ret = SoftBusSocketSend(socketFd, NULL, 0, 0);
1505060ff233Sopenharmony_ci    EXPECT_TRUE(ret <= 0);
1506060ff233Sopenharmony_ci    (void)memset_s(&buf, sizeof(struct SocketProtocol), 0, sizeof(struct SocketProtocol));
1507060ff233Sopenharmony_ci    buf.cmd = CMD_EXIT;
1508060ff233Sopenharmony_ci    ret = SoftBusSocketSend(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
1509060ff233Sopenharmony_ci    EXPECT_TRUE(ret != -1);
1510060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1511060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1512060ff233Sopenharmony_ci}
1513060ff233Sopenharmony_ci
1514060ff233Sopenharmony_ci/*
1515060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendTest003
1516060ff233Sopenharmony_ci* @tc.desc: bufLen is invalid
1517060ff233Sopenharmony_ci* @tc.type: FUNC
1518060ff233Sopenharmony_ci* @tc.require: 1
1519060ff233Sopenharmony_ci*/
1520060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendTest003, TestSize.Level0)
1521060ff233Sopenharmony_ci{
1522060ff233Sopenharmony_ci    sleep(1);
1523060ff233Sopenharmony_ci    int32_t pid = -1;
1524060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1525060ff233Sopenharmony_ci        SocketServiceStart(0);
1526060ff233Sopenharmony_ci        return;
1527060ff233Sopenharmony_ci    }
1528060ff233Sopenharmony_ci    sleep(1);
1529060ff233Sopenharmony_ci    int32_t socketFd = -1;
1530060ff233Sopenharmony_ci    SoftBusSockAddrIn serAddr = {
1531060ff233Sopenharmony_ci        .sinFamily = SOFTBUS_AF_INET,
1532060ff233Sopenharmony_ci        .sinPort = SoftBusHtoNs(8888),
1533060ff233Sopenharmony_ci        .sinAddr = {
1534060ff233Sopenharmony_ci            .sAddr = SoftBusInetAddr("127.0.0.1")
1535060ff233Sopenharmony_ci        }
1536060ff233Sopenharmony_ci    };
1537060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1538060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1539060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1540060ff233Sopenharmony_ci    ret = SoftBusSocketConnect(socketFd, (SoftBusSockAddr *)&serAddr, sizeof(SoftBusSockAddrIn));
1541060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1542060ff233Sopenharmony_ci    buf.cmd = CMD_RECV;
1543060ff233Sopenharmony_ci    (void)strncpy_s(buf.data, sizeof(buf.data), "Happy New Year!", sizeof(buf.data));
1544060ff233Sopenharmony_ci    ret = SoftBusSocketSend(socketFd, (void *)&buf, 0, 0);
1545060ff233Sopenharmony_ci    EXPECT_TRUE(ret <= 0);
1546060ff233Sopenharmony_ci    (void)memset_s(&buf, sizeof(struct SocketProtocol), 0, sizeof(struct SocketProtocol));
1547060ff233Sopenharmony_ci    buf.cmd = CMD_EXIT;
1548060ff233Sopenharmony_ci    ret = SoftBusSocketSend(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
1549060ff233Sopenharmony_ci    EXPECT_TRUE(ret != -1);
1550060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1551060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1552060ff233Sopenharmony_ci}
1553060ff233Sopenharmony_ci
1554060ff233Sopenharmony_ci/*
1555060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendTest004
1556060ff233Sopenharmony_ci* @tc.desc: positive
1557060ff233Sopenharmony_ci* @tc.type: FUNC
1558060ff233Sopenharmony_ci* @tc.require: 1
1559060ff233Sopenharmony_ci*/
1560060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendTest004, TestSize.Level0)
1561060ff233Sopenharmony_ci{
1562060ff233Sopenharmony_ci    sleep(1);
1563060ff233Sopenharmony_ci    int32_t pid = -1;
1564060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1565060ff233Sopenharmony_ci        SocketServiceStart(0);
1566060ff233Sopenharmony_ci        return;
1567060ff233Sopenharmony_ci    }
1568060ff233Sopenharmony_ci    sleep(1);
1569060ff233Sopenharmony_ci    int32_t socketFd = -1;
1570060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1571060ff233Sopenharmony_ci    ClientConnect(&socketFd);
1572060ff233Sopenharmony_ci
1573060ff233Sopenharmony_ci    buf.cmd = CMD_RECV;
1574060ff233Sopenharmony_ci    (void)strncpy_s(buf.data, sizeof(buf.data), "Happy New Year!", sizeof(buf.data));
1575060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSend(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 1);
1576060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
1577060ff233Sopenharmony_ci
1578060ff233Sopenharmony_ci    ClientExit(socketFd);
1579060ff233Sopenharmony_ci}
1580060ff233Sopenharmony_ci
1581060ff233Sopenharmony_ci/*
1582060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendToTest001
1583060ff233Sopenharmony_ci* @tc.desc: socketFd is illegal
1584060ff233Sopenharmony_ci* @tc.type: FUNC
1585060ff233Sopenharmony_ci* @tc.require: 1
1586060ff233Sopenharmony_ci*/
1587060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendToTest001, TestSize.Level0)
1588060ff233Sopenharmony_ci{
1589060ff233Sopenharmony_ci    int32_t socketFd = -1;
1590060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
1591060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
1592060ff233Sopenharmony_ci    };
1593060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1594060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSendTo(socketFd, (void *)&buf, sizeof(buf), 0, &addr, sizeof(SoftBusSockAddrIn));
1595060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
1596060ff233Sopenharmony_ci}
1597060ff233Sopenharmony_ci
1598060ff233Sopenharmony_ci/*
1599060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendToTest002
1600060ff233Sopenharmony_ci* @tc.desc: send to success
1601060ff233Sopenharmony_ci* @tc.type: FUNC
1602060ff233Sopenharmony_ci* @tc.require: 1
1603060ff233Sopenharmony_ci*/
1604060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendToTest002, TestSize.Level0)
1605060ff233Sopenharmony_ci{
1606060ff233Sopenharmony_ci    sleep(1);
1607060ff233Sopenharmony_ci    int32_t pid = -1;
1608060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1609060ff233Sopenharmony_ci        SocketServiceStart(0);
1610060ff233Sopenharmony_ci        return;
1611060ff233Sopenharmony_ci    }
1612060ff233Sopenharmony_ci    sleep(1);
1613060ff233Sopenharmony_ci    int32_t socketFd = -1;
1614060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1615060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
1616060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
1617060ff233Sopenharmony_ci    };
1618060ff233Sopenharmony_ci    ClientConnect(&socketFd);
1619060ff233Sopenharmony_ci
1620060ff233Sopenharmony_ci    buf.cmd = CMD_RECV;
1621060ff233Sopenharmony_ci    (void)strncpy_s(buf.data, sizeof(buf.data), "Happy New Year!", sizeof(buf.data));
1622060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSendTo(socketFd, (void *)&buf, sizeof(buf), 0, &addr, sizeof(SoftBusSockAddrIn));
1623060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
1624060ff233Sopenharmony_ci
1625060ff233Sopenharmony_ci    ClientExit(socketFd);
1626060ff233Sopenharmony_ci}
1627060ff233Sopenharmony_ci
1628060ff233Sopenharmony_ci/*
1629060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendToTest003
1630060ff233Sopenharmony_ci* @tc.desc: buf is null
1631060ff233Sopenharmony_ci* @tc.type: FUNC
1632060ff233Sopenharmony_ci* @tc.require: 1
1633060ff233Sopenharmony_ci*/
1634060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendToTest003, TestSize.Level0)
1635060ff233Sopenharmony_ci{
1636060ff233Sopenharmony_ci    sleep(1);
1637060ff233Sopenharmony_ci    int32_t pid = -1;
1638060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1639060ff233Sopenharmony_ci        SocketServiceStart(0);
1640060ff233Sopenharmony_ci        return;
1641060ff233Sopenharmony_ci    }
1642060ff233Sopenharmony_ci    sleep(1);
1643060ff233Sopenharmony_ci    int32_t socketFd = -1;
1644060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1645060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
1646060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
1647060ff233Sopenharmony_ci    };
1648060ff233Sopenharmony_ci    ClientConnect(&socketFd);
1649060ff233Sopenharmony_ci
1650060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSendTo(socketFd, NULL, sizeof(buf), 0, &addr, sizeof(SoftBusSockAddrIn));
1651060ff233Sopenharmony_ci    EXPECT_TRUE(ret == -1);
1652060ff233Sopenharmony_ci
1653060ff233Sopenharmony_ci    ClientExit(socketFd);
1654060ff233Sopenharmony_ci}
1655060ff233Sopenharmony_ci
1656060ff233Sopenharmony_ci/*
1657060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendToTest004
1658060ff233Sopenharmony_ci* @tc.desc: addr is NULL
1659060ff233Sopenharmony_ci* @tc.type: FUNC
1660060ff233Sopenharmony_ci* @tc.require: 1
1661060ff233Sopenharmony_ci*/
1662060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendToTest004, TestSize.Level0)
1663060ff233Sopenharmony_ci{
1664060ff233Sopenharmony_ci    sleep(1);
1665060ff233Sopenharmony_ci    int32_t pid = -1;
1666060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1667060ff233Sopenharmony_ci        SocketServiceStart(0);
1668060ff233Sopenharmony_ci        return;
1669060ff233Sopenharmony_ci    }
1670060ff233Sopenharmony_ci    sleep(1);
1671060ff233Sopenharmony_ci    int32_t socketFd = -1;
1672060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1673060ff233Sopenharmony_ci    ClientConnect(&socketFd);
1674060ff233Sopenharmony_ci
1675060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSendTo(socketFd, (void *)&buf, sizeof(buf), 0, NULL, sizeof(SoftBusSockAddrIn));
1676060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
1677060ff233Sopenharmony_ci
1678060ff233Sopenharmony_ci    ClientExit(socketFd);
1679060ff233Sopenharmony_ci}
1680060ff233Sopenharmony_ci
1681060ff233Sopenharmony_ci/*
1682060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendToTest005
1683060ff233Sopenharmony_ci* @tc.desc: addrLen is illegal
1684060ff233Sopenharmony_ci* @tc.type: FUNC
1685060ff233Sopenharmony_ci* @tc.require: 1
1686060ff233Sopenharmony_ci*/
1687060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendToTest005, TestSize.Level0)
1688060ff233Sopenharmony_ci{
1689060ff233Sopenharmony_ci    sleep(1);
1690060ff233Sopenharmony_ci    int32_t pid = -1;
1691060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1692060ff233Sopenharmony_ci        SocketServiceStart(0);
1693060ff233Sopenharmony_ci        return;
1694060ff233Sopenharmony_ci    }
1695060ff233Sopenharmony_ci    sleep(1);
1696060ff233Sopenharmony_ci    int32_t socketFd = -1;
1697060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1698060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
1699060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
1700060ff233Sopenharmony_ci    };
1701060ff233Sopenharmony_ci    ClientConnect(&socketFd);
1702060ff233Sopenharmony_ci
1703060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSendTo(socketFd, (void *)&buf, sizeof(buf), 0, &addr, 0);
1704060ff233Sopenharmony_ci
1705060ff233Sopenharmony_ci    EXPECT_TRUE(ret < 0);
1706060ff233Sopenharmony_ci
1707060ff233Sopenharmony_ci    ClientExit(socketFd);
1708060ff233Sopenharmony_ci}
1709060ff233Sopenharmony_ci
1710060ff233Sopenharmony_ci/*
1711060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendToTest006
1712060ff233Sopenharmony_ci* @tc.desc: bufLen is illegal
1713060ff233Sopenharmony_ci* @tc.type: FUNC
1714060ff233Sopenharmony_ci* @tc.require: 1
1715060ff233Sopenharmony_ci*/
1716060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendToTest006, TestSize.Level0)
1717060ff233Sopenharmony_ci{
1718060ff233Sopenharmony_ci    sleep(1);
1719060ff233Sopenharmony_ci    int32_t pid = -1;
1720060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1721060ff233Sopenharmony_ci        SocketServiceStart(0);
1722060ff233Sopenharmony_ci        return;
1723060ff233Sopenharmony_ci    }
1724060ff233Sopenharmony_ci    sleep(1);
1725060ff233Sopenharmony_ci    int32_t socketFd = -1;
1726060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1727060ff233Sopenharmony_ci    SoftBusSockAddr addr = {
1728060ff233Sopenharmony_ci        .saFamily = SOFTBUS_AF_INET,
1729060ff233Sopenharmony_ci    };
1730060ff233Sopenharmony_ci    ClientConnect(&socketFd);
1731060ff233Sopenharmony_ci
1732060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSendTo(socketFd, (void *)&buf, 0, 0, &addr, sizeof(SoftBusSockAddrIn));
1733060ff233Sopenharmony_ci    EXPECT_TRUE(ret == 0);
1734060ff233Sopenharmony_ci
1735060ff233Sopenharmony_ci    ClientExit(socketFd);
1736060ff233Sopenharmony_ci}
1737060ff233Sopenharmony_ci
1738060ff233Sopenharmony_ci/*
1739060ff233Sopenharmony_ci* @tc.name: SoftBusSocketSendTest007
1740060ff233Sopenharmony_ci* @tc.desc: buf is invalid
1741060ff233Sopenharmony_ci* @tc.type: FUNC
1742060ff233Sopenharmony_ci* @tc.require: 1
1743060ff233Sopenharmony_ci*/
1744060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketSendTest007, TestSize.Level0)
1745060ff233Sopenharmony_ci{
1746060ff233Sopenharmony_ci    sleep(1);
1747060ff233Sopenharmony_ci    int32_t pid = -1;
1748060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1749060ff233Sopenharmony_ci        SocketIpv6ServiceStart(0);
1750060ff233Sopenharmony_ci        return;
1751060ff233Sopenharmony_ci    }
1752060ff233Sopenharmony_ci    sleep(1);
1753060ff233Sopenharmony_ci    int32_t socketFd = -1;
1754060ff233Sopenharmony_ci    SoftBusSockAddrIn6 addrIn6 = {0};
1755060ff233Sopenharmony_ci    addrIn6.sin6Family = SOFTBUS_AF_INET6;
1756060ff233Sopenharmony_ci    addrIn6.sin6Port = SoftBusHtoNs(TEST_IPV6_PORT);
1757060ff233Sopenharmony_ci    const char *srcAddr = "::1";
1758060ff233Sopenharmony_ci    SoftBusInetPtoN(SOFTBUS_AF_INET6, srcAddr, &addrIn6.sin6Addr);
1759060ff233Sopenharmony_ci    addrIn6.sin6ScopeId = SoftBusIfNameToIndex("lo");
1760060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1761060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET6, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1762060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1763060ff233Sopenharmony_ci    ret = SoftBusSocketConnect(socketFd, (SoftBusSockAddr *)&addrIn6, sizeof(SoftBusSockAddrIn6));
1764060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1765060ff233Sopenharmony_ci    ret = SoftBusSocketSend(socketFd, NULL, 0, 0);
1766060ff233Sopenharmony_ci    EXPECT_TRUE(ret <= 0);
1767060ff233Sopenharmony_ci    (void)memset_s(&buf, sizeof(struct SocketProtocol), 0, sizeof(struct SocketProtocol));
1768060ff233Sopenharmony_ci    buf.cmd = CMD_EXIT;
1769060ff233Sopenharmony_ci    ret = SoftBusSocketSend(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
1770060ff233Sopenharmony_ci    EXPECT_TRUE(ret != -1);
1771060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1772060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1773060ff233Sopenharmony_ci}
1774060ff233Sopenharmony_ci
1775060ff233Sopenharmony_ci/*
1776060ff233Sopenharmony_ci* @tc.name: SoftBusSocketRecvTest001
1777060ff233Sopenharmony_ci* @tc.desc: socketFd is NULL
1778060ff233Sopenharmony_ci* @tc.type: FUNC
1779060ff233Sopenharmony_ci* @tc.require: 1
1780060ff233Sopenharmony_ci*/
1781060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketRecvTest001, TestSize.Level0)
1782060ff233Sopenharmony_ci{
1783060ff233Sopenharmony_ci    int32_t socketFd = -1;
1784060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1785060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketRecv(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
1786060ff233Sopenharmony_ci    EXPECT_NE(0, ret);
1787060ff233Sopenharmony_ci}
1788060ff233Sopenharmony_ci
1789060ff233Sopenharmony_ci/*
1790060ff233Sopenharmony_ci* @tc.name: SoftBusSocketRecvTest002
1791060ff233Sopenharmony_ci* @tc.desc: recv success
1792060ff233Sopenharmony_ci* @tc.type: FUNC
1793060ff233Sopenharmony_ci* @tc.require: 1
1794060ff233Sopenharmony_ci*/
1795060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketRecvTest002, TestSize.Level0)
1796060ff233Sopenharmony_ci{
1797060ff233Sopenharmony_ci    sleep(1);
1798060ff233Sopenharmony_ci    int32_t pid = -1;
1799060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
1800060ff233Sopenharmony_ci        SocketServiceStart(0);
1801060ff233Sopenharmony_ci        return;
1802060ff233Sopenharmony_ci    }
1803060ff233Sopenharmony_ci    sleep(1);
1804060ff233Sopenharmony_ci    int32_t socketFd = -1;
1805060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
1806060ff233Sopenharmony_ci    ClientConnect(&socketFd);
1807060ff233Sopenharmony_ci
1808060ff233Sopenharmony_ci    buf.cmd = CMD_RECV;
1809060ff233Sopenharmony_ci    (void)strncpy_s(buf.data, sizeof(buf.data), "Hello World!", sizeof(buf.data));
1810060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketSend(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
1811060ff233Sopenharmony_ci    EXPECT_TRUE(ret != -1);
1812060ff233Sopenharmony_ci
1813060ff233Sopenharmony_ci    (void)memset_s(&buf, sizeof(struct SocketProtocol), 0, sizeof(struct SocketProtocol));
1814060ff233Sopenharmony_ci    ret = SoftBusSocketRecv(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
1815060ff233Sopenharmony_ci    EXPECT_TRUE(ret != -1);
1816060ff233Sopenharmony_ci
1817060ff233Sopenharmony_ci    ClientExit(socketFd);
1818060ff233Sopenharmony_ci}
1819060ff233Sopenharmony_ci
1820060ff233Sopenharmony_ci/*
1821060ff233Sopenharmony_ci* @tc.name:  SoftBusSocketRecvFromTest001
1822060ff233Sopenharmony_ci* @tc.desc: positive
1823060ff233Sopenharmony_ci* @tc.type: FUNC
1824060ff233Sopenharmony_ci* @tc.require: 1
1825060ff233Sopenharmony_ci*/
1826060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketRecvFromTest001, TestSize.Level0)
1827060ff233Sopenharmony_ci{
1828060ff233Sopenharmony_ci    int32_t socketFd = -1;
1829060ff233Sopenharmony_ci    SoftBusSockAddr fromAddr = {0};
1830060ff233Sopenharmony_ci    int32_t fromAddrLen;
1831060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketRecvFrom(socketFd, NULL, 0, 0, &fromAddr, &fromAddrLen);
1832060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
1833060ff233Sopenharmony_ci}
1834060ff233Sopenharmony_ci
1835060ff233Sopenharmony_ci/*
1836060ff233Sopenharmony_ci* @tc.name: SoftBusSocketShutDownTest001
1837060ff233Sopenharmony_ci* @tc.desc: socketFd is service fd
1838060ff233Sopenharmony_ci* @tc.type: FUNC
1839060ff233Sopenharmony_ci* @tc.require: 1
1840060ff233Sopenharmony_ci*/
1841060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketShutDownTest001, TestSize.Level0)
1842060ff233Sopenharmony_ci{
1843060ff233Sopenharmony_ci    int32_t socketFd = -1;
1844060ff233Sopenharmony_ci    int32_t optVal = 1;
1845060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1846060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1847060ff233Sopenharmony_ci
1848060ff233Sopenharmony_ci    SoftBusSocketSetOpt(socketFd, SOFTBUS_SOL_SOCKET, SOFTBUS_SO_REUSEADDR, &optVal, sizeof(optVal));
1849060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1850060ff233Sopenharmony_ci
1851060ff233Sopenharmony_ci    SoftBusSocketShutDown(socketFd, SOFTBUS_SHUT_RDWR);
1852060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1853060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1854060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1855060ff233Sopenharmony_ci}
1856060ff233Sopenharmony_ci
1857060ff233Sopenharmony_ci/*
1858060ff233Sopenharmony_ci* @tc.name: SoftBusSocketShutDownTest002
1859060ff233Sopenharmony_ci* @tc.desc: socketFd is illegal
1860060ff233Sopenharmony_ci* @tc.type: FUNC
1861060ff233Sopenharmony_ci* @tc.require: 1
1862060ff233Sopenharmony_ci*/
1863060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketShutDownTest002, TestSize.Level0)
1864060ff233Sopenharmony_ci{
1865060ff233Sopenharmony_ci    int32_t socketFd = -1;
1866060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketShutDown(socketFd, SOFTBUS_SHUT_RDWR);
1867060ff233Sopenharmony_ci    EXPECT_TRUE(ret != 0);
1868060ff233Sopenharmony_ci}
1869060ff233Sopenharmony_ci
1870060ff233Sopenharmony_ci/*
1871060ff233Sopenharmony_ci* @tc.name: SoftBusSocketShutDownTest003
1872060ff233Sopenharmony_ci* @tc.desc: how is illegal
1873060ff233Sopenharmony_ci* @tc.type: FUNC
1874060ff233Sopenharmony_ci* @tc.require: 1
1875060ff233Sopenharmony_ci*/
1876060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketShutDownTest003, TestSize.Level0)
1877060ff233Sopenharmony_ci{
1878060ff233Sopenharmony_ci    int32_t socketFd;
1879060ff233Sopenharmony_ci
1880060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1881060ff233Sopenharmony_ci    EXPECT_TRUE(ret == 0);
1882060ff233Sopenharmony_ci    ret = SoftBusSocketShutDown(socketFd, -1);
1883060ff233Sopenharmony_ci    EXPECT_TRUE(ret != 0);
1884060ff233Sopenharmony_ci    SoftBusSocketClose(socketFd);
1885060ff233Sopenharmony_ci}
1886060ff233Sopenharmony_ci
1887060ff233Sopenharmony_ci/*
1888060ff233Sopenharmony_ci* @tc.name: SoftBusSocketCloseTest001
1889060ff233Sopenharmony_ci* @tc.desc: normal close
1890060ff233Sopenharmony_ci* @tc.type: FUNC
1891060ff233Sopenharmony_ci* @tc.require: 1
1892060ff233Sopenharmony_ci*/
1893060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketCloseTest001, TestSize.Level0)
1894060ff233Sopenharmony_ci{
1895060ff233Sopenharmony_ci    int32_t socketFd;
1896060ff233Sopenharmony_ci
1897060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketCreate(SOFTBUS_AF_INET, SOFTBUS_SOCK_STREAM, 0, &socketFd);
1898060ff233Sopenharmony_ci    EXPECT_TRUE(ret == 0);
1899060ff233Sopenharmony_ci    ret = SoftBusSocketClose(socketFd);
1900060ff233Sopenharmony_ci    EXPECT_TRUE(ret == 0);
1901060ff233Sopenharmony_ci}
1902060ff233Sopenharmony_ci
1903060ff233Sopenharmony_ci/*
1904060ff233Sopenharmony_ci* @tc.name: SoftBusSocketCloseTest002
1905060ff233Sopenharmony_ci* @tc.desc: fd is illegal
1906060ff233Sopenharmony_ci* @tc.type: FUNC
1907060ff233Sopenharmony_ci* @tc.require: 1
1908060ff233Sopenharmony_ci*/
1909060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketCloseTest002, TestSize.Level0)
1910060ff233Sopenharmony_ci{
1911060ff233Sopenharmony_ci    int32_t socketFd = -1;
1912060ff233Sopenharmony_ci
1913060ff233Sopenharmony_ci    int32_t ret = SoftBusSocketClose(socketFd);
1914060ff233Sopenharmony_ci    EXPECT_TRUE(ret == -1);
1915060ff233Sopenharmony_ci}
1916060ff233Sopenharmony_ci
1917060ff233Sopenharmony_ci/*
1918060ff233Sopenharmony_ci* @tc.name: SoftBusInetPtoNTest001
1919060ff233Sopenharmony_ci* @tc.desc: string is valid format
1920060ff233Sopenharmony_ci* @tc.type: FUNC
1921060ff233Sopenharmony_ci* @tc.require: 1
1922060ff233Sopenharmony_ci*/
1923060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetPtoNTest001, TestSize.Level0)
1924060ff233Sopenharmony_ci{
1925060ff233Sopenharmony_ci    const char *src = "192.168.0.1";
1926060ff233Sopenharmony_ci    char dst[TEST_BUF_SIZE] = {0};
1927060ff233Sopenharmony_ci    int32_t ret = SoftBusInetPtoN(SOFTBUS_AF_INET, src, dst);
1928060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
1929060ff233Sopenharmony_ci    EXPECT_EQ(0x100A8C0, *(unsigned int *)dst);
1930060ff233Sopenharmony_ci}
1931060ff233Sopenharmony_ci
1932060ff233Sopenharmony_ci/*
1933060ff233Sopenharmony_ci* @tc.name: SoftBusInetPtoNTest002
1934060ff233Sopenharmony_ci* @tc.desc: string is invalid format
1935060ff233Sopenharmony_ci* @tc.type: FUNC
1936060ff233Sopenharmony_ci* @tc.require: 1
1937060ff233Sopenharmony_ci*/
1938060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetPtoNTest002, TestSize.Level0)
1939060ff233Sopenharmony_ci{
1940060ff233Sopenharmony_ci    const char *src = "abcde";
1941060ff233Sopenharmony_ci    char dst[TEST_BUF_SIZE] = {0};
1942060ff233Sopenharmony_ci    int32_t ret = SoftBusInetPtoN(SOFTBUS_AF_INET, src, dst);
1943060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_INVALID_PARAM, ret);
1944060ff233Sopenharmony_ci}
1945060ff233Sopenharmony_ci
1946060ff233Sopenharmony_ci/*
1947060ff233Sopenharmony_ci* @tc.name: SoftBusInetPtoNTest003
1948060ff233Sopenharmony_ci* @tc.desc: string is invalid format
1949060ff233Sopenharmony_ci* @tc.type: FUNC
1950060ff233Sopenharmony_ci* @tc.require: 1
1951060ff233Sopenharmony_ci*/
1952060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetPtoNTest003, TestSize.Level0)
1953060ff233Sopenharmony_ci{
1954060ff233Sopenharmony_ci    const char *src = "1234";
1955060ff233Sopenharmony_ci    char dst[TEST_BUF_SIZE] = {0};
1956060ff233Sopenharmony_ci    int32_t ret = SoftBusInetPtoN(SOFTBUS_AF_INET, src, dst);
1957060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_INVALID_PARAM, ret);
1958060ff233Sopenharmony_ci}
1959060ff233Sopenharmony_ci
1960060ff233Sopenharmony_ci/*
1961060ff233Sopenharmony_ci* @tc.name: SoftBusInetPtoNTest004
1962060ff233Sopenharmony_ci* @tc.desc: string is invalid format
1963060ff233Sopenharmony_ci* @tc.type: FUNC
1964060ff233Sopenharmony_ci* @tc.require: 1
1965060ff233Sopenharmony_ci*/
1966060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetPtoNTest004, TestSize.Level0)
1967060ff233Sopenharmony_ci{
1968060ff233Sopenharmony_ci    const char *src = "0x1234";
1969060ff233Sopenharmony_ci    char dst[TEST_BUF_SIZE] = {0};
1970060ff233Sopenharmony_ci    int32_t ret = SoftBusInetPtoN(SOFTBUS_AF_INET, src, dst);
1971060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_INVALID_PARAM, ret);
1972060ff233Sopenharmony_ci}
1973060ff233Sopenharmony_ci
1974060ff233Sopenharmony_ci/*
1975060ff233Sopenharmony_ci* @tc.name: SoftBusInetPtoNTest005
1976060ff233Sopenharmony_ci* @tc.desc: string is invalid format
1977060ff233Sopenharmony_ci* @tc.type: FUNC
1978060ff233Sopenharmony_ci* @tc.require: 1
1979060ff233Sopenharmony_ci*/
1980060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetPtoNTest005, TestSize.Level0)
1981060ff233Sopenharmony_ci{
1982060ff233Sopenharmony_ci    const char *src = "__*0x1234";
1983060ff233Sopenharmony_ci    char dst[TEST_BUF_SIZE] = {0};
1984060ff233Sopenharmony_ci    int32_t ret = SoftBusInetPtoN(SOFTBUS_AF_INET, src, dst);
1985060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_INVALID_PARAM, ret);
1986060ff233Sopenharmony_ci}
1987060ff233Sopenharmony_ci
1988060ff233Sopenharmony_ci/*
1989060ff233Sopenharmony_ci* @tc.name: SoftBusInetPtoNTest006
1990060ff233Sopenharmony_ci* @tc.desc: af is illegal
1991060ff233Sopenharmony_ci* @tc.type: FUNC
1992060ff233Sopenharmony_ci* @tc.require: 1
1993060ff233Sopenharmony_ci*/
1994060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetPtoNTest006, TestSize.Level0)
1995060ff233Sopenharmony_ci{
1996060ff233Sopenharmony_ci    const char *src = "192.168.0.1";
1997060ff233Sopenharmony_ci    char dst[TEST_BUF_SIZE] = {0};
1998060ff233Sopenharmony_ci    int32_t ret = SoftBusInetPtoN(-1, src, dst);
1999060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
2000060ff233Sopenharmony_ci}
2001060ff233Sopenharmony_ci
2002060ff233Sopenharmony_ci/*
2003060ff233Sopenharmony_ci* @tc.name: SoftBusInetPtoNTest007
2004060ff233Sopenharmony_ci* @tc.desc: loop back
2005060ff233Sopenharmony_ci* @tc.type: FUNC
2006060ff233Sopenharmony_ci* @tc.require: 1
2007060ff233Sopenharmony_ci*/
2008060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetPtoNTest007, TestSize.Level0)
2009060ff233Sopenharmony_ci{
2010060ff233Sopenharmony_ci    const char *src = "::1";
2011060ff233Sopenharmony_ci    char dst[46] = {0};
2012060ff233Sopenharmony_ci    int32_t ret = SoftBusInetPtoN(SOFTBUS_AF_INET6, src, dst);
2013060ff233Sopenharmony_ci    EXPECT_EQ(0, ret);
2014060ff233Sopenharmony_ci}
2015060ff233Sopenharmony_ci
2016060ff233Sopenharmony_ci/*
2017060ff233Sopenharmony_ci* @tc.name: SoftBusHtoNlTest001
2018060ff233Sopenharmony_ci* @tc.desc: positive
2019060ff233Sopenharmony_ci* @tc.type: FUNC
2020060ff233Sopenharmony_ci* @tc.require: 1
2021060ff233Sopenharmony_ci*/
2022060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusHtoNlTest001, TestSize.Level0)
2023060ff233Sopenharmony_ci{
2024060ff233Sopenharmony_ci    uint32_t hostlong = 0x12345678;
2025060ff233Sopenharmony_ci    uint32_t ret = SoftBusHtoNl(hostlong);
2026060ff233Sopenharmony_ci    EXPECT_EQ(0x78563412, ret);
2027060ff233Sopenharmony_ci}
2028060ff233Sopenharmony_ci
2029060ff233Sopenharmony_ci/*
2030060ff233Sopenharmony_ci* @tc.name: SoftBusHtoNlTest002
2031060ff233Sopenharmony_ci* @tc.desc: positive
2032060ff233Sopenharmony_ci* @tc.type: FUNC
2033060ff233Sopenharmony_ci* @tc.require: 1
2034060ff233Sopenharmony_ci*/
2035060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusHtoNlTest002, TestSize.Level0)
2036060ff233Sopenharmony_ci{
2037060ff233Sopenharmony_ci    uint32_t hostlong = 0x0;
2038060ff233Sopenharmony_ci    uint32_t ret = SoftBusHtoNl(hostlong);
2039060ff233Sopenharmony_ci    EXPECT_EQ(0x0, ret);
2040060ff233Sopenharmony_ci}
2041060ff233Sopenharmony_ci
2042060ff233Sopenharmony_ci/*
2043060ff233Sopenharmony_ci* @tc.name: SoftBusHtoNsTest001
2044060ff233Sopenharmony_ci* @tc.desc: positive
2045060ff233Sopenharmony_ci* @tc.type: FUNC
2046060ff233Sopenharmony_ci* @tc.require: 1
2047060ff233Sopenharmony_ci*/
2048060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusHtoNsTest001, TestSize.Level0)
2049060ff233Sopenharmony_ci{
2050060ff233Sopenharmony_ci    uint16_t hostshort = 0x1234;
2051060ff233Sopenharmony_ci    uint16_t ret = SoftBusHtoNs(hostshort);
2052060ff233Sopenharmony_ci    EXPECT_EQ(0x3412, ret);
2053060ff233Sopenharmony_ci}
2054060ff233Sopenharmony_ci
2055060ff233Sopenharmony_ci/*
2056060ff233Sopenharmony_ci* @tc.name: SoftBusHtoNsTest002
2057060ff233Sopenharmony_ci* @tc.desc: positive
2058060ff233Sopenharmony_ci* @tc.type: FUNC
2059060ff233Sopenharmony_ci* @tc.require: 1
2060060ff233Sopenharmony_ci*/
2061060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusHtoNsTest002, TestSize.Level0)
2062060ff233Sopenharmony_ci{
2063060ff233Sopenharmony_ci    uint16_t hostshort = 0x0;
2064060ff233Sopenharmony_ci    uint16_t ret = SoftBusHtoNs(hostshort);
2065060ff233Sopenharmony_ci    EXPECT_EQ(0x0, ret);
2066060ff233Sopenharmony_ci}
2067060ff233Sopenharmony_ci
2068060ff233Sopenharmony_ci/*
2069060ff233Sopenharmony_ci* @tc.name: SoftBusNtoHlTest001
2070060ff233Sopenharmony_ci* @tc.desc: positive
2071060ff233Sopenharmony_ci* @tc.type: FUNC
2072060ff233Sopenharmony_ci* @tc.require: 1
2073060ff233Sopenharmony_ci*/
2074060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusNtoHlTest001, TestSize.Level0)
2075060ff233Sopenharmony_ci{
2076060ff233Sopenharmony_ci    int32_t netlong = 0x12345678;
2077060ff233Sopenharmony_ci    int32_t ret = SoftBusNtoHl(netlong);
2078060ff233Sopenharmony_ci    EXPECT_EQ(0x78563412, ret);
2079060ff233Sopenharmony_ci}
2080060ff233Sopenharmony_ci
2081060ff233Sopenharmony_ci/*
2082060ff233Sopenharmony_ci* @tc.name: SoftBusNtoHlTest002
2083060ff233Sopenharmony_ci* @tc.desc: positive
2084060ff233Sopenharmony_ci* @tc.type: FUNC
2085060ff233Sopenharmony_ci* @tc.require: 1
2086060ff233Sopenharmony_ci*/
2087060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusNtoHlTest002, TestSize.Level0)
2088060ff233Sopenharmony_ci{
2089060ff233Sopenharmony_ci    uint32_t netlong = 0x12;
2090060ff233Sopenharmony_ci    uint32_t ret = SoftBusNtoHl(netlong);
2091060ff233Sopenharmony_ci    EXPECT_EQ(0x12000000, ret);
2092060ff233Sopenharmony_ci}
2093060ff233Sopenharmony_ci
2094060ff233Sopenharmony_ci/*
2095060ff233Sopenharmony_ci* @tc.name: SoftBusNtoHsTest001
2096060ff233Sopenharmony_ci* @tc.desc: positive
2097060ff233Sopenharmony_ci* @tc.type: FUNC
2098060ff233Sopenharmony_ci* @tc.require: 1
2099060ff233Sopenharmony_ci*/
2100060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusNtoHsTest001, TestSize.Level0)
2101060ff233Sopenharmony_ci{
2102060ff233Sopenharmony_ci    uint16_t netshort = 0x1234;
2103060ff233Sopenharmony_ci    uint16_t ret = SoftBusNtoHs(netshort);
2104060ff233Sopenharmony_ci    EXPECT_EQ(0x3412, ret);
2105060ff233Sopenharmony_ci}
2106060ff233Sopenharmony_ci
2107060ff233Sopenharmony_ci/*
2108060ff233Sopenharmony_ci* @tc.name: SoftBusNtoHsTest002
2109060ff233Sopenharmony_ci* @tc.desc: positive
2110060ff233Sopenharmony_ci* @tc.type: FUNC
2111060ff233Sopenharmony_ci* @tc.require: 1
2112060ff233Sopenharmony_ci*/
2113060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusNtoHsTest002, TestSize.Level0)
2114060ff233Sopenharmony_ci{
2115060ff233Sopenharmony_ci    uint16_t netshort = 0x12;
2116060ff233Sopenharmony_ci    uint16_t ret = SoftBusNtoHs(netshort);
2117060ff233Sopenharmony_ci    EXPECT_EQ(0x1200, ret);
2118060ff233Sopenharmony_ci}
2119060ff233Sopenharmony_ci
2120060ff233Sopenharmony_ci/*
2121060ff233Sopenharmony_ci* @tc.name: SoftBusInetAddrTest001
2122060ff233Sopenharmony_ci* @tc.desc: positive
2123060ff233Sopenharmony_ci* @tc.type: FUNC
2124060ff233Sopenharmony_ci* @tc.require: 1
2125060ff233Sopenharmony_ci*/
2126060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetAddrTest001, TestSize.Level0)
2127060ff233Sopenharmony_ci{
2128060ff233Sopenharmony_ci    const char *cp = "127.0.0.1";
2129060ff233Sopenharmony_ci    int32_t ret = SoftBusInetAddr(cp);
2130060ff233Sopenharmony_ci    EXPECT_EQ(LOCAL_HOST_VALUE, ret);
2131060ff233Sopenharmony_ci}
2132060ff233Sopenharmony_ci
2133060ff233Sopenharmony_ci/*
2134060ff233Sopenharmony_ci* @tc.name: SoftBusInetAddrTest002
2135060ff233Sopenharmony_ci* @tc.desc: invalid cp
2136060ff233Sopenharmony_ci* @tc.type: FUNC
2137060ff233Sopenharmony_ci* @tc.require: 1
2138060ff233Sopenharmony_ci*/
2139060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetAddrTest002, TestSize.Level0)
2140060ff233Sopenharmony_ci{
2141060ff233Sopenharmony_ci    const char *cp = "abcde";
2142060ff233Sopenharmony_ci    int32_t ret = SoftBusInetAddr(cp);
2143060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
2144060ff233Sopenharmony_ci}
2145060ff233Sopenharmony_ci
2146060ff233Sopenharmony_ci/*
2147060ff233Sopenharmony_ci* @tc.name: SoftBusInetAddrTest003
2148060ff233Sopenharmony_ci* @tc.desc: invalid cp
2149060ff233Sopenharmony_ci* @tc.type: FUNC
2150060ff233Sopenharmony_ci* @tc.require: 1
2151060ff233Sopenharmony_ci*/
2152060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetAddrTest003, TestSize.Level0)
2153060ff233Sopenharmony_ci{
2154060ff233Sopenharmony_ci    const char *cp = "0x1234";
2155060ff233Sopenharmony_ci    int32_t ret = SoftBusInetAddr(cp);
2156060ff233Sopenharmony_ci    EXPECT_EQ(0x34120000, ret);
2157060ff233Sopenharmony_ci}
2158060ff233Sopenharmony_ci
2159060ff233Sopenharmony_ci/*
2160060ff233Sopenharmony_ci* @tc.name: SoftBusInetAddrTest004
2161060ff233Sopenharmony_ci* @tc.desc: invalid cp
2162060ff233Sopenharmony_ci* @tc.type: FUNC
2163060ff233Sopenharmony_ci* @tc.require: 1
2164060ff233Sopenharmony_ci*/
2165060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetAddrTest004, TestSize.Level0)
2166060ff233Sopenharmony_ci{
2167060ff233Sopenharmony_ci    const char *cp = "1234";
2168060ff233Sopenharmony_ci    int32_t ret = SoftBusInetAddr(cp);
2169060ff233Sopenharmony_ci    EXPECT_EQ(0xD2040000, ret);
2170060ff233Sopenharmony_ci}
2171060ff233Sopenharmony_ci
2172060ff233Sopenharmony_ci/*
2173060ff233Sopenharmony_ci* @tc.name: SoftBusInetAddrTest005
2174060ff233Sopenharmony_ci* @tc.desc: invalid cp
2175060ff233Sopenharmony_ci* @tc.type: FUNC
2176060ff233Sopenharmony_ci* @tc.require: 1
2177060ff233Sopenharmony_ci*/
2178060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusInetAddrTest005, TestSize.Level0)
2179060ff233Sopenharmony_ci{
2180060ff233Sopenharmony_ci    const char *cp = "adc1234";
2181060ff233Sopenharmony_ci    int32_t ret = SoftBusInetAddr(cp);
2182060ff233Sopenharmony_ci    EXPECT_EQ(-1, ret);
2183060ff233Sopenharmony_ci}
2184060ff233Sopenharmony_ci
2185060ff233Sopenharmony_ci/*
2186060ff233Sopenharmony_ci* @tc.name: SoftBusIfNameToIndexTest001
2187060ff233Sopenharmony_ci* @tc.desc: chba0
2188060ff233Sopenharmony_ci* @tc.type: FUNC
2189060ff233Sopenharmony_ci* @tc.require: 4
2190060ff233Sopenharmony_ci*/
2191060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusIfNameToIndexTest001, TestSize.Level0)
2192060ff233Sopenharmony_ci{
2193060ff233Sopenharmony_ci    const char *ifname = "wlan0";
2194060ff233Sopenharmony_ci    int32_t ret = SoftBusIfNameToIndex(ifname);
2195060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
2196060ff233Sopenharmony_ci}
2197060ff233Sopenharmony_ci
2198060ff233Sopenharmony_ci/*
2199060ff233Sopenharmony_ci* @tc.name: SoftBusIndexToIfNameTest001
2200060ff233Sopenharmony_ci* @tc.desc: invalidIndex
2201060ff233Sopenharmony_ci* @tc.type: FUNC
2202060ff233Sopenharmony_ci* @tc.require: SOFTBUS_ADAPTER_ERR
2203060ff233Sopenharmony_ci*/
2204060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusIndexToIfNameTest001, TestSize.Level0)
2205060ff233Sopenharmony_ci{
2206060ff233Sopenharmony_ci    char ifname[IF_NAME_SIZE] = { 0 };
2207060ff233Sopenharmony_ci    int32_t invalidIndex = -1;
2208060ff233Sopenharmony_ci    int32_t ret = SoftBusIndexToIfName(invalidIndex, ifname, IF_NAME_SIZE);
2209060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_ERR, ret);
2210060ff233Sopenharmony_ci}
2211060ff233Sopenharmony_ci
2212060ff233Sopenharmony_ci/*
2213060ff233Sopenharmony_ci* @tc.name: SoftBusIndexToIfNameTest001
2214060ff233Sopenharmony_ci* @tc.desc: invalidIndex
2215060ff233Sopenharmony_ci* @tc.type: FUNC
2216060ff233Sopenharmony_ci* @tc.require: SOFTBUS_INVALID_PARAM
2217060ff233Sopenharmony_ci*/
2218060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusIndexToIfNameTest002, TestSize.Level0)
2219060ff233Sopenharmony_ci{
2220060ff233Sopenharmony_ci    char ifname[IF_NAME_SIZE] = { 0 };
2221060ff233Sopenharmony_ci    int32_t invalidIndex = 1000;
2222060ff233Sopenharmony_ci    int32_t ret = SoftBusIndexToIfName(invalidIndex, ifname, IF_NAME_SIZE);
2223060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
2224060ff233Sopenharmony_ci}
2225060ff233Sopenharmony_ci
2226060ff233Sopenharmony_ci/*
2227060ff233Sopenharmony_ci* @tc.name: SoftBusIndexToIfNameTest001
2228060ff233Sopenharmony_ci* @tc.desc: WLAN_INDEX
2229060ff233Sopenharmony_ci* @tc.type: FUNC
2230060ff233Sopenharmony_ci* @tc.require: SOFTBUS_ADAPTER_OK
2231060ff233Sopenharmony_ci*/
2232060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusIndexToIfNameTest003, TestSize.Level0)
2233060ff233Sopenharmony_ci{
2234060ff233Sopenharmony_ci    char ifname[IF_NAME_SIZE] = { 0 };
2235060ff233Sopenharmony_ci    int32_t ret = SoftBusIndexToIfName(WLAN_INDEX, ifname, IF_NAME_SIZE);
2236060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ADAPTER_OK, ret);
2237060ff233Sopenharmony_ci}
2238060ff233Sopenharmony_ci
2239060ff233Sopenharmony_ci/*
2240060ff233Sopenharmony_ci* @tc.name: SoftBusSocketFullFunc001
2241060ff233Sopenharmony_ci* @tc.desc: Cover Serial Multiple Interfaces
2242060ff233Sopenharmony_ci* @tc.type: FUNC
2243060ff233Sopenharmony_ci* @tc.require:
2244060ff233Sopenharmony_ci*/
2245060ff233Sopenharmony_ciHWTEST_F(AdapterDsoftbusSocketTest, SoftBusSocketFullFunc001, TestSize.Level0)
2246060ff233Sopenharmony_ci{
2247060ff233Sopenharmony_ci    sleep(1);
2248060ff233Sopenharmony_ci    int32_t pid = -1;
2249060ff233Sopenharmony_ci    if ((pid = fork()) == 0) {
2250060ff233Sopenharmony_ci        SocketServiceStart(0);
2251060ff233Sopenharmony_ci        return;
2252060ff233Sopenharmony_ci    }
2253060ff233Sopenharmony_ci    sleep(1);
2254060ff233Sopenharmony_ci    int32_t ret;
2255060ff233Sopenharmony_ci    int32_t socketFd = -1;
2256060ff233Sopenharmony_ci    struct SocketProtocol buf = {0};
2257060ff233Sopenharmony_ci
2258060ff233Sopenharmony_ci    ClientConnect(&socketFd);
2259060ff233Sopenharmony_ci    EXPECT_TRUE(socketFd != -1);
2260060ff233Sopenharmony_ci
2261060ff233Sopenharmony_ci    buf.cmd = CMD_RECV;
2262060ff233Sopenharmony_ci    (void)strncpy_s(buf.data, sizeof(buf.data), "Happy New Year!", sizeof(buf.data));
2263060ff233Sopenharmony_ci    ret = SoftBusSocketSend(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
2264060ff233Sopenharmony_ci    sleep(1);
2265060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
2266060ff233Sopenharmony_ci    printf("data is %s\n", buf.data);
2267060ff233Sopenharmony_ci
2268060ff233Sopenharmony_ci    (void)memset_s(&buf, sizeof(struct SocketProtocol), 0, sizeof(struct SocketProtocol));
2269060ff233Sopenharmony_ci    ret = SoftBusSocketRecv(socketFd, (void *)&buf, sizeof(struct SocketProtocol), 0);
2270060ff233Sopenharmony_ci    EXPECT_TRUE(ret >= 0);
2271060ff233Sopenharmony_ci    printf("data is %s\n", buf.data);
2272060ff233Sopenharmony_ci
2273060ff233Sopenharmony_ci    ClientExit(socketFd);
2274060ff233Sopenharmony_ci}
2275060ff233Sopenharmony_ci}
2276