Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

googlemock - mock a method that returns a complex datatyp

I want to mock a method that returns a complex datatyp

class aClass
{
public:
   virtual const QMap<QString, QString> aMethod() const;
}

class MockaClass : public aClass
{
public:
   MOCK_CONST_METHOD0(aMethod, const QMap<QString, QString>());
}

This code does not compile: "macro "MOCK_CONST_METHOD0" passed 3 arguments, but takes just 2"

I think that the googlemock macro does not understand QMap and interpret the comma as parameter separator.

Is there a way to tell googlemock that QMap is the return value?

like image 365
Jens Ehrlich Avatar asked Apr 18 '12 10:04

Jens Ehrlich


1 Answers

Just use a typedef like this:

class aClass
{
public:
   typedef const QMap<QString, QString> MyType;
   virtual MyType aMethod() const;
}

class MockaClass : public aClass
{
public:
   MOCK_CONST_METHOD0(aMethod, MyType());
}
like image 113
nabulke Avatar answered Oct 12 '22 01:10

nabulke