Re: Multiple SetArgReferee?

1,235 views
Skip to first unread message

Leo

unread,
Aug 10, 2012, 9:01:31 PM8/10/12
to googl...@googlegroups.com
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!

Vlad Losev

unread,
Aug 11, 2012, 11:43:59 AM8/11/12
to Google C++ Mocking Framework
Note that WillOnce only accepts a single action. You have to use DoAll to combine actions.

Leo

unread,
Aug 13, 2012, 4:15:41 PM8/13/12
to googl...@googlegroups.com
That did it. Thanks!
Reply all
Reply to author
Forward
0 new messages