title: Google Mock: mock fstream object and control of execution in test
body: <p>I need to write some unit test for following function. In order to do that I need to mock ifstream object. I did that but I have a problem with control of execution during test. How can I set value returned by get in 
  <code>while(p_fileDescriptor-&gt;get(l_singleByte))</code>
  to eofbit object in one case and to "normal" istream object in another case? I tried some options, but it was not work. Could you help me with that?
  Bellow function there is my unit test.
  Function to test:</p>
  
  <pre><code>void ServerSendFileRequestHandler::sendRequestedFile(std::shared_ptr&lt;std::istream&gt; p_fileDescriptor, int&amp; p_clientSocket) const
  {
  unsigned int l_msgCounter = 1;
  unsigned long long l_byteCounter = 0;
  Message l_sendline;
  memset(&amp;l_sendline, 0, sizeof(l_sendline));
  
  char l_singleByte;
  while(p_fileDescriptor-&gt;get(l_singleByte))
  {
      checkIfReadByteSucceded(p_fileDescriptor, l_byteCounter);
      l_sendline.payload[l_byteCounter] = l_singleByte;
      l_byteCounter++;
  
      if(l_byteCounter == PAYLOAD_SIZE)
      {
          std::cout &lt;&lt; "Sending message number: " &lt;&lt; l_msgCounter &lt;&lt; std::endl;
          sendClientSendFileInd(l_sendline, l_byteCounter, p_clientSocket);
          l_msgCounter++;
  
          l_byteCounter = 0;
          memset(&amp;l_sendline, 0, sizeof(l_sendline));
      }
  }
  
  if(l_byteCounter)
  {
      std::cout &lt;&lt; "Sending message number: " &lt;&lt; l_msgCounter &lt;&lt; std::endl;
      sendClientSendFileInd(l_sendline, l_byteCounter, p_clientSocket);
      l_msgCounter++;
  }
  std::cout &lt;&lt; "Sending of file is done!" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>My unit test:</p>
  
  <pre><code>#include "gmock/gmock.h"
  #include &lt;istream&gt;
  using namespace std;
  class FstreamMock : public std::istream  
  {
  public:
      MOCK_METHOD1(get, istream&amp;(char&amp;));
  };
  
  using namespace testing;
  TEST_F(ServerSendFileRequestHandlerTestSuite, sendRequestedFileTest)
  {
      int l_clientSocket = 0;
      std::shared_ptr&lt;FstreamMock&gt; l_fileDescriptor;
      const bool i = false;
  
      char l_byte;
      //EXPECT_CALL(*l_fileDescriptor, get(_)).WillRepeatedly(ReturnRef(*l_fileDescriptor));
      EXPECT_CALL(*l_fileDescriptor, get(_)).WillRepeatedly(ReturnRef(*l_fileDescriptor);
      m_sut.sendRequestedFile(l_fileDescriptor, l_clientSocket);
  }
  </code></pre>