c++ - C+ + - 为什么MOCK_METHOD语法在GMock中不起作用?

可能是编译器问题?

MingGW(GCC 4.9.2)

Googletest 1.10.x


class SimpleClass {



public:


 virtual int simpleFirstFunction(int a, int b) { return (a + simpleSecondFunction(b)); }


 virtual int simpleSecondFunction(int b) { return (2 * b); }


 virtual ~SimpleClass();


};



class MockSimpleClass :public SimpleClass {


 MOCK_METHOD(int, simpleSecondFunction, (int a, int b), (override));


};



我看到2个编译器错误:

Error-1 :关于函数名

MockSimpleClass.cpp:18:24 : error :

'simpleSecondFunction'is not a type MOCK_METHOD(int ,simpleSecondFunction(int a ,int b) ,(override)) ;

Error-2 :关于输入参数

MockSimpleClass.cpp:18:46 : error :

expected identifier before'('token MOCK_METHOD(int ,simpleSecondFunction ,(int a ,int b) ,(override)) ;

Error-3 :关于"重写"周围的圆括号

MockSimpleClass.cpp:18:60 : error :

expected identifier before'('token MOCK_METHOD(int ,simpleSecondFunction(int a ,int b) ,(override)) ;

时间:

看起来好像没有定义MOCK_METHOD宏,你是否正确设置了包含路径,并在文件顶部添加了#include “ gmock/gmock.h ”指令。

如果你的include路径上有gmock头文件,则此方法应该有效:


#include"gmock/gmock.h"



class SimpleClass {



public:


 virtual int simpleFirstFunction(int a, int b) { return (a + simpleSecondFunction(b)); }


 virtual int simpleSecondFunction(int b) { return (2 * b); }


 virtual ~SimpleClass();


};



class MockSimpleClass : public SimpleClass {


public:


 MOCK_METHOD(int, simpleSecondFunction, (int b), (override));


};



...