Boost logo

Boost-Commit :

From: gennadiy.rozental_at_[hidden]
Date: 2007-10-15 23:51:55


Author: rogeeff
Date: 2007-10-15 23:51:54 EDT (Mon, 15 Oct 2007)
New Revision: 40069
URL: http://svn.boost.org/trac/boost/changeset/40069

Log:
unified test runner interface for both original and alternative init API, the same time streamlining error handling for all the cases
new property p_enabled is added to the test unit in preparation for the run by name
Text files modified:
   trunk/boost/test/framework.hpp | 12 +++++
   trunk/boost/test/impl/framework.ipp | 79 +++++++--------------------------------
   trunk/boost/test/impl/unit_test_main.ipp | 26 +++++++------
   trunk/boost/test/impl/unit_test_suite.ipp | 4 +
   trunk/boost/test/unit_test.hpp | 10 ----
   trunk/boost/test/unit_test_suite_impl.hpp | 3 +
   6 files changed, 46 insertions(+), 88 deletions(-)

Modified: trunk/boost/test/framework.hpp
==============================================================================
--- trunk/boost/test/framework.hpp (original)
+++ trunk/boost/test/framework.hpp 2007-10-15 23:51:54 EDT (Mon, 15 Oct 2007)
@@ -32,13 +32,23 @@
 namespace unit_test {
 
 // ************************************************************************** //
+// ************** init_unit_test_func ************** //
+// ************************************************************************** //
+
+#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
+typedef bool (*init_unit_test_func)();
+#else
+typedef test_suite* (*init_unit_test_func)( int, char* [] );
+#endif
+
+// ************************************************************************** //
 // ************** framework ************** //
 // ************************************************************************** //
 
 namespace framework {
 
 // initialization
-BOOST_TEST_DECL void init( int argc, char* argv[] );
+BOOST_TEST_DECL void init( init_unit_test_func init_func, int argc, char* argv[] );
 
 // mutation access methods
 BOOST_TEST_DECL void register_test_unit( test_case* tc );

Modified: trunk/boost/test/impl/framework.ipp
==============================================================================
--- trunk/boost/test/impl/framework.ipp (original)
+++ trunk/boost/test/impl/framework.ipp 2007-10-15 23:51:54 EDT (Mon, 15 Oct 2007)
@@ -49,17 +49,6 @@
 
 //____________________________________________________________________________//
 
-#ifndef BOOST_TEST_DYN_LINK
-
-// prototype for user's unit test init function
-#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
-extern bool init_unit_test();
-#else
-extern boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] );
-#endif
-
-#endif
-
 namespace boost {
 
 namespace unit_test {
@@ -91,15 +80,24 @@
 //____________________________________________________________________________//
 
 struct test_init_caller {
- test_init_caller() : m_manual_test_units( 0 ) {}
- int operator()()
+ explicit test_init_caller( init_unit_test_func init_func )
+ : m_manual_test_units( 0 )
+ , m_init_func( init_func )
+ {}
+ int operator()()
     {
- m_manual_test_units = init_unit_test_suite( framework::master_test_suite().argc, framework::master_test_suite().argv );
+#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
+ if( !(*m_init_func)() )
+ throw std::runtime_error( "test module initialization failed" );
+#else
+ m_manual_test_units = (*m_init_func)( framework::master_test_suite().argc, framework::master_test_suite().argv );
+#endif
         return 0;
     }
 
     // Data members
- test_suite* m_manual_test_units;
+ test_suite* m_manual_test_units;
+ init_unit_test_func m_init_func;
 };
 
 }
@@ -221,7 +219,7 @@
 namespace framework {
 
 void
-init( int argc, char* argv[] )
+init( init_unit_test_func init_func, int argc, char* argv[] )
 {
     runtime_config::init( &argc, argv );
 
@@ -248,16 +246,10 @@
     master_test_suite().argc = argc;
     master_test_suite().argv = argv;
 
-#ifndef BOOST_TEST_DYN_LINK
-
-#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
- if( !init_unit_test() )
- throw setup_error( BOOST_TEST_L("test tree initialization error" ) );
-#else
     try {
         boost::execution_monitor em;
 
- ut_detail::test_init_caller tic;
+ ut_detail::test_init_caller tic( init_func );
 
         em.execute( tic );
 
@@ -267,10 +259,6 @@
     catch( execution_exception const& ex ) {
         throw setup_error( ex.what() );
     }
-#endif
-
-#endif
-
 }
 
 //____________________________________________________________________________//
@@ -478,41 +466,4 @@
 
 #include <boost/test/detail/enable_warnings.hpp>
 
-// ***************************************************************************
-// Revision History :
-//
-// $Log$
-// Revision 1.10 2006/03/19 07:27:52 rogeeff
-// streamline test setup error message
-//
-// Revision 1.9 2006/01/30 07:29:49 rogeeff
-// split memory leaks detection API in two to get more functions with better defined roles
-//
-// Revision 1.8 2005/12/17 02:34:11 rogeeff
-// *** empty log message ***
-//
-// Revision 1.7 2005/12/14 05:35:57 rogeeff
-// DLL support implemented
-// Alternative init API introduced
-//
-// Revision 1.6 2005/05/08 08:55:09 rogeeff
-// typos and missing descriptions fixed
-//
-// Revision 1.5 2005/04/05 07:23:20 rogeeff
-// restore default
-//
-// Revision 1.4 2005/04/05 06:11:37 rogeeff
-// memory leak allocation point detection\nextra help with _WIN32_WINNT
-//
-// Revision 1.3 2005/03/23 21:02:19 rogeeff
-// Sunpro CC 5.3 fixes
-//
-// Revision 1.2 2005/02/21 10:12:18 rogeeff
-// Support for random order of test cases implemented
-//
-// Revision 1.1 2005/02/20 08:27:07 rogeeff
-// This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
-//
-// ***************************************************************************
-
 #endif // BOOST_TEST_FRAMEWORK_IPP_021005GER

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-15 23:51:54 EDT (Mon, 15 Oct 2007)
@@ -43,20 +43,11 @@
 // ************************************************************************** //
 
 int BOOST_TEST_DECL
-
-#if defined(BOOST_TEST_DYN_LINK)
-unit_test_main( bool (*init_unit_test_func)(), int argc, char* argv[] )
-#else
-unit_test_main( int argc, char* argv[] )
-#endif
+unit_test_main( init_unit_test_func init_func, int argc, char* argv[] )
 {
     try {
- framework::init( argc, argv );
+ framework::init( init_func, argc, argv );
 
-#ifdef BOOST_TEST_DYN_LINK
- 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() ) {
 //
 // }
@@ -99,7 +90,18 @@
 int BOOST_TEST_CALL_DECL
 main( int argc, char* argv[] )
 {
- return ::boost::unit_test::unit_test_main( argc, argv );
+ // prototype for user's unit test init function
+#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
+ extern bool init_unit_test();
+
+ boost::unit_test::init_unit_test_func init_func = &init_unit_test;
+#else
+ extern ::boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] );
+
+ boost::unit_test::init_unit_test_func init_func = &init_unit_test_suite;
+#endif
+
+ return ::boost::unit_test::unit_test_main( init_func, argc, argv );
 }
 
 #endif // !BOOST_TEST_DYN_LINK && !BOOST_TEST_NO_MAIN

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-15 23:51:54 EDT (Mon, 15 Oct 2007)
@@ -54,6 +54,7 @@
 , p_type_name( t == tut_case ? "case" : "suite" )
 , p_id( INV_TEST_UNIT_ID )
 , p_name( std::string( name.begin(), name.size() ) )
+, p_enabled( true )
 {
 }
 
@@ -171,6 +172,7 @@
 void
 traverse_test_tree( test_case const& tc, test_tree_visitor& V )
 {
+ if( tc.p_enabled )
     V.visit( tc );
 }
 
@@ -179,7 +181,7 @@
 void
 traverse_test_tree( test_suite const& suite, test_tree_visitor& V )
 {
- if( !V.test_suite_start( suite ) )
+ if( !suite.p_enabled || !V.test_suite_start( suite ) )
         return;
 
     try {

Modified: trunk/boost/test/unit_test.hpp
==============================================================================
--- trunk/boost/test/unit_test.hpp (original)
+++ trunk/boost/test/unit_test.hpp 2007-10-15 23:51:54 EDT (Mon, 15 Oct 2007)
@@ -43,15 +43,7 @@
 
 namespace boost { namespace unit_test {
 
-#if defined(BOOST_TEST_DYN_LINK)
-
-int BOOST_TEST_DECL unit_test_main( bool (*init_unit_test_func)(), int argc, char* argv[] );
-
-#else
-
-int BOOST_TEST_DECL unit_test_main( int argc, char* argv[] );
-
-#endif
+int BOOST_TEST_DECL unit_test_main( init_unit_test_func init_func, int argc, char* argv[] );
 
 }}
 

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-15 23:51:54 EDT (Mon, 15 Oct 2007)
@@ -67,6 +67,7 @@
     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 failures in this test unit
+ mutable readwrite_property<bool> p_enabled; // enabled status for this unit
 
     void increase_exp_fail( unsigned num );
 
@@ -198,7 +199,7 @@
 struct test_case_counter : test_tree_visitor {
     test_case_counter() : m_count( 0 ) {}
 
- void visit( test_case const& ) { m_count++; }
+ virtual void visit( test_case const& ) { m_count++; }
 
     counter_t m_count;
 };


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