Jon*_*han 6 testing googlemock
使用以下Google Mock声明时收到编译错误:
EXPECT_CALL(some_object, someFunction(1,An<AStructIDefined>()))
.Times(2);
Run Code Online (Sandbox Code Playgroud)
错误是:
1>ClCompile:
1> TestMyClass.cpp
1>TestMyClass.cpp(189): error C2664: 'mynamespace::MockMyClassClient::gmock_someFunction' : cannot convert parameter 2 from 'testing::Matcher<T>' to 'const testing::Matcher<T> &'
1> with
1> [
1> T=mynamespace::AStructIDefined
1> ]
1> and
1> [
1> T=const mynamespace::AStructIDefined &
1> ]
1> Reason: cannot convert from 'testing::Matcher<T>' to 'const testing::Matcher<T>'
1> with
1> [
1> T=mynamespace::AStructIDefined
1> ]
1> and
1> [
1> T=const mynamespace::AStructIDefined &
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
更新:
我正在使用VS2010.
someFunction的声明是:
virtual void someFunction( long long ll, const AStructIDefined& a_struct);
Run Code Online (Sandbox Code Playgroud)
An()是一个Google Mock 通配符匹配器,具有以下定义:
// Creates a matcher that matches any value of the given type T.
template <typename T>
inline Matcher<T> An() { return A<T>(); }
Run Code Online (Sandbox Code Playgroud)
结构的简化但有代表性的版本是:
namespace mynamespace {
class ABaseCLass
{
public:
virtual ~ABaseCLass(){};
virtual bool isValid() const = 0;
};
struct AStructIDefined : public ABaseCLass
{
public:
OrderStatusReport(SomeEnum1 e_, int i_, double d_);
SomeEnum1 e;
int i;
double d;
const std::string toString() const;
bool isSane() const;
bool operator== (const SomeEnum1& ref_) const;
double getD() const;
int getI() const;
bool isCondition() const;
};
} // namespace mynamespace
Run Code Online (Sandbox Code Playgroud)
解决方案是改变声明:
EXPECT_CALL(some_object, someFunction(1,An<AStructIDefined>()))
.Times(2);
Run Code Online (Sandbox Code Playgroud)
至
EXPECT_CALL(some_object, someFunction(1,An<const AStructIDefined &>()))
.Times(2);
Run Code Online (Sandbox Code Playgroud)
C++隐式地对函数参数进行强制转换const和引用&,但是google mock的声明似乎要求函数的签名中出现类型,而不是作为函数参数提交的类型.
| 归档时间: |
|
| 查看次数: |
4096 次 |
| 最近记录: |