/usr/include/boost/test/tree
Edit: /usr/include/boost/test/tree/test_case_template.hpp (7403B)
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
///@ file
/// Defines template_test_case_gen
// ***************************************************************************
#ifndef BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
#define BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
// Boost.Test
#include
#include
#include
#include
#include
#include
#include
// Boost
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#if defined(BOOST_NO_TYPEID) || defined(BOOST_NO_RTTI)
# include
#else
# include
#endif
// STL
#include // for std::string
#include // for std::list
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
!defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
#include
#include
#endif
#include
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
namespace ut_detail {
// ************************************************************************** //
// ************** test_case_template_invoker ************** //
// ************************************************************************** //
template
class test_case_template_invoker {
public:
void operator()() { TestCaseTemplate::run( (boost::type*)0 ); }
};
// ************************************************************************** //
// ************** generate_test_case_4_type ************** //
// ************************************************************************** //
template
struct generate_test_case_4_type {
explicit generate_test_case_4_type( const_string tc_name, const_string tc_file, std::size_t tc_line, Generator& G )
: m_test_case_name( tc_name )
, m_test_case_file( tc_file )
, m_test_case_line( tc_line )
, m_holder( G )
{}
template
void operator()( mpl::identity )
{
std::string full_name;
assign_op( full_name, m_test_case_name, 0 );
full_name += '<';
#if !defined(BOOST_NO_TYPEID) && !defined(BOOST_NO_RTTI)
full_name += boost::core::demangle(typeid(TestType).name()); // same as execution_monitor.ipp
#else
full_name += BOOST_CURRENT_FUNCTION;
#endif
// replacing ',' by ', ' first, and then removing any double space
static const std::string to_replace[] = { "class ", "struct ", ",", " ", " <", " >"};
static const std::string replacement[] = { "", "" , ", ", " ", "<" , ">"};
full_name = unit_test::utils::replace_all_occurrences_of(
full_name,
to_replace, to_replace + sizeof(to_replace)/sizeof(to_replace[0]),
replacement, replacement + sizeof(replacement)/sizeof(replacement[0]));
typedef typename boost::remove_reference::type TestTypewoRef;
if( boost::is_const::value )
full_name += "_const";
if( boost::is_volatile::value )
full_name += "_volatile";
if( boost::is_rvalue_reference::value )
full_name += "_refref";
else if( boost::is_lvalue_reference::value )
full_name += "_ref";
full_name += '>';
m_holder.m_test_cases.push_back( new test_case( ut_detail::normalize_test_case_name( full_name ),
m_test_case_file,
m_test_case_line,
test_case_template_invoker() ) );
}
private:
// Data members
const_string m_test_case_name;
const_string m_test_case_file;
std::size_t m_test_case_line;
Generator& m_holder;
};
// ************************************************************************** //
// ************** test_case_template ************** //
// ************************************************************************** //
class template_test_case_gen_base : public test_unit_generator {
public:
test_unit* next() const BOOST_OVERRIDE
{
if( m_test_cases.empty() )
return 0;
test_unit* res = m_test_cases.front();
m_test_cases.pop_front();
return res;
}
// Data members
mutable std::list m_test_cases;
};
template
class template_test_case_gen : public template_test_case_gen_base {
public:
// Constructor
template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
{
typedef generate_test_case_4_type,TestCaseTemplate> single_test_gen;
mpl::for_each >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
}
};
// Describing template test cases with tuples
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
!defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && \
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
template class C,
typename... parameter_pack>
class template_test_case_gen<
TestCaseTemplate,
C,
typename std::enable_if>::value>::type >
: public template_test_case_gen_base {
template
void for_each(F &f)
{
auto l = { (f(mpl::identity()), 0)... };
(void)l; // silence warning
}
public:
// Constructor
template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
{
using this_type = template_test_case_gen<
TestCaseTemplate,
C,
typename std::enable_if>::value>::type>;
using single_test_gen = generate_test_case_4_type;
single_test_gen op( tc_name, tc_file, tc_line, *this );
this->for_each(op);
}
};
#endif /* C++11 variadic, type alias */
} // namespace ut_detail
} // unit_test
} // namespace boost
#include
#endif // BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER