mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 03:03:23 +02:00
formatting fix and few tests from the old trunk
This commit is contained in:
@@ -57,18 +57,18 @@ class Foundation_API NumberFormatter
|
|||||||
/// an existing string.
|
/// an existing string.
|
||||||
///
|
///
|
||||||
/// Internally, std::sprintf() is used to do the actual
|
/// Internally, std::sprintf() is used to do the actual
|
||||||
/// formatting.
|
/// formatting.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum BoolFormat
|
enum BoolFormat
|
||||||
{
|
{
|
||||||
FMT_TRUE_FALSE,
|
FMT_TRUE_FALSE,
|
||||||
FMT_YES_NO,
|
FMT_YES_NO,
|
||||||
FMT_ON_OFF
|
FMT_ON_OFF
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::string format(int value);
|
static std::string format(int value);
|
||||||
/// Formats an integer value in decimal notation.
|
/// Formats an integer value in decimal notation.
|
||||||
|
|
||||||
static std::string format(int value, int width);
|
static std::string format(int value, int width);
|
||||||
/// Formats an integer value in decimal notation,
|
/// Formats an integer value in decimal notation,
|
||||||
@@ -220,15 +220,15 @@ public:
|
|||||||
|
|
||||||
static std::string format(const void* ptr);
|
static std::string format(const void* ptr);
|
||||||
/// Formats a pointer in an eight (32-bit architectures) or
|
/// Formats a pointer in an eight (32-bit architectures) or
|
||||||
/// sixteen (64-bit architectures) characters wide
|
/// sixteen (64-bit architectures) characters wide
|
||||||
/// field in hexadecimal notation.
|
/// field in hexadecimal notation.
|
||||||
|
|
||||||
static std::string format(bool value, BoolFormat format = FMT_TRUE_FALSE);
|
static std::string format(bool value, BoolFormat format = FMT_TRUE_FALSE);
|
||||||
/// Formats a bool value in decimal/text notation,
|
/// Formats a bool value in decimal/text notation,
|
||||||
/// according to format parameter.
|
/// according to format parameter.
|
||||||
|
|
||||||
static void append(std::string& str, int value);
|
static void append(std::string& str, int value);
|
||||||
/// Formats an integer value in decimal notation.
|
/// Formats an integer value in decimal notation.
|
||||||
|
|
||||||
static void append(std::string& str, int value, int width);
|
static void append(std::string& str, int value, int width);
|
||||||
/// Formats an integer value in decimal notation,
|
/// Formats an integer value in decimal notation,
|
||||||
|
@@ -112,24 +112,24 @@ public:
|
|||||||
|
|
||||||
static bool tryParseFloat(const std::string& s, double& value);
|
static bool tryParseFloat(const std::string& s, double& value);
|
||||||
/// Parses a double value in decimal floating point notation
|
/// Parses a double value in decimal floating point notation
|
||||||
/// from the given string.
|
/// from the given string.
|
||||||
/// Returns true if a valid floating point number has been found,
|
/// Returns true if a valid floating point number has been found,
|
||||||
/// false otherwise.
|
/// false otherwise.
|
||||||
|
|
||||||
static bool parseBool(const std::string& s);
|
static bool parseBool(const std::string& s);
|
||||||
/// Parses a bool value in decimal or string notation
|
/// Parses a bool value in decimal or string notation
|
||||||
/// from the given string.
|
/// from the given string.
|
||||||
/// Valid forms are: "0", "1", "true", "on", false", "yes", "no", "off".
|
/// Valid forms are: "0", "1", "true", "on", false", "yes", "no", "off".
|
||||||
/// String forms are NOT case sensitive.
|
/// String forms are NOT case sensitive.
|
||||||
/// Throws a SyntaxException if the string does not hold a valid bool number
|
/// Throws a SyntaxException if the string does not hold a valid bool number
|
||||||
|
|
||||||
static bool tryParseBool(const std::string& s, bool& value);
|
static bool tryParseBool(const std::string& s, bool& value);
|
||||||
/// Parses a bool value in decimal or string notation
|
/// Parses a bool value in decimal or string notation
|
||||||
/// from the given string.
|
/// from the given string.
|
||||||
/// Valid forms are: "0", "1", "true", "on", false", "yes", "no", "off".
|
/// Valid forms are: "0", "1", "true", "on", false", "yes", "no", "off".
|
||||||
/// String forms are NOT case sensitive.
|
/// String forms are NOT case sensitive.
|
||||||
/// Returns true if a valid bool number has been found,
|
/// Returns true if a valid bool number has been found,
|
||||||
/// false otherwise.
|
/// false otherwise.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -102,9 +102,11 @@ public:
|
|||||||
Notification* waitDequeueNotification();
|
Notification* waitDequeueNotification();
|
||||||
/// Dequeues the next pending notification.
|
/// Dequeues the next pending notification.
|
||||||
/// If no notification is available, waits for a notification
|
/// If no notification is available, waits for a notification
|
||||||
/// to be enqueued.
|
/// to be enqueued.
|
||||||
/// The caller gains ownership of the notification and
|
/// The caller gains ownership of the notification and
|
||||||
/// is expected to release it when done with it.
|
/// is expected to release it when done with it.
|
||||||
|
/// This method returns 0 (null) if wakeUpWaitingThreads()
|
||||||
|
/// has been called by another thread.
|
||||||
///
|
///
|
||||||
/// It is highly recommended that the result is immediately
|
/// It is highly recommended that the result is immediately
|
||||||
/// assigned to a Notification::Ptr, to avoid potential
|
/// assigned to a Notification::Ptr, to avoid potential
|
||||||
@@ -142,7 +144,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
NfQueue _nfQueue;
|
NfQueue _nfQueue;
|
||||||
Event _nfAvailable;
|
Event _nfAvailable;
|
||||||
mutable FastMutex _mutex;
|
mutable FastMutex _mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -38,8 +38,8 @@
|
|||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco
|
||||||
|
{
|
||||||
|
|
||||||
DigestEngine::DigestEngine()
|
DigestEngine::DigestEngine()
|
||||||
{
|
{
|
||||||
@@ -55,50 +55,51 @@ std::string DigestEngine::digestToHex(const Digest& bytes)
|
|||||||
{
|
{
|
||||||
static const char digits[] = "0123456789abcdef";
|
static const char digits[] = "0123456789abcdef";
|
||||||
std::string result;
|
std::string result;
|
||||||
result.reserve(bytes.size()*2);
|
result.reserve(bytes.size() * 2);
|
||||||
for (Digest::const_iterator it = bytes.begin(); it != bytes.end(); ++it)
|
for (Digest::const_iterator it = bytes.begin(); it != bytes.end(); ++it)
|
||||||
{
|
{
|
||||||
unsigned char c = *it;
|
unsigned char c = *it;
|
||||||
result += digits[(c >> 4) & 0xF];
|
result += digits[(c >> 4) & 0xF];
|
||||||
result += digits[c & 0xF];
|
result += digits[c & 0xF];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DigestEngine::Digest DigestEngine::digestFromHex(const std::string& digest)
|
DigestEngine::Digest DigestEngine::digestFromHex(const std::string& digest)
|
||||||
{
|
{
|
||||||
if (digest.size() % 2 != 0)
|
if (digest.size() % 2 != 0)
|
||||||
throw DataFormatException();
|
throw DataFormatException();
|
||||||
Digest result;
|
Digest result;
|
||||||
result.reserve(digest.size()/2);
|
result.reserve(digest.size() / 2);
|
||||||
for (std::size_t i = 0; i < digest.size(); ++i)
|
for (std::size_t i = 0; i < digest.size(); ++i)
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
// first upper 4 bits
|
// first upper 4 bits
|
||||||
if (digest[i] >= '0' && digest[i] <= '9')
|
if (digest[i] >= '0' && digest[i] <= '9')
|
||||||
c = digest[i] - '0';
|
c = digest[i] - '0';
|
||||||
else if (digest[i] >= 'a' && digest[i] <= 'f')
|
else if (digest[i] >= 'a' && digest[i] <= 'f')
|
||||||
c = digest[i] - 'a'+10;
|
c = digest[i] - 'a' + 10;
|
||||||
else if (digest[i] >= 'A' && digest[i] <= 'F')
|
else if (digest[i] >= 'A' && digest[i] <= 'F')
|
||||||
c = digest[i] - 'A'+10;
|
c = digest[i] - 'A' + 10;
|
||||||
else
|
else
|
||||||
throw DataFormatException();
|
throw DataFormatException();
|
||||||
c <<= 4;
|
c <<= 4;
|
||||||
++i;
|
++i;
|
||||||
if (digest[i] >= '0' && digest[i] <= '9')
|
if (digest[i] >= '0' && digest[i] <= '9')
|
||||||
c += digest[i] - '0';
|
c += digest[i] - '0';
|
||||||
else if (digest[i] >= 'a' && digest[i] <= 'f')
|
else if (digest[i] >= 'a' && digest[i] <= 'f')
|
||||||
c += digest[i] - 'a'+10;
|
c += digest[i] - 'a' + 10;
|
||||||
else if (digest[i] >= 'A' && digest[i] <= 'F')
|
else if (digest[i] >= 'A' && digest[i] <= 'F')
|
||||||
c += digest[i] - 'A'+10;
|
c += digest[i] - 'A' + 10;
|
||||||
else
|
else
|
||||||
throw DataFormatException();
|
throw DataFormatException();
|
||||||
|
|
||||||
result.push_back(static_cast<unsigned char>(c));
|
result.push_back(static_cast<unsigned char>(c));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
@@ -125,4 +125,60 @@ StringTokenizer::~StringTokenizer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool StringTokenizer::has(const std::string& token) const
|
||||||
|
{
|
||||||
|
Iterator it = begin();
|
||||||
|
Iterator stop = end();
|
||||||
|
for (; it != stop; ++it)
|
||||||
|
if (*it == token)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::size_t StringTokenizer::find(const std::string& token, std::size_t pos) const
|
||||||
|
{
|
||||||
|
Iterator it = begin();
|
||||||
|
Iterator stop = end();
|
||||||
|
for (it += pos; it != stop; ++it)
|
||||||
|
if (*it == token)
|
||||||
|
return it - begin();
|
||||||
|
|
||||||
|
throw NotFoundException(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::size_t StringTokenizer::replace(const std::string& oldToken, const std::string& newToken, std::size_t pos)
|
||||||
|
{
|
||||||
|
std::size_t count = 0;
|
||||||
|
TokenVec::iterator it = _tokens.begin();
|
||||||
|
TokenVec::iterator stop = _tokens.end();
|
||||||
|
for (it += pos; it != stop; ++it)
|
||||||
|
{
|
||||||
|
if (*it == oldToken)
|
||||||
|
{
|
||||||
|
*it = newToken;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::size_t StringTokenizer::count(const std::string& token) const
|
||||||
|
{
|
||||||
|
std::size_t cnt = 0;
|
||||||
|
Iterator it = begin();
|
||||||
|
Iterator stop = end();
|
||||||
|
for (; it != stop; ++it)
|
||||||
|
if (*it == token)
|
||||||
|
++cnt;
|
||||||
|
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
@@ -38,6 +38,9 @@
|
|||||||
#include "Poco/Bugcheck.h"
|
#include "Poco/Bugcheck.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER < 1400
|
||||||
|
#pragma warning(disable:4800)//forcing value to bool 'true' or 'false'
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Poco;
|
using namespace Poco;
|
||||||
|
|
||||||
@@ -112,9 +115,9 @@ void AnyTest::testVector()
|
|||||||
tmp.push_back(3);
|
tmp.push_back(3);
|
||||||
Any a = tmp;
|
Any a = tmp;
|
||||||
assert (a.type() == typeid(std::vector<int>));
|
assert (a.type() == typeid(std::vector<int>));
|
||||||
std::vector<int>tmp2 = AnyCast<std::vector<int> >(a);
|
std::vector<int> tmp2 = AnyCast<std::vector<int> >(a);
|
||||||
const std::vector<int >& vecCRef = RefAnyCast<std::vector<int> >(a);
|
const std::vector<int>& vecCRef = RefAnyCast<std::vector<int> >(a);
|
||||||
std::vector<int >& vecRef = RefAnyCast<std::vector<int> >(a);
|
std::vector<int>& vecRef = RefAnyCast<std::vector<int> >(a);
|
||||||
vecRef[0] = 0;
|
vecRef[0] = 0;
|
||||||
assert (vecRef[0] == vecCRef[0]);
|
assert (vecRef[0] == vecCRef[0]);
|
||||||
}
|
}
|
||||||
|
@@ -45,8 +45,13 @@ using Poco::DateTimeFormat;
|
|||||||
using Poco::DateTimeFormatter;
|
using Poco::DateTimeFormatter;
|
||||||
|
|
||||||
|
|
||||||
DateTimeFormatterTest::DateTimeFormatterTest(const std::string& name): CppUnit::TestCase(name)
|
DateTimeFormatterTest::DateTimeFormatterTest(const std::string& name)
|
||||||
|
: CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
|
// Linker regresion SF #3288584
|
||||||
|
std::string message;
|
||||||
|
Poco::LocalDateTime now;
|
||||||
|
Poco::DateTimeFormatter::append(message, now, "%H:%M:%S.%i");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -75,13 +80,13 @@ void DateTimeFormatterTest::testISO8601Frac()
|
|||||||
DateTime dt(2005, 1, 8, 12, 30, 00, 12, 34);
|
DateTime dt(2005, 1, 8, 12, 30, 00, 12, 34);
|
||||||
|
|
||||||
std::string str = DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FRAC_FORMAT);
|
std::string str = DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FRAC_FORMAT);
|
||||||
assert (str == "2005-01-08T12:30:00.012034Z");
|
assert(str == "2005-01-08T12:30:00.012034Z");
|
||||||
|
|
||||||
str = DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FRAC_FORMAT, 3600);
|
str = DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FRAC_FORMAT, 3600);
|
||||||
assert (str == "2005-01-08T12:30:00.012034+01:00");
|
assert(str == "2005-01-08T12:30:00.012034+01:00");
|
||||||
|
|
||||||
str = DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FRAC_FORMAT, -3600);
|
str = DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FRAC_FORMAT, -3600);
|
||||||
assert (str == "2005-01-08T12:30:00.012034-01:00");
|
assert(str == "2005-01-08T12:30:00.012034-01:00");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// DigestStreamTest.h
|
// DigestStreamTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/DigestStreamTest.h#1 $
|
// $Id: //poco/1.4/Foundation/testsuite/src/DigestStreamTest.h#1 $
|
||||||
//
|
//
|
||||||
// Definition of the DigestStreamTest class.
|
// Definition of the DigestStreamTest class.
|
||||||
//
|
//
|
||||||
@@ -46,13 +46,13 @@ public:
|
|||||||
DigestStreamTest(const std::string& name);
|
DigestStreamTest(const std::string& name);
|
||||||
~DigestStreamTest();
|
~DigestStreamTest();
|
||||||
|
|
||||||
void testInputStream();
|
void testInputStream();
|
||||||
void testOutputStream1();
|
void testOutputStream1();
|
||||||
void testOutputStream2();
|
void testOutputStream2();
|
||||||
void testToFromHex();
|
void testToFromHex();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
|
@@ -47,6 +47,7 @@
|
|||||||
#include "Poco/DateTimeFormat.h"
|
#include "Poco/DateTimeFormat.h"
|
||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
#include "Poco/DirectoryIterator.h"
|
#include "Poco/DirectoryIterator.h"
|
||||||
|
#include "Poco/Exception.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
@@ -64,6 +65,7 @@ using Poco::LocalDateTime;
|
|||||||
using Poco::DateTimeFormatter;
|
using Poco::DateTimeFormatter;
|
||||||
using Poco::DateTimeFormat;
|
using Poco::DateTimeFormat;
|
||||||
using Poco::DirectoryIterator;
|
using Poco::DirectoryIterator;
|
||||||
|
using Poco::InvalidArgumentException;
|
||||||
|
|
||||||
|
|
||||||
FileChannelTest::FileChannelTest(const std::string& name): CppUnit::TestCase(name)
|
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();
|
std::string name = filename();
|
||||||
try
|
try
|
||||||
@@ -371,7 +373,7 @@ void FileChannelTest::testPurgeAge()
|
|||||||
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
||||||
pChannel->setProperty(FileChannel::PROP_ROTATION, "1 K");
|
pChannel->setProperty(FileChannel::PROP_ROTATION, "1 K");
|
||||||
pChannel->setProperty(FileChannel::PROP_ARCHIVE, "number");
|
pChannel->setProperty(FileChannel::PROP_ARCHIVE, "number");
|
||||||
pChannel->setProperty(FileChannel::PROP_PURGEAGE, "5 seconds");
|
pChannel->setProperty(FileChannel::PROP_PURGEAGE, pa);
|
||||||
pChannel->open();
|
pChannel->open();
|
||||||
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
|
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
|
||||||
for (int i = 0; i < 200; ++i)
|
for (int i = 0; i < 200; ++i)
|
||||||
@@ -379,11 +381,11 @@ void FileChannelTest::testPurgeAge()
|
|||||||
pChannel->log(msg);
|
pChannel->log(msg);
|
||||||
}
|
}
|
||||||
File f0(name + ".0");
|
File f0(name + ".0");
|
||||||
assert (f0.exists());
|
assert(f0.exists());
|
||||||
File f1(name + ".1");
|
File f1(name + ".1");
|
||||||
assert (f1.exists());
|
assert(f1.exists());
|
||||||
File f2(name + ".2");
|
File f2(name + ".2");
|
||||||
assert (f2.exists());
|
assert(f2.exists());
|
||||||
|
|
||||||
Thread::sleep(5000);
|
Thread::sleep(5000);
|
||||||
for (int i = 0; i < 50; ++i)
|
for (int i = 0; i < 50; ++i)
|
||||||
@@ -391,7 +393,7 @@ void FileChannelTest::testPurgeAge()
|
|||||||
pChannel->log(msg);
|
pChannel->log(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (!f2.exists());
|
assert(!f2.exists());
|
||||||
}
|
}
|
||||||
catch (...)
|
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();
|
std::string name = filename();
|
||||||
try
|
try
|
||||||
@@ -410,7 +468,7 @@ void FileChannelTest::testPurgeCount()
|
|||||||
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
||||||
pChannel->setProperty(FileChannel::PROP_ROTATION, "1 K");
|
pChannel->setProperty(FileChannel::PROP_ROTATION, "1 K");
|
||||||
pChannel->setProperty(FileChannel::PROP_ARCHIVE, "number");
|
pChannel->setProperty(FileChannel::PROP_ARCHIVE, "number");
|
||||||
pChannel->setProperty(FileChannel::PROP_PURGECOUNT, "2");
|
pChannel->setProperty(FileChannel::PROP_PURGECOUNT, pc);
|
||||||
pChannel->open();
|
pChannel->open();
|
||||||
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
|
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
|
||||||
for (int i = 0; i < 200; ++i)
|
for (int i = 0; i < 200; ++i)
|
||||||
@@ -419,13 +477,12 @@ void FileChannelTest::testPurgeCount()
|
|||||||
Thread::sleep(50);
|
Thread::sleep(50);
|
||||||
}
|
}
|
||||||
File f0(name + ".0");
|
File f0(name + ".0");
|
||||||
assert (f0.exists());
|
assert(f0.exists());
|
||||||
File f1(name + ".1");
|
File f1(name + ".1");
|
||||||
assert (f1.exists());
|
assert(f1.exists());
|
||||||
File f2(name + ".2");
|
File f2(name + ".2");
|
||||||
assert (!f2.exists());
|
assert(!f2.exists());
|
||||||
}
|
} catch (...)
|
||||||
catch (...)
|
|
||||||
{
|
{
|
||||||
remove(name);
|
remove(name);
|
||||||
throw;
|
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()
|
void FileChannelTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -463,8 +567,7 @@ void FileChannelTest::remove(const std::string& baseName)
|
|||||||
{
|
{
|
||||||
File f(*it);
|
File f(*it);
|
||||||
f.remove();
|
f.remove();
|
||||||
}
|
} catch (...)
|
||||||
catch (...)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -515,6 +618,7 @@ std::string FileChannelTest::rotation(TimeRotation rtype) const
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rotation = "";
|
rotation = "";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return rotation;
|
return rotation;
|
||||||
}
|
}
|
||||||
|
@@ -58,14 +58,14 @@ void FormatTest::testChar()
|
|||||||
{
|
{
|
||||||
char c = 'a';
|
char c = 'a';
|
||||||
std::string s(format("%c", c));
|
std::string s(format("%c", c));
|
||||||
assert (s == "a");
|
assert(s == "a");
|
||||||
s = format("%2c", c);
|
s = format("%2c", c);
|
||||||
assert (s == " a");
|
assert(s == " a");
|
||||||
s = format("%-2c", c);
|
s = format("%-2c", c);
|
||||||
assert (s == "a ");
|
assert(s == "a ");
|
||||||
|
|
||||||
s = format("%c", std::string("foo"));
|
s = format("%c", std::string("foo"));
|
||||||
assert (s == "[ERRFMT]");
|
assert(s == "[ERRFMT]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ void FormatTest::testInt()
|
|||||||
x = 0x42;
|
x = 0x42;
|
||||||
s = format("%#x", x);
|
s = format("%#x", x);
|
||||||
assert (s == "0x42");
|
assert (s == "0x42");
|
||||||
|
|
||||||
s = format("%d", l);
|
s = format("%d", l);
|
||||||
assert (s == "[ERRFMT]");
|
assert (s == "[ERRFMT]");
|
||||||
}
|
}
|
||||||
@@ -292,6 +292,9 @@ void FormatTest::testFloatFix()
|
|||||||
float f = 1.5;
|
float f = 1.5;
|
||||||
s = format("%hf", f);
|
s = format("%hf", f);
|
||||||
assert (s.find("1.50") == 0);
|
assert (s.find("1.50") == 0);
|
||||||
|
|
||||||
|
s = format("%.0f", 1.0);
|
||||||
|
assert (s == "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -357,13 +360,13 @@ void FormatTest::testMultiple()
|
|||||||
void FormatTest::testIndex()
|
void FormatTest::testIndex()
|
||||||
{
|
{
|
||||||
std::string s(format("%[1]d%[0]d", 1, 2));
|
std::string s(format("%[1]d%[0]d", 1, 2));
|
||||||
assert (s == "21");
|
assert(s == "21");
|
||||||
|
|
||||||
s = format("%[5]d%[4]d%[3]d%[2]d%[1]d%[0]d", 1, 2, 3, 4, 5, 6);
|
s = format("%[5]d%[4]d%[3]d%[2]d%[1]d%[0]d", 1, 2, 3, 4, 5, 6);
|
||||||
assert (s == "654321");
|
assert(s == "654321");
|
||||||
|
|
||||||
s = format("%%%[1]d%%%[2]d%%%d", 1, 2, 3);
|
s = format("%%%[1]d%%%[2]d%%%d", 1, 2, 3);
|
||||||
assert (s == "%2%3%1");
|
assert(s == "%2%3%1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/LRUCache.h"
|
#include "Poco/LRUCache.h"
|
||||||
#include "Poco/Bugcheck.h"
|
#include "Poco/Bugcheck.h"
|
||||||
|
#include "Poco/Delegate.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace Poco;
|
using namespace Poco;
|
||||||
@@ -217,6 +218,49 @@ void LRUCacheTest::testDuplicateAdd()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LRUCacheTest::testUpdate()
|
||||||
|
{
|
||||||
|
addCnt = 0;
|
||||||
|
updateCnt = 0;
|
||||||
|
removeCnt = 0;
|
||||||
|
LRUCache<int, int> aCache(3);
|
||||||
|
aCache.Add += delegate(this, &LRUCacheTest::onAdd);
|
||||||
|
aCache.Remove += delegate(this, &LRUCacheTest::onRemove);
|
||||||
|
aCache.Update += delegate(this, &LRUCacheTest::onUpdate);
|
||||||
|
aCache.add(1, 2); // 1 ,one add event
|
||||||
|
assert(addCnt == 1);
|
||||||
|
assert(updateCnt == 0);
|
||||||
|
assert(removeCnt == 0);
|
||||||
|
|
||||||
|
assert(aCache.has(1));
|
||||||
|
assert(*aCache.get(1) == 2);
|
||||||
|
aCache.update(1, 3); // one update event only!
|
||||||
|
assert(addCnt == 1);
|
||||||
|
assert(updateCnt == 1);
|
||||||
|
assert(removeCnt == 0);
|
||||||
|
assert(aCache.has(1));
|
||||||
|
assert(*aCache.get(1) == 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LRUCacheTest::onUpdate(const void* pSender, const Poco::KeyValueArgs<int, int>& args)
|
||||||
|
{
|
||||||
|
++updateCnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LRUCacheTest::onAdd(const void* pSender, const Poco::KeyValueArgs<int, int>& args)
|
||||||
|
{
|
||||||
|
++addCnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LRUCacheTest::onRemove(const void* pSender, const int& args)
|
||||||
|
{
|
||||||
|
++removeCnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void LRUCacheTest::setUp()
|
void LRUCacheTest::setUp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -237,6 +281,7 @@ CppUnit::Test* LRUCacheTest::suite()
|
|||||||
CppUnit_addTest(pSuite, LRUCacheTest, testCacheSize2);
|
CppUnit_addTest(pSuite, LRUCacheTest, testCacheSize2);
|
||||||
CppUnit_addTest(pSuite, LRUCacheTest, testCacheSizeN);
|
CppUnit_addTest(pSuite, LRUCacheTest, testCacheSizeN);
|
||||||
CppUnit_addTest(pSuite, LRUCacheTest, testDuplicateAdd);
|
CppUnit_addTest(pSuite, LRUCacheTest, testDuplicateAdd);
|
||||||
|
CppUnit_addTest(pSuite, LRUCacheTest, testUpdate);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// LRUCacheTest.h
|
// LRUCacheTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/LRUCacheTest.h#1 $
|
// $Id: //poco/Main/Foundation/testsuite/src/LRUCacheTest.h#6 $
|
||||||
//
|
//
|
||||||
// Tests for LRUCache
|
// Tests for LRUCache
|
||||||
//
|
//
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
|
#include "Poco/KeyValueArgs.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -48,13 +49,24 @@ public:
|
|||||||
void testClear();
|
void testClear();
|
||||||
void testCacheSize0();
|
void testCacheSize0();
|
||||||
void testCacheSize1();
|
void testCacheSize1();
|
||||||
void testCacheSize2();
|
void testCacheSize2();
|
||||||
void testCacheSizeN();
|
void testCacheSizeN();
|
||||||
void testDuplicateAdd();
|
void testDuplicateAdd();
|
||||||
|
void testUpdate();
|
||||||
void setUp();
|
|
||||||
void tearDown();
|
void setUp();
|
||||||
static CppUnit::Test* suite();
|
void tearDown();
|
||||||
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onUpdate(const void* pSender, const Poco::KeyValueArgs<int, int>& args);
|
||||||
|
void onAdd(const void* pSender, const Poco::KeyValueArgs<int, int>& args);
|
||||||
|
void onRemove(const void* pSender, const int& args);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int addCnt;
|
||||||
|
int updateCnt;
|
||||||
|
int removeCnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// NumberFormatterTest.cpp
|
// NumberFormatterTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/NumberFormatterTest.cpp#1 $
|
// $Id: //poco/1.4/Foundation/testsuite/src/NumberFormatterTest.cpp#1 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@@ -86,16 +86,16 @@ void NumberFormatterTest::testFormat()
|
|||||||
assert (NumberFormatter::format((void*) 0x12345678) == "0000000012345678");
|
assert (NumberFormatter::format((void*) 0x12345678) == "0000000012345678");
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (NumberFormatter::format(12.25) == "12.25");
|
assert(NumberFormatter::format(12.25) == "12.25");
|
||||||
assert (NumberFormatter::format(12.25, 4) == "12.2500");
|
assert(NumberFormatter::format(12.25, 4) == "12.2500");
|
||||||
assert (NumberFormatter::format(12.25, 8, 4) == " 12.2500");
|
assert(NumberFormatter::format(12.25, 8, 4) == " 12.2500");
|
||||||
|
|
||||||
assert (NumberFormatter::format(true, NumberFormatter::FMT_TRUE_FALSE) == "true");
|
assert(NumberFormatter::format(true, NumberFormatter::FMT_TRUE_FALSE) == "true");
|
||||||
assert (NumberFormatter::format(false, NumberFormatter::FMT_TRUE_FALSE) == "false");
|
assert(NumberFormatter::format(false, NumberFormatter::FMT_TRUE_FALSE) == "false");
|
||||||
assert (NumberFormatter::format(true, NumberFormatter::FMT_YES_NO) == "yes");
|
assert(NumberFormatter::format(true, NumberFormatter::FMT_YES_NO) == "yes");
|
||||||
assert (NumberFormatter::format(false, NumberFormatter::FMT_YES_NO) == "no");
|
assert(NumberFormatter::format(false, NumberFormatter::FMT_YES_NO) == "no");
|
||||||
assert (NumberFormatter::format(true, NumberFormatter::FMT_ON_OFF) == "on");
|
assert(NumberFormatter::format(true, NumberFormatter::FMT_ON_OFF) == "on");
|
||||||
assert (NumberFormatter::format(false, NumberFormatter::FMT_ON_OFF) == "off");
|
assert(NumberFormatter::format(false, NumberFormatter::FMT_ON_OFF) == "off");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -153,15 +153,15 @@ void NumberFormatterTest::testFormatHex()
|
|||||||
|
|
||||||
void NumberFormatterTest::testFormatFloat()
|
void NumberFormatterTest::testFormatFloat()
|
||||||
{
|
{
|
||||||
std::string s(NumberFormatter::format(1.0f));
|
std::string s(NumberFormatter::format(1.0f));
|
||||||
assert (s == "1");
|
assert(s == "1");
|
||||||
s = NumberFormatter::format(0.1f);
|
s = NumberFormatter::format(0.1f);
|
||||||
assert (s == "0.1");
|
assert(s == "0.1");
|
||||||
|
|
||||||
s = NumberFormatter::format(1.0);
|
s = NumberFormatter::format(1.0);
|
||||||
assert (s == "1");
|
assert(s == "1");
|
||||||
s = NumberFormatter::format(0.1);
|
s = NumberFormatter::format(0.1);
|
||||||
assert (s == "0.1");
|
assert(s == "0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -179,10 +179,10 @@ CppUnit::Test* NumberFormatterTest::suite()
|
|||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NumberFormatterTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NumberFormatterTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat);
|
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat);
|
||||||
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat0);
|
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat0);
|
||||||
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatHex);
|
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatHex);
|
||||||
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatFloat);
|
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatFloat);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// NumberParserTest.cpp
|
// NumberParserTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/NumberParserTest.cpp#1 $
|
// $Id: //poco/1.4/Foundation/testsuite/src/NumberParserTest.cpp#1 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@@ -53,47 +53,47 @@ NumberParserTest::~NumberParserTest()
|
|||||||
|
|
||||||
void NumberParserTest::testParse()
|
void NumberParserTest::testParse()
|
||||||
{
|
{
|
||||||
assert (NumberParser::parse("123") == 123);
|
assert(NumberParser::parse("123") == 123);
|
||||||
assert (NumberParser::parse("-123") == -123);
|
assert(NumberParser::parse("-123") == -123);
|
||||||
assert (NumberParser::parseUnsigned("123") == 123);
|
assert(NumberParser::parseUnsigned("123") == 123);
|
||||||
assert (NumberParser::parseHex("12AB") == 0x12ab);
|
assert(NumberParser::parseHex("12AB") == 0x12ab);
|
||||||
|
|
||||||
assert (NumberParser::parseBool("0") == false);
|
assert(NumberParser::parseBool("0") == false);
|
||||||
assert (NumberParser::parseBool("FALSE") == false);
|
assert(NumberParser::parseBool("FALSE") == false);
|
||||||
assert (NumberParser::parseBool("no") == false);
|
assert(NumberParser::parseBool("no") == false);
|
||||||
assert (NumberParser::parseBool("1") == true);
|
assert(NumberParser::parseBool("1") == true);
|
||||||
assert (NumberParser::parseBool("True") == true);
|
assert(NumberParser::parseBool("True") == true);
|
||||||
assert (NumberParser::parseBool("YeS") == true);
|
assert(NumberParser::parseBool("YeS") == true);
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
assert (NumberParser::parse64("123") == 123);
|
assert(NumberParser::parse64("123") == 123);
|
||||||
assert (NumberParser::parse64("-123") == -123);
|
assert(NumberParser::parse64("-123") == -123);
|
||||||
assert (NumberParser::parseUnsigned64("123") == 123);
|
assert(NumberParser::parseUnsigned64("123") == 123);
|
||||||
assert (NumberParser::parseHex64("12AB") == 0x12ab);
|
assert(NumberParser::parseHex64("12AB") == 0x12ab);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assertEqualDelta (12.34, NumberParser::parseFloat("12.34"), 0.01);
|
assertEqualDelta(12.34, NumberParser::parseFloat("12.34"), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NumberParserTest::testParseError()
|
void NumberParserTest::testParseError()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NumberParser::parse("");
|
NumberParser::parse("");
|
||||||
NumberParser::parseBool("");
|
NumberParser::parseBool("");
|
||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
catch (SyntaxException&)
|
catch (SyntaxException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NumberParser::parse("asd");
|
NumberParser::parse("asd");
|
||||||
NumberParser::parseBool("asd");
|
NumberParser::parseBool("asd");
|
||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
catch (SyntaxException&)
|
catch (SyntaxException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// StringTokenizerTest.h
|
// StringTokenizerTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/StringTokenizerTest.h#1 $
|
// $Id: //poco/svn/Foundation/testsuite/src/StringTokenizerTest.h#2 $
|
||||||
//
|
//
|
||||||
// Definition of the StringTokenizerTest class.
|
// Definition of the StringTokenizerTest class.
|
||||||
//
|
//
|
||||||
@@ -44,13 +44,14 @@ class StringTokenizerTest: public CppUnit::TestCase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StringTokenizerTest(const std::string& name);
|
StringTokenizerTest(const std::string& name);
|
||||||
~StringTokenizerTest();
|
~StringTokenizerTest();
|
||||||
|
|
||||||
void testStringTokenizer();
|
void testStringTokenizer();
|
||||||
|
void testFind();
|
||||||
void testFind();
|
void testFind();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user