我正在使用 gmock 并对一个接受 boost::beast::http::response_parser 作为输出参数的函数进行模拟。函数签名大致如下:
error_code readFromSocket(boost::beast::http::response_parser& resp);
现在,为了测试这个函数,我使用了mock并使用如下的EXPECT_CALL
:
boost::beast::http::response_parser respObject;
// set status code in respObject
EXPECT_CALL(mockObject, readFromSocket(_))
.Times(1)
.DoAll(SetArgReferee<0>(respObject), Return(err::success));
当我尝试使用ByRef
,ByMove
,使用std::ref
等不同的组合时,它会返回一个operator= deleted compilation
编译错误,而且我理解为什么它们不起作用。
是否有人遇到过类似的情况,并知道如何解决这个错误?如果您需要澄清,请告诉我。
谢谢。
编辑
这是readFromSocket
的样子:
template<typename T>
error_code readFromSocket(beast::http::response_parser<T>& resp,
boost::asio::yield_context yield)
{
// read from socket using beast::http::async_read
return success;
}
这是我称呼它的方式。
beast::http::response_parser<beast::http::string_body> resp;
resp.body_limit((std::numeric_limits<std::string::size_type>::max)());
auto ec = readFromSocket(resp, yield);
// after this I do error handling and response status code handling.
body_limit()
按照描述运行。我们需要确保其限制内存和入站流量资源的效果。如果需要感知所设置的限制,请将其作为可测试接口读取将要设置的数字。保持一切简单。 - sehebody_limit()
是否正常工作。编辑问题以反映readFromSocket
的功能。 - Abhishek Arya