Question

I'm attempting to integrate googlemock into my tests. I had already successfully built and run tests on googletest, and now am trying to incrementally add the gmock functionality into the tests as well, but I've hit a compile error that I utterly do not understand.

I am not attempting to use or define mocked classes, or use anything gmock.h provides. At the top of my (previously working) tests.cpp file I merely type

#include "gmock/gmock.h"

And I get the compile error:

gmock/gmock-matchers.h(2497) : error C2059: syntax error : 'sizeof'

gmock/gmock-matchers.h(2505) : see reference to class template instantiation 'testing::internal::ElementsAreMatcherImpl' being compiled

gmock/gmock-matchers.h(2497) : error C2059: syntax error : ')'

gmock/gmock-matchers.h(2497) : error C2143: syntax error : missing ')' before '{'

gmock/gmock-matchers.h(2497) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

gmock/gmock-matchers.h(2499) : warning C4183: 'Message': missing return type; assumed to be a member function returning 'int'

I'm compiling this using nmake/vc++ on Windows 7, and I can't fathom why I would get these compile errors simply from adding the core gmock include file to my test file. Has anyone seen this sort of thing before?

Was it helpful?

Solution

  1. Did you init google mock with InitGoogleMock(&__argc, __argv) in test project's main function?
  2. You should include only "gmock/gmock.h" in your test files (and where you call InitGoogleMock) - no need for inclusion of gtest.h.
  3. Have you updated your googletest library to googlemock. (https://github.com/google/googletest)

If all the things above are true it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top