early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,54 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision: 74640 $
//
// Description : defines auto_test_unit_registrar
// ***************************************************************************
#ifndef BOOST_TEST_TREE_AUTO_REGISTRATION_HPP_100211GER
#define BOOST_TEST_TREE_AUTO_REGISTRATION_HPP_100211GER
// Boost.Test
#include <boost/test/detail/config.hpp>
#include <boost/test/tree/decorator.hpp>
#include <boost/test/tree/test_unit.hpp>
// STL
#include <list>
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
namespace ut_detail {
// ************************************************************************** //
// ************** auto_test_unit_registrar ************** //
// ************************************************************************** //
struct BOOST_TEST_DECL auto_test_unit_registrar {
// Constructors
auto_test_unit_registrar( test_case* tc, decorator::collector_t& decorators, counter_t exp_fail = 0 );
explicit auto_test_unit_registrar( const_string ts_name, const_string ts_file, std::size_t ts_line, decorator::collector_t& decorators );
explicit auto_test_unit_registrar( test_unit_generator const& tc_gen, decorator::collector_t& decorators );
explicit auto_test_unit_registrar( boost::shared_ptr<test_unit_generator> tc_gen, decorator::collector_t& decorators );
explicit auto_test_unit_registrar( int );
};
} // namespace ut_detail
} // namespace unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TREE_AUTO_REGISTRATION_HPP_100211GER

View File

