The Battle for Wesnoth  1.15.2+dev
auto_parameterized.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Pauli Nieminen <paniemin@cc.hut.fi>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
17 #include <boost/version.hpp>
18 
19 #include <boost/test/unit_test_suite.hpp>
20 #include <boost/test/parameterized_test.hpp>
21 
22 #if BOOST_VERSION >= 106000
23 #include <boost/test/tree/auto_registration.hpp>
24 #endif
25 
26 namespace test_utils {
27 
28 #ifndef BOOST_AUTO_TU_REGISTRAR
29 #define BOOST_AUTO_TU_REGISTRAR BOOST_AUTO_TC_REGISTRAR
30 #endif
31 
32 #if BOOST_VERSION >= 106000
33 #define WESNOTH_PARAMETERIZED_TEST_CASE( test_name, type_name, values, param_name ) \
34 struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \
35 { void test_method(const type_name&); }; \
36 \
37 type_name* BOOST_JOIN(test_name, _begin) = &values[0]; \
38 type_name* BOOST_JOIN(test_name, _end) = BOOST_JOIN(test_name, _begin) + (sizeof(values)/sizeof(values[0])); \
39 static void BOOST_AUTO_TC_INVOKER( test_name )(const type_name& param_name ) \
40 { \
41  test_name t; \
42  t.test_method(param_name); \
43 } \
44  \
45 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
46  \
47 BOOST_AUTO_TU_REGISTRAR( test_name )( \
48  boost::unit_test::make_test_case(&BOOST_AUTO_TC_INVOKER( test_name ), \
49  BOOST_TEST_STRINGIZE( test_name ), \
50  BOOST_TEST_STRINGIZE(__FILE__), __LINE__, \
51  BOOST_JOIN(test_name, _begin), BOOST_JOIN(test_name, _end)), \
52  boost::unit_test::decorator::collector::instance()); \
53  \
54 void test_name::test_method(const type_name& param_name) \
55 /**/
56 #else
57 #define WESNOTH_PARAMETERIZED_TEST_CASE( test_name, type_name, values, param_name ) \
58 struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \
59 { void test_method(const type_name&); }; \
60 \
61 type_name* BOOST_JOIN(test_name, _begin) = &values[0]; \
62 type_name* BOOST_JOIN(test_name, _end) = BOOST_JOIN(test_name, _begin) + (sizeof(values)/sizeof(values[0])); \
63 static void BOOST_AUTO_TC_INVOKER( test_name )(const type_name& param_name ) \
64 { \
65  test_name t; \
66  t.test_method(param_name); \
67 } \
68  \
69 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
70  \
71 BOOST_AUTO_TU_REGISTRAR( test_name )( \
72  boost::unit_test::make_test_case(&BOOST_AUTO_TC_INVOKER( test_name ), \
73  BOOST_TEST_STRINGIZE( test_name ), \
74  BOOST_JOIN(test_name, _begin), BOOST_JOIN(test_name, _end))); \
75  \
76 void test_name::test_method(const type_name& param_name) \
77 /**/
78 #endif
79 
80 }