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:
@@ -105,6 +105,8 @@ public:
|
||||
/// 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
|
||||
|
@@ -38,8 +38,8 @@
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
|
||||
DigestEngine::DigestEngine()
|
||||
{
|
||||
@@ -102,3 +102,4 @@ DigestEngine::Digest DigestEngine::digestFromHex(const std::string& digest)
|
||||
|
||||
|
||||
} // 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
|
||||
|
||||
|
@@ -38,6 +38,9 @@
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include <vector>
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1400
|
||||
#pragma warning(disable:4800)//forcing value to bool 'true' or 'false'
|
||||
#endif
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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)
|
||||
@@ -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)
|
||||
@@ -424,8 +482,7 @@ void FileChannelTest::testPurgeCount()
|
||||
assert(f1.exists());
|
||||
File f2(name + ".2");
|
||||
assert(!f2.exists());
|
||||
}
|
||||
catch (...)
|
||||
} 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;
|
||||
}
|
||||
|
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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<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()
|
||||
{
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
@@ -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"
|
||||
|
||||
|
||||
@@ -51,10 +52,21 @@ public:
|
||||
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<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 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
|
||||
void testStringTokenizer();
|
||||
void testFind();
|
||||
void testFind();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
Reference in New Issue
Block a user