source: NonGTP/Boost/boost/test/impl/xml_log_formatter.ipp @ 857

Revision 857, 5.9 KB checked in by igarcia, 19 years ago (diff)
Line 
1//  (C) Copyright Gennadiy Rozental 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: xml_log_formatter.ipp,v $
9//
10//  Version     : $Revision: 1.4 $
11//
12//  Description : implements XML Log formatter
13// ***************************************************************************
14
15#ifndef BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER
16#define BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER
17
18// Boost.Test
19#include <boost/test/output/xml_log_formatter.hpp>
20#include <boost/test/unit_test_suite.hpp>
21#include <boost/test/framework.hpp>
22#include <boost/test/utils/basic_cstring/io.hpp>
23
24#include <boost/test/utils/xml_printer.hpp>
25
26// Boost
27#include <boost/version.hpp>
28
29// STL
30#include <iostream>
31
32#include <boost/test/detail/suppress_warnings.hpp>
33
34//____________________________________________________________________________//
35
36namespace boost {
37
38namespace unit_test {
39
40namespace output {
41
42static const_string tu_type_name( test_unit const& tu )
43{
44    return tu.p_type == tut_case ? "TestCase" : "TestSuite";
45}
46
47// ************************************************************************** //
48// **************               xml_log_formatter              ************** //
49// ************************************************************************** //
50
51void
52xml_log_formatter::log_start( std::ostream& ostr, counter_t )
53{
54    ostr  << "<TestLog>";
55}
56
57//____________________________________________________________________________//
58
59void
60xml_log_formatter::log_finish( std::ostream& ostr )
61{
62    ostr  << "</TestLog>";
63}
64
65//____________________________________________________________________________//
66
67void
68xml_log_formatter::log_build_info( std::ostream& ostr )
69{
70    ostr  << "<BuildInfo"
71            << " platform"  << attr_value() << BOOST_PLATFORM
72            << " compiler"  << attr_value() << BOOST_COMPILER
73            << " stl"       << attr_value() << BOOST_STDLIB
74            << " boost=\""  << BOOST_VERSION/100000     << "."
75                            << BOOST_VERSION/100 % 1000 << "."
76                            << BOOST_VERSION % 100      << '\"'
77            << "/>";
78}
79
80//____________________________________________________________________________//
81
82void
83xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu )
84{
85    ostr << "<" << tu_type_name( tu ) << " name" << attr_value() << tu.p_name.get() << ">";
86}
87
88//____________________________________________________________________________//
89
90void
91xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed )
92{
93    if( tu.p_type == tut_case )
94        ostr << "<TestingTime>" << elapsed << "</TestingTime>";
95       
96    ostr << "</" << tu_type_name( tu ) << ">";
97}
98
99//____________________________________________________________________________//
100
101void
102xml_log_formatter::test_unit_skipped( std::ostream& ostr, test_unit const& tu )
103{
104    ostr << "<" << tu_type_name( tu )
105         << " name"    << attr_value() << tu.p_name.get()
106         << " skipped" << attr_value() << "yes"
107         << "/>";
108}
109   
110//____________________________________________________________________________//
111
112void
113xml_log_formatter::log_exception( std::ostream& ostr, log_checkpoint_data const& checkpoint_data, const_string explanation )
114{
115    ostr << "<Exception name" << attr_value() << framework::current_test_case().p_name.get() << ">"
116           << pcdata() << explanation;
117
118    if( !checkpoint_data.m_message.empty() ) {
119        ostr << "<LastCheckpoint file" << attr_value() << checkpoint_data.m_file
120             << " line"                << attr_value() << checkpoint_data.m_line
121             << ">"
122             << pcdata() << checkpoint_data.m_message
123             << "</LastCheckpoint>";
124    }
125
126    ostr << "</Exception>";
127}
128
129//____________________________________________________________________________//
130
131void
132xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& entry_data, log_entry_types let )
133{
134    static literal_string xml_tags[] = { "Info", "Message", "Warning", "Error", "FatalError" };
135
136    m_curr_tag = xml_tags[let];
137    ostr << '<' << m_curr_tag
138         << " file" << attr_value() << entry_data.m_file
139         << " line" << attr_value() << entry_data.m_line
140         << ">";
141}
142
143//____________________________________________________________________________//
144
145void
146xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value )
147{
148    ostr << pcdata() << value;
149}
150
151//____________________________________________________________________________//
152
153void
154xml_log_formatter::log_entry_finish( std::ostream& ostr )
155{
156    ostr << "</" << m_curr_tag << ">";
157
158    m_curr_tag.clear();
159}
160
161//____________________________________________________________________________//
162
163} // namespace output
164
165} // namespace unit_test
166
167} // namespace boost
168
169//____________________________________________________________________________//
170
171#include <boost/test/detail/enable_warnings.hpp>
172
173// ***************************************************************************
174//  Revision History :
175//
176//  $Log: xml_log_formatter.ipp,v $
177//  Revision 1.4  2005/04/30 16:47:14  rogeeff
178//  warning supressed
179//
180//  Revision 1.3  2005/04/29 06:29:35  rogeeff
181//  bug fix for incorect XML output
182//
183//  Revision 1.2  2005/02/20 08:27:07  rogeeff
184//  This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
185//
186//  Revision 1.1  2005/02/01 08:59:38  rogeeff
187//  supplied_log_formatters split
188//  change formatters interface to simplify result interface
189//
190// ***************************************************************************
191
192#endif // BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER
Note: See TracBrowser for help on using the repository browser.