希波莫克有模拟重载函数调用的OnCallFuncOverload宏。我试图用args的变量数来模拟函数。有人能给出一个带有args变量计数的重载函数的例子吗?
我的代码
void Verbose(LPCTSTR pszFormat, ...);
void Verbose(int level, LPCTSTR pszFormat, ...);
vlevel Verbose(vlevel level, LPCTSTR pszFormat, ...);我在尝试这段代码
TEST_F(VerboseTests, test)
{
MockRepository mocks;
mocks.OnCallFuncOverload((void(*)(int,LPCTSTR,...))Verbose);
}编译器输出:
hippomocks/hippomocks.h:3241:103: error: invalid conversion from ‘void (*)(int, LPCTSTR, ...) {aka void (*)(int, const char*, ...)}’ to ‘void (*)(int, const char*)’ [-fpermissive]
#define OnCallFuncOverload(func) RegisterExpect_<__LINE__>(func, HM_NS Any, #func, __FILE__, __LINE__)发布于 2016-08-04 14:04:45
确实有用。您必须使用the来说服编译器:
int Verbose(int level, ...)
{
return level;
}
typedef int (*va_func)(int level, const char* p1, int p2);
TEST(check_VA_func)
{
MockRepository mocks;
mocks.ExpectCallFuncOverload((va_func)Verbose).Return(22);
int result = Verbose(3,"Hi",9);
CHECK(result == 22);
}此解决方案的缺点是,您必须在编译时知道将在运行时调用多少参数。
https://stackoverflow.com/questions/36749410
复制相似问题