Boost logo

Boost :

Subject: Re: [boost] Interest check: Boost.Mock
From: Peder Holt (peder.holt_at_[hidden])
Date: 2009-06-11 03:10:47


2009/6/10 Peter Bindels <dascandy_at_[hidden]>

> Hi all,
>
> Over the past three-quarters of a year I've been working (with three
> friends) on a mocking framework for C++. In our vision, it would be a good
> complement to Boost.Test for testing classes separate from interfaces
> required - it would improve the ability to unit-test the classes that tie
> others together and that implement higher-level algorithms.
>
> <snip>

This looks very interesting. I have been looking for a proper mocking
framework for C++ for a while.
I looked at the implementation, and it looks very good.

One comment:
Registering overloaded functions can be done simpler:

struct Const {};
struct Volatile {};
struct NoQualifier {};

#define constMOCK_EATER ,Const
#define volatileMOCK_EATER ,Volatile
#define MOCK_EATER ,NoQualifier

template<typename Class,typename Signature,typename Qualifier>
class DeduceMemberFunction;

template<typename Class,typename R,typename A0>
class DeduceMemberFunction<Class*,R(A0),Const>
{
   typedef R (Class::*Type) const;
};
//And a gazillion other overloads on signatures:

#define OnCallOverload(obj, signature,func) RegisterExpect_<__LINE__,
DontCare>(obj, typename
DeduceMemberFunction<BOOST_TYPEOF(obj),BOOST_PP_CAT(signature,MOCK_EATER)>::Type(func),
#func, __FILE__)

Usage:
class IBar {
   int Test(int,double) const;
   int Test(int,double);
   void Test(double);
};

mocks.OnCallOverload(barMock,int(int,double) const,IBar::c);

(The code is not tested, but I have a similar layout in a library I am
developing where this technique is used)

Regards
Peder


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk