blob: bc70ca6568e8cfe6aa0c153d77ae2a05b5c1fce7 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (C) Copyright Gennadiy Rozental 2001-2008.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6// See http://www.boost.org/libs/test for the library home page.
7//
8// File : $RCSfile$
9//
10// Version : $Revision: 57992 $
11//
12// Description : defines Unit Test Framework public API
13// ***************************************************************************
14
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
16#define NDNBOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
18// Boost.Test
19#include <ndnboost/test/unit_test_suite_impl.hpp>
20#include <ndnboost/test/framework.hpp>
21
22//____________________________________________________________________________//
23
24// ************************************************************************** //
25// ************** Non-auto (explicit) test case interface ************** //
26// ************************************************************************** //
27
Jeff Thompson3d613fd2013-10-15 15:39:04 -070028#define NDNBOOST_TEST_CASE( test_function ) \
29ndnboost::unit_test::make_test_case( ndnboost::unit_test::callback0<>(test_function), NDNBOOST_TEST_STRINGIZE( test_function ) )
30#define NDNBOOST_CLASS_TEST_CASE( test_function, tc_instance ) \
31ndnboost::unit_test::make_test_case((test_function), NDNBOOST_TEST_STRINGIZE( test_function ), tc_instance )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070032
33// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -070034// ************** NDNBOOST_TEST_SUITE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070035// ************************************************************************** //
36
Jeff Thompson3d613fd2013-10-15 15:39:04 -070037#define NDNBOOST_TEST_SUITE( testsuite_name ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070038( new ndnboost::unit_test::test_suite( testsuite_name ) )
39
40// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -070041// ************** NDNBOOST_AUTO_TEST_SUITE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070042// ************************************************************************** //
43
Jeff Thompson3d613fd2013-10-15 15:39:04 -070044#define NDNBOOST_AUTO_TEST_SUITE( suite_name ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070045namespace suite_name { \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070046NDNBOOST_AUTO_TU_REGISTRAR( suite_name )( NDNBOOST_STRINGIZE( suite_name ) ); \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070047/**/
48
49// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -070050// ************** NDNBOOST_FIXTURE_TEST_SUITE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070051// ************************************************************************** //
52
Jeff Thompson3d613fd2013-10-15 15:39:04 -070053#define NDNBOOST_FIXTURE_TEST_SUITE( suite_name, F ) \
54NDNBOOST_AUTO_TEST_SUITE( suite_name ) \
55typedef F NDNBOOST_AUTO_TEST_CASE_FIXTURE; \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070056/**/
57
58// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -070059// ************** NDNBOOST_AUTO_TEST_SUITE_END ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070060// ************************************************************************** //
61
Jeff Thompson3d613fd2013-10-15 15:39:04 -070062#define NDNBOOST_AUTO_TEST_SUITE_END() \
63NDNBOOST_AUTO_TU_REGISTRAR( NDNBOOST_JOIN( end_suite, __LINE__ ) )( 1 ); \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070064} \
65/**/
66
67// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -070068// ************** NDNBOOST_AUTO_TEST_CASE_EXPECTED_FAILURES ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070069// ************************************************************************** //
70
Jeff Thompson3d613fd2013-10-15 15:39:04 -070071#define NDNBOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( test_name, n ) \
72struct NDNBOOST_AUTO_TC_UNIQUE_ID( test_name ); \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070073 \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070074static struct NDNBOOST_JOIN( test_name, _exp_fail_num_spec ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070075: ndnboost::unit_test::ut_detail:: \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070076 auto_tc_exp_fail<NDNBOOST_AUTO_TC_UNIQUE_ID( test_name ) > \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070077{ \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070078 NDNBOOST_JOIN( test_name, _exp_fail_num_spec )() \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070079 : ndnboost::unit_test::ut_detail:: \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080 auto_tc_exp_fail<NDNBOOST_AUTO_TC_UNIQUE_ID( test_name ) >( n ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070081 {} \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070082} NDNBOOST_JOIN( test_name, _exp_fail_num_spec_inst ); \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070083 \
84/**/
85
86// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -070087// ************** NDNBOOST_FIXTURE_TEST_CASE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070088// ************************************************************************** //
89
Jeff Thompson3d613fd2013-10-15 15:39:04 -070090#define NDNBOOST_FIXTURE_TEST_CASE( test_name, F ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070091struct test_name : public F { void test_method(); }; \
92 \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070093static void NDNBOOST_AUTO_TC_INVOKER( test_name )() \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070094{ \
95 test_name t; \
96 t.test_method(); \
97} \
98 \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070099struct NDNBOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700100 \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700101NDNBOOST_AUTO_TU_REGISTRAR( test_name )( \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700102 ndnboost::unit_test::make_test_case( \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700103 &NDNBOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700104 ndnboost::unit_test::ut_detail::auto_tc_exp_fail< \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700105 NDNBOOST_AUTO_TC_UNIQUE_ID( test_name )>::instance()->value() ); \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700106 \
107void test_name::test_method() \
108/**/
109
110// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700111// ************** NDNBOOST_AUTO_TEST_CASE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700112// ************************************************************************** //
113
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700114#define NDNBOOST_AUTO_TEST_CASE( test_name ) \
115NDNBOOST_FIXTURE_TEST_CASE( test_name, NDNBOOST_AUTO_TEST_CASE_FIXTURE )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700116/**/
117
118// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700119// ************** NDNBOOST_FIXTURE_TEST_CASE_TEMPLATE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700120// ************************************************************************** //
121
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700122#define NDNBOOST_FIXTURE_TEST_CASE_TEMPLATE( test_name, type_name, TL, F ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700123template<typename type_name> \
124struct test_name : public F \
125{ void test_method(); }; \
126 \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700127struct NDNBOOST_AUTO_TC_INVOKER( test_name ) { \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700128 template<typename TestType> \
129 static void run( ndnboost::type<TestType>* = 0 ) \
130 { \
131 test_name<TestType> t; \
132 t.test_method(); \
133 } \
134}; \
135 \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700136NDNBOOST_AUTO_TU_REGISTRAR( test_name )( \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700137 ndnboost::unit_test::ut_detail::template_test_case_gen< \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700138 NDNBOOST_AUTO_TC_INVOKER( test_name ),TL >( \
139 NDNBOOST_STRINGIZE( test_name ) ) ); \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700140 \
141template<typename type_name> \
142void test_name<type_name>::test_method() \
143/**/
144
145// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700146// ************** NDNBOOST_AUTO_TEST_CASE_TEMPLATE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700147// ************************************************************************** //
148
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700149#define NDNBOOST_AUTO_TEST_CASE_TEMPLATE( test_name, type_name, TL ) \
150NDNBOOST_FIXTURE_TEST_CASE_TEMPLATE( test_name, type_name, TL, NDNBOOST_AUTO_TEST_CASE_FIXTURE )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700151
152// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700153// ************** NDNBOOST_TEST_CASE_TEMPLATE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700154// ************************************************************************** //
155
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700156#define NDNBOOST_TEST_CASE_TEMPLATE( name, typelist ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700157 ndnboost::unit_test::ut_detail::template_test_case_gen<name,typelist >( \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700158 NDNBOOST_TEST_STRINGIZE( name ) ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700159/**/
160
161// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700162// ************** NDNBOOST_TEST_CASE_TEMPLATE_FUNCTION ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700163// ************************************************************************** //
164
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700165#define NDNBOOST_TEST_CASE_TEMPLATE_FUNCTION( name, type_name ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700166template<typename type_name> \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700167void NDNBOOST_JOIN( name, _impl )( ndnboost::type<type_name>* ); \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700168 \
169struct name { \
170 template<typename TestType> \
171 static void run( ndnboost::type<TestType>* frwrd = 0 ) \
172 { \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700173 NDNBOOST_JOIN( name, _impl )( frwrd ); \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700174 } \
175}; \
176 \
177template<typename type_name> \
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700178void NDNBOOST_JOIN( name, _impl )( ndnboost::type<type_name>* ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700179/**/
180
181// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700182// ************** NDNBOOST_GLOBAL_FIXURE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700183// ************************************************************************** //
184
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700185#define NDNBOOST_GLOBAL_FIXTURE( F ) \
186static ndnboost::unit_test::ut_detail::global_fixture_impl<F> NDNBOOST_JOIN( gf_, F ) ; \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700187/**/
188
189// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700190// ************** NDNBOOST_AUTO_TEST_CASE_FIXTURE ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700191// ************************************************************************** //
192
193namespace ndnboost { namespace unit_test { namespace ut_detail {
194
195struct nil_t {};
196
197} // namespace ut_detail
198} // unit_test
199} // namespace ndnboost
200
201// Intentionally is in global namespace, so that FIXURE_TEST_SUITE can reset it in user code.
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700202typedef ::ndnboost::unit_test::ut_detail::nil_t NDNBOOST_AUTO_TEST_CASE_FIXTURE;
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700203
204// ************************************************************************** //
205// ************** Auto registration facility helper macros ************** //
206// ************************************************************************** //
207
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700208#define NDNBOOST_AUTO_TU_REGISTRAR( test_name ) \
209static ndnboost::unit_test::ut_detail::auto_test_unit_registrar NDNBOOST_JOIN( NDNBOOST_JOIN( test_name, _registrar ), __LINE__ )
210#define NDNBOOST_AUTO_TC_INVOKER( test_name ) NDNBOOST_JOIN( test_name, _invoker )
211#define NDNBOOST_AUTO_TC_UNIQUE_ID( test_name ) NDNBOOST_JOIN( test_name, _id )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700212
213// ************************************************************************** //
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700214// ************** NDNBOOST_TEST_MAIN ************** //
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700215// ************************************************************************** //
216
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700217#if defined(NDNBOOST_TEST_MAIN)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700218
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700219#ifdef NDNBOOST_TEST_ALTERNATIVE_INIT_API
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700220bool init_unit_test() {
221#else
222::ndnboost::unit_test::test_suite*
223init_unit_test_suite( int, char* [] ) {
224#endif
225
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700226#ifdef NDNBOOST_TEST_MODULE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700227 using namespace ::ndnboost::unit_test;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700228 assign_op( framework::master_test_suite().p_name.value, NDNBOOST_TEST_STRINGIZE( NDNBOOST_TEST_MODULE ).trim( "\"" ), 0 );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700229
230#endif
231
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700232#ifdef NDNBOOST_TEST_ALTERNATIVE_INIT_API
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700233 return true;
234}
235#else
236 return 0;
237}
238#endif
239
240#endif
241
242//____________________________________________________________________________//
243
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700244#endif // NDNBOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700245