title: Google Mock Destructor
body: <p>I'm trying to become familiar with Google's mocking framework so I can more easily apply some TDD to my C++ development. I have the following interface:</p>
  
  <pre><code>#include &lt;string&gt;
  
  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;
  };
  </code></pre>
  
  <p>I want to verify that the destructor is called when an instance is deleted. So I have the following MockSymbol class:</p>
  
  <pre><code>#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(); }
  };
  </code></pre>
  
  <p>Note: I've omitted the include guards in the above but they are in my header files.</p>
  
  <p>I haven't been able to get to a point where I'm actually testing anything yet. I have the following:</p>
  
  <pre><code>#include "gmock/gmock.h"
  #include "MockSymbol.h"
  
  TEST(SymbolTableTests, DestructorDeletesAllSymbols) {
      ::testing::FLAGS_gmock_verbose = "info";
      MockSymbol *mockSymbol = new MockSymbol("mockSymbol");
      EXPECT_CALL(*mockSymbol, Die());
  }
  </code></pre>
  
  <p>When I execute my test runner, my other tests execute and pass as I expect them to. However, when the above test executes I get the following error:</p>
  
  <p>SymbolTableTests.cpp:11: EXPECT_CALL(*mockSymbol, Die()) invoked
  Segmentation fault      (core dumped)</p>
  
  <p>I've spent the last few hours searching Google and trying different things, but to know avail. Does anyone have any suggestions?</p>