gpt4 book ai didi

c++ - HippoMocks - 使用 std::vector 的模拟方法无法编译

转载 作者:行者123 更新时间:2023-11-28 07:59:53 32 4
gpt4 key购买 nike

在尝试使用 HippoMocks(Cygwin、GCC 4.5.3、CppUnit)模拟接口(interface)时,其中一种方法导致编译失败。进一步的分类表明,只有以 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]’

最佳答案

可能是在提示您没有为 Employee 定义运算符<<,但我不确定。我认为您错过了错误消息的最后一行?无论如何,我都会阅读文档并查看他们对被测试类的要求。

要求您定义 operator== 和 operator<< 以及其他可能是单元测试框架的标准。如果您考虑一下,单元测试框架将需要比较您正在测试的类型的对象,并且可能会在出现问题时尝试输出这些对象。

关于c++ - HippoMocks - 使用 std::vector 的模拟方法无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11771814/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com