lundi 1 juin 2015

Setting custom value to void pointer in gmock

I am using gmock to unit test my C implementation. For one of my mock function the out parameter is defined as void pointer. The mock function is given below:

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

According to How to set a value to void * argument of a mock method in google mock testing?

I created an ACTION_P

ACTION_P(SetArg2ToMCValue, value) {   reinterpret_cast<void *>(arg2) = value; }

In my test code I set the default value to the parameter that is casted to void in ACTION_P and my expectation

  struct.a = 5.0;
  struct.b = 15.0;
  //Expectations
EXPECT_CALL(*libfile_mock,  file_read(_,_,_)).WillOnce(DoAll(SetArg2ToMCValue(buffer), Return(0)));

When the test is run, I do not see the custom values, I set to the struct. Rather I see 0. How do I set value to an out parameter that is also a void pointer in gmock?

Aucun commentaire:

Enregistrer un commentaire