@@ -0,0 +1,309 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision: 62016 $
//
// Description : defines decorators to be using with auto registered test units
// ***************************************************************************
#ifndef BOOST_TEST_TREE_DECORATOR_HPP_091911GER
#define BOOST_TEST_TREE_DECORATOR_HPP_091911GER
// Boost.Test
#include <boost/test/detail/config.hpp>
#include <boost/test/detail/global_typedef.hpp>
#include <boost/test/tree/fixture.hpp>
#include <boost/test/tools/assertion_result.hpp>
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
// Boost
#include <boost/shared_ptr.hpp>
#include <boost/function/function0.hpp>
#include <boost/function/function1.hpp>
#include <boost/test/detail/suppress_warnings.hpp>
// STL
#include <vector>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
class test_unit;
namespace decorator {
// ************************************************************************** //
// ************** decorator::collector_t ************** //
// ************************************************************************** //
class base;
typedef boost::shared_ptr<base> base_ptr;
class BOOST_TEST_DECL collector_t {
public:
collector_t& operator*( base const& d );
void store_in( test_unit& tu );
void reset();
void stack();
std::vector<base_ptr> get_lazy_decorators() const;
// singleton pattern without ctor
BOOST_TEST_SINGLETON_CONS_NO_CTOR( collector_t )
private:
// Class invariant: minimal size is 1.
collector_t() : m_tu_decorators_stack(1) {}
// Data members
std::vector< std::vector<base_ptr> > m_tu_decorators_stack;
};
// ************************************************************************** //
// ************** decorator::base ************** //
// ************************************************************************** //
class BOOST_TEST_DECL base {
public:
// composition interface
virtual collector_t& operator*() const;
// application interface
virtual void apply( test_unit& tu ) = 0;
// deep cloning interface
virtual base_ptr clone() const = 0;
protected:
virtual ~base() {}
};
// ************************************************************************** //
// ************** decorator::stack_decorator ************** //
// ************************************************************************** //
//!@ A decorator that creates a new stack in the collector
//!
//! This decorator may be used in places where the currently accumulated decorators
//! in the collector should be applied to lower levels of the hierarchy rather
//! than the current one. This is for instance for dataset test cases, where the
//! macro does not let the user specify decorators for the underlying generated tests
//! (but rather on the main generator function), applying the stack_decorator at the
//! parent level lets us consume the decorator at the underlying test cases level.
class BOOST_TEST_DECL stack_decorator : public decorator::base {
public:
explicit stack_decorator() {}
collector_t& operator*() const BOOST_OVERRIDE;
private:
// decorator::base interface
void apply( test_unit& tu ) BOOST_OVERRIDE;
base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new stack_decorator()); }
};
// ************************************************************************** //
// ************** decorator::label ************** //
// ************************************************************************** //
class BOOST_TEST_DECL label : public decorator::base {
public:
explicit label( const_string l ) : m_label( l ) {}
private:
// decorator::base interface
void apply( test_unit& tu ) BOOST_OVERRIDE;
base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new label( m_label )); }
// Data members
const_string m_label;
};
// ************************************************************************** //
// ************** decorator::expected_failures ************** //
// ************************************************************************** //
class BOOST_TEST_DECL expected_failures : public decorator::base {
public:
explicit expected_failures( counter_t ef ) : m_exp_fail( ef ) {}
private:
// decorator::base interface
void apply( test_unit& tu ) BOOST_OVERRIDE;
base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new expected_failures( m_exp_fail )); }
// Data members
counter_t m_exp_fail;
};
// ************************************************************************** //
// ************** decorator::timeout ************** //
// ************************************************************************** //
class BOOST_TEST_DECL timeout : public decorator::base {
public:
explicit timeout( unsigned t ) : m_timeout( t ) {}
private:
// decorator::base interface
void apply( test_unit& tu ) BOOST_OVERRIDE;
base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new timeout( m_timeout )); }
// Data members
unsigned m_timeout;
};
// ************************************************************************** //
// ************** decorator::description ************** //
// ************************************************************************** //
class BOOST_TEST_DECL description : public decorator::base {
public:
explicit description( const_string descr ) : m_description( descr ) {}
private:
// decorator::base interface
void apply( test_unit& tu ) BOOST_OVERRIDE;
base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new description( m_description )); }
// Data members
const_string m_description;
};
// ************************************************************************** //
// ************** decorator::depends_on ************** //
// ************************************************************************** //
class BOOST_TEST_DECL depends_on : public decorator::base {
public:
explicit depends_on( const_string dependency ) : m_dependency( dependency ) {}
private:
// decorator::base interface
void apply( test_unit& tu ) BOOST_OVERRIDE;
base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new depends_on( m_dependency )); }
// Data members
const_string m_dependency;
};
// ************************************************************************** //
// ************** decorator::enable_if/enabled/disabled ************** //
// ************************************************************************** //
class BOOST_TEST_DECL enable_if_impl : public decorator::base {
protected:
void apply_impl( test_unit& tu, bool condition );
};
template<bool condition>
class enable_if : public enable_if_impl {
private:
// decorator::base interface
void apply( test_unit& tu ) BOOST_OVERRIDE { this->apply_impl( tu, condition ); }
base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new enable_if<condition>()); }
};
typedef enable_if<true> enabled;
typedef enable_if<false> disabled;
// ************************************************************************** //
// ************** decorator::fixture ************** //
// ************************************************************************** //
class BOOST_TEST_DECL fixture_t : public decorator::base {
public:
// Constructor
explicit fixture_t( test_unit_fixture_ptr impl ) : m_impl( impl ) {}
private:
// decorator::base interface
void apply( test_unit& tu ) BOOST_OVERRIDE;
base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new fixture_t( m_impl )); }
// Data members
test_unit_fixture_ptr m_impl;
};
//____________________________________________________________________________//
template<typename F>
inline fixture_t
fixture()
{
return fixture_t( test_unit_fixture_ptr( new unit_test::class_based_fixture<F>() ) );
}
//____________________________________________________________________________//
template<typename F, typename Arg>
inline fixture_t
fixture( Arg const& arg )
{
return fixture_t( test_unit_fixture_ptr( new unit_test::class_based_fixture<F,Arg>( arg ) ) );
}
//____________________________________________________________________________//
inline fixture_t
fixture( boost::function<void()> const& setup, boost::function<void()> const& teardown = boost::function<void()>() )
{
return fixture_t( test_unit_fixture_ptr( new unit_test::function_based_fixture( setup, teardown ) ) );
}
//____________________________________________________________________________//
// ************************************************************************** //
// ************** decorator::depends_on ************** //
// ************************************************************************** //
class BOOST_TEST_DECL precondition : public decorator::base {
public:
typedef boost::function<test_tools::assertion_result (test_unit_id)> predicate_t;
explicit precondition( predicate_t p ) : m_precondition( p ) {}
private:
// decorator::base interface
void apply( test_unit& tu ) BOOST_OVERRIDE;
base_ptr clone() const BOOST_OVERRIDE { return base_ptr(new precondition( m_precondition )); }
// Data members
predicate_t m_precondition;
};
} // namespace decorator
using decorator::label;
using decorator::expected_failures;
using decorator::timeout;
using decorator::description;
using decorator::depends_on;
using decorator::enable_if;
using decorator::enabled;
using decorator::disabled;
using decorator::fixture;
using decorator::precondition;
} // namespace unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TREE_DECORATOR_HPP_091911GER

View File

