X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FLog.test.cc;h=b4a1cbdc9829edbfcad5e71953f6cc7e0ca7f145;hb=394a298567543441521439ad15f7016cd569c449;hp=cc31c61e4cee7fb88c0a318738af172022732626;hpb=9ff976ea47b175355a1f7ef4d05f14edb98a82e4;p=senf.git diff --git a/Utils/Logger/Log.test.cc b/Utils/Logger/Log.test.cc index cc31c61..b4a1cbd 100644 --- a/Utils/Logger/Log.test.cc +++ b/Utils/Logger/Log.test.cc @@ -26,35 +26,27 @@ //#include "Log.test.hh" //#include "Log.test.ih" -// Custom includes -#include - // We need to put all tests into this single file to not violate the ODR -#define _senf_LOG_STREAM logstream -namespace { - std::stringstream logstream; -} - #define SENF_LOG_CONF (( (senf)(log)(Debug), (_), NOTICE )) -#include "Log.hh" -#include "Defaults.hh" -#include "Parameters.hh" -#include "Levels.hh" - +// Custom includes +#include "Logger.hh" #include #include #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -namespace { +namespace not_anonymous { - template struct Foo { - typedef int value; + SENF_LOG_CLASS_AREA(); + + static void log() { + SENF_LOG(("Foo::log")); + } }; SENF_LOG_DEF_ALIAS( LogCritical, (senf::log::Debug) (senf::log::CRITICAL) ); @@ -62,34 +54,55 @@ namespace { SENF_LOG_DEF_AREA( myArea ); } +using namespace not_anonymous; BOOST_AUTO_UNIT_TEST(logger) { + senf::log::StringTarget target; + + target.route(); + + // We cannot easily check the exact log string since that includes the current date/time + SENF_LOG_DEFAULT_STREAM(senf::log::Debug); SENF_LOG_DEFAULT_AREA(senf::log::DefaultArea); SENF_LOG_DEFAULT_LEVEL(senf::log::VERBOSE); - // should be disabled SENF_LOG(("Log message")); + BOOST_CHECK( target.str().empty() ); + target.clear(); + SENF_LOG((senf::log::VERBOSE)("Log message 2")); - // should be enabled + BOOST_CHECK( target.str().empty() ); + target.clear(); + SENF_LOG((senf::log::IMPORTANT)("Important message")); + BOOST_CHECK( ! target.str().empty() ); + target.clear(); + SENF_LOG((LogCritical) ("Another log message: " << 10)); + BOOST_CHECK( ! target.str().empty() ); + target.clear(); SENF_LOG_BLOCK((senf::log::Debug) (senf::log::IMPORTANT) ({ log << "Last message"; log << " continued here"; })); + BOOST_CHECK( ! target.str().empty() ); + target.clear(); + + Foo::log(); + BOOST_CHECK( ! target.str().empty() ); + target.clear(); - BOOST_CHECK_EQUAL( logstream.str(), - "Important message\n" - "Another log message: 10\n" - "Last message continued here\n" ); + SENF_LOG((Foo)("Foo area")); + BOOST_CHECK( target.str().empty() ); + target.clear(); } BOOST_AUTO_UNIT_TEST(streamRegistry) { - char const * streams[] = { "(anonymous namespace)::myStream", "senf::log::Debug" }; + char const * streams[] = { "not_anonymous::myStream", "senf::log::Debug" }; BOOST_CHECK_EQUAL_COLLECTIONS( senf::log::StreamRegistry::instance().begin(), senf::log::StreamRegistry::instance().end(), @@ -99,7 +112,7 @@ BOOST_AUTO_UNIT_TEST(streamRegistry) BOOST_AUTO_UNIT_TEST(areaRegistry) { - char const * areas[] = { "", "(anonymous namespace)::myArea" }; + char const * areas[] = { "", "not_anonymous::Foo", "not_anonymous::myArea" }; BOOST_CHECK_EQUAL_COLLECTIONS( senf::log::AreaRegistry::instance().begin(), senf::log::AreaRegistry::instance().end(),