Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 27 additions & 29 deletions src/test/cpp/xml/domtestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <apr_file_io.h>
#include "../testchar.h"
#include "log4cxx/helpers/loglog.h"
#include <log4cxx/helpers/filesystempath.h>
#include "log4cxx/helpers/pool.h"

using namespace log4cxx;
using namespace log4cxx::helpers;
Expand Down Expand Up @@ -62,20 +64,17 @@ LOGUNIT_CLASS(DOMTestCase)

LoggerPtr root;
LoggerPtr logger;

static const File TEMP_A1;
static const File TEMP_A2;
static const File FILTERED_A1;
static const File FILTERED_A2;
static const File TEMP_A1_2;
static const File TEMP_A2_2;
static const File FILTERED_A1_2;
static const File FILTERED_A2_2;
LogString output_dir;

public:
void setUp()
{
LogLog::setInternalDebugging(true);
#if !LOG4CXX_HAS_FILESYSTEM_PATH
spi::Configurator::properties().setProperty(LOG4CXX_STR("PROGRAM_FILE_PATH.PARENT_PATH"), LOG4CXX_STR("output"));
#endif
output_dir = spi::Configurator::properties().getProperty(LOG4CXX_STR("PROGRAM_FILE_PATH.PARENT_PATH"));

root = Logger::getRootLogger();
logger = Logger::getLogger(LOG4CXX_TEST_STR("org.apache.log4j.xml.DOMTestCase"));
}
Expand All @@ -94,6 +93,14 @@ LOGUNIT_CLASS(DOMTestCase)
{
auto status = DOMConfigurator::configure(LOG4CXX_TEST_STR("input/xml/DOMTestCase1.xml"));
LOGUNIT_ASSERT_EQUAL(status, spi::ConfigurationStatus::Configured);

// Check that ${PROGRAM_FILE_PATH.PARENT_PATH} is expanded
auto fa = LOG4CXX_NS::cast<FileAppender>(root->getAppender(LOG4CXX_STR("A1")));
LOGUNIT_ASSERT(fa);
File logFile{ fa->getFile() };
Pool p;
LOGUNIT_ASSERT(!output_dir.empty());
LOGUNIT_ASSERT_EQUAL(output_dir, logFile.getParent(p));
common();

ControlFilter cf1;
Expand All @@ -113,6 +120,11 @@ LOGUNIT_CLASS(DOMTestCase)
filters2.push_back(&threadFilter);
filters2.push_back(&iso8601Filter);

const File TEMP_A1{ output_dir + LOG4CXX_STR("/temp.A1") };
const File FILTERED_A1{ output_dir + LOG4CXX_STR("/filtered.A1") };
const File TEMP_A2{ output_dir + LOG4CXX_STR("/temp.A2") };
const File FILTERED_A2{ output_dir + LOG4CXX_STR("/filtered.A2") };

try
{
Transformer::transform(TEMP_A1, FILTERED_A1, filters1);
Expand All @@ -126,9 +138,7 @@ LOGUNIT_CLASS(DOMTestCase)

const File witness1(LOG4CXX_TEST_STR("witness/dom.A1.1"));
const File witness2(LOG4CXX_TEST_STR("witness/dom.A2.1"));
// TODO: A1 doesn't contain duplicate entries
//
// LOGUNIT_ASSERT(Compare::compare(FILTERED_A1, witness1));
LOGUNIT_ASSERT(Compare::compare(FILTERED_A1, witness1));
LOGUNIT_ASSERT(Compare::compare(FILTERED_A2, witness2));
}

Expand All @@ -150,6 +160,10 @@ LOGUNIT_CLASS(DOMTestCase)
filters2.push_back(&threadFilter);
filters2.push_back(&iso8601Filter);

const File TEMP_A1_2{ output_dir + LOG4CXX_STR("/temp.A1.2") };
const File TEMP_A2_2{ output_dir + LOG4CXX_STR("/temp.A2.2") };
const File FILTERED_A1_2{ output_dir + LOG4CXX_STR("/filtered.A1.2") };
const File FILTERED_A2_2{ output_dir + LOG4CXX_STR("/filtered.A2.2") };
try
{
Transformer::transform(TEMP_A1_2, FILTERED_A1_2, filters1);
Expand All @@ -162,11 +176,7 @@ LOGUNIT_CLASS(DOMTestCase)
}

const File witness1(LOG4CXX_TEST_STR("witness/dom.A1.2"));
const File witness2(LOG4CXX_TEST_STR("witness/dom.A2.2"));
// TODO: A1 doesn't contain duplicate entries
//
// LOGUNIT_ASSERT(Compare::compare(FILTERED_A1, witness1));
LOGUNIT_ASSERT(Compare::compare(FILTERED_A2, witness2));
LOGUNIT_ASSERT(Compare::compare(FILTERED_A1_2, witness1));
}


