From 53bd23d0e679746b78d0bcf9234e7b99983e6071 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 29 Nov 2011 04:52:52 +0100 Subject: ported from log4cxx to log4cpp log4cxx depends on Apache Portable Runtime Utility Library, so we switch to log4cpp with nearly the same features but with no dependencies for easier porting to other platforms --- test/Makefile | 2 +- test/base/image.cpp | 23 ++++++++++++++--------- test/base/songloading.cpp | 23 +++++++++-------------- test/log4cpp.property | 15 +++++++++++++++ test/log4cxx.xml | 42 ------------------------------------------ 5 files changed, 39 insertions(+), 66 deletions(-) create mode 100644 test/log4cpp.property delete mode 100644 test/log4cxx.xml (limited to 'test') diff --git a/test/Makefile b/test/Makefile index b8cd7cbd..61f92e19 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,7 +10,7 @@ sources:=$(wildcard *.cpp) $(wildcard */*.cpp) $(wildcard $(TOP)/src/*/*/*.cpp) deps:=$(sources:.cpp=.d) CXXFLAGS:=-Wall -Werror -I$(TOP)/src -I$(TOP)/src/base -I$(TOP)/src/menu -I$(TOP)/src/media -I$(TOP)/src/screens -I$(TOP)/src/frames -I$(TOP)/src/utils $(shell pkg-config ftgl --cflags) -g -LDFLAGS:=-lsqlite3 -lSDL -llog4cxx -lboost_program_options-mt -lboost_filesystem-mt -lboost_thread-mt -lSDL_image -lcppunit -lSDL_gfx -lGL $(shell pkg-config ftgl --libs) +LDFLAGS:=-lsqlite3 -lSDL $(shell log4cpp-config --libs) -lboost_program_options-mt -lboost_filesystem-mt -lboost_thread-mt -lSDL_image -lSDL_gfx -lcppunit -lGL $(shell pkg-config ftgl --libs) TARGET:=$(PROJECT) objects:=$(sources:.cpp=.o) diff --git a/test/base/image.cpp b/test/base/image.cpp index 50fb50b0..e9e9d3d4 100644 --- a/test/base/image.cpp +++ b/test/base/image.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include @@ -43,7 +43,7 @@ namespace usdx CPPUNIT_TEST_EXCEPTION(testNotAnImage, usdx::ImageLoadException); CPPUNIT_TEST_SUITE_END(); private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; public: void setUp() { @@ -57,7 +57,8 @@ namespace usdx { Image img("./testdata/test.bmp"); const SDL_Surface *surface = img.get_surface(); - LOG4CXX_DEBUG(log, "test.bmp: w = " << surface->w << "; h = " << surface->h); + log << log4cpp::Priority::DEBUG << "test.bmp: " << + "w = " << surface->w << "; h = " << surface->h; CPPUNIT_ASSERT(40 == surface->w); CPPUNIT_ASSERT(30 == surface->h); } @@ -66,7 +67,8 @@ namespace usdx { Image img("./testdata/test.jpg"); const SDL_Surface *surface = img.get_surface(); - LOG4CXX_DEBUG(log, "test.jpg: w = " << surface->w << "; h = " << surface->h); + log << log4cpp::Priority::DEBUG << "test.jpg: " << + "w = " << surface->w << "; h = " << surface->h; CPPUNIT_ASSERT(40 == surface->w); CPPUNIT_ASSERT(30 == surface->h); } @@ -75,7 +77,8 @@ namespace usdx { Image img("./testdata/test.png"); const SDL_Surface *surface = img.get_surface(); - LOG4CXX_DEBUG(log, "test.png: w = " << surface->w << "; h = " << surface->h); + log << log4cpp::Priority::DEBUG << "test.png: " << + "w = " << surface->w << "; h = " << surface->h; CPPUNIT_ASSERT(40 == surface->w); CPPUNIT_ASSERT(30 == surface->h); } @@ -84,7 +87,8 @@ namespace usdx { Image img("./testdata/test.gif"); const SDL_Surface *surface = img.get_surface(); - LOG4CXX_DEBUG(log, "test.gif: w = " << surface->w << "; h = " << surface->h); + log << log4cpp::Priority::DEBUG << "test.gif: " << + "w = " << surface->w << "; h = " << surface->h; CPPUNIT_ASSERT(40 == surface->w); CPPUNIT_ASSERT(30 == surface->h); } @@ -93,12 +97,13 @@ namespace usdx { Image img("./testdata/testsong_correct.txt"); const SDL_Surface *surface = img.get_surface(); - LOG4CXX_DEBUG(log, "testsong_correct.txt: w = " << surface->w << "; h = " << surface->h); + log << log4cpp::Priority::DEBUG << "testsong_correct.txt: " << + "w = " << surface->w << "; h = " << surface->h; } }; - log4cxx::LoggerPtr ImageTest::log = - log4cxx::Logger::getLogger("test.usdx.base.image"); + log4cpp::Category& ImageTest::log = + log4cpp::Category::getInstance("test.usdx.base.image"); CPPUNIT_TEST_SUITE_REGISTRATION(ImageTest); }; diff --git a/test/base/songloading.cpp b/test/base/songloading.cpp index ddb2756f..94690cc3 100644 --- a/test/base/songloading.cpp +++ b/test/base/songloading.cpp @@ -28,7 +28,8 @@ #include #include "song.hpp" #include "songloading/songloader.hpp" -#include +#include +#include namespace usdx { @@ -42,21 +43,19 @@ namespace usdx CPPUNIT_TEST_SUITE_END(); private: - int oldLogLevel; + log4cpp::Priority::Value oldLogLevel; public: void setUp() { // save old loglevel in case we want to disable logging - using namespace log4cxx; - oldLogLevel = Logger::getRootLogger()->getEffectiveLevel()->toInt(); + oldLogLevel = log4cpp::Category::getRoot().getPriority(); } void tearDown() { // set old loglevel in case we did disable logging - using namespace log4cxx; - Logger::getRootLogger()->setLevel(Level::toLevel(oldLogLevel)); + log4cpp::Category::getRoot().setPriority(oldLogLevel); } void testSongloadingTxtHeader() @@ -93,8 +92,7 @@ namespace usdx { // disable logging to avoid logmsgs when the exeption // is thrown - using namespace log4cxx; - Logger::getRootLogger()->setLevel(Level::getOff()); + log4cpp::Category::getRoot().setPriority(log4cpp::Priority::EMERG); Songloader::get_instance()-> load_header("testdata/testsong_missing_artist.txt"); @@ -104,8 +102,7 @@ namespace usdx { // disable logging to avoid logmsgs when the exeption // is thrown - using namespace log4cxx; - Logger::getRootLogger()->setLevel(Level::getOff()); + log4cpp::Category::getRoot().setPriority(log4cpp::Priority::EMERG); Songloader::get_instance()-> load_header("testdata/testsong_missing_title.txt"); @@ -115,8 +112,7 @@ namespace usdx { // disable logging to avoid logmsgs when the exeption // is thrown - using namespace log4cxx; - Logger::getRootLogger()->setLevel(Level::getOff()); + log4cpp::Category::getRoot().setPriority(log4cpp::Priority::EMERG); Songloader::get_instance()-> load_header("testdata/testsong_missing_mp3.txt"); @@ -127,8 +123,7 @@ namespace usdx { // disable logging to avoid logmsgs when the exeption // is thrown - using namespace log4cxx; - Logger::getRootLogger()->setLevel(Level::getOff()); + log4cpp::Category::getRoot().setPriority(log4cpp::Priority::EMERG); Songloader::get_instance()-> load_header("testdata/testsong_missing_bpm.txt"); diff --git a/test/log4cpp.property b/test/log4cpp.property new file mode 100644 index 00000000..4bcad324 --- /dev/null +++ b/test/log4cpp.property @@ -0,0 +1,15 @@ +log4cpp.rootCategory=DEBUG,console +log4cpp.category.usdx=,roll + +log4cpp.appender.console=org.apache.log4j.ConsoleAppender +log4cpp.appender.console.layout=org.apache.log4j.PatternLayout +log4cpp.appender.console.layout.ConversionPattern=%-6r [%-5p] %c - %m%n +log4cpp.appender.console.threshold=ERROR + +log4cpp.appender.roll=org.apache.log4j.rolling.RollingFileAppender +log4cpp.apperder.roll.maximumFileSize=400KB +log4cpp.apperder.roll.maxBackupIndex=4 +log4cpp.appender.roll.fileName=debug.log +log4cpp.appender.roll.append=true +log4cpp.appender.roll.layout=org.apache.log4j.PatternLayout +log4cpp.appender.roll.layout.ConversionPattern=%-6r [%-5p] %c - %m%n diff --git a/test/log4cxx.xml b/test/log4cxx.xml deleted file mode 100644 index 75daba46..00000000 --- a/test/log4cxx.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3