• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gtest/gtest.h>
16 
17 #include "uds_socket.h"
18 
19 namespace OHOS {
20 namespace MMI {
21 namespace {
22 using namespace testing::ext;
23 } // namespace
24 
25 class UDSSocketTest : public testing::Test {
26 public:
SetUpTestCase(void)27     static void SetUpTestCase(void) {}
TearDownTestCase(void)28     static void TearDownTestCase(void) {}
29 };
30 
31 class UDSSocketUnitTest : public UDSSocket {
32 public:
UDSSocketUnitTest()33     UDSSocketUnitTest() {}
~UDSSocketUnitTest()34     virtual ~UDSSocketUnitTest() {}
35 };
36 
37 HWTEST_F(UDSSocketTest, Close, TestSize.Level1)
38 {
39     UDSSocketUnitTest socObj;
40     socObj.Close();
41     EXPECT_EQ(-1, socObj.GetFd());
42 }
43 
44 HWTEST_F(UDSSocketTest, EpollCreate_001, TestSize.Level1)
45 {
46     int32_t size = 0;
47 
48     UDSSocketUnitTest socObj;
49     int32_t retResult = socObj.EpollCreate(size);
50     ASSERT_LE(retResult, 0);
51 }
52 
53 HWTEST_F(UDSSocketTest, EpollCreate_002, TestSize.Level1)
54 {
55     int32_t size = -1001;
56 
57     UDSSocketUnitTest socObj;
58     int32_t retResult = socObj.EpollCreate(size);
59     ASSERT_LE(retResult, 0);
60 }
61 
62 HWTEST_F(UDSSocketTest, EpollCtl_001, TestSize.Level1)
63 {
64     int32_t fd = 1001;
65     int32_t op = 0;
66     struct epoll_event event = {};
67 
68     UDSSocketUnitTest socObj;
69     int32_t retResult = socObj.EpollCtl(fd, op, event);
70     ASSERT_EQ(-1, retResult);
71 }
72 
73 HWTEST_F(UDSSocketTest, EpollCtl_003, TestSize.Level1)
74 {
75     int32_t fd = -1001;
76     int32_t op = 1001;
77     struct epoll_event event = {};
78 
79     UDSSocketUnitTest socObj;
80     int32_t retResult = socObj.EpollCtl(fd, op, event);
81     ASSERT_EQ(-1, retResult);
82 }
83 
84 HWTEST_F(UDSSocketTest, EpollCtl_004, TestSize.Level1)
85 {
86     int32_t fd = -1001;
87     int32_t op = -2002;
88     struct epoll_event event = {};
89 
90     UDSSocketUnitTest socObj;
91     int32_t retResult = socObj.EpollCtl(fd, op, event);
92     ASSERT_EQ(-1, retResult);
93 }
94 
95 HWTEST_F(UDSSocketTest, EpollWait_001, TestSize.Level1)
96 {
97     struct epoll_event events[MAX_EVENT_SIZE] = {};
98     int32_t timeout = -1;
99 
100     UDSSocketUnitTest socObj;
101     int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
102     ASSERT_EQ(-1, retResult);
103 }
104 
105 HWTEST_F(UDSSocketTest, EpollWait_002, TestSize.Level1)
106 {
107     struct epoll_event events[MAX_EVENT_SIZE] = {};
108     int32_t timeout = 1001;
109 
110     UDSSocketUnitTest socObj;
111     int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
112     ASSERT_EQ(-1, retResult);
113 }
114 
115 HWTEST_F(UDSSocketTest, EpollWait_003, TestSize.Level1)
116 {
117     struct epoll_event events[MAX_EVENT_SIZE] = {};
118     int32_t timeout = -1001;
119 
120     UDSSocketUnitTest socObj;
121     int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
122     ASSERT_EQ(-1, retResult);
123 }
124 
125 HWTEST_F(UDSSocketTest, EpollWait_004, TestSize.Level1)
126 {
127     struct epoll_event events[MAX_EVENT_SIZE] = {};
128     int32_t timeout = -1001;
129 
130     UDSSocketUnitTest socObj;
131     int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
132     ASSERT_EQ(-1, retResult);
133 }
134 } // namespace MMI
135 } // namespace OHOS
136