From fcaa3edb16066e93c03a6dd6b97585e734cd2602 Mon Sep 17 00:00:00 2001 From: Pablo Andres Fuente Date: Fri, 18 Oct 2024 22:46:38 -0300 Subject: [PATCH] Replace `TRUE/FALSE` with `IS_TRUE/IS_FALSE` on macros This fix projects/compilers that has defined `TRUE` as a macro. As an example, using cpp_mock with mingw will result on mocked method names not being identified as defined types when the number of parameters where one or zero. That was caused because `DEFINE_EXISTS` macro used `TRUE` wich was expanded to `1`, and that being concatenated to `MOCK_METHOD_SINGLE_`. Because `MOCK_METHOD_SINGLE_1` was not defined as a macro the preprocesed code was invalid. --- include/cpp_mock.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/cpp_mock.h b/include/cpp_mock.h index 2ba6ead..cbe1be5 100644 --- a/include/cpp_mock.h +++ b/include/cpp_mock.h @@ -628,14 +628,14 @@ namespace cpp_mock // detect the difference between 'type a' and 'a' #define CAT(a, b) a ## b #define GET_SECOND_ARG(a, b, ...) b -#define DEFINE_EXISTS(...) EXPAND_MACRO(GET_SECOND_ARG(__VA_ARGS__, TRUE)) +#define DEFINE_EXISTS(...) EXPAND_MACRO(GET_SECOND_ARG(__VA_ARGS__, IS_TRUE)) #define IS_TYPE_MISSING(x) DEFINE_EXISTS(CAT(TOKEN_IS_EMPTY_, x)) -#define TOKEN_IS_EMPTY_a ignored, FALSE +#define TOKEN_IS_EMPTY_a ignored, IS_FALSE #define GET_METHOD(method, suffix) CAT(method, suffix) #define NOOP(...) -#define MOCK_METHOD_IS_SINGLE_FALSE(Ret, Name, Args, Specs) MOCK_METHOD_IMPL(Ret, Name, Args, Specs, NOOP, NOOP) -#define MOCK_METHOD_IS_SINGLE_TRUE(Ret, Name, Args, Specs) MOCK_METHOD_IMPL(Ret, Name, Args, Specs, NAME_ARGS1, TRANSFORM1, a) -#define HANDLE_EMPTY_TYPE(...) GET_METHOD(MOCK_METHOD_IS_SINGLE_, IS_TYPE_MISSING(__VA_ARGS__ a)) +#define MOCK_METHOD_SINGLE_IS_FALSE(Ret, Name, Args, Specs) MOCK_METHOD_IMPL(Ret, Name, Args, Specs, NOOP, NOOP) +#define MOCK_METHOD_SINGLE_IS_TRUE(Ret, Name, Args, Specs) MOCK_METHOD_IMPL(Ret, Name, Args, Specs, NAME_ARGS1, TRANSFORM1, a) +#define HANDLE_EMPTY_TYPE(...) GET_METHOD(MOCK_METHOD_SINGLE_, IS_TYPE_MISSING(__VA_ARGS__ a)) #define MOCK_METHOD_1(Ret, Name, Args, Specs) HANDLE_EMPTY_TYPE Args (Ret, Name, Args, Specs) #define MOCK_METHOD_2(Ret, Name, Args, Specs) MOCK_METHOD_IMPL(Ret, Name, Args, Specs, NAME_ARGS2, TRANSFORM2, b, a)