Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Mock for a constant method in Turtle

I have,

class CFoo : public CFooPar
{
   public:
      CFoo(){}
      ~CFoo(){}

      virtual bool ret() const
      {
         return true;
      }
};

How can I create mock class for this virtual bool ret() const method?

Thank you!

like image 804
domlao Avatar asked May 08 '13 03:05

domlao


2 Answers

I use Google Mock for that (https://code.google.com/p/googlemock/wiki/V1_6_ForDummies).

With that tool, the mock reads

#include "gmock/gmock.h"
class MockCFoo : public CFoo {
    public:
    MOCK_CONST_METHOD0(ret, bool());
};
like image 153
rcomblen Avatar answered Oct 05 '22 08:10

rcomblen


If you mean using turtle here it is :

#include <turtle/mock.hpp>

MOCK_BASE_CLASS( MockCFoo, CFoo )
{
    MOCK_METHOD( ret, 0 )
};

The rest depends on how you use CFoo in your production code, however it would likely be similar to the turtle motivation case I suppose.

like image 38
mat007 Avatar answered Oct 05 '22 08:10

mat007