Is it possible to mock variadic functions?

1,059 views
Skip to first unread message

Dan

unread,
Apr 10, 2009, 11:42:47 AM4/10/09
to Google C++ Mocking Framework
The subject says it all, really.

I am trying to mock a class which I did not write and it contains a
number of variadic functions. I _can_ eliminate these by providing
overloaded versions, since I know what my code uses, but I'd prefer
not to. Is this possible?

Thanks in advance,
Dan.

Zhanyong Wan (λx.x x)

unread,
Apr 10, 2009, 4:18:17 PM4/10/09
to Dan, Google C++ Mocking Framework
Hi Dan,

You cannot mock a variadic function directly in Google Mock.

The problem is that in general, there is no way for a mock object to
know how many arguments are passed to the variadic method, and what
the arguments' types are. Only the *author* of the base class knows
the protocol, and we cannot look into his head.

Therefore, to mock such a function, the *user* must teach the mock
object how to figure out the number of arguments and their types. One
way to do it is to provide overloaded versions of the function, as you
mentioned.

Ellipsis arguments are inherited from C and not really a C++ feature.
They are unsafe to use and don't work with arguments that have
constructors or destructors. Therefore we recommend to avoid them in
C++, as much as possible.

--
Zhanyong

Reply all
Reply to author
Forward
0 new messages