]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/test/test/test-organization-ts/test_case_template-with-variadic-typelist.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / test / test / test-organization-ts / test_case_template-with-variadic-typelist.cpp
CommitLineData
92f5a8d4
TL
1// (C) Copyright Raffi Enficiaud 2019.
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// Extends #12092 with arbitrary type list
7// see https://svn.boost.org/trac10/ticket/13418 and
8// https://github.com/boostorg/test/issues/141
9// ***************************************************************************
10
11// Boost.Test
12#define BOOST_TEST_MODULE template_test_case_with_variadic
13#include <boost/test/unit_test.hpp>
14#include <boost/test/unit_test_log.hpp>
15#include <boost/test/results_collector.hpp>
16#include <boost/test/utils/nullstream.hpp>
17typedef boost::onullstream onullstream_type;
18
19#include <boost/mpl/integral_c.hpp>
20
21// tuple already done in another test module
22// #include <tuple>
23
24
25
26namespace ut = boost::unit_test;
27namespace mpl = boost::mpl;
28
29#include <iostream>
30
31struct logger_guard {
32 logger_guard(std::ostream& s_out) {
33 ut::unit_test_log.set_stream( s_out );
34 }
35 ~logger_guard() {
36 ut::unit_test_log.set_stream( std::cout );
37 }
38};
39
40template <class ... T>
41struct dummy1 {
42
43};
44
45
46//____________________________________________________________________________//
47
48BOOST_TEST_CASE_TEMPLATE_FUNCTION( test0, Number )
49{
50 BOOST_TEST( 2 == (int)Number::value );
51}
52
53BOOST_AUTO_TEST_CASE( test0_only_2 )
54{
55 onullstream_type null_output;
56 logger_guard G(null_output);
57
58 typedef dummy1< mpl::integral_c<int,2> > only_2;
59
60 ut::test_suite* test = BOOST_TEST_SUITE( "" );
61
62 test->add( BOOST_TEST_CASE_TEMPLATE( test0, only_2 ) );
63
64 test->p_default_status.value = ut::test_unit::RS_ENABLED;
65 ut::framework::finalize_setup_phase( test->p_id );
66 ut::framework::run( test );
67 ut::test_results const& tr = ut::results_collector.results( test->p_id );
68
69 ut::unit_test_log.set_stream( std::cout );
70 BOOST_TEST( tr.p_assertions_failed == 0U );
71 BOOST_TEST( !tr.p_aborted );
72}
73
74BOOST_AUTO_TEST_CASE( test1_with_9_errors )
75{
76 onullstream_type null_output;
77 logger_guard G(null_output);
78
79 typedef dummy1<
80 mpl::integral_c<int,0>,
81 mpl::integral_c<int,1>,
82 mpl::integral_c<int,2>,
83 mpl::integral_c<int,3>,
84 mpl::integral_c<int,4>,
85 mpl::integral_c<int,5>,
86 mpl::integral_c<int,6>,
87 mpl::integral_c<int,7>,
88 mpl::integral_c<int,8>,
89 mpl::integral_c<int,9>
90 > range_10;
91
92 ut::test_suite* test = BOOST_TEST_SUITE( "" );
93
94 test->add( BOOST_TEST_CASE_TEMPLATE( test0, range_10 ) );
95
96 test->p_default_status.value = ut::test_unit::RS_ENABLED;
97 ut::framework::finalize_setup_phase( test->p_id );
98 ut::framework::run( test );
99 ut::test_results const& tr = ut::results_collector.results( test->p_id );
100
101 ut::unit_test_log.set_stream( std::cout );
102 BOOST_TEST( tr.p_assertions_failed == 9U );
103 BOOST_TEST( !tr.p_aborted );
104}
105
106
107int counter = 0;
108BOOST_TEST_CASE_TEMPLATE_FUNCTION( test_counter, Number )
109{
110 BOOST_TEST( counter++ == (int)Number::value );
111}
112
113BOOST_AUTO_TEST_CASE( test_left_to_right_evaluation )
114{
115 onullstream_type null_output;
116 logger_guard G(null_output);
117
118 typedef dummy1<
119 mpl::integral_c<int,0>,
120 mpl::integral_c<int,1>,
121 mpl::integral_c<int,2>,
122 mpl::integral_c<int,3>,
123 mpl::integral_c<int,4>,
124 mpl::integral_c<int,5>,
125 mpl::integral_c<int,6>,
126 mpl::integral_c<int,7>,
127 mpl::integral_c<int,8>,
128 mpl::integral_c<int,9>
129 > range_10;
130
131 ut::test_suite* test = BOOST_TEST_SUITE( "" );
132
133 test->add( BOOST_TEST_CASE_TEMPLATE( test_counter, range_10 ) );
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 == 0U );
142 BOOST_TEST( !tr.p_aborted );
143}
144
145
146typedef dummy1<
147 mpl::integral_c<int,1>,
148 mpl::integral_c<int,3>,
149 mpl::integral_c<int,5>,
150 mpl::integral_c<int,6>,
151 mpl::integral_c<int,7>,
152 mpl::integral_c<int,8>,
153 mpl::integral_c<int,9>
154> range_special;
155
156BOOST_AUTO_TEST_CASE_TEMPLATE(odd_or_above_5, T, range_special) {
157 BOOST_TEST( (T::value % 2 || T::value >= 5 ) );
158}