
Ryo IGARASHI wrote:
On 3/23/06, Leif Gruenwoldt
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
#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