@@ -0,0 +1,191 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// Defines fixture interface and object makers
// ***************************************************************************
#ifndef BOOST_TEST_TREE_FIXTURE_HPP_100311GER
#define BOOST_TEST_TREE_FIXTURE_HPP_100311GER
// Boost.Test
#include <boost/test/detail/config.hpp>
// Boost
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/function/function0.hpp>
#include <boost/utility/declval.hpp>
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
// ************************************************************************** //
// ************** test_unit_fixture ************** //
// ************************************************************************** //
class BOOST_TEST_DECL test_unit_fixture {
public:
virtual ~test_unit_fixture() {}
// Fixture interface
virtual void setup() = 0;
virtual void teardown() = 0;
};
typedef shared_ptr<test_unit_fixture> test_unit_fixture_ptr;
// ************************************************************************** //
// ************** fixture helper functions ************** //
// ************************************************************************** //
namespace impl_fixture {
#if defined(BOOST_NO_CXX11_DECLTYPE) || defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES)
template<typename U, void (U::*)()> struct fixture_detect {};
template<typename T>
struct has_setup {
private:
template<typename U> static char Test(fixture_detect<U, &U::setup>*);
template<typename U> static int Test(...);
public:
static const bool value = sizeof(Test<T>(0)) == sizeof(char);
};
template<typename T>
struct has_teardown {
private:
template<typename U> static char Test(fixture_detect<U, &U::teardown>*);
template<typename U> static int Test(...);
public:
static const bool value = sizeof(Test<T>(0)) == sizeof(char);
};
#else
template<typename U> struct fixture_detect { typedef char type; };
template<typename T>
struct has_setup {
private:
template<typename U> static auto Test(U*) -> typename fixture_detect<decltype(boost::declval<U>().setup())>::type;
template<typename U> static int Test(...);
public:
static const bool value = sizeof(Test<T>(0)) == sizeof(char);
};
template<typename T>
struct has_teardown {
private:
template<typename U> static auto Test(U*) -> typename fixture_detect<decltype(boost::declval<U>().teardown())>::type;
template<typename U> static int Test(...);
public:
static const bool value = sizeof(Test<T>(0)) == sizeof(char);
};
#endif
template <bool has_setup = false>
struct call_setup { template <class U> void operator()(U& ) { } };
template <>
struct call_setup<true> { template <class U> void operator()(U& u) { u.setup(); } };
template <bool has_teardown = false>
struct call_teardown { template <class U> void operator()(U& ) { } };
template <>
struct call_teardown<true> { template <class U> void operator()(U& u) { u.teardown(); } };
}
//! Calls the fixture "setup" if detected by the compiler, otherwise does nothing.
template <class U>
void setup_conditional(U& u) {
return impl_fixture::call_setup<impl_fixture::has_setup<U>::value>()(u);
}
//! Calls the fixture "teardown" if detected by the compiler, otherwise does nothing.
template <class U>
void teardown_conditional(U& u) {
return impl_fixture::call_teardown<impl_fixture::has_teardown<U>::value>()(u);
}
// ************************************************************************** //
// ************** class_based_fixture ************** //
// ************************************************************************** //
template<typename F, typename Arg=void>
class class_based_fixture : public test_unit_fixture {
public:
// Constructor
explicit class_based_fixture( Arg const& arg ) : m_inst(), m_arg( arg ) {}
private:
// Fixture interface
void setup() BOOST_OVERRIDE { m_inst.reset( new F( m_arg ) ); setup_conditional(*m_inst); }
void teardown() BOOST_OVERRIDE { teardown_conditional(*m_inst); m_inst.reset(); }
// Data members
scoped_ptr<F> m_inst;
Arg m_arg;
};
//____________________________________________________________________________//
template<typename F>
class class_based_fixture<F,void> : public test_unit_fixture {
public:
// Constructor
class_based_fixture() : m_inst( 0 ) {}
private:
// Fixture interface
void setup() BOOST_OVERRIDE { m_inst.reset( new F ); setup_conditional(*m_inst); }
void teardown() BOOST_OVERRIDE { teardown_conditional(*m_inst); m_inst.reset(); }
// Data members
scoped_ptr<F> m_inst;
};
//____________________________________________________________________________//
// ************************************************************************** //
// ************** function_based_fixture ************** //
// ************************************************************************** //
class function_based_fixture : public test_unit_fixture {
public:
// Constructor
function_based_fixture( boost::function<void ()> const& setup_, boost::function<void ()> const& teardown_ )
: m_setup( setup_ )
, m_teardown( teardown_ )
{
}
private:
// Fixture interface
void setup() BOOST_OVERRIDE { if( m_setup ) m_setup(); }
void teardown() BOOST_OVERRIDE { if( m_teardown ) m_teardown(); }
// Data members
boost::function<void ()> m_setup;
boost::function<void ()> m_teardown;
};
} // namespace unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TREE_FIXTURE_HPP_100311GER

View File

