HippoMocks - how to mock with a Win32 API function

The HippoMocks documentation says it might mock a C function, including a Windows API function, but I couldn't find any example for it. Can anyone provide an example for a Mocking Windows API function?



source to share

1 answer

I need to get a new release, that's for sure.

You can mock an API function just like any other function, except that you don't specify any object to call it (because it doesn't). I've tested this a lot on Linux with regular libc API functions and it worked incredibly well. Windows shouldn't be any different, but here's why my example will complete:

void test() {
    MockRepository mocks;


Note that this works for any function, including those specified to never return. If you report an error to HippoMocks for a function that shouldn't return, the return code might not be caused by the error. Instead, try picking an exception to check instead. Now that I think about it, it was on Windows using VS2008 where there were literally no opcodes outside of the call to exit.

Hope you can get it to work. Be sure to grab the latest commit on Git (from Assembla) as the latest version doesn't contain that yet.



All Articles