1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <gtest/gtest.h>
16 #include <securec.h>
17
18 #include "softbus_error_code.h"
19 #include "softbus_def.h"
20 #include "softbus_adapter_mem.h"
21 #include "softbus_htp_socket_mock.h"
22 #include "softbus_htp_socket.c"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 class SoftbusHtpSocketMockTest : public testing::Test {
29 public:
SoftbusHtpSocketMockTest()30 SoftbusHtpSocketMockTest() { }
~SoftbusHtpSocketMockTest()31 ~SoftbusHtpSocketMockTest() { }
32 static void SetUpTestCase(void);
33 static void TearDownTestCase(void);
SetUp()34 void SetUp() override { }
TearDown()35 void TearDown() override { }
36 };
37
SetUpTestCase(void)38 void SoftbusHtpSocketMockTest::SetUpTestCase(void) { }
39
TearDownTestCase(void)40 void SoftbusHtpSocketMockTest::TearDownTestCase(void) { }
41
42 /**
43 * @tc.name: SoftbusHtpSocketMockTest001
44 * @tc.desc: test AcceptHtpClient function.
45 * @tc.type: FUNC
46 * @tc.require:
47 */
48 HWTEST_F(SoftbusHtpSocketMockTest, SoftbusHtpSocketMockTest001, TestSize.Level1)
49 {
50 int32_t fd = 1;
51 int32_t cfd = 1;
52 ConnectOption *clientAddr = static_cast<ConnectOption *>(SoftBusCalloc(sizeof(ConnectOption)));
53 EXPECT_TRUE(clientAddr != nullptr);
54
55 NiceMock<SoftbusHtpSocketMock> softbusHtpSocketMock;
56 EXPECT_CALL(softbusHtpSocketMock, SoftBusSocketAccept).WillOnce(Return(SOFTBUS_OK));
57
58 int32_t ret = AcceptHtpClient(fd, clientAddr, &cfd);
59 EXPECT_EQ(ret, SOFTBUS_OK);
60 SoftBusFree(clientAddr);
61 }
62
63 /**
64 * @tc.name: SoftbusHtpSocketMockTest001
65 * @tc.desc: test AcceptHtpClient function.
66 * @tc.type: FUNC
67 * @tc.require:
68 */
69 HWTEST_F(SoftbusHtpSocketMockTest, SoftbusHtpSocketMockTest002, TestSize.Level1)
70 {
71 int32_t fd = 1;
72
73 NiceMock<SoftbusHtpSocketMock> softbusHtpSocketMock;
74 EXPECT_CALL(softbusHtpSocketMock, SoftBusSocketGetLocalName).WillOnce(Return(SOFTBUS_OK));
75
76 int32_t ret = GetHtpSockPort(fd);
77 EXPECT_EQ(ret, SOFTBUS_OK);
78 }
79 }
80