|
13 | 13 | #undef MOCKABLE_INTERFACE
|
14 | 14 |
|
15 | 15 | /* This header is meant to be included by production code headers, so that the MOCKABLE_FUNCTION gets enabled. */
|
16 |
| -/* |
| 16 | +/* |
17 | 17 | If you are porting to a new platform and do not want to build the tests, but only the production code,
|
18 |
| - simply make sure that this file is in the include path (either by copying it to your inc folder or |
| 18 | + simply make sure that this file is in the include path (either by copying it to your inc folder or |
19 | 19 | by adjusting the include paths).
|
20 | 20 | */
|
21 | 21 |
|
|
26 | 26 | #define UMOCK_C_PROD_IS_NOT_VOID(x) \
|
27 | 27 | MU_IF(MU_C2(UMOCK_C_PROD_TEST_,x), 1, 0)
|
28 | 28 |
|
| 29 | + |
29 | 30 | #ifdef ENABLE_MOCKS
|
30 | 31 |
|
31 | 32 | #ifdef ENABLE_MOCK_FILTERING
|
|
43 | 44 | result modifiers function(MU_IF(MU_COUNT_ARG(__VA_ARGS__), , void) MU_FOR_EACH_2_COUNTED(UMOCK_C_PROD_ARG_IN_SIGNATURE, __VA_ARGS__)); \
|
44 | 45 | MU_IF(do_returns, MU_IF(UMOCK_C_PROD_IS_NOT_VOID(result), DO_NOTHING_WITH_RETURN_VALUES,), )
|
45 | 46 |
|
| 47 | +#ifdef ENABLE_MOCKS_DECL |
| 48 | + |
| 49 | +/* Codes_SRS_UMOCK_C_LIB_01_001: [MOCKABLE_FUNCTION shall be used to wrap function definition allowing the user to declare a function that can be mocked.]*/ |
| 50 | +#define MOCKABLE_FUNCTION(modifiers, result, function, ...) \ |
| 51 | + MU_IF(ENABLE_MOCK_FILTERING_SWITCH, \ |
| 52 | + MU_IF(MU_C2(please_mock_, function), \ |
| 53 | + MOCKABLE_FUNCTION_DISABLED, \ |
| 54 | + MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK_DECL \ |
| 55 | + ), \ |
| 56 | + MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK_DECL) (0, 0, modifiers, result, function, __VA_ARGS__) |
| 57 | + |
| 58 | +/* Codes_SRS_UMOCK_C_LIB_01_212: [ MOCKABLE_FUNCTION_WITH_RETURNS shall be used to wrap function definitions, allowing the user to declare a function that can be mocked and aditionally declares the values that are to be returned in case of success and failure. ]*/ |
| 59 | +#define MOCKABLE_FUNCTION_WITH_RETURNS(modifiers, result, function, ...) \ |
| 60 | + MU_IF(ENABLE_MOCK_FILTERING_SWITCH, \ |
| 61 | + MU_IF(MU_C2(please_mock_, function), \ |
| 62 | + MOCKABLE_FUNCTION_DISABLED, \ |
| 63 | + MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK_DECL \ |
| 64 | + ), \ |
| 65 | + MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK_DECL) (1, 1, modifiers, result, function, __VA_ARGS__) |
| 66 | + |
| 67 | +#define MOCKABLE_INTERFACE(interface_name, ...) \ |
| 68 | + MU_FOR_EACH_1(EXPAND_ENTRY, __VA_ARGS__) \ |
| 69 | + static void MU_C2(register_reals_, interface_name)(void); |
| 70 | + |
| 71 | +#else /*ENABLE_MOCKS_DECL*/ |
| 72 | + |
46 | 73 | /* Codes_SRS_UMOCK_C_LIB_01_001: [MOCKABLE_FUNCTION shall be used to wrap function definition allowing the user to declare a function that can be mocked.]*/
|
47 | 74 | #define MOCKABLE_FUNCTION(modifiers, result, function, ...) \
|
48 | 75 | MU_IF(ENABLE_MOCK_FILTERING_SWITCH,MU_IF(MU_C2(please_mock_, function),MOCKABLE_FUNCTION_DISABLED,MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK), MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK) (0, modifiers, result, function, __VA_ARGS__)
|
|
51 | 78 | #define MOCKABLE_FUNCTION_WITH_RETURNS(modifiers, result, function, ...) \
|
52 | 79 | MU_IF(ENABLE_MOCK_FILTERING_SWITCH,MU_IF(MU_C2(please_mock_, function),MOCKABLE_FUNCTION_DISABLED,MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK), MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK) (1, modifiers, result, function, __VA_ARGS__)
|
53 | 80 |
|
| 81 | +#define MOCKABLE_INTERFACE(interface_name, ...) \ |
| 82 | + MU_FOR_EACH_1(EXPAND_ENTRY, __VA_ARGS__) \ |
| 83 | + static void MU_C2(register_reals_, interface_name)(void) \ |
| 84 | + { \ |
| 85 | + MU_FOR_EACH_1(REGISTER_GLOBAL_MOCK_REAL, __VA_ARGS__); \ |
| 86 | + } \ |
| 87 | + |
| 88 | +#endif /*ENABLE_MOCKS_DECL*/ |
| 89 | + |
| 90 | + |
| 91 | + |
54 | 92 | // The below MOCKABLE_FUNCTION_WITH_CODE macros are a temporary solution and should not be used for long term
|
55 | 93 | // They will be removed once the real support is in umock_c
|
56 | 94 | #define MOCKABLE_FUNCTION_WITH_CODE(modifiers, result, function, ...) \
|
|
74 | 112 |
|
75 | 113 | /* Codes_SRS_UMOCK_C_LIB_01_215: [ Each item in ... shall be an entry for one mockable function. ]*/
|
76 | 114 | /* Codes_SRS_UMOCK_C_LIB_01_216: [ Each item in ... shall be defined using a macro called FUNCTION, which shall be an alias for MOCKABLE_FUNCTION. ]*/
|
77 |
| -#define MOCKABLE_INTERFACE(interface_name, ...) \ |
78 |
| - MU_FOR_EACH_1(EXPAND_ENTRY, __VA_ARGS__) \ |
79 |
| - static void MU_C2(register_reals_, interface_name)(void) \ |
80 |
| - { \ |
81 |
| - MU_FOR_EACH_1(REGISTER_GLOBAL_MOCK_REAL, __VA_ARGS__); \ |
82 |
| - } \ |
| 115 | + |
83 | 116 |
|
84 | 117 | #include "umock_c/umock_c.h"
|
85 | 118 |
|
86 |
| -#else |
| 119 | +#else /*ENABLE_MOCKS*/ |
87 | 120 |
|
88 | 121 | #define UMOCK_C_PROD_ARG_IN_SIGNATURE(count, arg_type, arg_name) arg_type arg_name MU_IFCOMMA(count)
|
89 | 122 |
|
|
107 | 140 | result modifiers function(MU_IF(MU_COUNT_ARG(__VA_ARGS__),,void) MU_FOR_EACH_2_COUNTED(UMOCK_C_PROD_ARG_IN_SIGNATURE, __VA_ARGS__)); \
|
108 | 141 | MU_IF(UMOCK_C_PROD_IS_NOT_VOID(result), DO_NOTHING_WITH_RETURN_VALUES,)
|
109 | 142 |
|
110 |
| -#define UMOCK_C_PROD_ARG_IN_SIGNATURE_2(count, arg_type, arg_name) |
| 143 | +#define UMOCK_C_PROD_ARG_IN_SIGNATURE_2(count, arg_type, arg_name) |
111 | 144 |
|
112 | 145 | // The below MOCKABLE_FUNCTION_WITH_CODE macros are a temporary solution and should not be used for long term
|
113 | 146 | // They will be removed once the real support is in umock_c
|
|
0 commit comments