test_system_mocks.h
Go to the documentation of this file.
1 /*
2  * Unit tests for XmlRpc++
3  *
4  * Copyright (C) 2017, Zoox Inc
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Author: Austin Hendrix <austin@zoox.com>
21  *
22  */
23 
24 #pragma once
25 
26 #include <arpa/inet.h>
27 #include <fcntl.h>
28 #include <limits.h>
29 #include <netdb.h>
30 #include <stdarg.h>
31 #include <sys/socket.h>
32 #include <sys/types.h>
33 #include <unistd.h>
34 
35 #ifndef MOCK_SYSCALL
36 #define MOCK_SYSCALL(ret, name, ARG_TYPES, ARG_NAMES) \
37  extern ret(*fake_##name) ARG_TYPES; \
38  extern int name##_calls; \
39  ret count_##name ARG_TYPES;
40 #endif // MOCK_SYSCALL
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 MOCK_SYSCALL(int,
47  accept,
48  (int sockfd, struct sockaddr* addr, socklen_t* addrlen),
49  (sockfd, addr, addrlen));
50 MOCK_SYSCALL(int,
51  bind,
52  (int sockfd, const struct sockaddr* addr, socklen_t addrlen),
53  (sockfd, addr, addrlen));
54 MOCK_SYSCALL(int, close, (int socket), (socket));
55 MOCK_SYSCALL(int,
56  connect,
57  (int sockfd, const struct sockaddr* addr, socklen_t addrlen),
58  (sockfd, addr, addrlen));
59 MOCK_SYSCALL(int,
60  getaddrinfo,
61  (const char* node,
62  const char* service,
63  const struct addrinfo* hints,
64  struct addrinfo** res),
65  (node, service, hints, res));
66 MOCK_SYSCALL(int,
67  getsockname,
68  (int sockfd, struct sockaddr* addr, socklen_t* addrlen),
69  (sockfd, addr, addrlen));
70 MOCK_SYSCALL(int, listen, (int sockfd, int backlog), (sockfd, backlog));
71 MOCK_SYSCALL(ssize_t,
72  read,
73  (int fd, void* buf, size_t count),
74  (fd, buf, count));
76  int,
77  setsockopt,
78  (int sockfd, int level, int optname, const void* optval, socklen_t optlen),
79  (sockfd, level, optname, optval, optlen));
80 MOCK_SYSCALL(int,
81  select,
82  (int nfds,
83  fd_set* readfds,
84  fd_set* writefds,
85  fd_set* exceptfds,
86  struct timeval* timeout),
87  (nfds, readfds, writefds, exceptfds, timeout));
88 MOCK_SYSCALL(int,
89  socket,
90  (int domain, int type, int protocol),
91  (domain, type, protocol));
92 MOCK_SYSCALL(ssize_t,
93  write,
94  (int fd, const void* buf, size_t count),
95  (fd, buf, count));
96 
97 // custom mock for fcntl because it is varargs
98 // the mocked version always takes the third argument
99 extern int (*fake_fcntl)(int fd, int cmd, unsigned long);
100 extern int fcntl_calls;
101 int count_fcntl(int fd, int cmd, unsigned long arg);
102 
103 // Custom mock for freeaddrinfo because it returns void.
104 extern void (*fake_freeaddrinfo)(struct addrinfo* res);
105 extern int freeaddrinfo_calls;
106 void count_freeaddrinfo(struct addrinfo* res);
107 
108 #ifdef __cplusplus
109 } // extern "C"
110 #endif
int count_fcntl(int fd, int cmd, unsigned long arg)
void(* fake_freeaddrinfo)(struct addrinfo *res)
#define MOCK_SYSCALL(ret, name, ARG_TYPES, ARG_NAMES)
void count_freeaddrinfo(struct addrinfo *res)
int fcntl_calls
int(* fake_fcntl)(int fd, int cmd, unsigned long)
int freeaddrinfo_calls


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix
autogenerated on Sun Feb 3 2019 03:29:51