@@ -0,0 +1,139 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// Defines global_fixture
// ***************************************************************************
#ifndef BOOST_TEST_TREE_GLOBAL_FIXTURE_HPP_091911GER
#define BOOST_TEST_TREE_GLOBAL_FIXTURE_HPP_091911GER
// Boost.Test
#include <boost/test/detail/config.hpp>
#include <boost/test/detail/global_typedef.hpp>
#include <boost/test/tree/observer.hpp>
#include <boost/test/tree/fixture.hpp>
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
// ************************************************************************** //
// ************** global_configuration ************** //
// ************************************************************************** //
class BOOST_TEST_DECL global_configuration : public test_observer {
public:
// Constructor
global_configuration();
/// Unregisters the global fixture from the framework
///
/// This is called by the framework at shutdown time
void unregister_from_framework();
// Dtor
~global_configuration() BOOST_OVERRIDE;
// Happens after the framework global observer init has been done
int priority() BOOST_OVERRIDE { return 1; }
private:
bool registered;
};
// ************************************************************************** //
// ************** global_fixture ************** //
// ************************************************************************** //
class BOOST_TEST_DECL global_fixture : public test_unit_fixture {
public:
// Constructor
global_fixture();
/// Unregisters the global fixture from the framework
///
/// This is called by the framework at shutdown time
void unregister_from_framework();
// Dtor
~global_fixture() BOOST_OVERRIDE;
private:
bool registered;
};
//____________________________________________________________________________//
namespace ut_detail {
template<typename F>
struct global_configuration_impl : public global_configuration {
// Constructor
global_configuration_impl() : m_configuration_observer( 0 ) {
}
// test observer interface
void test_start( counter_t, test_unit_id ) BOOST_OVERRIDE {
m_configuration_observer = new F;
}
// test observer interface
void test_finish() BOOST_OVERRIDE {
if(m_configuration_observer) {
delete m_configuration_observer;
m_configuration_observer = 0;
}
}
private:
// Data members
F* m_configuration_observer;
};
template<typename F>
struct global_fixture_impl : public global_fixture {
// Constructor
global_fixture_impl() : m_fixture( 0 ) {
}
// test fixture interface
void setup() BOOST_OVERRIDE {
m_fixture = new F;
setup_conditional(*m_fixture);
}
// test fixture interface
void teardown() BOOST_OVERRIDE {
if(m_fixture) {
teardown_conditional(*m_fixture);
}
delete m_fixture;
m_fixture = 0;
}
private:
// Data members
F* m_fixture;
};
} // namespace ut_detail
} // namespace unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TREE_GLOBAL_FIXTURE_HPP_091911GER

View File

@@ -0,0 +1,115 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
//!@file
//!@brief defines abstract interface for test observer
// ***************************************************************************
#ifndef BOOST_TEST_TEST_OBSERVER_HPP_021005GER
#define BOOST_TEST_TEST_OBSERVER_HPP_021005GER
// Boost.Test
#include <boost/test/detail/fwd_decl.hpp>
#include <boost/test/detail/global_typedef.hpp>
#include <boost/test/detail/config.hpp>
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
// ************************************************************************** //
// ************** test_observer ************** //
// ************************************************************************** //
/// @brief Generic test observer interface
///
/// This interface is used by observers in order to receive notifications from the
/// Boost.Test framework on the current execution state.
///
/// Several observers can be running at the same time, and it is not unusual to
/// have interactions among them. The @ref test_observer::priority member function allows the specification
/// of a particular order among them (lowest priority executed first, except specified otherwise).
///
class BOOST_TEST_DECL test_observer {
public:
//! Called before the framework starts executing the test cases
//!
//! @param[in] number_of_test_cases indicates the number of test cases. Only active
//! test cases are taken into account.
//! @param[in] root_test_unit_id the ID root of the test tree currently being tested
virtual void test_start( counter_t /* number_of_test_cases */, test_unit_id /* root_test_unit_id */ ) {}
//! Called after the framework ends executing the test cases
//!
//! @note The call is made with a reversed priority order.
virtual void test_finish() {}
//! Called when a critical error is detected
//!
//! The critical errors are mainly the signals sent by the system and caught by the Boost.Test framework.
//! Since the running binary may be in incoherent/instable state, the test execution is aborted and all remaining
//! tests are discarded.
//!
//! @note may be called before test_observer::test_unit_finish()
virtual void test_aborted() {}
//! Called before the framework starts executing a test unit
//!
//! @param[in] test_unit the test being executed
virtual void test_unit_start( test_unit const& /* test */) {}
//! Called at each end of a test unit.
//!
//! @param elapsed duration of the test unit in microseconds.
virtual void test_unit_finish( test_unit const& /* test */, unsigned long /* elapsed */ ) {}
virtual void test_unit_skipped( test_unit const& tu, const_string ) { test_unit_skipped( tu ); }
virtual void test_unit_skipped( test_unit const& ) {} ///< backward compatibility
//! Called when the test timed out
//!
//! This function is called to signal that a test unit (case or suite) timed out.
//! A valid test unit is available through boost::unit_test::framework::current_test_unit
virtual void test_unit_timed_out( test_unit const& ) {}
//! Called when a test unit indicates a fatal error.
//!
//! A fatal error happens when
//! - a strong assertion (with @c REQUIRE) fails, which indicates that the test case cannot continue
//! - an unexpected exception is caught by the Boost.Test framework
virtual void test_unit_aborted( test_unit const& ) {}
virtual void assertion_result( unit_test::assertion_result /* ar */ )
{
}
//! Called when an exception is intercepted
//!
//! In case an exception is intercepted, this call happens before the call
//! to @ref test_unit_aborted in order to log
//! additional data about the exception.
virtual void exception_caught( execution_exception const& ) {}
//! The priority indicates the order at which this observer is initialized
//! and tore down in the UTF framework. The order is lowest to highest priority.
virtual int priority() { return 0; }
protected:
BOOST_TEST_PROTECTED_VIRTUAL ~test_observer() {}
};
} // namespace unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TEST_OBSERVER_HPP_021005GER

