我正在上课operator[]
, 像这样 :
class Base
{
public:
virtual ~Base(){}
virtual const int & operator[]( const unsigned int index ) const = 0;
};
如何使用谷歌模拟框架为此方法创建模拟类?
我试过这个:
class MockBase : public Base
{
public:
MOCK_CONST_METHOD1( operator[],
const int& ( const unsigned int )
);
};
但这会产生下一个错误:
error: pasting "]" and "_" does not give a valid preprocessing token
error: pasting "]" and "_" does not give a valid preprocessing token
error: pasting "]" and "_" does not give a valid preprocessing token
error: pasting "]" and "_" does not give a valid preprocessing token
The MOCK_METHOD#
宏不适用于运算符。中给出的解决方案这条信息 http://groups.google.com/group/googlemock/browse_thread/thread/3bee5c4d556db301?pli=1说创建一个常规的模拟方法:
class Base {
public:
virtual ~Base () {}
virtual bool operator==(const Base &) = 0;
};
class MockBase: public Base {
public:
MOCK_METHOD1(Equals, bool(const Base &));
virtual bool operator==(const Base & rhs) { return Equals(rhs); }
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)