Set out parameter (void *) of a mock function using ACTION_P

348 views
Skip to first unread message

Ganesh Jayachandran

unread,
Jun 1, 2015, 11:45:23 AM6/1/15
to googl...@googlegroups.com
Hi,

I would like to set custom value to a void pointer which acts as an out parameter. For e.g. in the below mock function, I would like to set the data_p to a custom value. 

MOCK_METHOD3(file_read, int(const char *file_name, const char *type_name, void *data_p));


I defined a custom action 

ACTION_P(SetArg2ToMCValue, value) {

reinterpret_cast<void *>(arg2) = value;

}

In my test,the following is set

struct.param1 = 5.0;

struct.param2 = 5.0;

EXPECT_CALL(*lib_mock, file_read(_,_,_)).WillOnce(DoAll(SetArg2ToMCValue(&struct), Return(0)));

When the unit under test is called, I do not see the values I set in the struct. I get 0 for both param1 and param2. 

Can someone let me know what is wrong with the above logic?


Regards,

Ganesh


Reply all
Reply to author
Forward
0 new messages