tor  0.4.0.1-alpha
testsupport.h
Go to the documentation of this file.
1 /* Copyright (c) 2013-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
15 #ifndef TOR_TESTSUPPORT_H
16 #define TOR_TESTSUPPORT_H
17 
18 #ifdef TOR_UNIT_TESTS
19 
22 #define STATIC
23 #define EXTERN(type, name) extern type name;
24 #else
25 #define STATIC static
26 #define EXTERN(type, name)
27 #endif /* defined(TOR_UNIT_TESTS) */
28 
72 #ifdef TOR_UNIT_TESTS
73 #define MOCK_DECL(rv, funcname, arglist) \
74  rv funcname ##__real arglist; \
75  extern rv(*funcname) arglist
76 #define MOCK_IMPL(rv, funcname, arglist) \
77  rv(*funcname) arglist = funcname ##__real; \
78  rv funcname ##__real arglist
79 #define MOCK_DECL_ATTR(rv, funcname, arglist, attr) \
80  rv funcname ##__real arglist attr; \
81  extern rv(*funcname) arglist
82 #define MOCK_IMPL(rv, funcname, arglist) \
83  rv(*funcname) arglist = funcname ##__real; \
84  rv funcname ##__real arglist
85 #define MOCK(func, replacement) \
86  do { \
87  (func) = (replacement); \
88  } while (0)
89 #define UNMOCK(func) \
90  do { \
91  func = func ##__real; \
92  } while (0)
93 #else /* !(defined(TOR_UNIT_TESTS)) */
94 #define MOCK_DECL(rv, funcname, arglist) \
95  rv funcname arglist
96 #define MOCK_DECL_ATTR(rv, funcname, arglist, attr) \
97  rv funcname arglist attr
98 #define MOCK_IMPL(rv, funcname, arglist) \
99  rv funcname arglist
100 #endif /* defined(TOR_UNIT_TESTS) */
101 
103 #endif /* !defined(TOR_TESTSUPPORT_H) */