Skip to content

Commit

Permalink
LOGCXX-225: Replace CPPUNIT with LOGUNIT abstraction of CPPUNIT
Browse files Browse the repository at this point in the history
  • Loading branch information
Curt Arnold committed Jan 28, 2008
1 parent 9e1368f commit b279aa7
Show file tree
Hide file tree
Showing 71 changed files with 1,361 additions and 1,439 deletions.
6 changes: 3 additions & 3 deletions src/test/cpp/appenderskeletontestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#include "appenderskeletontestcase.h"
#include <cppunit/extensions/HelperMacros.h>
#include "logunit.h"
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/appenderskeleton.h>

Expand All @@ -28,12 +28,12 @@ using namespace log4cxx::helpers;
void AppenderSkeletonTestCase::testDefaultThreshold() {
ObjectPtrT<AppenderSkeleton> appender(createAppenderSkeleton());
LevelPtr threshold(appender->getThreshold());
CPPUNIT_ASSERT_EQUAL(Level::getAll()->toInt(), threshold->toInt());
LOGUNIT_ASSERT_EQUAL(Level::getAll()->toInt(), threshold->toInt());
}

void AppenderSkeletonTestCase::testSetOptionThreshold() {
ObjectPtrT<AppenderSkeleton> appender(createAppenderSkeleton());
appender->setOption(LOG4CXX_STR("threshold"), LOG4CXX_STR("debug"));
LevelPtr threshold(appender->getThreshold());
CPPUNIT_ASSERT_EQUAL(Level::getDebug()->toInt(), threshold->toInt());
LOGUNIT_ASSERT_EQUAL(Level::getDebug()->toInt(), threshold->toInt());
}
5 changes: 2 additions & 3 deletions src/test/cpp/appenderskeletontestcase.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
* limitations under the License.
*/

#include <cppunit/TestFixture.h>
#include <log4cxx/appenderskeleton.h>

#include "logunit.h"

/**
An abstract set of tests for inclusion in concrete
appender test case
*/
class AppenderSkeletonTestCase : public CppUnit::TestFixture
LOGUNIT_CLASS(AppenderSkeletonTestCase)
{

public:
Expand Down
59 changes: 29 additions & 30 deletions src/test/cpp/asyncappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* limitations under the License.
*/

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include "logunit.h"

#include <log4cxx/logger.h>
#include <log4cxx/logmanager.h>
Expand Down Expand Up @@ -103,22 +102,22 @@ typedef helpers::ObjectPtrT<BlockableVectorAppender> BlockableVectorAppenderPtr;
*/
class AsyncAppenderTestCase : public AppenderSkeletonTestCase
{
CPPUNIT_TEST_SUITE(AsyncAppenderTestCase);
LOGUNIT_TEST_SUITE(AsyncAppenderTestCase);
//
// tests inherited from AppenderSkeletonTestCase
//
CPPUNIT_TEST(testDefaultThreshold);
CPPUNIT_TEST(testSetOptionThreshold);
LOGUNIT_TEST(testDefaultThreshold);
LOGUNIT_TEST(testSetOptionThreshold);

CPPUNIT_TEST(closeTest);
CPPUNIT_TEST(test2);
CPPUNIT_TEST(test3);
LOGUNIT_TEST(closeTest);
LOGUNIT_TEST(test2);
LOGUNIT_TEST(test3);
//
// TODO: test fails on Linux.
//CPPUNIT_TEST(testBadAppender);
CPPUNIT_TEST(testLocationInfoTrue);
CPPUNIT_TEST(testConfiguration);
CPPUNIT_TEST_SUITE_END();
//LOGUNIT_TEST(testBadAppender);
LOGUNIT_TEST(testLocationInfoTrue);
LOGUNIT_TEST(testConfiguration);
LOGUNIT_TEST_SUITE_END();


public:
Expand Down Expand Up @@ -152,7 +151,7 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
root->debug(LOG4CXX_TEST_STR("m2"));

const std::vector<spi::LoggingEventPtr>& v = vectorAppender->getVector();
CPPUNIT_ASSERT_EQUAL((size_t) 1, v.size());
LOGUNIT_ASSERT_EQUAL((size_t) 1, v.size());
}

// this test checks whether appenders embedded within an AsyncAppender are also
Expand All @@ -172,8 +171,8 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
root->debug(LOG4CXX_TEST_STR("m2"));

const std::vector<spi::LoggingEventPtr>& v = vectorAppender->getVector();
CPPUNIT_ASSERT_EQUAL((size_t) 1, v.size());
CPPUNIT_ASSERT(vectorAppender->isClosed());
LOGUNIT_ASSERT_EQUAL((size_t) 1, v.size());
LOGUNIT_ASSERT(vectorAppender->isClosed());
}

