source: NonGTP/Boost/boost/test/unit_test_log.hpp @ 857

Revision 857, 6.4 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]1//  (C) Copyright Gennadiy Rozental 2001-2005.
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: unit_test_log.hpp,v $
9//
10//  Version     : $Revision: 1.30 $
11//
12//  Description : defines singleton class unit_test_log and all manipulators.
13//  unit_test_log has output stream like interface. It's implementation is
14//  completely hidden with pimple idiom
15// ***************************************************************************
16
17#ifndef BOOST_TEST_UNIT_TEST_LOG_HPP_071894GER
18#define BOOST_TEST_UNIT_TEST_LOG_HPP_071894GER
19
20// Boost.Test
21#include <boost/test/test_observer.hpp>
22
23#include <boost/test/detail/global_typedef.hpp>
24#include <boost/test/detail/log_level.hpp>
25#include <boost/test/detail/fwd_decl.hpp>
26
27#include <boost/test/utils/trivial_singleton.hpp>
28
29// Boost
30#include <boost/utility.hpp>
31
32// STL
33#include <iosfwd>   // for std::ostream&
34
35#include <boost/test/detail/suppress_warnings.hpp>
36
37//____________________________________________________________________________//
38
39namespace boost {
40
41namespace unit_test {
42
43// ************************************************************************** //
44// **************                log manipulators              ************** //
45// ************************************************************************** //
46
47namespace log {
48
49struct begin {};
50
51struct end {};
52
53struct line {
54    explicit    line( std::size_t ln ) : m_line_num( ln ) {}
55
56    std::size_t m_line_num;
57};
58
59struct file {
60    explicit    file( const_string fn ) : m_file_name( fn ) {}
61
62    const_string m_file_name;
63};
64
65struct checkpoint {
66    explicit    checkpoint( const_string message ) : m_message( message ) {}
67
68    const_string m_message;
69};
70
71} // namespace log
72
73// ************************************************************************** //
74// **************             entry_value_collector            ************** //
75// ************************************************************************** //
76
77namespace ut_detail {
78
79class entry_value_collector {
80public:
81    // Constructors
82    entry_value_collector() : m_last( true ) {}
83    entry_value_collector( entry_value_collector& rhs ) : m_last( true ) { rhs.m_last = false; }
84    ~entry_value_collector();
85
86    // collection interface
87    entry_value_collector operator<<( const_string );
88    entry_value_collector operator<<( log::checkpoint const& );
89
90private:
91    // Data members
92    bool    m_last;
93};
94
95} // namespace ut_detail
96
97// ************************************************************************** //
98// **************                 unit_test_log                ************** //
99// ************************************************************************** //
100
101class unit_test_log_t : public test_observer, public singleton<unit_test_log_t> {
102public:
103    // test_observer interface implementation
104    void                test_start( counter_t test_cases_amount );
105    void                test_finish();
106    void                test_aborted();
107
108    void                test_unit_start( test_unit const& );
109    void                test_unit_finish( test_unit const&, unsigned long elapsed );
110    void                test_unit_skipped( test_unit const& );
111    void                test_unit_aborted( test_unit const& );
112
113    void                assertion_result( bool passed );
114    void                exception_caught( execution_exception const& );
115
116    // log configuration methods
117    void                set_stream( std::ostream& );
118    void                set_threshold_level( log_level );
119    void                set_format( output_format );
120    void                set_formatter( unit_test_log_formatter* );
121
122    // entry logging
123    unit_test_log_t&    operator<<( log::begin const& );        // begin entry
124    unit_test_log_t&    operator<<( log::end const& );          // end entry
125    unit_test_log_t&    operator<<( log::file const& );         // set entry file name
126    unit_test_log_t&    operator<<( log::line const& );         // set entry line number
127    unit_test_log_t&    operator<<( log::checkpoint const& );   // set checkpoint
128    unit_test_log_t&    operator<<( log_level );                // set entry level
129    unit_test_log_t&    operator<<( const_string );             // log entry value
130
131    ut_detail::entry_value_collector operator()( log_level );   // initiate entry collection
132
133private:
134    BOOST_TEST_SINGLETON_CONS( unit_test_log_t );
135}; // unit_test_log_t
136
137BOOST_TEST_SINGLETON_INST( unit_test_log )
138
139// helper macros
140#define BOOST_UT_LOG_ENTRY                                             \
141    (boost::unit_test::unit_test_log << boost::unit_test::log::begin() \
142        << boost::unit_test::log::file( BOOST_TEST_L( __FILE__ ) )     \
143        << boost::unit_test::log::line( __LINE__ ))                    \
144/**/
145
146} // namespace unit_test
147
148} // namespace boost
149
150//____________________________________________________________________________//
151
152#include <boost/test/detail/enable_warnings.hpp>
153
154// ***************************************************************************
155//  Revision History :
156// 
157//  $Log: unit_test_log.hpp,v $
158//  Revision 1.30  2005/02/20 08:27:06  rogeeff
159//  This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
160//
161//  Revision 1.29  2005/02/02 12:08:14  rogeeff
162//  namespace log added for log manipulators
163//
164//  Revision 1.28  2005/02/01 06:40:06  rogeeff
165//  copyright update
166//  old log entries removed
167//  minor stilistic changes
168//  depricated tools removed
169//
170//  Revision 1.27  2005/01/30 03:26:29  rogeeff
171//  return an ability for explicit end()
172//
173//  Revision 1.26  2005/01/21 07:30:24  rogeeff
174//  to log testing time log formatter interfaces changed
175//
176//  Revision 1.25  2005/01/18 08:26:12  rogeeff
177//  unit_test_log rework:
178//     eliminated need for ::instance()
179//     eliminated need for << end and ...END macro
180//     straitend interface between log and formatters
181//     change compiler like formatter name
182//     minimized unit_test_log interface and reworked to use explicit calls
183//
184// ***************************************************************************
185
186#endif // BOOST_TEST_UNIT_TEST_LOG_HPP_071894GER
187
Note: See TracBrowser for help on using the repository browser.