title: GMock: How to return mock class variable as the return value
body: <p>I am trying to use GMock (google mocking framework for c++) for the first time. I have the following class:</p>
  
  <pre><code>class LocalCache
  {
  public:
    virtual time_t GetCurrentTime() = 0;
    virtual int AddEntry(const std::string key, std::string&amp; value);
    virtual int GetEntry(const std::string key, std::string&amp; value);
  };
  </code></pre>
  
  <p>The <code>GetEntry</code> method invokes <code>GetCurrentTime</code> call. I'd like to mock the GetCurrentTime method so that I can advance the clock in my test to test the aging out of entries which happens as part of the <code>GetEntry</code> call (please don't ask me why the aging is being done as part of <code>GetEntry</code> call... that's another discussion :( ). Here's my mock class:</p>
  
  <pre><code>class MockLocalCache : public LocalCache
  {
  public:
    using LocalCache::GetCurrentTime;
    MOCK_METHOD0(GetCurrentTime, time_t());
  
    MockLocalCache()
    : mCurrentTime(0)
    {
    }
  
    void EnableFakeTime()
    {
      ON_CALL(*this, GetCurrentTime()).WillByDefault(Return(mCurrentTime));
    }
  
    void SetTime(time_t now) { mCurrentTime = now; }
  
  private:
    time_t  mCurrentTime;
  };
  
  TEST(MockTest, TimeTest)
  {
    MockLocalCache mockCache;
  
    mockCache.EnableFakeTime();
  
    std::string key("mykey");
    std::string value("My Value");
  
    EXPECT_TRUE(mockCache.AddEntry(key, value));
  
    mockCache.SetTime(10);   // advance 10 seconds
  
    std::string expected;
    EXPECT_TRUE(mockCache.GetEntry(key, expected));
  }
  </code></pre>
  
  <p>When I run the test, I expected the <code>mCurrentTime</code> value to be return by my mock <code>GetCurrentTime</code> function. However, I get the following error output:</p>
  
  <pre><code>GMOCK WARNING:
  Uninteresting mock function call - taking default action specified at:
  ..../test_local_cache.cpp:62:
      Function call: GetCurrentTime()
            Returns: 0
  Stack trace:
  </code></pre>
  
  <p>Would appreciate it if someone can let me know what I am doing wrong and how to fix it. Thanks in advance. </p>