whazzmaster
whazzmaster

Reputation: 576

Compile error when I #include "gmock/gmock.h"

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?

Upvotes: 9

Views: 23140

Answers (3)

naveen_ky
naveen_ky

Reputation: 1

Things to make sure before using gtest and gmock.

  1. Include the gmock lib in Android.bp file.
  2. Include the header "external/googletest/googlemock/include" in include_dirs in Andoird.bp.
  3. Initialize the gmock and gtest in your test main function.
    testing::InitGoogleTest(&argc, argv);
    testing::InitGoogleMock(&argc, argv);

Upvotes: 0

arshad harshu
arshad harshu

Reputation: 1

#include <iostream>
#include "gmock/gmock.h"

template <typename T>
class Foo : private T {
public:
  void foo() {
    T::bar();
  }

};

class Bar {
public:
  void bar() {
    std::cout << "Hey there!" << std::endl;
  }
};



int main() {
  Foo<Bar> f;
  f.foo();
}

template <typename T>
class Foo : private T {
public:
  void foo() {
    T::bar();
  }
};

class Bar {
public:
  void bar() {
    std::cout << "Hey there!" << std::endl;
  }
};



int main() {
  Foo<Bar> f;
  f.foo();
}

Upvotes: -1

Doge Person
Doge Person

Reputation: 121

  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.

Upvotes: 4

Related Questions