Not as many questions as knowledge sharing.
According to GoogleMock, frequently asked questions cannot be used to mock variational functions because it is not known how many arguments will be passed to the function.
This is true, but in most cases it is known how many variables the function variable is called from the system test or how to convert variable arguments into one non-invariant argument.
My colleague (I donβt know if he is active on Stackoverflow) came up with a working solution, as shown in the example below (using the layout for the C-type interface):
class MockInterface { public: MockInterface() {} ~MockInterface() {} MOCK_METHOD4( variadicfunction, void( const std:: string name, AN_ENUM mode, const std::string func_name, const std::string message ) ); }; boost::shard_ptr<MockInterface> mock_interface; extern "C" { void variadicfunction( const char *name, AN_ENUM mode, const char *func_name, const char *format, ... ) { std::string non_variadic(""); if (format != NULL ) { va_list args; va_start( args, format );
Hope this is helpful.
googlemock
Nemelis
source share