summaryrefslogtreecommitdiff
path: root/boost/test/tree/test_case_template.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/test/tree/test_case_template.hpp')
-rw-r--r--boost/test/tree/test_case_template.hpp71
1 files changed, 60 insertions, 11 deletions
diff --git a/boost/test/tree/test_case_template.hpp b/boost/test/tree/test_case_template.hpp
index 6a1fc3e57b..83a13f00f5 100644
--- a/boost/test/tree/test_case_template.hpp
+++ b/boost/test/tree/test_case_template.hpp
@@ -41,6 +41,12 @@
#include <string> // for std::string
#include <list> // for std::list
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
+ !defined(BOOST_NO_CXX11_HDR_TUPLE) && \
+ !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
+ #include <tuple>
+#endif
+
#include <boost/test/detail/suppress_warnings.hpp>
@@ -64,7 +70,7 @@ public:
// ************** generate_test_case_4_type ************** //
// ************************************************************************** //
-template<typename Generator,typename TestCaseTemplate>
+template<typename Generator, typename TestCaseTemplate>
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 )
@@ -106,17 +112,8 @@ private:
// ************** test_case_template ************** //
// ************************************************************************** //
-template<typename TestCaseTemplate,typename TestTypesList>
-class template_test_case_gen : public test_unit_generator {
+class template_test_case_gen_base : public test_unit_generator {
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<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
-
- mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
- }
-
virtual test_unit* next() const
{
if( m_test_cases.empty() )
@@ -132,6 +129,58 @@ public:
mutable std::list<test_unit*> m_test_cases;
};
+template<typename TestCaseTemplate,typename TestTypesList>
+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<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
+
+ mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
+ }
+};
+
+// adding support for tuple
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
+ !defined(BOOST_NO_CXX11_HDR_TUPLE) && \
+ !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
+
+template<typename TestCaseTemplate, typename... tuple_parameter_pack>
+class template_test_case_gen<TestCaseTemplate, std::tuple<tuple_parameter_pack...> > : public template_test_case_gen_base {
+
+ template<int... Is>
+ struct seq { };
+
+ template<int N, int... Is>
+ struct gen_seq : gen_seq<N - 1, N - 1, Is...> { };
+
+ template<int... Is>
+ struct gen_seq<0, Is...> : seq<Is...> { };
+
+ template<typename tuple_t, typename F, int... Is>
+ void for_each(F &f, seq<Is...>)
+ {
+ auto l = { (f(mpl::identity<typename std::tuple_element<Is, tuple_t>::type>()), 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 tuple_t = std::tuple<tuple_parameter_pack...>;
+ using this_type = template_test_case_gen<TestCaseTemplate, tuple_t >;
+ using single_test_gen = generate_test_case_4_type<this_type, TestCaseTemplate>;
+
+ single_test_gen op( tc_name, tc_file, tc_line, *this );
+
+ this->for_each<tuple_t>(op, gen_seq<sizeof...(tuple_parameter_pack)>());
+ }
+};
+
+#endif /* C++11 variadic and tuples */
+
} // namespace ut_detail
} // unit_test
} // namespace boost