cppx-core
boost-test-framework.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 //
3 // In one translation unit, define BOOST_TEST_MODULE before including this.
4 // See the Boost Test documentation.
5 
6 #ifdef CPPX_BOOST_TEST_AS_HEADER_ONLY_PLEASE
7 # include <boost/test/included/unit_test.hpp>
8 #else
9 # include <boost/test/unit_test.hpp>
10 #endif
11 
14 
15 #ifndef CPPX_NO_DOLLARS_PLEASE
16 # define $begin_test_suite CPPX_BEGIN_TEST_SUITE
17 # define $end_test_suite CPPX_END_TEST_SUITE
18 
19 # define $test_case CPPX_TEST_CASE
20 
21 # define $expect CPPX_EXPECT
22 # define $expect_eq CPPX_EXPECT_EQ
23 # define $require CPPX_REQUIRE
24 # define $require_eq CPPX_REQUIRE_EQ
25 #endif
26 
27 // Example:
28 //
29 // $begin_test_suite( cppx_core, text, ascii, ascii_util );
30 //
31 // $test_case( testcasename, specificsname )
32 // {
33 // BOOST_TEST( true );
34 // }
35 //
36 // $end_test_suite( 4 ); // End 4 test suite nesting levels.
37 
38 #define CPPX_BEGIN_TEST_SUITE( ... ) \
39  CPPX_APPLY( CPPX_GENERATE_TEST_SUITE_START_, __VA_ARGS__ ) \
40  static_assert( true, "- just to support a semicolon after this -" )
41 
42 #define CPPX_GENERATE_TEST_SUITE_START_( name ) \
43  BOOST_AUTO_TEST_SUITE( name );
44 
45 #define CPPX_END_TEST_SUITE( nesting_level ) \
46  CPPX_REPEAT( nesting_level, CPPX_GENERATE_TEST_SUITE_END_ ) \
47  static_assert( true, "- just to support a semicolon after this -" )
48 
49 #define CPPX_GENERATE_TEST_SUITE_END_() \
50  BOOST_AUTO_TEST_SUITE_END();
51 
52 #define CPPX_TEST_CASE( testcasename, specificsname ) \
53  BOOST_AUTO_TEST_CASE( testcasename##_##specificsname )
54 
55 #define CPPX_EXPECT( ... ) \
56  CPPX_EXPECT_EXPANSION_HELPER_( CPPX_N_ARGUMENTS( __VA_ARGS__ ), __VA_ARGS__ )
57 
58 #define CPPX_EXPECT_EXPANSION_HELPER_( n_args, ... ) \
59  CPPX_INVOKE_MACRO( CPPX_JOINED( CPPX_EXPECT_, n_args ), ( __VA_ARGS__ ) )
60 
61 #define CPPX_EXPECT_1( condition ) \
62  BOOST_CHECK( condition )
63 
64 #define CPPX_EXPECT_2( condition, message_expr ) \
65  BOOST_CHECK_MESSAGE( condition, message_expr )
66 
67 #define CPPX_EXPECT_EQ( ... ) \
68  CPPX_EXPECT_EQ_EXPANSION_HELPER_( CPPX_N_ARGUMENTS( __VA_ARGS__ ), __VA_ARGS__ )
69 
70 #define CPPX_EXPECT_EQ_EXPANSION_HELPER_( n_args, ... ) \
71  CPPX_INVOKE_MACRO( CPPX_JOINED( CPPX_EXPECT_EQ_, n_args ), ( __VA_ARGS__ ) )
72 
73 #define CPPX_EXPECT_EQ_2( a, b ) \
74  BOOST_CHECK_EQUAL( a, b )
75 
76 #define CPPX_EXPECT_EQ_3( a, b, message_expr ) \
77  BOOST_CHECK_MESSAGE( (a) == (b), message_expr )
78 
79 #define CPPX_REQUIRE( ... ) \
80  CPPX_REQUIRE_EXPANSION_HELPER_( CPPX_N_ARGUMENTS( __VA_ARGS__ ), __VA_ARGS__ )
81 
82 #define CPPX_REQUIRE_EXPANSION_HELPER_( n_args, ... ) \
83  CPPX_INVOKE_MACRO( CPPX_JOINED( CPPX_REQUIRE_, n_args ), ( __VA_ARGS__ ) )
84 
85 #define CPPX_REQUIRE_1( condition ) \
86  BOOST_REQUIRE( condition )
87 
88 #define CPPX_REQUIRE_2( condition, message_expr ) \
89  BOOST_REQUIRE_MESSAGE( condition, message_expr )
90 
91 #define CPPX_REQUIRE_EQ( ... ) \
92  CPPX_REQUIRE_EQ_EXPANSION_HELPER_( CPPX_N_ARGUMENTS( __VA_ARGS__ ), __VA_ARGS__ )
93 
94 #define CPPX_REQUIRE_EQ_EXPANSION_HELPER_( n_args, ... ) \
95  CPPX_INVOKE_MACRO( CPPX_JOINED( CPPX_REQUIRE_EQ_, n_args ), ( __VA_ARGS__ ) )
96 
97 #define CPPX_REQUIRE_EQ_2( a, b ) \
98  BOOST_REQUIRE_EQUAL( a, b )
99 
100 #define CPPX_REQUIRE_EQ_3( a, b, message_expr ) \
101  BOOST_REQUIRE_MESSAGE( (a) == (b), message_expr )
$apply invokes the specified single-argument macro with each of the specified arguments.
$repeat(n, what) produces the what text n times.