将wxString与Google Mock一起使用

时间:2013-05-14 17:39:24

标签: c++ unit-testing wxwidgets googlemock

有没有人使用Google Mock和wxWidgets一起运气?我有一个带有setter的类Foo,它在签名中对wxString进行const引用,如下所示:

class Foo {
public:
    Foo();
    virtual ~Foo();
    void setName(const wxString& name);
};

然后我继续这样模仿Foo:

class MockFoo : public Foo {
    MOCK_METHOD1(setName, void(const wxString& name));
};

我的其他模拟工作得很好,但有一些关于它不喜欢的wxString参数。当我编译时,我看到以下内容:

C:\gmock-1.6.0\gtest\include\gtest\internal\gtest-internal.h:890: error: conversion from `const wxUniChar' to `long long int' is ambiguous
C:\wxWidgets-2.9.0\include\wx\unichar.h:74: note: candidates are: wxUniChar::operator char() const
C:\wxWidgets-2.9.0\include\wx\unichar.h:75: note:                 wxUniChar::operator unsigned char() const
//more potential candidates from wxUniChar follow after that

由于wxUniChar提供的operator()函数没有映射到Google Mock期望的内容,因此Google Mock无法确定调用哪个operator()函数。我看到'long long int'和'testing :: internal :: BiggestInt'转换的这个错误。

2 个答案:

答案 0 :(得分:0)

这必须是使用代理类wxUniCharRef作为wxString::operator[]()的结果类型的结果(有关更多详细信息,请参阅wxString documentation的“疏忽的陷阱”部分) ,但我不确定它究竟来自哪里,因为这里似乎没有任何代码访问wxString字符。究竟是gtest-internal.h的第890行?

另外,你说你正在使用对wxString的const引用,但你的代码没有。我不认为它与你的问题真的相关,但是在描述和代码片段之间存在这种差异是令人困惑的......

答案 1 :(得分:0)

以下对wxUniChar头文件的补充似乎有效:

wxUniChar(long long int c) { m_value = c; }

operator long long int() const { return (long long int)m_value; }

wxUniChar& operator=(long long int c) { m_value = c; return *this; }

bool operator op(long long int c) const { return m_value op (value_type)c; }

wxUniCharRef& operator=(long long int c) { return *this = wxUniChar(c); }

operator long long int() const { return UniChar(); }

bool operator op(long long int c) const { return UniChar() op c; }

我将这些插入到头文件的相应部分,编译错误消失了。如果我有时间,如果这听起来像是一个合理的解决方案,我将使用一些单元测试来处理wxWidgets的补丁。

相关问题