1 // (C) Copyright Gennadiy Rozental 2005-2014.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org/libs/test for the library home page.
7
8 // Boost.Test
9 #define BOOST_TEST_MODULE Unit_test_example_04
10 #include <boost/test/unit_test.hpp>
11 namespace bt=boost::unit_test;
12
13 //____________________________________________________________________________//
14
15 struct suite_fixture {
suite_fixturesuite_fixture16 suite_fixture() { BOOST_TEST_MESSAGE( "Running some test suite setup" ); }
~suite_fixturesuite_fixture17 ~suite_fixture() { BOOST_TEST_MESSAGE( "Running some test suite teardown" ); }
18 };
19 struct suite_fixture2 {
suite_fixture2suite_fixture220 suite_fixture2() { BOOST_TEST_MESSAGE( "Running some more test suite setup" ); }
~suite_fixture2suite_fixture221 ~suite_fixture2() { BOOST_TEST_MESSAGE( "Running some more test suite teardown" ); }
22 };
23
24 // automatically registered test cases could be organized in test suites
25 BOOST_AUTO_TEST_SUITE( my_suite1,
26 * bt::fixture<suite_fixture>()
27 * bt::fixture<suite_fixture2>() )
28
29 BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(my_test1,1)
30
some_setup()31 void some_setup()
32 {
33 BOOST_TEST_MESSAGE( "Running some extra setup" );
34 }
35
36 auto& d =
37 * bt::label( "L1" )
38 * bt::label( "L2" )
39 * bt::description( "test case 1 description" )
40 * bt::fixture( &some_setup );
BOOST_AUTO_TEST_CASE(my_test1)41 BOOST_AUTO_TEST_CASE( my_test1 )
42 {
43 BOOST_TEST( 2 == 1 );
44 }
45
46 //____________________________________________________________________________//
47
48 // this test case belongs to suite1 test suite
49 BOOST_AUTO_TEST_CASE( my_test2, * bt::description( "test case 2 description" ) )
50 {
51 int i = 0;
52
53 BOOST_TEST( i == 2 );
54
55 BOOST_TEST( i == 0 );
56 }
57
58 BOOST_AUTO_TEST_SUITE_END()
59
60 //____________________________________________________________________________//
61
62 // this test case belongs to master test suite
BOOST_AUTO_TEST_CASE(my_test3)63 BOOST_AUTO_TEST_CASE( my_test3 )
64 {
65 int i = 0;
66
67 BOOST_TEST( i == 0 );
68 }
69
70 //____________________________________________________________________________//
71
72 BOOST_TEST_DECORATOR(
73 * bt::label( "L3" )
74 * bt::description( "suite description" )
75 )
BOOST_AUTO_TEST_SUITE(my_suite2)76 BOOST_AUTO_TEST_SUITE( my_suite2 )
77
78 // this test case belongs to suite2 test suite
79 BOOST_AUTO_TEST_CASE( my_test4, * bt::depends_on( "my_suite2/internal_suite/my_test5" ) )
80 {
81 int i = 0;
82
83 BOOST_CHECK_EQUAL( i, 1 );
84 }
85
86 BOOST_AUTO_TEST_SUITE( internal_suite )
87
88 // this test case belongs to my_suite2:internal_suite test suite
89
90 BOOST_TEST_DECORATOR(
91 * bt::timeout( 100 )
92 )
93 BOOST_AUTO_TEST_CASE( my_test5, * bt::expected_failures( 1 ) )
94 {
95 int i = 0;
96
97 BOOST_CHECK_EQUAL( i, 1 );
98 }
99
100 BOOST_AUTO_TEST_CASE( my_test6, *bt::disabled() )
101 {
102 }
103
104 BOOST_AUTO_TEST_CASE( this_should_also_be_disabled,
105 * bt::depends_on( "my_suite2/internal_suite/disabled_suite/my_test7" ) )
106 {
107 }
108
109 BOOST_AUTO_TEST_SUITE( disabled_suite, * bt::disabled() )
110
BOOST_AUTO_TEST_CASE(my_test7)111 BOOST_AUTO_TEST_CASE( my_test7 ) {}
112
113 BOOST_AUTO_TEST_SUITE_END()
114
115 BOOST_AUTO_TEST_SUITE_END()
116
117 BOOST_AUTO_TEST_SUITE_END()
118
119 //____________________________________________________________________________//
120
121 // EOF
122