// this test checks whether appenders embedded within an AsyncAppender are also
Expand All @@ -196,8 +195,8 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
root->debug(LOG4CXX_TEST_STR("m2"));

const std::vector<spi::LoggingEventPtr>& v = vectorAppender->getVector();
CPPUNIT_ASSERT_EQUAL(LEN, v.size());
CPPUNIT_ASSERT_EQUAL(true, vectorAppender->isClosed());
LOGUNIT_ASSERT_EQUAL(LEN, v.size());
LOGUNIT_ASSERT_EQUAL(true, vectorAppender->isClosed());
}

/**
Expand All @@ -216,7 +215,7 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
Thread::sleep(10);
try {
LOG4CXX_INFO(root, "Message");
CPPUNIT_FAIL("Should have thrown exception");
LOGUNIT_FAIL("Should have thrown exception");
} catch(NullPointerException& ex) {
}
}
Expand Down Expand Up @@ -247,27 +246,27 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
const std::vector<spi::LoggingEventPtr>& events = blockableAppender->getVector();
LoggingEventPtr initialEvent = events[0];
LoggingEventPtr discardEvent = events[events.size() - 1];
CPPUNIT_ASSERT(initialEvent->getMessage() == LOG4CXX_STR("Hello, World"));
CPPUNIT_ASSERT(discardEvent->getMessage().substr(0,10) == LOG4CXX_STR("Discarded "));
CPPUNIT_ASSERT_EQUAL(log4cxx::spi::LocationInfo::getLocationUnavailable().getClassName(),
LOGUNIT_ASSERT(initialEvent->getMessage() == LOG4CXX_STR("Hello, World"));
LOGUNIT_ASSERT(discardEvent->getMessage().substr(0,10) == LOG4CXX_STR("Discarded "));
LOGUNIT_ASSERT_EQUAL(log4cxx::spi::LocationInfo::getLocationUnavailable().getClassName(),
discardEvent->getLocationInformation().getClassName());
}

void testConfiguration() {
log4cxx::xml::DOMConfigurator::configure("input/xml/asyncAppender1.xml");
AsyncAppenderPtr asyncAppender(Logger::getRootLogger()->getAppender(LOG4CXX_STR("ASYNC")));
CPPUNIT_ASSERT(!(asyncAppender == 0));
CPPUNIT_ASSERT_EQUAL(100, asyncAppender->getBufferSize());
CPPUNIT_ASSERT_EQUAL(false, asyncAppender->getBlocking());
CPPUNIT_ASSERT_EQUAL(true, asyncAppender->getLocationInfo());
LOGUNIT_ASSERT(!(asyncAppender == 0));
LOGUNIT_ASSERT_EQUAL(100, asyncAppender->getBufferSize());
LOGUNIT_ASSERT_EQUAL(false, asyncAppender->getBlocking());
LOGUNIT_ASSERT_EQUAL(true, asyncAppender->getLocationInfo());
AppenderList nestedAppenders(asyncAppender->getAllAppenders());
// TODO:
// test seems to work okay, but have not found a working way to
// get a reference to the nested vector appender
//
// CPPUNIT_ASSERT_EQUAL((size_t) 1, nestedAppenders.size());
// LOGUNIT_ASSERT_EQUAL((size_t) 1, nestedAppenders.size());
// VectorAppenderPtr vectorAppender(nestedAppenders[0]);
// CPPUNIT_ASSERT(0 != vectorAppender);
// LOGUNIT_ASSERT(0 != vectorAppender);
LoggerPtr root(Logger::getRootLogger());

size_t LEN = 20;
Expand All @@ -277,12 +276,12 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase

asyncAppender->close();
// const std::vector<spi::LoggingEventPtr>& v = vectorAppender->getVector();
// CPPUNIT_ASSERT_EQUAL(LEN, v.size());
// CPPUNIT_ASSERT_EQUAL(true, vectorAppender->isClosed());
// LOGUNIT_ASSERT_EQUAL(LEN, v.size());
// LOGUNIT_ASSERT_EQUAL(true, vectorAppender->isClosed());
}


};

//CPPUNIT_TEST_SUITE_REGISTRATION(AsyncAppenderTestCase);
//LOGUNIT_TEST_SUITE_REGISTRATION(AsyncAppenderTestCase);
#endif
13 changes: 6 additions & 7 deletions src/test/cpp/consoleappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
* limitations under the License.
*/

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <log4cxx/consoleappender.h>
#include "logunit.h"
#include "writerappendertestcase.h"

