File indexing completed on 2025-01-30 10:01:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_PROGRESS_MONITOR_IPP_020105GER
0016 #define BOOST_TEST_PROGRESS_MONITOR_IPP_020105GER
0017
0018
0019 #include <boost/test/progress_monitor.hpp>
0020 #include <boost/test/unit_test_parameters.hpp>
0021
0022 #include <boost/test/utils/setcolor.hpp>
0023
0024 #include <boost/test/tree/test_unit.hpp>
0025 #include <boost/test/tree/test_case_counter.hpp>
0026 #include <boost/test/tree/traverse.hpp>
0027
0028
0029 #include <boost/scoped_ptr.hpp>
0030
0031 #include <boost/test/detail/suppress_warnings.hpp>
0032
0033
0034
0035 namespace boost {
0036 namespace unit_test {
0037
0038
0039
0040
0041
0042 struct progress_display {
0043 progress_display( counter_t expected_count, std::ostream& os )
0044 : m_os(os)
0045 , m_count( 0 )
0046 , m_expected_count( expected_count )
0047 , m_next_tic_count( 0 )
0048 , m_tic( 0 )
0049 {
0050
0051 m_os << "\n0% 10 20 30 40 50 60 70 80 90 100%"
0052 << "\n|----|----|----|----|----|----|----|----|----|----|"
0053 << std::endl;
0054
0055 if( !m_expected_count )
0056 m_expected_count = 1;
0057 }
0058
0059 unsigned long operator+=( unsigned long increment )
0060 {
0061 if( (m_count += increment) < m_next_tic_count )
0062 return m_count;
0063
0064
0065
0066
0067 unsigned int tics_needed = static_cast<unsigned int>(
0068 (static_cast<double>(m_count)/m_expected_count)*50.0 );
0069
0070 do {
0071 m_os << '*' << std::flush;
0072 } while( ++m_tic < tics_needed );
0073
0074 m_next_tic_count = static_cast<unsigned long>((m_tic/50.0) * m_expected_count);
0075
0076 if( m_count == m_expected_count ) {
0077 if( m_tic < 51 )
0078 m_os << '*';
0079
0080 m_os << std::endl;
0081 }
0082
0083 return m_count;
0084 }
0085 unsigned long operator++() { return operator+=( 1 ); }
0086 unsigned long count() const { return m_count; }
0087
0088 private:
0089 BOOST_DELETED_FUNCTION(progress_display(progress_display const&))
0090 BOOST_DELETED_FUNCTION(progress_display& operator=(progress_display const&))
0091
0092 std::ostream& m_os;
0093
0094 unsigned long m_count;
0095 unsigned long m_expected_count;
0096 unsigned long m_next_tic_count;
0097 unsigned int m_tic;
0098 };
0099
0100 namespace {
0101
0102 struct progress_monitor_impl {
0103
0104 progress_monitor_impl()
0105 : m_stream( &std::cout )
0106 , m_color_output( false )
0107 {
0108 }
0109
0110 std::ostream* m_stream;
0111 scoped_ptr<progress_display> m_progress_display;
0112 bool m_color_output;
0113 };
0114
0115 progress_monitor_impl& s_pm_impl() { static progress_monitor_impl the_inst; return the_inst; }
0116
0117 #define PM_SCOPED_COLOR() \
0118 BOOST_TEST_SCOPE_SETCOLOR( s_pm_impl().m_color_output, *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA )
0119
0120 }
0121
0122
0123
0124 BOOST_TEST_SINGLETON_CONS_IMPL(progress_monitor_t)
0125
0126
0127
0128 void
0129 progress_monitor_t::test_start( counter_t test_cases_amount, test_unit_id )
0130 {
0131 s_pm_impl().m_color_output = runtime_config::get<bool>( runtime_config::btrt_color_output );
0132
0133 PM_SCOPED_COLOR();
0134
0135 s_pm_impl().m_progress_display.reset( new progress_display( test_cases_amount, *s_pm_impl().m_stream ) );
0136 }
0137
0138
0139
0140 void
0141 progress_monitor_t::test_aborted()
0142 {
0143 PM_SCOPED_COLOR();
0144
0145 (*s_pm_impl().m_progress_display) += s_pm_impl().m_progress_display->count();
0146 }
0147
0148
0149
0150 void
0151 progress_monitor_t::test_unit_finish( test_unit const& tu, unsigned long )
0152 {
0153 PM_SCOPED_COLOR();
0154
0155 if( tu.p_type == TUT_CASE )
0156 ++(*s_pm_impl().m_progress_display);
0157 }
0158
0159
0160
0161 void
0162 progress_monitor_t::test_unit_skipped( test_unit const& tu, const_string )
0163 {
0164 PM_SCOPED_COLOR();
0165
0166 test_case_counter tcc;
0167 traverse_test_tree( tu, tcc );
0168
0169 (*s_pm_impl().m_progress_display) += tcc.p_count;
0170 }
0171
0172
0173
0174 void
0175 progress_monitor_t::set_stream( std::ostream& ostr )
0176 {
0177 s_pm_impl().m_stream = &ostr;
0178 }
0179
0180
0181
0182 #undef PM_SCOPED_COLOR
0183
0184 }
0185 }
0186
0187 #include <boost/test/detail/enable_warnings.hpp>
0188
0189 #endif