??????? BOOST_TEST_CASE ?????????????????????????????????? ?嵥 17 ?У?test_case1??test_case2 ???? void ??????????????????????????д???????????Boost ?????????????Щ????棻????? BOOST_TEST_SUITE ???????????????μ? boost::unit_test::test_suite(<test suite name>)??

???????

???????????????????????test fixture?????????в???????????????????????????????????嵥 19 ????????????????

?????嵥 19. ?????? Boost ???

#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>
#include <iostream>
struct F {
F() : i( 0 ) { std::cout << "setup" << std::endl; }
~F()          { std::cout << "teardown" << std::endl; }
int i;
};
BOOST_AUTO_TEST_SUITE( test )
BOOST_FIXTURE_TEST_CASE( test_case1?? F )
{
BOOST_CHECK( i == 1 );
++i;
}
BOOST_AUTO_TEST_SUITE_END()

?????嵥 20 ???????????

?????嵥 20. Boost ????????

[arpan@tintin] ./a.out
Running 1 test case...
setup
fix.cpp(16): error in "test_case1": check i == 1 failed
teardown
*** 1 failure detected in test suite "example"

??????δ????????? BOOST_AUTO_TEST_CASE ????????? BOOST_FIXTURE_TEST_CASE????????????????????????????? constructor ?? destructor ??????б???????ú??????????????? Boost ???? unit_test_suite.hpp ?????????????? ?嵥 21????

?????嵥 21. ???? unit_test_suite.hpp ?е? Boost ???????

#define BOOST_FIXTURE_TEST_CASE( test_name?? F )       /
struct test_name : public F { void test_method(); };                   /
/
static void BOOST_AUTO_TC_INVOKER( test_name )()       /
{                                                                                       /
test_name t;                                                                        /
t.test_method();                                                                    /
}                                                                                       /
/
struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {};       /
/
BOOST_AUTO_TU_REGISTRAR( test_name )(                     /
boost::unit_test::make_test_case(                                            /
&BOOST_AUTO_TC_INVOKER( test_name )?? #test_name )??                  /
boost::unit_test::ut_detail::auto_tc_exp_fail<                                   /
BOOST_AUTO_TC_UNIQUE_ID( test_name )>::instance()->value() );   /
/
void test_name::test_method()                              /

???????????Boost ?? struct F ????????????????? ?嵥 19??????????????????????? C++ ???????й?????????п????????? struct ???????????????????????????????? ?嵥 19 ????????? i ????????? F ????????? t???? ?嵥 20???????????????п?????м?????????????????????????????????????????????????? ?嵥 22 ?????????????У?????????????????????????