c++ - Google Mock Destructor -
i'm trying become familiar google's mocking framework can more apply tdd c++ development. have following interface:
#include <string> class symbol { public: symbol (std::string name, unsigned long address) {} virtual ~symbol() {} virtual std::string getname() const = 0; virtual unsigned long getaddress() const = 0; virtual void setaddress(unsigned long address) = 0; };
i want verify destructor called when instance deleted. have following mocksymbol class:
#include "gmock/gmock.h" #include "symbol.h" class mocksymbol : public symbol { public: mocksymbol(std::string name, unsigned long address = 0) : symbol(name, address) {} mock_const_method0(getname, std::string()); mock_const_method0(getaddress, unsigned long()); mock_method1(setaddress, void(unsigned long address)); mock_method0(die, void()); virtual ~mocksymbol() { die(); } };
note: i've omitted include guards in above in header files.
i haven't been able point i'm testing yet. have following:
#include "gmock/gmock.h" #include "mocksymbol.h" test(symboltabletests, destructordeletesallsymbols) { ::testing::flags_gmock_verbose = "info"; mocksymbol *mocksymbol = new mocksymbol("mocksymbol"); expect_call(*mocksymbol, die()); }
when execute test runner, other tests execute , pass expect them to. however, when above test executes following error:
symboltabletests.cpp:11: expect_call(*mocksymbol, die()) invoked segmentation fault (core dumped)
i've spent last few hours searching google , trying different things, know avail. have suggestions?
i found setting gtest_disable_pthreads on in build config solves problem.
Comments
Post a Comment