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 : $RCSfile$
9//
10// Version : $Revision: -1 $
11//
12// Description : defines template_test_case_gen
13// ***************************************************************************
14
15#ifndef BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
16#define BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
17
18// Boost.Test
19#include <boost/test/detail/config.hpp>
20#include <boost/test/detail/global_typedef.hpp>
21#include <boost/test/detail/fwd_decl.hpp>
22#include <boost/test/detail/workaround.hpp>
23
24#include <boost/test/utils/class_properties.hpp>
25
26#include <boost/test/tree/observer.hpp>
27
28
29// Boost
30#include <boost/shared_ptr.hpp>
31#include <boost/mpl/for_each.hpp>
32#include <boost/mpl/identity.hpp>
33#include <boost/type.hpp>
34#include <boost/type_traits/is_const.hpp>
35#include <boost/function/function0.hpp>
36
37#ifndef BOOST_NO_RTTI
38#include <typeinfo> // for typeid
39#else
40#include <boost/current_function.hpp>
41#endif
42
43// STL
44#include <string> // for std::string
45#include <list> // for std::list
46
47#include <boost/test/detail/suppress_warnings.hpp>
48
49
50//____________________________________________________________________________//
51
52namespace boost {
53namespace unit_test {
54namespace ut_detail {
55
56// ************************************************************************** //
57// ************** test_case_template_invoker ************** //
58// ************************************************************************** //
59
60template<typename TestCaseTemplate,typename TestType>
61class test_case_template_invoker {
62public:
63 void operator()() { TestCaseTemplate::run( (boost::type<TestType>*)0 ); }
64};
65
66// ************************************************************************** //
67// ************** generate_test_case_4_type ************** //
68// ************************************************************************** //
69
70template<typename Generator,typename TestCaseTemplate>
71struct generate_test_case_4_type {
72 explicit generate_test_case_4_type( const_string tc_name, const_string tc_file, std::size_t tc_line, Generator& G )
73 : m_test_case_name( tc_name )
74 , m_test_case_file( tc_file )
75 , m_test_case_line( tc_line )
76 , m_holder( G )
77 {}
78
79 template<typename TestType>
80 void operator()( mpl::identity<TestType> )
81 {
82 std::string full_name;
83 assign_op( target&: full_name, src: m_test_case_name, 0 );
84 full_name += '<';
85#ifndef BOOST_NO_RTTI
86 full_name += typeid(TestType).name();
87#else
88 full_name += BOOST_CURRENT_FUNCTION;
89#endif
90 if( boost::is_const<TestType>::value )
91 full_name += "_const";
92 full_name += '>';
93
94 m_holder.m_test_cases.push_back( new test_case( ut_detail::normalize_test_case_name( tu_name: full_name ),
95 m_test_case_file,
96 m_test_case_line,
97 test_case_template_invoker<TestCaseTemplate,TestType>() ) );
98 }
99
100private:
101 // Data members
102 const_string m_test_case_name;
103 const_string m_test_case_file;
104 std::size_t m_test_case_line;
105 Generator& m_holder;
106};
107
108// ************************************************************************** //
109// ************** test_case_template ************** //
110// ************************************************************************** //
111
112template<typename TestCaseTemplate,typename TestTypesList>
113class template_test_case_gen : public test_unit_generator {
114public:
115 // Constructor
116 template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
117 {
118 typedef generate_test_case_4_type<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
119
120 mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
121 }
122
123 virtual test_unit* next() const
124 {
125 if( m_test_cases.empty() )
126 return 0;
127
128 test_unit* res = m_test_cases.front();
129 m_test_cases.pop_front();
130
131 return res;
132 }
133
134 // Data members
135 mutable std::list<test_unit*> m_test_cases;
136};
137
138} // namespace ut_detail
139} // unit_test
140} // namespace boost
141
142#include <boost/test/detail/enable_warnings.hpp>
143
144#endif // BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
145

source code of boost/boost/test/tree/test_case_template.hpp