2013-05-14 35 views
0

有沒有人有使用Google Mock與wxWidgets一起運氣?我有一個類Foo與需要常量引用wxString在簽名像這樣制定者:與谷歌模擬使用wxString

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

我然後進行嘲笑美孚這樣的:

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 

的JIST是,谷歌模擬無法確定哪個運營商()函數,因爲操作者調用由wxUniChar提供不映射到什麼谷歌預計模擬()函數。我看到'long long int'和'testing :: internal :: BiggestInt'轉換的錯誤。

回答

0

這必須是使用代理類,wxUniCharRef的結果,作爲wxString::operator[]()結果類型(詳見中wxString documentation節「粗心的陷阱」),但我不知道究竟哪裏呢它來自於這裏似乎沒有任何代碼訪問wxString字符。什麼是gtest-internal.h的890行?

此外,你說你正在使用一個const引用wxString,但你的代碼不。我不認爲這是你的問題確實相關,但它的混亂有說明和代碼片段之間的這種差異...

+0

對不一致。我更新了這個例子。我能夠通過向wxUniChar添加一個構造函數和各種operator =和operator()函數來修復'long long int'類型並構建wxWidgets,從而解決了我的問題。 – 2013-05-14 18:43:04

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打補丁。

+0

如果我們真的需要允許在同一個表達式中混合使用'wxUniChar'和'long long',那麼我們真的需要這個(對於'unsigned long long'也是如此)。但我仍然想知道爲什麼這首先需要... – 2013-05-14 20:11:06

+0

我相信這是因爲谷歌測試正在使用它所稱的'BiggestInt'類型,它的一些內部代碼可能會對Google Mock對象執行驗證。它看起來像long long long或__int64,具體取決於平臺。 – 2013-05-15 04:00:00