]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/test/tree/test_case_template.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / test / tree / test_case_template.hpp
1 // (C) Copyright Gennadiy Rozental 2001.
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
9 /// Defines template_test_case_gen
10 // ***************************************************************************
11
12 #ifndef BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
13 #define BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
14
15 // Boost.Test
16 #include <boost/test/detail/config.hpp>
17 #include <boost/test/detail/global_typedef.hpp>
18 #include <boost/test/detail/fwd_decl.hpp>
19 #include <boost/test/detail/workaround.hpp>
20
21 #include <boost/test/utils/class_properties.hpp>
22
23 #include <boost/test/tree/observer.hpp>
24
25
26 // Boost
27 #include <boost/shared_ptr.hpp>
28 #include <boost/mpl/for_each.hpp>
29 #include <boost/mpl/identity.hpp>
30 #include <boost/type.hpp>
31 #include <boost/type_traits/is_const.hpp>
32 #include <boost/function/function0.hpp>
33
34 #if defined(BOOST_NO_TYPEID) || defined(BOOST_NO_RTTI)
35 # include <boost/current_function.hpp>
36 #else
37 # include <boost/core/demangle.hpp>
38 #endif
39
40 // STL
41 #include <string> // for std::string
42 #include <list> // for std::list
43
44 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
45 !defined(BOOST_NO_CXX11_HDR_TUPLE) && \
46 !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
47 #include <tuple>
48 #endif
49
50 #include <boost/test/detail/suppress_warnings.hpp>
51
52
53 //____________________________________________________________________________//
54
55 namespace boost {
56 namespace unit_test {
57 namespace ut_detail {
58
59 // ************************************************************************** //
60 // ************** test_case_template_invoker ************** //
61 // ************************************************************************** //
62
63 template<typename TestCaseTemplate,typename TestType>
64 class test_case_template_invoker {
65 public:
66 void operator()() { TestCaseTemplate::run( (boost::type<TestType>*)0 ); }
67 };
68
69 // ************************************************************************** //
70 // ************** generate_test_case_4_type ************** //
71 // ************************************************************************** //
72
73 template<typename Generator, typename TestCaseTemplate>
74 struct generate_test_case_4_type {
75 explicit generate_test_case_4_type( const_string tc_name, const_string tc_file, std::size_t tc_line, Generator& G )
76 : m_test_case_name( tc_name )
77 , m_test_case_file( tc_file )
78 , m_test_case_line( tc_line )
79 , m_holder( G )
80 {}
81
82 template<typename TestType>
83 void operator()( mpl::identity<TestType> )
84 {
85 std::string full_name;
86 assign_op( full_name, m_test_case_name, 0 );
87 full_name += '<';
88 #if !defined(BOOST_NO_TYPEID) && !defined(BOOST_NO_RTTI)
89 full_name += boost::core::demangle(typeid(TestType).name()); // same as execution_monitor.ipp
90 #else
91 full_name += BOOST_CURRENT_FUNCTION;
92 #endif
93 if( boost::is_const<TestType>::value )
94 full_name += "_const";
95 full_name += '>';
96
97 m_holder.m_test_cases.push_back( new test_case( ut_detail::normalize_test_case_name( full_name ),
98 m_test_case_file,
99 m_test_case_line,
100 test_case_template_invoker<TestCaseTemplate,TestType>() ) );
101 }
102
103 private:
104 // Data members
105 const_string m_test_case_name;
106 const_string m_test_case_file;
107 std::size_t m_test_case_line;
108 Generator& m_holder;
109 };
110
111 // ************************************************************************** //
112 // ************** test_case_template ************** //
113 // ************************************************************************** //
114
115 class template_test_case_gen_base : public test_unit_generator {
116 public:
117 virtual test_unit* next() const
118 {
119 if( m_test_cases.empty() )
120 return 0;
121
122 test_unit* res = m_test_cases.front();
123 m_test_cases.pop_front();
124
125 return res;
126 }
127
128 // Data members
129 mutable std::list<test_unit*> m_test_cases;
130 };
131
132 template<typename TestCaseTemplate,typename TestTypesList>
133 class template_test_case_gen : public template_test_case_gen_base {
134 public:
135 // Constructor
136 template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
137 {
138 typedef generate_test_case_4_type<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
139
140 mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
141 }
142 };
143
144 // adding support for tuple
145 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
146 !defined(BOOST_NO_CXX11_HDR_TUPLE) && \
147 !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
148
149 template<typename TestCaseTemplate, typename... tuple_parameter_pack>
150 class template_test_case_gen<TestCaseTemplate, std::tuple<tuple_parameter_pack...> > : public template_test_case_gen_base {
151
152 template<int... Is>
153 struct seq { };
154
155 template<int N, int... Is>
156 struct gen_seq : gen_seq<N - 1, N - 1, Is...> { };
157
158 template<int... Is>
159 struct gen_seq<0, Is...> : seq<Is...> { };
160
161 template<typename tuple_t, typename F, int... Is>
162 void for_each(F &f, seq<Is...>)
163 {
164 auto l = { (f(mpl::identity<typename std::tuple_element<Is, tuple_t>::type>()), 0)... };
165 (void)l; // silence warning
166 }
167
168 public:
169 // Constructor
170 template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
171 {
172 using tuple_t = std::tuple<tuple_parameter_pack...>;
173 using this_type = template_test_case_gen<TestCaseTemplate, tuple_t >;
174 using single_test_gen = generate_test_case_4_type<this_type, TestCaseTemplate>;
175
176 single_test_gen op( tc_name, tc_file, tc_line, *this );
177
178 this->for_each<tuple_t>(op, gen_seq<sizeof...(tuple_parameter_pack)>());
179 }
180 };
181
182 #endif /* C++11 variadic and tuples */
183
184 } // namespace ut_detail
185 } // unit_test
186 } // namespace boost
187
188 #include <boost/test/detail/enable_warnings.hpp>
189
190 #endif // BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER