X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FLog.test.cc;h=0bec6da5070cb70c5ab6666fe191896736ae3e68;hb=f6f670f2dbc82b77db29df6cd452f2b351b9662a;hp=d57d625c931749f8981184beb063bcc0279074db;hpb=b52002fa2001e6472d6aa3dde263b85f654c6e8e;p=senf.git diff --git a/Utils/Logger/Log.test.cc b/Utils/Logger/Log.test.cc index d57d625..0bec6da 100644 --- a/Utils/Logger/Log.test.cc +++ b/Utils/Logger/Log.test.cc @@ -26,58 +26,100 @@ //#include "Log.test.hh" //#include "Log.test.ih" -// Custom includes -#include - -#define _senf_LOG_STREAM logstream -namespace { - std::stringstream logstream; -} +// We need to put all tests into this single file to not violate the ODR -#define SENF_LOG_CONF ((senf::log::Debug)(_)(VERBOSE)) - -#include "Log.hh" -#include "Defaults.hh" -#include "Parameters.hh" -#include "Levels.hh" +#define SENF_LOG_CONF (( (senf)(log)(Debug), (_), NOTICE )) \ + (( (not_anonymous)(myStream), (not_anonymous)(Foo), VERBOSE )) +// 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( LogFoo, (senf::log::Debug) (senf::log::CRITICAL) ); + SENF_LOG_DEF_ALIAS( LogCritical, (senf::log::Debug) (senf::log::CRITICAL) ); SENF_LOG_DEF_STREAM( myStream, senf::log::MESSAGE, senf::log::MESSAGE, senf::log::MESSAGE ); SENF_LOG_DEF_AREA( myArea ); } +using namespace not_anonymous; BOOST_AUTO_UNIT_TEST(logger) { + senf::log::StringTarget target; + + target.route(); + target.route("not_anonymous::myStream", "not_anonymous::Foo"); + + // 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::NOTICE); + SENF_LOG_DEFAULT_LEVEL(senf::log::VERBOSE); SENF_LOG(("Log message")); + BOOST_CHECK( target.str().empty() ); + target.clear(); + + SENF_LOG((senf::log::VERBOSE)("Log message 2")); + BOOST_CHECK( target.str().empty() ); + target.clear(); + + SENF_LOG((senf::log::IMPORTANT)("Important message")); + BOOST_CHECK( ! target.str().empty() ); + target.clear(); - SENF_LOG((LogFoo) ("Another log message: " << 10)); + 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(); + + SENF_LOG((Foo)("Foo area")); + BOOST_CHECK( target.str().empty() ); + target.clear(); +} + +BOOST_AUTO_UNIT_TEST(streamRegistry) +{ + char const * streams[] = { "not_anonymous::myStream", "senf::log::Debug" }; + + BOOST_CHECK_EQUAL_COLLECTIONS( senf::log::StreamRegistry::instance().begin(), + senf::log::StreamRegistry::instance().end(), + streams, streams+sizeof(streams)/sizeof(streams[0]) ); + BOOST_CHECK_EQUAL( senf::log::detail::StreamBase::nStreams, 2u ); +} + +BOOST_AUTO_UNIT_TEST(areaRegistry) +{ + char const * areas[] = { "", "not_anonymous::Foo", "not_anonymous::myArea" }; + + BOOST_CHECK_EQUAL_COLLECTIONS( senf::log::AreaRegistry::instance().begin(), + senf::log::AreaRegistry::instance().end(), + areas, areas+sizeof(areas)/sizeof(areas[0]) ); - BOOST_CHECK_EQUAL( logstream.str(), - "Log message\nAnother log message: 10\nLast message continued here\n" ); } ///////////////////////////////cc.e////////////////////////////////////////