Boost logo

Boost-Commit :

From: gennadiy.rozental_at_[hidden]
Date: 2007-10-14 17:14:30


Author: rogeeff
Date: 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
New Revision: 40035
URL: http://svn.boost.org/trac/boost/changeset/40035

Log:
Support for expected failures in test cases with automated registration reworked completely. It now allows to be used within auto-test-stuites.
framework API changed to return non const references to the test units to allow post creation modifications
unit_test_suite.hpp dependency on framework.hpp removed
inlined version includes all necessary files now
in test_tools.hpp BOOST_TEST_DECL is added/removed where necessary
Test suite auto registration modified to allow c++ namespace like behavior
Text files modified:
   trunk/boost/test/exception_safety.hpp | 2
   trunk/boost/test/framework.hpp | 12 ++--
   trunk/boost/test/impl/framework.ipp | 6 +-
   trunk/boost/test/impl/unit_test_main.ipp | 3 +
   trunk/boost/test/impl/unit_test_suite.ipp | 102 +++++++++++++++++++++++++++++++++++++--
   trunk/boost/test/included/unit_test.hpp | 5 +
   trunk/boost/test/logged_expectations.hpp | 2
   trunk/boost/test/test_tools.hpp | 81 +-----------------------------
   trunk/boost/test/unit_test_suite.hpp | 21 ++++---
   trunk/boost/test/unit_test_suite_impl.hpp | 70 ++++++++++++++-------------
   10 files changed, 166 insertions(+), 138 deletions(-)

Modified: trunk/boost/test/exception_safety.hpp
==============================================================================
--- trunk/boost/test/exception_safety.hpp (original)
+++ trunk/boost/test/exception_safety.hpp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -49,7 +49,7 @@
     boost::unit_test::make_test_case( \
         &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \
     boost::unit_test::ut_detail::auto_tc_exp_fail< \
- BOOST_AUTO_TC_UNIQUE_ID( test_name )>::value ); \
+ BOOST_AUTO_TC_UNIQUE_ID( test_name )>::instance()->value() ); \
                                                                         \
 void test_name::test_method() \
 /**/

Modified: trunk/boost/test/framework.hpp
==============================================================================
--- trunk/boost/test/framework.hpp (original)
+++ trunk/boost/test/framework.hpp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -54,17 +54,17 @@
 BOOST_TEST_DECL test_case const& current_test_case();
 #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x530) )
 template<typename UnitType>
-UnitType const& get( test_unit_id id )
+UnitType& get( test_unit_id id )
 {
- return static_cast<UnitType const&>( get( id, (test_unit_type)UnitType::type ) );
+ return static_cast<UnitType&>( get( id, (test_unit_type)UnitType::type ) );
 }
-test_unit const& get( test_unit_id, test_unit_type );
+test_unit& get( test_unit_id, test_unit_type );
 #else
-test_unit const& get( test_unit_id, test_unit_type );
+test_unit& get( test_unit_id, test_unit_type );
 template<typename UnitType>
-UnitType const& get( test_unit_id id )
+UnitType& get( test_unit_id id )
 {
- return static_cast<UnitType const&>( get( id, (test_unit_type)UnitType::type ) );
+ return static_cast<UnitType&>( get( id, (test_unit_type)UnitType::type ) );
 }
 #endif
 

Modified: trunk/boost/test/impl/framework.ipp
==============================================================================
--- trunk/boost/test/impl/framework.ipp (original)
+++ trunk/boost/test/impl/framework.ipp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -179,7 +179,7 @@
         }
     };
 
- typedef std::map<test_unit_id,test_unit const*> test_unit_store;
+ typedef std::map<test_unit_id,test_unit*> test_unit_store;
     typedef std::set<test_observer*,priority_order> observer_store;
 
     master_test_suite_t* m_master_test_suite;
@@ -335,10 +335,10 @@
 
 //____________________________________________________________________________//
 
