The signature of your method in the mock class is wrong :
MOCK_METHOD2(setSize, bool(int w, int h));
and the base class has the method with this signature :
virtual void setSize(int w, int h) = 0;
I am not sure which compiler you are using, but that should be a compiler error.
Fix the signature, and the error should go away :
MOCK_METHOD2(setSize, void(int w, int h));
Additionally,
class MockFoo : AbstractFoo
should be
class MockFoo : public AbstractFoo
Your problem has nothing to do with googlemock library - but rather with c++. What you are trying to achieve is not possible because of [class.virtual]/1.
Next example demonstrates the same problem :
struct A
{
A(int h,int l):x(h),y(l){}
int x; int y;
};
class AbstractFoo {
public:
virtual void setSize(int w, int h) = 0;
void setSize(const A& s){setSize(s.x,s.y);}
};
class MockFoo : public AbstractFoo
{
public:
void setSize(int , int ){}
};
int main()
{
MockFoo f;
A a(5,5);
f.setSize( a );
}
You can solve this issue by renaming setSize(const QSize& s)
method, or by casting MockFoo
object to AbstractFoo&
and then calling this method.
You can also take a look into NVI, since that it what it looks like you are trying to do.