googletest - mock gtest compilation error -
i had crated class "gtest_static_class.h" , created mock mockgtest_static_class.h, after creating gtest_static_example.cpp, call' mock class mockgtest_static_class.
the problem getting compilation error..
compilation error
/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 ()()]â private /x/opt/pp/include/gmock/gmock-spec-builders.h:89: error: within 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 status 1 make: *** [package/web/webscr/gtest_static_example.o] error 1 mm: warning: make exited status 2 # make finished 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 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 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(); }
Comments
Post a Comment