boost_listener.cpp

Go to the documentation of this file.
00001 
00008 /**************************************************************************
00009 
00010    begin                : Sun Oct 07 2007
00011    copyright            : (C) 2007 by Ewald Arnold
00012    email                : log4sendpp at ewald-arnold dot de
00013 
00014    This program is free software; you can redistribute it and/or modify
00015    it under the terms of the GNU Lesser General Public License as
00016    published by the Free Software Foundation; either version 2 of the License,
00017    or (at your option) any later version.
00018 
00019    This program is distributed in the hope that it will be useful,
00020    but WITHOUT ANY WARRANTY; without even the implied warranty of
00021    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022    GNU General Public License for more details.
00023 
00024    You should have received a copy of the GNU Lesser General Public License
00025    along with this program; if not, write to the Free Software
00026    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027 
00028  **/
00029 
00031 #define LOG4SENDPP_NEED_EXPORTS
00032 #include <log4sendpp/log4sendpp.h> // always first
00033 
00034 #ifdef LOG4SENDPP_USE_BOOSTTEST
00035 
00036 #include <boost/test/results_collector.hpp>
00037 #include <boost/test/unit_test_suite.hpp>
00038 #include <boost/version.hpp>
00039 
00040 #include <iostream>
00041 #include <ctime>
00042 
00043 #include <log4sendpp/arguments.h>
00044 #include <log4sendpp/locationinfo.h>
00045 #include <log4sendpp/boost_listener.h>
00046 
00047 
00048 LOG4SENDPP_NS_START
00049 
00050 
00051 LOG4SENDPP_API_IMPL(void)
00052   BoostListener::log_start( LOG4SENDPP_STD_NS::ostream&,
00053                             boost::unit_test::counter_t test_cases_amount )
00054 {
00055   LOG4SENDPP_NS::LocationInformation loc("", // filename
00056                                          0, // lineno
00057                                          "",
00058                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00059                                          ""); // throwable
00060   LOG4SENDPP_STD_NS::string fmt = "unit test starting with %1 tests";
00061   LOG4SENDPP_NS::Logger::logger().log(Logger::Trace, fmt << test_cases_amount, "Boost", &loc);
00062 }
00063 
00064 
00065 LOG4SENDPP_API_IMPL(void)
00066   BoostListener::log_finish( LOG4SENDPP_STD_NS::ostream& )
00067 {
00068   LOG4SENDPP_NS::LocationInformation loc("", // filename
00069                                          0, // lineno
00070                                          "",
00071                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00072                                          ""); // throwable
00073   LOG4SENDPP_STD_NS::string fmt = "test finishing";
00074   LOG4SENDPP_NS::Logger::logger().log(Logger::Trace, fmt, "Boost", &loc);
00075 }
00076 
00077 
00078 LOG4SENDPP_API_IMPL(void)
00079   BoostListener::log_build_info( LOG4SENDPP_STD_NS::ostream& )
00080 {
00081   LOG4SENDPP_NS::LocationInformation loc("", // filename
00082                                          0, // lineno
00083                                          "",
00084                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00085                                          ""); // throwable
00086   LOG4SENDPP_STD_NS::string fmt
00087     = "Platform: %1\n"
00088       "Compiler: %2\n"
00089       "STL     : %3\n"
00090       "Boost   : %4.%5.%6\n";
00091 
00092   LOG4SENDPP_NS::Logger::logger().info(fmt << BOOST_PLATFORM
00093                                            << BOOST_COMPILER
00094                                            << BOOST_STDLIB
00095                                            << (BOOST_VERSION/100000)
00096                                            << (BOOST_VERSION/100 % 1000)
00097                                            << (BOOST_VERSION % 100),
00098                                       "Boost", &loc);
00099 }
00100 
00101 
00102 LOG4SENDPP_API_IMPL(void)
00103   BoostListener::test_unit_start( LOG4SENDPP_STD_NS::ostream&,
00104                                   boost::unit_test::test_unit const& tu )
00105 {
00106   LOG4SENDPP_NS::LocationInformation loc(tu.p_name.get(),
00107                                          0, //
00108                                          "", // boost::unit_test::framework::current_test_case().p_name.get(),
00109                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00110                                          "");
00111   std::string s = tu.p_type == boost::unit_test::tut_case ? "Start TestCase" : "Start TestSuite";
00112   LOG4SENDPP_NS::Logger::logger().trace(s, "Boost", &loc);
00113 }
00114 
00115 
00116 LOG4SENDPP_API_IMPL(void)
00117   BoostListener::test_unit_finish( LOG4SENDPP_STD_NS::ostream&,
00118                                    boost::unit_test::test_unit const& tu,
00119                                    unsigned long elapsed )
00120 {
00121   LOG4SENDPP_NS::LocationInformation loc(tu.p_name.get(),
00122                                          0, //
00123                                          "", // boost::unit_test::framework::current_test_case().p_name.get(),
00124                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00125                                          "");
00126 
00127   std::string s = tu.p_type == boost::unit_test::tut_case ? "Finish TestCase" : "Finish TestSuite";
00128   LOG4SENDPP_NS::Logger::logger().trace(s, "Boost", &loc);
00129 }
00130 
00131 
00132 LOG4SENDPP_API_IMPL(void)
00133   BoostListener::test_unit_skipped( LOG4SENDPP_STD_NS::ostream&,
00134                                     boost::unit_test::test_unit const &tu )
00135 {
00136   LOG4SENDPP_NS::LocationInformation loc(tu.p_name.get(),
00137                                          0,
00138                                          boost::unit_test::framework::current_test_case().p_name.get(),
00139                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00140                                          "");
00141 
00142   LOG4SENDPP_NS::Logger::logger().info("test skipped", "Boost", &loc);
00143 }
00144 
00145 
00146 LOG4SENDPP_API_IMPL(void)
00147   BoostListener::log_exception( LOG4SENDPP_STD_NS::ostream&,
00148                                 boost::unit_test::log_checkpoint_data const& checkpoint_data,
00149                                 boost::unit_test::const_string explanation )
00150 {
00151   LOG4SENDPP_NS::LocationInformation loc(checkpoint_data.m_file_name.begin(),
00152                                          checkpoint_data.m_line_num,
00153                                          boost::unit_test::framework::current_test_case().p_name.get(),
00154                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00155                                          "");
00156 
00157   LOG4SENDPP_STD_NS::string fmt = "%1\n%2";
00158   LOG4SENDPP_NS::Logger::logger().trace(fmt << explanation.begin()
00159                                             << checkpoint_data.m_message, "Boost", &loc);
00160 }
00161 
00162 
00163 LOG4SENDPP_API_IMPL(void)
00164   BoostListener::log_entry_start( LOG4SENDPP_STD_NS::ostream&,
00165                                   boost::unit_test::log_entry_data const& entry_data,
00166                                   log_entry_types let )
00167 {
00168   static Logger::Level levels [] =
00169   {
00170     Logger::Info,
00171     Logger::Info,
00172     Logger::Warning,
00173     Logger::Error,
00174     Logger::Fatal
00175   };
00176 
00177   entry_level = levels[let];
00178   entry_filename = entry_data.m_file_name;
00179   entry_line = entry_data.m_line_num;
00180   entry_value.clear();
00181 }
00182 
00183 
00184 LOG4SENDPP_API_IMPL(void)
00185   BoostListener::log_entry_value( LOG4SENDPP_STD_NS::ostream&,
00186                                   boost::unit_test::const_string value )
00187 {
00188   entry_value += value.begin();
00189 }
00190 
00191 
00192 LOG4SENDPP_API_IMPL(void)
00193   BoostListener::log_entry_finish( LOG4SENDPP_STD_NS::ostream& )
00194 {
00195   LOG4SENDPP_NS::LocationInformation loc(entry_filename,
00196                                          entry_line,
00197                                          boost::unit_test::framework::current_test_case().p_name.get(),
00198                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00199                                          "");
00200 
00201   LOG4SENDPP_NS::Logger::logger().log(entry_level, entry_value, "Boost", &loc);
00202 }
00203 
00204 
00206 
00207 
00208 LOG4SENDPP_API_IMPL(void) BoostReporter::results_report_start( std::ostream& ostr )
00209 {
00210 }
00211 
00212 
00213 LOG4SENDPP_API_IMPL(void) BoostReporter::results_report_finish( std::ostream& ostr )
00214 {
00215 }
00216 
00217 
00218 LOG4SENDPP_API_IMPL(void)
00219   BoostReporter::test_unit_report_start( boost::unit_test::test_unit const& tu,
00220                                          LOG4SENDPP_STD_NS::ostream& ostr )
00221 {
00222   boost::unit_test::test_results const& tr = boost::unit_test::results_collector_t::instance().results( tu.p_id );
00223 
00224   LOG4SENDPP_STD_NS::string descr;
00225 
00226   Logger::Level level = Logger::Info;
00227   if( tr.passed() )
00228       descr = "passed";
00229 
00230   else if( tr.p_skipped )
00231       descr = "skipped";
00232 
00233   else if( tr.p_aborted )
00234       descr = "aborted";
00235 
00236   else
00237   {
00238       level = Logger::Error;
00239       descr = "failed";
00240   }
00241 
00242   LOG4SENDPP_STD_NS::string msg1;
00243   typedef LOG4SENDPP_STD_NS::string ss;
00244 
00245   msg1 = ( tu.p_type == boost::unit_test::tut_case ? "TestCase" : "TestSuite" );
00246 
00247   LOG4SENDPP_STD_NS::string fmt =
00248     ": %1\n"
00249     "\n"
00250     " result: %2\n"
00251     " assertions passed: %3\n"
00252     " assertions failed: %4\n"
00253     " expected failures: %5\n";
00254    msg1 += fmt
00255       <<  tu.p_name.get()
00256       << descr
00257       << tr.p_assertions_passed
00258       << tr.p_assertions_failed
00259       << tr.p_expected_failures;
00260 
00261   LOG4SENDPP_STD_NS::string msg2;
00262 
00263   if( tu.p_type == boost::unit_test::tut_suite )
00264   {
00265     fmt =
00266       "\n"
00267       " test cases passed : %1\n"
00268       " test cases failed : %2\n"
00269       " test cases skipped: %3\n"
00270       " test cases aborted: %4\n";
00271 
00272     msg2 = fmt
00273       << tr.p_test_cases_passed
00274       << tr.p_test_cases_failed
00275       << tr.p_test_cases_skipped
00276       << tr.p_test_cases_aborted;
00277   }
00278 
00279   LOG4SENDPP_NS::Logger::logger().log(level, msg1 + msg2, "Boost", 0);
00280 }
00281 
00282 
00283 LOG4SENDPP_API_IMPL(void) BoostReporter::test_unit_report_finish( boost::unit_test::test_unit const&, LOG4SENDPP_STD_NS::ostream& ostr )
00284 {
00285 }
00286 
00287 
00288 LOG4SENDPP_API_IMPL(void) BoostReporter::do_confirmation_report( boost::unit_test::test_unit const& tu, std::ostream& ostr )
00289 {
00290     test_unit_report_start( tu, ostr );
00291     test_unit_report_finish( tu, ostr );
00292 }
00293 
00294 
00295 LOG4SENDPP_NS_END
00296 
00297 
00298 #endif // LOG4SENDPP_USE_BOOST
00299 

Generated on Sat Nov 24 14:41:22 2007 for log4sendpp by  doxygen 1.5.3