I'm trying to build a simple mocked class
#include "interpolation.hpp"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
class MockInterp1D : public Interp1DBase {
public:
MOCK_METHOD1(evaluateAt, double(double));
MOCK_METHOD2(evaluateAt, double(double, int));
};
based on the following base class
class Interp1DBase {
public:
virtual double evaluateAt(double) const = 0;
virtual double evaluateAt(double, int) const = 0;
virtual ~Interp1DBase() { };
};
using Google Mocks. When I try to compile the tests where this mock is used, I get the following error:
In file included from /usr/include/gmock/gmock-generated-function-mockers.h:43:0,
from /usr/include/gmock/gmock.h:61,
from /home/tlycken/exjobb/Code/alpha-orbit-follower/test/interpolation/interpolation-mocks.hpp:4,
from /home/tlycken/exjobb/Code/alpha-orbit-follower/test/physics/B-field-tests.hpp:6,
from /home/tlycken/exjobb/Code/alpha-orbit-follower/test/physics/B-field-tests.cpp:2:
/usr/include/gmock/gmock-spec-builders.h:134:41: error: expected ‘;’ at end of member declaration
bool VerifyAndClearExpectationsLocked()
^
and then literally hundreds of similar syntax or definition errors all pointing to files within GMock.
I took a look at gmock-spec-builder.h:134, and found the following (in some context):
// Verifies that all expectations on this mock function have been
// satisfied. Reports one or more Google Test non-fatal failures
// and returns false if not.
bool VerifyAndClearExpectationsLocked()
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
which led me to believe that GTEST_EXCLUSIVE_LOCK_REQUIRED_ might be a macro that for some reason wasn't defined. And indeed, after digging through all header files included from either gmock/gmock.h or gtest/gtest.h I still haven't found the definition of that macro.
What am I doing wrong here?
UPDATE:
I've been able to produce an even simple minimal example:
// in file mock-test.cpp
#include <gmock/gmock.h>
// Yeah, that's the only content
Compile with
g++ -o mock-test.o -c mock-test.cpp
Causes the same error.
I've installed GMock through sudo apt-get install google-mock, which gave me a folder under /usr/src where I could run cmake . followed by make to generate library files which I copied to /usr/lib. The header files were already in /usr/include so I didn't do anything about them manually.
I got the same error when I tried to compile using gmock 1.7 with gtest 1.6. Make sure you are using the same version of gtest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With