Reputation: 10357
I need to unit test some C++ objects that I've written that use a 3rd party C library. For reasons beyond the scope of this question, I can't call the 3rd party C library directly, and need to stub it out for the test suite.
For other parts of our unit test suite we use googlemock
, but I don't think it can be used for C
libraries. I can stub out the library manually, but prefer not to (partly due to laziness (its rather large), but mainly because its just a matter of principles).
So here's my question: is there a tool that generates stubbed code based on a C
library header file? Once I have the stubbed-out code, I'll do some minor mods to it, then I'll link against it for the unit testing.
Upvotes: 4
Views: 2164
Reputation: 6030
You cant wrap those calls in a class like described in http://code.google.com/p/googlemock/wiki/CookBook#Mocking_Free_Functions
Then You can inject (in dynamic or static way) this class and set expectation on it.
Upvotes: 2
Reputation: 180887
stubgen can generate stub members from header files, unless you have special requirements it should be able to do what you're looking for.
Upvotes: 3