Boost logo

Boost Users :

From: Paul Giaccone (paulg_at_[hidden])
Date: 2006-03-27 05:05:42


Ryo IGARASHI wrote:

>On 3/23/06, Leif Gruenwoldt <leifer_at_[hidden]> wrote:
>
>
>>Is there a way to test the private functions of a class without moving
>>them into public scope during test?
>>
>>What are some strategies for this?
>>
>>
>
>Try following evil hack.
>
>// someclass_test.hpp
>#define private public
>#define protected public
>
>#include <someclass.hpp>
>
>#undef protected
>#undef private
>
>

Evil, evil, evil!

Slightly less so is what I have done in my code. Define a variable (say,
TESTING) in the makefile or preprocessor definitions of your test
program. In your class definitin, change "private:" to the following:

#ifdef TESTING
public:
#else
private:
#endif

Of course, you leave TESTING undefined (or make sure it is undefined) in
your non-test program.

It's perhaps not nice to look at, but it's less nasty than the above
hack, IMO.

Paul


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net