Using Google Mock with boost :: bind

I have a class whose constructor performs the Boost function, and I would like to test it using Google Mock. The following code shows a sample class and my attempt to test it:

MyClass.h:

#include <boost/function.hpp>
class MyClass
{
public:
    MyClass(boost::function<void()> callback);
    void callCallback();
private:
    boost::function<void()> m_callback;
};

MyClassTest.cpp:

#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <boost/bind.hpp>
#include "MyClass.h"
class CallbackMock
{
public:
    MOCK_METHOD0(callback, void());
};

TEST(MyClassShould, CallItsCallback)
{
    CallbackMock callbackMock;
    MyClass myClass(boost::bind(&CallbackMock::callback, callbackMock));
    EXPECT_CALL(callbackMock, callback()).Times(1);
    myClass.callCallback();
}

Trying to compile MyClassTest.cpp in Visual Studio 2008 gives the following error:

... gmock/gmock --mockers.h(76): C2248: ':: :: FunctionMockerBase:: FunctionMockerBase': ':: :: FunctionMockerBase' 1 > 1 > [1 >
F = void (void) 1 > ] 1 >
.../gmock-spec-builders.h(1656): . ':: :: FunctionMockerBase:: FunctionMockerBase' 1 > 1 > [1 >
F = void (void) 1 > ] 1 >
":: :: FunctionMocker:: FunctionMocker (Const :: :: FunctionMocker &) '1 > 1 > [1 >
= void (void) 1 > ]

, boost:: bind. mocked void callback() {} ( Google Mock, ). ?

+5
2

, :

MyClass myClass(boost::bind(&CallbackMock::callback, callbackMock));

&callbackMock

+5

, Google Mock mocks - . boost::bind , . bind:

MyClass myClass(boost::bind(&CallbackMock::callback, &callbackMock));
+16

All Articles