-test_unit const&
+test_unit&
 get( test_unit_id id, test_unit_type t )
 {
- test_unit const* res = s_frk_impl().m_test_units[id];
+ test_unit* res = s_frk_impl().m_test_units[id];
 
     if( (res->p_type & t) == 0 )
         throw internal_error( "Invalid test unit type" );

Modified: trunk/boost/test/impl/unit_test_main.ipp
==============================================================================
--- trunk/boost/test/impl/unit_test_main.ipp (original)
+++ trunk/boost/test/impl/unit_test_main.ipp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -57,6 +57,9 @@
     if( !(*init_unit_test_func)() )
         throw framework::setup_error( BOOST_TEST_L( "test tree initialization error" ) );
 #endif
+// !! ?? if( !runtime_config.test_to_run().is_empty() ) {
+//
+// }
 
         framework::run();
 

Modified: trunk/boost/test/impl/unit_test_suite.ipp
==============================================================================
--- trunk/boost/test/impl/unit_test_suite.ipp (original)
+++ trunk/boost/test/impl/unit_test_suite.ipp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -84,6 +84,17 @@
 
 //____________________________________________________________________________//
 
+void
+test_unit::increase_exp_fail( unsigned num )
+{
+ p_expected_failures.value += num;
+
+ if( p_parent_id != 0 )
+ framework::get<test_suite>( p_parent_id ).increase_exp_fail( num );
+}
+
+//____________________________________________________________________________//
+
 // ************************************************************************** //
 // ************** test_case ************** //
 // ************************************************************************** //
@@ -115,21 +126,17 @@
 
 //____________________________________________________________________________//
 
-// !! need to prevent modifing test unit once it is added to tree
-
 void
 test_suite::add( test_unit* tu, counter_t expected_failures, unsigned timeout )
 {
- if( expected_failures != 0 )
- tu->p_expected_failures.value = expected_failures;
-
- p_expected_failures.value += tu->p_expected_failures;
-
     if( timeout != 0 )
         tu->p_timeout.value = timeout;
 
     m_members.push_back( tu->p_id );
     tu->p_parent_id.value = p_id;
+
+ if( expected_failures != 0 )
+ tu->increase_exp_fail( expected_failures );
 }
 
 //____________________________________________________________________________//
@@ -144,6 +151,19 @@
 
 //____________________________________________________________________________//
 
+test_unit_id
+test_suite::get( const_string tu_name ) const
+{
+ BOOST_TEST_FOREACH( test_unit_id, id, m_members ) {
+ if( framework::get( id, test_id_2_unit_type( id ) ).p_name == tu_name )
+ return id;
+ }
+
+ return INV_TEST_UNIT_ID;
+}
+
+//____________________________________________________________________________//
+
 // ************************************************************************** //
 // ************** traverse_test_tree ************** //
 // ************************************************************************** //
@@ -213,8 +233,76 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** auto_test_unit_registrar ************** //
+// ************************************************************************** //
+
+auto_test_unit_registrar::auto_test_unit_registrar( test_case* tc, counter_t exp_fail )
+{
+ curr_ts_store().back()->add( tc, exp_fail );
+}
+
+//____________________________________________________________________________//
+
+auto_test_unit_registrar::auto_test_unit_registrar( const_string ts_name )
+{
+ test_unit_id id = curr_ts_store().back()->get( ts_name );
+
+ test_suite* ts;
+
+ if( id != INV_TEST_UNIT_ID ) {
+ ts = &framework::get<test_suite>( id ); // !! test for invalid tu type
+ BOOST_ASSERT( ts->p_parent_id == curr_ts_store().back()->p_id );
+ }
+ else {
+ ts = new test_suite( ts_name );
+ curr_ts_store().back()->add( ts );
+ }
+
+ curr_ts_store().push_back( ts );
+}
+
+//____________________________________________________________________________//
+
+auto_test_unit_registrar::auto_test_unit_registrar( test_unit_generator const& tc_gen )
+{
+ curr_ts_store().back()->add( tc_gen );
+}
+
+//____________________________________________________________________________//
+
+auto_test_unit_registrar::auto_test_unit_registrar( int )
+{
+ if( curr_ts_store().size() == 0 )
+ return; // report error?
+
+ curr_ts_store().pop_back();
+}
+
+//____________________________________________________________________________//
+
+std::list<test_suite*>&
+auto_test_unit_registrar::curr_ts_store()
+{
+ static std::list<test_suite*> inst( 1, &framework::master_test_suite() );
+ return inst;
+}
+
+//____________________________________________________________________________//
+
 } // namespace ut_detail
 
+// ************************************************************************** //
+// ************** global_fixture ************** //
+// ************************************************************************** //
+
+global_fixture::global_fixture()
+{
+ framework::register_observer( *this );
+}
+
+//____________________________________________________________________________//
+
 } // namespace unit_test
 
 } // namespace boost

Modified: trunk/boost/test/included/unit_test.hpp
==============================================================================
--- trunk/boost/test/included/unit_test.hpp (original)
+++ trunk/boost/test/included/unit_test.hpp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -16,8 +16,11 @@
 #define BOOST_INCLUDED_UNIT_TEST_FRAMEWORK_HPP_071894GER
 
 #include <boost/test/impl/compiler_log_formatter.ipp>
