|
Boost Users : |
Subject: Re: [Boost-users] boost test: How to make boost test a friend ?
From: Olaf Meeuwissen (olaf.meeuwissen_at_[hidden])
Date: 2010-02-28 19:09:41
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Gennadiy Rozental wrote:
> Avi Bahra wrote:
>> I am looking into boost test.
>> I dont not want to expose some member functions as public.
>> However I need to access them for testing, is there
>> any way making boost test a friend of this class ?
>
> You do not really need to make Boost.Test routines friends of your
> class. You should be able to get away with making your test functions as
> friends.
Another option is to make those member functions protected and derive a
class for testing purposes that promotes them to public.
class A {
int a;
protected:
int get_value () { return a; }
};
class test_A : public A {
public:
using get_value ();
};
Now your tests can use test_A objects and access its public get_value().
Just keep class test_A out of your program/module and everything should
be fine.
This approach has the benefit that it keeps all the testing stuff out of
your regular code as well.
Hope this helps,
- --
Olaf Meeuwissen, LPIC-2 FLOSS Engineer -- AVASYS CORPORATION
FSF Associate Member #1962 Help support software freedom
http://www.fsf.org/jf?referrer=1962
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkuLBcUACgkQt5qrxaZLMnJa6QCfcivgQfJst0lgwGq5W2eLHlY6
wwkAn2RvgHhP8vwEX6O6X25lCetuUIcW
=qldS
-----END PGP SIGNATURE-----
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