Index: boost/test/progress_monitor.hpp =================================================================== --- boost/test/progress_monitor.hpp (revision 80605) +++ boost/test/progress_monitor.hpp (working copy) @@ -18,6 +18,7 @@ // Boost.Test #include #include +#include // STL #include // for std::ostream& @@ -41,7 +42,7 @@ void test_aborted(); void test_unit_start( test_unit const& ) {} - void test_unit_finish( test_unit const&, unsigned long ); + void test_unit_finish( test_unit const&, elapsed_t ); void test_unit_skipped( test_unit const& ); void test_unit_aborted( test_unit const& ) {} Index: boost/test/impl/framework.ipp =================================================================== --- boost/test/impl/framework.ipp (revision 80605) +++ boost/test/impl/framework.ipp (working copy) @@ -40,9 +40,9 @@ #include #include +#include // Boost -#include #include // STL @@ -372,7 +372,7 @@ return true; } - void test_unit_finish( test_unit const& tu, unit_test_monitor_t::error_level run_result, unsigned long elapsed ) + void test_unit_finish( test_unit const& tu, unit_test_monitor_t::error_level run_result, elapsed_t elapsed ) { // if run error is critical skip teardown, who knows what the state of the program at this point if( !unit_test_monitor.is_critical_error( run_result ) ) { @@ -412,9 +412,11 @@ m_curr_test_case = tc.p_id; // execute the test case body - boost::timer tc_timer; + timer_t tc_timer; unit_test_monitor_t::error_level run_result = unit_test_monitor.execute_and_translate( tc.p_test_func, tc.p_timeout ); - unsigned long elapsed = static_cast( tc_timer.elapsed() * 1e6 ); + + tc_timer.stop(); + elapsed_t elapsed = tc_timer.elapsed(); // cleanup leftover context m_context.clear(); @@ -433,7 +435,7 @@ void test_suite_finish( test_suite const& ts ) { - test_unit_finish( ts, unit_test_monitor_t::test_ok, 0 ); + test_unit_finish( ts, unit_test_monitor_t::test_ok, elapsed_t() ); } ////////////////////////////////////////////////////////////////// Index: boost/test/impl/test_tree.ipp =================================================================== --- boost/test/impl/test_tree.ipp (revision 80605) +++ boost/test/impl/test_tree.ipp (working copy) @@ -31,9 +31,10 @@ #include #include +#include // Boost -#include +// none // STL #include Index: boost/test/impl/compiler_log_formatter.ipp =================================================================== --- boost/test/impl/compiler_log_formatter.ipp (revision 80605) +++ boost/test/impl/compiler_log_formatter.ipp (working copy) @@ -24,6 +24,7 @@ #include #include #include +#include // Boost #include @@ -99,18 +100,15 @@ //____________________________________________________________________________// void -compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed ) +compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, elapsed_t elapsed ) { BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE ); output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\""; - if( elapsed > 0 ) { + if( has_time( elapsed ) ) { output << "; testing time: "; - if( elapsed % 1000 == 0 ) - output << elapsed/1000 << "ms"; - else - output << elapsed << "mks"; + output << to_string( elapsed ); } output << std::endl; Index: boost/test/impl/unit_test_log.ipp =================================================================== --- boost/test/impl/unit_test_log.ipp (revision 80605) +++ boost/test/impl/unit_test_log.ipp (working copy) @@ -28,6 +28,8 @@ #include #include +#include + // Boost #include #include @@ -177,7 +179,7 @@ //____________________________________________________________________________// void -unit_test_log_t::test_unit_finish( test_unit const& tu, unsigned long elapsed ) +unit_test_log_t::test_unit_finish( test_unit const& tu, elapsed_t elapsed ) { if( s_log_impl().m_threshold_level > log_test_units ) return; Index: boost/test/impl/results_collector.ipp =================================================================== --- boost/test/impl/results_collector.ipp (revision 80605) +++ boost/test/impl/results_collector.ipp (working copy) @@ -24,6 +24,7 @@ #include #include #include +#include // Boost #include @@ -204,7 +205,7 @@ //____________________________________________________________________________// void -results_collector_t::test_unit_finish( test_unit const& tu, unsigned long ) +results_collector_t::test_unit_finish( test_unit const& tu, elapsed_t ) { if( tu.p_type == tut_suite ) { results_collect_helper ch( s_rc_impl().m_results_store[tu.p_id], tu ); Index: boost/test/impl/progress_monitor.ipp =================================================================== --- boost/test/impl/progress_monitor.ipp (revision 80605) +++ boost/test/impl/progress_monitor.ipp (working copy) @@ -24,9 +24,10 @@ #include #include #include +#include +#include // Boost -#include #include #include @@ -79,7 +80,7 @@ //____________________________________________________________________________// void -progress_monitor_t::test_unit_finish( test_unit const& tu, unsigned long ) +progress_monitor_t::test_unit_finish( test_unit const& tu, elapsed_t ) { BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA ); Index: boost/test/impl/xml_log_formatter.ipp =================================================================== --- boost/test/impl/xml_log_formatter.ipp (revision 80605) +++ boost/test/impl/xml_log_formatter.ipp (working copy) @@ -23,6 +23,8 @@ #include #include +#include + // Boost #include @@ -86,11 +88,11 @@ //____________________________________________________________________________// void -xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed ) +xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, elapsed_t elapsed ) { if( tu.p_type == tut_case ) - ostr << "" << elapsed << ""; - + ostr << to_xml( elapsed ); + ostr << ""; } Index: boost/test/unit_test_log.hpp =================================================================== --- boost/test/unit_test_log.hpp (revision 80605) +++ boost/test/unit_test_log.hpp (working copy) @@ -28,6 +28,8 @@ #include #include +#include + // Boost // STL @@ -96,7 +98,7 @@ void test_aborted(); void test_unit_start( test_unit const& ); - void test_unit_finish( test_unit const&, unsigned long elapsed ); + void test_unit_finish( test_unit const&, elapsed_t elapsed ); void test_unit_skipped( test_unit const& ); void test_unit_aborted( test_unit const& ); Index: boost/test/results_collector.hpp =================================================================== --- boost/test/results_collector.hpp (revision 80605) +++ boost/test/results_collector.hpp (working copy) @@ -83,7 +83,7 @@ void test_aborted(); void test_unit_start( test_unit const& ); - void test_unit_finish( test_unit const&, unsigned long elapsed ); + void test_unit_finish( test_unit const&, elapsed_t elapsed ); void test_unit_skipped( test_unit const& ); void test_unit_aborted( test_unit const& ); Index: boost/test/output/xml_log_formatter.hpp =================================================================== --- boost/test/output/xml_log_formatter.hpp (revision 80605) +++ boost/test/output/xml_log_formatter.hpp (working copy) @@ -19,6 +19,8 @@ #include #include +#include + // STL #include // std::size_t @@ -42,7 +44,7 @@ void log_build_info( std::ostream& ); void test_unit_start( std::ostream&, test_unit const& tu ); - void test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed ); + void test_unit_finish( std::ostream&, test_unit const& tu, elapsed_t elapsed ); void test_unit_skipped( std::ostream&, test_unit const& tu ); void log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const& ex ); Index: boost/test/output/compiler_log_formatter.hpp =================================================================== --- boost/test/output/compiler_log_formatter.hpp (revision 80605) +++ boost/test/output/compiler_log_formatter.hpp (working copy) @@ -21,6 +21,8 @@ #include +#include + //____________________________________________________________________________// namespace boost { @@ -39,7 +41,7 @@ void log_build_info( std::ostream& ); void test_unit_start( std::ostream&, test_unit const& tu ); - void test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed ); + void test_unit_finish( std::ostream&, test_unit const& tu, elapsed_t elapsed ); void test_unit_skipped( std::ostream&, test_unit const& tu ); void log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const& ex ); Index: boost/test/utils/progress.hpp =================================================================== --- boost/test/utils/progress.hpp (revision 0) +++ boost/test/utils/progress.hpp (working copy) @@ -0,0 +1,105 @@ +// boost progress.hpp header file ------------------------------------------// + +// Copyright Beman Dawes 1994-99. 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/timer for documentation. + +// Revision History +// 1 Dec 01 Add leading progress display strings (suggested by Toon Knapen) +// 20 May 01 Introduce several static_casts<> to eliminate warning messages +// (Fixed by Beman, reported by Herve Bronnimann) +// 12 Jan 01 Change to inline implementation to allow use without library +// builds. See docs for more rationale. (Beman Dawes) +// 22 Jul 99 Name changed to .hpp +// 16 Jul 99 Second beta +// 6 Jul 99 Initial boost version + +#ifndef BOOST_TEST_UTILS_PROGRESS_DISPLAY_HPP +#define BOOST_TEST_UTILS_PROGRESS_DISPLAY_HPP + +#include +#include // for ostream, cout, etc +#include // for string + +namespace boost { +namespace unit_test { + +// progress_display --------------------------------------------------------// + +// progress_display displays an appropriate indication of +// progress at an appropriate place in an appropriate form. + +// NOTE: (Jan 12, 2001) Tried to change unsigned long to boost::uintmax_t, but +// found some compilers couldn't handle the required conversion to double. +// Reverted to unsigned long until the compilers catch up. + +class progress_display : private noncopyable +{ + public: + explicit progress_display( unsigned long expected_count, + std::ostream & os = std::cout, + const std::string & s1 = "\n", //leading strings + const std::string & s2 = "", + const std::string & s3 = "" ) + // os is hint; implementation may ignore, particularly in embedded systems + : m_os(os), m_s1(s1), m_s2(s2), m_s3(s3) { restart(expected_count); } + + void restart( unsigned long expected_count ) + // Effects: display appropriate scale + // Postconditions: count()==0, expected_count()==expected_count + { + _count = _next_tic_count = _tic = 0; + _expected_count = expected_count; + + m_os << m_s1 << "0% 10 20 30 40 50 60 70 80 90 100%\n" + << m_s2 << "|----|----|----|----|----|----|----|----|----|----|" + << std::endl // endl implies flush, which ensures display + << m_s3; + if ( !_expected_count ) _expected_count = 1; // prevent divide by zero + } // restart + + unsigned long operator+=( unsigned long increment ) + // Effects: Display appropriate progress tic if needed. + // Postconditions: count()== original count() + increment + // Returns: count(). + { + if ( (_count += increment) >= _next_tic_count ) { display_tic(); } + return _count; + } + + unsigned long operator++() { return operator+=( 1 ); } + unsigned long count() const { return _count; } + unsigned long expected_count() const { return _expected_count; } + + private: + std::ostream & m_os; // may not be present in all imps + const std::string m_s1; // string is more general, safer than + const std::string m_s2; // const char *, and efficiency or size are + const std::string m_s3; // not issues + + unsigned long _count, _expected_count, _next_tic_count; + unsigned int _tic; + void display_tic() + { + // use of floating point ensures that both large and small counts + // work correctly. static_cast<>() is also used several places + // to suppress spurious compiler warnings. + unsigned int tics_needed = + static_cast( + (static_cast(_count)/_expected_count)*50.0 ); + do { m_os << '*' << std::flush; } while ( ++_tic < tics_needed ); + _next_tic_count = + static_cast((_tic/50.0)*_expected_count); + if ( _count == _expected_count ) { + if ( _tic < 51 ) m_os << '*'; + m_os << std::endl; + } + } // display_tic +}; + +} // namespace unit_test +} // namespace boost + +#endif // BOOST_TEST_UTILS_PROGRESS_DISPLAY_HPP Index: boost/test/utils/timer.hpp =================================================================== --- boost/test/utils/timer.hpp (revision 0) +++ boost/test/utils/timer.hpp (working copy) @@ -0,0 +1,93 @@ +// (C) Copyright Jamie Allsop 2012. +// 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. +// +// Description : timer and elapsed types +// *************************************************************************** + +#ifndef BOOST_TEST_UTILS_TIMER_HPP +#define BOOST_TEST_UTILS_TIMER_HPP + +#ifdef BOOST_TEST_USE_DEPRECATED_TIMER +#include +#else +#include +#endif + +#include + +namespace boost { +namespace unit_test { + +// ************************************************************************** // +// ************** opaque timer and elapsed types ************** // +// ************************************************************************** // + +#ifdef BOOST_TEST_USE_DEPRECATED_TIMER + +typedef boost::timer timer_t; +typedef unsigned long elapsed_t; + +inline std::string to_string( elapsed_t elapsed ) +{ + std::ostringstream output; + if( elapsed % 1000 == 0 ) + { + output << elapsed/1000 << "ms"; + } + else + { + output << elapsed << "mks"; + } + return output.str(); +} + +inline std::string to_xml( elapsed_t elapsed ) +{ + std::ostringstream output; + output << "" << elapsed << ""; + return output.str(); +} + +inline bool has_time( const elapsed_t& elapsed ) +{ + return elapsed; +} + +#else + +typedef boost::timer::cpu_timer timer_t; +typedef boost::timer::cpu_times elapsed_t; + +inline std::string to_string( elapsed_t elapsed ) +{ + return boost::timer::format( elapsed, 9, "%ws wall, %us user + %ss system = %ts CPU (%p%)" ); +} + +inline std::string to_xml( elapsed_t elapsed ) +{ + std::ostringstream output; + output << "" << ( elapsed.user + elapsed.system ) << "" + << "" << elapsed.wall << "" + << "" << elapsed.user << "" + << "" << elapsed.system << ""; + return output.str(); +} + +inline bool has_time( const elapsed_t& elapsed ) +{ + return elapsed.wall != 0 || elapsed.user != 0 || elapsed.system != 0; +} + +#endif + +//____________________________________________________________________________// + +} // namespace unit_test +} // namespace boost + +#endif // BOOST_TEST_UTILS_TIMER_HPP + Index: boost/test/unit_test_log_formatter.hpp =================================================================== --- boost/test/unit_test_log_formatter.hpp (revision 80605) +++ boost/test/unit_test_log_formatter.hpp (working copy) @@ -20,6 +20,8 @@ #include #include +#include + // STL #include #include // for std::string @@ -92,7 +94,7 @@ virtual void log_build_info( std::ostream& ) = 0; virtual void test_unit_start( std::ostream&, test_unit const& tu ) = 0; - virtual void test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed ) = 0; + virtual void test_unit_finish( std::ostream&, test_unit const& tu, elapsed_t elapsed ) = 0; virtual void test_unit_skipped( std::ostream&, test_unit const& ) = 0; virtual void log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const& ex ) = 0; Index: boost/test/tree/observer.hpp =================================================================== --- boost/test/tree/observer.hpp (revision 80605) +++ boost/test/tree/observer.hpp (working copy) @@ -22,6 +22,8 @@ #include +#include + //____________________________________________________________________________// namespace boost { @@ -39,7 +41,7 @@ virtual void test_aborted() {} virtual void test_unit_start( test_unit const& ) {} - virtual void test_unit_finish( test_unit const&, unsigned long /* elapsed */ ) {} + virtual void test_unit_finish( test_unit const&, elapsed_t /* elapsed */ ) {} virtual void test_unit_skipped( test_unit const& ) {} virtual void test_unit_aborted( test_unit const& ) {} Index: libs/test/test/Jamfile.v2 =================================================================== --- libs/test/test/Jamfile.v2 (revision 80605) +++ libs/test/test/Jamfile.v2 (working copy) @@ -6,6 +6,13 @@ # See http://www.boost.org/libs/test for the library home page. +project + : requirements + /boost/system//boost_system + /boost/timer//boost_timer + ; + + rule test-btl-lib ( test-rule : test-name : lib-name ? : pattern_file * : source_files * : extra-libs ? ) { source_files ?= $(test-name).cpp ;