Question

Intro

I'm having a problem with implementing a pure virtual interface using Google Mock (v1.7.0).

In order to determine the root cause, I've put together pure virtual interface Simple and MockSimple as a test. I believe what I have done here is in line with this Google Mock example.

Yet, when I compile it, I get an error. Why is this? What am I doing wrong?

Simple Test Code

#include "gmock/gmock.h"
#include "gtest/gtest.h"

class Simple
{
public:
    virtual ~Simple() {}
    virtual int Initialize()   = 0;
};

class MockSimple : public Simple
{
public:
    MOCK_METHOD0(Initialize, int());
};

TEST(Hello, MockSimple)
{
    MockSimple m;
    EXPECT_CALL(m, Initialize);
    m.Initialize();
}

Compilation Command

g++ -I../gmock/include/ -I../gmock/gtest/include  -c test.cpp -o test.o

Error Output

test.cpp: In member function ‘virtual void Hello_MockSimple_Test::TestBody()’:
test.cpp:20:5: error: ‘m.MockSimple::gmock_Initialize’ does not have class type
Was it helpful?

Solution

Need argument list (an empty one, in this case) for the method called in the EXPECT_CALL :)

EXPECT_CALL(m, Initialize());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top