title: C++ Google Mock SaveArg : how to save a pointer argument
body: <p>I having difficulty saving a pointer argument that my mock receives.</p>
  
  <pre><code>#define SIZE_OF_DATA
  
  typedef struct {
      uint32_t someValue1;
      uint16_t someValue2;
      // other values here
  } LargeStruct;
  
  
  class SomeClass {
  public:
      // assume sendData is a generic function where data is actually pointer to a LargeStruct
      void sendData(const uint8_t* data, const uint16_t size);
  }
  
  class MockClass : public SomeClass {
  public:
      MOCK_METHOD2(sendData, void(const uint8_t*, const uint16_t));
  };
  </code></pre>
  
  <p>I want to save the first argument to sendData (the pointer) and look at the data it points to (it points to a large struct, so I don't want to copy by value):</p>
  
  <pre><code>TEST(SomeFixture, sendData_checkSentDataIsValid) {
     MockClass mock;
  
    const uint8_t *pData;
    EXPECT_CALL(mock, sendData(_, SIZE_OF_DATA)).WillOnce(SaveArg&lt;0&gt;(&amp;pData));
  
    // do something here that calls sendData()
  
    // hopefully data should point to the same data that was passed in to the method
    LargeStruct *ls = (LargeStruct *)pData;
  
    // now verify that the data is ok...
    // some expectations here
    EXPECT_EQ(SOMEVALUEIWANT, ls-&gt;someValue1); 
  
  }
  </code></pre>
  
  <p>However, the data pointed to by pData is wrong - I think I appear to be saving the pointer value into the struct, rather than saving the pointer.  </p>
  
  <p>I think the problem lies in the variable I pass to SaveArg, but I can't seem to get it in a version that compiles and gives me the correct answer.  Any pointers please?</p>