user1135541
user1135541

Reputation: 1891

Gmock setting out parameter

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.

Upvotes: 4

Views: 13228

Answers (1)

Misha Brukman
Misha Brukman

Reputation: 13424

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));

Upvotes: 10

Related Questions