View File

@@ -0,0 +1,58 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// Defines @ref test_case_counter
// ***************************************************************************
#ifndef BOOST_TEST_TREE_TEST_CASE_COUNTER_HPP_100211GER
#define BOOST_TEST_TREE_TEST_CASE_COUNTER_HPP_100211GER
// Boost.Test
#include <boost/test/detail/config.hpp>
#include <boost/test/utils/class_properties.hpp>
#include <boost/test/tree/test_unit.hpp>
#include <boost/test/tree/visitor.hpp>
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
// ************************************************************************** //
// ************** test_case_counter ************** //
// ************************************************************************** //
///! Counts the number of enabled test cases
class test_case_counter : public test_tree_visitor {
public:
// Constructor
// @param ignore_disabled ignore the status when counting
test_case_counter(bool ignore_status = false)
: p_count( 0 )
, m_ignore_status(ignore_status)
{}
BOOST_READONLY_PROPERTY( counter_t, (test_case_counter)) p_count;
private:
// test tree visitor interface
void visit( test_case const& tc ) BOOST_OVERRIDE { if( m_ignore_status || tc.is_enabled() ) ++p_count.value; }
bool test_suite_start( test_suite const& ts ) BOOST_OVERRIDE { return m_ignore_status || ts.is_enabled(); }
bool m_ignore_status;
};
} // namespace unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TREE_TEST_CASE_COUNTER_HPP_100211GER

View File

