Boost logo

Boost Users :

Subject: [Boost-users] [test] testing protected/private methods out of test suits
From: M. Siebeneicher (trashing_at_[hidden])
Date: 2008-09-18 03:26:44


Hello boost-users,

I tried to test protected/private class methods by declaring the test-case-class as a friend of the class-to-test. The test-case-class is defined by the macro BOOST_FIXTURE_TEST_CASE(T, F). That works fine as long as I encapsulate the test-case with BOOST_AUTO_TEST_SUITE(suite_name) and BOOST_AUTO_TEST_SUITE_END().

I'm not able to define the correct friend declaration, cause the compiler . Can someone give me hint, please?

the code looks like this:

// test-case-class.cpp
namespace foo { namespace bar {

BOOST_AUTO_TEST_SUITE(suite_name)

struct F {
  class-to-test class_to_test_instance;
}
.
.
.

BOOST_FIXTURE_TEST_CASE(test-case-class, F) {
  F.class_to_test_instance.i;
  .
  .
  .
}
.
.
.
BOOST_AUTO_TEST_SUITE_END()
}}

class-to-test.cpp

namespace foo { namespace bar {
.
.
.
class class-to-test {
public:
  friend struct test-case-class; // that's wrong // No access to protected member i
  friend struct suite_name::test-case-class; // this is wrong, too: compiler error, can't find foo::bar::suite_name, ....

protected:
  int i;
  .
  .
  .
};

}}

greetz,
modbom

-- 
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx

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