The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
auto_parameterized.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Pauli Nieminen <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef TESTS_UTILS_AUTO_PARAMETERIZED_HPP_INCLUDED
16 #define TESTS_UTILS_AUTO_PARAMETERIZED_HPP_INCLUDED
17 
18 #include <boost/version.hpp>
19 
20 #include <boost/test/unit_test_suite.hpp>
21 #include <boost/test/parameterized_test.hpp>
22 
23 #if BOOST_VERSION >= 106000
24 #include <boost/test/tree/auto_registration.hpp>
25 #endif
26 
27 namespace test_utils {
28 
29 #ifndef BOOST_AUTO_TU_REGISTRAR
30 #define BOOST_AUTO_TU_REGISTRAR BOOST_AUTO_TC_REGISTRAR
31 #endif
32 
33 #if BOOST_VERSION >= 106000
34 #define WESNOTH_PARAMETERIZED_TEST_CASE( test_name, type_name, values, param_name ) \
35 struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \
36 { void test_method(const type_name&); }; \
37 \
38 type_name* BOOST_JOIN(test_name, _begin) = &values[0]; \
39 type_name* BOOST_JOIN(test_name, _end) = BOOST_JOIN(test_name, _begin) + (sizeof(values)/sizeof(values[0])); \
40 static void BOOST_AUTO_TC_INVOKER( test_name )(const type_name& param_name ) \
41 { \
42  test_name t; \
43  t.test_method(param_name); \
44 } \
45  \
46 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
47  \
48 BOOST_AUTO_TU_REGISTRAR( test_name )( \
49  boost::unit_test::make_test_case(&BOOST_AUTO_TC_INVOKER( test_name ), \
50  BOOST_TEST_STRINGIZE( test_name ), \
51  BOOST_TEST_STRINGIZE(__FILE__), __LINE__, \
52  BOOST_JOIN(test_name, _begin), BOOST_JOIN(test_name, _end)), \
53  boost::unit_test::decorator::collector::instance()); \
54  \
55 void test_name::test_method(const type_name& param_name) \
56 /**/
57 #else
58 #define WESNOTH_PARAMETERIZED_TEST_CASE( test_name, type_name, values, param_name ) \
59 struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \
60 { void test_method(const type_name&); }; \
61 \
62 type_name* BOOST_JOIN(test_name, _begin) = &values[0]; \
63 type_name* BOOST_JOIN(test_name, _end) = BOOST_JOIN(test_name, _begin) + (sizeof(values)/sizeof(values[0])); \
64 static void BOOST_AUTO_TC_INVOKER( test_name )(const type_name& param_name ) \
65 { \
66  test_name t; \
67  t.test_method(param_name); \
68 } \
69  \
70 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
71  \
72 BOOST_AUTO_TU_REGISTRAR( test_name )( \
73  boost::unit_test::make_test_case(&BOOST_AUTO_TC_INVOKER( test_name ), \
74  BOOST_TEST_STRINGIZE( test_name ), \
75  BOOST_JOIN(test_name, _begin), BOOST_JOIN(test_name, _end))); \
76  \
77 void test_name::test_method(const type_name& param_name) \
78 /**/
79 #endif
80 
81 }
82 #endif