Can gmock be used for stubbing C functions?

前端 未结 6 1761
时光取名叫无心
时光取名叫无心 2020-12-05 15:25

I am new to gmock, so I want to know how can I stub simple C function called in a function under test for Unit Testing.

Example:

int func(int a)
{
           


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 15:47

    You can use the Cutie library to mock C function GoogleMock style.
    There's a full sample in the repo, but just a taste:

    INSTALL_MOCK(close);
    CUTIE_EXPECT_CALL(fclose, _).WillOnce(Return(i));
    

提交回复
热议问题