using namespace log4cxx;
Expand All @@ -28,14 +27,14 @@ using namespace log4cxx::helpers;
*/
class ConsoleAppenderTestCase : public WriterAppenderTestCase
{
CPPUNIT_TEST_SUITE(ConsoleAppenderTestCase);
LOGUNIT_TEST_SUITE(ConsoleAppenderTestCase);
//
// tests inherited from AppenderSkeletonTestCase
//
CPPUNIT_TEST(testDefaultThreshold);
CPPUNIT_TEST(testSetOptionThreshold);
LOGUNIT_TEST(testDefaultThreshold);
LOGUNIT_TEST(testSetOptionThreshold);

CPPUNIT_TEST_SUITE_END();
LOGUNIT_TEST_SUITE_END();


public:
Expand All @@ -45,4 +44,4 @@ class ConsoleAppenderTestCase : public WriterAppenderTestCase
}
};

CPPUNIT_TEST_SUITE_REGISTRATION(ConsoleAppenderTestCase);
LOGUNIT_TEST_SUITE_REGISTRATION(ConsoleAppenderTestCase);
52 changes: 20 additions & 32 deletions src/test/cpp/customlogger/xloggertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
#define LOG4CXX_TEST 1
#include <log4cxx/private/log4cxx_private.h>


#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include "../logunit.h"
#include "xlogger.h"
#include <log4cxx/xml/domconfigurator.h>
#include "../util/transformer.h"
Expand All @@ -36,12 +34,12 @@ using namespace log4cxx::xml;
/**
Tests handling of custom loggers.
*/
class XLoggerTestCase : public CppUnit::TestFixture
LOGUNIT_CLASS(XLoggerTestCase)
{
CPPUNIT_TEST_SUITE(XLoggerTestCase);
CPPUNIT_TEST(test1);
CPPUNIT_TEST(test2);
CPPUNIT_TEST_SUITE_END();
LOGUNIT_TEST_SUITE(XLoggerTestCase);
LOGUNIT_TEST(test1);
LOGUNIT_TEST(test2);
LOGUNIT_TEST_SUITE_END();

XLoggerPtr logger;

Expand All @@ -67,37 +65,27 @@ class XLoggerTestCase : public CppUnit::TestFixture
fn.append(".xml");
DOMConfigurator::configure(fn);

int i = -1;
std::ostringstream os;
os << "Message " << ++i;
if (logger->isEnabledFor(log4cxx::XLevel::getTrace())) {
logger->forcedLog(log4cxx::XLevel::getTrace(), os.str(), LOG4CXX_LOCATION);
}
int i = 0;
LOG4CXX_LOG(logger, log4cxx::XLevel::getTrace(), "Message " << i);

os.str("");
os << "Message " << ++ i;
LOG4CXX_DEBUG(logger, os.str());
os.str("");
os << "Message " << ++ i;
LOG4CXX_WARN(logger, os.str());
os.str("");
os << "Message " << ++ i;
LOG4CXX_ERROR(logger, os.str());
os.str("");
os << "Message " << ++ i;
LOG4CXX_FATAL(logger, os.str());
os.str("");
os << "Message " << ++ i;
LOG4CXX_DEBUG(logger, os.str());
i++;
LOG4CXX_DEBUG(logger, "Message " << i);
i++;
LOG4CXX_WARN(logger, "Message " << i);
i++;
LOG4CXX_ERROR(logger, "Message " << i);
i++;
LOG4CXX_FATAL(logger, "Message " << i);
i++;
LOG4CXX_DEBUG(logger, "Message " << i);

const File OUTPUT("output/temp");
std::string witness("witness/customLogger.");
witness.append(number);
const File WITNESS(witness);
CPPUNIT_ASSERT(Compare::compare(OUTPUT, WITNESS));
//#endif
LOGUNIT_ASSERT(Compare::compare(OUTPUT, WITNESS));
}
};

