fix: NULL pointer strategy when setting rotation never #4411

Regression from 66e93f98cc3530c9ea5a748cf2248d2592b61853.
This commit is contained in:
Aron Budea 2024-01-23 15:56:28 +10:30 committed by Matej Kenda
parent 6dcafc8989
commit fe08b68c2a
3 changed files with 32 additions and 1 deletions

View File

@ -271,7 +271,9 @@ RotateStrategy* FileChannel::createRotationStrategy(const std::string& rotation,
pStrategy = new RotateBySizeStrategy(n*1024*1024); pStrategy = new RotateBySizeStrategy(n*1024*1024);
else if (unit.empty()) else if (unit.empty())
pStrategy = new RotateBySizeStrategy(n); pStrategy = new RotateBySizeStrategy(n);
else if (unit != "never") else if (unit == "never")
pStrategy = new NullRotateStrategy();
else
throw InvalidArgumentException("rotation", rotation); throw InvalidArgumentException("rotation", rotation);
return pStrategy; return pStrategy;

View File

@ -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() void FileChannelTest::testRotateBySize()
{ {
std::string name = filename(); std::string name = filename();
@ -804,6 +831,7 @@ CppUnit::Test* FileChannelTest::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FileChannelTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FileChannelTest");
CppUnit_addTest(pSuite, FileChannelTest, testRotateNever);
CppUnit_addTest(pSuite, FileChannelTest, testRotateBySize); CppUnit_addTest(pSuite, FileChannelTest, testRotateBySize);
CppUnit_addTest(pSuite, FileChannelTest, testRotateByAge); CppUnit_addTest(pSuite, FileChannelTest, testRotateByAge);
CppUnit_addLongTest(pSuite, FileChannelTest, testRotateAtTimeDayUTC); CppUnit_addLongTest(pSuite, FileChannelTest, testRotateAtTimeDayUTC);

View File

@ -31,6 +31,7 @@ public:
FileChannelTest(const std::string& name); FileChannelTest(const std::string& name);
~FileChannelTest(); ~FileChannelTest();
void testRotateNever();
void testRotateBySize(); void testRotateBySize();
void testRotateByAge(); void testRotateByAge();
void testRotateAtTimeDayUTC(); void testRotateAtTimeDayUTC();