Derive-C
Loading...
Searching...
No Matches
mock.h
Go to the documentation of this file.
1
2#pragma once
3
4// JUSTIFY: No macro parens
5// - So we can take a single argument `args` that is bracketed.
6// NOLINTBEGIN(bugprone-macro-parentheses)
7
8#if defined ENABLE_MOCKING
9 #define MOCK_REAL(name) __real_##name
10 #define MOCK_SET(name) __mock_set_##name
11 #define MOCK_TYPE(name) __type_##name
12
13 // JUSTIFY: No Semicolon after
14 // - Users may want to add additional attributes to the declaration
15 // so we leave the termination of the real declaration to the user.
23 #define MOCKABLE_DECLARE(ret, name, args) \
24 typedef ret(*MOCK_TYPE(name)) args; \
25 extern MOCK_TYPE(name) name; \
26 void MOCK_SET(name)(MOCK_TYPE(name) func); \
27 ret MOCK_REAL(name) args
28
29 #define MOCKABLE_DEFINE(ret, name, args) \
30 MOCK_TYPE(name) name = MOCK_REAL(name); \
31 void MOCK_SET(name)(MOCK_TYPE(name) func) { name = func; } \
32 ret MOCK_REAL(name) args
33#else
34 #define MOCKABLE_DECLARE(ret, name, args) ret name args
35 #define MOCKABLE_DEFINE(ret, name, args) ret name args
36#endif
37
39#define MOCKABLE(ret, name, args) \
40 MOCKABLE_DECLARE(ret, name, args); \
41 MOCKABLE_DEFINE(ret, name, args)
42
43// NOLINTEND(bugprone-macro-parentheses)