CPPUNIT_TEST_SUITE_REGISTRATION(XLoggerTestCase);
LOGUNIT_TEST_SUITE_REGISTRATION(XLoggerTestCase);

13 changes: 6 additions & 7 deletions src/test/cpp/db/odbcappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
* limitations under the License.
*/

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <log4cxx/db/odbcappender.h>
#include "../appenderskeletontestcase.h"
#include "../logunit.h"

#define LOG4CXX_TEST 1
#include <log4cxx/private/log4cxx_private.h>
Expand All @@ -33,14 +32,14 @@ using namespace log4cxx::helpers;
*/
class ODBCAppenderTestCase : public AppenderSkeletonTestCase
{
CPPUNIT_TEST_SUITE(ODBCAppenderTestCase);
LOGUNIT_TEST_SUITE(ODBCAppenderTestCase);
//
// tests inherited from AppenderSkeletonTestCase
//
CPPUNIT_TEST(testDefaultThreshold);
CPPUNIT_TEST(testSetOptionThreshold);
LOGUNIT_TEST(testDefaultThreshold);
LOGUNIT_TEST(testSetOptionThreshold);

CPPUNIT_TEST_SUITE_END();
LOGUNIT_TEST_SUITE_END();


public:
Expand All @@ -50,6 +49,6 @@ class ODBCAppenderTestCase : public AppenderSkeletonTestCase
}
};

CPPUNIT_TEST_SUITE_REGISTRATION(ODBCAppenderTestCase);
LOGUNIT_TEST_SUITE_REGISTRATION(ODBCAppenderTestCase);

#endif
18 changes: 8 additions & 10 deletions src/test/cpp/defaultinit/testcase1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
* limitations under the License.
*/

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include "../logunit.h"

#include <log4cxx/logmanager.h>
#include <log4cxx/logger.h>

using namespace log4cxx;

class TestCase1 : public CppUnit::TestFixture
LOGUNIT_CLASS(TestCase1)
{
CPPUNIT_TEST_SUITE(TestCase1);
CPPUNIT_TEST(noneTest);
CPPUNIT_TEST_SUITE_END();
LOGUNIT_TEST_SUITE(TestCase1);
LOGUNIT_TEST(noneTest);
LOGUNIT_TEST_SUITE_END();

public:
void setUp()
Expand All @@ -44,11 +43,10 @@ class TestCase1 : public CppUnit::TestFixture
LoggerPtr root = Logger::getRootLogger();
LOG4CXX_DEBUG(root, "Hello, world");
bool rootIsConfigured = !root->getAllAppenders().empty();
CPPUNIT_ASSERT(!rootIsConfigured);
LOGUNIT_ASSERT(!rootIsConfigured);
}
};

CPPUNIT_NS::Test* createTestCase1() {
return TestCase1::suite();
}

LOGUNIT_TEST_SUITE_REGISTRATION_NO_AUTO_RUN(TestCase1)

Loading

0 comments on commit b279aa7

Please sign in to comment.