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)
6 // See http://www.boost.org/libs/test for the library home page.
9 /// Defines template_test_case_gen
10 // ***************************************************************************
12 #ifndef BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
13 #define BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
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>
21 #include <boost/test/utils/class_properties.hpp>
23 #include <boost/test/tree/observer.hpp>
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>
34 #if defined(BOOST_NO_TYPEID) || defined(BOOST_NO_RTTI)
35 # include <boost/current_function.hpp>
37 # include <boost/core/demangle.hpp>
41 #include <string> // for std::string
42 #include <list> // for std::list
44 #include <boost/test/detail/suppress_warnings.hpp>
47 //____________________________________________________________________________//
53 // ************************************************************************** //
54 // ************** test_case_template_invoker ************** //
55 // ************************************************************************** //
57 template<typename TestCaseTemplate,typename TestType>
58 class test_case_template_invoker {
60 void operator()() { TestCaseTemplate::run( (boost::type<TestType>*)0 ); }
63 // ************************************************************************** //
64 // ************** generate_test_case_4_type ************** //
65 // ************************************************************************** //
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 )
76 template<typename TestType>
77 void operator()( mpl::identity<TestType> )
79 std::string full_name;
80 assign_op( full_name, m_test_case_name, 0 );
82 #if !defined(BOOST_NO_TYPEID) && !defined(BOOST_NO_RTTI)
83 full_name += boost::core::demangle(typeid(TestType).name()); // same as execution_monitor.ipp
85 full_name += BOOST_CURRENT_FUNCTION;
87 if( boost::is_const<TestType>::value )
88 full_name += "_const";
91 m_holder.m_test_cases.push_back( new test_case( ut_detail::normalize_test_case_name( full_name ),
94 test_case_template_invoker<TestCaseTemplate,TestType>() ) );
99 const_string m_test_case_name;
100 const_string m_test_case_file;
101 std::size_t m_test_case_line;
105 // ************************************************************************** //
106 // ************** test_case_template ************** //
107 // ************************************************************************** //
109 template<typename TestCaseTemplate,typename TestTypesList>
110 class template_test_case_gen : public test_unit_generator {
113 template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
115 typedef generate_test_case_4_type<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
117 mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
120 virtual test_unit* next() const
122 if( m_test_cases.empty() )
125 test_unit* res = m_test_cases.front();
126 m_test_cases.pop_front();
132 mutable std::list<test_unit*> m_test_cases;
135 } // namespace ut_detail
139 #include <boost/test/detail/enable_warnings.hpp>
141 #endif // BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER