Skip to content

Conversation

@pafuent
Copy link

@pafuent pafuent commented Oct 19, 2024

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 which was expanded to 1, and that being concatenated to MOCK_METHOD_SINGLE_. Because MOCK_METHOD_SINGLE_1 was not defined as a macro the preprocessed code was invalid.

If you compile this with mingw you can reproduce the issue:

#include "cpp_mock.h"

struct SomeInterface {
    virtual int foo(const int&, float, std::string) = 0;
    virtual int bar(std::string) = 0;
};

struct SomeInterfaceMock : public SomeInterface {
  MockMethod(int, foo, (const int&, float, std::string));
  MockMethod(int, bar, (std::string));
};

int main() {
  SomeInterfaceMock mock;

  When(mock.foo).With(1, 3.14, "foo123").Return(42);
  assert(mock.foo(1, 3.14, "foo123") == 42);

  mock.bar("bar123");
  Verify(mock.bar).With("bar123").Times(1);
} 

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant