1 // (C) Copyright Gennadiy Rozental 2003-2015.
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 // File : $RCSfile$
9 //
10 // Version : $Revision$
11 //
12 // Description : tests function template test case
13 // ***************************************************************************
14
15 // Boost.Test
16 #define BOOST_TEST_MAIN
17 #include <boost/test/unit_test.hpp>
18 #include <boost/test/unit_test_log.hpp>
19 #include <boost/test/results_collector.hpp>
20 #include <boost/test/utils/nullstream.hpp>
21 typedef boost::onullstream onullstream_type;
22
23 // BOOST
24 #include <boost/mpl/range_c.hpp>
25 #include <boost/mpl/list_c.hpp>
26 #include <boost/scoped_ptr.hpp>
27
28 namespace ut = boost::unit_test;
29 namespace mpl = boost::mpl;
30
31 // STL
32 #include <iostream>
33
34 //____________________________________________________________________________//
35
BOOST_TEST_CASE_TEMPLATE_FUNCTION(test0,Number)36 BOOST_TEST_CASE_TEMPLATE_FUNCTION( test0, Number )
37 {
38 BOOST_TEST( 2 == (int)Number::value );
39 }
40
41 //____________________________________________________________________________//
42
BOOST_TEST_CASE_TEMPLATE_FUNCTION(test1,Number)43 BOOST_TEST_CASE_TEMPLATE_FUNCTION( test1, Number )
44 {
45 BOOST_TEST( 6 == (int)Number::value );
46 BOOST_TEST_REQUIRE( 2 <= (int)Number::value );
47 BOOST_TEST( 3 == (int)Number::value );
48 }
49
50 //____________________________________________________________________________//
51
BOOST_TEST_CASE_TEMPLATE_FUNCTION(test2,Number)52 BOOST_TEST_CASE_TEMPLATE_FUNCTION( test2, Number )
53 {
54 throw Number();
55 }
56
57 //____________________________________________________________________________//
58
BOOST_AUTO_TEST_CASE(test0_only_2)59 BOOST_AUTO_TEST_CASE( test0_only_2 )
60 {
61 onullstream_type null_output;
62
63 typedef boost::mpl::list_c<int,2,2,2,2,2,2,2> only_2;
64 ut::unit_test_log.set_stream( null_output );
65
66 ut::test_suite* test = BOOST_TEST_SUITE( "" );
67
68 test->add( BOOST_TEST_CASE_TEMPLATE( test0, only_2 ) );
69
70 test->p_default_status.value = ut::test_unit::RS_ENABLED;
71 ut::framework::finalize_setup_phase( test->p_id );
72 ut::framework::run( test );
73 ut::test_results const& tr = ut::results_collector.results( test->p_id );
74
75 ut::unit_test_log.set_stream( std::cout );
76 BOOST_TEST( tr.p_assertions_failed == 0U );
77 BOOST_TEST( !tr.p_aborted );
78 }
79
80 //____________________________________________________________________________//
81
BOOST_AUTO_TEST_CASE(test0_one_to_ten)82 BOOST_AUTO_TEST_CASE( test0_one_to_ten )
83 {
84 onullstream_type null_output;
85 ut::test_suite* test = BOOST_TEST_SUITE( "" );
86
87 typedef boost::mpl::range_c<int,0,10> one_to_ten;
88 ut::unit_test_log.set_stream( null_output );
89
90 test->add( BOOST_TEST_CASE_TEMPLATE( test0, one_to_ten ) );
91
92 test->p_default_status.value = ut::test_unit::RS_ENABLED;
93 ut::framework::finalize_setup_phase( test->p_id );
94 ut::framework::run( test );
95 ut::test_results const& tr = ut::results_collector.results( test->p_id );
96
97 ut::unit_test_log.set_stream( std::cout );
98 BOOST_TEST( tr.p_assertions_failed == 9U );
99 BOOST_TEST( !tr.p_aborted );
100
101 }
102
103 //____________________________________________________________________________//
104
BOOST_AUTO_TEST_CASE(test1_one_to_five)105 BOOST_AUTO_TEST_CASE( test1_one_to_five )
106 {
107 onullstream_type null_output;
108 ut::test_suite* test = BOOST_TEST_SUITE( "" );
109
110 typedef boost::mpl::range_c<int,1,5> one_to_five;
111 ut::unit_test_log.set_stream( null_output );
112 test->add( BOOST_TEST_CASE_TEMPLATE( test1, one_to_five ) );
113
114 test->p_default_status.value = ut::test_unit::RS_ENABLED;
115 ut::framework::finalize_setup_phase( test->p_id );
116 ut::framework::run( test );
117 ut::test_results const& tr = ut::results_collector.results( test->p_id );
118
119 ut::unit_test_log.set_stream( std::cout );
120 BOOST_TEST( tr.p_assertions_failed == 7U );
121 BOOST_TEST( !tr.p_aborted );
122 }
123
124 //____________________________________________________________________________//
125
BOOST_AUTO_TEST_CASE(test2_one_to_three)126 BOOST_AUTO_TEST_CASE( test2_one_to_three )
127 {
128 onullstream_type null_output;
129 ut::test_suite* test = BOOST_TEST_SUITE( "" );
130
131 typedef boost::mpl::range_c<int,1,3> one_to_three;
132 ut::unit_test_log.set_stream( null_output );
133 test->add( BOOST_TEST_CASE_TEMPLATE( test2, one_to_three ) );
134
135 test->p_default_status.value = ut::test_unit::RS_ENABLED;
136 ut::framework::finalize_setup_phase( test->p_id );
137 ut::framework::run( test );
138 ut::test_results const& tr = ut::results_collector.results( test->p_id );
139
140 ut::unit_test_log.set_stream( std::cout );
141 BOOST_TEST( tr.p_assertions_failed == 2U );
142 BOOST_TEST( !tr.p_aborted );
143 BOOST_TEST( !tr.passed() );
144 }
145
146 //____________________________________________________________________________//
147
148 // EOF
149