Member function templates cannot be virtual, so you won't be able to
override GetNextValue() in a subclass.
If you want to mock Foo, you must know which value type(s) your tests
are gonna need. Therefore you can add some virtual functions in Foo
to wrap GetNextValue(), such that they can be mocked out:
struct Foo {
...
// This cannot be mocked.
template <typename ValueType>
void GetNextValue(...);
// This can.
virtual void GetNextIntValue(const std::string& name, int& value,
const unsigned int index) {
GetNextValue(name, value, index);
}
...
}
--
Zhanyong
2009/11/3 Michael Harrington <kib...@gmail.com>:
> It's not necessarily a matter of overriding the function. We are using
> policy-based design, so we actually inherit from the mock in order to
> test it rather than pass in a mock derived from a real class -- so the
> mock can be a concrete class of its own and the vtable doesn't even
> matter.
>
> Is it possible to create a mock method that will provide the same
> templated interface to the production code?
Even mock method has some state stored as a member variable of the
mock class. You cannot have member variable templates. Therefore you
cannot have mock method templates.
So my suggestion remains the same (except that the methods don't have
to be virtual). If you want, you can overload the wrappers such that
they share the same name as the template, but I'd avoid that myself.
--
Zhanyong