-#include <boost/test/impl/execution_monitor.ipp>
 #include <boost/test/impl/framework.ipp>
+#include <boost/test/impl/exception_safety.ipp>
+#include <boost/test/impl/execution_monitor.ipp>
+#include <boost/test/impl/interaction_based.ipp>
+#include <boost/test/impl/logged_expectations.ipp>
 #include <boost/test/impl/plain_report_formatter.ipp>
 #include <boost/test/impl/progress_monitor.ipp>
 #include <boost/test/impl/results_collector.ipp>

Modified: trunk/boost/test/logged_expectations.hpp
==============================================================================
--- trunk/boost/test/logged_expectations.hpp (original)
+++ trunk/boost/test/logged_expectations.hpp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -47,7 +47,7 @@
     boost::unit_test::make_test_case( \
         &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \
     boost::unit_test::ut_detail::auto_tc_exp_fail< \
- BOOST_AUTO_TC_UNIQUE_ID( test_name )>::value ); \
+ BOOST_AUTO_TC_UNIQUE_ID( test_name )>::instance()->value() ); \
                                                                         \
 void test_name::test_method() \
 /**/

Modified: trunk/boost/test/test_tools.hpp
==============================================================================
--- trunk/boost/test/test_tools.hpp (original)
+++ trunk/boost/test/test_tools.hpp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -161,6 +161,7 @@
     BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", CHECK, CHECK_EQUAL, (L)(R) )
 #define BOOST_REQUIRE_EQUAL( L, R ) \
     BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", REQUIRE, CHECK_EQUAL, (L)(R) )
+
 //____________________________________________________________________________//
 
 #define BOOST_WARN_CLOSE( L, R, T ) \
@@ -469,12 +470,12 @@
 //____________________________________________________________________________//
 
 predicate_result BOOST_TEST_DECL equal_impl( char const* left, char const* right );
-inline predicate_result BOOST_TEST_DECL equal_impl( char* left, char const* right ) { return equal_impl( (char const*)left, (char const*)right ); }
-inline predicate_result BOOST_TEST_DECL equal_impl( char const* left, char* right ) { return equal_impl( (char const*)left, (char const*)right ); }
-inline predicate_result BOOST_TEST_DECL equal_impl( char* left, char* right ) { return equal_impl( (char const*)left, (char const*)right ); }
+inline predicate_result equal_impl( char* left, char const* right ) { return equal_impl( (char const*)left, (char const*)right ); }
+inline predicate_result equal_impl( char const* left, char* right ) { return equal_impl( (char const*)left, (char const*)right ); }
+inline predicate_result equal_impl( char* left, char* right ) { return equal_impl( (char const*)left, (char const*)right ); }
 
 #if !defined( BOOST_NO_CWCHAR )
-predicate_result equal_impl( wchar_t const* left, wchar_t const* right );
+predicate_result BOOST_TEST_DECL equal_impl( wchar_t const* left, wchar_t const* right );
 inline predicate_result equal_impl( wchar_t* left, wchar_t const* right ) { return equal_impl( (wchar_t const*)left, (wchar_t const*)right ); }
 inline predicate_result equal_impl( wchar_t const* left, wchar_t* right ) { return equal_impl( (wchar_t const*)left, (wchar_t const*)right ); }
 inline predicate_result equal_impl( wchar_t* left, wchar_t* right ) { return equal_impl( (wchar_t const*)left, (wchar_t const*)right ); }
@@ -600,78 +601,6 @@
 // Revision History :
 //
 // $Log$
