Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gmock call function two times

I would like to mock function that return void:

class FileDownloaderMock : public FileDownloader
{
public:
    MOCK_CONST_METHOD1(downloadFile,
                       void(data *data_ptr));

}; 

in test case i would like to call this function 2 times, firstly should rise an exception and in the second times should work correctly. So my test case looks like this but doesn't work.

TEST_F(BCtrlTargetBdDownloaderTests, DownloaderShouldCorrectlyDownloadTargetBdInFirstAttempt)
{
     EXPECT_CALL(m_fileDownloader, downloadFile( DataReqMatcher(l_expectedReq) ) ).Times(2)
        .WillOnce(Throw(UpgradeException("Download failed") )); 
    }

The console output:

to few actions specified in EXPECT_CALL(m_fileDownloader, downloadFile( DataReqMatcher(l_expectedReq) ))... Expected to be called twice, but has only 1 WillOnce().

So how can I solve this puzzle? Best Regards

like image 901
user1877600 Avatar asked Sep 02 '14 16:09

user1877600


1 Answers

Your EXPECT_CALL configuration should look like

 EXPECT_CALL(m_fileDownloader, downloadFile( DataReqMatcher(l_expectedReq) ) )
    .Times(2)
    .WillOnce(Throw(UpgradeException("Download failed")))
    .WillOnce(Return()); 
like image 60
πάντα ῥεῖ Avatar answered Oct 20 '22 12:10

πάντα ῥεῖ