1 //  (C) Copyright Gennadiy Rozental 2003-2008.
2 //  Distributed under the Boost Software License, Version 1.0.
3 //  (See accompanying file LICENSE_1_0.txt or copy at
4 //  http://www.boost.org/LICENSE_1_0.txt)
5 
6 //  See http://www.boost.org/libs/test for the library home page.
7 //
8 //  File        : $RCSfile$
9 //
10 //  Version     : $Revision: 57992 $
11 //
12 //  Description :
13 // ***************************************************************************
14 
15 #ifndef BOOST_TEST_UNIT_TEST_LOG_FORMATTER_HPP_071894GER
16 #define BOOST_TEST_UNIT_TEST_LOG_FORMATTER_HPP_071894GER
17 
18 // Boost.Test
19 #include <boost/test/detail/global_typedef.hpp>
20 #include <boost/test/detail/log_level.hpp>
21 #include <boost/test/detail/fwd_decl.hpp>
22 
23 #include <boost/test/execution_monitor.hpp>
24 
25 // STL
26 #include <iosfwd>
27 #include <string> // for std::string
28 
29 #include <boost/test/detail/suppress_warnings.hpp>
30 
31 //____________________________________________________________________________//
32 
33 namespace boost {
34 
35 namespace unit_test {
36 
37 // ************************************************************************** //
38 // **************                log_entry_data                ************** //
39 // ************************************************************************** //
40 
41 struct BOOST_TEST_DECL log_entry_data {
log_entry_databoost::unit_test::log_entry_data42     log_entry_data()
43     {
44         m_file_name.reserve( 200 );
45     }
46 
47     std::string     m_file_name;
48     std::size_t     m_line_num;
49     log_level       m_level;
50 
clearboost::unit_test::log_entry_data51     void clear()
52     {
53         m_file_name.erase();
54         m_line_num      = 0;
55         m_level     = log_nothing;
56     }
57 };
58 
59 // ************************************************************************** //
60 // **************                checkpoint_data               ************** //
61 // ************************************************************************** //
62 
63 struct BOOST_TEST_DECL log_checkpoint_data
64 {
65     const_string    m_file_name;
66     std::size_t     m_line_num;
67     std::string     m_message;
68 
clearboost::unit_test::log_checkpoint_data69     void clear()
70     {
71         m_file_name.clear();
72         m_line_num    = 0;
73         m_message = std::string();
74     }
75 };
76 
77 // ************************************************************************** //
78 // **************            unit_test_log_formatter           ************** //
79 // ************************************************************************** //
80 
81 class BOOST_TEST_DECL unit_test_log_formatter {
82 public:
83     enum log_entry_types { BOOST_UTL_ET_INFO,
84                            BOOST_UTL_ET_MESSAGE,
85                            BOOST_UTL_ET_WARNING,
86                            BOOST_UTL_ET_ERROR,
87                            BOOST_UTL_ET_FATAL_ERROR };
88 
89     // Destructor
~unit_test_log_formatter()90     virtual             ~unit_test_log_formatter() {}
91 
92     // Formatter interface
93     virtual void        log_start( std::ostream&, counter_t test_cases_amount ) = 0;
94     virtual void        log_finish( std::ostream& ) = 0;
95     virtual void        log_build_info( std::ostream& ) = 0;
96 
97     virtual void        test_unit_start( std::ostream&, test_unit const& tu ) = 0;
98     virtual void        test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed ) = 0;
99     virtual void        test_unit_skipped( std::ostream&, test_unit const& ) = 0;
100 
log_exception(std::ostream & os,log_checkpoint_data const & cd,execution_exception const & ex)101     virtual void        log_exception( std::ostream& os, log_checkpoint_data const& cd, execution_exception const& ex )
102     {
103         // for backward compatibility
104         log_exception( os, cd, ex.what() );
105     }
log_exception(std::ostream &,log_checkpoint_data const &,const_string)106     virtual void        log_exception( std::ostream&, log_checkpoint_data const&, const_string /* explanation */ ) {}
107 
108     virtual void        log_entry_start( std::ostream&, log_entry_data const&, log_entry_types let ) = 0;
109     virtual void        log_entry_value( std::ostream&, const_string value ) = 0;
110     virtual void        log_entry_value( std::ostream&, lazy_ostream const& value ); // there is a default impl
111     virtual void        log_entry_finish( std::ostream& ) = 0;
112 };
113 
114 } // namespace unit_test
115 
116 } // namespace boost
117 
118 //____________________________________________________________________________//
119 
120 #include <boost/test/detail/enable_warnings.hpp>
121 
122 #endif // BOOST_TEST_UNIT_TEST_LOG_FORMATTER_HPP_071894GER
123 
124