@@ -0,0 +1,211 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
///@ file
/// Defines template_test_case_gen
// ***************************************************************************
#ifndef BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
#define BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
// Boost.Test
#include <boost/test/detail/config.hpp>
#include <boost/test/detail/global_typedef.hpp>
#include <boost/test/detail/fwd_decl.hpp>
#include <boost/test/tree/test_unit.hpp>
#include <boost/test/utils/class_properties.hpp>
#include <boost/test/tree/observer.hpp>
#include <boost/test/utils/algorithm.hpp>
// Boost
#include <boost/shared_ptr.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/type.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_volatile.hpp>
#include <boost/type_traits/is_lvalue_reference.hpp>
#include <boost/type_traits/is_rvalue_reference.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/function/function0.hpp>
#if defined(BOOST_NO_TYPEID) || defined(BOOST_NO_RTTI)
# include <boost/current_function.hpp>
#else
# include <boost/core/demangle.hpp>
#endif
// STL
#include <string> // for std::string
#include <list> // for std::list
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
!defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
#include <type_traits>
#include <boost/mpl/is_sequence.hpp>
#endif
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
namespace ut_detail {
// ************************************************************************** //
// ************** test_case_template_invoker ************** //
// ************************************************************************** //
template<typename TestCaseTemplate,typename TestType>
class test_case_template_invoker {
public:
void operator()() { TestCaseTemplate::run( (boost::type<TestType>*)0 ); }
};
// ************************************************************************** //
// ************** generate_test_case_4_type ************** //
// ************************************************************************** //
template<typename Generator, typename TestCaseTemplate>
struct generate_test_case_4_type {
explicit generate_test_case_4_type( const_string tc_name, const_string tc_file, std::size_t tc_line, Generator& G )
: m_test_case_name( tc_name )
, m_test_case_file( tc_file )
, m_test_case_line( tc_line )
, m_holder( G )
{}
template<typename TestType>
void operator()( mpl::identity<TestType> )
{
std::string full_name;
assign_op( full_name, m_test_case_name, 0 );
full_name += '<';
#if !defined(BOOST_NO_TYPEID) && !defined(BOOST_NO_RTTI)
full_name += boost::core::demangle(typeid(TestType).name()); // same as execution_monitor.ipp
#else
full_name += BOOST_CURRENT_FUNCTION;
#endif
// replacing ',' by ', ' first, and then removing any double space
static const std::string to_replace[] = { "class ", "struct ", ",", " ", " <", " >"};
static const std::string replacement[] = { "", "" , ", ", " ", "<" , ">"};
full_name = unit_test::utils::replace_all_occurrences_of(
full_name,
to_replace, to_replace + sizeof(to_replace)/sizeof(to_replace[0]),
replacement, replacement + sizeof(replacement)/sizeof(replacement[0]));
typedef typename boost::remove_reference<TestType>::type TestTypewoRef;
if( boost::is_const<TestTypewoRef>::value )
full_name += "_const";
if( boost::is_volatile<TestTypewoRef>::value )
full_name += "_volatile";
if( boost::is_rvalue_reference<TestType>::value )
full_name += "_refref";
else if( boost::is_lvalue_reference<TestType>::value )
full_name += "_ref";
full_name += '>';
m_holder.m_test_cases.push_back( new test_case( ut_detail::normalize_test_case_name( full_name ),
m_test_case_file,
m_test_case_line,
test_case_template_invoker<TestCaseTemplate,TestType>() ) );
}
private:
// Data members
const_string m_test_case_name;
const_string m_test_case_file;
std::size_t m_test_case_line;
Generator& m_holder;
};
// ************************************************************************** //
// ************** test_case_template ************** //
// ************************************************************************** //
class template_test_case_gen_base : public test_unit_generator {
public:
test_unit* next() const BOOST_OVERRIDE
{
if( m_test_cases.empty() )
return 0;
test_unit* res = m_test_cases.front();
m_test_cases.pop_front();
return res;
}
// Data members
mutable std::list<test_unit*> m_test_cases;
};
template<typename TestCaseTemplate,typename TestTypesList, typename enabler = void>
class template_test_case_gen : public template_test_case_gen_base {
public:
// Constructor
template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
{
typedef generate_test_case_4_type<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
}
};
// Describing template test cases with tuples
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
!defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && \
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
template<typename TestCaseTemplate,
template <class ...> class C,
typename... parameter_pack>
class template_test_case_gen<
TestCaseTemplate,
C<parameter_pack...>,
typename std::enable_if<!boost::mpl::is_sequence<C<parameter_pack...>>::value>::type >
: public template_test_case_gen_base {
template<typename F>
void for_each(F &f)
{
auto l = { (f(mpl::identity<parameter_pack>()), 0)... };
(void)l; // silence warning
}
public:
// Constructor
template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
{
using this_type = template_test_case_gen<
TestCaseTemplate,
C<parameter_pack...>,
typename std::enable_if<!boost::mpl::is_sequence<C<parameter_pack...>>::value>::type>;
using single_test_gen = generate_test_case_4_type<this_type, TestCaseTemplate>;
single_test_gen op( tc_name, tc_file, tc_line, *this );
this->for_each(op);
}
};
#endif /* C++11 variadic, type alias */
} // namespace ut_detail
} // unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER

View File

