blob: 3f316f8a1090d08b52c4745d537575be52d7ca99 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (C) Copyright Gennadiy Rozental 2005-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: 54633 $
11//
12// Description : defines framework interface
13// ***************************************************************************
14
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_TEST_FRAMEWORK_HPP_020805GER
16#define NDNBOOST_TEST_FRAMEWORK_HPP_020805GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
18// Boost.Test
19#include <ndnboost/test/detail/global_typedef.hpp>
20#include <ndnboost/test/detail/fwd_decl.hpp>
21#include <ndnboost/test/utils/trivial_singleton.hpp>
22
23#include <ndnboost/test/detail/suppress_warnings.hpp>
24
25// STL
26#include <stdexcept>
27
28//____________________________________________________________________________//
29
30namespace ndnboost {
31
32namespace unit_test {
33
34// ************************************************************************** //
35// ************** init_unit_test_func ************** //
36// ************************************************************************** //
37
Jeff Thompson3d613fd2013-10-15 15:39:04 -070038#ifdef NDNBOOST_TEST_ALTERNATIVE_INIT_API
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070039typedef bool (*init_unit_test_func)();
40#else
41typedef test_suite* (*init_unit_test_func)( int, char* [] );
42#endif
43
44// ************************************************************************** //
45// ************** framework ************** //
46// ************************************************************************** //
47
48namespace framework {
49
50// initialization
Jeff Thompson3d613fd2013-10-15 15:39:04 -070051NDNBOOST_TEST_DECL void init( init_unit_test_func init_func, int argc, char* argv[] );
52NDNBOOST_TEST_DECL bool is_initialized();
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070053
54// mutation access methods
Jeff Thompson3d613fd2013-10-15 15:39:04 -070055NDNBOOST_TEST_DECL void register_test_unit( test_case* tc );
56NDNBOOST_TEST_DECL void register_test_unit( test_suite* ts );
57NDNBOOST_TEST_DECL void deregister_test_unit( test_unit* tu );
58NDNBOOST_TEST_DECL void clear();
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070059
Jeff Thompson3d613fd2013-10-15 15:39:04 -070060NDNBOOST_TEST_DECL void register_observer( test_observer& );
61NDNBOOST_TEST_DECL void deregister_observer( test_observer& );
62NDNBOOST_TEST_DECL void reset_observers();
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070063
Jeff Thompson3d613fd2013-10-15 15:39:04 -070064NDNBOOST_TEST_DECL master_test_suite_t& master_test_suite();
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070065
66// constant access methods
Jeff Thompson3d613fd2013-10-15 15:39:04 -070067NDNBOOST_TEST_DECL test_case const& current_test_case();
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070068
Jeff Thompson3d613fd2013-10-15 15:39:04 -070069NDNBOOST_TEST_DECL test_unit& get( test_unit_id, test_unit_type );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070070template<typename UnitType>
71UnitType& get( test_unit_id id )
72{
73 return static_cast<UnitType&>( get( id, static_cast<test_unit_type>(UnitType::type) ) );
74}
75
76// test initiation
Jeff Thompson3d613fd2013-10-15 15:39:04 -070077NDNBOOST_TEST_DECL void run( test_unit_id = INV_TEST_UNIT_ID, bool continue_test = true );
78NDNBOOST_TEST_DECL void run( test_unit const*, bool continue_test = true );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070079
80// public test events dispatchers
Jeff Thompson3d613fd2013-10-15 15:39:04 -070081NDNBOOST_TEST_DECL void assertion_result( bool passed );
82NDNBOOST_TEST_DECL void exception_caught( execution_exception const& );
83NDNBOOST_TEST_DECL void test_unit_aborted( test_unit const& );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070084
85// ************************************************************************** //
86// ************** framework errors ************** //
87// ************************************************************************** //
88
89struct internal_error : std::runtime_error {
90 internal_error( const_string m ) : std::runtime_error( std::string( m.begin(), m.size() ) ) {}
91};
92
93struct setup_error : std::runtime_error {
94 setup_error( const_string m ) : std::runtime_error( std::string( m.begin(), m.size() ) ) {}
95};
96
Jeff Thompson3d613fd2013-10-15 15:39:04 -070097#define NDNBOOST_TEST_SETUP_ASSERT( cond, msg ) if( cond ) {} else throw unit_test::framework::setup_error( msg )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070098
99struct nothing_to_test {}; // not really an error
100
101} // namespace framework
102
103} // unit_test
104
105} // namespace ndnboost
106
107//____________________________________________________________________________//
108
109#include <ndnboost/test/detail/enable_warnings.hpp>
110
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700111#endif // NDNBOOST_TEST_FRAMEWORK_HPP_020805GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700112