From 0ad8b3c9244c6293ff91ecbf6bf441d83b78d661 Mon Sep 17 00:00:00 2001 From: Marian Krivos Date: Sun, 29 Apr 2012 11:04:08 +0000 Subject: [PATCH] formatting fix and few tests from the old trunk --- Foundation/include/Poco/NumberFormatter.h | 32 ++--- Foundation/include/Poco/NumberParser.h | 32 ++--- .../include/Poco/TimedNotificationQueue.h | 6 +- Foundation/src/DigestEngine.cpp | 69 ++++----- Foundation/src/StringTokenizer.cpp | 56 ++++++++ Foundation/testsuite/src/AnyTest.cpp | 9 +- .../testsuite/src/DateTimeFormatterTest.cpp | 13 +- Foundation/testsuite/src/DigestStreamTest.h | 14 +- Foundation/testsuite/src/FileChannelTest.cpp | 134 ++++++++++++++++-- Foundation/testsuite/src/FormatTest.cpp | 21 +-- Foundation/testsuite/src/LRUCacheTest.cpp | 45 ++++++ Foundation/testsuite/src/LRUCacheTest.h | 28 ++-- .../testsuite/src/NumberFormatterTest.cpp | 48 +++---- Foundation/testsuite/src/NumberParserTest.cpp | 60 ++++---- .../testsuite/src/StringTokenizerTest.h | 11 +- 15 files changed, 405 insertions(+), 173 deletions(-) diff --git a/Foundation/include/Poco/NumberFormatter.h b/Foundation/include/Poco/NumberFormatter.h index 4f65e5f9d..b3367a0a0 100644 --- a/Foundation/include/Poco/NumberFormatter.h +++ b/Foundation/include/Poco/NumberFormatter.h @@ -57,18 +57,18 @@ class Foundation_API NumberFormatter /// an existing string. /// /// Internally, std::sprintf() is used to do the actual - /// formatting. + /// formatting. { public: - enum BoolFormat - { - FMT_TRUE_FALSE, - FMT_YES_NO, - FMT_ON_OFF - }; + enum BoolFormat + { + FMT_TRUE_FALSE, + FMT_YES_NO, + FMT_ON_OFF + }; - static std::string format(int value); - /// Formats an integer value in decimal notation. + static std::string format(int value); + /// Formats an integer value in decimal notation. static std::string format(int value, int width); /// Formats an integer value in decimal notation, @@ -220,15 +220,15 @@ public: static std::string format(const void* ptr); /// Formats a pointer in an eight (32-bit architectures) or - /// sixteen (64-bit architectures) characters wide - /// field in hexadecimal notation. + /// sixteen (64-bit architectures) characters wide + /// field in hexadecimal notation. - static std::string format(bool value, BoolFormat format = FMT_TRUE_FALSE); - /// Formats a bool value in decimal/text notation, - /// according to format parameter. + static std::string format(bool value, BoolFormat format = FMT_TRUE_FALSE); + /// Formats a bool value in decimal/text notation, + /// according to format parameter. - static void append(std::string& str, int value); - /// Formats an integer value in decimal notation. + static void append(std::string& str, int value); + /// Formats an integer value in decimal notation. static void append(std::string& str, int value, int width); /// Formats an integer value in decimal notation, diff --git a/Foundation/include/Poco/NumberParser.h b/Foundation/include/Poco/NumberParser.h index 1d79241d6..08d7b320d 100644 --- a/Foundation/include/Poco/NumberParser.h +++ b/Foundation/include/Poco/NumberParser.h @@ -112,24 +112,24 @@ public: static bool tryParseFloat(const std::string& s, double& value); /// Parses a double value in decimal floating point notation - /// from the given string. - /// Returns true if a valid floating point number has been found, - /// false otherwise. + /// from the given string. + /// Returns true if a valid floating point number has been found, + /// false otherwise. - static bool parseBool(const std::string& s); - /// Parses a bool value in decimal or string notation - /// from the given string. - /// Valid forms are: "0", "1", "true", "on", false", "yes", "no", "off". - /// String forms are NOT case sensitive. - /// Throws a SyntaxException if the string does not hold a valid bool number + static bool parseBool(const std::string& s); + /// Parses a bool value in decimal or string notation + /// from the given string. + /// Valid forms are: "0", "1", "true", "on", false", "yes", "no", "off". + /// String forms are NOT case sensitive. + /// Throws a SyntaxException if the string does not hold a valid bool number - static bool tryParseBool(const std::string& s, bool& value); - /// Parses a bool value in decimal or string notation - /// from the given string. - /// Valid forms are: "0", "1", "true", "on", false", "yes", "no", "off". - /// String forms are NOT case sensitive. - /// Returns true if a valid bool number has been found, - /// false otherwise. + static bool tryParseBool(const std::string& s, bool& value); + /// Parses a bool value in decimal or string notation + /// from the given string. + /// Valid forms are: "0", "1", "true", "on", false", "yes", "no", "off". + /// String forms are NOT case sensitive. + /// Returns true if a valid bool number has been found, + /// false otherwise. }; diff --git a/Foundation/include/Poco/TimedNotificationQueue.h b/Foundation/include/Poco/TimedNotificationQueue.h index 0f22f3097..aa5d71d31 100644 --- a/Foundation/include/Poco/TimedNotificationQueue.h +++ b/Foundation/include/Poco/TimedNotificationQueue.h @@ -102,9 +102,11 @@ public: Notification* waitDequeueNotification(); /// Dequeues the next pending notification. /// If no notification is available, waits for a notification - /// to be enqueued. + /// to be enqueued. /// The caller gains ownership of the notification and /// 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 /// assigned to a Notification::Ptr, to avoid potential @@ -142,7 +144,7 @@ protected: private: NfQueue _nfQueue; - Event _nfAvailable; + Event _nfAvailable; mutable FastMutex _mutex; }; diff --git a/Foundation/src/DigestEngine.cpp b/Foundation/src/DigestEngine.cpp index 7d606a8e1..b5595533c 100644 --- a/Foundation/src/DigestEngine.cpp +++ b/Foundation/src/DigestEngine.cpp @@ -38,8 +38,8 @@ #include "Poco/Exception.h" -namespace Poco { - +namespace Poco +{ DigestEngine::DigestEngine() { @@ -55,50 +55,51 @@ std::string DigestEngine::digestToHex(const Digest& bytes) { static const char digits[] = "0123456789abcdef"; std::string result; - result.reserve(bytes.size()*2); + result.reserve(bytes.size() * 2); for (Digest::const_iterator it = bytes.begin(); it != bytes.end(); ++it) { unsigned char c = *it; result += digits[(c >> 4) & 0xF]; result += digits[c & 0xF]; - } - return result; + } + return result; } DigestEngine::Digest DigestEngine::digestFromHex(const std::string& digest) { - if (digest.size() % 2 != 0) - throw DataFormatException(); - Digest result; - result.reserve(digest.size()/2); - for (std::size_t i = 0; i < digest.size(); ++i) - { - int c = 0; - // first upper 4 bits - if (digest[i] >= '0' && digest[i] <= '9') - c = digest[i] - '0'; - else if (digest[i] >= 'a' && digest[i] <= 'f') - c = digest[i] - 'a'+10; - else if (digest[i] >= 'A' && digest[i] <= 'F') - c = digest[i] - 'A'+10; - else - throw DataFormatException(); - c <<= 4; - ++i; - if (digest[i] >= '0' && digest[i] <= '9') - c += digest[i] - '0'; - else if (digest[i] >= 'a' && digest[i] <= 'f') - c += digest[i] - 'a'+10; - else if (digest[i] >= 'A' && digest[i] <= 'F') - c += digest[i] - 'A'+10; - else - throw DataFormatException(); + if (digest.size() % 2 != 0) + throw DataFormatException(); + Digest result; + result.reserve(digest.size() / 2); + for (std::size_t i = 0; i < digest.size(); ++i) + { + int c = 0; + // first upper 4 bits + if (digest[i] >= '0' && digest[i] <= '9') + c = digest[i] - '0'; + else if (digest[i] >= 'a' && digest[i] <= 'f') + c = digest[i] - 'a' + 10; + else if (digest[i] >= 'A' && digest[i] <= 'F') + c = digest[i] - 'A' + 10; + else + throw DataFormatException(); + c <<= 4; + ++i; + if (digest[i] >= '0' && digest[i] <= '9') + c += digest[i] - '0'; + else if (digest[i] >= 'a' && digest[i] <= 'f') + c += digest[i] - 'a' + 10; + else if (digest[i] >= 'A' && digest[i] <= 'F') + c += digest[i] - 'A' + 10; + else + throw DataFormatException(); - result.push_back(static_cast(c)); - } - return result; + result.push_back(static_cast(c)); + } + return result; } } // namespace Poco + diff --git a/Foundation/src/StringTokenizer.cpp b/Foundation/src/StringTokenizer.cpp index b1d7872e6..48508693a 100644 --- a/Foundation/src/StringTokenizer.cpp +++ b/Foundation/src/StringTokenizer.cpp @@ -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 + diff --git a/Foundation/testsuite/src/AnyTest.cpp b/Foundation/testsuite/src/AnyTest.cpp index 8aa3ef5c0..c1a6b211c 100644 --- a/Foundation/testsuite/src/AnyTest.cpp +++ b/Foundation/testsuite/src/AnyTest.cpp @@ -38,6 +38,9 @@ #include "Poco/Bugcheck.h" #include +#if defined(_MSC_VER) && _MSC_VER < 1400 + #pragma warning(disable:4800)//forcing value to bool 'true' or 'false' +#endif using namespace Poco; @@ -112,9 +115,9 @@ void AnyTest::testVector() tmp.push_back(3); Any a = tmp; assert (a.type() == typeid(std::vector)); - std::vectortmp2 = AnyCast >(a); - const std::vector& vecCRef = RefAnyCast >(a); - std::vector& vecRef = RefAnyCast >(a); + std::vector tmp2 = AnyCast >(a); + const std::vector& vecCRef = RefAnyCast >(a); + std::vector& vecRef = RefAnyCast >(a); vecRef[0] = 0; assert (vecRef[0] == vecCRef[0]); } diff --git a/Foundation/testsuite/src/DateTimeFormatterTest.cpp b/Foundation/testsuite/src/DateTimeFormatterTest.cpp index e891df1c4..7a71e74cf 100644 --- a/Foundation/testsuite/src/DateTimeFormatterTest.cpp +++ b/Foundation/testsuite/src/DateTimeFormatterTest.cpp @@ -45,8 +45,13 @@ using Poco::DateTimeFormat; 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); 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); - 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); - assert (str == "2005-01-08T12:30:00.012034-01:00"); + assert(str == "2005-01-08T12:30:00.012034-01:00"); } diff --git a/Foundation/testsuite/src/DigestStreamTest.h b/Foundation/testsuite/src/DigestStreamTest.h index 53d0f688b..1833e8235 100644 --- a/Foundation/testsuite/src/DigestStreamTest.h +++ b/Foundation/testsuite/src/DigestStreamTest.h @@ -1,7 +1,7 @@ // // 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. // @@ -46,13 +46,13 @@ public: DigestStreamTest(const std::string& name); ~DigestStreamTest(); - void testInputStream(); - void testOutputStream1(); - void testOutputStream2(); - void testToFromHex(); + void testInputStream(); + void testOutputStream1(); + void testOutputStream2(); + void testToFromHex(); - void setUp(); - void tearDown(); + void setUp(); + void tearDown(); static CppUnit::Test* suite(); diff --git a/Foundation/testsuite/src/FileChannelTest.cpp b/Foundation/testsuite/src/FileChannelTest.cpp index 7ed701489..4ea77c5c5 100644 --- a/Foundation/testsuite/src/FileChannelTest.cpp +++ b/Foundation/testsuite/src/FileChannelTest.cpp @@ -47,6 +47,7 @@ #include "Poco/DateTimeFormat.h" #include "Poco/NumberFormatter.h" #include "Poco/DirectoryIterator.h" +#include "Poco/Exception.h" #include @@ -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 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 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 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 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; } diff --git a/Foundation/testsuite/src/FormatTest.cpp b/Foundation/testsuite/src/FormatTest.cpp index fba532730..7b9f15c21 100644 --- a/Foundation/testsuite/src/FormatTest.cpp +++ b/Foundation/testsuite/src/FormatTest.cpp @@ -58,14 +58,14 @@ void FormatTest::testChar() { char c = 'a'; std::string s(format("%c", c)); - assert (s == "a"); + assert(s == "a"); s = format("%2c", c); - assert (s == " a"); + assert(s == " a"); s = format("%-2c", c); - assert (s == "a "); - + assert(s == "a "); + s = format("%c", std::string("foo")); - assert (s == "[ERRFMT]"); + assert(s == "[ERRFMT]"); } @@ -181,7 +181,7 @@ void FormatTest::testInt() x = 0x42; s = format("%#x", x); assert (s == "0x42"); - + s = format("%d", l); assert (s == "[ERRFMT]"); } @@ -292,6 +292,9 @@ void FormatTest::testFloatFix() float f = 1.5; s = format("%hf", f); assert (s.find("1.50") == 0); + + s = format("%.0f", 1.0); + assert (s == "1"); } @@ -357,13 +360,13 @@ void FormatTest::testMultiple() void FormatTest::testIndex() { 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); - assert (s == "654321"); + assert(s == "654321"); s = format("%%%[1]d%%%[2]d%%%d", 1, 2, 3); - assert (s == "%2%3%1"); + assert(s == "%2%3%1"); } diff --git a/Foundation/testsuite/src/LRUCacheTest.cpp b/Foundation/testsuite/src/LRUCacheTest.cpp index 5b9865d36..a65a5f2ad 100644 --- a/Foundation/testsuite/src/LRUCacheTest.cpp +++ b/Foundation/testsuite/src/LRUCacheTest.cpp @@ -36,6 +36,7 @@ #include "Poco/Exception.h" #include "Poco/LRUCache.h" #include "Poco/Bugcheck.h" +#include "Poco/Delegate.h" using namespace Poco; @@ -217,6 +218,49 @@ void LRUCacheTest::testDuplicateAdd() } +void LRUCacheTest::testUpdate() +{ + addCnt = 0; + updateCnt = 0; + removeCnt = 0; + LRUCache 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& args) +{ + ++updateCnt; +} + + +void LRUCacheTest::onAdd(const void* pSender, const Poco::KeyValueArgs& args) +{ + ++addCnt; +} + + +void LRUCacheTest::onRemove(const void* pSender, const int& args) +{ + ++removeCnt; +} + + void LRUCacheTest::setUp() { } @@ -237,6 +281,7 @@ CppUnit::Test* LRUCacheTest::suite() CppUnit_addTest(pSuite, LRUCacheTest, testCacheSize2); CppUnit_addTest(pSuite, LRUCacheTest, testCacheSizeN); CppUnit_addTest(pSuite, LRUCacheTest, testDuplicateAdd); + CppUnit_addTest(pSuite, LRUCacheTest, testUpdate); return pSuite; } diff --git a/Foundation/testsuite/src/LRUCacheTest.h b/Foundation/testsuite/src/LRUCacheTest.h index e9eef9966..0ae8b643a 100644 --- a/Foundation/testsuite/src/LRUCacheTest.h +++ b/Foundation/testsuite/src/LRUCacheTest.h @@ -1,7 +1,7 @@ // // LRUCacheTest.h // -// $Id: //poco/1.4/Foundation/testsuite/src/LRUCacheTest.h#1 $ +// $Id: //poco/Main/Foundation/testsuite/src/LRUCacheTest.h#6 $ // // Tests for LRUCache // @@ -36,6 +36,7 @@ #include "Poco/Foundation.h" +#include "Poco/KeyValueArgs.h" #include "CppUnit/TestCase.h" @@ -48,13 +49,24 @@ public: void testClear(); void testCacheSize0(); void testCacheSize1(); - void testCacheSize2(); - void testCacheSizeN(); - void testDuplicateAdd(); - - void setUp(); - void tearDown(); - static CppUnit::Test* suite(); + void testCacheSize2(); + void testCacheSizeN(); + void testDuplicateAdd(); + void testUpdate(); + + void setUp(); + void tearDown(); + static CppUnit::Test* suite(); + +private: + void onUpdate(const void* pSender, const Poco::KeyValueArgs& args); + void onAdd(const void* pSender, const Poco::KeyValueArgs& args); + void onRemove(const void* pSender, const int& args); + +private: + int addCnt; + int updateCnt; + int removeCnt; }; diff --git a/Foundation/testsuite/src/NumberFormatterTest.cpp b/Foundation/testsuite/src/NumberFormatterTest.cpp index 60d8bb8e2..b7e3054ab 100644 --- a/Foundation/testsuite/src/NumberFormatterTest.cpp +++ b/Foundation/testsuite/src/NumberFormatterTest.cpp @@ -1,7 +1,7 @@ // // 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. // and Contributors. @@ -86,16 +86,16 @@ void NumberFormatterTest::testFormat() assert (NumberFormatter::format((void*) 0x12345678) == "0000000012345678"); } - assert (NumberFormatter::format(12.25) == "12.25"); - assert (NumberFormatter::format(12.25, 4) == "12.2500"); - assert (NumberFormatter::format(12.25, 8, 4) == " 12.2500"); + assert(NumberFormatter::format(12.25) == "12.25"); + assert(NumberFormatter::format(12.25, 4) == "12.2500"); + assert(NumberFormatter::format(12.25, 8, 4) == " 12.2500"); - assert (NumberFormatter::format(true, NumberFormatter::FMT_TRUE_FALSE) == "true"); - assert (NumberFormatter::format(false, NumberFormatter::FMT_TRUE_FALSE) == "false"); - assert (NumberFormatter::format(true, NumberFormatter::FMT_YES_NO) == "yes"); - assert (NumberFormatter::format(false, NumberFormatter::FMT_YES_NO) == "no"); - assert (NumberFormatter::format(true, NumberFormatter::FMT_ON_OFF) == "on"); - assert (NumberFormatter::format(false, NumberFormatter::FMT_ON_OFF) == "off"); + assert(NumberFormatter::format(true, NumberFormatter::FMT_TRUE_FALSE) == "true"); + assert(NumberFormatter::format(false, NumberFormatter::FMT_TRUE_FALSE) == "false"); + assert(NumberFormatter::format(true, NumberFormatter::FMT_YES_NO) == "yes"); + assert(NumberFormatter::format(false, NumberFormatter::FMT_YES_NO) == "no"); + assert(NumberFormatter::format(true, NumberFormatter::FMT_ON_OFF) == "on"); + assert(NumberFormatter::format(false, NumberFormatter::FMT_ON_OFF) == "off"); } @@ -153,15 +153,15 @@ void NumberFormatterTest::testFormatHex() void NumberFormatterTest::testFormatFloat() { - std::string s(NumberFormatter::format(1.0f)); - assert (s == "1"); - s = NumberFormatter::format(0.1f); - assert (s == "0.1"); - - s = NumberFormatter::format(1.0); - assert (s == "1"); - s = NumberFormatter::format(0.1); - assert (s == "0.1"); + std::string s(NumberFormatter::format(1.0f)); + assert(s == "1"); + s = NumberFormatter::format(0.1f); + assert(s == "0.1"); + + s = NumberFormatter::format(1.0); + assert(s == "1"); + s = NumberFormatter::format(0.1); + assert(s == "0.1"); } @@ -179,10 +179,10 @@ CppUnit::Test* NumberFormatterTest::suite() { CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NumberFormatterTest"); - CppUnit_addTest(pSuite, NumberFormatterTest, testFormat); - CppUnit_addTest(pSuite, NumberFormatterTest, testFormat0); - CppUnit_addTest(pSuite, NumberFormatterTest, testFormatHex); - CppUnit_addTest(pSuite, NumberFormatterTest, testFormatFloat); + CppUnit_addTest(pSuite, NumberFormatterTest, testFormat); + CppUnit_addTest(pSuite, NumberFormatterTest, testFormat0); + CppUnit_addTest(pSuite, NumberFormatterTest, testFormatHex); + CppUnit_addTest(pSuite, NumberFormatterTest, testFormatFloat); - return pSuite; + return pSuite; } diff --git a/Foundation/testsuite/src/NumberParserTest.cpp b/Foundation/testsuite/src/NumberParserTest.cpp index a4d2743f1..2c40b73cf 100644 --- a/Foundation/testsuite/src/NumberParserTest.cpp +++ b/Foundation/testsuite/src/NumberParserTest.cpp @@ -1,7 +1,7 @@ // // 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. // and Contributors. @@ -53,47 +53,47 @@ NumberParserTest::~NumberParserTest() void NumberParserTest::testParse() { - assert (NumberParser::parse("123") == 123); - assert (NumberParser::parse("-123") == -123); - assert (NumberParser::parseUnsigned("123") == 123); - assert (NumberParser::parseHex("12AB") == 0x12ab); + assert(NumberParser::parse("123") == 123); + assert(NumberParser::parse("-123") == -123); + assert(NumberParser::parseUnsigned("123") == 123); + assert(NumberParser::parseHex("12AB") == 0x12ab); - assert (NumberParser::parseBool("0") == false); - assert (NumberParser::parseBool("FALSE") == false); - assert (NumberParser::parseBool("no") == false); - assert (NumberParser::parseBool("1") == true); - assert (NumberParser::parseBool("True") == true); - assert (NumberParser::parseBool("YeS") == true); + assert(NumberParser::parseBool("0") == false); + assert(NumberParser::parseBool("FALSE") == false); + assert(NumberParser::parseBool("no") == false); + assert(NumberParser::parseBool("1") == true); + assert(NumberParser::parseBool("True") == true); + assert(NumberParser::parseBool("YeS") == true); #if defined(POCO_HAVE_INT64) - assert (NumberParser::parse64("123") == 123); - assert (NumberParser::parse64("-123") == -123); - assert (NumberParser::parseUnsigned64("123") == 123); - assert (NumberParser::parseHex64("12AB") == 0x12ab); + assert(NumberParser::parse64("123") == 123); + assert(NumberParser::parse64("-123") == -123); + assert(NumberParser::parseUnsigned64("123") == 123); + assert(NumberParser::parseHex64("12AB") == 0x12ab); #endif - assertEqualDelta (12.34, NumberParser::parseFloat("12.34"), 0.01); + assertEqualDelta(12.34, NumberParser::parseFloat("12.34"), 0.01); } void NumberParserTest::testParseError() { - try - { - NumberParser::parse(""); - NumberParser::parseBool(""); - failmsg("must throw SyntaxException"); - } - catch (SyntaxException&) + try + { + NumberParser::parse(""); + NumberParser::parseBool(""); + failmsg("must throw SyntaxException"); + } + catch (SyntaxException&) { } - try - { - NumberParser::parse("asd"); - NumberParser::parseBool("asd"); - failmsg("must throw SyntaxException"); - } - catch (SyntaxException&) + try + { + NumberParser::parse("asd"); + NumberParser::parseBool("asd"); + failmsg("must throw SyntaxException"); + } + catch (SyntaxException&) { } diff --git a/Foundation/testsuite/src/StringTokenizerTest.h b/Foundation/testsuite/src/StringTokenizerTest.h index 344c42d77..d271aa502 100644 --- a/Foundation/testsuite/src/StringTokenizerTest.h +++ b/Foundation/testsuite/src/StringTokenizerTest.h @@ -1,7 +1,7 @@ // // 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. // @@ -44,13 +44,14 @@ class StringTokenizerTest: public CppUnit::TestCase { public: StringTokenizerTest(const std::string& name); - ~StringTokenizerTest(); + ~StringTokenizerTest(); - void testStringTokenizer(); + void testStringTokenizer(); + void testFind(); void testFind(); - void setUp(); - void tearDown(); + void setUp(); + void tearDown(); static CppUnit::Test* suite();