Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // (C) Copyright Gennadiy Rozental 2005-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 : implements XML Log formatter |
| 13 | // *************************************************************************** |
| 14 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 15 | #ifndef NDNBOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER |
| 16 | #define NDNBOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 17 | |
| 18 | // Boost.Test |
| 19 | #include <ndnboost/test/output/xml_log_formatter.hpp> |
| 20 | #include <ndnboost/test/unit_test_suite_impl.hpp> |
| 21 | #include <ndnboost/test/framework.hpp> |
| 22 | #include <ndnboost/test/utils/basic_cstring/io.hpp> |
| 23 | |
| 24 | #include <ndnboost/test/utils/xml_printer.hpp> |
| 25 | |
| 26 | // Boost |
| 27 | #include <ndnboost/version.hpp> |
| 28 | |
| 29 | // STL |
| 30 | #include <iostream> |
| 31 | |
| 32 | #include <ndnboost/test/detail/suppress_warnings.hpp> |
| 33 | |
| 34 | //____________________________________________________________________________// |
| 35 | |
| 36 | namespace ndnboost { |
| 37 | |
| 38 | namespace unit_test { |
| 39 | |
| 40 | namespace output { |
| 41 | |
| 42 | static 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 | |
| 51 | void |
| 52 | xml_log_formatter::log_start( std::ostream& ostr, counter_t ) |
| 53 | { |
| 54 | ostr << "<TestLog>"; |
| 55 | } |
| 56 | |
| 57 | //____________________________________________________________________________// |
| 58 | |
| 59 | void |
| 60 | xml_log_formatter::log_finish( std::ostream& ostr ) |
| 61 | { |
| 62 | ostr << "</TestLog>"; |
| 63 | } |
| 64 | |
| 65 | //____________________________________________________________________________// |
| 66 | |
| 67 | void |
| 68 | xml_log_formatter::log_build_info( std::ostream& ostr ) |
| 69 | { |
| 70 | ostr << "<BuildInfo" |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 71 | << " platform" << attr_value() << NDNBOOST_PLATFORM |
| 72 | << " compiler" << attr_value() << NDNBOOST_COMPILER |
| 73 | << " stl" << attr_value() << NDNBOOST_STDLIB |
| 74 | << " boost=\"" << NDNBOOST_VERSION/100000 << "." |
| 75 | << NDNBOOST_VERSION/100 % 1000 << "." |
| 76 | << NDNBOOST_VERSION % 100 << '\"' |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 77 | << "/>"; |
| 78 | } |
| 79 | |
| 80 | //____________________________________________________________________________// |
| 81 | |
| 82 | void |
| 83 | xml_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 | |
| 90 | void |
| 91 | xml_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 | |
| 101 | void |
| 102 | xml_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 | |
| 112 | void |
| 113 | xml_log_formatter::log_exception( std::ostream& ostr, log_checkpoint_data const& checkpoint_data, execution_exception const& ex ) |
| 114 | { |
| 115 | execution_exception::location const& loc = ex.where(); |
| 116 | |
| 117 | ostr << "<Exception file" << attr_value() << loc.m_file_name |
| 118 | << " line" << attr_value() << loc.m_line_num; |
| 119 | |
| 120 | if( !loc.m_function.is_empty() ) |
| 121 | ostr << " function" << attr_value() << loc.m_function; |
| 122 | |
| 123 | ostr << ">" << cdata() << ex.what(); |
| 124 | |
| 125 | if( !checkpoint_data.m_file_name.is_empty() ) { |
| 126 | ostr << "<LastCheckpoint file" << attr_value() << checkpoint_data.m_file_name |
| 127 | << " line" << attr_value() << checkpoint_data.m_line_num |
| 128 | << ">" |
| 129 | << cdata() << checkpoint_data.m_message |
| 130 | << "</LastCheckpoint>"; |
| 131 | } |
| 132 | |
| 133 | ostr << "</Exception>"; |
| 134 | } |
| 135 | |
| 136 | //____________________________________________________________________________// |
| 137 | |
| 138 | void |
| 139 | xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& entry_data, log_entry_types let ) |
| 140 | { |
| 141 | static literal_string xml_tags[] = { "Info", "Message", "Warning", "Error", "FatalError" }; |
| 142 | |
| 143 | m_curr_tag = xml_tags[let]; |
| 144 | ostr << '<' << m_curr_tag |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 145 | << NDNBOOST_TEST_L( " file" ) << attr_value() << entry_data.m_file_name |
| 146 | << NDNBOOST_TEST_L( " line" ) << attr_value() << entry_data.m_line_num |
| 147 | << NDNBOOST_TEST_L( "><![CDATA[" ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | //____________________________________________________________________________// |
| 151 | |
| 152 | void |
| 153 | xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value ) |
| 154 | { |
| 155 | ostr << value; |
| 156 | } |
| 157 | |
| 158 | //____________________________________________________________________________// |
| 159 | |
| 160 | void |
| 161 | xml_log_formatter::log_entry_finish( std::ostream& ostr ) |
| 162 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 163 | ostr << NDNBOOST_TEST_L( "]]></" ) << m_curr_tag << NDNBOOST_TEST_L( ">" ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 164 | |
| 165 | m_curr_tag.clear(); |
| 166 | } |
| 167 | |
| 168 | //____________________________________________________________________________// |
| 169 | |
| 170 | } // namespace output |
| 171 | |
| 172 | } // namespace unit_test |
| 173 | |
| 174 | } // namespace ndnboost |
| 175 | |
| 176 | //____________________________________________________________________________// |
| 177 | |
| 178 | #include <ndnboost/test/detail/enable_warnings.hpp> |
| 179 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 180 | #endif // NDNBOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER |