• 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 
16 #include "uds_socket.h"
17 #include <gtest/gtest.h>
18 
19 namespace {
20 using namespace testing::ext;
21 using namespace OHOS::MMI;
22 
23 class UDSSocketTest : public testing::Test {
24 public:
SetUpTestCase(void)25     static void SetUpTestCase(void) {}
TearDownTestCase(void)26     static void TearDownTestCase(void) {}
27 };
28 
29 class UDSSocketUnitTest : public UDSSocket {
30 public:
UDSSocketUnitTest()31     UDSSocketUnitTest() {}
~UDSSocketUnitTest()32     virtual ~UDSSocketUnitTest() {}
33 };
34 
35 #if BINDER_TODO
36 
37 HWTEST_F(UDSSocketTest, Close, TestSize.Level1)
38 {
39     UDSSocketUnitTest socObj;
40     int32_t retResult = socObj.Close();
41     EXPECT_EQ(RET_OK, retResult);
42 }
43 
44 HWTEST_F(UDSSocketTest, Bind_001, TestSize.Level1)
45 {
46     char path[1] = "";
47 
48     UDSSocketUnitTest socObj;
49     int32_t retResult = socObj.Bind(path);
50     ASSERT_EQ(-1, retResult);
51 }
52 
53 HWTEST_F(UDSSocketTest, Bind_002, TestSize.Level1)
54 {
55     char path[] = "./";
56 
57     UDSSocketUnitTest socObj;
58     int32_t retResult = socObj.Bind(path);
59     ASSERT_EQ(-1, retResult);
60 }
61 
62 HWTEST_F(UDSSocketTest, Connect_001, TestSize.Level1)
63 {
64     char path[] = "3362";
65 
66     UDSSocketUnitTest socObj;
67     int32_t retResult = socObj.Connect(path);
68     ASSERT_EQ(-1, retResult);
69 }
70 
71 HWTEST_F(UDSSocketTest, Connect_002, TestSize.Level1)
72 {
73     char path[] = "./";
74 
75     UDSSocketUnitTest socObj;
76     int32_t retResult = socObj.Connect(path);
77     ASSERT_EQ(-1, retResult);
78 }
79 
80 HWTEST_F(UDSSocketTest, Listen_001, TestSize.Level1)
81 {
82     int32_t n = -1001;
83 
84     UDSSocketUnitTest socObj;
85     int32_t retResult = socObj.Listen(n);
86     ASSERT_EQ(-1, retResult);
87 }
88 
89 HWTEST_F(UDSSocketTest, Listen_002, TestSize.Level1)
90 {
91     int32_t n = 1001;
92 
93     UDSSocketUnitTest socObj;
94     int32_t retResult = socObj.Listen(n);
95     ASSERT_EQ(-1, retResult);
96 }
97 
98 HWTEST_F(UDSSocketTest, Accept_001, TestSize.Level1)
99 {
100     sockaddr_un addr;
101 
102     UDSSocketUnitTest socObj;
103     int32_t retResult = socObj.Accept(addr);
104     EXPECT_EQ(-1, retResult);
105 }
106 
107 HWTEST_F(UDSSocketTest, Accept_002, TestSize.Level1)
108 {
109     sockaddr_un addr = {};
110 
111     UDSSocketUnitTest socObj;
112     int32_t retResult = socObj.Accept(addr);
113     EXPECT_EQ(-1, retResult);
114 }
115 
116 HWTEST_F(UDSSocketTest, Read_001, TestSize.Level1)
117 {
118     char buf[] = "";
119     size_t size = 1;
120 
121     UDSSocketUnitTest socObj;
122     socObj.ReadUnitTest(buf, size);
123 }
124 
125 HWTEST_F(UDSSocketTest, Read002, TestSize.Level1)
126 {
127     char buf[] = "THIS IS RECEIVE DATA";
128     size_t size = 20;
129 
130     UDSSocketUnitTest socObj;
131     socObj.ReadUnitTest(buf, size);
132 }
133 
134 HWTEST_F(UDSSocketTest, Read003, TestSize.Level1)
135 {
136     char buf[] = "This is receive data.";
137     size_t size = -21;
138 
139     UDSSocketUnitTest socObj;
140     socObj.ReadUnitTest(buf, size);
141 }
142 
143 HWTEST_F(UDSSocketTest, Read004, TestSize.Level1)
144 {
145     char *buf = nullptr;
146     size_t size = 20;
147 
148     UDSSocketUnitTest socObj;
149     socObj.ReadUnitTest(buf, size);
150 }
151 
152 HWTEST_F(UDSSocketTest, Write_001, TestSize.Level1)
153 {
154     const char *buf = "";
155     size_t size = 1;
156     UDSSocketUnitTest socObj;
157 
158     socObj.WriteUnitTest(buf, size);
159 }
160 
161 HWTEST_F(UDSSocketTest, Write_002, TestSize.Level1)
162 {
163     const char *buf = nullptr;
164     size_t size = 1;
165     UDSSocketUnitTest socObj;
166 
167     socObj.WriteUnitTest(buf, size);
168 }
169 
170 HWTEST_F(UDSSocketTest, Write_003, TestSize.Level1)
171 {
172     const char *buf = "THIS IS WRITE DATA";
173     size_t size = 18;
174     UDSSocketUnitTest socObj;
175 
176     socObj.WriteUnitTest(buf, size);
177 }
178 
179 HWTEST_F(UDSSocketTest, Write_004, TestSize.Level1)
180 {
181     const char *buf = "this is write data";
182     size_t size = -18;
183     UDSSocketUnitTest socObj;
184 
185     socObj.WriteUnitTest(buf, size);
186 }
187 
188 HWTEST_F(UDSSocketTest, Send_001, TestSize.Level1)
189 {
190     const char *buf = "";
191     size_t size = 1;
192     int32_t flags = 0;
193 
194     UDSSocketUnitTest socObj;
195     socObj.SendUnitTest(buf, size, flags);
196 }
197 
198 HWTEST_F(UDSSocketTest, Send_002, TestSize.Level1)
199 {
200     const char *buf = "THIS IS RECEIVE DATA";
201     size_t size = 18;
202     int32_t flags = 0;
203 
204     UDSSocketUnitTest socObj;
205     socObj.SendUnitTest(buf, size, flags);
206 }
207 
208 HWTEST_F(UDSSocketTest, Send_003, TestSize.Level1)
209 {
210     const char *buf = "This is receive data.";
211     size_t size = -18;
212     int32_t flags = 0;
213 
214     UDSSocketUnitTest socObj;
215     socObj.SendUnitTest(buf, size, flags);
216 }
217 
218 HWTEST_F(UDSSocketTest, Send_004, TestSize.Level1)
219 {
220     const char *buf = "data";
221     size_t size = 4;
222     int32_t flags = 1;
223 
224     UDSSocketUnitTest socObj;
225     socObj.SendUnitTest(buf, size, flags);
226 }
227 
228 HWTEST_F(UDSSocketTest, Send_005, TestSize.Level1)
229 {
230     const char *buf = nullptr;
231     size_t size = 0;
232     int32_t flags = 1;
233 
234     UDSSocketUnitTest socObj;
235     socObj.SendUnitTest(buf, size, flags);
236 }
237 
238 HWTEST_F(UDSSocketTest, Recv_001, TestSize.Level1)
239 {
240     char buf[] = "";
241     size_t size = 1;
242     int32_t flags = 0;
243 
244     UDSSocketUnitTest socObj;
245     socObj.RecvUnitTest(buf, size, flags);
246 }
247 
248 HWTEST_F(UDSSocketTest, Recv_002, TestSize.Level1)
249 {
250     char buf[] = "This is Recv data.";
251     size_t size = 18;
252     int32_t flags = 0;
253 
254     UDSSocketUnitTest socObj;
255     socObj.RecvUnitTest(buf, size, flags);
256 }
257 
258 HWTEST_F(UDSSocketTest, Recv_003, TestSize.Level1)
259 {
260     char buf[] = "This is Recv data.";
261     size_t size = -18;
262     int32_t flags = 0;
263 
264     UDSSocketUnitTest socObj;
265     socObj.RecvUnitTest(buf, size, flags);
266 }
267 
268 HWTEST_F(UDSSocketTest, Recv_004, TestSize.Level1)
269 {
270     char buf[] = "This is Recv data.";
271     size_t size = 0;
272     int32_t flags = 1;
273 
274     UDSSocketUnitTest socObj;
275     socObj.RecvUnitTest(buf, size, flags);
276 }
277 
278 HWTEST_F(UDSSocketTest, Recv_005, TestSize.Level1)
279 {
280     char *buf = nullptr;
281     size_t size = 18;
282     int32_t flags = 0;
283 
284     UDSSocketUnitTest socObj;
285     socObj.RecvUnitTest(buf, size, flags);
286 }
287 
288 HWTEST_F(UDSSocketTest, Recv_006, TestSize.Level1)
289 {
290     char *buf = nullptr;
291     size_t size = 0;
292     int32_t flags = 0;
293 
294     UDSSocketUnitTest socObj;
295     socObj.RecvUnitTest(buf, size, flags);
296 }
297 
298 HWTEST_F(UDSSocketTest, Recvfrom_001, TestSize.Level1)
299 {
300     char buf[] = "";
301     size_t size = 1;
302     sockaddr *addr = nullptr;
303     size_t *addrlen = nullptr;
304     uint32_t flags = 0;
305 
306     UDSSocketUnitTest socObj;
307     socObj.RecvfromUnitTest(buf, size, flags, addr, addrlen);
308 }
309 
310 HWTEST_F(UDSSocketTest, Recvfrom_002, TestSize.Level1)
311 {
312     char buf[] = "This Data";
313     size_t size = 1;
314     sockaddr *addr = nullptr;
315     size_t *addrlen = nullptr;
316     uint32_t flags = 0;
317 
318     UDSSocketUnitTest socObj;
319     socObj.RecvfromUnitTest(buf, size, flags, addr, addrlen);
320 }
321 
322 HWTEST_F(UDSSocketTest, Recvfrom_003, TestSize.Level1)
323 {
324     char buf[] = "This Data";
325     size_t size = 1;
326     sockaddr *addr = {};
327     size_t *addrlen = nullptr;
328     uint32_t flags = 10;
329 
330     UDSSocketUnitTest socObj;
331     socObj.RecvfromUnitTest(buf, size, flags, addr, addrlen);
332 }
333 
334 HWTEST_F(UDSSocketTest, Sendto_001, TestSize.Level1)
335 {
336     const char *buf = "";
337     size_t size = 1;
338     sockaddr *addr = nullptr;
339     size_t addrlen = 0;
340     uint32_t flags = 0;
341 
342     UDSSocketUnitTest socObj;
343     socObj.SendtoUnitTest(buf, size, flags, addr, addrlen);
344 }
345 
346 HWTEST_F(UDSSocketTest, Sendto_002, TestSize.Level1)
347 {
348     const char *buf = "This is send to data.";
349     size_t size = 21;
350     sockaddr *addr = nullptr;
351     size_t addrlen = 0;
352     uint32_t flags = 0;
353 
354     UDSSocketUnitTest socObj;
355     socObj.SendtoUnitTest(buf, size, flags, addr, addrlen);
356 }
357 
358 HWTEST_F(UDSSocketTest, Sendto_003, TestSize.Level1)
359 {
360     const char *buf = "This is send to data.";
361     size_t size = 21;
362     sockaddr *addr = {};
363     size_t addrlen = 0;
364     uint32_t flags = 0;
365 
366     UDSSocketUnitTest socObj;
367     socObj.SendtoUnitTest(buf, size, flags, addr, addrlen);
368 }
369 
370 HWTEST_F(UDSSocketTest, Sendto_004, TestSize.Level1)
371 {
372     const char *buf = "This is send to data.";
373     size_t size = 21;
374     sockaddr *addr = {};
375     size_t addrlen = 10;
376     uint32_t flags = 0;
377 
378     UDSSocketUnitTest socObj;
379     socObj.SendtoUnitTest(buf, size, flags, addr, addrlen);
380 }
381 
382 HWTEST_F(UDSSocketTest, Sendto_005, TestSize.Level1)
383 {
384     const char *buf = "This is send to data.";
385     size_t size = 21;
386     sockaddr *addr = {};
387     size_t addrlen = 10;
388     uint32_t flags = 22;
389 
390     UDSSocketUnitTest socObj;
391     socObj.SendtoUnitTest(buf, size, flags, addr, addrlen);
392 }
393 
394 HWTEST_F(UDSSocketTest, EpollCreat_001, TestSize.Level1)
395 {
396     int32_t size = 0;
397 
398     UDSSocketUnitTest socObj;
399     int32_t retResult = socObj.EpollCreat(size);
400     ASSERT_EQ(-1, retResult);
401 }
402 
403 HWTEST_F(UDSSocketTest, EpollCreat_002, TestSize.Level1)
404 {
405     int32_t size = -1001;
406 
407     UDSSocketUnitTest socObj;
408     int32_t retResult = socObj.EpollCreat(size);
409     ASSERT_EQ(-1, retResult);
410 }
411 
412 HWTEST_F(UDSSocketTest, EpollCtl_001, TestSize.Level1)
413 {
414     int32_t fd = 1001;
415     int32_t op = 0;
416     struct epoll_event event = {};
417 
418     UDSSocketUnitTest socObj;
419     int32_t retResult = socObj.EpollCtl(fd, op, event);
420     ASSERT_EQ(-1, retResult);
421 }
422 
423 HWTEST_F(UDSSocketTest, EpollCtl_003, TestSize.Level1)
424 {
425     int32_t fd = -1001;
426     int32_t op = 1001;
427     struct epoll_event event = {};
428 
429     UDSSocketUnitTest socObj;
430     int32_t retResult = socObj.EpollCtl(fd, op, event);
431     ASSERT_EQ(-1, retResult);
432 }
433 
434 HWTEST_F(UDSSocketTest, EpollCtl_004, TestSize.Level1)
435 {
436     int32_t fd = -1001;
437     int32_t op = -2002;
438     struct epoll_event event = {};
439 
440     UDSSocketUnitTest socObj;
441     int32_t retResult = socObj.EpollCtl(fd, op, event);
442     ASSERT_EQ(-1, retResult);
443 }
444 
445 HWTEST_F(UDSSocketTest, EpollWait_001, TestSize.Level1)
446 {
447     struct epoll_event events[MAX_EVENT_SIZE] = {};
448     int32_t timeout = -1;
449 
450     UDSSocketUnitTest socObj;
451     int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
452     ASSERT_EQ(-1, retResult);
453 }
454 
455 HWTEST_F(UDSSocketTest, EpollWait_002, TestSize.Level1)
456 {
457     struct epoll_event events[MAX_EVENT_SIZE] = {};
458     int32_t timeout = 1001;
459 
460     UDSSocketUnitTest socObj;
461     int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
462     ASSERT_EQ(-1, retResult);
463 }
464 
465 HWTEST_F(UDSSocketTest, EpollWait_003, TestSize.Level1)
466 {
467     struct epoll_event events[MAX_EVENT_SIZE] = {};
468     int32_t timeout = -1001;
469 
470     UDSSocketUnitTest socObj;
471     int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
472     ASSERT_EQ(-1, retResult);
473 }
474 
475 HWTEST_F(UDSSocketTest, EpollWait_004, TestSize.Level1)
476 {
477     struct epoll_event events[MAX_EVENT_SIZE] = {};
478     int32_t timeout = -1001;
479 
480     UDSSocketUnitTest socObj;
481     int32_t retResult = socObj.EpollWait(*events, MAX_EVENT_SIZE, timeout);
482     ASSERT_EQ(-1, retResult);
483 }
484 #endif
485 } // namespace
486