-// Revision 1.66 2007/04/05 14:46:47 dgregor
-// Add include of climits
-//
-// Revision 1.65 2007/02/22 18:00:39 speedsnail
-// Removed the msvc-6.5 hack from HEAD again. Gennadiy Rozental didn't like it anyways...
-//
-// Revision 1.64 2006/12/16 14:36:23 speedsnail
-// Workaround for msvc-6.5: *_EQUAL macros give Internal Compiler Errors, when inlining is turned on.
-//
-// Revision 1.63 2006/11/14 21:33:01 jhunold
-// Add missing export macros for print_log_value<>
-//
-// Revision 1.62 2006/11/14 07:34:30 jhunold
-// Removed wrong export declarations.
-//
-// Revision 1.61 2006/11/13 20:03:48 jhunold
-// Added missing export declarations.
-//
-// Revision 1.60 2006/03/19 07:27:11 rogeeff
-// avoid warning
-//
-// Revision 1.59 2006/03/03 17:39:46 rogeeff
-// paaspoint added to check throw
-//
-// Revision 1.58 2006/02/06 10:04:55 rogeeff
-// BOOST_TEST_MODULE - master test suite name
-//
-// Revision 1.57 2006/01/28 07:00:47 rogeeff
-// sunpro port
-//
-// Revision 1.56 2005/12/19 03:08:30 rogeeff
-// added is_abstract to guard numeric_limits instantiation
-//
-// Revision 1.55 2005/12/14 05:20:41 rogeeff
-// dll support introduced
-// BOOST_TEST_PASSPOINT() introduced
-// BOOST_MESSAGE depricated. Use BOOST_TEST_MESSAGE instead
-// BOOST_CHECKPOINT is depricated. Use BOOST_TEST_CHECKPOINT intead
-//
-// Revision 1.54 2005/06/07 04:38:20 rogeeff
-// borland fix
-//
-// Revision 1.53 2005/05/11 04:51:14 rogeeff
-// borlard portability fix
-//
-// Revision 1.52 2005/03/22 07:08:47 rogeeff
-// string comparisons streamlined
-// precision settings made portable
-//
-// Revision 1.51 2005/02/21 10:23:54 rogeeff
-// major issue with TT redesign causing TT to reevaluate it's arguments fixed
-// FP precision extended
-//
-// Revision 1.50 2005/02/20 08:27:06 rogeeff
-// This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
-//
-// Revision 1.49 2005/02/01 06:40:06 rogeeff
-// copyright update
-// old log entries removed
-// minor stylistic changes
-// deprecated tools removed
-//
-// Revision 1.48 2005/01/30 03:32:57 rogeeff
-// Test Tools completely reworked:
-// interfaces streamlined to provide 3 version for each tool
-// implementation reworked to use single vararg formatter function
-// CHECK_COLLECTION now expect 4 arguments
-// BITWISE_EQUAL renamed to CHECK_BITWISE_EQUAL but still provided as deprecated
-// CHECK_COLLECTION interface changed to use PP_SEQ and as a result support arbitrary number of predicate arguments
-// most of templates eliminated
-// deprecated tools removed
-// print_helper object generator added
 //
 // ***************************************************************************
 

Modified: trunk/boost/test/unit_test_suite.hpp
==============================================================================
--- trunk/boost/test/unit_test_suite.hpp (original)
+++ trunk/boost/test/unit_test_suite.hpp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -17,6 +17,7 @@
 
 // Boost.Test
 #include <boost/test/unit_test_suite_impl.hpp>
+#include <boost/test/framework.hpp>
 
 //____________________________________________________________________________//
 
@@ -42,8 +43,7 @@
 
 #define BOOST_AUTO_TEST_SUITE( suite_name ) \
 namespace suite_name { \
-BOOST_AUTO_TC_REGISTRAR( suite_name )( BOOST_TEST_SUITE( \
- BOOST_STRINGIZE( suite_name ) ) ); \
+BOOST_AUTO_TC_REGISTRAR( suite_name )( BOOST_STRINGIZE( suite_name ) ); \
 /**/
 
 // ************************************************************************** //
@@ -70,14 +70,17 @@
 
 #define BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( test_name, n ) \
 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ); \
-namespace boost { namespace unit_test { namespace ut_detail { \
                                                                         \
-template<> \
-struct auto_tc_exp_fail<BOOST_AUTO_TC_UNIQUE_ID( test_name ) > { \
- enum { value = n }; \
-}; \
+static struct BOOST_JOIN( test_name, _exp_fail_num_spec ) \
+: boost::unit_test::ut_detail:: \
+ auto_tc_exp_fail<BOOST_AUTO_TC_UNIQUE_ID( test_name ) > \
+{ \
+ BOOST_JOIN( test_name, _exp_fail_num_spec )() \
+ : boost::unit_test::ut_detail:: \
+ auto_tc_exp_fail<BOOST_AUTO_TC_UNIQUE_ID( test_name ) >( n ) \
+ {} \
+} BOOST_JOIN( test_name, _exp_fail_num_spec_inst ); \
                                                                         \
-}}} \
 /**/
 
 // ************************************************************************** //
@@ -99,7 +102,7 @@
     boost::unit_test::make_test_case( \
         &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \
     boost::unit_test::ut_detail::auto_tc_exp_fail< \
- BOOST_AUTO_TC_UNIQUE_ID( test_name )>::value ); \
+ BOOST_AUTO_TC_UNIQUE_ID( test_name )>::instance()->value() ); \
                                                                         \
 void test_name::test_method() \
 /**/

