title: gmock : Doing custom check that can fail
body: <p>I am using google mock library in my unit tests, and I am trying to do a custom check that can fail.</p>
  
  <p>Next example demonstrates what I am trying to do :</p>
  
  <pre><code>struct Base
  {
  };
  struct Derived : Base
  {
    int a;
  };
  
  struct MockClass
  {
    MOCK_METHOD1( Send, void ( Base &amp; ) );
  };
  </code></pre>
  
  <p>Now I would like to check if the fake object got passed object of type Derived in the Send method, and the value a.
  So, how to do it?</p>
  
  <p>My idea is to use Invoke and forward the call to some function, which will dynamic_cast from Base to Derived, and check the value. If the type is not of expected throw an exception. Like this :</p>
  
  <pre><code>void TestCall( Base &amp;obj )
  {
    Derived *realObj = dynamic_cast&lt; Derived * &gt;( &amp;obj );
    if ( NULL == realObj )
    {
      throw 123;
    }
  }
  </code></pre>
  
  <p>then test like this :</p>
  
  <pre><code>MockClass mockObj;
  EXPECT_CALL( mockObj, Send(_) )
    .WillOnce( Invoke( &amp;TestCall ) );
  </code></pre>
  
  <p>Is this going to work? Or is there a better way?</p>