]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/test/tree/test_case_template.hpp
update sources to v12.2.3
[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 #include <boost/test/detail/suppress_warnings.hpp>
45
46
47 //____________________________________________________________________________//
48
49 namespace boost {
50 namespace unit_test {
51 namespace ut_detail {
52
53 // ************************************************************************** //
54 // ************** test_case_template_invoker ************** //
55 // ************************************************************************** //
56
57 template<typename TestCaseTemplate,typename TestType>
58 class test_case_template_invoker {
59 public:
60 void operator()() { TestCaseTemplate::run( (boost::type<TestType>*)0 ); }
61 };
62
63 // ************************************************************************** //
64 // ************** generate_test_case_4_type ************** //
65 // ************************************************************************** //
66
67 template<typename Generator,typename TestCaseTemplate>
68 struct generate_test_case_4_type {
69 explicit generate_test_case_4_type( const_string tc_name, const_string tc_file, std::size_t tc_line, Generator& G )
70 : m_test_case_name( tc_name )
71 , m_test_case_file( tc_file )
72 , m_test_case_line( tc_line )
73 , m_holder( G )
74 {}
75
76 template<typename TestType>
77 void operator()( mpl::identity<TestType> )
78 {
79 std::string full_name;
80 assign_op( full_name, m_test_case_name, 0 );
81 full_name += '<';
82 #if !defined(BOOST_NO_TYPEID) && !defined(BOOST_NO_RTTI)
83 full_name += boost::core::demangle(typeid(TestType).name()); // same as execution_monitor.ipp
84 #else
85 full_name += BOOST_CURRENT_FUNCTION;
86 #endif
87 if( boost::is_const<TestType>::value )
88 full_name += "_const";
89 full_name += '>';
90
91 m_holder.m_test_cases.push_back( new test_case( ut_detail::normalize_test_case_name( full_name ),
92 m_test_case_file,
93 m_test_case_line,
94 test_case_template_invoker<TestCaseTemplate,TestType>() ) );
95 }
96
97 private:
98 // Data members
99 const_string m_test_case_name;
100 const_string m_test_case_file;
101 std::size_t m_test_case_line;
102 Generator& m_holder;
103 };
104
105 // ************************************************************************** //
106 // ************** test_case_template ************** //
107 // ************************************************************************** //
108
109 template<typename TestCaseTemplate,typename TestTypesList>
110 class template_test_case_gen : public test_unit_generator {
111 public:
112 // Constructor
113 template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
114 {
115 typedef generate_test_case_4_type<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
116
117 mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
118 }
119
120 virtual test_unit* next() const
121 {
122 if( m_test_cases.empty() )
123 return 0;
124
125 test_unit* res = m_test_cases.front();
126 m_test_cases.pop_front();
127
128 return res;
129 }
130
131 // Data members
132 mutable std::list<test_unit*> m_test_cases;
133 };
134
135 } // namespace ut_detail
136 } // unit_test
137 } // namespace boost
138
139 #include <boost/test/detail/enable_warnings.hpp>
140
141 #endif // BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER