Back to index

nordugrid-arc-nox  1.1.0~rc6
LoggerTest.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #include <sstream>
00004 
00005 #include <cppunit/extensions/HelperMacros.h>
00006 
00007 #include <arc/Logger.h>
00008 
00009 class LoggerTest
00010   : public CppUnit::TestFixture {
00011 
00012   CPPUNIT_TEST_SUITE(LoggerTest);
00013   CPPUNIT_TEST(TestLoggerINFO);
00014   CPPUNIT_TEST(TestLoggerVERBOSE);
00015   CPPUNIT_TEST_SUITE_END();
00016 
00017 public:
00018   void setUp();
00019   void tearDown();
00020 
00021   void TestLoggerINFO();
00022   void TestLoggerVERBOSE();
00023 
00024 private:
00025   std::stringstream stream;
00026   Arc::LogStream *output;
00027   Arc::Logger *logger;
00028 };
00029 
00030 
00031 void LoggerTest::setUp() {
00032   output = new Arc::LogStream(stream);
00033   Arc::Logger::getRootLogger().addDestination(*output);
00034   logger = new Arc::Logger(Arc::Logger::getRootLogger(), "TestLogger", Arc::INFO);
00035 }
00036 
00037 void LoggerTest::tearDown() {
00038   Arc::Logger::getRootLogger().removeDestinations();
00039   delete logger;
00040   delete output;
00041 }
00042 
00043 void LoggerTest::TestLoggerINFO() {
00044   std::string res;
00045   logger->msg(Arc::VERBOSE, "This VERBOSE message should not be seen");
00046   res = stream.str();
00047   CPPUNIT_ASSERT(res.empty());
00048 
00049   logger->msg(Arc::INFO, "This INFO message should be seen");
00050   res = stream.str();
00051   res = res.substr(res.rfind(']') + 2);
00052   CPPUNIT_ASSERT_EQUAL(res, std::string("This INFO message should be seen\n"));
00053   stream.str("");
00054 }
00055 
00056 
00057 void LoggerTest::TestLoggerVERBOSE() {
00058   std::string res;
00059   logger->setThreshold(Arc::VERBOSE);
00060   logger->msg(Arc::VERBOSE, "This VERBOSE message should now be seen");
00061   res = stream.str();
00062   res = res.substr(res.rfind(']') + 2);
00063   CPPUNIT_ASSERT_EQUAL(res, std::string("This VERBOSE message should now be seen\n"));
00064   stream.str("");
00065 
00066   logger->msg(Arc::INFO, "This INFO message should also be seen");
00067   res = stream.str();
00068   res = res.substr(res.rfind(']') + 2);
00069   CPPUNIT_ASSERT_EQUAL(res, std::string("This INFO message should also be seen\n"));
00070   stream.str("");
00071 }
00072 
00073 
00074 CPPUNIT_TEST_SUITE_REGISTRATION(LoggerTest);