我已经创建了一个类说“GTEST_static_class.h”并为它创建了一个模拟 MockGTEST_static_class.h,之后我创建了 GTest_static_example.cpp,它调用了模拟类 MockGTEST_static_class。
问题是我收到编译错误..
编译错误
/x/opt/pp/include/gmock/gmock-spec-builders.h: In copy constructor âtesting::internal::FunctionMocker<void ()()>::FunctionMocker(const testing::internal::FunctionMocker<void ()()>&)â:
/x/opt/pp/include/gmock/gmock-spec-builders.h:1656: error: âtesting::internal::FunctionMockerBase<F>::FunctionMockerBase(const testing::internal::FunctionMockerBase<F>&) [with F = void ()()]â is private
/x/opt/pp/include/gmock/gmock-spec-builders.h:89: error: within this context
package/web/webscr/MockGTEST_static_class.h: In copy constructor âMockGTEST_static_class::MockGTEST_static_class(const MockGTEST_static_class&)â:
package/web/webscr/MockGTEST_static_class.h:7: note: synthesized method âtesting::internal::FunctionMocker<void ()()>::FunctionMocker(const testing::internal::FunctionMocker<void ()()>&)â first required here
package/web/webscr/GTest_static_example.cpp: In member function âvirtual void GTest_static_example_case1_Test::TestBody()â:
package/web/webscr/GTest_static_example.cpp:42: note: synthesized method âMockGTEST_static_class::MockGTEST_static_class(const MockGTEST_static_class&)â first required here
distcc[751] ERROR: compile package/web/webscr/GTest_static_example.cpp on localhost failed
runtask: /x/opt/pp/bin/distcc /usr/bin/g++ -D __LINUX__ -D _GNU_SOURCE -D XERCES_VERSION_AT_LEAST_27 -D WITH_OPENSSL -O2 -m32 -Wall -Wcast-qual -Werror -pipe -fno-strict-aliasing -D GTEST_DONT_DEFINE_ASSERT_EQ -D GTEST_DONT_DEFINE_ASSERT_NE -D GTEST_DONT_DEFINE_ASSERT_LE -D GTEST_DONT_DEFINE_ASSERT_LT -D GTEST_DONT_DEFINE_ASSERT_GE -D GTEST_DONT_DEFINE_ASSERT_GT -Wno-non-virtual-dtor -ftemplate-depth-48 -D GSOAP_PPSB -fpermissive -fno-enforce-eh-specs -Wno-deprecated -feliminate-unused-debug-types -I/x/local/gopc/gimp/code -I/x/local/gopc/scratch/prebuilts/ffxclient-devel-101.0-5531003.i686.rpm-install/include -I/x/paypal/build_uncert/RHEL5.4/infra/101.0.5447330/ifeature/include -I/x/paypal/build_uncert/RHEL5.4/infra/101.0.5447330/infra/include -I/x/local/gopc/scratch/prebuilts/ivr-biz-devel-1.0-4657646.i686.rpm-install/include -I/x/local/gopc/scratch/prebuilts/ivrserv-devel-1.0-4725318.i686.rpm-install/include -I/x/local/gopc/scratch/prebuilts/riskaimcommon-101.0.SNAPSHOT.rpm-install/include -I/x/local/gopc/scratch/prebuilts/sec-engg-devel-legacyBF_int-5077867.i686.rpm-install/include -I/x/local/gopc/scratch/prebuilts/user-devel-101.0-5530926.i686.rpm-install/include -isystem /x/opt/pp -isystem /usr/include/libxml2 -isystem /usr/include/xercesc -isystem /x/home/oracle/product/11.2.0.2/include -isystem /x/opt/ppdb4-4.5.20/include -isystem /x/opt/pp/include -isystem /x/opt/pp/include/mimepp -isystem /x/opt/pp/include/python2.6 -c package/web/webscr/GTest_static_example.cpp -o package/web/webscr/GTest_static_example.o exited with status 1
make: *** [package/web/webscr/GTest_static_example.o] Error 1
mm: WARNING: make exited with status 2
# Make finished with status 2 in 0.10 minutes (0.10 total)
GTEST_static_class.h
#include<iostream>
using namespace std;
class GTEST_static_class
{
public:
void display()
{
cout<< "inside the GTEST_static_class:: display " <<endl;
}
};
MockGTEST_static_class.h
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "GTEST_static_class.h"
class MockGTEST_static_class : public GTEST_static_class
{
public:
static GTEST_static_class m_GTEST_static_class;
static void set_instance( GTEST_static_class _class)
{
m_GTEST_static_class = _class;
}
/*
static iGTEST_static_class GTEST_class;
static void set_instance( GTEST_static_class _class)
{
GTEST_class = _class;
}
*/
MOCK_METHOD0(display,void(void));
};
GTest_static_example.cpp
#include <gtest/gtest.h>
#include <iostream>
#include "MockGTEST_static_class.h"
using namespace std;
class GTest_static_example : public::testing::Test
{
public:
virtual void SetUp();
virtual void TearDown();
void call_display()
{
GTEST_static_class _class = GTEST_static_class();
_class.display();
cout<<"display called from GTest_static_example"<<endl;
}
};
int main(int argc, char * argv[])
{
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
//return 1;
}
void GTest_static_example::SetUp()
{
}
void GTest_static_example::TearDown()
{
}
TEST_F(GTest_static_example,case1)
{
MockGTEST_static_class mock = MockGTEST_static_class();
MockGTEST_static_class::set_instance(mock);
//set_instance(mock);
EXPECT_CALL(mock,display()).Times(1);
//EXPECT_CALL(GTEST_static_class,display()).Times(1);
call_display();
}