Expand Down Expand Up @@ -196,7 +206,6 @@ LOGUNIT_CLASS(DOMTestCase)

/**
* Creates a output file that ends with a superscript 3.
* Output file is checked by build.xml after completion.
*/
void test3()
{
Expand All @@ -217,7 +226,6 @@ LOGUNIT_CLASS(DOMTestCase)

/**
* Creates a output file that ends with a ideographic 4.
* Output file is checked by build.xml after completion.
*/
void test4()
{
Expand Down Expand Up @@ -285,13 +293,3 @@ LOGUNIT_CLASS(DOMTestCase)

LOGUNIT_TEST_SUITE_REGISTRATION(DOMTestCase);

const File DOMTestCase::TEMP_A1(LOG4CXX_TEST_STR("output/temp.A1"));
const File DOMTestCase::TEMP_A2(LOG4CXX_TEST_STR("output/temp.A2"));
const File DOMTestCase::FILTERED_A1(LOG4CXX_TEST_STR("output/filtered.A1"));
const File DOMTestCase::FILTERED_A2(LOG4CXX_TEST_STR("output/filtered.A2"));

const File DOMTestCase::TEMP_A1_2(LOG4CXX_TEST_STR("output/temp.A1.2"));
const File DOMTestCase::TEMP_A2_2(LOG4CXX_TEST_STR("output/temp.A2.2"));
const File DOMTestCase::FILTERED_A1_2(LOG4CXX_TEST_STR("output/filtered.A1.2"));
const File DOMTestCase::FILTERED_A2_2(LOG4CXX_TEST_STR("output/filtered.A2.2"));

4 changes: 2 additions & 2 deletions src/test/resources/input/xml/DOMTestCase1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="A1" class="org.apache.log4j.FileAppender">

<param name="File" value="output/temp.A1" />
<param name="File" value="${PROGRAM_FILE_PATH.PARENT_PATH}/temp.A1" />
<param name="Append" value="false" />

<layout class="org.apache.log4j.PatternLayout">
Expand All @@ -30,7 +30,7 @@
</appender>

<appender name="A2" class="org.apache.log4j.FileAppender">
<param name="File" value="output/temp.A2" />
<param name="File" value="${PROGRAM_FILE_PATH.PARENT_PATH}/temp.A2" />
<param name="Append" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value=" [%t] %p %c - %m%n" />
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/input/xml/DOMTestCase2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="A1" class="org.apache.log4j.FileAppender">

<param name="File" value="output\temp.A1.2" />
<param name="File" value="${PROGRAM_FILE_PATH.PARENT_PATH}\temp.A1.2" />
<param name="Append" value="false" />

<layout class="org.apache.log4j.PatternLayout">
Expand All @@ -30,7 +30,7 @@
</appender>

<appender name="A2" class="org.apache.log4j.FileAppender">
<param name="File" value="output\temp.A2.2" />
<param name="File" value="${PROGRAM_FILE_PATH.PARENT_PATH}\temp.A2.2" />
<param name="Append" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} [%t] %-5p - %m%n"/>
Expand Down