Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75035 - in trunk/boost/test: . impl
From: gennadiy.rozental_at_[hidden]
Date: 2011-10-18 05:20:13


Author: rogeeff
Date: 2011-10-18 05:20:11 EDT (Tue, 18 Oct 2011)
New Revision: 75035
URL: http://svn.boost.org/trac/boost/changeset/75035

Log:
avoid crash if testing tool is used in global fixture
Fixes #5563

Text files modified:
   trunk/boost/test/framework.hpp | 1 +
   trunk/boost/test/impl/framework.ipp | 8 ++++++++
   trunk/boost/test/impl/results_collector.ipp | 4 ++--
   trunk/boost/test/impl/test_tools.ipp | 4 ++--
   4 files changed, 13 insertions(+), 4 deletions(-)

Modified: trunk/boost/test/framework.hpp
==============================================================================
--- trunk/boost/test/framework.hpp (original)
+++ trunk/boost/test/framework.hpp 2011-10-18 05:20:11 EDT (Tue, 18 Oct 2011)
@@ -87,6 +87,7 @@
 
 // constant access methods
 BOOST_TEST_DECL test_case const& current_test_case();
+BOOST_TEST_DECL test_unit_id current_test_case_id(); /* safe version of above */
 
 BOOST_TEST_DECL test_unit& get( test_unit_id, test_unit_type );
 template<typename UnitType>

Modified: trunk/boost/test/impl/framework.ipp
==============================================================================
--- trunk/boost/test/impl/framework.ipp (original)
+++ trunk/boost/test/impl/framework.ipp 2011-10-18 05:20:11 EDT (Tue, 18 Oct 2011)
@@ -972,6 +972,14 @@
 
 //____________________________________________________________________________//
 
+test_unit_id
+current_test_case_id()
+{
+ return s_frk_impl().m_curr_test_case;
+}
+
+//____________________________________________________________________________//
+
 // ************************************************************************** //
 // ************** framework::get ************** //
 // ************************************************************************** //

Modified: trunk/boost/test/impl/results_collector.ipp
==============================================================================
--- trunk/boost/test/impl/results_collector.ipp (original)
+++ trunk/boost/test/impl/results_collector.ipp 2011-10-18 05:20:11 EDT (Tue, 18 Oct 2011)
@@ -247,7 +247,7 @@
 void
 results_collector_t::assertion_result( bool passed )
 {
- test_results& tr = s_rc_impl().m_results_store[framework::current_test_case().p_id];
+ test_results& tr = s_rc_impl().m_results_store[framework::current_test_case_id()];
 
     if( passed )
         tr.p_assertions_passed.value++;
@@ -263,7 +263,7 @@
 void
 results_collector_t::exception_caught( execution_exception const& )
 {
- test_results& tr = s_rc_impl().m_results_store[framework::current_test_case().p_id];
+ test_results& tr = s_rc_impl().m_results_store[framework::current_test_case_id()];
 
     tr.p_assertions_failed.value++;
 }

Modified: trunk/boost/test/impl/test_tools.ipp
==============================================================================
--- trunk/boost/test/impl/test_tools.ipp (original)
+++ trunk/boost/test/impl/test_tools.ipp 2011-10-18 05:20:11 EDT (Tue, 18 Oct 2011)
@@ -284,8 +284,8 @@
 {
     using namespace unit_test;
 
- if( !framework::is_initialized() )
- throw std::runtime_error( "can't use testing tools before framework is initialized" );
+ if( framework::current_test_case_id() == INV_TEST_UNIT_ID )
+ throw std::runtime_error( "can't use testing tools outside of test case implementation" );
 
     if( !!pr )
         tl = PASS;


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