Skip to content

Commit

Permalink
add test to verify outputstream resets
Browse files Browse the repository at this point in the history
  • Loading branch information
rm5248 committed Nov 11, 2023
1 parent fd90b6a commit 8c5ca16
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/cpp/helpers/messagebuffertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "../logunit.h"
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>
#include "util/compare.h"

#if LOG4CXX_CFSTRING_API
#include <CoreFoundation/CFString.h>
Expand All @@ -42,6 +45,7 @@ LOGUNIT_CLASS(MessageBufferTest)
LOGUNIT_TEST(testInsertNull);
LOGUNIT_TEST(testInsertInt);
LOGUNIT_TEST(testInsertManipulator);
LOGUNIT_TEST(testBaseChange);
#if LOG4CXX_WCHAR_T_API
LOGUNIT_TEST(testInsertConstWStr);
LOGUNIT_TEST(testInsertWString);
Expand Down Expand Up @@ -136,6 +140,30 @@ LOGUNIT_CLASS(MessageBufferTest)
LOGUNIT_ASSERT_EQUAL(true, buf.hasStream());
}

void testBaseChange()
{
LoggerPtr root;
LoggerPtr logger;

root = Logger::getRootLogger();
logger = Logger::getLogger(LOG4CXX_STR("java.org.apache.log4j.PatternLayoutTest"));

PropertyConfigurator::configure(LOG4CXX_FILE("input/messagebuffer1.properties"));

int num = 220;
LOG4CXX_INFO(logger, "number in hex: " << std::hex << num);
LOG4CXX_INFO(logger, "number in dec: " << num);

LOGUNIT_ASSERT(Compare::compare(LOG4CXX_STR("output/messagebuffer"), LOG4CXX_FILE("witness/messagebuffer.1")));

auto rep = root->getLoggerRepository();

if (rep)
{
rep->resetConfiguration();
}
}

#if LOG4CXX_WCHAR_T_API
void testInsertConstWStr()
{
Expand Down
21 changes: 21 additions & 0 deletions src/test/resources/input/messagebuffer1.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
log4j.rootCategory=DEBUG, testAppender
log4j.appender.testAppender=org.apache.log4j.FileAppender
log4j.appender.testAppender.file=output/messagebuffer
log4j.appender.testAppender.Append=false
log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.testAppender.layout.ConversionPattern=%-5p - %m%n
2 changes: 2 additions & 0 deletions src/test/resources/witness/messagebuffer.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INFO - number in hex: dc
INFO - number in dec: 220

0 comments on commit 8c5ca16

Please sign in to comment.