c++ - GoogleMock: How to SetArgReferee according to another input parameter? -
i use googlemock mock service below:
class request { int req_id; int request; }; class response { int req_id; int response; }; int request(response& res, const request& req) { res.req_id = req.req_id; res.response = 2 * req.request; return 1; } expect_call(mock_service, request(_,_)).willonce(doall(setargreferee<0>(/* here? */), return(1)));
how can setargreferee
response& res
according passed in const request& req
, i.e. res.req_id = req.req_id;
, res.response = 2 * req.request;
?
your code not mocked - guess illustration of problem.
so assuming have mocked function reqest
within mocked class mockservice - use invoke action
request
function parameter:
expect_call(mock_service, request(_,_)).willonce(invoke(&request));
if call base class function - this:
class mock_service_class : public service_class { public: mock_method2(request, int(response& res, const request& req)); int baserequest(response& res, const request& req) { return service_class::request(res, req); } };
and expect_call
in way:
expect_call(mock_service, request(_,_)) .willonce(invoke(&mock_servide, &mock_service_class::baserequest));
Comments
Post a Comment