diff options
Diffstat (limited to 'icetray/unittests/testIceTrayLogger.cpp')
-rw-r--r-- | icetray/unittests/testIceTrayLogger.cpp | 128 |
1 files changed, 67 insertions, 61 deletions
diff --git a/icetray/unittests/testIceTrayLogger.cpp b/icetray/unittests/testIceTrayLogger.cpp index 68e8ccc..393a6f2 100644 --- a/icetray/unittests/testIceTrayLogger.cpp +++ b/icetray/unittests/testIceTrayLogger.cpp @@ -10,6 +10,7 @@ #include <boost/format.hpp> #include <slicer/common.h> #include <logWriterConsole.h> +#include <slicer/modelPartsTypes.h> #include "testService.h" using namespace IceTray::Logging; @@ -28,12 +29,12 @@ class TestLogWriter : public AbstractLogWriter { { } - TestLogWriter(Ice::Properties * p) : + TestLogWriter(const Ice::PropertiesPtr & p) : AbstractLogWriter("TestLogWriter", p) { } - void message(LogLevel priority, const Domain & domain, const std::string & message, const Ice::Current &) override + void message(LogLevel priority, Domain domain, std::string message, const Ice::Current &) override { msgs.push_back({priority, domain, message}); } @@ -50,6 +51,11 @@ namespace std { } return s; } + ostream & + operator<<(ostream & s, const LogLevel & ll) { + s << Slicer::ModelPartForEnum<LogLevel>::lookup(ll); + return s; + } } class StaticLogTest { @@ -87,9 +93,9 @@ class TestLogImpl { ic->destroy(); } - LogWriterPrx add(LogWriter * w) + LogWriterPrxPtr add(const LogWriterPtr & w) { - return LogWriterPrx::uncheckedCast(adp->addWithUUID(w)); + return Ice::uncheckedCast<LogWriterPrx>(adp->addWithUUID(w)); } protected: @@ -104,8 +110,8 @@ class TestLogImpl { BOOST_FIXTURE_TEST_SUITE(li, TestLogImpl); BOOST_AUTO_TEST_CASE(no_writers) { - log->message(EMERG, ""); - log->message(DEBUG, ""); + log->message(LogLevel::EMERG, ""); + log->message(LogLevel::DEBUG, ""); } BOOST_AUTO_TEST_CASE(ostreamDomain) { @@ -115,8 +121,8 @@ BOOST_AUTO_TEST_CASE(ostreamDomain) { } BOOST_AUTO_TEST_CASE(priority_filtering) { - auto w = new TestLogWriter(WARNING); - auto e = new TestLogWriter(ERR); + auto w = std::make_shared<TestLogWriter>(LogLevel::WARNING); + auto e = std::make_shared<TestLogWriter>(LogLevel::ERR); auto wp = add(w); auto ep = add(e); manager.addWriter(wp); @@ -124,58 +130,58 @@ BOOST_AUTO_TEST_CASE(priority_filtering) { BOOST_REQUIRE(w->msgs.empty()); BOOST_REQUIRE(e->msgs.empty()); - log->message(DEBUG, "debug"); + log->message(LogLevel::DEBUG, "debug"); BOOST_REQUIRE(w->msgs.empty()); BOOST_REQUIRE(e->msgs.empty()); - log->message(INFO, "into"); + log->message(LogLevel::INFO, "info"); BOOST_REQUIRE(w->msgs.empty()); BOOST_REQUIRE(e->msgs.empty()); - log->message(NOTICE, "notice"); + log->message(LogLevel::NOTICE, "notice"); BOOST_REQUIRE(w->msgs.empty()); BOOST_REQUIRE(e->msgs.empty()); - log->message(WARNING, "warning"); + log->message(LogLevel::WARNING, "warning"); BOOST_REQUIRE_EQUAL(1, w->msgs.size()); BOOST_REQUIRE(e->msgs.empty()); - log->message(ERR, "err"); + log->message(LogLevel::ERR, "err"); BOOST_REQUIRE_EQUAL(2, w->msgs.size()); BOOST_REQUIRE_EQUAL(1, e->msgs.size()); - log->message(CRIT, "crit"); + log->message(LogLevel::CRIT, "crit"); BOOST_REQUIRE_EQUAL(3, w->msgs.size()); BOOST_REQUIRE_EQUAL(2, e->msgs.size()); - log->message(ALERT, "alert"); + log->message(LogLevel::ALERT, "alert"); BOOST_REQUIRE_EQUAL(4, w->msgs.size()); BOOST_REQUIRE_EQUAL(3, e->msgs.size()); - log->message(EMERG, "emerg"); + log->message(LogLevel::EMERG, "emerg"); BOOST_REQUIRE_EQUAL(5, w->msgs.size()); BOOST_REQUIRE_EQUAL(4, e->msgs.size()); manager.removeWriter(wp); - log->message(ERR, "err2"); + log->message(LogLevel::ERR, "err2"); BOOST_REQUIRE_EQUAL(5, w->msgs.size()); BOOST_REQUIRE_EQUAL(5, e->msgs.size()); } BOOST_AUTO_TEST_CASE( no_domains ) { - auto d = new TestLogWriter(); + auto d = std::make_shared<TestLogWriter>(); manager.addWriter(add(d)); - log->message(DEBUG, "debug message."); - log->message(EMERG, "emergency message."); + log->message(LogLevel::DEBUG, "debug message."); + log->message(LogLevel::EMERG, "emergency message."); BOOST_REQUIRE(d->msgs.empty()); } BOOST_AUTO_TEST_CASE(formatter_plain) { - auto d = new TestLogWriter(DEBUG); + auto d = std::make_shared<TestLogWriter>(LogLevel::DEBUG); manager.addWriter(add(d)); - log->message(DEBUG, "plain message."); + log->message(LogLevel::DEBUG, "plain message."); BOOST_REQUIRE_EQUAL(1, d->msgs.size()); BOOST_REQUIRE_EQUAL("plain message.", d->msgs.front().message); BOOST_REQUIRE_EQUAL(testDomain, d->msgs.front().domain); @@ -183,9 +189,9 @@ BOOST_AUTO_TEST_CASE(formatter_plain) BOOST_AUTO_TEST_CASE(formatter_libc) { - auto d = new TestLogWriter(DEBUG); + auto d = std::make_shared<TestLogWriter>(LogLevel::DEBUG); manager.addWriter(add(d)); - log->messagef(DEBUG, "plain %s.", "message"); + log->messagef(LogLevel::DEBUG, "plain %s.", "message"); BOOST_REQUIRE_EQUAL(1, d->msgs.size()); BOOST_REQUIRE_EQUAL("plain message.", d->msgs.front().message); BOOST_REQUIRE_EQUAL(testDomain, d->msgs.front().domain); @@ -193,9 +199,9 @@ BOOST_AUTO_TEST_CASE(formatter_libc) BOOST_AUTO_TEST_CASE(formatter_boost_format) { - auto d = new TestLogWriter(DEBUG); + auto d = std::make_shared<TestLogWriter>(LogLevel::DEBUG); manager.addWriter(add(d)); - log->messagebf(DEBUG, "plain %s", std::string("message")); + log->messagebf(LogLevel::DEBUG, "plain %s", std::string("message")); BOOST_REQUIRE_EQUAL(1, d->msgs.size()); BOOST_REQUIRE_EQUAL("plain message", d->msgs.front().message); BOOST_REQUIRE_EQUAL(testDomain, d->msgs.front().domain); @@ -204,9 +210,9 @@ BOOST_AUTO_TEST_CASE(formatter_boost_format) AdHocFormatter(Plain, "plain %?."); BOOST_AUTO_TEST_CASE(formatter_adhoc_compiletime) { - auto d = new TestLogWriter(DEBUG); + auto d = std::make_shared<TestLogWriter>(LogLevel::DEBUG); manager.addWriter(add(d)); - log->messagectf<Plain>(DEBUG, "message"); + log->messagectf<Plain>(LogLevel::DEBUG, "message"); BOOST_REQUIRE_EQUAL(1, d->msgs.size()); BOOST_REQUIRE_EQUAL("plain message.", d->msgs.front().message); BOOST_REQUIRE_EQUAL(testDomain, d->msgs.front().domain); @@ -215,7 +221,7 @@ BOOST_AUTO_TEST_CASE(formatter_adhoc_compiletime) BOOST_AUTO_TEST_CASE( domains_none ) { // No domains - auto l = add(new TestLogWriter()); + auto l = add(std::make_shared<TestLogWriter>()); BOOST_REQUIRE(!l->level(test)); BOOST_REQUIRE(!l->level(testDomain)); BOOST_REQUIRE(!l->lowestLevel()); @@ -224,21 +230,21 @@ BOOST_AUTO_TEST_CASE( domains_none ) BOOST_AUTO_TEST_CASE( domains_single ) { // A single catch-all domain at the given level - auto l = add(new TestLogWriter(ERR)); - BOOST_REQUIRE_EQUAL(ERR, *l->level(test)); - BOOST_REQUIRE_EQUAL(ERR, *l->level(testDomain)); + auto l = add(std::make_shared<TestLogWriter>(LogLevel::ERR)); + BOOST_REQUIRE_EQUAL(LogLevel::ERR, *l->level(test)); + BOOST_REQUIRE_EQUAL(LogLevel::ERR, *l->level(testDomain)); BOOST_REQUIRE(l->lowestLevel()); - BOOST_REQUIRE_EQUAL(ERR, *l->lowestLevel()); + BOOST_REQUIRE_EQUAL(LogLevel::ERR, *l->lowestLevel()); } BOOST_AUTO_TEST_CASE( domains_fromNullProperties ) { // A single catch-all domain at the default level (WARNING) - auto l = add(new TestLogWriter("", Ice::PropertiesPtr())); - BOOST_REQUIRE_EQUAL(WARNING, *l->level(test)); - BOOST_REQUIRE_EQUAL(WARNING, *l->level(testDomain)); + auto l = add(std::make_shared<TestLogWriter>("", Ice::PropertiesPtr())); + BOOST_REQUIRE_EQUAL(LogLevel::WARNING, *l->level(test)); + BOOST_REQUIRE_EQUAL(LogLevel::WARNING, *l->level(testDomain)); BOOST_REQUIRE(l->lowestLevel()); - BOOST_REQUIRE_EQUAL(WARNING, *l->lowestLevel()); + BOOST_REQUIRE_EQUAL(LogLevel::WARNING, *l->lowestLevel()); } BOOST_AUTO_TEST_CASE( domains_fromProperties ) @@ -249,13 +255,13 @@ BOOST_AUTO_TEST_CASE( domains_fromProperties ) p->setProperty("TestLogWriter.domains.test.debug", "DEBUG"); p->setProperty("TestLogWriter.domains", "ignored"); p->setProperty("TestLogWriter.default", "WARNING"); - auto l = add(new TestLogWriter("TestLogWriter", p)); - BOOST_REQUIRE_EQUAL(WARNING, *l->level(test)); - BOOST_REQUIRE_EQUAL(WARNING, *l->level(other)); - BOOST_REQUIRE_EQUAL(EMERG, *l->level(testDomain)); - BOOST_REQUIRE_EQUAL(DEBUG, *l->level(testDebug)); + auto l = add(std::make_shared<TestLogWriter>("TestLogWriter", p)); + BOOST_REQUIRE_EQUAL(LogLevel::WARNING, *l->level(test)); + BOOST_REQUIRE_EQUAL(LogLevel::WARNING, *l->level(other)); + BOOST_REQUIRE_EQUAL(LogLevel::EMERG, *l->level(testDomain)); + BOOST_REQUIRE_EQUAL(LogLevel::DEBUG, *l->level(testDebug)); BOOST_REQUIRE(l->lowestLevel()); - BOOST_REQUIRE_EQUAL(DEBUG, *l->lowestLevel()); + BOOST_REQUIRE_EQUAL(LogLevel::DEBUG, *l->lowestLevel()); } BOOST_AUTO_TEST_CASE( domains_fromProperties_noDefault ) @@ -264,11 +270,11 @@ BOOST_AUTO_TEST_CASE( domains_fromProperties_noDefault ) Ice::PropertiesPtr p = ic->getProperties(); p->setProperty("TestLogWriter.domains.test.domain", "EMERG"); p->setProperty("TestLogWriter.domains.test.debug", "DEBUG"); - auto l = add(new TestLogWriter("TestLogWriter", p)); - BOOST_REQUIRE_EQUAL(EMERG, *l->level(testDomain)); - BOOST_REQUIRE_EQUAL(DEBUG, *l->level(testDebug)); + auto l = add(std::make_shared<TestLogWriter>("TestLogWriter", p)); + BOOST_REQUIRE_EQUAL(LogLevel::EMERG, *l->level(testDomain)); + BOOST_REQUIRE_EQUAL(LogLevel::DEBUG, *l->level(testDebug)); BOOST_REQUIRE(l->lowestLevel()); - BOOST_REQUIRE_EQUAL(DEBUG, *l->lowestLevel()); + BOOST_REQUIRE_EQUAL(LogLevel::DEBUG, *l->lowestLevel()); } BOOST_AUTO_TEST_CASE( domains_fromProperties_onlyDefault ) @@ -276,13 +282,13 @@ BOOST_AUTO_TEST_CASE( domains_fromProperties_onlyDefault ) // Domains configured according to properties Ice::PropertiesPtr p = ic->getProperties(); p->setProperty("TestLogWriter.default", "INFO"); - auto l = add(new TestLogWriter("TestLogWriter", p)); - BOOST_REQUIRE_EQUAL(INFO, *l->level(test)); - BOOST_REQUIRE_EQUAL(INFO, *l->level(other)); - BOOST_REQUIRE_EQUAL(INFO, *l->level(testDomain)); - BOOST_REQUIRE_EQUAL(INFO, *l->level(testDebug)); + auto l = add(std::make_shared<TestLogWriter>("TestLogWriter", p)); + BOOST_REQUIRE_EQUAL(LogLevel::INFO, *l->level(test)); + BOOST_REQUIRE_EQUAL(LogLevel::INFO, *l->level(other)); + BOOST_REQUIRE_EQUAL(LogLevel::INFO, *l->level(testDomain)); + BOOST_REQUIRE_EQUAL(LogLevel::INFO, *l->level(testDebug)); BOOST_REQUIRE(l->lowestLevel()); - BOOST_REQUIRE_EQUAL(INFO, *l->lowestLevel()); + BOOST_REQUIRE_EQUAL(LogLevel::INFO, *l->lowestLevel()); } BOOST_AUTO_TEST_CASE( domains_fromProperties_badLevel ) @@ -325,55 +331,55 @@ BOOST_AUTO_TEST_CASE( console ) { IceTray::Logging::LogWriterPtr lwp = IceTray::Logging::LogWriterFactory::createNew("ConsoleLogWriter", NULL); - lwp->message(DEBUG, testDomain, "some message"); + lwp->message(LogLevel::DEBUG, testDomain, "some message", {}); } BOOST_AUTO_TEST_CASE( consoleNoWidth ) { std::stringstream str; - ConsoleLogWriter::writeStream(str, -1, DEBUG, testDomain, "message"); + ConsoleLogWriter::writeStream(str, -1, LogLevel::DEBUG, testDomain, "message"); BOOST_REQUIRE_EQUAL("DEBUG: test.domain: message\n", str.str()); } BOOST_AUTO_TEST_CASE( consoleWidthJustRight ) { std::stringstream str; - ConsoleLogWriter::writeStream(str, 11, DEBUG, testDomain, "message"); + ConsoleLogWriter::writeStream(str, 11, LogLevel::DEBUG, testDomain, "message"); BOOST_REQUIRE_EQUAL("DEBUG: test.domain: message\n", str.str()); } BOOST_AUTO_TEST_CASE( consoleWidthSmall ) { std::stringstream str; - ConsoleLogWriter::writeStream(str, 10, DEBUG, testDomain, "message"); + ConsoleLogWriter::writeStream(str, 10, LogLevel::DEBUG, testDomain, "message"); BOOST_REQUIRE_EQUAL("DEBUG: t.domain: message\n", str.str()); } BOOST_AUTO_TEST_CASE( consoleWidthTiny ) { std::stringstream str; - ConsoleLogWriter::writeStream(str, 8, DEBUG, testDomain, "message"); + ConsoleLogWriter::writeStream(str, 8, LogLevel::DEBUG, testDomain, "message"); BOOST_REQUIRE_EQUAL("DEBUG: t.domain: message\n", str.str()); } BOOST_AUTO_TEST_CASE( consoleWidthTooTiny ) { std::stringstream str; - ConsoleLogWriter::writeStream(str, 7, DEBUG, testDomain, "message"); + ConsoleLogWriter::writeStream(str, 7, LogLevel::DEBUG, testDomain, "message"); BOOST_REQUIRE_EQUAL("DEBUG: t.d: message\n", str.str()); } BOOST_AUTO_TEST_CASE( consoleWidthOverflow ) { std::stringstream str; - ConsoleLogWriter::writeStream(str, 1, DEBUG, testDomain, "message"); + ConsoleLogWriter::writeStream(str, 1, LogLevel::DEBUG, testDomain, "message"); BOOST_REQUIRE_EQUAL("DEBUG: t.d: message\n", str.str()); } BOOST_AUTO_TEST_CASE( consoleNoDomain ) { std::stringstream str; - ConsoleLogWriter::writeStream(str, 0, DEBUG, {}, "message"); + ConsoleLogWriter::writeStream(str, 0, LogLevel::DEBUG, {}, "message"); BOOST_REQUIRE_EQUAL("DEBUG: : message\n", str.str()); } |