00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031 #define LOG4SENDPP_NEED_EXPORTS
00032 #include <log4sendpp/log4sendpp.h>
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("",
00057 0,
00058 test->getName(),
00059 LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00060 "");
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 "");
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("",
00098 0,
00099 test->getName(),
00100 LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00101 "");
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