@@ -0,0 +1,291 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// Defines @ref boost::unit_test::test_unit "test_unit", @ref boost::unit_test::test_case "test_case",
/// @ref boost::unit_test::test_suite "test_suite" and @ref boost::unit_test::master_test_suite_t "master_test_suite_t"
// ***************************************************************************
#ifndef BOOST_TEST_TREE_TEST_UNIT_HPP_100211GER
#define BOOST_TEST_TREE_TEST_UNIT_HPP_100211GER
// Boost.Test
#include <boost/test/detail/config.hpp>
#include <boost/test/detail/global_typedef.hpp>
#include <boost/test/detail/fwd_decl.hpp>
#include <boost/test/tree/decorator.hpp>
#include <boost/test/tree/fixture.hpp>
#include <boost/test/framework.hpp>
#include <boost/test/tools/assertion_result.hpp>
#include <boost/test/utils/class_properties.hpp>
// Boost
#include <boost/function/function0.hpp>
#include <boost/function/function1.hpp>
// STL
#include <vector>
#include <string>
#include <map>
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
namespace framework {
class state;
}
// ************************************************************************** //
// ************** test_unit ************** //
// ************************************************************************** //
typedef std::vector<test_unit_id> test_unit_id_list;
class BOOST_TEST_DECL test_unit {
public:
enum { type = TUT_ANY };
enum run_status { RS_DISABLED, RS_ENABLED, RS_INHERIT, RS_INVALID };
typedef std::vector<test_unit_id> id_list;
typedef std::vector<test_unit_fixture_ptr> fixture_list_t;
typedef BOOST_READONLY_PROPERTY(test_unit_id,(framework::state)) id_t;
typedef BOOST_READONLY_PROPERTY(test_unit_id,(test_suite)) parent_id_t;
typedef BOOST_READONLY_PROPERTY(id_list,(test_unit)) id_list_t;
typedef std::vector<decorator::base_ptr> decor_list_t;
typedef BOOST_READONLY_PROPERTY(std::vector<std::string>,(test_unit)) label_list_t;
typedef boost::function<test_tools::assertion_result (test_unit_id)> precondition_t;
typedef BOOST_READONLY_PROPERTY(std::vector<precondition_t>,(test_unit)) precond_list_t;
// preconditions management
void depends_on( test_unit* tu );
void add_precondition( precondition_t const& );
test_tools::assertion_result check_preconditions() const;
// labels management
void add_label( const_string l );
bool has_label( const_string l ) const;
// helper access methods
void increase_exp_fail( counter_t num );
bool is_enabled() const { return p_run_status == RS_ENABLED; }
std::string full_name() const;
// Public r/o properties
test_unit_type const p_type; ///< type for this test unit
const_string const p_type_name; ///< "case"/"suite"/"module"
const_string const p_file_name;
std::size_t const p_line_num;
id_t p_id; ///< unique id for this test unit
parent_id_t p_parent_id; ///< parent test suite id
label_list_t p_labels; ///< list of labels associated with this test unit
id_list_t p_dependencies; ///< list of test units this one depends on
precond_list_t p_preconditions; ///< user supplied preconditions for this test unit;
// Public r/w properties
readwrite_property<std::string> p_name; ///< name for this test unit
readwrite_property<std::string> p_description; ///< description for this test unit
readwrite_property<unsigned> p_timeout; ///< timeout for the test unit execution in seconds
readwrite_property<counter_t> p_expected_failures; ///< number of expected failures in this test unit
readwrite_property<run_status> p_default_status; ///< run status obtained by this unit during setup phase
readwrite_property<run_status> p_run_status; ///< run status assigned to this unit before execution phase after applying all filters
readwrite_property<counter_t> p_sibling_rank; ///< rank of this test unit amoung siblings of the same parent
readwrite_property<decor_list_t> p_decorators; ///< automatically assigned decorators; execution is delayed till framework::finalize_setup_phase function
readwrite_property<fixture_list_t> p_fixtures; ///< fixtures associated with this test unit
protected:
~test_unit();
// Constructor
test_unit( const_string tu_name, const_string tc_file, std::size_t tc_line, test_unit_type t );
// Master test suite constructor
explicit test_unit( const_string module_name );
};
// ************************************************************************** //
// ************** test_unit_generator ************** //
// ************************************************************************** //
class BOOST_TEST_DECL test_unit_generator {
public:
virtual test_unit* next() const = 0;
protected:
BOOST_TEST_PROTECTED_VIRTUAL ~test_unit_generator() {}
};
// ************************************************************************** //
// ************** test_case ************** //
// ************************************************************************** //
class BOOST_TEST_DECL test_case : public test_unit {
public:
enum { type = TUT_CASE };
// Constructor
test_case( const_string tc_name, boost::function<void ()> const& test_func );
test_case( const_string tc_name, const_string tc_file, std::size_t tc_line, boost::function<void ()> const& test_func );
// Public property
typedef BOOST_READONLY_PROPERTY(boost::function<void ()>,(test_case)) test_func;
test_func p_test_func;
private:
friend class framework::state;
~test_case() {}
};
// ************************************************************************** //
// ************** test_suite ************** //
// ************************************************************************** //
//! Class representing test suites
class BOOST_TEST_DECL test_suite : public test_unit {
public:
enum { type = TUT_SUITE };
// Constructor
explicit test_suite( const_string ts_name, const_string ts_file, std::size_t ts_line );
// test unit list management
/*!@brief Adds a test unit to a test suite.
*
* It is possible to specify the timeout and the expected failures.
*/
void add( test_unit* tu, counter_t expected_failures = 0, unsigned timeout = 0 );
/// @overload
void add( test_unit_generator const& gen, unsigned timeout = 0 );
/// @overload
void add( test_unit_generator const& gen, decorator::collector_t& decorators );
/// @overload
void add( boost::shared_ptr<test_unit_generator> gen_ptr, decorator::collector_t& decorators );
//! Removes a test from the test suite.
void remove( test_unit_id id );
//! Generates all the delayed test_units from the generators
void generate( );
//! Check for duplicates name in test cases
//!
//! Raises a setup_error if there are duplicates
void check_for_duplicate_test_cases();
// access methods
test_unit_id get( const_string tu_name ) const;
std::size_t size() const { return m_children.size(); }
protected:
// Master test suite constructor
explicit test_suite( const_string module_name );
friend BOOST_TEST_DECL
void traverse_test_tree( test_suite const&, test_tree_visitor&, bool );
friend class framework::state;
virtual ~test_suite() {}
typedef std::multimap<counter_t,test_unit_id> children_per_rank;
// Data members
test_unit_id_list m_children;
children_per_rank m_ranked_children; ///< maps child sibling rank to list of children with that rank
std::vector< std::pair<boost::shared_ptr<test_unit_generator>, std::vector<decorator::base_ptr> > > m_generators; /// lazy evaluation
};
// ************************************************************************** //
// ************** master_test_suite ************** //
// ************************************************************************** //
class BOOST_TEST_DECL master_test_suite_t : public test_suite {
private:
master_test_suite_t();
master_test_suite_t(const master_test_suite_t&); // undefined
master_test_suite_t& operator=(master_test_suite_t const &); // undefined
public:
// Data members
int argc;
char** argv;
friend BOOST_TEST_DECL master_test_suite_t& boost::unit_test::framework::master_test_suite();
};
// ************************************************************************** //
// ************** user_tc_method_invoker ************** //
// ************************************************************************** //
namespace ut_detail {
BOOST_TEST_DECL std::string normalize_test_case_name( const_string tu_name );
//____________________________________________________________________________//
template<typename InstanceType,typename UserTestCase>
struct user_tc_method_invoker {
typedef void (UserTestCase::*TestMethod )();
user_tc_method_invoker( shared_ptr<InstanceType> inst, TestMethod test_method )
: m_inst( inst ), m_test_method( test_method ) {}
void operator()() { ((*m_inst).*m_test_method)(); }
shared_ptr<InstanceType> m_inst;
TestMethod m_test_method;
};
} // namespace ut_detail
// ************************************************************************** //
// ************** make_test_case ************** //
// ************************************************************************** //
inline test_case*
make_test_case( boost::function<void ()> const& test_func, const_string tc_name, const_string tc_file, std::size_t tc_line )
{
return new test_case( ut_detail::normalize_test_case_name( tc_name ), tc_file, tc_line, test_func );
}
//____________________________________________________________________________//
template<typename UserTestCase, typename InstanceType>
inline test_case*
make_test_case( void (UserTestCase::* test_method )(),
const_string tc_name,
const_string tc_file,
std::size_t tc_line,
boost::shared_ptr<InstanceType> user_test_case )
{
return new test_case( ut_detail::normalize_test_case_name( tc_name ),
tc_file,
tc_line,
ut_detail::user_tc_method_invoker<InstanceType,UserTestCase>( user_test_case, test_method ) );
}
//____________________________________________________________________________//
} // namespace unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TREE_TEST_UNIT_HPP_100211GER

