I'm writing a unit test for a class that uses named pipes. I need to stub CreateNamedPipe, ConnectNamedPipe, WriteFile, ReadFile, FlushFileBuffers, DisconnectNamedPipe, CloseHandle, and GetLastError
These are all defined in WinBase.h as dll imports.
Unfortunately WinBase.h is a gigantic file that's used everywhere, so one can't merely stub out the items you want to test...
I tried copying WinBase.h and making inline versions of the functions:
bool
ConnectNamedPipe(
__in HANDLE hNamedPipe,
__inout_opt LPOVERLAPPED lpOverlapped
)
{ return false; }
But I get a compile error for every overridden function/object pair:
3>test.obj : error LNK2005: ReadFile already defined in main.obj
Main is very minimal, but it does contain
#include <file_templates/cppunit/generic_cppunit_main.cpp>
Which is likely to include WinBase.h somewhere in it's depths...
Even if I resolve this compile error, there's a possibility that I could break cppunit in the process?
Any solutions short of abstracting out all pipe calls and stubbing the abstract instead of WinBase.h?
inlinekeyword. Otherwise you'll get linker errors. - Greg Hewgill