Skip to content

Commit

Permalink
fix: NULL pointer strategy when setting rotation never #4411
Browse files Browse the repository at this point in the history
Regression from 66e93f9.
  • Loading branch information
thebearon committed Jan 23, 2024
1 parent 6d7a4ff commit 3ceba2a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Foundation/src/FileChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ RotateStrategy* FileChannel::createRotationStrategy(const std::string& rotation,
pStrategy = new RotateBySizeStrategy(n*1024*1024);
else if (unit.empty())
pStrategy = new RotateBySizeStrategy(n);
else if (unit != "never")
else if (unit == "never")
pStrategy = new NullRotateStrategy();
else
throw InvalidArgumentException("rotation", rotation);

return pStrategy;
Expand Down
28 changes: 28 additions & 0 deletions Foundation/testsuite/src/FileChannelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@ FileChannelTest::~FileChannelTest()
}


void FileChannelTest::testRotateNever()
{
std::string name = filename();
try
{
AutoPtr<FileChannel> pChannel = new FileChannel(name);
pChannel->setProperty(FileChannel::PROP_ROTATION, "never");
pChannel->open();
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
for (int i = 0; i < 200; ++i)
{
pChannel->log(msg);
}
File f(name);
assertTrue (f.exists());
f = name + ".0";
assertTrue (!f.exists());
}
catch (...)
{
remove(name);
throw;
}
remove(name);
}


void FileChannelTest::testRotateBySize()
{
std::string name = filename();
Expand Down Expand Up @@ -804,6 +831,7 @@ CppUnit::Test* FileChannelTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FileChannelTest");

CppUnit_addTest(pSuite, FileChannelTest, testRotateNever);
CppUnit_addTest(pSuite, FileChannelTest, testRotateBySize);
CppUnit_addTest(pSuite, FileChannelTest, testRotateByAge);
CppUnit_addLongTest(pSuite, FileChannelTest, testRotateAtTimeDayUTC);
Expand Down
1 change: 1 addition & 0 deletions Foundation/testsuite/src/FileChannelTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FileChannelTest: public CppUnit::TestCase
FileChannelTest(const std::string& name);
~FileChannelTest();

void testRotateNever();
void testRotateBySize();
void testRotateByAge();
void testRotateAtTimeDayUTC();
Expand Down

0 comments on commit 3ceba2a

Please sign in to comment.