Please note that I simplified my code samples a bit for posting and missed changing my method references from get_reported_latitude_and_longitude_radians() to get_reported_latitude_and_longitude(). My apology.
On Friday, August 10, 2012 8:39:54 PM UTC-4, Leo wrote:
I'm a Googlemock newbie and trying to get a mocked function to return specified values through its reference arguments
The mocked class is "VehicleData" and the original prototype is
void get_reported_latitude_and_longitude(DOUBLE8 &latitudeDegrees, DOUBLE8 &longitudeDegrees);
where DOUBLE8 is simply a typedef on for the double type.
I've replaced the method in MockVehicleData with
MOCK_METHOD2(get_reported_latitude_and_longitude, void(DOUBLE8& latitudeDegrees, DOUBLE8& longitudeDegrees));
I then entered the following in my test method:
TEST_F(MyTest, UpdateMapPosition)
{
...
DOUBLE8 lat = 40.71;
DOUBLE8 lon = 73.98;
EXPECT_CALL(*mockVehicleData, get_reported_latitude_and_longitude_radians(_, _))
.WillOnce(SetArgReferee<0>(lat), SetArgReferee<1>(lon));
...
}
My compilation fails with the message: error: no matching function for call to ‘testing::internal::TypedExpectation<void ()(DOUBLE8&, DOUBLE8&)>::WillOnce(testing::SetArgRefereeActionP<0, double>, testing::SetArgRefereeActionP<1, double>)’
However, if I only specify one argument in WillOnce, the test code compiles successfully, e.g.
EXPECT_CALL(*mockVehicleData, get_reported_latitude_and_longitude_radians(_, _))
.WillOnce(SetArgReferee<0>(lat));
Would someone please tell me how I can specify two references to be passed back?
Thanks!