nested template tests using boost.test BOOST_AUTO_TEST_CASE_TEMPLATE

It seems that one cannot do nested AUTO_TEST_CASE_TEMPLATE's with boost.test. Is there another way around this (besides unrolling manually)? I wish to do something like the following: i.e. testing every combination of two (or more?) lists of types. Example below. Thank you, Johann. define BOOST_TEST_MODULE std_map #define BOOST_TEST_DYN_LINK #include <map> #include <boost/test/unit_test.hpp> #include <boost/test/test_case_template.hpp> #include <boost/mpl/list.hpp> typedef boost::mpl::list<short, int, long, long long> test_int_types; typedef boost::mpl::list<float, double, long double> test_float_types; BOOST_AUTO_TEST_SUITE( std_map_suite ) BOOST_AUTO_TEST_CASE_TEMPLATE( int_template_case, Ti, test_int_types ) { BOOST_AUTO_TEST_CASE_TEMPLATE( float_template_case, Tf, test_float_types ) { std::map<Ti, Tf> m; m.insert(std::make_pair((Ti)0,(Tf)0)); BOOST_CHECK_EQUAL(m.size(), size_t(1)); } } BOOST_AUTO_TEST_SUITE_END() -- View this message in context: http://www.nabble.com/nested-template-tests-using-boost.test-BOOST_AUTO_TEST... Sent from the Boost - Users mailing list archive at Nabble.com.

johanngoetz <jgoetz <at> ucla.edu> writes:
It seems that one cannot do nested AUTO_TEST_CASE_TEMPLATE's with boost.test.
No. Neither of the Boost.Test test cases really support this kind of usage
Is there another way around this (besides unrolling manually)? I wish to do
Not really manually, but you will have to linearize it
something like the following: i.e. testing every combination of two (or more?) lists of types. Example below. Thank you, Johann.
define BOOST_TEST_MODULE std_map #define BOOST_TEST_DYN_LINK #include <map> #include <boost/test/unit_test.hpp> #include <boost/test/test_case_template.hpp> #include <boost/mpl/list.hpp> typedef boost::mpl::list<short, int, long, long long> test_int_types; typedef boost::mpl::list<float, double, long double> test_float_types;
I believe MPL have something to help here. What you need is to have linear_view like this: typedef linear_view<test_init_types,test_float_types>::type test_types;
BOOST_AUTO_TEST_SUITE( std_map_suite ) BOOST_AUTO_TEST_CASE_TEMPLATE( int_template_case, Ti, test_int_types ) {
Now you can write: BOOST_AUTO_TEST_CASE_TEMPLATE( test_case, TT, test_types ) {
) { std::map<Ti, Tf> m;
and use like this: std::map<TT::first, TT::second> m;
m.insert(std::make_pair((Ti)0,(Tf)0)); BOOST_CHECK_EQUAL(m.size(), size_t(1)); } } BOOST_AUTO_TEST_SUITE_END()
Gennadiy

I couldn't find linear_view anywhere in boost. Is this from an older version of mpl? I am using boost's current svn trunk source. Anyways, looking deeper into mpl I managed to do what I wanted with something like the following. If anyone has a better way, please let me know. As a side note, I am starting to understand some of the power associated with the mpl library. #define BOOST_TEST_MODULE std_map #define BOOST_TEST_DYN_LINK #include <map> #include <boost/test/unit_test.hpp> #include <boost/test/test_case_template.hpp> #include <boost/mpl/list.hpp> #include <boost/mpl/map.hpp> namespace mpl = boost::mpl; typedef mpl::list< mpl::pair<short, float>, mpl::pair<short, double>, mpl::pair<short, long double>, mpl::pair<int, float>, mpl::pair<int, double>, mpl::pair<int, long double>
test_int_float_types;
BOOST_AUTO_TEST_SUITE( std_map_suite ) BOOST_AUTO_TEST_CASE_TEMPLATE( int_template_case, TT, test_int_float_types ) { std::map<typename TT::first, typename TT::second> m; m.insert(std::make_pair((typename TT::first)0,(typename TT::second)0)); BOOST_CHECK_EQUAL(m.size(), size_t(1)); } BOOST_AUTO_TEST_SUITE_END() -- View this message in context: http://www.nabble.com/nested-template-tests-using-boost.test-BOOST_AUTO_TEST... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
Gennadiy Rozental
-
johanngoetz