Bumping with more information in case it makes my question more interesting :)To be more explicit, I'm wondering if I can write a separate C++ file containing a mock function that simply reports the call + parameters manually to the mock engine:A.c:void A(void) {B(1, 2, 3, 4);}B.c:void B(int w, int x, int y, int z) {// do something very expensive here.}MockB.cc:void B(int w, int x, int y, int z) {GoogleMock::ReportFreeFunctionCall("B", w, x, y, z); // Or something like this}The idea is that at link time, when compiling the unit tests for A, I'd link against MockB.cc, and the expensive B wouldn't exist.For example clarity I'm intentionally ignoring language requirements like extern "C" { ... }, #include directives, etc.I'm assuming this is infeasible, since the compiler doesn't know the relationship between A's call to B, the string "B", and probably can't do anything interesting with the address of the mock function B. The EXPECT_CALL syntax doesn't look supportive of this approach either, but I figured I'd poll the experts before pursuing alternatives.
CharlesOn Wed, Jul 12, 2017 at 5:06 PM, Charles Nicholson <nicho...@google.com> wrote:Hi everyone-I see in the cookbook that the best practice for testing free functions is to shim them into an interface and then mock the interface. This seems totally reasonable, but I'd like to test C99 code with C++ unit tests, so all functions are global.CppUTest's solution is to require manual mocking, where it's up to the programmer to report actual calls. Googlemock's use of templates to capture parameters elegantly avoids the extra typing and fragility with the manual approach, but doesn't appear to be able to mock global functions.It seems like googlemock is not a good choice for mocking C99 code, but I wanted to put it in front of the community and experts in case I'm not fully informed.Thanks,Charles
--
---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframework+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.