mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-29 21:30:04 +01:00
[SF 2632636] FileChannel Purge Unit Tests Broken
This commit is contained in:
parent
614c87b4be
commit
8fe9757195
@ -154,6 +154,7 @@ class Foundation_API FileChannel: public Channel
|
||||
///
|
||||
/// The purgeAge property can have the following values:
|
||||
///
|
||||
/// * "none" or "" no purging
|
||||
/// * <n> [seconds] the maximum age is <n> seconds.
|
||||
/// * <n> minutes: the maximum age is <n> minutes.
|
||||
/// * <n> hours: the maximum age is <n> hours.
|
||||
@ -161,10 +162,10 @@ class Foundation_API FileChannel: public Channel
|
||||
/// * <n> weeks: the maximum age is <n> weeks.
|
||||
/// * <n> months: the maximum age is <n> months, where a month has 30 days.
|
||||
///
|
||||
/// The purgeCount property has an integer value that
|
||||
/// specifies the maximum number of archived log files.
|
||||
/// If the number is exceeded, archived log files are
|
||||
/// deleted, starting with the oldest.
|
||||
/// The purgeCount property has an integer value that specifies the maximum number
|
||||
/// of archived log files. If the number is exceeded, archived log files are
|
||||
/// deleted, starting with the oldest. When "none" or empty string are
|
||||
/// supplied, they reset purgeCount to none (no purging).
|
||||
///
|
||||
/// For a more lightweight file channel class, see SimpleFileChannel.
|
||||
{
|
||||
|
@ -302,8 +302,14 @@ void FileChannel::setCompress(const std::string& compress)
|
||||
|
||||
void FileChannel::setPurgeAge(const std::string& age)
|
||||
{
|
||||
delete _pPurgeStrategy;
|
||||
_pPurgeStrategy = 0;
|
||||
_purgeAge = "none";
|
||||
if (age.empty() || 0 == icompare(age, "none")) return;
|
||||
|
||||
std::string::const_iterator it = age.begin();
|
||||
std::string::const_iterator end = age.end();
|
||||
|
||||
int n = 0;
|
||||
while (it != end && std::isspace(*it)) ++it;
|
||||
while (it != end && std::isdigit(*it)) { n *= 10; n += *it++ - '0'; }
|
||||
@ -324,8 +330,10 @@ void FileChannel::setPurgeAge(const std::string& age)
|
||||
factor = 30*Timespan::DAYS;
|
||||
else if (unit != "seconds")
|
||||
throw InvalidArgumentException("purgeAge", age);
|
||||
|
||||
delete _pPurgeStrategy;
|
||||
|
||||
if (0 == n)
|
||||
throw InvalidArgumentException("Zero is not valid purge age.");
|
||||
|
||||
_pPurgeStrategy = new PurgeByAgeStrategy(Timespan(factor*n));
|
||||
_purgeAge = age;
|
||||
}
|
||||
@ -333,14 +341,22 @@ void FileChannel::setPurgeAge(const std::string& age)
|
||||
|
||||
void FileChannel::setPurgeCount(const std::string& count)
|
||||
{
|
||||
delete _pPurgeStrategy;
|
||||
_pPurgeStrategy = 0;
|
||||
_purgeAge = "none";
|
||||
if (count.empty() || 0 == icompare(count, "none")) return;
|
||||
|
||||
int n = 0;
|
||||
std::string::const_iterator it = count.begin();
|
||||
std::string::const_iterator end = count.end();
|
||||
int n = 0;
|
||||
|
||||
while (it != end && std::isspace(*it)) ++it;
|
||||
while (it != end && std::isdigit(*it)) { n *= 10; n += *it++ - '0'; }
|
||||
while (it != end && std::isspace(*it)) ++it;
|
||||
|
||||
delete _pPurgeStrategy;
|
||||
if (0 == n)
|
||||
throw InvalidArgumentException("Zero is not valid purge count.");
|
||||
|
||||
_pPurgeStrategy = new PurgeByCountStrategy(n);
|
||||
_purgeCount = count;
|
||||
}
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/DirectoryIterator.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
@ -64,6 +65,7 @@ using Poco::LocalDateTime;
|
||||
using Poco::DateTimeFormatter;
|
||||
using Poco::DateTimeFormat;
|
||||
using Poco::DirectoryIterator;
|
||||
using Poco::InvalidArgumentException;
|
||||
|
||||
|
||||
FileChannelTest::FileChannelTest(const std::string& name): CppUnit::TestCase(name)
|
||||
@ -405,6 +407,7 @@ void FileChannelTest::purgeAge(const std::string& pa)
|
||||
void FileChannelTest::noPurgeAge(const std::string& npa)
|
||||
{
|
||||
std::string name = filename();
|
||||
|
||||
try
|
||||
{
|
||||
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
||||
@ -444,8 +447,16 @@ void FileChannelTest::noPurgeAge(const std::string& npa)
|
||||
void FileChannelTest::testPurgeAge()
|
||||
{
|
||||
purgeAge("5 seconds");
|
||||
noPurgeAge("0 seconds");
|
||||
try
|
||||
{
|
||||
noPurgeAge("0 seconds");
|
||||
fail ("must fail");
|
||||
} catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
noPurgeAge("");
|
||||
noPurgeAge("none");
|
||||
}
|
||||
|
||||
|
||||
@ -516,8 +527,16 @@ void FileChannelTest::noPurgeCount(const std::string& npc)
|
||||
void FileChannelTest::testPurgeCount()
|
||||
{
|
||||
purgeCount("2");
|
||||
try
|
||||
{
|
||||
noPurgeCount("0");
|
||||
fail ("must fail");
|
||||
} catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
noPurgeCount("");
|
||||
noPurgeCount("0");
|
||||
noPurgeCount("none");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user