Randy, one possibility is that you have a typo in the mock definition.
If somehow you missed a parenthesis somewhere, the compiler could
think the rest of the entire file is one macro argument, which could
make it seriously confused and do insane things. To catch such
errors, you might want to try binary search (i.e. commenting out
roughly half of the code and see if it compiles, repeating until you
find the problem).
Thanks,
--
Zhanyong
Thank you both for the helpful suggestions. I'm positive it is not a typo. The code will eventually compile. I tried Vlad's version, minus the gtest code, since we are using a different framework. Eventually, it compiles just fine, it just uses way too much memory. I have tried faking all methods I don't really need, which brought the count from 115+ down to just over 50 methods. The compiler still eats up 800MB while compiling and takes quite a while.On top of that, if I include this header inside of any source file that has other includes (especially includes for other gmocked classes) the compiler eventually fails due to error C1128 (number of sections exceeded object file format limit).
For the sake of reference, we are testing a native c++ library that is part of a mixed-mode application. We are using MS Test, so the unit tests are technically C++/CLI (managed), but they test native code, using native gmock objects.
The original cause of this problem was that I mocked the IDirect3D9 interface (as gmock_IDirect3D9) and then had the constructor of gmock_IDirect3D9 initializing an instance of gmock_IDirect3DDevice9 and setting the default action for gmock_IDirect3D9::CreateDevice() to return the instance of gmock_IDirect3DDevice9. The end behavior is that a mocked IDirect3D9 always returns a mocked IDirect3DDevice9 by default, without the testing code being required to always set that action up.
Anyway, I was thinking that normally a class that implements such a large interface wouldn't put all of the actual function definitions into a header file(which the MOCK_METHOD* macros do), thereby forcing the compiler to go through those definitions every time the file is included. Normally, one would simply put declarations for the functions in the header and put the definitions into an implementation file, causing the compiler to generate the functions only once.Is there any way to do this with gmock? If I could split the definitions for the mocked functions up into a few source files, it should ease the amount of generation the compiler has to do all at once. It seems like that might help. Otherwise, I can barely mock any of this interface before I run into memory issues.
Glad you enjoyed it.
FYI: I played with Google Mock's implementation a bit to see if I can
reduce VC's memory consumption. I didn't find anything easy that
would lead to a meaningful result. Therefore I'm shelving this for
now. Thanks,
2009/5/1 Randy Schott <randy...@gmail.com>:
--
Zhanyong