I have a C function to mock using gmock. C function is:
int functionA(const char key[12],char value[64])
functionA will be called in a c++ function I am testing, so i need to mock this C function. and i have successfully mocked this C function and can set return value using gmock. But i still need to save the first argument as well as set the value for second argument for testing purpose. (First argument is input, second argument is the actual output, return value is just a return code, so i need to save the first argument and assert it to make sure this function is called with certain parameter, and set the value for second argument to mock the output). My Code is:
const char pa[12] = {0};
char pb[64] = {0};
const char data[12] = {0};
char set[64] = {1};
EXPECT_CALL(MockObj, functionA(pa, pb)).WillOnce(DoAll(SaveArg<0>(&data),SetArgPointee<1>(set), Return(2)));
EXPECT_EQ( functionA(pa, pb), 2);
char expected1[64] = {1};
EXPECT_EQ (expected1, pb);
const char expected0[12] = {0};
EXPECT_EQ(expected0, pa);
But i got errors:
error: invalid conversion from 'const char*' to 'char' [-fpermissive]
*::std::tr1::get<N>(args) = value_;
error: assignment of read-only location '*(const char (*)[12])((const testing::SaveArgActionP<0, const char (*)[12]>::gmock_Impl<void(const char*, char*)>*)this)->testing::SaveArgActionP<0, const char (*)[12]>::gmock_Impl<void(const char*, char*)>::pointer'
*pointer = ::std::tr1::get<k>(args);
Without setting and saving args (just have "return") it works and can give me the expected return value, so it seems i am not correct when saving and setting args, what is the problem? Thanks
Aucun commentaire:
Enregistrer un commentaire