1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "uds_socket.h"
19
20 namespace OHOS {
21 namespace MMI {
22 namespace {
23 using namespace testing::ext;
24 } // namespace
25
26 class UDSSocketTest : public testing::Test {
27 public:
SetUpTestCase(void)28 static void SetUpTestCase(void) {}
TearDownTestCase(void)29 static void TearDownTestCase(void) {}
30 };
31
32 class UDSSocketUnitTest : public UDSSocket {
33 public:
UDSSocketUnitTest()34 UDSSocketUnitTest() {}
~UDSSocketUnitTest()35 virtual ~UDSSocketUnitTest() {}
36 };
37
HWTEST_F(UDSSocketTest, Close, TestSize.Level1)38 HWTEST_F(UDSSocketTest, Close, TestSize.Level1)
39 {
40 UDSSocketUnitTest socObj;
41 socObj.Close();
42 EXPECT_EQ(-1, socObj.GetFd());
43 }
44
HWTEST_F(UDSSocketTest, EpollCreate_001, TestSize.Level1)45 HWTEST_F(UDSSocketTest, EpollCreate_001, TestSize.Level1)
46 {
47 int32_t size = 0;
48
49 UDSSocketUnitTest socObj;
50 int32_t retResult = socObj.EpollCreate(size);
51 ASSERT_LE(retResult, 0);
52 }
53
HWTEST_F(UDSSocketTest, EpollCreate_002, TestSize.Level1)54 HWTEST_F(UDSSocketTest, EpollCreate_002, TestSize.Level1)
55 {
56 int32_t size = -1001;
57
58 UDSSocketUnitTest socObj;
59 int32_t retResult = socObj.EpollCreate(size);
60 ASSERT_LE(retResult, 0);
61 }
62
HWTEST_F(UDSSocketTest, EpollCtl_001, TestSize.Level1)63 HWTEST_F(UDSSocketTest, EpollCtl_001, TestSize.Level1)
64 {
65 int32_t fd = 1001;
66 int32_t op = 0;
67 struct epoll_event event = {};
68
69 UDSSocketUnitTest socObj;
70 int32_t retResult = socObj.EpollCtl(fd, op, event);
71 ASSERT_EQ(-1, retResult);
72 }
73
HWTEST_F(UDSSocketTest, EpollCtl_003, TestSize.Level1)74 HWTEST_F(UDSSocketTest, EpollCtl_003, TestSize.Level1)
75 {
76 int32_t fd = -1001;
77 int32_t op = 1001;
78 struct epoll_event event = {};
79
80 UDSSocketUnitTest socObj;
81 int32_t retResult = socObj.EpollCtl(fd, op, event);
82 ASSERT_EQ(-1, retResult);
83 }
84
HWTEST_F(UDSSocketTest, EpollCtl_004, TestSize.Level1)85 HWTEST_F(UDSSocketTest, EpollCtl_004, TestSize.Level1)
86 {
87 int32_t fd = -1001;
88 int32_t op = -2002;
89 struct epoll_event event = {};
90
91 UDSSocketUnitTest socObj;
92 int32_t retResult = socObj.EpollCtl(fd, op, event);
93 ASSERT_EQ(-1, retResult);
94 }
95
HWTEST_F(UDSSocketTest, EpollWait_001, TestSize.Level1)96 HWTEST_F(UDSSocketTest, EpollWait_001, TestSize.Level1)
97 {
98 struct epoll_event events[MAX_EVENT_SIZE] = {};
99 int32_t timeout = -1;
100
101 UDSSocketUnitTest socObj;
102 int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
103 ASSERT_EQ(-1, retResult);
104 }
105
HWTEST_F(UDSSocketTest, EpollWait_002, TestSize.Level1)106 HWTEST_F(UDSSocketTest, EpollWait_002, TestSize.Level1)
107 {
108 struct epoll_event events[MAX_EVENT_SIZE] = {};
109 int32_t timeout = 1001;
110
111 UDSSocketUnitTest socObj;
112 int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
113 ASSERT_EQ(-1, retResult);
114 }
115
HWTEST_F(UDSSocketTest, EpollWait_003, TestSize.Level1)116 HWTEST_F(UDSSocketTest, EpollWait_003, TestSize.Level1)
117 {
118 struct epoll_event events[MAX_EVENT_SIZE] = {};
119 int32_t timeout = -1001;
120
121 UDSSocketUnitTest socObj;
122 int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
123 ASSERT_EQ(-1, retResult);
124 }
125
HWTEST_F(UDSSocketTest, EpollWait_004, TestSize.Level1)126 HWTEST_F(UDSSocketTest, EpollWait_004, TestSize.Level1)
127 {
128 struct epoll_event events[MAX_EVENT_SIZE] = {};
129 int32_t timeout = -1001;
130
131 UDSSocketUnitTest socObj;
132 int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
133 ASSERT_EQ(-1, retResult);
134 }
135 } // namespace MMI
136 } // namespace OHOS
137