View File

@@ -0,0 +1,58 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision: -1 $
//
// Description : defines traverse_test_tree algorithm
// ***************************************************************************
#ifndef BOOST_TEST_TREE_TRAVERSE_HPP_100211GER
#define BOOST_TEST_TREE_TRAVERSE_HPP_100211GER
// Boost.Test
#include <boost/test/detail/config.hpp>
#include <boost/test/tree/test_unit.hpp>
#include <boost/test/tree/visitor.hpp>
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
// ************************************************************************** //
// ************** traverse_test_tree ************** //
// ************************************************************************** //
BOOST_TEST_DECL void traverse_test_tree( test_case const&, test_tree_visitor&, bool ignore_status = false );
BOOST_TEST_DECL void traverse_test_tree( test_suite const&, test_tree_visitor&, bool ignore_status = false );
BOOST_TEST_DECL void traverse_test_tree( test_unit_id , test_tree_visitor&, bool ignore_status = false );
//____________________________________________________________________________//
inline void
traverse_test_tree( test_unit const& tu, test_tree_visitor& V, bool ignore_status = false )
{
if( tu.p_type == TUT_CASE )
traverse_test_tree( static_cast<test_case const&>( tu ), V, ignore_status );
else
traverse_test_tree( static_cast<test_suite const&>( tu ), V, ignore_status );
}
//____________________________________________________________________________//
} // namespace unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TREE_TRAVERSE_HPP_100211GER

View File

@@ -0,0 +1,52 @@
// (C) Copyright Gennadiy Rozental 2001.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision: -1 $
//
// Description : defines test_tree_visitor
// ***************************************************************************
#ifndef BOOST_TEST_TREE_VISITOR_HPP_100211GER
#define BOOST_TEST_TREE_VISITOR_HPP_100211GER
// Boost.Test
#include <boost/test/detail/config.hpp>
#include <boost/test/tree/test_unit.hpp>
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
namespace boost {
namespace unit_test {
// ************************************************************************** //
// ************** test_tree_visitor ************** //
// ************************************************************************** //
class BOOST_TEST_DECL test_tree_visitor {
public:
// test tree visitor interface
virtual bool visit( test_unit const& ) { return true; }
virtual void visit( test_case const& tc ) { visit( (test_unit const&)tc ); }
virtual bool test_suite_start( test_suite const& ts ){ return visit( (test_unit const&)ts ); }
virtual void test_suite_finish( test_suite const& ) {}
protected:
BOOST_TEST_PROTECTED_VIRTUAL ~test_tree_visitor() {}
};
} // namespace unit_test
} // namespace boost
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TREE_VISITOR_HPP_100211GER