The Battle for Wesnoth  1.15.12+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/test/unit_test_suite.hpp>
18 #include <boost/test/parameterized_test.hpp>
19 #include <boost/test/tree/auto_registration.hpp>
20 
21 namespace test_utils {
22 
23 #ifndef BOOST_AUTO_TU_REGISTRAR
24 #define BOOST_AUTO_TU_REGISTRAR BOOST_AUTO_TC_REGISTRAR
25 #endif
26 
27 #define WESNOTH_PARAMETERIZED_TEST_CASE( test_name, type_name, values, param_name ) \
28 struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \
29 { void test_method(const type_name&); }; \
30 \
31 type_name* BOOST_JOIN(test_name, _begin) = &values[0]; \
32 type_name* BOOST_JOIN(test_name, _end) = BOOST_JOIN(test_name, _begin) + (sizeof(values)/sizeof(values[0])); \
33 static void BOOST_AUTO_TC_INVOKER( test_name )(const type_name& param_name ) \
34 { \
35  test_name t; \
36  t.test_method(param_name); \
37 } \
38  \
39 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
40  \
41 BOOST_AUTO_TU_REGISTRAR( test_name )( \
42  boost::unit_test::make_test_case(&BOOST_AUTO_TC_INVOKER( test_name ), \
43  BOOST_TEST_STRINGIZE( test_name ), \
44  BOOST_TEST_STRINGIZE(__FILE__), __LINE__, \
45  BOOST_JOIN(test_name, _begin), BOOST_JOIN(test_name, _end)), \
46  boost::unit_test::decorator::collector::instance()); \
47  \
48 void test_name::test_method(const type_name& param_name) \
49 /**/
50 }