Search code examples
mockingtddgooglemock

What is the meaning of this 'error: ‘send’ is not a type' in declaring mocks


I am trying to mock zmq.hpp.

namespace zmq {
class ZmqMockSocket : public socket_t {
    MOCK_METHOD((size_t), send, (), (override));
};

I get the following error:

zmq_mock.h:16:25: error: ‘send’ is not a type
MOCK_METHOD((size_t), send, (), (override);
                      ^~~~

The send is defined class socket_t as :

virtual size_t send (void) = 0;

Solution

  • You are using the MOCK_METHOD as indicated in a NEW gmock cookbook. I had the same problem, and finally found out that it's because of my OLD gtest/gmock version.

    I saw this issue, where MOCK_METHOD is supported with old gtest/gmock version. It's second argument is a type. This is the reason why your compiler sees function 'send' as a type. Then there was this change in 2018, where MOCK_METHOD(ReturnType, MethodName, (Args...)) was introduced. You can also check in the release v1.10.0.

    Solution: Use the old style MOCK_METHODn macros or use the MOCK_METHOD with the correct order of argument.