Boost logo

Boost Users :

Subject: [Boost-users] [Test] How to Access Private Data from a Test
From: Merrill Cornish (merrill.cornish_at_[hidden])
Date: 2015-06-25 15:37:30


In the Bad-Old-Days when I had to roll my own, I would define my tests
as methods of a special test class. If those tests needed to access
private data in the classes under test, I would declare special test
class as a friend of the class under test--one extra statement and
everything worked.

How do I do that using Boost test (1.58.0) with the AUTO_TEST family of
macros?

In the labyrinth of macro expansions, I found a struct name with the
argument name from BOOST_AUTO_TEST_CASE(), but a friend of that name
doesn't work.

The ideal case would be to declare the string name in
BOOST_AUTO_TEST_SUITE() as a friend so one friend declaration does it
all. Alternately, having to declare a separate friend for each
BOOST_AUTO_TEST_CASE() would be tedious (especially for large classes),
but it would work.

At the moment, I'm using the ole private=public trick:

     #define private public
     #include "header_under_test"
     #undef private

However, I've already discovered one system header, <sstream>, that
won't work with that kludge. There may be others.

Is there another workaround for Boost Tests? I can't be the only one
who has to access private data in tests.

Merrill Cornish


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