Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gmock setting out parameter

Tags:

c++

googlemock

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.

like image 851
user1135541 Avatar asked Jan 11 '23 11:01

user1135541


1 Answers

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));
like image 161
Misha Brukman Avatar answered Jan 21 '23 16:01

Misha Brukman