goto
goto

Reputation: 433

HippoMocks - How to mock Win32 API Function

HippoMocks documentation says that it can mock C function including Windows API function, but I could not find any example for it. Can anyone give an example for windows API function mocking?

http://www.hippomocks.com/wiki/index.php/What_can_be_mocked

Upvotes: 3

Views: 2058

Answers (1)

dascandy
dascandy

Reputation: 7302

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

You can mock an API function as you would any other function, except that you don't specify any object to call it on (because it doesn't have any). I've tested it a lot on Linux with the regular libc API functions and that worked incredibly well. Windows should be no different, but this is why my example will be exit:

void test() {
    MockRepository mocks;
    mocks.ExpectCallFunc(&exit).With(2).Throw(std::exception());
}

Note that this works for any function, including those that are specified never to return. If you do tell HippoMocks to mock a function that shouldn't return, the return code may not have been generated causing errors. Try throwing a test-specific exception instead. Now that I think of it, that was on Windows using VS2008 where it literally had no opcodes beyond the call to exit.

Hope you can get it to work. Be sure to take the most current commit on Git (from Assembla) as the last release doesn't contain this yet.

Upvotes: 4

Related Questions