2012-08-02 62 views
0

嘗試HippoMocks(Cygwin,GCC 4.5.3,CppUnit)模擬一個接口時,其中一種方法導致編譯失敗。進一步的分類表明只有std :: vector作爲參數的模擬方法會失敗。HippoMocks - std :: vector模擬方法無法編譯

例如

m_Mocks.ExpectCall(m_EmpSvcMock.get(), IEmployeeServiceProxy::GetEmployees); // compile error! 
m_Mocks.ExpectCall(m_EmpSvcMock.get(), IEmployeeServiceProxy::AddEmployee); // compile OK! 

其中

class IEmployeeServiceProxy 
{ 
public: 
    virtual ~IEmployeeServiceProxy() { } 
    virtual void AddEmployee(const Employee&) = 0; 
    virtual void GetEmployees(std::vector<Employee>&) = 0; 
}; 

struct Employee 
{ 
    boost::uuids::uuid Id; 
    std::string Name; 
}; 

編譯器錯誤:

/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stream_iterator.h: In member function ‘std::ostream_iterator<_Tp, _CharT, _Traits>& std::ostream_iterator<_Tp, _CharT, _Traits>::operator=(const _Tp&) [with _Tp = EmployeeServiceLib::Employee, _CharT = char, _Traits = std::char_traits<char>, std::ostream_iterator<_Tp, _CharT, _Traits> = std::ostream_iterator<EmployeeServiceLib::Employee, char, std::char_traits<char> >]’: 
In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/iterator:67:0, 
       from /usr/include/boost/uuid/string_generator.hpp:14, 
       from /usr/include/boost/uuid/uuid_generators.hpp:15, 
       from tests/../../RcfTestShared/IEmployeeService.hpp:7, 
       from tests/../IEmployeeServiceProxy.h:11, 
       from tests/ClientTest.h:13, 
       from tests/ClientTest.cpp:8: 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_algobase.h:349:8: instantiated from ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = const EmployeeServiceLib::Employee*, _OI = std::ostream_iterator<EmployeeServiceLib::Employee, char, std::char_traits<char> >]’ 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_algobase.h:404:70: instantiated from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false, _II = const EmployeeServiceLib::Employee*, _OI = std::ostream_iterator<EmployeeServiceLib::Employee, char, std::char_traits<char> >]’ 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_algobase.h:442:39: instantiated from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false, _II = __gnu_cxx::__normal_iterator<const EmployeeServiceLib::Employee*, std::vector<EmployeeServiceLib::Employee> >, _OI = std::ostream_iterator<EmployeeServiceLib::Employee, char, std::char_traits<char> >]’ 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_algobase.h:474:18: instantiated from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const EmployeeServiceLib::Employee*, std::vector<EmployeeServiceLib::Employee> >, _OI = std::ostream_iterator<EmployeeServiceLib::Employee, char, std::char_traits<char> >]’ 
../../RCF/RCF-1.3.1/include/RCF/Tools.hpp:116:9: instantiated from ‘std::ostream& std::operator<<(std::ostream&, const std::vector<_RealType>&) [with T = EmployeeServiceLib::Employee, std::ostream = std::basic_ostream<char>]’ 
../../hippomocks/HippoMocks/hippomocks.h:94:5: instantiated from ‘static void printArg<T>::print(std::ostream&, T, bool) [with T = std::vector<EmployeeServiceLib::Employee>&, std::ostream = std::basic_ostream<char>]’ 
../../hippomocks/HippoMocks/hippomocks.h:170:5: instantiated from ‘void ref_tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>::printTo(std::ostream&) const [with A = std::vector<EmployeeServiceLib::Employee>&, B = NullType, C = NullType, D = NullType, E = NullType, F = NullType, G = NullType, H = NullType, I = NullType, J = NullType, K = NullType, L = NullType, M = NullType, N = NullType, O = NullType, P = NullType, std::ostream = std::basic_ostream<char>]’ 
tests/ClientTest.cpp:47:1: instantiated from here 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stream_iterator.h:196:2: error: cannot bind ‘std::ostream_iterator<EmployeeServiceLib::Employee, char, std::char_traits<char> >::ostream_type’ lvalue to ‘std::basic_ostream<char>&&’ 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/ostream:579:5: error: initializing argument 1 of ‘std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char, _Traits = std::char_traits<char>, _Tp = EmployeeServiceLib::Employee]’ 
+0

那麼你現在已經刪除了錯誤信息,但是在短暫的時間裏我看到它們,我認爲問題在於它試圖將Employee對象與運算符==進行比較。你是否爲Employee類定義了operator ==? operator == for std :: vector 只要運算符==定義爲T即可運行。 – jahhaj 2012-08-02 06:11:32

+0

@jahhaj:我已經將HippoMocks更新爲svn的最新版本,現在我有一個不同的錯誤... – 2012-08-02 06:21:48

+0

不同的錯誤是?你也沒有回答我的問題,你有運營商==爲員工定義?我認爲這對任何一個Employee類的單元測試都很重要。 – jahhaj 2012-08-02 06:24:57

回答

1

也許它的抱怨,你沒有操作< <爲員工定義,但我不能肯定。我認爲你錯過了錯誤信息的最後一行?無論如何,我會閱讀文檔,看看他們對正在測試的課程有什麼要求。

要求您定義運算符==和運算符< <,也許其他人對於單元測試框架非常標準。如果您考慮一下,單元測試框架將需要比較您正在測試的類型的對象,並可能在出現問題時嘗試輸出這些對象。

+0

如果該類沒有<<運算符<<定義,那麼在那裏可以自動使用其他東西。它會打印「???」代替。沒有默認的比較,因爲沒有可能的解決方案是合理的。 – dascandy 2012-08-02 06:58:23

+0

@dascandy:我有幾個問題需要注意 - 我如何直接與您聯繫,而不是就此問題提問? – 2012-08-02 07:09:13

+0

您可以隨時使用我的電子郵件地址[email protected]。我剛剛注意到維基已經腐敗 - 哎呀...我會首先解決它,它應該有大部分的答案,但現在它只有一個數據庫錯誤。 – dascandy 2012-08-02 07:51:09