The Battle for Wesnoth  1.19.5+dev
auto_parameterized.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Pauli Nieminen <paniemin@cc.hut.fi>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include <boost/test/unit_test_suite.hpp>
19 #include <boost/test/parameterized_test.hpp>
20 #include <boost/test/tree/auto_registration.hpp>
21 
22 namespace test_utils {
23 
24 #ifndef BOOST_AUTO_TU_REGISTRAR
25 #define BOOST_AUTO_TU_REGISTRAR BOOST_AUTO_TC_REGISTRAR
26 #endif
27 
28 #define WESNOTH_PARAMETERIZED_TEST_CASE( test_name, type_name, values, param_name ) \
29 struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \
30 { void test_method(const type_name&); }; \
31 \
32 type_name* BOOST_JOIN(test_name, _begin) = &values[0]; \
33 type_name* BOOST_JOIN(test_name, _end) = BOOST_JOIN(test_name, _begin) + (sizeof(values)/sizeof(values[0])); \
34 static void BOOST_AUTO_TC_INVOKER( test_name )(const type_name& param_name ) \
35 { \
36  test_name t; \
37  t.test_method(param_name); \
38 } \
39  \
40 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
41  \
42 BOOST_AUTO_TU_REGISTRAR( test_name )( \
43  boost::unit_test::make_test_case(&BOOST_AUTO_TC_INVOKER( test_name ), \
44  BOOST_TEST_STRINGIZE( test_name ), \
45  BOOST_TEST_STRINGIZE(__FILE__), __LINE__, \
46  BOOST_JOIN(test_name, _begin), BOOST_JOIN(test_name, _end)), \
47  boost::unit_test::decorator::collector::instance()); \
48  \
49 void test_name::test_method(const type_name& param_name) \
50 /**/
51 }