test
test_system_mocks.c
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
// The auto-generated mocks here don't use their parameters, so we disable
25
// that warning.
26
#ifdef __GNUC__
27
#pragma GCC diagnostic ignored "-Wunused-parameter"
28
#endif
29
30
#define MOCK_SYSCALL(ret, name, ARG_TYPES, ARG_NAMES) \
31
ret(*fake_##name) ARG_TYPES = 0; \
32
ret __wrap_##name ARG_TYPES { \
33
if (fake_##name) { \
34
return fake_##name ARG_NAMES; \
35
} else { \
36
return -1; \
37
} \
38
} \
39
int name##_calls = 0; \
40
ret count_##name ARG_TYPES { \
41
name##_calls++; \
42
return 0; \
43
}
44
45
#include "
test_system_mocks.h
"
46
47
// custom mock for fcntl because it is varargs
48
// the mocked version always takes the third argument
49
int (*
fake_fcntl
)(
int
fd,
int
cmd,
unsigned
long) = 0;
50
int
__wrap_fcntl
(
int
fd,
int
cmd, ...) {
51
va_list ap;
52
va_start(ap, cmd);
53
unsigned
long
arg = va_arg(ap,
unsigned
long
);
54
va_end(ap);
55
56
if
(
fake_fcntl
) {
57
return
fake_fcntl
(fd, cmd, arg);
58
}
else
{
59
return
-1;
60
}
61
}
62
int
fcntl_calls
= 0;
63
int
count_fcntl
(
int
fd,
int
cmd,
unsigned
long
arg) {
64
fcntl_calls
++;
65
return
0;
66
}
67
68
// Custom mock for freeaddrinfo because it returns void.
69
void (*
fake_freeaddrinfo
)(
struct
addrinfo* res) = 0;
70
void
__wrap_freeaddrinfo
(
struct
addrinfo* res) {
71
if
(
fake_freeaddrinfo
) {
72
return
fake_freeaddrinfo
(res);
73
}
else
{
74
return
;
75
}
76
}
77
int
freeaddrinfo_calls
= 0;
78
void
count_freeaddrinfo
(
struct
addrinfo* res) {
79
freeaddrinfo_calls
++;
80
return
;
81
}
fake_fcntl
int(* fake_fcntl)(int fd, int cmd, unsigned long)=0
Definition:
test_system_mocks.c:49
count_freeaddrinfo
void count_freeaddrinfo(struct addrinfo *res)
Definition:
test_system_mocks.c:78
freeaddrinfo_calls
int freeaddrinfo_calls
Definition:
test_system_mocks.c:77
__wrap_fcntl
int __wrap_fcntl(int fd, int cmd,...)
Definition:
test_system_mocks.c:50
count_fcntl
int count_fcntl(int fd, int cmd, unsigned long arg)
Definition:
test_system_mocks.c:63
fcntl_calls
int fcntl_calls
Definition:
test_system_mocks.c:62
__wrap_freeaddrinfo
void __wrap_freeaddrinfo(struct addrinfo *res)
Definition:
test_system_mocks.c:70
test_system_mocks.h
fake_freeaddrinfo
void(* fake_freeaddrinfo)(struct addrinfo *res)=0
Definition:
test_system_mocks.c:69
xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas
, Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:32