I have a c++ function to test, and this c++ function will call a legacy C function, so I need to mock the C function using gmock. The C function is:
int functionA(const char key[3],char value[5])
Now I can create a mock object and set the return value for it. But I also need to set the value for the second argument, because the value for the second argument is the actual output, and return value is a just a return code. My code is .t.cpp is:
const char pa[3] = {0};
char pb[5] = {0};
char set[5] = {1};
EXPECT_CALL(MockObj, functionA(pa, pb)).WillOnce(DoAll(SetArgPointee<1>(set), Return(2)));
EXPECT_EQ( phatics_decode(pa, pb), 2);
I got compiling errors:
array used as initializer
explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
error: invalid conversion from 'const char*' to 'char' [-fpermissive]
*::std::tr1::get<N>(args) = value_;
So what's wrong? Also, is there is a way to assert i set the argument correctly? After i set argument, will it be stored in "pb"? Thanks
Aucun commentaire:
Enregistrer un commentaire