I have an issue with the google mock EXPECT_CALL macro. The following code gives compilation error on the EXPECT_CALL Statement:
error C2660: 'testing::Eq' : function does not take 1 arguments \gmock-1.6.0\include\gmock\gmock-matchers.h
Basically I have a base container and base data object for that container, both abstract and a cache which has a pointer to base container and an Add method that takes a reference to base data object. I have created a basic program to demonstrate the issue. Thanks a lot if anyone can help.
#include "gtest/gtest.h"
#include "gmock/gmock.h"
namespace
{
class BaseData
{
public:
virtual void SetValue(const int value) = 0;
};
class BaseContainer
{
public:
virtual void Add(const BaseData& data) = 0;
};
class MockContainer : public BaseContainer
{
public:
MOCK_METHOD1(Add, void (const BaseData& data));
};
class MockData : public BaseData
{
public:
MOCK_METHOD1(SetValue, void (int));
};
class Cache
{
private:
BaseContainer* container;
public:
Cache(BaseContainer* c)
{
container = c;
}
~Cache()
{
}
void AddToContainer(const BaseData& data)
{
container->Add(data);
}
};
class CacheTestFixture : public ::testing::Test
{
protected:
CacheTestFixture() {}
virtual ~CacheTestFixture() {}
virtual void SetUp() {}
virtual void TearDown() {}
};
TEST_F(CacheTestFixture, TestAdd)
{
MockData data;
MockContainer container;
EXPECT_CALL(container, Add(data)).WillRepeatedly(::testing::Return());
Cache c(&container);
ASSERT_NO_THROW(c.AddToContainer(data));
}
}
int _tmain(int argc, _TCHAR* argv[])
{
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
EXPECT_CALL(container, Add(testing::Ref(data))).WillRepeatedly(::testing::Return());
To send the mock implementation as a base class reference, testing::Eq
would require the ==
operator to be implemented on the abstract base class which is not desirable.
You need to use ::testing::Eq(ByRef(data))
::testing::Eq
is Matcher that needs to be used, read about matchers on Google Mock Cookbook.
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