cppunit_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_CPPUNIT
00035 
00036 #include <ctime>
00037 
00038 #include <cppunit/extensions/TestFactoryRegistry.h>
00039 #include <cppunit/ui/text/TestRunner.h>
00040 #include <cppunit/extensions/HelperMacros.h>
00041 #include <cppunit/TestResult.h>
00042 #include <cppunit/TestFailure.h>
00043 
00044 #include <log4sendpp/logger.h>
00045 #include <log4sendpp/arguments.h>
00046 #include <log4sendpp/locationinfo.h>
00047 #include <log4sendpp/cppunit_listener.h>
00048 
00049 
00050 LOG4SENDPP_NS_START
00051 
00052 
00053 LOG4SENDPP_API_IMPL(void) CppUnitListener::startTest( CppUnit::Test *test )
00054 {
00055   starttime = LOG4SENDPP_STD_NS::time(0);
00056   LOG4SENDPP_NS::LocationInformation loc("", // filename
00057                                          0, // lineno
00058                                          test->getName(),
00059                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00060                                          ""); // throwable
00061 
00062   LOG4SENDPP_NS::Logger::logger().log(Logger::Trace, "test starting", "CppUnit", &loc);
00063 }
00064 
00065 
00066 LOG4SENDPP_API_IMPL(void) CppUnitListener::addFailure( const CppUnit::TestFailure &failure )
00067 {
00068   LOG4SENDPP_NS::LocationInformation loc(failure. sourceLine().fileName(),
00069                                          failure. sourceLine().lineNumber(),
00070                                          failure.failedTestName(),
00071                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00072                                          ""); // throwable
00073 
00074   LOG4SENDPP_STD_NS::string msg;
00075   if (failure.isError())
00076     msg = "Error: %1";
00077   else
00078     msg = "Failure: %1";
00079 
00080   CppUnit::Message message = failure.thrownException()->message();
00081   msg << message.shortDescription();
00082   if (message.detailCount())
00083     msg += "\n" + message.details();
00084 
00085   LOG4SENDPP_NS::Logger::logger().log(Logger::Error, msg, "CppUnit", &loc);
00086 }
00087 
00088 
00089 LOG4SENDPP_API_IMPL(void) CppUnitListener::endTest(CppUnit::Test *test)
00090 {
00091   LOG4SENDPP_STD_NS::time_t endtime = LOG4SENDPP_STD_NS::time(0);
00092   LOG4SENDPP_STD_NS::time_t difftime = starttime - endtime;
00093   unsigned mi = difftime / 60;
00094   unsigned sec = difftime % 60;
00095   LOG4SENDPP_STD_NS::string fmt = "test ending after %1:%2";
00096 
00097   LOG4SENDPP_NS::LocationInformation loc("", // filename
00098                                          0, // lineno
00099                                          test->getName(),
00100                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00101                                          ""); // throwable
00102 
00103   LOG4SENDPP_NS::Logger::logger().log(Logger::Trace,
00104                                       fmt << mi << sec,
00105                                       "CppUnit",
00106                                       &loc);
00107 }
00108 
00109 
00110 LOG4SENDPP_NS_END
00111 
00112 
00113 #endif // LOG4SENDPP_USE_CPPUNIT
00114 
00115 

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