Modified: trunk/boost/test/unit_test_suite_impl.hpp
==============================================================================
--- trunk/boost/test/unit_test_suite_impl.hpp (original)
+++ trunk/boost/test/unit_test_suite_impl.hpp 2007-10-14 17:14:29 EDT (Sun, 14 Oct 2007)
@@ -23,7 +23,6 @@
 #include <boost/test/detail/fwd_decl.hpp>
 #include <boost/test/detail/workaround.hpp>
 #include <boost/test/test_observer.hpp>
-#include <boost/test/framework.hpp>
 
 // Boost
 #include <boost/shared_ptr.hpp>
@@ -67,7 +66,9 @@
     // Public r/w properties
     readwrite_property<std::string> p_name; // name for this test unit
     readwrite_property<unsigned> p_timeout; // timeout for the test unit execution
- readwrite_property<counter_t> p_expected_failures; // number of expected failured in this test unit
+ readwrite_property<counter_t> p_expected_failures; // number of expected failures in this test unit
+
+ void increase_exp_fail( unsigned num );
 
 private:
     // Data members
@@ -120,16 +121,19 @@
     // Constructor
     explicit test_suite( const_string ts_name );
 
- // test case list management
+ // test unit list management
     void add( test_unit* tu, counter_t expected_failures = 0, unsigned timeout = 0 );
     void add( test_unit_generator const& gen, unsigned timeout = 0 );
 
+ // access methods
+ test_unit_id get( const_string tu_name ) const;
+
 protected:
- friend BOOST_TEST_DECL void traverse_test_tree( test_suite const&, test_tree_visitor& );
+ friend BOOST_TEST_DECL
+ void traverse_test_tree( test_suite const&, test_tree_visitor& );
     friend class framework_impl;
     virtual ~test_suite() {}
 
-private:
     // Data members
     std::vector<test_unit_id> m_members;
 };
@@ -172,7 +176,7 @@
 
 BOOST_TEST_DECL void traverse_test_tree( test_case const&, test_tree_visitor& );
 BOOST_TEST_DECL void traverse_test_tree( test_suite const&, test_tree_visitor& );
-BOOST_TEST_DECL void traverse_test_tree( test_unit_id id, test_tree_visitor& );
+BOOST_TEST_DECL void traverse_test_tree( test_unit_id , test_tree_visitor& );
 
 //____________________________________________________________________________//
 
@@ -258,41 +262,39 @@
 
 struct BOOST_TEST_DECL auto_test_unit_registrar
 {
- // Constructor
- explicit auto_test_unit_registrar( test_case* tc, counter_t exp_fail )
- {
- curr_ts_store().back()->add( tc, exp_fail );
- }
- explicit auto_test_unit_registrar( test_suite* ts )
- {
- curr_ts_store().back()->add( ts );
-
- curr_ts_store().push_back( ts );
- }
- explicit auto_test_unit_registrar( test_unit_generator const& tc_gen )
- {
- curr_ts_store().back()->add( tc_gen );
- }
- explicit auto_test_unit_registrar( int )
- {
- if( curr_ts_store().size() > 1 )
- curr_ts_store().pop_back();
- // else report error
- }
+ // Constructors
+ auto_test_unit_registrar( test_case* tc, counter_t exp_fail );
+ explicit auto_test_unit_registrar( const_string ts_name );
+ explicit auto_test_unit_registrar( test_unit_generator const& tc_gen );
+ explicit auto_test_unit_registrar( int );
 
 private:
- static std::list<test_suite*>& curr_ts_store()
- {
- static std::list<test_suite*> inst( 1, &framework::master_test_suite() );
- return inst;
- }
+ static std::list<test_suite*>& curr_ts_store();
 };
 
 //____________________________________________________________________________//
 
 template<typename T>
 struct auto_tc_exp_fail {
- enum { value = 0 };
+ explicit auto_tc_exp_fail( unsigned v = 0 )
+ : m_value( v )
+ {
+ instance() = this;
+ }
+
+ static auto_tc_exp_fail*& instance()
+ {
+ static auto_tc_exp_fail inst;
+ static auto_tc_exp_fail* inst_ptr = &inst;
+
+ return inst_ptr;
+ }
+
+ unsigned value() const { return m_value; }
+
+private:
+ // Data members
+ unsigned m_value;
 };
 
 //____________________________________________________________________________//
@@ -306,7 +308,7 @@
 class BOOST_TEST_DECL global_fixture : public test_observer {
 public:
     // Constructor
- global_fixture() { framework::register_observer( *this ); }
+ global_fixture();
 };
 
 //____________________________________________________________________________//


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk