Gmock setting out parameter

c++, googlemock

Solution

If you want the output parameter of a function to point to a `void*`, then its type needs to be `void**`:

MOCK_METHOD1(dequeue, void(void** data));

otherwise, you can only return the value but not a pointer to a value through the output parameter.

If you make the appropriate change to the signature of your `dequeue()` method and the call to `MOCK_METHOD1()`, then this should do what you want:

EXPECT_CALL(FQO, dequeue(_))
    .WillOnce(SetArgPointee<0>(a));

Problem

In a GMock test method, I need to set the out parameter to a variable's address, so that the out parameter of `dequeue()`, which is `data` points to the variable `ch`: ``` MOCK_METHOD1(dequeue, void(void* data)); char ch = 'm'; void* a = (void*)&ch; EXPECT_CALL(FQO, dequeue(_)) .WillOnce(/*here I need to set argument to a*/); ``` I tried to figure out side effects but keep getting an error.

Original source