mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-05 12:47:47 +01:00
formatting fix and few tests from the old trunk
This commit is contained in:
@@ -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)
|
||||
@@ -363,7 +365,7 @@ void FileChannelTest::testCompress()
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::testPurgeAge()
|
||||
void FileChannelTest::purgeAge(const std::string& pa)
|
||||
{
|
||||
std::string name = filename();
|
||||
try
|
||||
@@ -371,7 +373,7 @@ void FileChannelTest::testPurgeAge()
|
||||
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
||||
pChannel->setProperty(FileChannel::PROP_ROTATION, "1 K");
|
||||
pChannel->setProperty(FileChannel::PROP_ARCHIVE, "number");
|
||||
pChannel->setProperty(FileChannel::PROP_PURGEAGE, "5 seconds");
|
||||
pChannel->setProperty(FileChannel::PROP_PURGEAGE, pa);
|
||||
pChannel->open();
|
||||
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
|
||||
for (int i = 0; i < 200; ++i)
|
||||
@@ -379,11 +381,11 @@ void FileChannelTest::testPurgeAge()
|
||||
pChannel->log(msg);
|
||||
}
|
||||
File f0(name + ".0");
|
||||
assert (f0.exists());
|
||||
assert(f0.exists());
|
||||
File f1(name + ".1");
|
||||
assert (f1.exists());
|
||||
assert(f1.exists());
|
||||
File f2(name + ".2");
|
||||
assert (f2.exists());
|
||||
assert(f2.exists());
|
||||
|
||||
Thread::sleep(5000);
|
||||
for (int i = 0; i < 50; ++i)
|
||||
@@ -391,7 +393,7 @@ void FileChannelTest::testPurgeAge()
|
||||
pChannel->log(msg);
|
||||
}
|
||||
|
||||
assert (!f2.exists());
|
||||
assert(!f2.exists());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -402,7 +404,63 @@ void FileChannelTest::testPurgeAge()
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::testPurgeCount()
|
||||
void FileChannelTest::noPurgeAge(const std::string& npa)
|
||||
{
|
||||
std::string name = filename();
|
||||
|
||||
try
|
||||
{
|
||||
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
||||
pChannel->setProperty(FileChannel::PROP_ROTATION, "1 K");
|
||||
pChannel->setProperty(FileChannel::PROP_ARCHIVE, "number");
|
||||
pChannel->setProperty(FileChannel::PROP_PURGEAGE, npa);
|
||||
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 f0(name + ".0");
|
||||
assert(f0.exists());
|
||||
File f1(name + ".1");
|
||||
assert(f1.exists());
|
||||
File f2(name + ".2");
|
||||
assert(f2.exists());
|
||||
|
||||
Thread::sleep(5000);
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
pChannel->log(msg);
|
||||
}
|
||||
|
||||
assert(f2.exists());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
remove(name);
|
||||
throw;
|
||||
}
|
||||
remove(name);
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::testPurgeAge()
|
||||
{
|
||||
purgeAge("5 seconds");
|
||||
try
|
||||
{
|
||||
noPurgeAge("0 seconds");
|
||||
fail ("must fail");
|
||||
} catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
noPurgeAge("");
|
||||
noPurgeAge("none");
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::purgeCount(const std::string& pc)
|
||||
{
|
||||
std::string name = filename();
|
||||
try
|
||||
@@ -410,7 +468,7 @@ void FileChannelTest::testPurgeCount()
|
||||
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
||||
pChannel->setProperty(FileChannel::PROP_ROTATION, "1 K");
|
||||
pChannel->setProperty(FileChannel::PROP_ARCHIVE, "number");
|
||||
pChannel->setProperty(FileChannel::PROP_PURGECOUNT, "2");
|
||||
pChannel->setProperty(FileChannel::PROP_PURGECOUNT, pc);
|
||||
pChannel->open();
|
||||
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
|
||||
for (int i = 0; i < 200; ++i)
|
||||
@@ -419,13 +477,12 @@ void FileChannelTest::testPurgeCount()
|
||||
Thread::sleep(50);
|
||||
}
|
||||
File f0(name + ".0");
|
||||
assert (f0.exists());
|
||||
assert(f0.exists());
|
||||
File f1(name + ".1");
|
||||
assert (f1.exists());
|
||||
assert(f1.exists());
|
||||
File f2(name + ".2");
|
||||
assert (!f2.exists());
|
||||
}
|
||||
catch (...)
|
||||
assert(!f2.exists());
|
||||
} catch (...)
|
||||
{
|
||||
remove(name);
|
||||
throw;
|
||||
@@ -434,6 +491,53 @@ void FileChannelTest::testPurgeCount()
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::noPurgeCount(const std::string& npc)
|
||||
{
|
||||
std::string name = filename();
|
||||
try
|
||||
{
|
||||
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
||||
pChannel->setProperty(FileChannel::PROP_ROTATION, "1 K");
|
||||
pChannel->setProperty(FileChannel::PROP_ARCHIVE, "number");
|
||||
pChannel->setProperty(FileChannel::PROP_PURGECOUNT, npc);
|
||||
pChannel->open();
|
||||
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
|
||||
for (int i = 0; i < 200; ++i)
|
||||
{
|
||||
pChannel->log(msg);
|
||||
Thread::sleep(50);
|
||||
}
|
||||
File f0(name + ".0");
|
||||
assert(f0.exists());
|
||||
File f1(name + ".1");
|
||||
assert(f1.exists());
|
||||
File f2(name + ".2");
|
||||
assert(f2.exists());
|
||||
} catch (...)
|
||||
{
|
||||
remove(name);
|
||||
throw;
|
||||
}
|
||||
remove(name);
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::testPurgeCount()
|
||||
{
|
||||
purgeCount("2");
|
||||
try
|
||||
{
|
||||
noPurgeCount("0");
|
||||
fail("must fail");
|
||||
} catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
noPurgeCount("");
|
||||
noPurgeCount("none");
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -463,8 +567,7 @@ void FileChannelTest::remove(const std::string& baseName)
|
||||
{
|
||||
File f(*it);
|
||||
f.remove();
|
||||
}
|
||||
catch (...)
|
||||
} catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -515,6 +618,7 @@ std::string FileChannelTest::rotation(TimeRotation rtype) const
|
||||
break;
|
||||
default:
|
||||
rotation = "";
|
||||
break;
|
||||
}
|
||||
return rotation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user