106f6ba60Sopenharmony_ci/*
206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License.
506f6ba60Sopenharmony_ci * You may obtain a copy of the License at
606f6ba60Sopenharmony_ci *
706f6ba60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
806f6ba60Sopenharmony_ci *
906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and
1306f6ba60Sopenharmony_ci * limitations under the License.
1406f6ba60Sopenharmony_ci */
1506f6ba60Sopenharmony_ci
1606f6ba60Sopenharmony_ci#include <gtest/gtest.h>
1706f6ba60Sopenharmony_ci#include "socket_context.h"
1806f6ba60Sopenharmony_ci
1906f6ba60Sopenharmony_ciusing namespace testing::ext;
2006f6ba60Sopenharmony_ci
2106f6ba60Sopenharmony_cinamespace {
2206f6ba60Sopenharmony_ciclass SocketContextTest : public testing::Test {
2306f6ba60Sopenharmony_cipublic:
2406f6ba60Sopenharmony_ci    static void SetUpTestCase() {}
2506f6ba60Sopenharmony_ci
2606f6ba60Sopenharmony_ci    static void TearDownTestCase() {}
2706f6ba60Sopenharmony_ci    void SetUp() {}
2806f6ba60Sopenharmony_ci    void TearDown() {}
2906f6ba60Sopenharmony_ci};
3006f6ba60Sopenharmony_ci
3106f6ba60Sopenharmony_ci/**
3206f6ba60Sopenharmony_ci * @tc.name: Service
3306f6ba60Sopenharmony_ci * @tc.desc: Socket send file descriptor test.
3406f6ba60Sopenharmony_ci * @tc.type: FUNC
3506f6ba60Sopenharmony_ci */
3606f6ba60Sopenharmony_ciHWTEST_F(SocketContextTest, SendFileDescriptor, TestSize.Level1)
3706f6ba60Sopenharmony_ci{
3806f6ba60Sopenharmony_ci    SocketContext socketContext;
3906f6ba60Sopenharmony_ci    ASSERT_TRUE(!socketContext.SendFileDescriptor(-1));
4006f6ba60Sopenharmony_ci    ASSERT_TRUE(!socketContext.SendFileDescriptor(1));
4106f6ba60Sopenharmony_ci}
4206f6ba60Sopenharmony_ci
4306f6ba60Sopenharmony_ci/**
4406f6ba60Sopenharmony_ci * @tc.name: Service
4506f6ba60Sopenharmony_ci * @tc.desc: Abnormal socket detection.
4606f6ba60Sopenharmony_ci * @tc.type: FUNC
4706f6ba60Sopenharmony_ci */
4806f6ba60Sopenharmony_ciHWTEST_F(SocketContextTest, RawProtocolProc, TestSize.Level1)
4906f6ba60Sopenharmony_ci{
5006f6ba60Sopenharmony_ci    std::string s="abc";
5106f6ba60Sopenharmony_ci    SocketContext socketContext;
5206f6ba60Sopenharmony_ci    std::vector<unsigned char> buf(64); // 64: the buf size
5306f6ba60Sopenharmony_ci    ASSERT_EQ(socketContext.RawProtocolProc(2, (const int8_t *)s.c_str(), s.size()), -1);
5406f6ba60Sopenharmony_ci    EXPECT_FALSE(socketContext.ReceiveData(-1, buf.data(), buf.size()));
5506f6ba60Sopenharmony_ci    EXPECT_FALSE(socketContext.ReceiveData(1, nullptr, 0));
5606f6ba60Sopenharmony_ci    EXPECT_FALSE(socketContext.SendRaw(1, (const int8_t *)s.c_str(), s.size(), -1));
5706f6ba60Sopenharmony_ci}
5806f6ba60Sopenharmony_ci
5906f6ba60Sopenharmony_ci/**
6006f6ba60Sopenharmony_ci * @tc.name: Service
6106f6ba60Sopenharmony_ci * @tc.desc: Socket receiving test.
6206f6ba60Sopenharmony_ci * @tc.type: FUNC
6306f6ba60Sopenharmony_ci */
6406f6ba60Sopenharmony_ciHWTEST_F(SocketContextTest, ReceiveFileDiscriptor, TestSize.Level1)
6506f6ba60Sopenharmony_ci{
6606f6ba60Sopenharmony_ci    SocketContext socketContext;
6706f6ba60Sopenharmony_ci    ASSERT_EQ(socketContext.ReceiveFileDiscriptor(), -1);
6806f6ba60Sopenharmony_ci}
6906f6ba60Sopenharmony_ci/**
7006f6ba60Sopenharmony_ci * @tc.name: Service
7106f6ba60Sopenharmony_ci * @tc.desc: Socket send heart beat test.
7206f6ba60Sopenharmony_ci * @tc.type: FUNC
7306f6ba60Sopenharmony_ci */
7406f6ba60Sopenharmony_ciHWTEST_F(SocketContextTest, SendHeartBeat, TestSize.Level1)
7506f6ba60Sopenharmony_ci{
7606f6ba60Sopenharmony_ci    SocketContext socketContext;
7706f6ba60Sopenharmony_ci    EXPECT_FALSE(socketContext.SendHeartBeat());
7806f6ba60Sopenharmony_ci    EXPECT_FALSE(socketContext.SendHookConfig(nullptr, 0));
7906f6ba60Sopenharmony_ci}
8006f6ba60Sopenharmony_ci
8106f6ba60Sopenharmony_ci} // namespace