mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-09-16 09:17:17 +02:00
Update POCO library.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Event.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Environment.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::ActiveDispatcher;
|
||||
@@ -25,6 +27,7 @@ using Poco::ActiveStarter;
|
||||
using Poco::Thread;
|
||||
using Poco::Event;
|
||||
using Poco::Exception;
|
||||
using Poco::Environment;
|
||||
|
||||
|
||||
namespace
|
||||
@@ -39,11 +42,11 @@ namespace
|
||||
testVoidIn(this, &ActiveObject::testVoidInImpl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~ActiveObject()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ActiveMethod<int, int, ActiveObject, ActiveStarter<ActiveDispatcher> > testMethod;
|
||||
|
||||
ActiveMethod<void, int, ActiveObject, ActiveStarter<ActiveDispatcher> > testVoid;
|
||||
@@ -51,12 +54,12 @@ namespace
|
||||
ActiveMethod<void, void, ActiveObject, ActiveStarter<ActiveDispatcher> > testVoidInOut;
|
||||
|
||||
ActiveMethod<int, void, ActiveObject, ActiveStarter<ActiveDispatcher> > testVoidIn;
|
||||
|
||||
|
||||
void cont()
|
||||
{
|
||||
_continue.set();
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
int testMethodImpl(const int& n)
|
||||
{
|
||||
@@ -81,7 +84,7 @@ namespace
|
||||
_continue.wait();
|
||||
return 123;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Event _continue;
|
||||
};
|
||||
@@ -195,6 +198,12 @@ void ActiveDispatcherTest::testVoidIn()
|
||||
}
|
||||
|
||||
|
||||
void ActiveDispatcherTest::testActiveDispatcher()
|
||||
{
|
||||
std::cout << "(disabled on TSAN runs)";
|
||||
}
|
||||
|
||||
|
||||
void ActiveDispatcherTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -209,13 +218,19 @@ CppUnit::Test* ActiveDispatcherTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ActiveDispatcherTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testWait);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testWaitInterval);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testTryWait);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testFailure);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testVoid);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testVoidIn);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testVoidInOut);
|
||||
// see https://github.com/pocoproject/poco/pull/3617
|
||||
if (!Environment::has("TSAN_OPTIONS"))
|
||||
{
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testWait);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testWaitInterval);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testTryWait);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testFailure);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testVoid);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testVoidIn);
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testVoidInOut);
|
||||
}
|
||||
else
|
||||
CppUnit_addTest(pSuite, ActiveDispatcherTest, testActiveDispatcher);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ public:
|
||||
void testVoid();
|
||||
void testVoidIn();
|
||||
void testVoidInOut();
|
||||
void testActiveDispatcher();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
@@ -41,11 +41,11 @@ namespace
|
||||
testVoidIn(this,&ActiveObject::testVoidInImpl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~ActiveObject()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IntIntType testMethod;
|
||||
|
||||
VoidIntType testVoid;
|
||||
@@ -53,12 +53,12 @@ namespace
|
||||
VoidVoidType testVoidInOut;
|
||||
|
||||
IntVoidType testVoidIn;
|
||||
|
||||
|
||||
void cont()
|
||||
{
|
||||
_continue.set();
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
int testMethodImpl(const int& n)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ namespace
|
||||
_continue.wait();
|
||||
return 123;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Event _continue;
|
||||
};
|
||||
|
@@ -24,21 +24,21 @@ namespace
|
||||
class ActiveObject
|
||||
{
|
||||
public:
|
||||
ActiveObject():
|
||||
ActiveObject():
|
||||
_activity(this, &ActiveObject::run),
|
||||
_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~ActiveObject()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Activity<ActiveObject>& activity()
|
||||
{
|
||||
return _activity;
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt64 count() const
|
||||
{
|
||||
return _count;
|
||||
@@ -47,7 +47,7 @@ namespace
|
||||
protected:
|
||||
void run()
|
||||
{
|
||||
while (!_activity.isStopped())
|
||||
while (!_activity.isStopped())
|
||||
++_count;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace
|
||||
Poco::UInt64 _count;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
ActivityTest::ActivityTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
|
216
vendor/POCO/Foundation/testsuite/src/AnyTest.cpp
vendored
216
vendor/POCO/Foundation/testsuite/src/AnyTest.cpp
vendored
@@ -13,8 +13,10 @@
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Any.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1400
|
||||
@@ -50,7 +52,7 @@ AnyTest::~AnyTest()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testDefaultCtor()
|
||||
void AnyTest::testAnyDefaultCtor()
|
||||
{
|
||||
const Any value;
|
||||
|
||||
@@ -60,7 +62,7 @@ void AnyTest::testDefaultCtor()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testConvertingCtor()
|
||||
void AnyTest::testAnyConvertingCtor()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any value = text;
|
||||
@@ -74,7 +76,7 @@ void AnyTest::testConvertingCtor()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testCopyCtor()
|
||||
void AnyTest::testAnyCopyCtor()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any original = text, copy = original;
|
||||
@@ -87,7 +89,7 @@ void AnyTest::testCopyCtor()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testCopyAssign()
|
||||
void AnyTest::testAnyCopyAssign()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any original = text, copy;
|
||||
@@ -109,7 +111,7 @@ void AnyTest::testCopyAssign()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testConvertingAssign()
|
||||
void AnyTest::testAnyConvertingAssign()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any value;
|
||||
@@ -125,7 +127,7 @@ void AnyTest::testConvertingAssign()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testCastToReference()
|
||||
void AnyTest::testAnyCastToReference()
|
||||
{
|
||||
Any a(137);
|
||||
const Any b(a);
|
||||
@@ -166,7 +168,7 @@ void AnyTest::testCastToReference()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testBadCast()
|
||||
void AnyTest::testAnyBadCast()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any value = text;
|
||||
@@ -180,10 +182,35 @@ void AnyTest::testBadCast()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testSwap()
|
||||
void AnyTest::testAnySwap()
|
||||
{
|
||||
Any empty1, empty2;
|
||||
assertTrue (empty1.empty());
|
||||
assertTrue (empty2.empty());
|
||||
empty1.swap(empty2);
|
||||
assertTrue (empty1.empty());
|
||||
assertTrue (empty2.empty());
|
||||
|
||||
std::string text = "test message";
|
||||
empty1 = text;
|
||||
assertTrue (!empty1.empty());
|
||||
assertTrue (empty2.empty());
|
||||
assertTrue (text == AnyCast<std::string>(empty1));
|
||||
|
||||
empty1.swap(empty2);
|
||||
assertTrue (empty1.empty());
|
||||
assertTrue (!empty2.empty());
|
||||
assertTrue (text == AnyCast<std::string>(empty2));
|
||||
|
||||
Any original = text, swapped;
|
||||
#ifdef POCO_NO_SOO
|
||||
assertFalse (original.local());
|
||||
#else
|
||||
assertTrue (original.local());
|
||||
#endif
|
||||
assertFalse (original.empty());
|
||||
assertFalse (swapped.local());
|
||||
assertTrue (swapped.empty());
|
||||
std::string* originalPtr = AnyCast<std::string>(&original);
|
||||
Any* swapResult = &original.swap(swapped);
|
||||
|
||||
@@ -192,14 +219,84 @@ void AnyTest::testSwap()
|
||||
assertTrue (swapped.type() == typeid(std::string));
|
||||
assertTrue (text == AnyCast<std::string>(swapped));
|
||||
assertTrue (0 != originalPtr);
|
||||
#ifdef POCO_NO_SOO // pointers only match when heap-allocated
|
||||
assertTrue (originalPtr == AnyCast<std::string>(&swapped));
|
||||
#endif
|
||||
assertTrue (swapResult == &original);
|
||||
|
||||
struct BigObject
|
||||
{
|
||||
Poco::UInt64 one = 1;
|
||||
Poco::UInt64 two = 2;
|
||||
Poco::UInt64 three = 3;
|
||||
Poco::UInt64 four = 4;
|
||||
Poco::UInt64 five = 5;
|
||||
Poco::UInt64 six = 6;
|
||||
Poco::UInt64 seven = 7;
|
||||
Poco::UInt64 eight = 8;
|
||||
Poco::UInt64 nine = 9;
|
||||
|
||||
bool operator==(const BigObject& other)
|
||||
{
|
||||
return one == other.one &&
|
||||
two == other.two &&
|
||||
three == other.three &&
|
||||
four == other.four &&
|
||||
five == other.five &&
|
||||
six == other.six &&
|
||||
seven == other.seven &&
|
||||
eight == other.eight &&
|
||||
nine == other.nine;
|
||||
}
|
||||
};
|
||||
|
||||
poco_assert (sizeof(BigObject) > POCO_SMALL_OBJECT_SIZE);
|
||||
|
||||
BigObject bigObject;
|
||||
Any bigOriginal = bigObject, swappedBig;
|
||||
assertFalse (bigOriginal.local());
|
||||
assertFalse (bigOriginal.empty());
|
||||
assertFalse (swappedBig.local());
|
||||
assertTrue (swappedBig.empty());
|
||||
BigObject* bigPtr = AnyCast<BigObject>(&bigOriginal);
|
||||
Any* swapBigResult = &bigOriginal.swap(swappedBig);
|
||||
|
||||
assertTrue (bigOriginal.empty());
|
||||
assertTrue (!swappedBig.empty());
|
||||
assertTrue (swappedBig.type() == typeid(BigObject));
|
||||
assertTrue (bigObject == AnyCast<BigObject>(swappedBig));
|
||||
assertTrue (0 != bigPtr);
|
||||
assertTrue (swapBigResult == &bigOriginal);
|
||||
|
||||
// assure proper assignment behavior after swapping
|
||||
original = text;
|
||||
bigOriginal = bigObject;
|
||||
#ifdef POCO_NO_SOO
|
||||
assertFalse (original.local());
|
||||
#else
|
||||
assertTrue (original.local());
|
||||
#endif
|
||||
assertFalse (bigOriginal.local());
|
||||
|
||||
Any temp = original;
|
||||
#ifdef POCO_NO_SOO
|
||||
assertFalse (temp.local());
|
||||
#else
|
||||
assertTrue (temp.local());
|
||||
#endif
|
||||
|
||||
original = bigOriginal;
|
||||
assertTrue (bigObject == AnyCast<BigObject>(original));
|
||||
assertFalse (original.local());
|
||||
|
||||
bigOriginal = temp;
|
||||
assertTrue (text == AnyCast<std::string>(bigOriginal));
|
||||
#ifdef POCO_NO_SOO
|
||||
assertFalse (bigOriginal.local());
|
||||
#else
|
||||
assertTrue (bigOriginal.local());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testEmptyCopy()
|
||||
void AnyTest::testAnyEmptyCopy()
|
||||
{
|
||||
const Any null;
|
||||
Any copied = null, assigned;
|
||||
@@ -211,10 +308,12 @@ void AnyTest::testEmptyCopy()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testInt()
|
||||
void AnyTest::testAnyInt()
|
||||
{
|
||||
Any e;
|
||||
assertTrue (e.empty());
|
||||
e = 0;
|
||||
assertFalse (e.empty());
|
||||
|
||||
Any a = 13;
|
||||
assertTrue (a.type() == typeid(int));
|
||||
@@ -235,7 +334,7 @@ void AnyTest::testInt()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testComplexType()
|
||||
void AnyTest::testAnyComplexType()
|
||||
{
|
||||
SomeClass str(13,std::string("hello"));
|
||||
Any a = str;
|
||||
@@ -251,7 +350,7 @@ void AnyTest::testComplexType()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testVector()
|
||||
void AnyTest::testAnyVector()
|
||||
{
|
||||
std::vector<int> tmp;
|
||||
tmp.push_back(1);
|
||||
@@ -272,6 +371,68 @@ void AnyTest::testVector()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testPlaceholder()
|
||||
{
|
||||
#ifndef POCO_NO_SOO
|
||||
Placeholder<char> ph;
|
||||
assertTrue(ph.isEmpty());
|
||||
assertFalse(ph.isLocal());
|
||||
|
||||
char c = *ph.assign<char, char>(1);
|
||||
assertTrue(1 == c);
|
||||
assertFalse(ph.isEmpty());
|
||||
assertTrue(ph.isLocal());
|
||||
|
||||
ph.erase();
|
||||
assertTrue(ph.isEmpty());
|
||||
assertFalse(ph.isLocal());
|
||||
|
||||
Placeholder<int> phi;
|
||||
assertTrue(phi.isEmpty());
|
||||
assertFalse(phi.isLocal());
|
||||
|
||||
int i = *phi.assign<int, int>(0);
|
||||
assertTrue(0 == i);
|
||||
assertFalse(phi.isEmpty());
|
||||
assertTrue(phi.isLocal());
|
||||
|
||||
phi.erase();
|
||||
assertTrue(phi.isEmpty());
|
||||
assertFalse(phi.isLocal());
|
||||
|
||||
Placeholder<std::shared_ptr<int>> sph;
|
||||
assertTrue(sph.isEmpty());
|
||||
assertFalse(sph.isLocal());
|
||||
|
||||
i = **sph.assign<std::shared_ptr<int>, int*>(new int(1));
|
||||
assertTrue(1 == i);
|
||||
assertFalse(sph.isEmpty());
|
||||
assertTrue(sph.isLocal());
|
||||
|
||||
Placeholder<Poco::SharedPtr<int>> psph;
|
||||
assertTrue(psph.isEmpty());
|
||||
assertFalse(psph.isLocal());
|
||||
|
||||
i = **psph.assign<Poco::SharedPtr<int>, int*>(new int(2));
|
||||
assertTrue(2 == i);
|
||||
assertFalse(psph.isEmpty());
|
||||
assertTrue(psph.isLocal());
|
||||
|
||||
Placeholder<std::vector<int>> vph;
|
||||
assertTrue(vph.isEmpty());
|
||||
assertFalse(vph.isLocal());
|
||||
|
||||
std::vector<int> inv{1,2,3};
|
||||
std::vector<int> outv = *vph.assign<std::vector<int>, std::vector<int>>(inv);
|
||||
assertTrue(inv == outv);
|
||||
assertFalse(vph.isEmpty());
|
||||
assertTrue(vph.isLocal());
|
||||
|
||||
// ...
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -286,18 +447,19 @@ CppUnit::Test* AnyTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AnyTest");
|
||||
|
||||
CppUnit_addTest(pSuite, AnyTest, testConvertingCtor);
|
||||
CppUnit_addTest(pSuite, AnyTest, testDefaultCtor);
|
||||
CppUnit_addTest(pSuite, AnyTest, testCopyCtor);
|
||||
CppUnit_addTest(pSuite, AnyTest, testCopyAssign);
|
||||
CppUnit_addTest(pSuite, AnyTest, testConvertingAssign);
|
||||
CppUnit_addTest(pSuite, AnyTest, testBadCast);
|
||||
CppUnit_addTest(pSuite, AnyTest, testSwap);
|
||||
CppUnit_addTest(pSuite, AnyTest, testEmptyCopy);
|
||||
CppUnit_addTest(pSuite, AnyTest, testCastToReference);
|
||||
CppUnit_addTest(pSuite, AnyTest, testInt);
|
||||
CppUnit_addTest(pSuite, AnyTest, testComplexType);
|
||||
CppUnit_addTest(pSuite, AnyTest, testVector);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyConvertingCtor);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyDefaultCtor);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyCopyCtor);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyCopyAssign);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyConvertingAssign);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyBadCast);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnySwap);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyEmptyCopy);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyCastToReference);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyInt);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyComplexType);
|
||||
CppUnit_addTest(pSuite, AnyTest, testAnyVector);
|
||||
CppUnit_addTest(pSuite, AnyTest, testPlaceholder);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
28
vendor/POCO/Foundation/testsuite/src/AnyTest.h
vendored
28
vendor/POCO/Foundation/testsuite/src/AnyTest.h
vendored
@@ -23,20 +23,22 @@ public:
|
||||
AnyTest(const std::string& name);
|
||||
~AnyTest();
|
||||
|
||||
void testConvertingCtor();
|
||||
void testDefaultCtor();
|
||||
void testCopyCtor();
|
||||
void testCopyAssign();
|
||||
void testConvertingAssign();
|
||||
void testBadCast();
|
||||
void testSwap();
|
||||
void testEmptyCopy();
|
||||
void testCastToReference();
|
||||
void testAnyConvertingCtor();
|
||||
void testAnyDefaultCtor();
|
||||
void testAnyCopyCtor();
|
||||
void testAnyCopyAssign();
|
||||
void testAnyConvertingAssign();
|
||||
void testAnyBadCast();
|
||||
void testAnySwap();
|
||||
void testAnyEmptyCopy();
|
||||
void testAnyCastToReference();
|
||||
|
||||
void testAnyInt();
|
||||
void testAnyComplexType();
|
||||
void testAnyVector();
|
||||
|
||||
void testPlaceholder();
|
||||
|
||||
void testInt();
|
||||
void testComplexType();
|
||||
void testVector();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
static CppUnit::Test* suite();
|
||||
|
@@ -90,7 +90,7 @@ void ArrayTest::testOperations()
|
||||
}
|
||||
|
||||
// swap
|
||||
Array b;
|
||||
Array b;
|
||||
b.assign(10);
|
||||
for(int i=0; i<SIZE; i++){
|
||||
assertTrue (a[i] == 100);
|
||||
@@ -226,6 +226,6 @@ CppUnit::Test* ArrayTest::suite()
|
||||
CppUnit_addTest(pSuite, ArrayTest, testIterator);
|
||||
CppUnit_addTest(pSuite, ArrayTest, testAlgorithm);
|
||||
CppUnit_addTest(pSuite, ArrayTest, testMultiLevelArray);
|
||||
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -26,39 +26,39 @@ namespace
|
||||
{
|
||||
++_count;
|
||||
}
|
||||
|
||||
|
||||
void duplicate()
|
||||
{
|
||||
++_rc;
|
||||
}
|
||||
|
||||
|
||||
void release()
|
||||
{
|
||||
if (--_rc == 0)
|
||||
delete this;
|
||||
}
|
||||
|
||||
|
||||
int rc() const
|
||||
{
|
||||
return _rc;
|
||||
}
|
||||
|
||||
|
||||
static int count()
|
||||
{
|
||||
return _count;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
~TestObj()
|
||||
{
|
||||
--_count;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
int _rc;
|
||||
static int _count;
|
||||
};
|
||||
|
||||
|
||||
int TestObj::_count = 0;
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,7 @@ public:
|
||||
void testOverwriteDelegate();
|
||||
void testAsyncNotify();
|
||||
void testNullMutex();
|
||||
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
static CppUnit::Test* suite();
|
||||
@@ -71,7 +71,7 @@ protected:
|
||||
|
||||
int getCount() const;
|
||||
private:
|
||||
int _count;
|
||||
std::atomic<int> _count;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -87,7 +87,7 @@ void BinaryReaderWriterTest::write(BinaryWriter& writer)
|
||||
writer << (unsigned) 123456;
|
||||
writer << (long) -1234567890;
|
||||
writer << (unsigned long) 1234567890;
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
writer << (Int64) -1234567890;
|
||||
writer << (UInt64) 1234567890;
|
||||
@@ -95,13 +95,13 @@ void BinaryReaderWriterTest::write(BinaryWriter& writer)
|
||||
|
||||
writer << (float) 1.5;
|
||||
writer << (double) -1.5;
|
||||
|
||||
|
||||
writer << "foo";
|
||||
writer << "";
|
||||
|
||||
|
||||
writer << std::string("bar");
|
||||
writer << std::string();
|
||||
|
||||
|
||||
writer.write7BitEncoded((UInt32) 100);
|
||||
writer.write7BitEncoded((UInt32) 1000);
|
||||
writer.write7BitEncoded((UInt32) 10000);
|
||||
@@ -115,7 +115,7 @@ void BinaryReaderWriterTest::write(BinaryWriter& writer)
|
||||
writer.write7BitEncoded((UInt64) 100000);
|
||||
writer.write7BitEncoded((UInt64) 1000000);
|
||||
#endif
|
||||
|
||||
|
||||
std::vector<int> vec;
|
||||
vec.push_back(1);
|
||||
vec.push_back(2);
|
||||
@@ -133,7 +133,7 @@ void BinaryReaderWriterTest::read(BinaryReader& reader)
|
||||
assertTrue (b);
|
||||
reader >> b;
|
||||
assertTrue (!b);
|
||||
|
||||
|
||||
char c;
|
||||
reader >> c;
|
||||
assertTrue (c == 'a');
|
||||
@@ -166,7 +166,7 @@ void BinaryReaderWriterTest::read(BinaryReader& reader)
|
||||
Int64 int64v;
|
||||
reader >> int64v;
|
||||
assertTrue (int64v == -1234567890);
|
||||
|
||||
|
||||
UInt64 uint64v;
|
||||
reader >> uint64v;
|
||||
assertTrue (uint64v == 1234567890);
|
||||
@@ -175,11 +175,11 @@ void BinaryReaderWriterTest::read(BinaryReader& reader)
|
||||
float floatv;
|
||||
reader >> floatv;
|
||||
assertTrue (floatv == 1.5);
|
||||
|
||||
|
||||
double doublev;
|
||||
reader >> doublev;
|
||||
assertTrue (doublev == -1.5);
|
||||
|
||||
|
||||
std::string str;
|
||||
reader >> str;
|
||||
assertTrue (str == "foo");
|
||||
@@ -189,7 +189,7 @@ void BinaryReaderWriterTest::read(BinaryReader& reader)
|
||||
assertTrue (str == "bar");
|
||||
reader >> str;
|
||||
assertTrue (str == "");
|
||||
|
||||
|
||||
UInt32 uint32v;
|
||||
reader.read7BitEncoded(uint32v);
|
||||
assertTrue (uint32v == 100);
|
||||
|
@@ -122,7 +122,7 @@ void ByteOrderTest::testByteOrderBigEndian()
|
||||
assertTrue (norm == flip);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
Int16 norm = 4;
|
||||
Int16 flip = ByteOrder::fromBigEndian(norm);
|
||||
@@ -203,7 +203,7 @@ void ByteOrderTest::testByteOrderBigEndian()
|
||||
assertTrue (norm == flip);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
Int16 norm = 4;
|
||||
Int16 flip = ByteOrder::fromBigEndian(norm);
|
||||
@@ -290,7 +290,7 @@ void ByteOrderTest::testByteOrderLittleEndian()
|
||||
assertTrue (norm == flip);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
Int16 norm = 4;
|
||||
Int16 flip = ByteOrder::toLittleEndian(norm);
|
||||
@@ -371,7 +371,7 @@ void ByteOrderTest::testByteOrderLittleEndian()
|
||||
assertTrue (norm == flip);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
Int16 norm = 4;
|
||||
Int16 flip = ByteOrder::fromLittleEndian(norm);
|
||||
@@ -458,7 +458,7 @@ void ByteOrderTest::testByteOrderNetwork()
|
||||
assertTrue (norm == flip);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
Int16 norm = 4;
|
||||
Int16 flip = ByteOrder::fromNetwork(norm);
|
||||
@@ -539,7 +539,7 @@ void ByteOrderTest::testByteOrderNetwork()
|
||||
assertTrue (norm == flip);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
Int16 norm = 4;
|
||||
Int16 flip = ByteOrder::fromNetwork(norm);
|
||||
|
@@ -31,6 +31,8 @@ using Poco::StreamChannel;
|
||||
using Poco::Formatter;
|
||||
using Poco::Message;
|
||||
using Poco::AutoPtr;
|
||||
using Poco::Thread;
|
||||
using Poco::Runnable;
|
||||
|
||||
|
||||
class SimpleFormatter: public Formatter
|
||||
@@ -45,6 +47,32 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class LogRunnable : public Runnable
|
||||
{
|
||||
public:
|
||||
LogRunnable(AutoPtr<AsyncChannel> pAsync):
|
||||
_pAsync(pAsync),
|
||||
_stop(false)
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
Message msg;
|
||||
while (!_stop) _pAsync->log(msg);
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
_stop = true;
|
||||
}
|
||||
|
||||
private:
|
||||
AutoPtr<AsyncChannel> _pAsync;
|
||||
std::atomic<bool> _stop;
|
||||
};
|
||||
|
||||
|
||||
ChannelTest::ChannelTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
@@ -71,12 +99,17 @@ void ChannelTest::testAsync()
|
||||
{
|
||||
AutoPtr<TestChannel> pChannel = new TestChannel;
|
||||
AutoPtr<AsyncChannel> pAsync = new AsyncChannel(pChannel);
|
||||
LogRunnable lr(pAsync);
|
||||
pAsync->open();
|
||||
Thread t;
|
||||
t.start(lr);
|
||||
Message msg;
|
||||
pAsync->log(msg);
|
||||
pAsync->log(msg);
|
||||
pAsync->close();
|
||||
assertTrue (pChannel->list().size() == 2);
|
||||
lr.stop();
|
||||
t.join();
|
||||
assertTrue (pChannel->list().size() >= 2);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "Poco/ClassLoader.h"
|
||||
#include "Poco/Manifest.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "TestPlugin.h"
|
||||
|
||||
|
||||
@@ -39,15 +40,16 @@ void ClassLoaderTest::testClassLoader1()
|
||||
{
|
||||
std::string path = "TestLibrary";
|
||||
path.append(SharedLibrary::suffix());
|
||||
|
||||
Poco::Path libraryPath = Poco::Path::current();
|
||||
libraryPath.append(path);
|
||||
ClassLoader<TestPlugin> cl;
|
||||
|
||||
assertTrue (cl.begin() == cl.end());
|
||||
assertNullPtr (cl.findClass("PluginA"));
|
||||
assertNullPtr (cl.findManifest(path));
|
||||
|
||||
assertTrue (!cl.isLibraryLoaded(path));
|
||||
|
||||
assertNullPtr (cl.findManifest(libraryPath.toString()));
|
||||
|
||||
assertTrue (!cl.isLibraryLoaded(libraryPath.toString()));
|
||||
|
||||
try
|
||||
{
|
||||
const ClassLoader<TestPlugin>::Meta& POCO_UNUSED meta = cl.classFor("PluginA");
|
||||
@@ -63,7 +65,7 @@ void ClassLoaderTest::testClassLoader1()
|
||||
|
||||
try
|
||||
{
|
||||
const ClassLoader<TestPlugin>::Manif& POCO_UNUSED manif = cl.manifestFor(path);
|
||||
const ClassLoader<TestPlugin>::Manif& POCO_UNUSED manif = cl.manifestFor(libraryPath.toString());
|
||||
fail("not found - must throw exception");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
@@ -80,26 +82,27 @@ void ClassLoaderTest::testClassLoader2()
|
||||
{
|
||||
std::string path = "TestLibrary";
|
||||
path.append(SharedLibrary::suffix());
|
||||
|
||||
Poco::Path libraryPath = Poco::Path::current();
|
||||
libraryPath.append(path);
|
||||
ClassLoader<TestPlugin> cl;
|
||||
cl.loadLibrary(path);
|
||||
cl.loadLibrary(libraryPath.toString());
|
||||
|
||||
assertTrue (cl.begin() != cl.end());
|
||||
assertNotNullPtr (cl.findClass("PluginA"));
|
||||
assertNotNullPtr (cl.findClass("PluginB"));
|
||||
assertNotNullPtr (cl.findClass("PluginC"));
|
||||
assertNotNullPtr (cl.findManifest(path));
|
||||
|
||||
assertTrue (cl.isLibraryLoaded(path));
|
||||
assertTrue (cl.manifestFor(path).size() == 3);
|
||||
|
||||
assertNotNullPtr (cl.findManifest(libraryPath.toString()));
|
||||
|
||||
assertTrue (cl.isLibraryLoaded(libraryPath.toString()));
|
||||
assertTrue (cl.manifestFor(libraryPath.toString()).size() == 3);
|
||||
|
||||
ClassLoader<TestPlugin>::Iterator it = cl.begin();
|
||||
assertTrue (it != cl.end());
|
||||
assertTrue (it->first == path);
|
||||
assertTrue (it->first == libraryPath.toString());
|
||||
assertTrue (it->second->size() == 3);
|
||||
++it;
|
||||
assertTrue (it == cl.end());
|
||||
|
||||
|
||||
TestPlugin* pPluginA = cl.classFor("PluginA").create();
|
||||
assertTrue (pPluginA->name() == "PluginA");
|
||||
assertTrue (!cl.classFor("PluginA").isAutoDelete(pPluginA));
|
||||
@@ -108,18 +111,18 @@ void ClassLoaderTest::testClassLoader2()
|
||||
TestPlugin* pPluginB = cl.classFor("PluginB").create();
|
||||
assertTrue (pPluginB->name() == "PluginB");
|
||||
delete pPluginB;
|
||||
|
||||
|
||||
pPluginB = cl.create("PluginB");
|
||||
assertTrue (pPluginB->name() == "PluginB");
|
||||
delete pPluginB;
|
||||
|
||||
|
||||
assertTrue (cl.canCreate("PluginA"));
|
||||
assertTrue (cl.canCreate("PluginB"));
|
||||
assertTrue (!cl.canCreate("PluginC"));
|
||||
|
||||
TestPlugin& pluginC = cl.instance("PluginC");
|
||||
assertTrue (pluginC.name() == "PluginC");
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
TestPlugin& POCO_UNUSED plgB = cl.instance("PluginB");
|
||||
@@ -128,7 +131,7 @@ void ClassLoaderTest::testClassLoader2()
|
||||
catch (InvalidAccessException&)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
TestPlugin* POCO_UNUSED pPluginC = cl.create("PluginC");
|
||||
@@ -147,7 +150,7 @@ void ClassLoaderTest::testClassLoader2()
|
||||
catch (InvalidAccessException&)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const AbstractMetaObject<TestPlugin>& meta1 = cl.classFor("PluginC");
|
||||
assertTrue (meta1.isAutoDelete(&(meta1.instance())));
|
||||
|
||||
@@ -162,7 +165,7 @@ void ClassLoaderTest::testClassLoader2()
|
||||
meta2.destroy(pPlugin);
|
||||
assertTrue (!meta2.isAutoDelete(pPlugin));
|
||||
|
||||
cl.unloadLibrary(path);
|
||||
cl.unloadLibrary(libraryPath.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -170,23 +173,24 @@ void ClassLoaderTest::testClassLoader3()
|
||||
{
|
||||
std::string path = "TestLibrary";
|
||||
path.append(SharedLibrary::suffix());
|
||||
|
||||
Poco::Path libraryPath = Poco::Path::current();
|
||||
libraryPath.append(path);
|
||||
ClassLoader<TestPlugin> cl;
|
||||
cl.loadLibrary(path);
|
||||
cl.loadLibrary(path);
|
||||
cl.unloadLibrary(path);
|
||||
|
||||
assertTrue (cl.manifestFor(path).size() == 3);
|
||||
|
||||
cl.loadLibrary(libraryPath.toString());
|
||||
cl.loadLibrary(libraryPath.toString());
|
||||
cl.unloadLibrary(libraryPath.toString());
|
||||
|
||||
assertTrue (cl.manifestFor(libraryPath.toString()).size() == 3);
|
||||
|
||||
ClassLoader<TestPlugin>::Iterator it = cl.begin();
|
||||
assertTrue (it != cl.end());
|
||||
assertTrue (it->first == path);
|
||||
assertTrue (it->first == libraryPath.toString());
|
||||
assertTrue (it->second->size() == 3);
|
||||
++it;
|
||||
assertTrue (it == cl.end());
|
||||
|
||||
cl.unloadLibrary(path);
|
||||
assertNullPtr (cl.findManifest(path));
|
||||
|
||||
cl.unloadLibrary(libraryPath.toString());
|
||||
assertNullPtr (cl.findManifest(libraryPath.toString()));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -48,15 +48,15 @@ void ClockTest::testClock()
|
||||
assertTrue (t2 <= t3);
|
||||
Clock::ClockDiff d = (t2 - t1);
|
||||
assertTrue (d >= 180000 && d <= 300000);
|
||||
|
||||
|
||||
Clock::ClockDiff acc = Clock::accuracy();
|
||||
assertTrue (acc > 0 && acc < Clock::resolution());
|
||||
std::cout << "Clock accuracy: " << acc << std::endl;
|
||||
|
||||
|
||||
t1.swap(t2);
|
||||
assertTrue (t1 > t2);
|
||||
t2.swap(t1);
|
||||
|
||||
|
||||
Clock now;
|
||||
Thread::sleep(201);
|
||||
assertTrue (now.elapsed() >= 200000);
|
||||
|
@@ -36,7 +36,7 @@ namespace
|
||||
_mutex(mutex)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void run()
|
||||
{
|
||||
_mutex.lock();
|
||||
@@ -44,18 +44,18 @@ namespace
|
||||
_mutex.unlock();
|
||||
_ran = true;
|
||||
}
|
||||
|
||||
|
||||
bool ran() const
|
||||
{
|
||||
return _ran;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
bool _ran;
|
||||
Condition& _cond;
|
||||
Mutex& _mutex;
|
||||
};
|
||||
|
||||
|
||||
class TryWaitRunnable: public Runnable
|
||||
{
|
||||
public:
|
||||
@@ -65,7 +65,7 @@ namespace
|
||||
_mutex(mutex)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void run()
|
||||
{
|
||||
_mutex.lock();
|
||||
@@ -75,12 +75,12 @@ namespace
|
||||
}
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
bool ran() const
|
||||
{
|
||||
return _ran;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
bool _ran;
|
||||
Condition& _cond;
|
||||
@@ -106,26 +106,26 @@ void ConditionTest::testSignal()
|
||||
Mutex mtx;
|
||||
WaitRunnable r1(cond, mtx);
|
||||
WaitRunnable r2(cond, mtx);
|
||||
|
||||
|
||||
Thread t1;
|
||||
Thread t2;
|
||||
|
||||
|
||||
t1.start(r1);
|
||||
Thread::sleep(200);
|
||||
t2.start(r2);
|
||||
|
||||
|
||||
assertTrue (!r1.ran());
|
||||
assertTrue (!r2.ran());
|
||||
|
||||
|
||||
cond.signal();
|
||||
|
||||
|
||||
t1.join();
|
||||
assertTrue (r1.ran());
|
||||
|
||||
|
||||
assertTrue (!t2.tryJoin(200));
|
||||
|
||||
|
||||
cond.signal();
|
||||
|
||||
|
||||
t2.join();
|
||||
|
||||
assertTrue (r2.ran());
|
||||
@@ -139,33 +139,33 @@ void ConditionTest::testBroadcast()
|
||||
WaitRunnable r1(cond, mtx);
|
||||
WaitRunnable r2(cond, mtx);
|
||||
TryWaitRunnable r3(cond, mtx);
|
||||
|
||||
|
||||
Thread t1;
|
||||
Thread t2;
|
||||
Thread t3;
|
||||
|
||||
|
||||
t1.start(r1);
|
||||
Thread::sleep(200);
|
||||
t2.start(r2);
|
||||
Thread::sleep(200);
|
||||
t3.start(r3);
|
||||
|
||||
|
||||
assertTrue (!r1.ran());
|
||||
assertTrue (!r2.ran());
|
||||
assertTrue (!r3.ran());
|
||||
|
||||
|
||||
cond.signal();
|
||||
t1.join();
|
||||
|
||||
|
||||
assertTrue (r1.ran());
|
||||
assertTrue (!t2.tryJoin(500));
|
||||
assertTrue (!t3.tryJoin(500));
|
||||
|
||||
|
||||
cond.broadcast();
|
||||
|
||||
|
||||
t2.join();
|
||||
t3.join();
|
||||
|
||||
|
||||
assertTrue (r2.ran());
|
||||
assertTrue (r3.ran());
|
||||
}
|
||||
|
@@ -14,10 +14,11 @@
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Timespan.h"
|
||||
|
||||
|
||||
using Poco::DateTime;
|
||||
using Poco::Timestamp;
|
||||
using Poco::Timespan;
|
||||
using Poco::DateTimeFormat;
|
||||
using Poco::DateTimeFormatter;
|
||||
@@ -68,6 +69,22 @@ void DateTimeFormatterTest::testISO8601Frac()
|
||||
}
|
||||
|
||||
|
||||
void DateTimeFormatterTest::testISO8601Timestamp()
|
||||
{
|
||||
DateTime dt(1582, 10, 15, 1, 2, 34, 56, 78);
|
||||
Timestamp ts = dt.timestamp();
|
||||
|
||||
std::string str = DateTimeFormatter::format(ts, DateTimeFormat::ISO8601_FRAC_FORMAT);
|
||||
assertTrue (str == "1582-10-15T01:02:34.056078Z");
|
||||
|
||||
DateTime preGregorian(1580, 1, 1, 1, 2, 34, 56, 78);
|
||||
ts = preGregorian.timestamp();
|
||||
|
||||
str = DateTimeFormatter::format(ts, DateTimeFormat::ISO8601_FRAC_FORMAT);
|
||||
assertTrue (str == "1580-01-01T01:02:34.056078Z");
|
||||
}
|
||||
|
||||
|
||||
void DateTimeFormatterTest::testRFC822()
|
||||
{
|
||||
DateTime dt(2005, 1, 8, 12, 30, 00);
|
||||
@@ -191,7 +208,7 @@ void DateTimeFormatterTest::testTimespan()
|
||||
Timespan ts4(0, 24, 60, 60, 1001000);
|
||||
str = DateTimeFormatter::format(ts4);
|
||||
assertTrue (str == "1d 01:01:01.001");
|
||||
|
||||
|
||||
Timespan ts5(2, 11, 30, 20, 0);
|
||||
str = DateTimeFormatter::format(ts5, "%h %m %s");
|
||||
assertTrue (str == "59 3570 214220");
|
||||
@@ -214,6 +231,7 @@ CppUnit::Test* DateTimeFormatterTest::suite()
|
||||
|
||||
CppUnit_addTest(pSuite, DateTimeFormatterTest, testISO8601);
|
||||
CppUnit_addTest(pSuite, DateTimeFormatterTest, testISO8601Frac);
|
||||
CppUnit_addTest(pSuite, DateTimeFormatterTest, testISO8601Timestamp);
|
||||
CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC822);
|
||||
CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC1123);
|
||||
CppUnit_addTest(pSuite, DateTimeFormatterTest, testHTTP);
|
||||
|
@@ -26,6 +26,7 @@ public:
|
||||
|
||||
void testISO8601();
|
||||
void testISO8601Frac();
|
||||
void testISO8601Timestamp();
|
||||
void testRFC822();
|
||||
void testRFC1123();
|
||||
void testHTTP();
|
||||
@@ -35,7 +36,7 @@ public:
|
||||
void testSORTABLE();
|
||||
void testCustom();
|
||||
void testTimespan();
|
||||
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
|
@@ -392,7 +392,7 @@ void DateTimeParserTest::testRFC850()
|
||||
assertTrue (dt.minute() == 30);
|
||||
assertTrue (dt.second() == 0);
|
||||
assertTrue (tzd == -3600);
|
||||
|
||||
|
||||
dt = DateTimeParser::parse(DateTimeFormat::RFC850_FORMAT, "Wed, 12-Sep-73 02:01:12 CEST", tzd);
|
||||
assertTrue (dt.year() == 1973);
|
||||
assertTrue (dt.month() == 9);
|
||||
@@ -484,7 +484,7 @@ void DateTimeParserTest::testCustom()
|
||||
assertTrue (dt.minute() == 0);
|
||||
assertTrue (dt.second() == 0);
|
||||
assertTrue (tzd == 0);
|
||||
|
||||
|
||||
dt = DateTimeParser::parse("%m/%d/%y", "01/18/05", tzd);
|
||||
assertTrue (dt.year() == 2005);
|
||||
assertTrue (dt.month() == 1);
|
||||
@@ -493,7 +493,7 @@ void DateTimeParserTest::testCustom()
|
||||
assertTrue (dt.minute() == 0);
|
||||
assertTrue (dt.second() == 0);
|
||||
assertTrue (tzd == 0);
|
||||
|
||||
|
||||
dt = DateTimeParser::parse("%h:%M %a", "12:30 am", tzd);
|
||||
assertTrue (dt.hour() == 0);
|
||||
assertTrue (dt.minute() == 30);
|
||||
@@ -557,7 +557,7 @@ void DateTimeParserTest::testGuess()
|
||||
assertTrue (dt.minute() == 30);
|
||||
assertTrue (dt.second() == 0);
|
||||
assertTrue (tzd == 0);
|
||||
|
||||
|
||||
dt = DateTimeParser::parse("2005-01-08T12:30:00+01:00", tzd);
|
||||
assertTrue (dt.year() == 2005);
|
||||
assertTrue (dt.month() == 1);
|
||||
@@ -640,7 +640,7 @@ void DateTimeParserTest::testGuess()
|
||||
assertTrue (dt.minute() == 30);
|
||||
assertTrue (dt.second() == 0);
|
||||
assertTrue (tzd == 3600);
|
||||
|
||||
|
||||
dt = DateTimeParser::parse("Sat Jan 8 12:30:00 2005", tzd);
|
||||
assertTrue (dt.year() == 2005);
|
||||
assertTrue (dt.month() == 1);
|
||||
|
@@ -81,7 +81,7 @@ void DateTimeTest::testJulian()
|
||||
assertTrue (dt.dayOfWeek() == 4);
|
||||
assertTrue (dt.julianDay() == 2440587.5);
|
||||
assertTrue (dt.timestamp() == 0);
|
||||
|
||||
|
||||
dt = 2299160.5; // 1582-10-15 00:00:00 (first day of Gregorian reform, UTC base)
|
||||
assertTrue (dt.year() == 1582);
|
||||
assertTrue (dt.month() == 10);
|
||||
@@ -131,7 +131,7 @@ void DateTimeTest::testGregorian()
|
||||
assertTrue (dt.dayOfWeek() == 4);
|
||||
assertTrue (dt.julianDay() == 2440587.5);
|
||||
assertTrue (dt.timestamp() == 0);
|
||||
|
||||
|
||||
dt.assign(2001, 9, 9, 1, 46, 40);
|
||||
assertTrue (dt.year() == 2001);
|
||||
assertTrue (dt.month() == 9);
|
||||
@@ -186,7 +186,7 @@ void DateTimeTest::testStatics()
|
||||
assertTrue (!DateTime::isLeapYear(2001));
|
||||
assertTrue (!DateTime::isLeapYear(1800));
|
||||
assertTrue (!DateTime::isLeapYear(1900));
|
||||
|
||||
|
||||
assertTrue (DateTime::daysOfMonth(2000, 1) == 31);
|
||||
assertTrue (DateTime::daysOfMonth(2000, 2) == 29);
|
||||
assertTrue (DateTime::daysOfMonth(1999, 2) == 28);
|
||||
@@ -216,9 +216,9 @@ void DateTimeTest::testCalcs()
|
||||
assertTrue (dt1.week(DateTime::MONDAY) == 1);
|
||||
dt1.assign(2007, 12, 31);
|
||||
assertTrue (dt1.week(DateTime::MONDAY) == 53);
|
||||
|
||||
|
||||
// Jan 1 is Mon
|
||||
dt1.assign(2001, 1, 1);
|
||||
dt1.assign(2001, 1, 1);
|
||||
assertTrue (dt1.week() == 1);
|
||||
dt1.assign(2001, 1, 7);
|
||||
assertTrue (dt1.week() == 1);
|
||||
@@ -252,7 +252,7 @@ void DateTimeTest::testCalcs()
|
||||
assertTrue (dt1.week() == 3);
|
||||
dt1.assign(2003, 1, 20);
|
||||
assertTrue (dt1.week() == 4);
|
||||
|
||||
|
||||
// Jan 1 is Thu
|
||||
dt1.assign(2004, 1, 1);
|
||||
assertTrue (dt1.week() == 1);
|
||||
@@ -288,7 +288,7 @@ void DateTimeTest::testCalcs()
|
||||
assertTrue (dt1.week() == 2);
|
||||
dt1.assign(2000, 1, 17);
|
||||
assertTrue (dt1.week() == 3);
|
||||
|
||||
|
||||
// Jan 1 is Sun
|
||||
dt1.assign(1995, 1, 1);
|
||||
assertTrue (dt1.week() == 0);
|
||||
@@ -309,7 +309,7 @@ void DateTimeTest::testAMPM()
|
||||
assertTrue (dt1.isAM());
|
||||
assertTrue (!dt1.isPM());
|
||||
assertTrue (dt1.hourAMPM() == 12);
|
||||
|
||||
|
||||
dt1.assign(2005, 1, 1, 12, 15, 30);
|
||||
assertTrue (!dt1.isAM());
|
||||
assertTrue (dt1.isPM());
|
||||
@@ -327,14 +327,14 @@ void DateTimeTest::testRelational()
|
||||
DateTime dt1(2005, 1, 1, 0, 15, 30);
|
||||
DateTime dt2(2005, 1, 2, 0, 15, 30);
|
||||
DateTime dt3(dt1);
|
||||
|
||||
|
||||
assertTrue (dt1 < dt2);
|
||||
assertTrue (dt1 <= dt2);
|
||||
assertTrue (dt2 > dt1);
|
||||
assertTrue (dt2 >= dt1);
|
||||
assertTrue (dt1 != dt2);
|
||||
assertTrue (!(dt1 == dt2));
|
||||
|
||||
|
||||
assertTrue (dt1 == dt3);
|
||||
assertTrue (!(dt1 != dt3));
|
||||
assertTrue (dt1 >= dt3);
|
||||
@@ -342,38 +342,38 @@ void DateTimeTest::testRelational()
|
||||
assertTrue (!(dt1 > dt3));
|
||||
assertTrue (!(dt1 < dt3));
|
||||
|
||||
static const struct
|
||||
static const struct
|
||||
{
|
||||
int year;
|
||||
int month;
|
||||
int month;
|
||||
int day;
|
||||
} values[] =
|
||||
} values[] =
|
||||
{
|
||||
{ 1, 1, 1 },
|
||||
{ 10, 4, 5 },
|
||||
{ 1, 1, 1 },
|
||||
{ 10, 4, 5 },
|
||||
{ 100, 6, 7 },
|
||||
{ 1000, 8, 9 },
|
||||
{ 2000, 1, 31 },
|
||||
{ 1000, 8, 9 },
|
||||
{ 2000, 1, 31 },
|
||||
{ 2002, 7, 4 },
|
||||
{ 2002, 12, 31 },
|
||||
{ 2003, 1, 1 },
|
||||
{ 2002, 12, 31 },
|
||||
{ 2003, 1, 1 },
|
||||
{ 2003, 1, 2 },
|
||||
{ 2003, 8, 5 },
|
||||
{ 2003, 8, 6 },
|
||||
{ 2003, 8, 5 },
|
||||
{ 2003, 8, 6 },
|
||||
{ 2003, 8, 7 },
|
||||
{ 2004, 9, 3 },
|
||||
{ 2004, 9, 4 },
|
||||
{ 2004, 9, 3 },
|
||||
{ 2004, 9, 4 },
|
||||
};
|
||||
|
||||
const int num_values = sizeof values / sizeof *values;
|
||||
for (int i = 0; i < num_values; ++i)
|
||||
for (int i = 0; i < num_values; ++i)
|
||||
{
|
||||
DateTime v;
|
||||
const DateTime& V = v;
|
||||
v.assign(values[i].year, values[i].month, values[i].day);
|
||||
for (int j = 0; j < num_values; ++j)
|
||||
for (int j = 0; j < num_values; ++j)
|
||||
{
|
||||
DateTime u;
|
||||
DateTime u;
|
||||
const DateTime& U = u;
|
||||
u.assign(values[j].year, values[j].month, values[j].day);
|
||||
|
||||
@@ -390,19 +390,19 @@ void DateTimeTest::testArithmetics()
|
||||
{
|
||||
DateTime dt1(2005, 1, 1, 0, 15, 30);
|
||||
DateTime dt2(2005, 1, 2, 0, 15, 30);
|
||||
|
||||
|
||||
Timespan s = dt2 - dt1;
|
||||
assertTrue (s.days() == 1);
|
||||
|
||||
|
||||
DateTime dt3 = dt1 + s;
|
||||
assertTrue (dt3 == dt2);
|
||||
|
||||
|
||||
dt3 -= s;
|
||||
assertTrue (dt3 == dt1);
|
||||
dt1 += s;
|
||||
assertTrue (dt1 == dt2);
|
||||
|
||||
static const struct
|
||||
static const struct
|
||||
{
|
||||
int lineNum; // source line number
|
||||
int year1; // operand/result date1 year
|
||||
@@ -412,11 +412,11 @@ void DateTimeTest::testArithmetics()
|
||||
int year2; // operand/result date2 year
|
||||
int month2; // operand/result date2 month
|
||||
unsigned int day2; // operand/result date2 day
|
||||
} data[] =
|
||||
} data[] =
|
||||
{
|
||||
// - - - -first- - - - - - - second - - -
|
||||
// - - - -first- - - - - - - second - - -
|
||||
//line no. year month day numDays year month day
|
||||
//------- ----- ----- ----- ------- ----- ----- -----
|
||||
//------- ----- ----- ----- ------- ----- ----- -----
|
||||
{ __LINE__, 1, 1, 1, 1, 1, 1, 2 },
|
||||
{ __LINE__, 10, 2, 28, 1, 10, 3, 1 },
|
||||
{ __LINE__, 100, 3, 31, 2, 100, 4, 2 },
|
||||
@@ -434,7 +434,7 @@ void DateTimeTest::testArithmetics()
|
||||
};
|
||||
|
||||
const int num_data = sizeof data / sizeof *data;
|
||||
for (int di = 0; di < num_data; ++di)
|
||||
for (int di = 0; di < num_data; ++di)
|
||||
{
|
||||
const int line = data[di].lineNum;
|
||||
const int num_days = data[di].numDays;
|
||||
@@ -471,7 +471,7 @@ void DateTimeTest::testArithmetics()
|
||||
|
||||
void DateTimeTest::testIncrementDecrement()
|
||||
{
|
||||
static const struct
|
||||
static const struct
|
||||
{
|
||||
int lineNum; // source line number
|
||||
int year1; // (first) date year
|
||||
@@ -480,11 +480,11 @@ void DateTimeTest::testIncrementDecrement()
|
||||
int year2; // (second) date year
|
||||
int month2; // (second) date month
|
||||
unsigned int day2; // (second) date day
|
||||
} data[] =
|
||||
} data[] =
|
||||
{
|
||||
// - - - -first- - - - - - - second - - -
|
||||
// - - - -first- - - - - - - second - - -
|
||||
//line no. year month day year month day
|
||||
//------- ----- ----- ----- ----- ----- -----
|
||||
//------- ----- ----- ----- ----- ----- -----
|
||||
{ __LINE__, 1, 1, 1, 1, 1, 2 },
|
||||
{ __LINE__, 10, 2, 28, 10, 3, 1 },
|
||||
{ __LINE__, 100, 3, 31, 100, 4, 1 },
|
||||
@@ -511,14 +511,14 @@ void DateTimeTest::testIncrementDecrement()
|
||||
const int num_data = sizeof data / sizeof *data;
|
||||
int di;
|
||||
|
||||
for (di = 0; di < num_data; ++di)
|
||||
for (di = 0; di < num_data; ++di)
|
||||
{
|
||||
const int line = data[di].lineNum;
|
||||
DateTime x = DateTime(data[di].year1, data[di].month1,
|
||||
DateTime x = DateTime(data[di].year1, data[di].month1,
|
||||
data[di].day1);
|
||||
// Would do pre-increment of x here.
|
||||
const DateTime& X = x;
|
||||
x = x + Timespan(1,0,0,0,0);
|
||||
x = x + Timespan(1,0,0,0,0);
|
||||
DateTime y = x; const DateTime& Y = y;
|
||||
|
||||
loop_1_assert (line, data[di].year2 == X.year());
|
||||
@@ -530,7 +530,7 @@ void DateTimeTest::testIncrementDecrement()
|
||||
loop_1_assert (line, data[di].day2 == Y.day());
|
||||
}
|
||||
|
||||
for (di = 0; di < num_data; ++di)
|
||||
for (di = 0; di < num_data; ++di)
|
||||
{
|
||||
const int line = data[di].lineNum;
|
||||
DateTime x = DateTime(data[di].year1, data[di].month1, data[di].day1);
|
||||
@@ -540,7 +540,7 @@ void DateTimeTest::testIncrementDecrement()
|
||||
|
||||
// Would do post increment of x here.
|
||||
const DateTime& X = x;
|
||||
x = x + Timespan(1,0,0,0,0);
|
||||
x = x + Timespan(1,0,0,0,0);
|
||||
|
||||
loop_1_assert (line, data[di].year2 == X.year());
|
||||
loop_1_assert (line, data[di].month2 == X.month());
|
||||
@@ -549,13 +549,13 @@ void DateTimeTest::testIncrementDecrement()
|
||||
loop_1_assert (line, data[di].month1 == Y.month());
|
||||
loop_1_assert (line, data[di].day1 == Y.day());
|
||||
}
|
||||
|
||||
for (di = 0; di < num_data; ++di)
|
||||
|
||||
for (di = 0; di < num_data; ++di)
|
||||
{
|
||||
const int line = data[di].lineNum;
|
||||
DateTime x = DateTime(data[di].year2, data[di].month2, data[di].day2);
|
||||
const DateTime& X = x;
|
||||
x = x - Timespan(1,0,0,0,0);
|
||||
x = x - Timespan(1,0,0,0,0);
|
||||
DateTime y = x; DateTime Y = y;
|
||||
|
||||
loop_1_assert (line, data[di].year1 == X.year());
|
||||
@@ -567,7 +567,7 @@ void DateTimeTest::testIncrementDecrement()
|
||||
loop_1_assert (line, data[di].day1 == Y.day());
|
||||
}
|
||||
|
||||
for (di = 0; di < num_data; ++di)
|
||||
for (di = 0; di < num_data; ++di)
|
||||
{
|
||||
const int line = data[di].lineNum;
|
||||
DateTime x1 = DateTime(data[di].year1, data[di].month1, data[di].day1);
|
||||
@@ -575,7 +575,7 @@ void DateTimeTest::testIncrementDecrement()
|
||||
DateTime y = x; DateTime Y = y;
|
||||
const DateTime& X = x;
|
||||
// would post-decrement x here.
|
||||
x = x - Timespan(1,0,0,0,0);
|
||||
x = x - Timespan(1,0,0,0,0);
|
||||
|
||||
loop_1_assert (line, data[di].year1 == X.year());
|
||||
loop_1_assert (line, data[di].month1 == X.month());
|
||||
@@ -594,7 +594,7 @@ void DateTimeTest::testSwap()
|
||||
DateTime dt2(2005, 1, 2, 0, 15, 30);
|
||||
DateTime dt3(2005, 1, 1, 0, 15, 30);
|
||||
DateTime dt4(2005, 1, 2, 0, 15, 30);
|
||||
|
||||
|
||||
dt1.swap(dt2);
|
||||
assertTrue (dt2 == dt3);
|
||||
assertTrue (dt1 == dt4);
|
||||
@@ -625,28 +625,28 @@ void DateTimeTest::testUsage()
|
||||
|
||||
void DateTimeTest::testSetYearDay()
|
||||
{
|
||||
static const struct
|
||||
static const struct
|
||||
{
|
||||
int d_lineNum; // source line number
|
||||
int d_year; // year under test
|
||||
unsigned int d_day; // day-of-year under test
|
||||
int d_expMonth; // expected month
|
||||
unsigned int d_expDay; // expected day
|
||||
} data[] =
|
||||
} data[] =
|
||||
{
|
||||
//line no. year dayOfYr exp. month exp. day
|
||||
//------- ----- ------- ---------- --------
|
||||
{ __LINE__, 1, 1, 1, 1 },
|
||||
{ __LINE__, 1, 1, 1, 1 },
|
||||
{ __LINE__, 1, 2, 1, 2 },
|
||||
{ __LINE__, 1, 365, 12, 31 },
|
||||
{ __LINE__, 1996, 1, 1, 1 },
|
||||
{ __LINE__, 1996, 1, 1, 1 },
|
||||
{ __LINE__, 1996, 2, 1, 2 },
|
||||
{ __LINE__, 1996, 365, 12, 30 },
|
||||
{ __LINE__, 1996, 366, 12, 31 }
|
||||
};
|
||||
|
||||
const int num_data = sizeof data / sizeof *data;
|
||||
for (int di = 0; di < num_data; ++di)
|
||||
for (int di = 0; di < num_data; ++di)
|
||||
{
|
||||
const int POCO_UNUSED line = data[di].d_lineNum;
|
||||
const int year = data[di].d_year;
|
||||
@@ -672,25 +672,25 @@ void DateTimeTest::testSetYearDay()
|
||||
#endif
|
||||
}
|
||||
|
||||
static const struct
|
||||
static const struct
|
||||
{
|
||||
int d_lineNum; // source line number
|
||||
int d_year; // year under test
|
||||
int d_day; // day-of-year under test
|
||||
int d_exp; // expected status
|
||||
} data2[] =
|
||||
} data2[] =
|
||||
{
|
||||
//line no. year dayOfYr expected value
|
||||
//------- ----- ------- --------------
|
||||
{ __LINE__, 1, 1, 1 },
|
||||
{ __LINE__, 1, 1, 1 },
|
||||
{ __LINE__, 1, -1, 0 },
|
||||
{ __LINE__, 1, 0, 0 },
|
||||
{ __LINE__, 1, 365, 1 },
|
||||
{ __LINE__, 1, 366, 0 },
|
||||
{ __LINE__, 1, 367, 0 },
|
||||
{ __LINE__, 0, 0, 0 },
|
||||
{ __LINE__, -1, -1, 0 },
|
||||
{ __LINE__, 1996, 1, 1 },
|
||||
{ __LINE__, 0, 0, 0 },
|
||||
{ __LINE__, -1, -1, 0 },
|
||||
{ __LINE__, 1996, 1, 1 },
|
||||
{ __LINE__, 1996, 2, 1 },
|
||||
{ __LINE__, 1996, 32, 1 },
|
||||
{ __LINE__, 1996, 365, 1 },
|
||||
@@ -699,7 +699,7 @@ void DateTimeTest::testSetYearDay()
|
||||
};
|
||||
|
||||
const int num_data2 = sizeof data2 / sizeof *data2;
|
||||
for (int di = 0; di < num_data2; ++di)
|
||||
for (int di = 0; di < num_data2; ++di)
|
||||
{
|
||||
const int POCO_UNUSED line = data2[di].d_lineNum;
|
||||
const int POCO_UNUSED year = data2[di].d_year;
|
||||
@@ -721,53 +721,53 @@ void DateTimeTest::testSetYearDay()
|
||||
|
||||
void DateTimeTest::testIsValid()
|
||||
{
|
||||
static const struct
|
||||
static const struct
|
||||
{
|
||||
int d_lineNum; // source line number
|
||||
int d_year; // year under test
|
||||
int d_month; // month under test
|
||||
int d_day; // day under test
|
||||
bool d_exp; // expected value
|
||||
} data[] =
|
||||
} data[] =
|
||||
{
|
||||
//line no. year month day expected value
|
||||
//------- ----- ----- ----- --------------
|
||||
{ __LINE__, 0, 0, 0, false },
|
||||
{ __LINE__, 1, 1, 0, false },
|
||||
{ __LINE__, 1, 0, 1, false },
|
||||
{ __LINE__, 0, 1, 1, true },
|
||||
{ __LINE__, 1, 1, -1, false },
|
||||
{ __LINE__, 1, -1, 1, false },
|
||||
{ __LINE__, 2004, 1, 32, false },
|
||||
{ __LINE__, 2004, 2, 30, false },
|
||||
{ __LINE__, 2004, 3, 32, false },
|
||||
{ __LINE__, 2004, 4, 31, false },
|
||||
{ __LINE__, 2004, 5, 32, false },
|
||||
{ __LINE__, 2004, 6, 31, false },
|
||||
{ __LINE__, 2004, 7, 32, false },
|
||||
{ __LINE__, 2004, 8, 32, false },
|
||||
{ __LINE__, 2004, 9, 31, false },
|
||||
{ __LINE__, 2004, 10, 32, false },
|
||||
{ __LINE__, 2004, 11, 31, false },
|
||||
{ __LINE__, 2004, 12, 32, false },
|
||||
{ __LINE__, 0, 0, 0, false },
|
||||
{ __LINE__, 1, 1, 0, false },
|
||||
{ __LINE__, 1, 0, 1, false },
|
||||
{ __LINE__, 0, 1, 1, true },
|
||||
{ __LINE__, 1, 1, -1, false },
|
||||
{ __LINE__, 1, -1, 1, false },
|
||||
{ __LINE__, 2004, 1, 32, false },
|
||||
{ __LINE__, 2004, 2, 30, false },
|
||||
{ __LINE__, 2004, 3, 32, false },
|
||||
{ __LINE__, 2004, 4, 31, false },
|
||||
{ __LINE__, 2004, 5, 32, false },
|
||||
{ __LINE__, 2004, 6, 31, false },
|
||||
{ __LINE__, 2004, 7, 32, false },
|
||||
{ __LINE__, 2004, 8, 32, false },
|
||||
{ __LINE__, 2004, 9, 31, false },
|
||||
{ __LINE__, 2004, 10, 32, false },
|
||||
{ __LINE__, 2004, 11, 31, false },
|
||||
{ __LINE__, 2004, 12, 32, false },
|
||||
{ __LINE__, 0, 12, 31, true },
|
||||
{ __LINE__, 0, 2, 29, true },
|
||||
{ __LINE__, 1, 1, 1, true },
|
||||
{ __LINE__, 2010, 1, 2, true },
|
||||
{ __LINE__, 2011, 2, 5, true },
|
||||
{ __LINE__, 2012, 3, 10, true },
|
||||
{ __LINE__, 2013, 4, 17, true },
|
||||
{ __LINE__, 2014, 5, 23, true },
|
||||
{ __LINE__, 1600, 2, 29, true },
|
||||
{ __LINE__, 1700, 2, 29, false },
|
||||
{ __LINE__, 1800, 2, 29, false },
|
||||
{ __LINE__, 1900, 2, 29, false },
|
||||
{ __LINE__, 2000, 2, 29, true },
|
||||
{ __LINE__, 2100, 2, 29, false },
|
||||
{ __LINE__, 1, 1, 1, true },
|
||||
{ __LINE__, 2010, 1, 2, true },
|
||||
{ __LINE__, 2011, 2, 5, true },
|
||||
{ __LINE__, 2012, 3, 10, true },
|
||||
{ __LINE__, 2013, 4, 17, true },
|
||||
{ __LINE__, 2014, 5, 23, true },
|
||||
{ __LINE__, 1600, 2, 29, true },
|
||||
{ __LINE__, 1700, 2, 29, false },
|
||||
{ __LINE__, 1800, 2, 29, false },
|
||||
{ __LINE__, 1900, 2, 29, false },
|
||||
{ __LINE__, 2000, 2, 29, true },
|
||||
{ __LINE__, 2100, 2, 29, false },
|
||||
};
|
||||
|
||||
const int num_data = sizeof data / sizeof *data;
|
||||
for (int di = 0; di < num_data; ++di)
|
||||
for (int di = 0; di < num_data; ++di)
|
||||
{
|
||||
const int line = data[di].d_lineNum;
|
||||
const int year = data[di].d_year;
|
||||
@@ -785,22 +785,22 @@ void DateTimeTest::testDayOfWeek()
|
||||
{
|
||||
typedef DateTime::DaysOfWeek DOW;
|
||||
|
||||
static const struct
|
||||
static const struct
|
||||
{
|
||||
int d_lineNum; // source line number
|
||||
int d_year; // year under test
|
||||
int d_month; // month under test
|
||||
int d_day; // day under test
|
||||
DOW d_expDay; // number of days to be added
|
||||
} data[] =
|
||||
} data[] =
|
||||
{
|
||||
//Line no. year month day expDay
|
||||
//------- ----- ----- ----- -------
|
||||
{ __LINE__, 1600, 1, 1, DateTime::SATURDAY },
|
||||
{ __LINE__, 1600, 1, 2, DateTime::SUNDAY },
|
||||
{ __LINE__, 1600, 1, 2, DateTime::SUNDAY },
|
||||
{ __LINE__, 1600, 1, 3, DateTime::MONDAY },
|
||||
{ __LINE__, 1600, 1, 4, DateTime::TUESDAY },
|
||||
{ __LINE__, 1600, 1, 5, DateTime::WEDNESDAY },
|
||||
{ __LINE__, 1600, 1, 5, DateTime::WEDNESDAY },
|
||||
{ __LINE__, 1600, 1, 6, DateTime::THURSDAY },
|
||||
{ __LINE__, 1600, 1, 7, DateTime::FRIDAY },
|
||||
{ __LINE__, 1600, 1, 8, DateTime::SATURDAY },
|
||||
@@ -810,25 +810,25 @@ void DateTimeTest::testDayOfWeek()
|
||||
{ __LINE__, 1752, 8, 30, DateTime::WEDNESDAY },
|
||||
{ __LINE__, 1752, 8, 31, DateTime::THURSDAY },
|
||||
{ __LINE__, 1752, 9, 1, DateTime::FRIDAY },
|
||||
{ __LINE__, 1752, 9, 2, DateTime::SATURDAY },
|
||||
{ __LINE__, 1752, 9, 2, DateTime::SATURDAY },
|
||||
{ __LINE__, 1752, 9, 14, DateTime::THURSDAY },
|
||||
{ __LINE__, 1752, 9, 15, DateTime::FRIDAY },
|
||||
{ __LINE__, 1752, 9, 16, DateTime::SATURDAY },
|
||||
{ __LINE__, 1752, 9, 16, DateTime::SATURDAY },
|
||||
{ __LINE__, 1752, 9, 17, DateTime::SUNDAY },
|
||||
{ __LINE__, 1752, 9, 18, DateTime::MONDAY },
|
||||
{ __LINE__, 1752, 9, 19, DateTime::TUESDAY },
|
||||
{ __LINE__, 1999, 12, 28, DateTime::TUESDAY },
|
||||
{ __LINE__, 1999, 12, 29, DateTime::WEDNESDAY },
|
||||
{ __LINE__, 1999, 12, 29, DateTime::WEDNESDAY },
|
||||
{ __LINE__, 1999, 12, 30, DateTime::THURSDAY },
|
||||
{ __LINE__, 1999, 12, 31, DateTime::FRIDAY },
|
||||
{ __LINE__, 2000, 1, 1, DateTime::SATURDAY },
|
||||
{ __LINE__, 2000, 1, 1, DateTime::SATURDAY },
|
||||
{ __LINE__, 2000, 1, 2, DateTime::SUNDAY },
|
||||
{ __LINE__, 2000, 1, 3, DateTime::MONDAY },
|
||||
{ __LINE__, 2000, 1, 4, DateTime::TUESDAY },
|
||||
};
|
||||
|
||||
|
||||
const int num_data = sizeof data / sizeof *data;
|
||||
for (int di = 0; di < num_data ; ++di)
|
||||
for (int di = 0; di < num_data ; ++di)
|
||||
{
|
||||
const int line = data[di].d_lineNum;
|
||||
DateTime x = DateTime(data[di].d_year, data[di].d_month, data[di].d_day);
|
||||
@@ -854,7 +854,7 @@ void DateTimeTest::testLeapSeconds()
|
||||
{
|
||||
DateTime dt1(2015, 6, 30, 23, 59, 60);
|
||||
DateTime dt2(2015, 7, 1, 0, 0, 0);
|
||||
|
||||
|
||||
assertTrue (dt1 == dt2);
|
||||
}
|
||||
|
||||
|
@@ -99,6 +99,6 @@ CppUnit::Test* DigestStreamTest::suite()
|
||||
CppUnit_addTest(pSuite, DigestStreamTest, testOutputStream1);
|
||||
CppUnit_addTest(pSuite, DigestStreamTest, testOutputStream2);
|
||||
CppUnit_addTest(pSuite, DigestStreamTest, testToFromHex);
|
||||
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -29,12 +29,12 @@ public:
|
||||
void testSortedDirectoryIterator();
|
||||
void testSimpleRecursiveDirectoryIterator();
|
||||
void testSiblingsFirstRecursiveDirectoryIterator();
|
||||
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
|
||||
protected:
|
||||
Poco::Path path() const;
|
||||
void createSubdir(Poco::Path& p);
|
||||
|
@@ -24,7 +24,7 @@
|
||||
using Poco::DirectoryWatcher;
|
||||
|
||||
|
||||
DirectoryWatcherTest::DirectoryWatcherTest(const std::string& name):
|
||||
DirectoryWatcherTest::DirectoryWatcherTest(const std::string& name):
|
||||
CppUnit::TestCase(name),
|
||||
_error(false)
|
||||
{
|
||||
@@ -39,23 +39,24 @@ DirectoryWatcherTest::~DirectoryWatcherTest()
|
||||
void DirectoryWatcherTest::testAdded()
|
||||
{
|
||||
DirectoryWatcher dw(path().toString(), DirectoryWatcher::DW_FILTER_ENABLE_ALL, 2);
|
||||
|
||||
|
||||
dw.itemAdded += Poco::delegate(this, &DirectoryWatcherTest::onItemAdded);
|
||||
dw.itemRemoved += Poco::delegate(this, &DirectoryWatcherTest::onItemRemoved);
|
||||
dw.itemModified += Poco::delegate(this, &DirectoryWatcherTest::onItemModified);
|
||||
dw.itemMovedFrom += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedFrom);
|
||||
dw.itemMovedTo += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedTo);
|
||||
|
||||
|
||||
Poco::Thread::sleep(1000);
|
||||
|
||||
|
||||
Poco::Path p(path());
|
||||
p.setFileName("test.txt");
|
||||
Poco::FileOutputStream fos(p.toString());
|
||||
fos << "Hello, world!";
|
||||
fos.close();
|
||||
|
||||
|
||||
Poco::Thread::sleep(2000*dw.scanInterval());
|
||||
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
assertTrue (_events.size() >= 1);
|
||||
assertTrue (_events[0].callback == "onItemAdded");
|
||||
assertTrue (Poco::Path(_events[0].path).getFileName() == "test.txt");
|
||||
@@ -73,20 +74,21 @@ void DirectoryWatcherTest::testRemoved()
|
||||
fos.close();
|
||||
|
||||
DirectoryWatcher dw(path().toString(), DirectoryWatcher::DW_FILTER_ENABLE_ALL, 2);
|
||||
|
||||
|
||||
dw.itemAdded += Poco::delegate(this, &DirectoryWatcherTest::onItemAdded);
|
||||
dw.itemRemoved += Poco::delegate(this, &DirectoryWatcherTest::onItemRemoved);
|
||||
dw.itemModified += Poco::delegate(this, &DirectoryWatcherTest::onItemModified);
|
||||
dw.itemMovedFrom += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedFrom);
|
||||
dw.itemMovedTo += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedTo);
|
||||
|
||||
|
||||
Poco::Thread::sleep(1000);
|
||||
|
||||
|
||||
Poco::File f(p.toString());
|
||||
f.remove();
|
||||
|
||||
|
||||
Poco::Thread::sleep(2000*dw.scanInterval());
|
||||
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
assertTrue (_events.size() >= 1);
|
||||
assertTrue (_events[0].callback == "onItemRemoved");
|
||||
assertTrue (Poco::Path(_events[0].path).getFileName() == "test.txt");
|
||||
@@ -104,21 +106,22 @@ void DirectoryWatcherTest::testModified()
|
||||
fos.close();
|
||||
|
||||
DirectoryWatcher dw(path().toString(), DirectoryWatcher::DW_FILTER_ENABLE_ALL, 2);
|
||||
|
||||
|
||||
dw.itemAdded += Poco::delegate(this, &DirectoryWatcherTest::onItemAdded);
|
||||
dw.itemRemoved += Poco::delegate(this, &DirectoryWatcherTest::onItemRemoved);
|
||||
dw.itemModified += Poco::delegate(this, &DirectoryWatcherTest::onItemModified);
|
||||
dw.itemMovedFrom += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedFrom);
|
||||
dw.itemMovedTo += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedTo);
|
||||
|
||||
|
||||
Poco::Thread::sleep(1000);
|
||||
|
||||
|
||||
Poco::FileOutputStream fos2(p.toString(), std::ios::app);
|
||||
fos2 << "Again!";
|
||||
fos2.close();
|
||||
|
||||
|
||||
Poco::Thread::sleep(2000*dw.scanInterval());
|
||||
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
assertTrue (_events.size() >= 1);
|
||||
assertTrue (_events[0].callback == "onItemModified");
|
||||
assertTrue (Poco::Path(_events[0].path).getFileName() == "test.txt");
|
||||
@@ -136,22 +139,23 @@ void DirectoryWatcherTest::testMoved()
|
||||
fos.close();
|
||||
|
||||
DirectoryWatcher dw(path().toString(), DirectoryWatcher::DW_FILTER_ENABLE_ALL, 2);
|
||||
|
||||
|
||||
dw.itemAdded += Poco::delegate(this, &DirectoryWatcherTest::onItemAdded);
|
||||
dw.itemRemoved += Poco::delegate(this, &DirectoryWatcherTest::onItemRemoved);
|
||||
dw.itemModified += Poco::delegate(this, &DirectoryWatcherTest::onItemModified);
|
||||
dw.itemMovedFrom += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedFrom);
|
||||
dw.itemMovedTo += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedTo);
|
||||
|
||||
|
||||
Poco::Thread::sleep(1000);
|
||||
|
||||
|
||||
Poco::Path p2(path());
|
||||
p2.setFileName("test2.txt");
|
||||
Poco::File f(p.toString());
|
||||
f.renameTo(p2.toString());
|
||||
|
||||
|
||||
Poco::Thread::sleep(2000*dw.scanInterval());
|
||||
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
if (dw.supportsMoveEvents())
|
||||
{
|
||||
assertTrue (_events.size() >= 2);
|
||||
@@ -188,11 +192,153 @@ void DirectoryWatcherTest::testMoved()
|
||||
}
|
||||
|
||||
|
||||
void DirectoryWatcherTest::testSuspend()
|
||||
{
|
||||
Poco::Path p(path());
|
||||
p.setFileName("test.txt");
|
||||
Poco::FileOutputStream fos(p.toString());
|
||||
fos << "Hello, world!";
|
||||
fos.close();
|
||||
|
||||
DirectoryWatcher dw(path().toString(), DirectoryWatcher::DW_FILTER_ENABLE_ALL, 2);
|
||||
|
||||
dw.itemAdded += Poco::delegate(this, &DirectoryWatcherTest::onItemAdded);
|
||||
dw.itemRemoved += Poco::delegate(this, &DirectoryWatcherTest::onItemRemoved);
|
||||
dw.itemModified += Poco::delegate(this, &DirectoryWatcherTest::onItemModified);
|
||||
dw.itemMovedFrom += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedFrom);
|
||||
dw.itemMovedTo += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedTo);
|
||||
|
||||
Poco::Thread::sleep(1000);
|
||||
|
||||
dw.suspendEvents();
|
||||
|
||||
Poco::FileOutputStream fos2(p.toString(), std::ios::app);
|
||||
fos2 << "Again!";
|
||||
fos2.close();
|
||||
|
||||
Poco::Thread::sleep(2000*dw.scanInterval());
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
assertTrue (_events.size() == 0);
|
||||
assertTrue (!_error);
|
||||
}
|
||||
|
||||
|
||||
void DirectoryWatcherTest::testResume()
|
||||
{
|
||||
Poco::Path p(path());
|
||||
p.setFileName("test.txt");
|
||||
Poco::FileOutputStream fos(p.toString());
|
||||
fos << "Hello, world!";
|
||||
fos.close();
|
||||
|
||||
DirectoryWatcher dw(path().toString(), DirectoryWatcher::DW_FILTER_ENABLE_ALL, 2);
|
||||
|
||||
dw.itemAdded += Poco::delegate(this, &DirectoryWatcherTest::onItemAdded);
|
||||
dw.itemRemoved += Poco::delegate(this, &DirectoryWatcherTest::onItemRemoved);
|
||||
dw.itemModified += Poco::delegate(this, &DirectoryWatcherTest::onItemModified);
|
||||
dw.itemMovedFrom += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedFrom);
|
||||
dw.itemMovedTo += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedTo);
|
||||
|
||||
Poco::Thread::sleep(1000);
|
||||
|
||||
dw.suspendEvents();
|
||||
|
||||
Poco::FileOutputStream fos2(p.toString(), std::ios::app);
|
||||
fos2 << "Again!";
|
||||
fos2.close();
|
||||
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
assertTrue (_events.size() == 0);
|
||||
assertTrue (!_error);
|
||||
}
|
||||
|
||||
dw.resumeEvents();
|
||||
|
||||
Poco::FileOutputStream fos3(p.toString(), std::ios::app);
|
||||
fos3 << "Now it works!";
|
||||
fos3.close();
|
||||
|
||||
Poco::Thread::sleep(2000*dw.scanInterval());
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
assertTrue (_events.size() >= 1);
|
||||
assertTrue (_events[0].callback == "onItemModified");
|
||||
assertTrue (Poco::Path(_events[0].path).getFileName() == "test.txt");
|
||||
assertTrue (_events[0].type == DirectoryWatcher::DW_ITEM_MODIFIED);
|
||||
assertTrue (!_error);
|
||||
}
|
||||
|
||||
|
||||
void DirectoryWatcherTest::testSuspendMultipleTimes()
|
||||
{
|
||||
Poco::Path p(path());
|
||||
p.setFileName("test.txt");
|
||||
Poco::FileOutputStream fos(p.toString());
|
||||
fos << "Hello, world!";
|
||||
fos.close();
|
||||
|
||||
DirectoryWatcher dw(path().toString(), DirectoryWatcher::DW_FILTER_ENABLE_ALL, 2);
|
||||
|
||||
dw.itemAdded += Poco::delegate(this, &DirectoryWatcherTest::onItemAdded);
|
||||
dw.itemRemoved += Poco::delegate(this, &DirectoryWatcherTest::onItemRemoved);
|
||||
dw.itemModified += Poco::delegate(this, &DirectoryWatcherTest::onItemModified);
|
||||
dw.itemMovedFrom += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedFrom);
|
||||
dw.itemMovedTo += Poco::delegate(this, &DirectoryWatcherTest::onItemMovedTo);
|
||||
|
||||
Poco::Thread::sleep(1000);
|
||||
|
||||
dw.suspendEvents();
|
||||
dw.suspendEvents();
|
||||
dw.suspendEvents();
|
||||
|
||||
Poco::FileOutputStream fos2(p.toString(), std::ios::app);
|
||||
fos2 << "Not notified!";
|
||||
fos2.close();
|
||||
|
||||
Poco::Thread::sleep(2000*dw.scanInterval());
|
||||
|
||||
assertTrue (_events.size() == 0);
|
||||
assertTrue (!_error);
|
||||
|
||||
dw.resumeEvents();
|
||||
|
||||
Poco::FileOutputStream fos3(p.toString(), std::ios::app);
|
||||
fos3 << "Still not notified!";
|
||||
fos3.close();
|
||||
|
||||
Poco::Thread::sleep(2000*dw.scanInterval());
|
||||
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
assertTrue (_events.size() == 0);
|
||||
assertTrue (!_error);
|
||||
}
|
||||
|
||||
dw.resumeEvents();
|
||||
dw.resumeEvents();
|
||||
|
||||
Poco::FileOutputStream fos4(p.toString(), std::ios::app);
|
||||
fos4 << "Now it works!";
|
||||
fos4.close();
|
||||
|
||||
Poco::Thread::sleep(2000*dw.scanInterval());
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
assertTrue (_events.size() >= 1);
|
||||
assertTrue (_events[0].callback == "onItemModified");
|
||||
assertTrue (Poco::Path(_events[0].path).getFileName() == "test.txt");
|
||||
assertTrue (_events[0].type == DirectoryWatcher::DW_ITEM_MODIFIED);
|
||||
assertTrue (!_error);
|
||||
}
|
||||
|
||||
|
||||
void DirectoryWatcherTest::setUp()
|
||||
{
|
||||
_error = false;
|
||||
_events.clear();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Poco::File d(path().toString());
|
||||
@@ -226,6 +372,8 @@ void DirectoryWatcherTest::onItemAdded(const Poco::DirectoryWatcher::DirectoryEv
|
||||
de.callback = "onItemAdded";
|
||||
de.path = ev.item.path();
|
||||
de.type = ev.event;
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
_events.push_back(de);
|
||||
}
|
||||
|
||||
@@ -236,6 +384,8 @@ void DirectoryWatcherTest::onItemRemoved(const Poco::DirectoryWatcher::Directory
|
||||
de.callback = "onItemRemoved";
|
||||
de.path = ev.item.path();
|
||||
de.type = ev.event;
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
_events.push_back(de);
|
||||
}
|
||||
|
||||
@@ -246,6 +396,8 @@ void DirectoryWatcherTest::onItemModified(const Poco::DirectoryWatcher::Director
|
||||
de.callback = "onItemModified";
|
||||
de.path = ev.item.path();
|
||||
de.type = ev.event;
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
_events.push_back(de);
|
||||
}
|
||||
|
||||
@@ -256,6 +408,8 @@ void DirectoryWatcherTest::onItemMovedFrom(const Poco::DirectoryWatcher::Directo
|
||||
de.callback = "onItemMovedFrom";
|
||||
de.path = ev.item.path();
|
||||
de.type = ev.event;
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
_events.push_back(de);
|
||||
}
|
||||
|
||||
@@ -266,12 +420,15 @@ void DirectoryWatcherTest::onItemMovedTo(const Poco::DirectoryWatcher::Directory
|
||||
de.callback = "onItemMovedTo";
|
||||
de.path = ev.item.path();
|
||||
de.type = ev.event;
|
||||
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
_events.push_back(de);
|
||||
}
|
||||
|
||||
|
||||
void DirectoryWatcherTest::onError(const Poco::Exception& exc)
|
||||
{
|
||||
|
||||
_error = true;
|
||||
}
|
||||
|
||||
@@ -292,6 +449,9 @@ CppUnit::Test* DirectoryWatcherTest::suite()
|
||||
CppUnit_addTest(pSuite, DirectoryWatcherTest, testRemoved);
|
||||
CppUnit_addTest(pSuite, DirectoryWatcherTest, testModified);
|
||||
CppUnit_addTest(pSuite, DirectoryWatcherTest, testMoved);
|
||||
CppUnit_addTest(pSuite, DirectoryWatcherTest, testSuspend);
|
||||
CppUnit_addTest(pSuite, DirectoryWatcherTest, testResume);
|
||||
CppUnit_addTest(pSuite, DirectoryWatcherTest, testSuspendMultipleTimes);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "Poco/DirectoryWatcher.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
@@ -35,12 +36,15 @@ public:
|
||||
void testRemoved();
|
||||
void testModified();
|
||||
void testMoved();
|
||||
|
||||
void testSuspend();
|
||||
void testResume();
|
||||
void testSuspendMultipleTimes();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
|
||||
protected:
|
||||
void onItemAdded(const Poco::DirectoryWatcher::DirectoryEvent& ev);
|
||||
void onItemRemoved(const Poco::DirectoryWatcher::DirectoryEvent& ev);
|
||||
@@ -48,7 +52,7 @@ protected:
|
||||
void onItemMovedFrom(const Poco::DirectoryWatcher::DirectoryEvent& ev);
|
||||
void onItemMovedTo(const Poco::DirectoryWatcher::DirectoryEvent& ev);
|
||||
void onError(const Poco::Exception& exc);
|
||||
|
||||
|
||||
Poco::Path path() const;
|
||||
|
||||
private:
|
||||
@@ -60,6 +64,7 @@ private:
|
||||
};
|
||||
std::vector<DirEvent> _events;
|
||||
bool _error;
|
||||
Poco::Mutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -95,7 +95,7 @@ void ExpireCacheTest::testExpireN()
|
||||
assertTrue (aCache.has(3));
|
||||
tmp = aCache.get(1);
|
||||
SharedPtr<int> tmp2 = aCache.get(3);
|
||||
assertTrue (*tmp == 2);
|
||||
assertTrue (*tmp == 2);
|
||||
assertTrue (*tmp2 == 4);
|
||||
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
|
@@ -93,7 +93,7 @@ void ExpireLRUCacheTest::testExpireN()
|
||||
assertTrue (aCache.has(3));
|
||||
tmp = aCache.get(1);
|
||||
SharedPtr<int> tmp2 = aCache.get(3);
|
||||
assertTrue (*tmp == 2);
|
||||
assertTrue (*tmp == 2);
|
||||
assertTrue (*tmp2 == 4);
|
||||
|
||||
Thread::sleep(DURHALFSLEEP+25); //3|1
|
||||
|
@@ -42,17 +42,17 @@ void FIFOBufferStreamTest::testInput()
|
||||
assertTrue (c == 'T');
|
||||
c = str1.get();
|
||||
assertTrue (c == 'h');
|
||||
|
||||
|
||||
std::string str;
|
||||
str1 >> str;
|
||||
assertTrue (str == "is");
|
||||
|
||||
|
||||
char buffer[32];
|
||||
str1.read(buffer, sizeof(buffer));
|
||||
assertTrue (str1.gcount() == 10);
|
||||
buffer[str1.gcount()] = 0;
|
||||
assertTrue (std::string(" is a test") == buffer);
|
||||
|
||||
|
||||
const char* data2 = "123";
|
||||
FIFOBufferStream str2(data2, 3);
|
||||
|
||||
@@ -109,7 +109,7 @@ void FIFOBufferStreamTest::testNotify()
|
||||
iostr >> input;
|
||||
assertTrue (std::string("This") == input);
|
||||
assertTrue (iostr.rdbuf()->fifoBuffer().isEmpty());
|
||||
|
||||
|
||||
assertTrue (1 == _readableToNot);
|
||||
assertTrue (1 == _notToReadable);
|
||||
assertTrue (1 == _writableToNot);
|
||||
|
@@ -63,7 +63,7 @@ protected:
|
||||
|
||||
int getCount() const;
|
||||
private:
|
||||
int _count;
|
||||
std::atomic<int> _count;
|
||||
};
|
||||
|
||||
|
||||
|
12
vendor/POCO/Foundation/testsuite/src/FPETest.cpp
vendored
12
vendor/POCO/Foundation/testsuite/src/FPETest.cpp
vendored
@@ -34,7 +34,7 @@ void FPETest::testClassify()
|
||||
float b = 0.0f;
|
||||
float nan = a/b;
|
||||
float inf = 1.0f/b;
|
||||
|
||||
|
||||
assertTrue (FPE::isNaN(nan));
|
||||
assertTrue (!FPE::isNaN(a));
|
||||
assertTrue (FPE::isInfinite(inf));
|
||||
@@ -45,7 +45,7 @@ void FPETest::testClassify()
|
||||
double b = 0;
|
||||
double nan = a/b;
|
||||
double inf = 1.0/b;
|
||||
|
||||
|
||||
assertTrue (FPE::isNaN(nan));
|
||||
assertTrue (!FPE::isNaN(a));
|
||||
assertTrue (FPE::isInfinite(inf));
|
||||
@@ -89,7 +89,7 @@ void FPETest::testFlags()
|
||||
#if !defined(POCO_NO_FPENVIRONMENT)
|
||||
assertTrue (FPE::isFlag(FPE::FP_DIVIDE_BY_ZERO));
|
||||
#endif
|
||||
assertTrue (FPE::isInfinite(c));
|
||||
assertTrue (FPE::isInfinite(c));
|
||||
|
||||
FPE::clearFlags();
|
||||
a = 1.23456789e210;
|
||||
@@ -103,7 +103,7 @@ void FPETest::testFlags()
|
||||
FPE::clearFlags();
|
||||
a = 1.23456789e-99;
|
||||
b = 9.87654321e210;
|
||||
c = div(a, b);
|
||||
c = div(a, b);
|
||||
#if !defined(POCO_NO_FPENVIRONMENT)
|
||||
assertTrue (FPE::isFlag(FPE::FP_UNDERFLOW));
|
||||
#endif
|
||||
@@ -123,13 +123,13 @@ void FPETest::testFlags()
|
||||
void FPETest::testRound()
|
||||
{
|
||||
#if !defined(__osf__) && !defined(__VMS) && !defined(POCO_NO_FPENVIRONMENT)
|
||||
FPE::setRoundingMode(FPE::FP_ROUND_TONEAREST);
|
||||
FPE::setRoundingMode(FPE::FP_ROUND_TONEAREST);
|
||||
assertTrue (FPE::getRoundingMode() == FPE::FP_ROUND_TONEAREST);
|
||||
{
|
||||
FPE env(FPE::FP_ROUND_TOWARDZERO);
|
||||
assertTrue (FPE::getRoundingMode() == FPE::FP_ROUND_TOWARDZERO);
|
||||
}
|
||||
assertTrue (FPE::getRoundingMode() == FPE::FP_ROUND_TONEAREST);
|
||||
assertTrue (FPE::getRoundingMode() == FPE::FP_ROUND_TONEAREST);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -26,6 +26,9 @@
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/DirectoryIterator.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/RotateStrategy.h"
|
||||
#include "Poco/ArchiveStrategy.h"
|
||||
#include "Poco/PurgeStrategy.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -287,6 +290,57 @@ void FileChannelTest::testRotateAtTimeMinLocal()
|
||||
}
|
||||
|
||||
|
||||
class RotateByCustomStrategy : public Poco::RotateStrategy
|
||||
/// The file is rotated when the log file
|
||||
/// exceeds a given age.
|
||||
///
|
||||
/// For this to work reliably across all platforms and file systems
|
||||
/// (there are severe issues on most platforms finding out the real
|
||||
/// creation date of a file), the creation date of the file is
|
||||
/// written into the log file as the first entry.
|
||||
{
|
||||
public:
|
||||
bool mustRotate(Poco::LogFile* pFile)
|
||||
{
|
||||
return pFile->size() > 2000;
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
void FileChannelTest::testRotateByStrategy()
|
||||
{
|
||||
std::string name = filename();
|
||||
try
|
||||
{
|
||||
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
||||
|
||||
// this test rotates at 2k just like testRotateBySize. Set the prop rotation to 50k to verify that the rotation strategy takes over
|
||||
pChannel->setProperty(FileChannel::PROP_ROTATION, "50 K");
|
||||
pChannel->setRotationStrategy(new RotateByCustomStrategy());
|
||||
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 f(name + ".0");
|
||||
assertTrue(f.exists());
|
||||
f = name + ".1";
|
||||
assertTrue(f.exists());
|
||||
f = name + ".2";
|
||||
assertTrue(!f.exists());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
remove(name);
|
||||
throw;
|
||||
}
|
||||
remove(name);
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::testArchive()
|
||||
{
|
||||
std::string name = filename();
|
||||
@@ -313,6 +367,88 @@ void FileChannelTest::testArchive()
|
||||
}
|
||||
|
||||
|
||||
class ArchiveByCustomNumberStrategy : public Poco::ArchiveStrategy
|
||||
/// A monotonic increasing number is appended to the
|
||||
/// log file name. The most recent archived file
|
||||
/// always has the number zero.
|
||||
{
|
||||
public:
|
||||
Poco::LogFile* open(Poco::LogFile* pFile)
|
||||
{
|
||||
return pFile;
|
||||
}
|
||||
|
||||
|
||||
Poco::LogFile* archive(Poco::LogFile* pFile)
|
||||
{
|
||||
std::string basePath = pFile->path();
|
||||
delete pFile;
|
||||
int n = -1;
|
||||
std::string path;
|
||||
do
|
||||
{
|
||||
path = basePath;
|
||||
path = path.substr(0, path.length() - 4);
|
||||
path.append("_");
|
||||
NumberFormatter::append(path, ++n);
|
||||
path.append(".log");
|
||||
} while (exists(path));
|
||||
|
||||
while (n >= 0)
|
||||
{
|
||||
std::string oldPath = basePath;
|
||||
if (n > 0)
|
||||
{
|
||||
oldPath = oldPath.substr(0, oldPath.length() - 4);
|
||||
oldPath.append("_");
|
||||
NumberFormatter::append(oldPath, n - 1);
|
||||
oldPath.append(".log");
|
||||
}
|
||||
std::string newPath = basePath;
|
||||
newPath = newPath.substr(0, newPath.length() - 4);
|
||||
newPath.append("_");
|
||||
NumberFormatter::append(newPath, n);
|
||||
newPath.append(".log");
|
||||
moveFile(oldPath, newPath);
|
||||
--n;
|
||||
}
|
||||
return new Poco::LogFile(basePath);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void FileChannelTest::testArchiveByStrategy()
|
||||
{
|
||||
std::string name = filename();
|
||||
try
|
||||
{
|
||||
AutoPtr<FileChannel> pChannel = new FileChannel(name);
|
||||
pChannel->setProperty(FileChannel::PROP_ROTATION, "2 K");
|
||||
pChannel->setProperty(FileChannel::PROP_ARCHIVE, "number");
|
||||
|
||||
pChannel->setArchiveStrategy(new ArchiveByCustomNumberStrategy());
|
||||
|
||||
pChannel->open();
|
||||
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
|
||||
for (int i = 0; i < 200; ++i)
|
||||
{
|
||||
pChannel->log(msg);
|
||||
}
|
||||
name = name.substr(0, name.length() - 4);
|
||||
name.append("_0.log");
|
||||
|
||||
File f(name);
|
||||
assertTrue(f.exists());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
remove(name);
|
||||
throw;
|
||||
}
|
||||
remove(name);
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::testCompress()
|
||||
{
|
||||
std::string name = filename();
|
||||
@@ -544,6 +680,40 @@ void FileChannelTest::testWrongPurgeOption()
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::testPurgeByStrategy()
|
||||
{
|
||||
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, "");
|
||||
// simpler to test the type that already exists. A true "custom" purge strategy might be time based or total size based
|
||||
pChannel->setPurgeStrategy(new Poco::PurgeByCountStrategy(2));
|
||||
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");
|
||||
assertTrue(f0.exists());
|
||||
File f1(name + ".1");
|
||||
assertTrue(f1.exists());
|
||||
File f2(name + ".2");
|
||||
assertTrue(!f2.exists());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
remove(name);
|
||||
throw;
|
||||
}
|
||||
remove(name);
|
||||
}
|
||||
|
||||
|
||||
void FileChannelTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -642,11 +812,14 @@ CppUnit::Test* FileChannelTest::suite()
|
||||
CppUnit_addLongTest(pSuite, FileChannelTest, testRotateAtTimeHourLocal);
|
||||
CppUnit_addLongTest(pSuite, FileChannelTest, testRotateAtTimeMinUTC);
|
||||
CppUnit_addLongTest(pSuite, FileChannelTest, testRotateAtTimeMinLocal);
|
||||
CppUnit_addTest(pSuite, FileChannelTest, testRotateByStrategy);
|
||||
CppUnit_addTest(pSuite, FileChannelTest, testArchive);
|
||||
CppUnit_addTest(pSuite, FileChannelTest, testArchiveByStrategy);
|
||||
CppUnit_addTest(pSuite, FileChannelTest, testCompress);
|
||||
CppUnit_addLongTest(pSuite, FileChannelTest, testPurgeAge);
|
||||
CppUnit_addTest(pSuite, FileChannelTest, testPurgeCount);
|
||||
CppUnit_addTest(pSuite, FileChannelTest, testWrongPurgeOption);
|
||||
CppUnit_addTest(pSuite, FileChannelTest, testPurgeByStrategy);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@
|
||||
class FileChannelTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
enum TimeRotation
|
||||
enum TimeRotation
|
||||
{
|
||||
DAY_HOUR_MIN = 0,
|
||||
HOUR_MIN,
|
||||
@@ -39,11 +39,14 @@ public:
|
||||
void testRotateAtTimeHourLocal();
|
||||
void testRotateAtTimeMinUTC();
|
||||
void testRotateAtTimeMinLocal();
|
||||
void testRotateByStrategy();
|
||||
void testArchive();
|
||||
void testArchiveByStrategy();
|
||||
void testCompress();
|
||||
void testPurgeAge();
|
||||
void testPurgeCount();
|
||||
void testWrongPurgeOption();
|
||||
void testPurgeByStrategy();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
@@ -42,7 +42,7 @@ public:
|
||||
void testRenameFailIfExists();
|
||||
void testRootDir();
|
||||
void testLongPath();
|
||||
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
|
@@ -27,6 +27,6 @@ CppUnit::Test* FilesystemTestSuite::suite()
|
||||
pSuite->addTest(DirectoryWatcherTest::suite());
|
||||
#endif // POCO_NO_INOTIFY
|
||||
pSuite->addTest(DirectoryIteratorsTest::suite());
|
||||
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ using Poco::format;
|
||||
using Poco::BadCastException;
|
||||
using Poco::Int64;
|
||||
using Poco::UInt64;
|
||||
using Poco::Any;
|
||||
|
||||
|
||||
FormatTest::FormatTest(const std::string& name): CppUnit::TestCase(name)
|
||||
@@ -87,12 +88,12 @@ void FormatTest::testInt()
|
||||
assertTrue (s == " 42");
|
||||
s = format("%04hu", hu);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
s = format("%*hu", 4, hu);
|
||||
assertTrue (s == " 42");
|
||||
s = format("%0*hu", 4, hu);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
unsigned x = 0x42;
|
||||
s = format("%x", x);
|
||||
assertTrue (s == "42");
|
||||
@@ -126,12 +127,12 @@ void FormatTest::testInt()
|
||||
assertTrue (s == " 42");
|
||||
s = format("%04u", u);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
s = format("%*u", 4, u);
|
||||
assertTrue (s == " 42");
|
||||
s = format("%0*u", 4, u);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
long l = 42;
|
||||
s = format("%ld", l);
|
||||
assertTrue (s == "42");
|
||||
@@ -152,12 +153,12 @@ void FormatTest::testInt()
|
||||
assertTrue (s == " 42");
|
||||
s = format("%04lu", ul);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
s = format("%*lu", 4, ul);
|
||||
assertTrue (s == " 42");
|
||||
s = format("%0*lu", 4, ul);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
unsigned long xl = 0x42;
|
||||
s = format("%lx", xl);
|
||||
assertTrue (s == "42");
|
||||
@@ -165,12 +166,12 @@ void FormatTest::testInt()
|
||||
assertTrue (s == " 42");
|
||||
s = format("%04lx", xl);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
s = format("%*lx", 4, xl);
|
||||
assertTrue (s == " 42");
|
||||
s = format("%0*lx", 4, xl);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
Int64 i64 = 42;
|
||||
s = format("%Ld", i64);
|
||||
assertTrue (s == "42");
|
||||
@@ -178,12 +179,12 @@ void FormatTest::testInt()
|
||||
assertTrue (s == " 42");
|
||||
s = format("%04Ld", i64);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
s = format("%*Ld", 4, i64);
|
||||
assertTrue (s == " 42");
|
||||
s = format("%0*Ld", 4, i64);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
UInt64 ui64 = 42;
|
||||
s = format("%Lu", ui64);
|
||||
assertTrue (s == "42");
|
||||
@@ -191,18 +192,18 @@ void FormatTest::testInt()
|
||||
assertTrue (s == " 42");
|
||||
s = format("%04Lu", ui64);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
s = format("%*Lu", 4, ui64);
|
||||
assertTrue (s == " 42");
|
||||
s = format("%0*Lu", 4, ui64);
|
||||
assertTrue (s == "0042");
|
||||
|
||||
|
||||
x = 0xaa;
|
||||
s = format("%x", x);
|
||||
assertTrue (s == "aa");
|
||||
s = format("%X", x);
|
||||
assertTrue (s == "AA");
|
||||
|
||||
|
||||
i = 42;
|
||||
s = format("%+d", i);
|
||||
assertTrue (s == "+42");
|
||||
@@ -221,7 +222,7 @@ void FormatTest::testInt()
|
||||
|
||||
s = format("%d", i);
|
||||
assertTrue (s == "-42");
|
||||
|
||||
|
||||
x = 0x42;
|
||||
s = format("%#x", x);
|
||||
assertTrue (s == "0x42");
|
||||
@@ -264,7 +265,7 @@ void FormatTest::testAnyInt()
|
||||
char c = 42;
|
||||
std::string s(format("%?i", c));
|
||||
assertTrue (s == "42");
|
||||
|
||||
|
||||
c = 43;
|
||||
s.clear();
|
||||
format(s, "%?i", c);
|
||||
@@ -277,35 +278,35 @@ void FormatTest::testAnyInt()
|
||||
signed char sc = -42;
|
||||
s = format("%?i", sc);
|
||||
assertTrue (s == "-42");
|
||||
|
||||
|
||||
unsigned char uc = 65;
|
||||
s = format("%?i", uc);
|
||||
assertTrue (s == "65");
|
||||
|
||||
|
||||
short ss = -134;
|
||||
s = format("%?i", ss);
|
||||
assertTrue (s == "-134");
|
||||
|
||||
|
||||
unsigned short us = 200;
|
||||
s = format("%?i", us);
|
||||
assertTrue (s == "200");
|
||||
|
||||
|
||||
int i = -12345;
|
||||
s = format("%?i", i);
|
||||
assertTrue (s == "-12345");
|
||||
|
||||
|
||||
unsigned ui = 12345;
|
||||
s = format("%?i", ui);
|
||||
assertTrue (s == "12345");
|
||||
|
||||
|
||||
long l = -54321;
|
||||
s = format("%?i", l);
|
||||
assertTrue (s == "-54321");
|
||||
|
||||
|
||||
unsigned long ul = 54321;
|
||||
s = format("%?i", ul);
|
||||
assertTrue (s == "54321");
|
||||
|
||||
|
||||
Int64 i64 = -12345678;
|
||||
s = format("%?i", i64);
|
||||
assertTrue (s == "-12345678");
|
||||
@@ -313,7 +314,7 @@ void FormatTest::testAnyInt()
|
||||
UInt64 ui64 = 12345678;
|
||||
s = format("%?i", ui64);
|
||||
assertTrue (s == "12345678");
|
||||
|
||||
|
||||
ss = 0x42;
|
||||
s = format("%?x", ss);
|
||||
assertTrue (s == "42");
|
||||
@@ -340,12 +341,12 @@ void FormatTest::testFloatFix()
|
||||
assertTrue (s == " 1.50");
|
||||
s = format("%-6.2f", d);
|
||||
assertTrue (s == "1.50 ");
|
||||
|
||||
|
||||
s = format("%*.*f", 6, 2, d);
|
||||
assertTrue (s == " 1.50");
|
||||
s = format("%-*.*f", 6,2, d);
|
||||
assertTrue (s == "1.50 ");
|
||||
|
||||
|
||||
float f = 1.5;
|
||||
s = format("%hf", f);
|
||||
assertTrue (s.find("1.50") == 0);
|
||||
@@ -422,7 +423,7 @@ void FormatTest::testMultiple()
|
||||
|
||||
s = format("%%%d%%%d%%%d", 1, 2, 3);
|
||||
assertTrue (s == "%1%2%3");
|
||||
|
||||
|
||||
s = format("%d%d%d%d", 1, 2, 3, 4);
|
||||
assertTrue (s == "1234");
|
||||
|
||||
@@ -453,6 +454,27 @@ void FormatTest::testIndex()
|
||||
}
|
||||
|
||||
|
||||
void FormatTest::testAny()
|
||||
{
|
||||
Any a = 42;
|
||||
std::string s(format("%d", a));
|
||||
assertTrue (s == "42");
|
||||
|
||||
a = std::string("42");
|
||||
s = format("%s", a);
|
||||
assertTrue (s == "42");
|
||||
|
||||
a = 42.;
|
||||
s = format("%f", a);
|
||||
assertTrue (s.find("42.0") == 0);
|
||||
|
||||
s.clear();
|
||||
std::vector<Any> av{ 42, std::string("42"), 42. };
|
||||
format(s, "%d '%s' %f", av);
|
||||
assertTrue (s.find("42 '42' 42.0") == 0);
|
||||
}
|
||||
|
||||
|
||||
void FormatTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -476,6 +498,7 @@ CppUnit::Test* FormatTest::suite()
|
||||
CppUnit_addTest(pSuite, FormatTest, testString);
|
||||
CppUnit_addTest(pSuite, FormatTest, testMultiple);
|
||||
CppUnit_addTest(pSuite, FormatTest, testIndex);
|
||||
CppUnit_addTest(pSuite, FormatTest, testAny);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ public:
|
||||
void testString();
|
||||
void testMultiple();
|
||||
void testIndex();
|
||||
void testAny();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
@@ -39,7 +39,7 @@ void GlobTest::testMatchChars()
|
||||
assertTrue (!g1.match("b"));
|
||||
assertTrue (!g1.match("aa"));
|
||||
assertTrue (!g1.match(""));
|
||||
|
||||
|
||||
Glob g2("ab");
|
||||
assertTrue (g2.match("ab"));
|
||||
assertTrue (!g2.match("aab"));
|
||||
@@ -54,24 +54,24 @@ void GlobTest::testMatchQM()
|
||||
assertTrue (g1.match("b"));
|
||||
assertTrue (!g1.match("aa"));
|
||||
assertTrue (g1.match("."));
|
||||
|
||||
|
||||
Glob g2("\\?");
|
||||
assertTrue (g2.match("?"));
|
||||
assertTrue (!g2.match("a"));
|
||||
assertTrue (!g2.match("ab"));
|
||||
|
||||
|
||||
Glob g3("a?");
|
||||
assertTrue (g3.match("aa"));
|
||||
assertTrue (g3.match("az"));
|
||||
assertTrue (!g3.match("a"));
|
||||
assertTrue (!g3.match("aaa"));
|
||||
|
||||
|
||||
Glob g4("??");
|
||||
assertTrue (g4.match("aa"));
|
||||
assertTrue (g4.match("ab"));
|
||||
assertTrue (!g4.match("a"));
|
||||
assertTrue (!g4.match("abc"));
|
||||
|
||||
|
||||
Glob g5("?a?");
|
||||
assertTrue (g5.match("aaa"));
|
||||
assertTrue (g5.match("bac"));
|
||||
@@ -83,7 +83,7 @@ void GlobTest::testMatchQM()
|
||||
assertTrue (g6.match("a?"));
|
||||
assertTrue (!g6.match("az"));
|
||||
assertTrue (!g6.match("a"));
|
||||
|
||||
|
||||
Glob g7("?", Glob::GLOB_DOT_SPECIAL);
|
||||
assertTrue (g7.match("a"));
|
||||
assertTrue (g7.match("b"));
|
||||
@@ -100,7 +100,7 @@ void GlobTest::testMatchAsterisk()
|
||||
assertTrue (g1.match("ab"));
|
||||
assertTrue (g1.match("abc"));
|
||||
assertTrue (g1.match("."));
|
||||
|
||||
|
||||
Glob g2("a*");
|
||||
assertTrue (g2.match("a"));
|
||||
assertTrue (g2.match("aa"));
|
||||
@@ -114,7 +114,7 @@ void GlobTest::testMatchAsterisk()
|
||||
assertTrue (g3.match("abab"));
|
||||
assertTrue (!g3.match("ac"));
|
||||
assertTrue (!g3.match("baab"));
|
||||
|
||||
|
||||
Glob g4("*a");
|
||||
assertTrue (g4.match("a"));
|
||||
assertTrue (g4.match("ba"));
|
||||
@@ -124,7 +124,7 @@ void GlobTest::testMatchAsterisk()
|
||||
assertTrue (!g4.match("b"));
|
||||
assertTrue (!g4.match("ab"));
|
||||
assertTrue (!g4.match("aaab"));
|
||||
|
||||
|
||||
Glob g5("a*a");
|
||||
assertTrue (g5.match("aa"));
|
||||
assertTrue (g5.match("aba"));
|
||||
@@ -132,14 +132,14 @@ void GlobTest::testMatchAsterisk()
|
||||
assertTrue (!g5.match("aab"));
|
||||
assertTrue (!g5.match("aaab"));
|
||||
assertTrue (!g5.match("baaaa"));
|
||||
|
||||
|
||||
Glob g6("a*b*c");
|
||||
assertTrue (g6.match("abc"));
|
||||
assertTrue (g6.match("aabbcc"));
|
||||
assertTrue (g6.match("abcbbc"));
|
||||
assertTrue (g6.match("aaaabbbbcccc"));
|
||||
assertTrue (!g6.match("aaaabbbcb"));
|
||||
|
||||
|
||||
Glob g7("a*b*");
|
||||
assertTrue (g7.match("aaabbb"));
|
||||
assertTrue (g7.match("abababab"));
|
||||
@@ -154,18 +154,18 @@ void GlobTest::testMatchAsterisk()
|
||||
assertTrue (g1.match("a"));
|
||||
assertTrue (g1.match("ab"));
|
||||
assertTrue (g1.match("abc"));
|
||||
|
||||
|
||||
Glob g9("a\\*");
|
||||
assertTrue (g9.match("a*"));
|
||||
assertTrue (!g9.match("aa"));
|
||||
assertTrue (!g9.match("a"));
|
||||
|
||||
|
||||
Glob g10("a*\\*");
|
||||
assertTrue (g10.match("a*"));
|
||||
assertTrue (g10.match("aaa*"));
|
||||
assertTrue (!g10.match("a"));
|
||||
assertTrue (!g10.match("aa"));
|
||||
|
||||
|
||||
Glob g11("*", Glob::GLOB_DOT_SPECIAL);
|
||||
assertTrue (g11.match(""));
|
||||
assertTrue (g11.match("a"));
|
||||
@@ -181,35 +181,35 @@ void GlobTest::testMatchRange()
|
||||
assertTrue (g1.match("a"));
|
||||
assertTrue (!g1.match("b"));
|
||||
assertTrue (!g1.match("aa"));
|
||||
|
||||
|
||||
Glob g2("[ab]");
|
||||
assertTrue (g2.match("a"));
|
||||
assertTrue (g2.match("b"));
|
||||
assertTrue (!g2.match("c"));
|
||||
assertTrue (!g2.match("ab"));
|
||||
|
||||
|
||||
Glob g3("[abc]");
|
||||
assertTrue (g3.match("a"));
|
||||
assertTrue (g3.match("b"));
|
||||
assertTrue (g3.match("c"));
|
||||
assertTrue (!g3.match("ab"));
|
||||
|
||||
|
||||
Glob g4("[a-z]");
|
||||
assertTrue (g4.match("a"));
|
||||
assertTrue (g4.match("z"));
|
||||
assertTrue (!g4.match("A"));
|
||||
|
||||
|
||||
Glob g5("[!a]");
|
||||
assertTrue (g5.match("b"));
|
||||
assertTrue (g5.match("c"));
|
||||
assertTrue (!g5.match("a"));
|
||||
assertTrue (!g5.match("bb"));
|
||||
|
||||
|
||||
Glob g6("[!a-z]");
|
||||
assertTrue (g6.match("A"));
|
||||
assertTrue (!g6.match("a"));
|
||||
assertTrue (!g6.match("z"));
|
||||
|
||||
|
||||
Glob g7("[0-9a-zA-Z_]");
|
||||
assertTrue (g7.match("0"));
|
||||
assertTrue (g7.match("1"));
|
||||
@@ -222,51 +222,51 @@ void GlobTest::testMatchRange()
|
||||
assertTrue (g7.match("Z"));
|
||||
assertTrue (g7.match("_"));
|
||||
assertTrue (!g7.match("-"));
|
||||
|
||||
|
||||
Glob g8("[1-3]");
|
||||
assertTrue (g8.match("1"));
|
||||
assertTrue (g8.match("2"));
|
||||
assertTrue (g8.match("3"));
|
||||
assertTrue (!g8.match("0"));
|
||||
assertTrue (!g8.match("4"));
|
||||
|
||||
|
||||
Glob g9("[!1-3]");
|
||||
assertTrue (g9.match("0"));
|
||||
assertTrue (g9.match("4"));
|
||||
assertTrue (!g9.match("1"));
|
||||
assertTrue (!g9.match("2"));
|
||||
assertTrue (!g9.match("3"));
|
||||
|
||||
|
||||
Glob g10("[\\!a]");
|
||||
assertTrue (g10.match("!"));
|
||||
assertTrue (g10.match("a"));
|
||||
assertTrue (!g10.match("x"));
|
||||
|
||||
|
||||
Glob g11("[a\\-c]");
|
||||
assertTrue (g11.match("a"));
|
||||
assertTrue (g11.match("c"));
|
||||
assertTrue (g11.match("-"));
|
||||
assertTrue (!g11.match("b"));
|
||||
|
||||
|
||||
Glob g12("[\\]]");
|
||||
assertTrue (g12.match("]"));
|
||||
assertTrue (!g12.match("["));
|
||||
|
||||
|
||||
Glob g13("[[\\]]");
|
||||
assertTrue (g13.match("["));
|
||||
assertTrue (g13.match("]"));
|
||||
assertTrue (!g13.match("x"));
|
||||
|
||||
|
||||
Glob g14("\\[]");
|
||||
assertTrue (g14.match("[]"));
|
||||
assertTrue (!g14.match("[["));
|
||||
|
||||
|
||||
Glob g15("a[bc]");
|
||||
assertTrue (g15.match("ab"));
|
||||
assertTrue (g15.match("ac"));
|
||||
assertTrue (!g15.match("a"));
|
||||
assertTrue (!g15.match("aa"));
|
||||
|
||||
|
||||
Glob g16("[ab]c");
|
||||
assertTrue (g16.match("ac"));
|
||||
assertTrue (g16.match("bc"));
|
||||
@@ -282,24 +282,24 @@ void GlobTest::testMisc()
|
||||
Glob g1("*.cpp");
|
||||
assertTrue (g1.match("Glob.cpp"));
|
||||
assertTrue (!g1.match("Glob.h"));
|
||||
|
||||
|
||||
Glob g2("*.[hc]");
|
||||
assertTrue (g2.match("foo.c"));
|
||||
assertTrue (g2.match("foo.h"));
|
||||
assertTrue (!g2.match("foo.i"));
|
||||
|
||||
|
||||
Glob g3("*.*");
|
||||
assertTrue (g3.match("foo.cpp"));
|
||||
assertTrue (g3.match("foo.h"));
|
||||
assertTrue (g3.match("foo."));
|
||||
assertTrue (!g3.match("foo"));
|
||||
|
||||
|
||||
Glob g4("File*.?pp");
|
||||
assertTrue (g4.match("File.hpp"));
|
||||
assertTrue (g4.match("File.cpp"));
|
||||
assertTrue (g4.match("Filesystem.hpp"));
|
||||
assertTrue (!g4.match("File.h"));
|
||||
|
||||
|
||||
Glob g5("File*.[ch]*");
|
||||
assertTrue (g5.match("File.hpp"));
|
||||
assertTrue (g5.match("File.cpp"));
|
||||
@@ -316,7 +316,7 @@ void GlobTest::testCaseless()
|
||||
assertTrue (!g1.match("Glob.h"));
|
||||
assertTrue (g1.match("Glob.CPP"));
|
||||
assertTrue (!g1.match("Glob.H"));
|
||||
|
||||
|
||||
Glob g2("*.[hc]", Glob::GLOB_CASELESS);
|
||||
assertTrue (g2.match("foo.c"));
|
||||
assertTrue (g2.match("foo.h"));
|
||||
@@ -324,7 +324,7 @@ void GlobTest::testCaseless()
|
||||
assertTrue (g2.match("foo.C"));
|
||||
assertTrue (g2.match("foo.H"));
|
||||
assertTrue (!g2.match("foo.I"));
|
||||
|
||||
|
||||
Glob g4("File*.?pp", Glob::GLOB_CASELESS);
|
||||
assertTrue (g4.match("file.hpp"));
|
||||
assertTrue (g4.match("FILE.CPP"));
|
||||
@@ -332,7 +332,7 @@ void GlobTest::testCaseless()
|
||||
assertTrue (g4.match("FILESYSTEM.HPP"));
|
||||
assertTrue (!g4.match("FILE.H"));
|
||||
assertTrue (!g4.match("file.h"));
|
||||
|
||||
|
||||
Glob g5("File*.[ch]*", Glob::GLOB_CASELESS);
|
||||
assertTrue (g5.match("file.hpp"));
|
||||
assertTrue (g5.match("FILE.HPP"));
|
||||
@@ -387,7 +387,7 @@ void GlobTest::testGlob()
|
||||
createFile("globtest/testsuite/src/test.h");
|
||||
createFile("globtest/testsuite/src/test.c");
|
||||
createFile("globtest/testsuite/src/main.c");
|
||||
|
||||
|
||||
std::set<std::string> files;
|
||||
Glob::glob("globtest/*", files);
|
||||
translatePaths(files);
|
||||
@@ -407,7 +407,7 @@ void GlobTest::testGlob()
|
||||
assertTrue (files.find("globtest/include/") != files.end());
|
||||
assertTrue (files.find("globtest/src/") != files.end());
|
||||
assertTrue (files.find("globtest/testsuite/") != files.end());
|
||||
|
||||
|
||||
files.clear();
|
||||
Glob::glob("globtest/*/*.[hc]", files);
|
||||
translatePaths(files);
|
||||
@@ -417,7 +417,7 @@ void GlobTest::testGlob()
|
||||
assertTrue (files.find("globtest/src/one.c") != files.end());
|
||||
assertTrue (files.find("globtest/src/one.c") != files.end());
|
||||
assertTrue (files.find("globtest/src/main.c") != files.end());
|
||||
|
||||
|
||||
files.clear();
|
||||
Glob::glob("gl?bt?st/*/*/*.c", files);
|
||||
translatePaths(files);
|
||||
@@ -431,7 +431,7 @@ void GlobTest::testGlob()
|
||||
assertTrue (files.size() == 2);
|
||||
assertTrue (files.find("globtest/testsuite/src/test.c") != files.end());
|
||||
assertTrue (files.find("globtest/testsuite/src/main.c") != files.end());
|
||||
|
||||
|
||||
files.clear();
|
||||
Glob::glob("globtest/*/src/*", files);
|
||||
translatePaths(files);
|
||||
@@ -439,7 +439,7 @@ void GlobTest::testGlob()
|
||||
assertTrue (files.find("globtest/testsuite/src/test.h") != files.end());
|
||||
assertTrue (files.find("globtest/testsuite/src/test.c") != files.end());
|
||||
assertTrue (files.find("globtest/testsuite/src/main.c") != files.end());
|
||||
|
||||
|
||||
files.clear();
|
||||
Glob::glob("globtest/*/", files);
|
||||
translatePaths(files);
|
||||
@@ -463,7 +463,7 @@ void GlobTest::testGlob()
|
||||
translatePaths(files);
|
||||
assertTrue (files.size() == 1);
|
||||
#endif
|
||||
|
||||
|
||||
File dir("globtest");
|
||||
dir.remove(true);
|
||||
}
|
||||
|
@@ -13,10 +13,16 @@
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/HMACEngine.h"
|
||||
#include "Poco/MD5Engine.h"
|
||||
#include "Poco/SHA2Engine.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
using Poco::HMACEngine;
|
||||
using Poco::MD5Engine;
|
||||
using Poco::SHA2Engine224;
|
||||
using Poco::SHA2Engine256;
|
||||
using Poco::SHA2Engine384;
|
||||
using Poco::SHA2Engine512;
|
||||
using Poco::DigestEngine;
|
||||
|
||||
|
||||
@@ -30,24 +36,24 @@ HMACEngineTest::~HMACEngineTest()
|
||||
}
|
||||
|
||||
|
||||
void HMACEngineTest::testHMAC()
|
||||
void HMACEngineTest::testHMAC_MD5()
|
||||
{
|
||||
// test vectors from RFC 2104
|
||||
|
||||
|
||||
std::string key(16, 0x0b);
|
||||
std::string data("Hi There");
|
||||
HMACEngine<MD5Engine> hmac1(key);
|
||||
hmac1.update(data);
|
||||
std::string digest = DigestEngine::digestToHex(hmac1.digest());
|
||||
assertTrue (digest == "9294727a3638bb1c13f48ef8158bfc9d");
|
||||
|
||||
|
||||
key = "Jefe";
|
||||
data = "what do ya want for nothing?";
|
||||
HMACEngine<MD5Engine> hmac2(key);
|
||||
hmac2.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac2.digest());
|
||||
assertTrue (digest == "750c783e6ab0b503eaa86e310a5db738");
|
||||
|
||||
|
||||
key = std::string(16, std::string::value_type(0xaa));
|
||||
data = std::string(50, std::string::value_type(0xdd));
|
||||
HMACEngine<MD5Engine> hmac3(key);
|
||||
@@ -57,6 +63,324 @@ void HMACEngineTest::testHMAC()
|
||||
}
|
||||
|
||||
|
||||
void HMACEngineTest::testHMAC_SHA2_224()
|
||||
{
|
||||
// test vectors from RFC 4231
|
||||
|
||||
std::string key(20, 0x0b);
|
||||
std::string data("Hi There");
|
||||
HMACEngine<SHA2Engine224> hmac1(key);
|
||||
hmac1.update(data);
|
||||
std::string digest = DigestEngine::digestToHex(hmac1.digest());
|
||||
assertTrue (digest == "896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22");
|
||||
|
||||
key = "Jefe";
|
||||
data = "what do ya want for nothing?";
|
||||
HMACEngine<SHA2Engine224> hmac2(key);
|
||||
hmac2.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac2.digest());
|
||||
assertTrue (digest == "a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44");
|
||||
|
||||
key = std::string(20, std::string::value_type(0xaa));
|
||||
data = std::string(50, std::string::value_type(0xdd));
|
||||
HMACEngine<SHA2Engine224> hmac3(key);
|
||||
hmac3.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac3.digest());
|
||||
assertTrue (digest == "7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea");
|
||||
|
||||
std::vector<char> str = {
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
|
||||
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
|
||||
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19
|
||||
};
|
||||
key = std::string(str.begin(), str.end()); // 25 bytes
|
||||
data = std::string(50, 0xcd);
|
||||
HMACEngine<SHA2Engine224> hmac4(key);
|
||||
hmac4.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac4.digest());
|
||||
assertTrue (digest == "6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a");
|
||||
|
||||
key = std::string(20, std::string::value_type(0x0c));
|
||||
data = std::string("Test With Truncation");
|
||||
HMACEngine<SHA2Engine224> hmac5(key);
|
||||
hmac5.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac5.digest(), 16);
|
||||
assertTrue (digest == "0e2aea68a90c8d37c988bcdb9fca6fa8");
|
||||
|
||||
key = std::string(131, std::string::value_type(0xaa));
|
||||
data = std::string("Test Using Larger Than Block-Size Key - Hash Key First");
|
||||
HMACEngine<SHA2Engine224> hmac6(key);
|
||||
hmac6.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac6.digest());
|
||||
assertTrue (digest == "95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e");
|
||||
|
||||
key = std::string(131, std::string::value_type(0xaa));
|
||||
data = std::string("This is a test using a larger than block-size key "
|
||||
"and a larger than block-size data. The key needs to be hashed "
|
||||
"before being used by the HMAC algorithm.");
|
||||
HMACEngine<SHA2Engine224> hmac7(key);
|
||||
hmac7.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac7.digest());
|
||||
assertTrue (digest == "3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1");
|
||||
|
||||
HMACEngine<SHA2Engine224> hmac8(key);
|
||||
hmac8.update(data);
|
||||
try
|
||||
{
|
||||
const DigestEngine::Digest& d = hmac8.digest();
|
||||
digest = DigestEngine::digestToHex(d, d.size()+1);
|
||||
fail("Invalid digest length, must throw.");
|
||||
}
|
||||
catch(const Poco::InvalidArgumentException& e) {}
|
||||
}
|
||||
|
||||
|
||||
void HMACEngineTest::testHMAC_SHA2_256()
|
||||
{
|
||||
// test vectors from RFC 4231
|
||||
|
||||
std::string key(20, 0x0b);
|
||||
std::string data("Hi There");
|
||||
HMACEngine<SHA2Engine256> hmac1(key);
|
||||
hmac1.update(data);
|
||||
std::string digest = DigestEngine::digestToHex(hmac1.digest());
|
||||
assertTrue (digest == "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7");
|
||||
|
||||
key = "Jefe";
|
||||
data = "what do ya want for nothing?";
|
||||
HMACEngine<SHA2Engine256> hmac2(key);
|
||||
hmac2.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac2.digest());
|
||||
assertTrue (digest == "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843");
|
||||
|
||||
key = std::string(20, std::string::value_type(0xaa));
|
||||
data = std::string(50, std::string::value_type(0xdd));
|
||||
HMACEngine<SHA2Engine256> hmac3(key);
|
||||
hmac3.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac3.digest());
|
||||
assertTrue (digest == "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe");
|
||||
|
||||
std::vector<char> str = {
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
|
||||
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
|
||||
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19
|
||||
};
|
||||
key = std::string(str.begin(), str.end()); // 25 bytes
|
||||
data = std::string(50, 0xcd);
|
||||
HMACEngine<SHA2Engine256> hmac4(key);
|
||||
hmac4.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac4.digest());
|
||||
assertTrue (digest == "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b");
|
||||
|
||||
key = std::string(20, std::string::value_type(0x0c));
|
||||
data = std::string("Test With Truncation");
|
||||
HMACEngine<SHA2Engine256> hmac5(key);
|
||||
hmac5.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac5.digest(), 16);
|
||||
assertTrue (digest == "a3b6167473100ee06e0c796c2955552b");
|
||||
|
||||
key = std::string(131, std::string::value_type(0xaa));
|
||||
data = std::string("Test Using Larger Than Block-Size Key - Hash Key First");
|
||||
HMACEngine<SHA2Engine256> hmac6(key);
|
||||
hmac6.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac6.digest());
|
||||
assertTrue (digest == "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54");
|
||||
|
||||
key = std::string(131, std::string::value_type(0xaa));
|
||||
data = std::string("This is a test using a larger than block-size key "
|
||||
"and a larger than block-size data. The key needs to be hashed "
|
||||
"before being used by the HMAC algorithm.");
|
||||
HMACEngine<SHA2Engine256> hmac7(key);
|
||||
hmac7.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac7.digest());
|
||||
assertTrue (digest == "9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2");
|
||||
|
||||
HMACEngine<SHA2Engine256> hmac8(key);
|
||||
hmac8.update(data);
|
||||
try
|
||||
{
|
||||
const DigestEngine::Digest& d = hmac8.digest();
|
||||
digest = DigestEngine::digestToHex(d, d.size()+1);
|
||||
fail("Invalid digest length, must throw.");
|
||||
}
|
||||
catch(const Poco::InvalidArgumentException& e) {}
|
||||
}
|
||||
|
||||
|
||||
void HMACEngineTest::testHMAC_SHA2_384()
|
||||
{
|
||||
// test vectors from RFC 4231
|
||||
|
||||
std::string key(20, 0x0b);
|
||||
std::string data("Hi There");
|
||||
HMACEngine<SHA2Engine384> hmac1(key);
|
||||
hmac1.update(data);
|
||||
std::string digest = DigestEngine::digestToHex(hmac1.digest());
|
||||
assertTrue (digest == "afd03944d84895626b0825f4ab46907f"
|
||||
"15f9dadbe4101ec682aa034c7cebc59c"
|
||||
"faea9ea9076ede7f4af152e8b2fa9cb6");
|
||||
|
||||
key = "Jefe";
|
||||
data = "what do ya want for nothing?";
|
||||
HMACEngine<SHA2Engine384> hmac2(key);
|
||||
hmac2.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac2.digest());
|
||||
assertTrue (digest == "af45d2e376484031617f78d2b58a6b1b"
|
||||
"9c7ef464f5a01b47e42ec3736322445e"
|
||||
"8e2240ca5e69e2c78b3239ecfab21649");
|
||||
|
||||
key = std::string(20, std::string::value_type(0xaa));
|
||||
data = std::string(50, std::string::value_type(0xdd));
|
||||
HMACEngine<SHA2Engine384> hmac3(key);
|
||||
hmac3.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac3.digest());
|
||||
assertTrue (digest == "88062608d3e6ad8a0aa2ace014c8a86f"
|
||||
"0aa635d947ac9febe83ef4e55966144b"
|
||||
"2a5ab39dc13814b94e3ab6e101a34f27");
|
||||
|
||||
std::vector<char> str = {
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
|
||||
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
|
||||
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19
|
||||
};
|
||||
key = std::string(str.begin(), str.end()); // 25 bytes
|
||||
data = std::string(50, 0xcd);
|
||||
HMACEngine<SHA2Engine384> hmac4(key);
|
||||
hmac4.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac4.digest());
|
||||
assertTrue (digest == "3e8a69b7783c25851933ab6290af6ca7"
|
||||
"7a9981480850009cc5577c6e1f573b4e"
|
||||
"6801dd23c4a7d679ccf8a386c674cffb");
|
||||
|
||||
key = std::string(20, std::string::value_type(0x0c));
|
||||
data = std::string("Test With Truncation");
|
||||
HMACEngine<SHA2Engine384> hmac5(key);
|
||||
hmac5.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac5.digest(), 16);
|
||||
assertTrue (digest == "3abf34c3503b2a23a46efc619baef897");
|
||||
|
||||
key = std::string(131, std::string::value_type(0xaa));
|
||||
data = std::string("Test Using Larger Than Block-Size Key - Hash Key First");
|
||||
HMACEngine<SHA2Engine384> hmac6(key);
|
||||
hmac6.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac6.digest());
|
||||
assertTrue (digest == "4ece084485813e9088d2c63a041bc5b4"
|
||||
"4f9ef1012a2b588f3cd11f05033ac4c6"
|
||||
"0c2ef6ab4030fe8296248df163f44952");
|
||||
|
||||
key = std::string(131, std::string::value_type(0xaa));
|
||||
data = std::string("This is a test using a larger than block-size key "
|
||||
"and a larger than block-size data. The key needs to be hashed "
|
||||
"before being used by the HMAC algorithm.");
|
||||
HMACEngine<SHA2Engine384> hmac7(key);
|
||||
hmac7.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac7.digest());
|
||||
assertTrue (digest == "6617178e941f020d351e2f254e8fd32c"
|
||||
"602420feb0b8fb9adccebb82461e99c5"
|
||||
"a678cc31e799176d3860e6110c46523e");
|
||||
|
||||
HMACEngine<SHA2Engine384> hmac8(key);
|
||||
hmac8.update(data);
|
||||
try
|
||||
{
|
||||
const DigestEngine::Digest& d = hmac8.digest();
|
||||
digest = DigestEngine::digestToHex(d, d.size()+1);
|
||||
fail("Invalid digest length, must throw.");
|
||||
}
|
||||
catch(const Poco::InvalidArgumentException& e) {}
|
||||
}
|
||||
|
||||
|
||||
void HMACEngineTest::testHMAC_SHA2_512()
|
||||
{
|
||||
// test vectors from RFC 4231
|
||||
|
||||
std::string key(20, 0x0b);
|
||||
std::string data("Hi There");
|
||||
HMACEngine<SHA2Engine512> hmac1(key);
|
||||
hmac1.update(data);
|
||||
std::string digest = DigestEngine::digestToHex(hmac1.digest());
|
||||
assertTrue (digest == "87aa7cdea5ef619d4ff0b4241a1d6cb0"
|
||||
"2379f4e2ce4ec2787ad0b30545e17cde"
|
||||
"daa833b7d6b8a702038b274eaea3f4e4"
|
||||
"be9d914eeb61f1702e696c203a126854");
|
||||
|
||||
key = "Jefe";
|
||||
data = "what do ya want for nothing?";
|
||||
HMACEngine<SHA2Engine512> hmac2(key);
|
||||
hmac2.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac2.digest());
|
||||
assertTrue (digest == "164b7a7bfcf819e2e395fbe73b56e0a3"
|
||||
"87bd64222e831fd610270cd7ea250554"
|
||||
"9758bf75c05a994a6d034f65f8f0e6fd"
|
||||
"caeab1a34d4a6b4b636e070a38bce737");
|
||||
|
||||
key = std::string(20, std::string::value_type(0xaa));
|
||||
data = std::string(50, std::string::value_type(0xdd));
|
||||
HMACEngine<SHA2Engine512> hmac3(key);
|
||||
hmac3.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac3.digest());
|
||||
assertTrue (digest == "fa73b0089d56a284efb0f0756c890be9"
|
||||
"b1b5dbdd8ee81a3655f83e33b2279d39"
|
||||
"bf3e848279a722c806b485a47e67c807"
|
||||
"b946a337bee8942674278859e13292fb");
|
||||
|
||||
std::vector<char> str = {
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
|
||||
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
|
||||
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19
|
||||
};
|
||||
key = std::string(str.begin(), str.end()); // 25 bytes
|
||||
data = std::string(50, 0xcd);
|
||||
HMACEngine<SHA2Engine512> hmac4(key);
|
||||
hmac4.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac4.digest());
|
||||
assertTrue (digest == "b0ba465637458c6990e5a8c5f61d4af7"
|
||||
"e576d97ff94b872de76f8050361ee3db"
|
||||
"a91ca5c11aa25eb4d679275cc5788063"
|
||||
"a5f19741120c4f2de2adebeb10a298dd");
|
||||
|
||||
key = std::string(20, std::string::value_type(0x0c));
|
||||
data = std::string("Test With Truncation");
|
||||
HMACEngine<SHA2Engine512> hmac5(key);
|
||||
hmac5.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac5.digest(), 16);
|
||||
assertTrue (digest == "415fad6271580a531d4179bc891d87a6");
|
||||
|
||||
key = std::string(131, std::string::value_type(0xaa));
|
||||
data = std::string("Test Using Larger Than Block-Size Key - Hash Key First");
|
||||
HMACEngine<SHA2Engine512> hmac6(key);
|
||||
hmac6.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac6.digest());
|
||||
assertTrue (digest == "80b24263c7c1a3ebb71493c1dd7be8b4"
|
||||
"9b46d1f41b4aeec1121b013783f8f352"
|
||||
"6b56d037e05f2598bd0fd2215d6a1e52"
|
||||
"95e64f73f63f0aec8b915a985d786598");
|
||||
|
||||
key = std::string(131, std::string::value_type(0xaa));
|
||||
data = std::string("This is a test using a larger than block-size key "
|
||||
"and a larger than block-size data. The key needs to be hashed "
|
||||
"before being used by the HMAC algorithm.");
|
||||
HMACEngine<SHA2Engine512> hmac7(key);
|
||||
hmac7.update(data);
|
||||
digest = DigestEngine::digestToHex(hmac7.digest());
|
||||
assertTrue (digest == "e37b6a775dc87dbaa4dfa9f96e5e3ffd"
|
||||
"debd71f8867289865df5a32d20cdc944"
|
||||
"b6022cac3c4982b10d5eeb55c3e4de15"
|
||||
"134676fb6de0446065c97440fa8c6a58");
|
||||
|
||||
HMACEngine<SHA2Engine512> hmac8(key);
|
||||
hmac8.update(data);
|
||||
try
|
||||
{
|
||||
const DigestEngine::Digest& d = hmac8.digest();
|
||||
digest = DigestEngine::digestToHex(d, d.size()+1);
|
||||
fail("Invalid digest length, must throw.");
|
||||
}
|
||||
catch(const Poco::InvalidArgumentException& e) {}
|
||||
}
|
||||
|
||||
|
||||
void HMACEngineTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -71,7 +395,11 @@ CppUnit::Test* HMACEngineTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HMACEngineTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HMACEngineTest, testHMAC);
|
||||
CppUnit_addTest(pSuite, HMACEngineTest, testHMAC_MD5);
|
||||
CppUnit_addTest(pSuite, HMACEngineTest, testHMAC_SHA2_224);
|
||||
CppUnit_addTest(pSuite, HMACEngineTest, testHMAC_SHA2_256);
|
||||
CppUnit_addTest(pSuite, HMACEngineTest, testHMAC_SHA2_384);
|
||||
CppUnit_addTest(pSuite, HMACEngineTest, testHMAC_SHA2_512);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -24,7 +24,11 @@ public:
|
||||
HMACEngineTest(const std::string& name);
|
||||
~HMACEngineTest();
|
||||
|
||||
void testHMAC();
|
||||
void testHMAC_MD5();
|
||||
void testHMAC_SHA2_224();
|
||||
void testHMAC_SHA2_256();
|
||||
void testHMAC_SHA2_384();
|
||||
void testHMAC_SHA2_512();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
@@ -35,9 +35,9 @@ void HashMapTest::testInsert()
|
||||
|
||||
typedef HashMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
|
||||
assertTrue (hm.empty());
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, i*2));
|
||||
@@ -50,10 +50,10 @@ void HashMapTest::testInsert()
|
||||
assertTrue (it->second == i*2);
|
||||
assertTrue (hm.count(i) == 1);
|
||||
assertTrue (hm.size() == i + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assertTrue (!hm.empty());
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
@@ -61,14 +61,14 @@ void HashMapTest::testInsert()
|
||||
assertTrue (it->first == i);
|
||||
assertTrue (it->second == i*2);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, 0));
|
||||
assertTrue (res.first->first == i);
|
||||
assertTrue (res.first->second == i*2);
|
||||
assertTrue (!res.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ void HashMapTest::testErase()
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
assertTrue (hm.size() == N);
|
||||
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hm.erase(i);
|
||||
@@ -92,13 +92,13 @@ void HashMapTest::testErase()
|
||||
assertTrue (it == hm.end());
|
||||
}
|
||||
assertTrue (hm.size() == N/2);
|
||||
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assertTrue (it == hm.end());
|
||||
}
|
||||
|
||||
|
||||
for (int i = 1; i < N; i += 2)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
@@ -110,13 +110,13 @@ void HashMapTest::testErase()
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assertTrue (it != hm.end());
|
||||
assertTrue (it->first == i);
|
||||
assertTrue (it->second == i*2);
|
||||
assertTrue (it->second == i*2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ void HashMapTest::testIterator()
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
|
||||
std::map<int, int> values;
|
||||
IntMap::Iterator it; // do not initialize here to test proper behavior of uninitialized iterators
|
||||
it = hm.begin();
|
||||
@@ -142,7 +142,7 @@ void HashMapTest::testIterator()
|
||||
values[it->first] = it->second;
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
assertTrue (values.size() == N);
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ void HashMapTest::testConstIterator()
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
|
||||
std::map<int, int> values;
|
||||
IntMap::ConstIterator it = hm.begin();
|
||||
while (it != hm.end())
|
||||
@@ -167,7 +167,7 @@ void HashMapTest::testConstIterator()
|
||||
values[it->first] = it->second;
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
assertTrue (values.size() == N);
|
||||
}
|
||||
|
||||
@@ -180,12 +180,12 @@ void HashMapTest::testIndex()
|
||||
hm[1] = 2;
|
||||
hm[2] = 4;
|
||||
hm[3] = 6;
|
||||
|
||||
|
||||
assertTrue (hm.size() == 3);
|
||||
assertTrue (hm[1] == 2);
|
||||
assertTrue (hm[2] == 4);
|
||||
assertTrue (hm[3] == 6);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
const IntMap& im = hm;
|
||||
|
@@ -34,9 +34,9 @@ void HashSetTest::testInsert()
|
||||
const int N = 1000;
|
||||
|
||||
HashSet<int, Hash<int> > hs;
|
||||
|
||||
|
||||
assertTrue (hs.empty());
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<HashSet<int, Hash<int> >::Iterator, bool> res = hs.insert(i);
|
||||
@@ -46,23 +46,23 @@ void HashSetTest::testInsert()
|
||||
assertTrue (it != hs.end());
|
||||
assertTrue (*it == i);
|
||||
assertTrue (hs.size() == i + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assertTrue (!hs.empty());
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
HashSet<int, Hash<int> >::Iterator it = hs.find(i);
|
||||
assertTrue (it != hs.end());
|
||||
assertTrue (*it == i);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<HashSet<int, Hash<int> >::Iterator, bool> res = hs.insert(i);
|
||||
assertTrue (*res.first == i);
|
||||
assertTrue (!res.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ void HashSetTest::testErase()
|
||||
hs.insert(i);
|
||||
}
|
||||
assertTrue (hs.size() == N);
|
||||
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hs.erase(i);
|
||||
@@ -85,7 +85,7 @@ void HashSetTest::testErase()
|
||||
assertTrue (it == hs.end());
|
||||
}
|
||||
assertTrue (hs.size() == N/2);
|
||||
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
HashSet<int, Hash<int> >::Iterator it = hs.find(i);
|
||||
@@ -103,7 +103,7 @@ void HashSetTest::testErase()
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
HashSet<int, Hash<int> >::Iterator it = hs.find(i);
|
||||
@@ -123,7 +123,7 @@ void HashSetTest::testIterator()
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
|
||||
|
||||
std::set<int> values;
|
||||
HashSet<int, Hash<int> >::Iterator it = hs.begin();
|
||||
while (it != hs.end())
|
||||
@@ -147,7 +147,7 @@ void HashSetTest::testConstIterator()
|
||||
{
|
||||
hs.insert(i);
|
||||
}
|
||||
|
||||
|
||||
std::set<int> values;
|
||||
HashSet<int, Hash<int> >::ConstIterator it = hs.begin();
|
||||
while (it != hs.end())
|
||||
@@ -156,7 +156,7 @@ void HashSetTest::testConstIterator()
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
assertTrue (values.size() == N);
|
||||
}
|
||||
|
||||
|
@@ -41,9 +41,9 @@ void LinearHashTableTest::testInsert()
|
||||
const int N = 1000;
|
||||
|
||||
LinearHashTable<int, Hash<int> > ht;
|
||||
|
||||
|
||||
assertTrue (ht.empty());
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<LinearHashTable<int, Hash<int> >::Iterator, bool> res = ht.insert(i);
|
||||
@@ -53,18 +53,18 @@ void LinearHashTableTest::testInsert()
|
||||
assertTrue (it != ht.end());
|
||||
assertTrue (*it == i);
|
||||
assertTrue (ht.size() == i + 1);
|
||||
}
|
||||
}
|
||||
assertTrue (ht.buckets() == N + 1);
|
||||
|
||||
|
||||
assertTrue (!ht.empty());
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
|
||||
assertTrue (it != ht.end());
|
||||
assertTrue (*it == i);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<LinearHashTable<int, Hash<int> >::Iterator, bool> res = ht.insert(i);
|
||||
@@ -72,7 +72,7 @@ void LinearHashTableTest::testInsert()
|
||||
assertTrue (!res.second);
|
||||
assertTrue (ht.size() == N);
|
||||
assertTrue (ht.buckets() == N + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ void LinearHashTableTest::testErase()
|
||||
ht.insert(i);
|
||||
}
|
||||
assertTrue (ht.size() == N);
|
||||
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
ht.erase(i);
|
||||
@@ -95,13 +95,13 @@ void LinearHashTableTest::testErase()
|
||||
assertTrue (it == ht.end());
|
||||
}
|
||||
assertTrue (ht.size() == N/2);
|
||||
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
|
||||
assertTrue (it == ht.end());
|
||||
}
|
||||
|
||||
|
||||
for (int i = 1; i < N; i += 2)
|
||||
{
|
||||
LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
|
||||
@@ -113,7 +113,7 @@ void LinearHashTableTest::testErase()
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
|
||||
@@ -133,7 +133,7 @@ void LinearHashTableTest::testIterator()
|
||||
{
|
||||
ht.insert(i);
|
||||
}
|
||||
|
||||
|
||||
std::set<int> values;
|
||||
LinearHashTable<int, Hash<int> >::Iterator it = ht.begin();
|
||||
while (it != ht.end())
|
||||
@@ -142,7 +142,7 @@ void LinearHashTableTest::testIterator()
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
assertTrue (values.size() == N);
|
||||
}
|
||||
|
||||
@@ -166,9 +166,9 @@ void LinearHashTableTest::testConstIterator()
|
||||
values.insert(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
assertTrue (values.size() == N);
|
||||
|
||||
|
||||
values.clear();
|
||||
const LinearHashTable<int, Hash<int> > cht(ht);
|
||||
|
||||
@@ -179,8 +179,8 @@ void LinearHashTableTest::testConstIterator()
|
||||
values.insert(*cit);
|
||||
++cit;
|
||||
}
|
||||
|
||||
assertTrue (values.size() == N);
|
||||
|
||||
assertTrue (values.size() == N);
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ void LinearHashTableTest::testPerformanceInt()
|
||||
sw.stop();
|
||||
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
@@ -212,7 +212,7 @@ void LinearHashTableTest::testPerformanceInt()
|
||||
|
||||
{
|
||||
HashTable<int, int> ht;
|
||||
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
@@ -221,7 +221,7 @@ void LinearHashTableTest::testPerformanceInt()
|
||||
sw.stop();
|
||||
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
@@ -230,7 +230,7 @@ void LinearHashTableTest::testPerformanceInt()
|
||||
sw.stop();
|
||||
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
std::set<int> s;
|
||||
sw.start();
|
||||
@@ -241,7 +241,7 @@ void LinearHashTableTest::testPerformanceInt()
|
||||
sw.stop();
|
||||
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
@@ -251,7 +251,7 @@ void LinearHashTableTest::testPerformanceInt()
|
||||
std::cout << "Find set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ void LinearHashTableTest::testPerformanceStr()
|
||||
{
|
||||
const int N = 5000000;
|
||||
Stopwatch sw;
|
||||
|
||||
|
||||
std::vector<std::string> values;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
@@ -276,7 +276,7 @@ void LinearHashTableTest::testPerformanceStr()
|
||||
sw.stop();
|
||||
std::cout << "Insert LHT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
@@ -289,7 +289,7 @@ void LinearHashTableTest::testPerformanceStr()
|
||||
|
||||
{
|
||||
HashTable<std::string, int> ht;
|
||||
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
@@ -298,7 +298,7 @@ void LinearHashTableTest::testPerformanceStr()
|
||||
sw.stop();
|
||||
std::cout << "Insert HT: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
@@ -307,7 +307,7 @@ void LinearHashTableTest::testPerformanceStr()
|
||||
sw.stop();
|
||||
std::cout << "Find HT: " << sw.elapsedSeconds() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
std::set<std::string> s;
|
||||
sw.start();
|
||||
@@ -318,7 +318,7 @@ void LinearHashTableTest::testPerformanceStr()
|
||||
sw.stop();
|
||||
std::cout << "Insert set: " << sw.elapsedSeconds() << std::endl;
|
||||
sw.reset();
|
||||
|
||||
|
||||
sw.start();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
|
@@ -30,7 +30,7 @@ public:
|
||||
void testConstIterator();
|
||||
void testPerformanceInt();
|
||||
void testPerformanceStr();
|
||||
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
|
@@ -35,9 +35,9 @@ void ListMapTest::testInsert()
|
||||
|
||||
typedef ListMap<int, int> IntMap;
|
||||
IntMap hm;
|
||||
|
||||
|
||||
assertTrue (hm.empty());
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator res = hm.insert(IntMap::ValueType(i, i*2));
|
||||
@@ -48,10 +48,10 @@ void ListMapTest::testInsert()
|
||||
assertTrue (it->first == i);
|
||||
assertTrue (it->second == i*2);
|
||||
assertTrue (hm.size() == i + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assertTrue (!hm.empty());
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
@@ -59,14 +59,14 @@ void ListMapTest::testInsert()
|
||||
assertTrue (it->first == i);
|
||||
assertTrue (it->second == i*2);
|
||||
}
|
||||
|
||||
|
||||
hm.clear();
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator res = hm.insert(IntMap::ValueType(i, 0));
|
||||
assertTrue (res->first == i);
|
||||
assertTrue (res->second == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ void ListMapTest::testInsertOrder()
|
||||
assertTrue (it != lm.end() && it->first == "bar" && it->second == 43);
|
||||
|
||||
++it;
|
||||
assertTrue (it == lm.end());
|
||||
assertTrue (it == lm.end());
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ void ListMapTest::testErase()
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
assertTrue (hm.size() == N);
|
||||
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
hm.erase(i);
|
||||
@@ -125,13 +125,13 @@ void ListMapTest::testErase()
|
||||
assertTrue (it == hm.end());
|
||||
}
|
||||
assertTrue (hm.size() == N/2);
|
||||
|
||||
|
||||
for (int i = 0; i < N; i += 2)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assertTrue (it == hm.end());
|
||||
}
|
||||
|
||||
|
||||
for (int i = 1; i < N; i += 2)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
@@ -143,13 +143,13 @@ void ListMapTest::testErase()
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
IntMap::Iterator it = hm.find(i);
|
||||
assertTrue (it != hm.end());
|
||||
assertTrue (it->first == i);
|
||||
assertTrue (it->second == i*2);
|
||||
assertTrue (it->second == i*2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ void ListMapTest::testIterator()
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
|
||||
std::map<int, int> values;
|
||||
IntMap::Iterator it; // do not initialize here to test proper behavior of uninitialized iterators
|
||||
it = hm.begin();
|
||||
@@ -175,7 +175,7 @@ void ListMapTest::testIterator()
|
||||
values[it->first] = it->second;
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
assertTrue (values.size() == N);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ void ListMapTest::testConstIterator()
|
||||
{
|
||||
hm.insert(IntMap::ValueType(i, i*2));
|
||||
}
|
||||
|
||||
|
||||
std::map<int, int> values;
|
||||
IntMap::ConstIterator it = hm.begin();
|
||||
while (it != hm.end())
|
||||
@@ -200,7 +200,7 @@ void ListMapTest::testConstIterator()
|
||||
values[it->first] = it->second;
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
assertTrue (values.size() == N);
|
||||
}
|
||||
|
||||
@@ -239,12 +239,12 @@ void ListMapTest::testStringIndex()
|
||||
hm["index1"] = "value2";
|
||||
hm["index2"] = "value4";
|
||||
hm["index3"] = "value6";
|
||||
|
||||
|
||||
assertTrue (hm.size() == 3);
|
||||
assertTrue (hm["index1"] == "value2");
|
||||
assertTrue (hm["Index2"] == "value4");
|
||||
assertTrue (hm["inDeX3"] == "value6");
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
const StringMap& im = hm;
|
||||
|
@@ -65,7 +65,7 @@ void LocalDateTimeTest::testGregorian1()
|
||||
// the one on 1970-1-1
|
||||
//assertTrue (dt.tzd() == Timezone::tzd());
|
||||
assertTrue (dt.julianDay() == 2440587.5);
|
||||
|
||||
|
||||
dt.assign(2001, 9, 9, 1, 46, 40);
|
||||
assertTrue (dt.year() == 2001);
|
||||
assertTrue (dt.month() == 9);
|
||||
@@ -92,7 +92,7 @@ void LocalDateTimeTest::testGregorian2()
|
||||
assertTrue (dt.millisecond() == 0);
|
||||
assertTrue (dt.dayOfWeek() == 4);
|
||||
assertTrue (dt.tzd() == 2*3600);
|
||||
|
||||
|
||||
dt.assign(-7*3600, 2001, 9, 9, 1, 46, 40, 0, 0);
|
||||
assertTrue (dt.year() == 2001);
|
||||
assertTrue (dt.month() == 9);
|
||||
@@ -134,12 +134,12 @@ void LocalDateTimeTest::testConversions()
|
||||
assertTrue (dt5.millisecond() == 234);
|
||||
assertTrue (dt5.dayOfWeek() == 5);
|
||||
assertTrue (dt5.tzd() == -4*3600);
|
||||
|
||||
|
||||
DateTime dt6(2005, 1, 28, 14, 24, 44, 234, 0);
|
||||
LocalDateTime dt7(3600, dt6);
|
||||
LocalDateTime dt8(3600, dt6, false);
|
||||
LocalDateTime dt9(3600, dt6, true);
|
||||
|
||||
|
||||
assertTrue (dt7.hour() == 15);
|
||||
assertTrue (dt8.hour() == 14);
|
||||
assertTrue (dt9.hour() == 15);
|
||||
@@ -169,9 +169,9 @@ void LocalDateTimeTest::testCalcs()
|
||||
assertTrue (dt1.week(DateTime::MONDAY) == 1);
|
||||
dt1.assign(2007, 12, 31);
|
||||
assertTrue (dt1.week(DateTime::MONDAY) == 53);
|
||||
|
||||
|
||||
// Jan 1 is Mon
|
||||
dt1.assign(2001, 1, 1);
|
||||
dt1.assign(2001, 1, 1);
|
||||
assertTrue (dt1.week() == 1);
|
||||
dt1.assign(2001, 1, 7);
|
||||
assertTrue (dt1.week() == 1);
|
||||
@@ -205,7 +205,7 @@ void LocalDateTimeTest::testCalcs()
|
||||
assertTrue (dt1.week() == 3);
|
||||
dt1.assign(2003, 1, 20);
|
||||
assertTrue (dt1.week() == 4);
|
||||
|
||||
|
||||
// Jan 1 is Thu
|
||||
dt1.assign(2004, 1, 1);
|
||||
assertTrue (dt1.week() == 1);
|
||||
@@ -241,7 +241,7 @@ void LocalDateTimeTest::testCalcs()
|
||||
assertTrue (dt1.week() == 2);
|
||||
dt1.assign(2000, 1, 17);
|
||||
assertTrue (dt1.week() == 3);
|
||||
|
||||
|
||||
// Jan 1 is Sun
|
||||
dt1.assign(1995, 1, 1);
|
||||
assertTrue (dt1.week() == 0);
|
||||
@@ -262,7 +262,7 @@ void LocalDateTimeTest::testAMPM()
|
||||
assertTrue (dt1.isAM());
|
||||
assertTrue (!dt1.isPM());
|
||||
assertTrue (dt1.hourAMPM() == 12);
|
||||
|
||||
|
||||
dt1.assign(2005, 1, 1, 12, 15, 30);
|
||||
assertTrue (!dt1.isAM());
|
||||
assertTrue (dt1.isPM());
|
||||
@@ -280,14 +280,14 @@ void LocalDateTimeTest::testRelational1()
|
||||
LocalDateTime dt1(2005, 1, 1, 0, 15, 30);
|
||||
LocalDateTime dt2(2005, 1, 2, 0, 15, 30);
|
||||
LocalDateTime dt3(dt1);
|
||||
|
||||
|
||||
assertTrue (dt1 < dt2);
|
||||
assertTrue (dt1 <= dt2);
|
||||
assertTrue (dt2 > dt1);
|
||||
assertTrue (dt2 >= dt1);
|
||||
assertTrue (dt1 != dt2);
|
||||
assertTrue (!(dt1 == dt2));
|
||||
|
||||
|
||||
assertTrue (dt1 == dt3);
|
||||
assertTrue (!(dt1 != dt3));
|
||||
assertTrue (dt1 >= dt3);
|
||||
@@ -309,7 +309,7 @@ void LocalDateTimeTest::testRelational2()
|
||||
assertTrue (dt2 >= dt1);
|
||||
assertTrue (dt1 != dt2);
|
||||
assertTrue (!(dt1 == dt2));
|
||||
|
||||
|
||||
assertTrue (dt1 == dt3);
|
||||
assertTrue (!(dt1 != dt3));
|
||||
assertTrue (dt1 >= dt3);
|
||||
@@ -323,13 +323,13 @@ void LocalDateTimeTest::testArithmetics1()
|
||||
{
|
||||
LocalDateTime dt1(2005, 1, 1, 0, 15, 30);
|
||||
LocalDateTime dt2(2005, 1, 2, 0, 15, 30);
|
||||
|
||||
|
||||
Timespan s = dt2 - dt1;
|
||||
assertTrue (s.days() == 1);
|
||||
|
||||
|
||||
LocalDateTime dt3 = dt1 + s;
|
||||
assertTrue (dt3 == dt2);
|
||||
|
||||
|
||||
dt3 -= s;
|
||||
assertTrue (dt3 == dt1);
|
||||
dt1 += s;
|
||||
@@ -341,13 +341,13 @@ void LocalDateTimeTest::testArithmetics2()
|
||||
{
|
||||
LocalDateTime dt1(2*3600, 2005, 1, 1, 15, 30, 0, 0, 0);
|
||||
LocalDateTime dt2(5*3600, 2005, 1, 2, 18, 30, 0, 0, 0);
|
||||
|
||||
|
||||
Timespan s = dt2 - dt1;
|
||||
assertTrue (s.days() == 1);
|
||||
|
||||
|
||||
LocalDateTime dt3 = dt1 + s;
|
||||
assertTrue (dt3 == dt2);
|
||||
|
||||
|
||||
dt3 -= s;
|
||||
assertTrue (dt3 == dt1);
|
||||
dt1 += s;
|
||||
@@ -359,7 +359,7 @@ void LocalDateTimeTest::testSwap()
|
||||
{
|
||||
LocalDateTime dt1(2005, 1, 1, 0, 15, 30);
|
||||
LocalDateTime dt2(2005, 1, 2, 0, 15, 30);
|
||||
|
||||
|
||||
assertTrue (dt1 < dt2);
|
||||
dt1.swap(dt2);
|
||||
assertTrue (dt2 < dt1);
|
||||
@@ -454,6 +454,41 @@ void LocalDateTimeTest::testTimezone()
|
||||
}
|
||||
|
||||
|
||||
void LocalDateTimeTest::testTimezone2()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
std::vector<std::string> timezones = {
|
||||
"/usr/share/zoneinfo/America/Los_Angeles",
|
||||
"/usr/share/zoneinfo/Europe/London",
|
||||
"/usr/share/zoneinfo/Europe/Dublin", // special winter time of Ireland
|
||||
"/usr/share/zoneinfo/Europe/Prague",
|
||||
};
|
||||
|
||||
std::cout << "\n";
|
||||
|
||||
for (const std::string& tz : timezones)
|
||||
{
|
||||
setenv("TZ", tz.c_str(), 1); // POSIX-specific
|
||||
std::vector<LocalDateTime> times = {
|
||||
LocalDateTime(2022, 06, 29), // summer period
|
||||
LocalDateTime(2022, 01, 29), // winter period
|
||||
};
|
||||
for (const LocalDateTime& ldt : times) {
|
||||
std::time_t t = ldt.timestamp().epochTime();
|
||||
std::tm then;
|
||||
then = *std::localtime(&t);
|
||||
#if POCO_OS == POCO_OS_SOLARIS
|
||||
assertTrue((mktime(&then)-t) * 1000 == ldt.tzd());
|
||||
#else
|
||||
assertTrue (then.tm_gmtoff == ldt.tzd());
|
||||
#endif
|
||||
}
|
||||
unsetenv("TZ");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void LocalDateTimeTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -479,6 +514,7 @@ CppUnit::Test* LocalDateTimeTest::suite()
|
||||
CppUnit_addTest(pSuite, LocalDateTimeTest, testArithmetics2);
|
||||
CppUnit_addTest(pSuite, LocalDateTimeTest, testSwap);
|
||||
CppUnit_addTest(pSuite, LocalDateTimeTest, testTimezone);
|
||||
CppUnit_addTest(pSuite, LocalDateTimeTest, testTimezone2);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ public:
|
||||
void testArithmetics2();
|
||||
void testSwap();
|
||||
void testTimezone();
|
||||
void testTimezone2();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
@@ -48,14 +48,14 @@ void LoggerTest::testLogger()
|
||||
assertTrue (root.information());
|
||||
assertTrue (!root.debug());
|
||||
assertTrue (!root.trace());
|
||||
|
||||
|
||||
root.information("Informational message");
|
||||
assertTrue (pChannel->list().size() == 1);
|
||||
root.warning("Warning message");
|
||||
assertTrue (pChannel->list().size() == 2);
|
||||
root.debug("Debug message");
|
||||
assertTrue (pChannel->list().size() == 2);
|
||||
|
||||
|
||||
Logger& logger1 = Logger::get("Logger1");
|
||||
Logger& logger2 = Logger::get("Logger2");
|
||||
Logger& logger11 = Logger::get("Logger1.Logger1");
|
||||
@@ -85,7 +85,7 @@ void LoggerTest::testLogger()
|
||||
assertTrue (logger12.is(Message::PRIO_INFORMATION));
|
||||
assertTrue (logger21.is(Message::PRIO_INFORMATION));
|
||||
assertTrue (logger22.is(Message::PRIO_INFORMATION));
|
||||
|
||||
|
||||
Logger::setLevel("Logger2.Logger1", Message::PRIO_ERROR);
|
||||
assertTrue (logger1.is(Message::PRIO_DEBUG));
|
||||
assertTrue (logger11.is(Message::PRIO_DEBUG));
|
||||
@@ -96,7 +96,7 @@ void LoggerTest::testLogger()
|
||||
assertTrue (logger12.is(Message::PRIO_INFORMATION));
|
||||
assertTrue (logger21.is(Message::PRIO_ERROR));
|
||||
assertTrue (logger22.is(Message::PRIO_INFORMATION));
|
||||
|
||||
|
||||
Logger::setLevel("", Message::PRIO_WARNING);
|
||||
assertTrue (root.getLevel() == Message::PRIO_WARNING);
|
||||
assertTrue (logger1.getLevel() == Message::PRIO_WARNING);
|
||||
@@ -105,7 +105,7 @@ void LoggerTest::testLogger()
|
||||
assertTrue (logger1.getLevel() == Message::PRIO_WARNING);
|
||||
assertTrue (logger21.getLevel() == Message::PRIO_WARNING);
|
||||
assertTrue (logger22.getLevel() == Message::PRIO_WARNING);
|
||||
|
||||
|
||||
AutoPtr<TestChannel> pChannel2 = new TestChannel;
|
||||
Logger::setChannel("Logger2", pChannel2);
|
||||
assertTrue (pChannel.get() == root.getChannel().get());
|
||||
@@ -115,7 +115,7 @@ void LoggerTest::testLogger()
|
||||
assertTrue (pChannel2.get() == logger2.getChannel().get());
|
||||
assertTrue (pChannel2.get() == logger21.getChannel().get());
|
||||
assertTrue (pChannel2.get() == logger22.getChannel().get());
|
||||
|
||||
|
||||
root.setLevel(Message::PRIO_TRACE);
|
||||
pChannel->list().clear();
|
||||
root.trace("trace");
|
||||
@@ -141,7 +141,7 @@ void LoggerTest::testLogger()
|
||||
pChannel->list().clear();
|
||||
root.fatal("fatal");
|
||||
assertTrue (pChannel->list().begin()->getPriority() == Message::PRIO_FATAL);
|
||||
|
||||
|
||||
root.setLevel("1");
|
||||
assertTrue (root.getLevel() == Message::PRIO_FATAL);
|
||||
root.setLevel("8");
|
||||
@@ -256,18 +256,18 @@ void LoggerTest::testDump()
|
||||
Logger& root = Logger::root();
|
||||
root.setChannel(pChannel);
|
||||
root.setLevel(Message::PRIO_INFORMATION);
|
||||
|
||||
|
||||
char buffer1[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
|
||||
root.dump("test", buffer1, sizeof(buffer1));
|
||||
assertTrue (pChannel->list().empty());
|
||||
|
||||
|
||||
root.setLevel(Message::PRIO_DEBUG);
|
||||
root.dump("test", buffer1, sizeof(buffer1));
|
||||
|
||||
|
||||
std::string msg = pChannel->list().begin()->getText();
|
||||
assertTrue (msg == "test\n0000 00 01 02 03 04 05 ......");
|
||||
pChannel->clear();
|
||||
|
||||
|
||||
char buffer2[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
|
||||
@@ -276,7 +276,7 @@ void LoggerTest::testDump()
|
||||
msg = pChannel->list().begin()->getText();
|
||||
assertTrue (msg == "0000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ................");
|
||||
pChannel->clear();
|
||||
|
||||
|
||||
char buffer3[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
|
@@ -38,14 +38,14 @@ LoggingRegistryTest::~LoggingRegistryTest()
|
||||
void LoggingRegistryTest::testRegister()
|
||||
{
|
||||
LoggingRegistry& reg = LoggingRegistry::defaultRegistry();
|
||||
|
||||
|
||||
reg.clear();
|
||||
|
||||
|
||||
Channel::Ptr pC1 = new ConsoleChannel();
|
||||
Channel::Ptr pC2 = new ConsoleChannel();
|
||||
Formatter::Ptr pF1 = new PatternFormatter("");
|
||||
Formatter::Ptr pF2 = new PatternFormatter("");
|
||||
|
||||
|
||||
reg.registerChannel("c1", pC1);
|
||||
reg.registerChannel("c2", pC2);
|
||||
reg.registerFormatter("f1", pF1);
|
||||
@@ -55,12 +55,12 @@ void LoggingRegistryTest::testRegister()
|
||||
assertTrue (pC1 == pC);
|
||||
pC = reg.channelForName("c2");
|
||||
assertTrue (pC2 == pC);
|
||||
|
||||
|
||||
Formatter* pF = reg.formatterForName("f1");
|
||||
assertTrue (pF1 == pF);
|
||||
pF = reg.formatterForName("f2");
|
||||
assertTrue (pF2 == pF);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
pC = reg.channelForName("c3");
|
||||
@@ -75,21 +75,21 @@ void LoggingRegistryTest::testRegister()
|
||||
void LoggingRegistryTest::testReregister()
|
||||
{
|
||||
LoggingRegistry& reg = LoggingRegistry::defaultRegistry();
|
||||
|
||||
|
||||
reg.clear();
|
||||
|
||||
|
||||
Channel::Ptr pC1 = new ConsoleChannel();
|
||||
Channel::Ptr pC2 = new ConsoleChannel();
|
||||
Channel::Ptr pC1b = new ConsoleChannel();
|
||||
AutoPtr<Formatter> pF1 = new PatternFormatter("");
|
||||
AutoPtr<Formatter> pF2 = new PatternFormatter("");
|
||||
AutoPtr<Formatter> pF1b = new PatternFormatter("");
|
||||
|
||||
|
||||
reg.registerChannel("c1", pC1);
|
||||
reg.registerChannel("c2", pC2);
|
||||
reg.registerFormatter("f1", pF1);
|
||||
reg.registerFormatter("f2", pF2);
|
||||
|
||||
|
||||
reg.registerChannel("c1", pC1b);
|
||||
|
||||
Channel::Ptr pC = reg.channelForName("c1");
|
||||
@@ -110,14 +110,14 @@ void LoggingRegistryTest::testReregister()
|
||||
void LoggingRegistryTest::testUnregister()
|
||||
{
|
||||
LoggingRegistry& reg = LoggingRegistry::defaultRegistry();
|
||||
|
||||
|
||||
reg.clear();
|
||||
|
||||
|
||||
Channel::Ptr pC1 = new ConsoleChannel();
|
||||
Channel::Ptr pC2 = new ConsoleChannel();
|
||||
AutoPtr<Formatter> pF1 = new PatternFormatter("");
|
||||
AutoPtr<Formatter> pF2 = new PatternFormatter("");
|
||||
|
||||
|
||||
reg.registerChannel("c1", pC1);
|
||||
reg.registerChannel("c2", pC2);
|
||||
reg.registerFormatter("f1", pF1);
|
||||
@@ -125,7 +125,7 @@ void LoggingRegistryTest::testUnregister()
|
||||
|
||||
reg.unregisterChannel("c1");
|
||||
reg.unregisterFormatter("f2");
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Channel::Ptr pC = reg.channelForName("c1");
|
||||
|
@@ -48,7 +48,7 @@ void MD4EngineTest::testMD4()
|
||||
|
||||
engine.update("abcdefghijklmnopqrstuvwxyz");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "d79e1c308aa5bbcdeea8ed63df412da9");
|
||||
|
||||
|
||||
engine.update("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
engine.update("abcdefghijklmnopqrstuvwxyz0123456789");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "043f8582f241db351ce627e153e7f0e4");
|
||||
|
@@ -61,9 +61,9 @@ void ManifestTest::testManifest()
|
||||
assertTrue (manifest.find("MfTestObject2") != manifest.end());
|
||||
assertTrue (manifest.find("MfTestObject3") != manifest.end());
|
||||
assertTrue (manifest.find("MfTestObject4") == manifest.end());
|
||||
|
||||
|
||||
std::set<std::string> classes;
|
||||
|
||||
|
||||
Manifest<MfTestBase>::Iterator it = manifest.begin();
|
||||
assertTrue (it != manifest.end());
|
||||
classes.insert(it->name());
|
||||
@@ -75,11 +75,11 @@ void ManifestTest::testManifest()
|
||||
classes.insert(it->name());
|
||||
it++;
|
||||
assertTrue (it == manifest.end());
|
||||
|
||||
|
||||
assertTrue (classes.find("MfTestObject1") != classes.end());
|
||||
assertTrue (classes.find("MfTestObject2") != classes.end());
|
||||
assertTrue (classes.find("MfTestObject3") != classes.end());
|
||||
|
||||
|
||||
manifest.clear();
|
||||
assertTrue (manifest.empty());
|
||||
assertTrue (manifest.size() == 0);
|
||||
|
@@ -36,11 +36,11 @@ MemoryPoolTest::~MemoryPoolTest()
|
||||
void MemoryPoolTest::testMemoryPool()
|
||||
{
|
||||
MemoryPool pool1(100, 0, 10);
|
||||
|
||||
|
||||
assertTrue (pool1.blockSize() == 100);
|
||||
assertTrue (pool1.allocated() == 0);
|
||||
assertTrue (pool1.available() == 0);
|
||||
|
||||
|
||||
std::vector<void*> ptrs;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
@@ -48,7 +48,7 @@ void MemoryPoolTest::testMemoryPool()
|
||||
assertTrue (pool1.allocated() == i + 1);
|
||||
assertTrue (pool1.available() == 0);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
pool1.get();
|
||||
@@ -57,7 +57,7 @@ void MemoryPoolTest::testMemoryPool()
|
||||
catch (Poco::OutOfMemoryException&)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int av = 0;
|
||||
for (std::vector<void*>::iterator it = ptrs.begin(); it != ptrs.end(); ++it)
|
||||
{
|
||||
@@ -65,7 +65,7 @@ void MemoryPoolTest::testMemoryPool()
|
||||
++av;
|
||||
assertTrue (pool1.available() == av);
|
||||
}
|
||||
|
||||
|
||||
MemoryPool pool2(32, 5, 10);
|
||||
assertTrue (pool2.available() == 5);
|
||||
assertTrue (pool2.blockSize() == 32);
|
||||
|
@@ -34,22 +34,22 @@ void MemoryStreamTest::testInput()
|
||||
{
|
||||
const char* data = "This is a test";
|
||||
MemoryInputStream istr1(data, 14);
|
||||
|
||||
|
||||
int c = istr1.get();
|
||||
assertTrue (c == 'T');
|
||||
c = istr1.get();
|
||||
assertTrue (c == 'h');
|
||||
|
||||
|
||||
std::string str;
|
||||
istr1 >> str;
|
||||
assertTrue (str == "is");
|
||||
|
||||
|
||||
char buffer[32];
|
||||
istr1.read(buffer, sizeof(buffer));
|
||||
assertTrue (istr1.gcount() == 10);
|
||||
buffer[istr1.gcount()] = 0;
|
||||
assertTrue (std::string(" is a test") == buffer);
|
||||
|
||||
|
||||
const char* data2 = "123";
|
||||
MemoryInputStream istr2(data2, 3);
|
||||
c = istr2.get();
|
||||
@@ -77,7 +77,7 @@ void MemoryStreamTest::testOutput()
|
||||
ostr1 << "This is a test " << 42 << std::ends;
|
||||
assertTrue (ostr1.charsWritten() == 18);
|
||||
assertTrue (std::string("This is a test 42") == output);
|
||||
|
||||
|
||||
char output2[4];
|
||||
MemoryOutputStream ostr2(output2, 4);
|
||||
ostr2 << "test";
|
||||
|
@@ -26,7 +26,7 @@ public:
|
||||
|
||||
void testLock();
|
||||
void testTryLock();
|
||||
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
|
1290
vendor/POCO/Foundation/testsuite/src/NamedTuplesTest.cpp
vendored
1290
vendor/POCO/Foundation/testsuite/src/NamedTuplesTest.cpp
vendored
File diff suppressed because it is too large
Load Diff
@@ -162,7 +162,7 @@ void NotificationCenterTest::testDefaultCenter()
|
||||
void NotificationCenterTest::handle1(Poco::Notification* pNf)
|
||||
{
|
||||
poco_check_ptr (pNf);
|
||||
AutoPtr<Notification> nf = pNf;
|
||||
AutoPtr<Notification> nf = pNf;
|
||||
_set.insert("handle1");
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ void NotificationCenterTest::handle1(Poco::Notification* pNf)
|
||||
void NotificationCenterTest::handle2(Poco::Notification* pNf)
|
||||
{
|
||||
poco_check_ptr (pNf);
|
||||
AutoPtr<Notification> nf = pNf;
|
||||
AutoPtr<Notification> nf = pNf;
|
||||
_set.insert("handle2");
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ void NotificationCenterTest::handle2(Poco::Notification* pNf)
|
||||
void NotificationCenterTest::handle3(Poco::Notification* pNf)
|
||||
{
|
||||
poco_check_ptr (pNf);
|
||||
AutoPtr<Notification> nf = pNf;
|
||||
AutoPtr<Notification> nf = pNf;
|
||||
_set.insert("handle3");
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ void NotificationCenterTest::handle3(Poco::Notification* pNf)
|
||||
void NotificationCenterTest::handleTest(TestNotification* pNf)
|
||||
{
|
||||
poco_check_ptr (pNf);
|
||||
AutoPtr<TestNotification> nf = pNf;
|
||||
AutoPtr<TestNotification> nf = pNf;
|
||||
_set.insert("handleTest");
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,7 @@ protected:
|
||||
void handle3(Poco::Notification* pNf);
|
||||
void handleTest(TestNotification* pNf);
|
||||
void handleAuto(const Poco::AutoPtr<Poco::Notification>& pNf);
|
||||
|
||||
|
||||
private:
|
||||
std::set<std::string> _set;
|
||||
};
|
||||
|
@@ -72,7 +72,7 @@ void NotificationQueueTest::testQueueDequeue()
|
||||
assertTrue (queue.empty());
|
||||
assertTrue (queue.size() == 0);
|
||||
pNf->release();
|
||||
|
||||
|
||||
queue.enqueueNotification(new QTestNotification("first"));
|
||||
queue.enqueueNotification(new QTestNotification("second"));
|
||||
assertTrue (!queue.empty());
|
||||
@@ -97,7 +97,7 @@ void NotificationQueueTest::testQueueDequeue()
|
||||
|
||||
void NotificationQueueTest::testQueueDequeueUrgent()
|
||||
{
|
||||
NotificationQueue queue;
|
||||
NotificationQueue queue;
|
||||
queue.enqueueNotification(new QTestNotification("first"));
|
||||
queue.enqueueNotification(new QTestNotification("second"));
|
||||
queue.enqueueUrgentNotification(new QTestNotification("third"));
|
||||
@@ -158,7 +158,7 @@ void NotificationQueueTest::testThreads()
|
||||
Thread t1("thread1");
|
||||
Thread t2("thread2");
|
||||
Thread t3("thread3");
|
||||
|
||||
|
||||
RunnableAdapter<NotificationQueueTest> ra(*this, &NotificationQueueTest::work);
|
||||
t1.start(ra);
|
||||
t2.start(ra);
|
||||
|
@@ -39,13 +39,13 @@ void NumberFormatterTest::testFormat()
|
||||
assertTrue (NumberFormatter::format((unsigned) 123) == "123");
|
||||
assertTrue (NumberFormatter::format((unsigned) 123, 5) == " 123");
|
||||
assertTrue (NumberFormatter::format0((unsigned) 123, 5) == "00123");
|
||||
|
||||
|
||||
assertTrue (NumberFormatter::format((long) 123) == "123");
|
||||
assertTrue (NumberFormatter::format((long) -123) == "-123");
|
||||
assertTrue (NumberFormatter::format((long) -123, 5) == " -123");
|
||||
|
||||
assertTrue (NumberFormatter::format((unsigned long) 123) == "123");
|
||||
assertTrue (NumberFormatter::format((unsigned long) 123, 5) == " 123");
|
||||
assertTrue (NumberFormatter::format((unsigned long) 123, 5) == " 123");
|
||||
|
||||
assertTrue (NumberFormatter::format(123) == "123");
|
||||
assertTrue (NumberFormatter::format(-123) == "-123");
|
||||
@@ -57,7 +57,7 @@ void NumberFormatterTest::testFormat()
|
||||
assertTrue (NumberFormatter::format((Int64) -123, 5) == " -123");
|
||||
|
||||
assertTrue (NumberFormatter::format((UInt64) 123) == "123");
|
||||
assertTrue (NumberFormatter::format((UInt64) 123, 5) == " 123");
|
||||
assertTrue (NumberFormatter::format((UInt64) 123, 5) == " 123");
|
||||
#if defined(POCO_LONG_IS_64_BIT)
|
||||
assertTrue (NumberFormatter::format((long long) 123) == "123");
|
||||
assertTrue (NumberFormatter::format((long long) -123) == "-123");
|
||||
@@ -263,6 +263,20 @@ void NumberFormatterTest::testFormatFloat()
|
||||
assertTrue (NumberFormatter::format(50.546, 0) == "51");
|
||||
assertTrue (NumberFormatter::format(50.546f, 0) == "51");
|
||||
assertTrue (NumberFormatter::format(50.546f, 2) == "50.55");
|
||||
|
||||
try
|
||||
{
|
||||
Poco::NumberFormatter::format(0.1, -1);
|
||||
fail ("NumberFormatter::format() must throw on negative precision");
|
||||
}
|
||||
catch(Poco::InvalidArgumentException&){}
|
||||
|
||||
try
|
||||
{
|
||||
Poco::NumberFormatter::format(0.1, 2, -1);
|
||||
fail ("NumberFormatter::format() must throw on negative precision");
|
||||
}
|
||||
catch(Poco::InvalidArgumentException&){}
|
||||
}
|
||||
|
||||
|
||||
@@ -293,7 +307,7 @@ void NumberFormatterTest::testAppend()
|
||||
NumberFormatter::append0(s, 123u, 5);
|
||||
assertTrue (s == "00123");
|
||||
|
||||
|
||||
|
||||
s.erase();
|
||||
NumberFormatter::append(s, 123.4);
|
||||
assertTrue (s == "123.4");
|
||||
|
@@ -58,9 +58,9 @@ void NumberParserTest::testParse()
|
||||
{
|
||||
char ts = sep[i];
|
||||
|
||||
assertTrue (NumberParser::parse("123") == 123);
|
||||
assertTrue (NumberParser::parse(format("123%c456", ts), ts) == 123456);
|
||||
assertTrue (NumberParser::parse(format("1%c234%c567", ts, ts), ts) == 1234567);
|
||||
assertEqual (NumberParser::parse("123"), 123);
|
||||
assertEqual (NumberParser::parse(format("123%c456", ts), ts), 123456);
|
||||
assertEqual (NumberParser::parse(format("1%c234%c567", ts, ts), ts), 1234567);
|
||||
}
|
||||
|
||||
assertTrue (NumberParser::parse("+123") == 123);
|
||||
@@ -137,14 +137,14 @@ void NumberParserTest::testParse()
|
||||
double d = 1.234e100;
|
||||
assertEqualDelta(d, NumberParser::parseFloat(format("1%c234e100", dp), dp, ts), 0.01);
|
||||
assertEqualDelta(d, NumberParser::parseFloat(format("1%c234E+100", dp), dp, ts), 0.01);
|
||||
|
||||
|
||||
d = 1.234e-100;
|
||||
assertEqualDelta(d, NumberParser::parseFloat(format("1%c234E-100", dp), dp, ts), 0.01);
|
||||
|
||||
|
||||
d = -1.234e100;
|
||||
assertEqualDelta(d, NumberParser::parseFloat(format("-1%c234e+100", dp), dp, ts), 0.01);
|
||||
assertEqualDelta(d, NumberParser::parseFloat(format("-1%c234E100", dp), dp, ts), 0.01);
|
||||
|
||||
|
||||
d = 1234.234e-100;
|
||||
assertEqualDelta(d, NumberParser::parseFloat(format("1%c234%c234e-100", ts, dp), dp, ts), 0.01);
|
||||
d = 12345.234e-100;
|
||||
@@ -163,7 +163,7 @@ void NumberParserTest::testParse()
|
||||
double d = 12.34e-10;
|
||||
assertEqualDelta(d, NumberParser::parseFloat(format("12%c34e-10", dp), dp, ts), 0.01);
|
||||
assertEqualDelta(-12.34, NumberParser::parseFloat(format("-12%c34", dp), dp, ts), 0.01);
|
||||
|
||||
|
||||
assertEqualDelta(12.34, NumberParser::parseFloat(format("12%c34", dp), dp, ts), 0.01);
|
||||
}
|
||||
}
|
||||
@@ -188,6 +188,19 @@ void NumberParserTest::testLimits()
|
||||
assertTrue (testLowerLimit64<Int64>());
|
||||
assertTrue (testUpperLimit64<UInt64>());
|
||||
#endif
|
||||
|
||||
Poco::Int64 val1, val2;
|
||||
// smallest 64-bit int is actually -9223372036854775808
|
||||
// but the sign and number are parsed as two tokens,
|
||||
// resulting in compiler warning, for explanation see
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661
|
||||
NumberParser::tryParse64("-9223372036854775807", val1);
|
||||
NumberParser::tryParse64("9223372036854775807", val2);
|
||||
assertTrue (val1 == -9223372036854775807LL);
|
||||
assertTrue (val2 == 9223372036854775807LL);
|
||||
int i;
|
||||
assertFalse (NumberParser::tryParse("-9223372036854775807", i));
|
||||
assertFalse (NumberParser::tryParse("9223372036854775807", i));
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +270,7 @@ void NumberParserTest::testParseError()
|
||||
NumberParser::parseHex("23z");
|
||||
failmsg("must throw SyntaxException");
|
||||
} catch (SyntaxException&) { }
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
try
|
||||
@@ -283,7 +296,7 @@ void NumberParserTest::testParseError()
|
||||
NumberParser::parseHex64("12345z");
|
||||
failmsg("must throw SyntaxException");
|
||||
} catch (SyntaxException&) { }
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
NumberParser::parseHex64(format("123%c45", ts));
|
||||
@@ -300,6 +313,13 @@ void NumberParserTest::testParseError()
|
||||
} catch (SyntaxException&) { }
|
||||
|
||||
#endif // POCO_NO_FPENVIRONMENT
|
||||
|
||||
try
|
||||
{
|
||||
const char test[] = { char(-23), char(-108), char(-103), char(-24), char(-81), char(-81), 0 };
|
||||
Poco::NumberParser::parse(test);
|
||||
failmsg("must throw SyntaxException");
|
||||
} catch (SyntaxException&) { }
|
||||
}
|
||||
|
||||
|
||||
|
@@ -35,20 +35,20 @@ PBKDF2EngineTest::~PBKDF2EngineTest()
|
||||
void PBKDF2EngineTest::testPBKDF2a()
|
||||
{
|
||||
// test vector 1 from RFC 6070
|
||||
|
||||
|
||||
std::string p("password");
|
||||
std::string s("salt");
|
||||
PBKDF2Engine<HMACEngine<SHA1Engine> > pbkdf2(s, 1, 20);
|
||||
pbkdf2.update(p);
|
||||
std::string dk = DigestEngine::digestToHex(pbkdf2.digest());
|
||||
assertTrue (dk == "0c60c80f961f0e71f3a9b524af6012062fe037a6");
|
||||
assertTrue (dk == "0c60c80f961f0e71f3a9b524af6012062fe037a6");
|
||||
}
|
||||
|
||||
|
||||
void PBKDF2EngineTest::testPBKDF2b()
|
||||
{
|
||||
// test vector 2 from RFC 6070
|
||||
|
||||
|
||||
std::string p("password");
|
||||
std::string s("salt");
|
||||
PBKDF2Engine<HMACEngine<SHA1Engine> > pbkdf2(s, 2, 20);
|
||||
@@ -61,7 +61,7 @@ void PBKDF2EngineTest::testPBKDF2b()
|
||||
void PBKDF2EngineTest::testPBKDF2c()
|
||||
{
|
||||
// test vector 3 from RFC 6070
|
||||
|
||||
|
||||
std::string p("password");
|
||||
std::string s("salt");
|
||||
PBKDF2Engine<HMACEngine<SHA1Engine> > pbkdf2(s, 4096, 20);
|
||||
@@ -86,7 +86,7 @@ void PBKDF2EngineTest::testPBKDF2d()
|
||||
void PBKDF2EngineTest::testPBKDF2e()
|
||||
{
|
||||
// test vector 5 from RFC 6070
|
||||
|
||||
|
||||
std::string p("passwordPASSWORDpassword");
|
||||
std::string s("saltSALTsaltSALTsaltSALTsaltSALTsalt");
|
||||
PBKDF2Engine<HMACEngine<SHA1Engine> > pbkdf2(s, 4096, 25);
|
||||
@@ -99,7 +99,7 @@ void PBKDF2EngineTest::testPBKDF2e()
|
||||
void PBKDF2EngineTest::testPBKDF2f()
|
||||
{
|
||||
// test vector 6 from RFC 6070
|
||||
|
||||
|
||||
std::string p("pass\0word", 9);
|
||||
std::string s("sa\0lt", 5);
|
||||
PBKDF2Engine<HMACEngine<SHA1Engine> > pbkdf2(s, 4096, 16);
|
||||
|
@@ -44,12 +44,12 @@ void PatternFormatterTest::testPatternFormatter()
|
||||
msg.setTime(DateTime(2005, 1, 1, 14, 30, 15, 500).timestamp());
|
||||
msg.setSourceFile(__FILE__);
|
||||
msg["testParam"] = "Test Parameter";
|
||||
|
||||
|
||||
std::string result;
|
||||
fmt.setProperty("pattern", "%Y-%m-%dT%H:%M:%S [%s] %p: %t");
|
||||
fmt.format(msg, result);
|
||||
assertTrue (result == "2005-01-01T14:30:15 [TestSource] Error: Test message text");
|
||||
|
||||
|
||||
result.clear();
|
||||
fmt.setProperty("pattern", "%w, %e %b %y %H:%M:%S.%i [%s:%I:%T] %q: %t");
|
||||
fmt.format(msg, result);
|
||||
@@ -60,14 +60,14 @@ void PatternFormatterTest::testPatternFormatter()
|
||||
fmt.format(msg, result);
|
||||
assertTrue (result.find("2005-01-01 14:30:15 [") == 0);
|
||||
assertTrue (result.find(":TestSource]3-Test message text") != std::string::npos);
|
||||
|
||||
|
||||
result.clear();
|
||||
assertTrue (fmt.getProperty("times") == "UTC");
|
||||
fmt.setProperty("times", "local");
|
||||
fmt.format(msg, result);
|
||||
assertTrue (result.find("2005-01-01 ") == 0);
|
||||
assertTrue (result.find(":TestSource]3-Test message text") != std::string::npos);
|
||||
|
||||
|
||||
result.clear();
|
||||
fmt.setProperty("pattern", "%[testParam]");
|
||||
fmt.format(msg, result);
|
||||
|
@@ -71,7 +71,7 @@ protected:
|
||||
|
||||
int getCount() const;
|
||||
private:
|
||||
int _count;
|
||||
std::atomic<int> _count;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -25,7 +25,7 @@ using Poco::Thread;
|
||||
using Poco::RunnableAdapter;
|
||||
|
||||
|
||||
namespace
|
||||
namespace
|
||||
{
|
||||
class QTestNotification: public Notification
|
||||
{
|
||||
@@ -72,7 +72,7 @@ void PriorityNotificationQueueTest::testQueueDequeue()
|
||||
assertTrue (queue.empty());
|
||||
assertTrue (queue.size() == 0);
|
||||
pNf->release();
|
||||
|
||||
|
||||
queue.enqueueNotification(new QTestNotification("first"), 1);
|
||||
queue.enqueueNotification(new QTestNotification("fourth"), 4);
|
||||
queue.enqueueNotification(new QTestNotification("third"), 3);
|
||||
@@ -137,11 +137,11 @@ void PriorityNotificationQueueTest::testWaitDequeue()
|
||||
void PriorityNotificationQueueTest::testThreads()
|
||||
{
|
||||
const int NOTIFICATION_COUNT = 5000;
|
||||
|
||||
|
||||
Thread t1("thread1");
|
||||
Thread t2("thread2");
|
||||
Thread t3("thread3");
|
||||
|
||||
|
||||
RunnableAdapter<PriorityNotificationQueueTest> ra(*this, &PriorityNotificationQueueTest::work);
|
||||
t1.start(ra);
|
||||
t2.start(ra);
|
||||
|
@@ -208,7 +208,7 @@ void ProcessTest::testLaunchArgs()
|
||||
std::string expectedArg = args[argNumber];
|
||||
if (expectedArg.npos != expectedArg.find("already quoted")) {
|
||||
expectedArg = "already quoted \" \\";
|
||||
}
|
||||
}
|
||||
assertTrue (receivedArg == expectedArg);
|
||||
++argNumber;
|
||||
receivedArg = "";
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "Poco/RWLock.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Runnable.h"
|
||||
#include <atomic>
|
||||
|
||||
|
||||
using Poco::RWLock;
|
||||
@@ -24,10 +25,15 @@ using Poco::Runnable;
|
||||
class RWLockRunnable: public Runnable
|
||||
{
|
||||
public:
|
||||
RWLockRunnable(RWLock& lock, volatile int& counter): _lock(lock), _counter(counter), _ok(true)
|
||||
#ifdef __cpp_lib_atomic_ref
|
||||
RWLockRunnable(RWLock& lock, int& counter):
|
||||
#else
|
||||
RWLockRunnable(RWLock& lock, volatile int& counter):
|
||||
#endif
|
||||
_lock(lock), _counter(counter), _ok(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void run()
|
||||
{
|
||||
int lastCount = 0;
|
||||
@@ -57,15 +63,19 @@ public:
|
||||
_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ok() const
|
||||
{
|
||||
return _ok;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
RWLock& _lock;
|
||||
#ifdef __cpp_lib_atomic_ref
|
||||
std::atomic_ref<int> _counter;
|
||||
#else
|
||||
volatile int& _counter;
|
||||
#endif
|
||||
bool _ok;
|
||||
};
|
||||
|
||||
@@ -73,10 +83,15 @@ private:
|
||||
class RWTryLockRunnable: public Runnable
|
||||
{
|
||||
public:
|
||||
RWTryLockRunnable(RWLock& lock, volatile int& counter): _lock(lock), _counter(counter), _ok(true)
|
||||
#ifdef __cpp_lib_atomic_ref
|
||||
RWTryLockRunnable(RWLock& lock, int& counter):
|
||||
#else
|
||||
RWTryLockRunnable(RWLock& lock, volatile int& counter):
|
||||
#endif
|
||||
_lock(lock), _counter(counter), _ok(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void run()
|
||||
{
|
||||
int lastCount = 0;
|
||||
@@ -106,15 +121,19 @@ public:
|
||||
_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ok() const
|
||||
{
|
||||
return _ok;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
RWLock& _lock;
|
||||
#ifdef __cpp_lib_atomic_ref
|
||||
std::atomic_ref<int> _counter;
|
||||
#else
|
||||
volatile int& _counter;
|
||||
#endif
|
||||
bool _ok;
|
||||
};
|
||||
|
||||
|
@@ -32,7 +32,7 @@ RandomStreamTest::~RandomStreamTest()
|
||||
void RandomStreamTest::testStream()
|
||||
{
|
||||
RandomInputStream rnd;
|
||||
|
||||
|
||||
const int n = 16;
|
||||
std::vector<int> d(n, 0);
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
@@ -49,7 +49,7 @@ void RandomStreamTest::testStream()
|
||||
for (int k = 0; k < n; ++k) var += (d[k] - avg)*(d[k] - avg);
|
||||
var /= n;
|
||||
int sd = int(std::sqrt((double) var));
|
||||
|
||||
|
||||
assertTrue (110 < avg && avg < 140);
|
||||
assertTrue (sd < 20);
|
||||
}
|
||||
|
@@ -48,8 +48,8 @@ void RandomTest::testSequence2()
|
||||
Poco::Random rnd2;
|
||||
rnd1.seed(12345);
|
||||
rnd2.seed(54321);
|
||||
|
||||
bool equals = true;
|
||||
|
||||
bool equals = true;
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
if (rnd1.next() != rnd2.next())
|
||||
@@ -74,7 +74,7 @@ void RandomTest::testDistribution1()
|
||||
}
|
||||
int sum = 0;
|
||||
for (int k = 0; k < n; ++k) sum += d[k];
|
||||
|
||||
|
||||
assertTrue (sum == n);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ void RandomTest::testDistribution2()
|
||||
for (int k = 0; k < n; ++k) var += (d[k] - avg)*(d[k] - avg);
|
||||
var /= n;
|
||||
int sd = int(std::sqrt((double) var));
|
||||
|
||||
|
||||
assertTrue (95 < avg && avg < 105);
|
||||
assertTrue (sd < 15);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ void RandomTest::testDistribution3()
|
||||
for (int k = 0; k < n; ++k) var += (d[k] - avg)*(d[k] - avg);
|
||||
var /= n;
|
||||
int sd = int(std::sqrt((double) var));
|
||||
|
||||
|
||||
assertTrue (95 < avg && avg < 105);
|
||||
assertTrue (sd < 15);
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ public:
|
||||
void testDistribution1();
|
||||
void testDistribution2();
|
||||
void testDistribution3();
|
||||
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
|
@@ -263,6 +263,17 @@ void RegularExpressionTest::testError()
|
||||
}
|
||||
|
||||
|
||||
void RegularExpressionTest::testGroup()
|
||||
{
|
||||
RegularExpression::MatchVec matches;
|
||||
RegularExpression re("(?P<group1>[a-z]+) (?P<group2>[0-9]+)");
|
||||
assertTrue (re.match("abcd 1234", 0, matches) == 3);
|
||||
assertTrue (matches[0].name == "");
|
||||
assertTrue (matches[1].name == "group1");
|
||||
assertTrue (matches[2].name == "group2");
|
||||
}
|
||||
|
||||
|
||||
void RegularExpressionTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -292,6 +303,7 @@ CppUnit::Test* RegularExpressionTest::suite()
|
||||
CppUnit_addTest(pSuite, RegularExpressionTest, testSubst3);
|
||||
CppUnit_addTest(pSuite, RegularExpressionTest, testSubst4);
|
||||
CppUnit_addTest(pSuite, RegularExpressionTest, testError);
|
||||
CppUnit_addTest(pSuite, RegularExpressionTest, testGroup);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -39,6 +39,7 @@ public:
|
||||
void testSubst3();
|
||||
void testSubst4();
|
||||
void testError();
|
||||
void testGroup();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
@@ -36,6 +36,9 @@ void SHA2EngineTest::testSHA224()
|
||||
{
|
||||
SHA2Engine engine(SHA2Engine::SHA_224);
|
||||
|
||||
engine.update("");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f");
|
||||
|
||||
engine.update("abc");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7");
|
||||
|
||||
@@ -55,6 +58,9 @@ void SHA2EngineTest::testSHA256()
|
||||
{
|
||||
SHA2Engine engine(SHA2Engine::SHA_256);
|
||||
|
||||
engine.update("");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
||||
|
||||
engine.update("abc");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
|
||||
|
||||
@@ -74,6 +80,9 @@ void SHA2EngineTest::testSHA384()
|
||||
{
|
||||
SHA2Engine engine(SHA2Engine::SHA_384);
|
||||
|
||||
engine.update("");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b");
|
||||
|
||||
engine.update("abc");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7");
|
||||
|
||||
@@ -93,6 +102,9 @@ void SHA2EngineTest::testSHA512()
|
||||
{
|
||||
SHA2Engine engine(SHA2Engine::SHA_512);
|
||||
|
||||
engine.update("");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
|
||||
|
||||
engine.update("abc");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f");
|
||||
|
||||
@@ -107,6 +119,47 @@ void SHA2EngineTest::testSHA512()
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b");
|
||||
}
|
||||
|
||||
void SHA2EngineTest::testSHA512_224()
|
||||
{
|
||||
SHA2Engine engine(SHA2Engine::SHA_512_224);
|
||||
|
||||
engine.update("");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4");
|
||||
|
||||
engine.update("abc");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa");
|
||||
|
||||
engine.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "e5302d6d54bb242275d1e7622d68df6eb02dedd13f564c13dbda2174");
|
||||
|
||||
engine.update("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9");
|
||||
|
||||
for (int i = 0; i < 1000000; ++i)
|
||||
engine.update('a');
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "37ab331d76f0d36de422bd0edeb22a28accd487b7a8453ae965dd287");
|
||||
}
|
||||
|
||||
void SHA2EngineTest::testSHA512_256()
|
||||
{
|
||||
SHA2Engine engine(SHA2Engine::SHA_512_256);
|
||||
|
||||
engine.update("");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a");
|
||||
|
||||
engine.update("abc");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23");
|
||||
|
||||
engine.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "bde8e1f9f19bb9fd3406c90ec6bc47bd36d8ada9f11880dbc8a22a7078b6a461");
|
||||
|
||||
engine.update("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu");
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a");
|
||||
|
||||
for (int i = 0; i < 1000000; ++i)
|
||||
engine.update('a');
|
||||
assertTrue (DigestEngine::digestToHex(engine.digest()) == "9a59a052930187a97038cae692f30708aa6491923ef5194394dc68d56c74fb21");
|
||||
}
|
||||
|
||||
void SHA2EngineTest::setUp()
|
||||
{
|
||||
@@ -126,6 +179,7 @@ CppUnit::Test* SHA2EngineTest::suite()
|
||||
CppUnit_addTest(pSuite, SHA2EngineTest, testSHA256);
|
||||
CppUnit_addTest(pSuite, SHA2EngineTest, testSHA384);
|
||||
CppUnit_addTest(pSuite, SHA2EngineTest, testSHA512);
|
||||
|
||||
CppUnit_addTest(pSuite, SHA2EngineTest, testSHA512_224);
|
||||
CppUnit_addTest(pSuite, SHA2EngineTest, testSHA512_256);
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -28,6 +28,8 @@ public:
|
||||
void testSHA256();
|
||||
void testSHA384();
|
||||
void testSHA512();
|
||||
void testSHA512_224();
|
||||
void testSHA512_256();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
@@ -29,28 +29,28 @@ public:
|
||||
SemaRunnable(int n, int max): _ran(false), _sema(n, max)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void run()
|
||||
{
|
||||
_sema.wait();
|
||||
_ran = true;
|
||||
}
|
||||
|
||||
|
||||
bool ran() const
|
||||
{
|
||||
return _ran;
|
||||
}
|
||||
|
||||
|
||||
void set()
|
||||
{
|
||||
_sema.set();
|
||||
}
|
||||
|
||||
|
||||
void wait()
|
||||
{
|
||||
_sema.wait();
|
||||
}
|
||||
|
||||
|
||||
void wait(long milliseconds)
|
||||
{
|
||||
_sema.wait(milliseconds);
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
{
|
||||
return _sema.tryWait(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
bool _ran;
|
||||
Semaphore _sema;
|
||||
@@ -100,7 +100,7 @@ void SemaphoreTest::testInitZero()
|
||||
assertTrue (r.tryWait(0));
|
||||
r.wait();
|
||||
assertTrue (!r.tryWait(10));
|
||||
|
||||
|
||||
Thread t;
|
||||
t.start(r);
|
||||
Thread::sleep(100);
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/SharedLibrary.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Path.h"
|
||||
|
||||
|
||||
using Poco::SharedLibrary;
|
||||
@@ -38,17 +39,19 @@ void SharedLibraryTest::testSharedLibrary1()
|
||||
{
|
||||
std::string path = "TestLibrary";
|
||||
path.append(SharedLibrary::suffix());
|
||||
Poco::Path libraryPath = Poco::Path::current();
|
||||
libraryPath.append(path);
|
||||
SharedLibrary sl;
|
||||
assertTrue (!sl.isLoaded());
|
||||
sl.load(path);
|
||||
assertTrue (sl.getPath() == path);
|
||||
sl.load(libraryPath.toString());
|
||||
assertTrue (sl.getPath() == libraryPath.toString());
|
||||
assertTrue (sl.isLoaded());
|
||||
assertTrue (sl.hasSymbol("pocoBuildManifest"));
|
||||
assertTrue (sl.hasSymbol("pocoInitializeLibrary"));
|
||||
assertTrue (sl.hasSymbol("pocoUninitializeLibrary"));
|
||||
assertTrue (sl.hasSymbol("gimmeFive"));
|
||||
assertTrue (!sl.hasSymbol("fooBar123"));
|
||||
|
||||
|
||||
void* p1 = sl.getSymbol("pocoBuildManifest");
|
||||
assertNotNullPtr(p1);
|
||||
try
|
||||
@@ -72,13 +75,15 @@ void SharedLibraryTest::testSharedLibrary2()
|
||||
{
|
||||
std::string path = "TestLibrary";
|
||||
path.append(SharedLibrary::suffix());
|
||||
SharedLibrary sl(path);
|
||||
assertTrue (sl.getPath() == path);
|
||||
Poco::Path libraryPath = Poco::Path::current();
|
||||
libraryPath.append(path);
|
||||
SharedLibrary sl(libraryPath.toString());
|
||||
assertTrue (sl.getPath() == libraryPath.toString());
|
||||
assertTrue (sl.isLoaded());
|
||||
|
||||
GimmeFiveFunc gimmeFive = (GimmeFiveFunc) sl.getSymbol("gimmeFive");
|
||||
assertTrue (gimmeFive() == 5);
|
||||
|
||||
|
||||
sl.unload();
|
||||
assertTrue (!sl.isLoaded());
|
||||
}
|
||||
@@ -105,12 +110,14 @@ void SharedLibraryTest::testSharedLibrary3()
|
||||
|
||||
path = "TestLibrary";
|
||||
path.append(SharedLibrary::suffix());
|
||||
sl.load(path);
|
||||
Poco::Path libraryPath = Poco::Path::current();
|
||||
libraryPath.append(path);
|
||||
sl.load(libraryPath.toString());
|
||||
assertTrue (sl.isLoaded());
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
sl.load(path);
|
||||
sl.load(libraryPath.toString());
|
||||
failmsg("library already loaded - must throw exception");
|
||||
}
|
||||
catch (LibraryAlreadyLoadedException&)
|
||||
|
@@ -67,7 +67,7 @@ Poco::Path SharedMemoryTest::findDataFile(const std::string& afile)
|
||||
Poco::File aFile(result.toString());
|
||||
if (!aFile.exists() || (aFile.exists() && !aFile.isFile()))
|
||||
throw Poco::FileNotFoundException("Didn't find file " + afile);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -38,11 +38,11 @@ void StopwatchTest::testStopwatch()
|
||||
Thread::sleep(200);
|
||||
sw.stop();
|
||||
Timestamp::TimeDiff d = sw.elapsed();
|
||||
assertTrue (d >= 180000 && d <= 300000);
|
||||
sw.start();
|
||||
assertTrue (d >= 180000 && d <= 300000);
|
||||
sw.start();
|
||||
Thread::sleep(100);
|
||||
d = sw.elapsed();
|
||||
assertTrue (d >= 280000 && d <= 400000);
|
||||
assertTrue (d >= 280000 && d <= 400000);
|
||||
Thread::sleep(100);
|
||||
sw.stop();
|
||||
d = sw.elapsed();
|
||||
@@ -52,7 +52,7 @@ void StopwatchTest::testStopwatch()
|
||||
Thread::sleep(200);
|
||||
sw.stop();
|
||||
d = sw.elapsed();
|
||||
assertTrue (d >= 180000 && d <= 300000);
|
||||
assertTrue (d >= 180000 && d <= 300000);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -40,14 +40,14 @@ StreamConverterTest::~StreamConverterTest()
|
||||
void StreamConverterTest::testIdentityASCIIIn()
|
||||
{
|
||||
ASCIIEncoding encoding;
|
||||
|
||||
|
||||
std::istringstream istr1("");
|
||||
std::ostringstream ostr1;
|
||||
InputStreamConverter converter1(istr1, encoding, encoding);
|
||||
StreamCopier::copyStream(converter1, ostr1);
|
||||
assertTrue (ostr1.str() == "");
|
||||
assertTrue (converter1.errors() == 0);
|
||||
|
||||
|
||||
std::istringstream istr2("foo bar");
|
||||
std::ostringstream ostr2;
|
||||
InputStreamConverter converter2(istr2, encoding, encoding);
|
||||
@@ -67,13 +67,13 @@ void StreamConverterTest::testIdentityASCIIIn()
|
||||
void StreamConverterTest::testIdentityASCIIOut()
|
||||
{
|
||||
ASCIIEncoding encoding;
|
||||
|
||||
|
||||
std::ostringstream ostr1;
|
||||
OutputStreamConverter converter1(ostr1, encoding, encoding);
|
||||
converter1 << "";
|
||||
assertTrue (ostr1.str() == "");
|
||||
assertTrue (converter1.errors() == 0);
|
||||
|
||||
|
||||
std::ostringstream ostr2;
|
||||
OutputStreamConverter converter2(ostr2, encoding, encoding);
|
||||
converter2 << "foo bar";
|
||||
@@ -91,14 +91,14 @@ void StreamConverterTest::testIdentityASCIIOut()
|
||||
void StreamConverterTest::testIdentityUTF8In()
|
||||
{
|
||||
UTF8Encoding encoding;
|
||||
|
||||
|
||||
std::istringstream istr1("");
|
||||
std::ostringstream ostr1;
|
||||
InputStreamConverter converter1(istr1, encoding, encoding);
|
||||
StreamCopier::copyStream(converter1, ostr1);
|
||||
assertTrue (ostr1.str() == "");
|
||||
assertTrue (converter1.errors() == 0);
|
||||
|
||||
|
||||
std::istringstream istr2("foo bar");
|
||||
std::ostringstream ostr2;
|
||||
InputStreamConverter converter2(istr2, encoding, encoding);
|
||||
@@ -112,7 +112,7 @@ void StreamConverterTest::testIdentityUTF8In()
|
||||
StreamCopier::copyStream(converter3, ostr3);
|
||||
assertTrue (ostr3.str() == "x");
|
||||
assertTrue (converter3.errors() == 0);
|
||||
|
||||
|
||||
const unsigned char greek[] = {0x20, 0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce, 0xbc, 0xce, 0xb5, 0x20, 0x00};
|
||||
std::string text((const char*) greek);
|
||||
|
||||
@@ -140,13 +140,13 @@ void StreamConverterTest::testIdentityUTF8In()
|
||||
void StreamConverterTest::testIdentityUTF8Out()
|
||||
{
|
||||
UTF8Encoding encoding;
|
||||
|
||||
|
||||
std::ostringstream ostr1;
|
||||
OutputStreamConverter converter1(ostr1, encoding, encoding);
|
||||
converter1 << "";
|
||||
assertTrue (ostr1.str() == "");
|
||||
assertTrue (converter1.errors() == 0);
|
||||
|
||||
|
||||
std::ostringstream ostr2;
|
||||
OutputStreamConverter converter2(ostr2, encoding, encoding);
|
||||
converter2 << "foo bar";
|
||||
@@ -158,7 +158,7 @@ void StreamConverterTest::testIdentityUTF8Out()
|
||||
converter3 << "x";
|
||||
assertTrue (ostr3.str() == "x");
|
||||
assertTrue (converter3.errors() == 0);
|
||||
|
||||
|
||||
const unsigned char greek[] = {0x20, 0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce, 0xbc, 0xce, 0xb5, 0x20, 0x00};
|
||||
std::string text((const char*) greek);
|
||||
|
||||
@@ -220,7 +220,7 @@ void StreamConverterTest::testLatin1toUTF8In()
|
||||
{
|
||||
UTF8Encoding utf8Encoding;
|
||||
Latin1Encoding latin1Encoding;
|
||||
|
||||
|
||||
const unsigned char latin1Chars[] = {'g', 252, 'n', 't', 'e', 'r', 0};
|
||||
const unsigned char utf8Chars[] = {'g', 195, 188, 'n', 't', 'e', 'r', 0};
|
||||
std::string latin1Text((const char*) latin1Chars);
|
||||
@@ -239,7 +239,7 @@ void StreamConverterTest::testLatin1toUTF8Out()
|
||||
{
|
||||
UTF8Encoding utf8Encoding;
|
||||
Latin1Encoding latin1Encoding;
|
||||
|
||||
|
||||
const unsigned char latin1Chars[] = {'g', 252, 'n', 't', 'e', 'r', 0};
|
||||
const unsigned char utf8Chars[] = {'g', 195, 188, 'n', 't', 'e', 'r', 0};
|
||||
std::string latin1Text((const char*) latin1Chars);
|
||||
@@ -260,7 +260,7 @@ void StreamConverterTest::testErrorsIn()
|
||||
|
||||
const unsigned char badChars[] = {'a', 'b', 255, 'c', 254, 0};
|
||||
std::string badText((const char*) badChars);
|
||||
|
||||
|
||||
std::istringstream istr1(badText);
|
||||
std::ostringstream ostr1;
|
||||
InputStreamConverter converter1(istr1, utf8Encoding, latin1Encoding);
|
||||
@@ -276,7 +276,7 @@ void StreamConverterTest::testErrorsOut()
|
||||
|
||||
const unsigned char badChars[] = {'a', 'b', 255, 'c', 254, 0};
|
||||
std::string badText((const char*) badChars);
|
||||
|
||||
|
||||
std::ostringstream ostr1;
|
||||
OutputStreamConverter converter1(ostr1, utf8Encoding, latin1Encoding);
|
||||
converter1 << badText;
|
||||
|
@@ -31,7 +31,7 @@ public:
|
||||
IdentifierToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~IdentifierToken()
|
||||
{
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
{
|
||||
return Token::IDENTIFIER_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
bool start(char c, std::istream& istr)
|
||||
{
|
||||
if (c != -1 && Ascii::isAlpha(c))
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
void finish(std::istream& istr)
|
||||
{
|
||||
int c = istr.peek();
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
IntLiteralToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~IntLiteralToken()
|
||||
{
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
{
|
||||
return Token::INTEGER_LITERAL_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
bool start(char c, std::istream& istr)
|
||||
{
|
||||
if (c != -1 && Ascii::isDigit(c))
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
void finish(std::istream& istr)
|
||||
{
|
||||
int c = istr.peek();
|
||||
@@ -121,7 +121,7 @@ void StreamTokenizerTest::testTokenizer1()
|
||||
tokenizer.addToken(new WhitespaceToken());
|
||||
tokenizer.addToken(new IdentifierToken());
|
||||
tokenizer.addToken(new IntLiteralToken());
|
||||
|
||||
|
||||
const Token* next = tokenizer.next();
|
||||
assertTrue (next->tokenClass() == Token::EOF_TOKEN);
|
||||
}
|
||||
@@ -135,11 +135,11 @@ void StreamTokenizerTest::testTokenizer2()
|
||||
tokenizer.addToken(new WhitespaceToken());
|
||||
tokenizer.addToken(new IdentifierToken());
|
||||
tokenizer.addToken(new IntLiteralToken());
|
||||
|
||||
|
||||
const Token* next = tokenizer.next();
|
||||
assertTrue (next->tokenClass() == Token::IDENTIFIER_TOKEN);
|
||||
assertTrue (next->tokenString() == "foo");
|
||||
|
||||
|
||||
next = tokenizer.next();
|
||||
assertTrue (next->tokenClass() == Token::EOF_TOKEN);
|
||||
}
|
||||
@@ -153,7 +153,7 @@ void StreamTokenizerTest::testTokenizer3()
|
||||
tokenizer.addToken(new WhitespaceToken());
|
||||
tokenizer.addToken(new IdentifierToken());
|
||||
tokenizer.addToken(new IntLiteralToken());
|
||||
|
||||
|
||||
const Token* next = tokenizer.next();
|
||||
assertTrue (next->tokenClass() == Token::IDENTIFIER_TOKEN);
|
||||
assertTrue (next->tokenString() == "foo");
|
||||
@@ -175,7 +175,7 @@ void StreamTokenizerTest::testTokenizer4()
|
||||
tokenizer.addToken(new WhitespaceToken());
|
||||
tokenizer.addToken(new IdentifierToken());
|
||||
tokenizer.addToken(new IntLiteralToken());
|
||||
|
||||
|
||||
const Token* next = tokenizer.next();
|
||||
assertTrue (next->tokenClass() == Token::IDENTIFIER_TOKEN);
|
||||
assertTrue (next->tokenString() == "foo");
|
||||
@@ -197,7 +197,7 @@ void StreamTokenizerTest::testTokenizer5()
|
||||
tokenizer.addToken(new WhitespaceToken());
|
||||
tokenizer.addToken(new IdentifierToken());
|
||||
tokenizer.addToken(new IntLiteralToken());
|
||||
|
||||
|
||||
const Token* next = tokenizer.next();
|
||||
assertTrue (next->tokenClass() == Token::IDENTIFIER_TOKEN);
|
||||
assertTrue (next->tokenString() == "foo");
|
||||
@@ -223,7 +223,7 @@ void StreamTokenizerTest::testTokenizer6()
|
||||
tokenizer.addToken(new WhitespaceToken());
|
||||
tokenizer.addToken(new IdentifierToken());
|
||||
tokenizer.addToken(new IntLiteralToken());
|
||||
|
||||
|
||||
const Token* next = tokenizer.next();
|
||||
assertTrue (next->tokenClass() == Token::IDENTIFIER_TOKEN);
|
||||
assertTrue (next->tokenString() == "foo");
|
||||
@@ -249,7 +249,7 @@ void StreamTokenizerTest::testTokenizer7()
|
||||
tokenizer.addToken(new WhitespaceToken());
|
||||
tokenizer.addToken(new IdentifierToken());
|
||||
tokenizer.addToken(new IntLiteralToken());
|
||||
|
||||
|
||||
const Token* next = tokenizer.next();
|
||||
assertTrue (next->tokenClass() == Token::IDENTIFIER_TOKEN);
|
||||
assertTrue (next->tokenString() == "foo");
|
||||
|
383
vendor/POCO/Foundation/testsuite/src/StringTest.cpp
vendored
383
vendor/POCO/Foundation/testsuite/src/StringTest.cpp
vendored
@@ -70,6 +70,7 @@ using Poco::MemoryInputStream;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::RangeException;
|
||||
using Poco::isIntOverflow;
|
||||
using Poco::safeMultiply;
|
||||
using Poco::isSafeIntCast;
|
||||
using Poco::safeIntCast;
|
||||
using Poco::FPEnvironment;
|
||||
@@ -915,121 +916,6 @@ void StringTest::testNumericLocale()
|
||||
}
|
||||
|
||||
|
||||
void StringTest::benchmarkStrToInt()
|
||||
{
|
||||
Poco::Stopwatch sw;
|
||||
std::string num = "123456789";
|
||||
int res;
|
||||
sw.start();
|
||||
for (int i = 0; i < 1000000; ++i) parseStream(num, res);
|
||||
sw.stop();
|
||||
std::cout << "parseStream Number: " << res << std::endl;
|
||||
double timeStream = sw.elapsed() / 1000.0;
|
||||
|
||||
char* pC = 0;
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) res = std::strtol(num.c_str(), &pC, 10);
|
||||
sw.stop();
|
||||
std::cout << "std::strtol Number: " << res << std::endl;
|
||||
double timeStrtol = sw.elapsed() / 1000.0;
|
||||
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) strToInt(num.c_str(), res, 10);
|
||||
sw.stop();
|
||||
std::cout << "strToInt Number: " << res << std::endl;
|
||||
double timeStrToInt = sw.elapsed() / 1000.0;
|
||||
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) std::sscanf(num.c_str(), "%d", &res);
|
||||
sw.stop();
|
||||
std::cout << "sscanf Number: " << res << std::endl;
|
||||
double timeScanf = sw.elapsed() / 1000.0;
|
||||
|
||||
int graph;
|
||||
std::cout << std::endl << "Timing and speedup relative to I/O stream:" << std::endl << std::endl;
|
||||
std::cout << std::setw(14) << "Stream:\t" << std::setw(10) << std::setfill(' ') << timeStream << "[ms]" << std::endl;
|
||||
|
||||
std::cout << std::setw(14) << "std::strtol:\t" << std::setw(10) << std::setfill(' ') << timeStrtol << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStrtol) << '\t' ;
|
||||
graph = (int) (timeStream / timeStrtol); for (int i = 0; i < graph; ++i) std::cout << '|';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "strToInt:\t" << std::setw(10) << std::setfill(' ') << timeStrToInt << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStrToInt) << '\t' ;
|
||||
graph = (int) (timeStream / timeStrToInt); for (int i = 0; i < graph; ++i) std::cout << '|';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "std::sscanf:\t" << std::setw(10) << std::setfill(' ') << timeScanf << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeScanf) << '\t' ;
|
||||
graph = (int) (timeStream / timeScanf); for (int i = 0; i < graph; ++i) std::cout << '|';
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void StringTest::benchmarkStrToFloat()
|
||||
{
|
||||
Poco::Stopwatch sw;
|
||||
std::string num = "1.0372157551632929e-112";
|
||||
std::cout << "The Number: " << num << std::endl;
|
||||
double res;
|
||||
sw.start();
|
||||
for (int i = 0; i < 1000000; ++i) parseStream(num, res);
|
||||
sw.stop();
|
||||
std::cout << "parseStream Number: " << std::setprecision(std::numeric_limits<double>::digits10) << res << std::endl;
|
||||
double timeStream = sw.elapsed() / 1000.0;
|
||||
|
||||
// standard strtod
|
||||
char* pC = 0;
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) res = std::strtod(num.c_str(), &pC);
|
||||
sw.stop();
|
||||
std::cout << "std::strtod Number: " << res << std::endl;
|
||||
double timeStdStrtod = sw.elapsed() / 1000.0;
|
||||
|
||||
// POCO Way
|
||||
sw.restart();
|
||||
char ou = 0;
|
||||
for (int i = 0; i < 1000000; ++i) strToDouble(num, res, ou);
|
||||
sw.stop();
|
||||
std::cout << "strToDouble Number: " << res << std::endl;
|
||||
double timeStrToDouble = sw.elapsed() / 1000.0;
|
||||
|
||||
// standard sscanf
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) std::sscanf(num.c_str(), "%lf", &res);
|
||||
sw.stop();
|
||||
std::cout << "sscanf Number: " << res << std::endl;
|
||||
double timeScanf = sw.elapsed() / 1000.0;
|
||||
|
||||
// double-conversion Strtod
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) strToDouble(num.c_str());
|
||||
sw.stop();
|
||||
std::cout << "Strtod Number: " << res << std::endl;
|
||||
double timeStrtod = sw.elapsed() / 1000.0;
|
||||
|
||||
int graph;
|
||||
std::cout << std::endl << "Timing and speedup relative to I/O stream:" << std::endl << std::endl;
|
||||
std::cout << std::setw(14) << "Stream:\t" << std::setw(10) << std::setfill(' ') << std::setprecision(4) << timeStream << "[ms]" << std::endl;
|
||||
|
||||
std::cout << std::setw(14) << "std::strtod:\t" << std::setw(10) << std::setfill(' ') << timeStdStrtod << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStdStrtod) << '\t' ;
|
||||
graph = (int) (timeStream / timeStdStrtod); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "strToDouble:\t" << std::setw(10) << std::setfill(' ') << timeStrToDouble << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStrToDouble) << '\t' ;
|
||||
graph = (int) (timeStream / timeStrToDouble); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "std::sscanf:\t" << std::setw(10) << std::setfill(' ') << timeScanf << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeScanf) << '\t' ;
|
||||
graph = (int) (timeStream / timeScanf); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "StrtoD:\t" << std::setw(10) << std::setfill(' ') << timeScanf << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStrtod) << '\t' ;
|
||||
graph = (int) (timeStream / timeStrtod); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void StringTest::testIntToString()
|
||||
{
|
||||
//intToStr(T number, unsigned short base, std::string& result, bool prefix = false, int width = -1, char fill = ' ', char thSep = 0)
|
||||
@@ -1325,6 +1211,15 @@ void StringTest::testNumericStringLimit()
|
||||
numericStringLowerLimit<int16_t, int8_t>();
|
||||
numericStringLowerLimit<int32_t, int16_t>();
|
||||
numericStringLowerLimit<int64_t, int32_t>();
|
||||
|
||||
multiplyOverflow<int8_t>();
|
||||
multiplyOverflow<uint8_t>();
|
||||
multiplyOverflow<int16_t>();
|
||||
multiplyOverflow<uint16_t>();
|
||||
multiplyOverflow<int32_t>();
|
||||
multiplyOverflow<uint32_t>();
|
||||
multiplyOverflow<int64_t>();
|
||||
multiplyOverflow<uint64_t>();
|
||||
}
|
||||
|
||||
|
||||
@@ -1343,68 +1238,11 @@ void formatStream(double value, std::string& str)
|
||||
void formatSprintf(double value, std::string& str)
|
||||
{
|
||||
char buffer[128];
|
||||
std::sprintf(buffer, "%.*g", 16, value);
|
||||
std::snprintf(buffer, sizeof(buffer), "%.*g", 16, value);
|
||||
str = buffer;
|
||||
}
|
||||
|
||||
|
||||
void StringTest::benchmarkFloatToStr()
|
||||
{
|
||||
Poco::Stopwatch sw;
|
||||
double val = 1.0372157551632929e-112;
|
||||
std::cout << "The Number: " << std::setprecision(std::numeric_limits<double>::digits10) << val << std::endl;
|
||||
std::string str;
|
||||
sw.start();
|
||||
for (int i = 0; i < 1000000; ++i) formatStream(val, str);
|
||||
sw.stop();
|
||||
std::cout << "formatStream Number: " << str << std::endl;
|
||||
double timeStream = sw.elapsed() / 1000.0;
|
||||
|
||||
// standard sprintf
|
||||
str = "";
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) formatSprintf(val, str);
|
||||
sw.stop();
|
||||
std::cout << "std::sprintf Number: " << str << std::endl;
|
||||
double timeSprintf = sw.elapsed() / 1000.0;
|
||||
|
||||
// POCO Way (via double-conversion)
|
||||
// no padding
|
||||
sw.restart();
|
||||
char buffer[POCO_MAX_FLT_STRING_LEN];
|
||||
for (int i = 0; i < 1000000; ++i) doubleToStr(buffer, POCO_MAX_FLT_STRING_LEN, val);
|
||||
sw.stop();
|
||||
std::cout << "doubleToStr(char) Number: " << buffer << std::endl;
|
||||
double timeDoubleToStrChar = sw.elapsed() / 1000.0;
|
||||
|
||||
// with padding
|
||||
str = "";
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) doubleToStr(str, val);
|
||||
sw.stop();
|
||||
std::cout << "doubleToStr(std::string) Number: " << str << std::endl;
|
||||
double timeDoubleToStrString = sw.elapsed() / 1000.0;
|
||||
|
||||
int graph;
|
||||
std::cout << std::endl << "Timing and speedup relative to I/O stream:" << std::endl << std::endl;
|
||||
std::cout << std::setw(14) << "Stream:\t" << std::setw(10) << std::setfill(' ') << std::setprecision(4) << timeStream << "[ms]" << std::endl;
|
||||
|
||||
std::cout << std::setw(14) << "sprintf:\t" << std::setw(10) << std::setfill(' ') << timeSprintf << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeSprintf) << '\t' ;
|
||||
graph = (int) (timeStream / timeSprintf); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "doubleToChar:\t" << std::setw(10) << std::setfill(' ') << timeDoubleToStrChar << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeDoubleToStrChar) << '\t' ;
|
||||
graph = (int) (timeStream / timeDoubleToStrChar); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "doubleToString:\t" << std::setw(10) << std::setfill(' ') << timeDoubleToStrString << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeDoubleToStrString) << '\t' ;
|
||||
graph = (int) (timeStream / timeDoubleToStrString); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void StringTest::testJSONString()
|
||||
{
|
||||
assertTrue (toJSON("\\", false) == "\\\\");
|
||||
@@ -1471,6 +1309,201 @@ void StringTest::testJSONString()
|
||||
}
|
||||
|
||||
|
||||
|
||||
void StringTest::conversionBenchmarks()
|
||||
{
|
||||
std::cout << std::endl << "===================" << std::endl;
|
||||
benchmarkFloatToStr();
|
||||
std::cout << "===================" << std::endl << std::endl;
|
||||
std::cout << "===================" << std::endl;
|
||||
benchmarkStrToFloat();
|
||||
std::cout << "===================" << std::endl << std::endl;
|
||||
std::cout << "===================" << std::endl;
|
||||
benchmarkStrToInt();
|
||||
std::cout << "===================" << std::endl << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void StringTest::benchmarkFloatToStr()
|
||||
{
|
||||
Poco::Stopwatch sw;
|
||||
double val = 1.0372157551632929e-112;
|
||||
std::cout << "The Number: " << std::setprecision(std::numeric_limits<double>::digits10) << val << std::endl;
|
||||
std::string str;
|
||||
sw.start();
|
||||
for (int i = 0; i < 1000000; ++i) formatStream(val, str);
|
||||
sw.stop();
|
||||
std::cout << "formatStream Number: " << str << std::endl;
|
||||
double timeStream = sw.elapsed() / 1000.0;
|
||||
|
||||
// standard sprintf
|
||||
str = "";
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) formatSprintf(val, str);
|
||||
sw.stop();
|
||||
std::cout << "std::sprintf Number: " << str << std::endl;
|
||||
double timeSprintf = sw.elapsed() / 1000.0;
|
||||
|
||||
// POCO Way (via double-conversion)
|
||||
// no padding
|
||||
sw.restart();
|
||||
char buffer[POCO_MAX_FLT_STRING_LEN];
|
||||
for (int i = 0; i < 1000000; ++i) doubleToStr(buffer, POCO_MAX_FLT_STRING_LEN, val);
|
||||
sw.stop();
|
||||
std::cout << "doubleToStr(char) Number: " << buffer << std::endl;
|
||||
double timeDoubleToStrChar = sw.elapsed() / 1000.0;
|
||||
|
||||
// with padding
|
||||
str = "";
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) doubleToStr(str, val);
|
||||
sw.stop();
|
||||
std::cout << "doubleToStr(std::string) Number: " << str << std::endl;
|
||||
double timeDoubleToStrString = sw.elapsed() / 1000.0;
|
||||
|
||||
int graph;
|
||||
std::cout << std::endl << "Timing and speedup relative to I/O stream:" << std::endl << std::endl;
|
||||
std::cout << std::setw(14) << "Stream:\t" << std::setw(10) << std::setfill(' ') << std::setprecision(4) << timeStream << "[ms]" << std::endl;
|
||||
|
||||
std::cout << std::setw(14) << "sprintf:\t" << std::setw(10) << std::setfill(' ') << timeSprintf << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeSprintf) << '\t' ;
|
||||
graph = (int) (timeStream / timeSprintf); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "doubleToChar:\t" << std::setw(10) << std::setfill(' ') << timeDoubleToStrChar << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeDoubleToStrChar) << '\t' ;
|
||||
graph = (int) (timeStream / timeDoubleToStrChar); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "doubleToString:\t" << std::setw(10) << std::setfill(' ') << timeDoubleToStrString << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeDoubleToStrString) << '\t' ;
|
||||
graph = (int) (timeStream / timeDoubleToStrString); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void StringTest::benchmarkStrToInt()
|
||||
{
|
||||
Poco::Stopwatch sw;
|
||||
std::string num = "123456789";
|
||||
int res[4] = {};
|
||||
sw.start();
|
||||
for (int i = 0; i < 1000000; ++i) parseStream(num, res[0]);
|
||||
sw.stop();
|
||||
std::cout << "parseStream Number: " << res[0] << std::endl;
|
||||
double timeStream = sw.elapsed() / 1000.0;
|
||||
|
||||
char* pC = 0;
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) res[1] = std::strtol(num.c_str(), &pC, 10);
|
||||
sw.stop();
|
||||
std::cout << "std::strtol Number: " << res[1] << std::endl;
|
||||
double timeStrtol = sw.elapsed() / 1000.0;
|
||||
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) strToInt(num.c_str(), res[2], 10);
|
||||
sw.stop();
|
||||
std::cout << "strToInt Number: " << res[2] << std::endl;
|
||||
double timeStrToInt = sw.elapsed() / 1000.0;
|
||||
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) std::sscanf(num.c_str(), "%d", &res[3]);
|
||||
sw.stop();
|
||||
std::cout << "sscanf Number: " << res[3] << std::endl;
|
||||
double timeScanf = sw.elapsed() / 1000.0;
|
||||
|
||||
assertEqual (res[0], res[1]);
|
||||
assertEqual (res[1], res[2]);
|
||||
assertEqual (res[2], res[3]);
|
||||
|
||||
int graph;
|
||||
std::cout << std::endl << "Timing and speedup relative to I/O stream:" << std::endl << std::endl;
|
||||
std::cout << std::setw(14) << "Stream:\t" << std::setw(10) << std::setfill(' ') << timeStream << "[ms]" << std::endl;
|
||||
|
||||
std::cout << std::setw(14) << "std::strtol:\t" << std::setw(10) << std::setfill(' ') << timeStrtol << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStrtol) << '\t' ;
|
||||
graph = (int) (timeStream / timeStrtol); for (int i = 0; i < graph; ++i) std::cout << '|';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "strToInt:\t" << std::setw(10) << std::setfill(' ') << timeStrToInt << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStrToInt) << '\t' ;
|
||||
graph = (int) (timeStream / timeStrToInt); for (int i = 0; i < graph; ++i) std::cout << '|';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "std::sscanf:\t" << std::setw(10) << std::setfill(' ') << timeScanf << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeScanf) << '\t' ;
|
||||
graph = (int) (timeStream / timeScanf); for (int i = 0; i < graph; ++i) std::cout << '|';
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void StringTest::benchmarkStrToFloat()
|
||||
{
|
||||
double res[5] = {};
|
||||
Poco::Stopwatch sw;
|
||||
std::string num = "1.0372157551632929e-112";
|
||||
std::cout << "The Number: " << num << std::endl;
|
||||
sw.start();
|
||||
for (int i = 0; i < 1000000; ++i) parseStream(num, res[0]);
|
||||
sw.stop();
|
||||
std::cout << "parseStream Number: " << std::setprecision(std::numeric_limits<double>::digits10) << res[0] << std::endl;
|
||||
double timeStream = sw.elapsed() / 1000.0;
|
||||
|
||||
// standard strtod
|
||||
char* pC = 0;
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) res[1] = std::strtod(num.c_str(), &pC);
|
||||
sw.stop();
|
||||
std::cout << "std::strtod Number: " << res[1] << std::endl;
|
||||
double timeStdStrtod = sw.elapsed() / 1000.0;
|
||||
|
||||
// POCO Way
|
||||
sw.restart();
|
||||
char ou = 0;
|
||||
for (int i = 0; i < 1000000; ++i) strToDouble(num, res[2], ou);
|
||||
sw.stop();
|
||||
std::cout << "Poco::strToDouble(const string&, double&) Number: " << res[2] << std::endl;
|
||||
double timeStrToDouble = sw.elapsed() / 1000.0;
|
||||
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) res[3] = strToDouble(num.c_str());
|
||||
sw.stop();
|
||||
std::cout << "Poco::strToDouble(const char*) Number: " << res[3] << std::endl;
|
||||
double timeStrtoD = sw.elapsed() / 1000.0;
|
||||
|
||||
// standard sscanf
|
||||
sw.restart();
|
||||
for (int i = 0; i < 1000000; ++i) std::sscanf(num.c_str(), "%lf", &res[4]);
|
||||
sw.stop();
|
||||
std::cout << "sscanf Number: " << res[4] << std::endl;
|
||||
double timeScanf = sw.elapsed() / 1000.0;
|
||||
|
||||
assertEqual (res[0], res[1]);
|
||||
assertEqual (res[1], res[2]);
|
||||
assertEqual (res[2], res[3]);
|
||||
assertEqual (res[3], res[4]);
|
||||
|
||||
int graph;
|
||||
std::cout << std::endl << "Timing and speedup relative to I/O stream:" << std::endl << std::endl;
|
||||
std::cout << std::setw(14) << "Stream:\t" << std::setw(10) << std::setfill(' ') << std::setprecision(4) << timeStream << "[ms]" << std::endl;
|
||||
|
||||
std::cout << std::setw(14) << "std::strtod:\t" << std::setw(10) << std::setfill(' ') << timeStdStrtod << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStdStrtod) << '\t' ;
|
||||
graph = (int) (timeStream / timeStdStrtod); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "strToDouble:\t" << std::setw(10) << std::setfill(' ') << timeStrToDouble << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStrToDouble) << '\t' ;
|
||||
graph = (int) (timeStream / timeStrToDouble); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "strToDouble:\t" << std::setw(10) << std::setfill(' ') << timeScanf << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeStrtoD) << '\t' ;
|
||||
graph = (int) (timeStream / timeStrtoD); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl << std::setw(14) << "std::sscanf:\t" << std::setw(10) << std::setfill(' ') << timeScanf << "[ms]" <<
|
||||
std::setw(10) << std::setfill(' ') << "Speedup: " << (timeStream / timeScanf) << '\t' ;
|
||||
graph = (int) (timeStream / timeScanf); for (int i = 0; i < graph; ++i) std::cout << '#';
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void StringTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -1510,12 +1543,10 @@ CppUnit::Test* StringTest::suite()
|
||||
CppUnit_addTest(pSuite, StringTest, testNumericStringLimit);
|
||||
CppUnit_addTest(pSuite, StringTest, testStringToFloatError);
|
||||
CppUnit_addTest(pSuite, StringTest, testNumericLocale);
|
||||
//CppUnit_addTest(pSuite, StringTest, benchmarkStrToFloat);
|
||||
//CppUnit_addTest(pSuite, StringTest, benchmarkStrToInt);
|
||||
CppUnit_addTest(pSuite, StringTest, testIntToString);
|
||||
CppUnit_addTest(pSuite, StringTest, testFloatToString);
|
||||
//CppUnit_addTest(pSuite, StringTest, benchmarkFloatToStr);
|
||||
CppUnit_addTest(pSuite, StringTest, testJSONString);
|
||||
CppUnit_addTest(pSuite, StringTest, conversionBenchmarks);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include "Poco/NumericString.h"
|
||||
#include "Poco/MemoryStream.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <limits>
|
||||
|
||||
|
||||
class StringTest: public CppUnit::TestCase
|
||||
@@ -53,12 +54,14 @@ public:
|
||||
void testNumericStringLimit();
|
||||
void testStringToFloatError();
|
||||
void testNumericLocale();
|
||||
void benchmarkStrToFloat();
|
||||
void benchmarkStrToInt();
|
||||
|
||||
void testIntToString();
|
||||
void testFloatToString();
|
||||
|
||||
void conversionBenchmarks();
|
||||
void benchmarkFloatToStr();
|
||||
void benchmarkStrToFloat();
|
||||
void benchmarkStrToInt();
|
||||
|
||||
void testJSONString();
|
||||
|
||||
@@ -74,7 +77,9 @@ private:
|
||||
{
|
||||
T result = 0;
|
||||
if (123 <= std::numeric_limits<T>::max())
|
||||
{
|
||||
assertTrue (Poco::strToInt("123", result, 10)); assertTrue (result == 123);
|
||||
}
|
||||
|
||||
assertTrue (Poco::strToInt("0", result, 10)); assertTrue (result == 0);
|
||||
assertTrue (Poco::strToInt("000", result, 10)); assertTrue (result == 0);
|
||||
@@ -128,7 +133,6 @@ private:
|
||||
assertFalse(s == std::numeric_limits<Smaller>::min());
|
||||
assertTrue(Poco::strToInt<Smaller>(val, s, 10));
|
||||
assertTrue (s == std::numeric_limits<Smaller>::min());
|
||||
assertTrue(s == std::numeric_limits<Smaller>::min());
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
@@ -143,6 +147,21 @@ private:
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void multiplyOverflow()
|
||||
{
|
||||
T m = static_cast<T>(10);
|
||||
T t = 0;
|
||||
T f = std::numeric_limits<T>::max()/m;
|
||||
assertTrue (Poco::safeMultiply(t, f, m));
|
||||
f += 1;
|
||||
assertFalse (Poco::safeMultiply(t, f, m));
|
||||
f = std::numeric_limits<T>::min()/m;
|
||||
assertTrue (Poco::safeMultiply(t, f, m));
|
||||
f -= 1;
|
||||
assertFalse (Poco::safeMultiply(t, f, m));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool parseStream(const std::string& s, T& value)
|
||||
{
|
||||
|
@@ -63,7 +63,7 @@ void StringTokenizerTest::testStringTokenizer()
|
||||
assertTrue (it != st.end());
|
||||
assertTrue (*it++ == "abc");
|
||||
assertTrue (it == st.end());
|
||||
}
|
||||
}
|
||||
{
|
||||
StringTokenizer st(" abc ", "", StringTokenizer::TOK_TRIM);
|
||||
StringTokenizer::Iterator it = st.begin();
|
||||
@@ -324,7 +324,7 @@ void StringTokenizerTest::testStringTokenizer()
|
||||
assertTrue (st.find("2") == 1);
|
||||
assertTrue (st.find("3") == 2);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
Poco::StringTokenizer st(" 2- ","-", Poco::StringTokenizer::TOK_TRIM);
|
||||
assertTrue (st.count() == 2);
|
||||
@@ -337,7 +337,7 @@ void StringTokenizerTest::testStringTokenizer()
|
||||
void StringTokenizerTest::testFind()
|
||||
{
|
||||
StringTokenizer st("0,1,2,3,3,2,1,0", ",", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
|
||||
|
||||
|
||||
assertTrue (st.count() == 8);
|
||||
assertTrue (2 == st.count("0"));
|
||||
assertTrue (2 == st.count("1"));
|
||||
@@ -356,7 +356,7 @@ void StringTokenizerTest::testFind()
|
||||
assertTrue (st[5] == "2");
|
||||
assertTrue (st[6] == "1");
|
||||
assertTrue (st[7] == "0");
|
||||
|
||||
|
||||
assertTrue (st.has("0"));
|
||||
assertTrue (st.has("1"));
|
||||
assertTrue (st.has("2"));
|
||||
|
@@ -49,12 +49,12 @@ namespace
|
||||
class TestTask: public Task
|
||||
{
|
||||
public:
|
||||
TestTask():
|
||||
TestTask():
|
||||
Task("TestTask"),
|
||||
_fail(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void runTask()
|
||||
{
|
||||
_event.wait();
|
||||
@@ -67,12 +67,12 @@ namespace
|
||||
setProgress(1.0);
|
||||
_event.wait();
|
||||
}
|
||||
|
||||
|
||||
void fail()
|
||||
{
|
||||
_fail = true;
|
||||
}
|
||||
|
||||
|
||||
void cont()
|
||||
{
|
||||
_event.set();
|
||||
@@ -82,20 +82,20 @@ namespace
|
||||
Event _event;
|
||||
bool _fail;
|
||||
};
|
||||
|
||||
|
||||
class SimpleTask: public Task
|
||||
{
|
||||
public:
|
||||
SimpleTask(): Task("SimpleTask")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void runTask()
|
||||
{
|
||||
sleep(10000);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TaskObserver
|
||||
{
|
||||
public:
|
||||
@@ -107,73 +107,73 @@ namespace
|
||||
_progress(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~TaskObserver()
|
||||
{
|
||||
delete _pException;
|
||||
}
|
||||
|
||||
|
||||
void taskStarted(TaskStartedNotification* pNf)
|
||||
{
|
||||
_started = true;
|
||||
pNf->release();
|
||||
}
|
||||
|
||||
|
||||
void taskCancelled(TaskCancelledNotification* pNf)
|
||||
{
|
||||
_cancelled = true;
|
||||
pNf->release();
|
||||
}
|
||||
|
||||
|
||||
void taskFinished(TaskFinishedNotification* pNf)
|
||||
{
|
||||
_finished = true;
|
||||
pNf->release();
|
||||
}
|
||||
|
||||
|
||||
void taskFailed(TaskFailedNotification* pNf)
|
||||
{
|
||||
_pException = pNf->reason().clone();
|
||||
pNf->release();
|
||||
}
|
||||
|
||||
|
||||
void taskProgress(TaskProgressNotification* pNf)
|
||||
{
|
||||
_progress = pNf->progress();
|
||||
pNf->release();
|
||||
}
|
||||
|
||||
|
||||
bool started() const
|
||||
{
|
||||
return _started;
|
||||
}
|
||||
|
||||
|
||||
bool cancelled() const
|
||||
{
|
||||
return _cancelled;
|
||||
}
|
||||
|
||||
|
||||
bool finished() const
|
||||
{
|
||||
return _finished;
|
||||
}
|
||||
|
||||
|
||||
float progress() const
|
||||
{
|
||||
return _progress;
|
||||
}
|
||||
|
||||
|
||||
Exception* error() const
|
||||
{
|
||||
return _pException;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
bool _started;
|
||||
bool _cancelled;
|
||||
bool _finished;
|
||||
Exception* _pException;
|
||||
float _progress;
|
||||
std::atomic<bool> _started;
|
||||
std::atomic<bool> _cancelled;
|
||||
std::atomic<bool> _finished;
|
||||
std::atomic<Exception*> _pException;
|
||||
std::atomic<float> _progress;
|
||||
};
|
||||
|
||||
|
||||
@@ -181,27 +181,27 @@ namespace
|
||||
class CustomNotificationTask: public Task
|
||||
{
|
||||
public:
|
||||
CustomNotificationTask(const T& t):
|
||||
CustomNotificationTask(const T& t):
|
||||
Task("CustomNotificationTask"),
|
||||
_custom(t)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void runTask()
|
||||
{
|
||||
sleep(10000);
|
||||
}
|
||||
|
||||
|
||||
void setCustom(const T& custom)
|
||||
{
|
||||
_custom = custom;
|
||||
postNotification(new TaskCustomNotification<T>(this, _custom));
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
T _custom;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class C>
|
||||
class CustomTaskObserver
|
||||
@@ -210,11 +210,11 @@ namespace
|
||||
CustomTaskObserver(const C& custom): _custom(custom)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~CustomTaskObserver()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void taskCustom(TaskCustomNotification<C>* pNf)
|
||||
{
|
||||
_custom = pNf->custom();
|
||||
@@ -253,10 +253,11 @@ void TaskManagerTest::testFinish()
|
||||
tm.addObserver(Observer<TaskObserver, TaskProgressNotification>(to, &TaskObserver::taskProgress));
|
||||
AutoPtr<TestTask> pTT = new TestTask;
|
||||
tm.start(pTT.duplicate());
|
||||
while (pTT->state() < Task::TASK_RUNNING) Thread::sleep(50);
|
||||
assertTrue (pTT->progress() == 0);
|
||||
Thread::sleep(200);
|
||||
pTT->cont();
|
||||
while (pTT->progress() != 0.5) Thread::sleep(50);
|
||||
while (to.progress() == 0) Thread::sleep(50);
|
||||
assertTrue (to.progress() == 0.5);
|
||||
assertTrue (to.started());
|
||||
assertTrue (pTT->state() == Task::TASK_RUNNING);
|
||||
@@ -274,6 +275,8 @@ void TaskManagerTest::testFinish()
|
||||
list = tm.taskList();
|
||||
assertTrue (list.empty());
|
||||
assertTrue (!to.error());
|
||||
tm.cancelAll();
|
||||
tm.joinAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -288,6 +291,7 @@ void TaskManagerTest::testCancel()
|
||||
tm.addObserver(Observer<TaskObserver, TaskProgressNotification>(to, &TaskObserver::taskProgress));
|
||||
AutoPtr<TestTask> pTT = new TestTask;
|
||||
tm.start(pTT.duplicate());
|
||||
while (pTT->state() < Task::TASK_RUNNING) Thread::sleep(50);
|
||||
assertTrue (pTT->progress() == 0);
|
||||
Thread::sleep(200);
|
||||
pTT->cont();
|
||||
@@ -299,15 +303,20 @@ void TaskManagerTest::testCancel()
|
||||
assertTrue (list.size() == 1);
|
||||
assertTrue (tm.count() == 1);
|
||||
tm.cancelAll();
|
||||
while (pTT->state() != Task::TASK_CANCELLING) Thread::sleep(50);
|
||||
pTT->cont();
|
||||
assertTrue (to.cancelled());
|
||||
pTT->cont();
|
||||
while (pTT->state() != Task::TASK_FINISHED) Thread::sleep(50);
|
||||
assertTrue (pTT->state() == Task::TASK_FINISHED);
|
||||
while (!to.finished()) Thread::sleep(50);
|
||||
assertTrue (to.finished());
|
||||
while (tm.count() == 1) Thread::sleep(50);
|
||||
list = tm.taskList();
|
||||
assertTrue (list.empty());
|
||||
assertTrue (!to.error());
|
||||
tm.cancelAll();
|
||||
tm.joinAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -322,6 +331,7 @@ void TaskManagerTest::testError()
|
||||
tm.addObserver(Observer<TaskObserver, TaskProgressNotification>(to, &TaskObserver::taskProgress));
|
||||
AutoPtr<TestTask> pTT = new TestTask;
|
||||
tm.start(pTT.duplicate());
|
||||
while (pTT->state() < Task::TASK_RUNNING) Thread::sleep(50);
|
||||
assertTrue (pTT->progress() == 0);
|
||||
Thread::sleep(200);
|
||||
pTT->cont();
|
||||
@@ -335,28 +345,33 @@ void TaskManagerTest::testError()
|
||||
pTT->fail();
|
||||
pTT->cont();
|
||||
while (pTT->state() != Task::TASK_FINISHED) Thread::sleep(50);
|
||||
pTT->cont();
|
||||
while (pTT->state() != Task::TASK_FINISHED) Thread::sleep(50);
|
||||
assertTrue (pTT->state() == Task::TASK_FINISHED);
|
||||
while (!to.finished()) Thread::sleep(50);
|
||||
assertTrue (to.finished());
|
||||
assertTrue (to.error() != 0);
|
||||
while (tm.count() == 1) Thread::sleep(50);
|
||||
list = tm.taskList();
|
||||
assertTrue (list.empty());
|
||||
tm.cancelAll();
|
||||
tm.joinAll();
|
||||
}
|
||||
|
||||
|
||||
void TaskManagerTest::testCustom()
|
||||
{
|
||||
TaskManager tm;
|
||||
|
||||
|
||||
CustomTaskObserver<int> ti(0);
|
||||
tm.addObserver(
|
||||
Observer<CustomTaskObserver<int>, TaskCustomNotification<int> >
|
||||
(ti, &CustomTaskObserver<int>::taskCustom));
|
||||
|
||||
|
||||
AutoPtr<CustomNotificationTask<int> > pCNT1 = new CustomNotificationTask<int>(0);
|
||||
tm.start(pCNT1.duplicate());
|
||||
assertTrue (ti.custom() == 0);
|
||||
|
||||
|
||||
for (int i = 1; i < 10; ++i)
|
||||
{
|
||||
pCNT1->setCustom(i);
|
||||
@@ -367,7 +382,7 @@ void TaskManagerTest::testCustom()
|
||||
tm.addObserver(
|
||||
Observer<CustomTaskObserver<std::string>, TaskCustomNotification<std::string> >
|
||||
(ts, &CustomTaskObserver<std::string>::taskCustom));
|
||||
|
||||
|
||||
AutoPtr<CustomNotificationTask<std::string> > pCNT2 = new CustomNotificationTask<std::string>("");
|
||||
tm.start(pCNT2.duplicate());
|
||||
assertTrue (tm.taskList().size() == 2);
|
||||
@@ -375,17 +390,17 @@ void TaskManagerTest::testCustom()
|
||||
std::string str("notify me");
|
||||
pCNT2->setCustom(str);
|
||||
assertTrue (ts.custom() == str);
|
||||
|
||||
|
||||
S s;
|
||||
s.i = 0;
|
||||
s.str = "";
|
||||
|
||||
CustomTaskObserver<S*> ptst(&s);
|
||||
|
||||
|
||||
tm.addObserver(
|
||||
Observer<CustomTaskObserver<S*>, TaskCustomNotification<S*> >
|
||||
(ptst, &CustomTaskObserver<S*>::taskCustom));
|
||||
|
||||
|
||||
AutoPtr<CustomNotificationTask<S*> > pCNT3 = new CustomNotificationTask<S*>(&s);
|
||||
tm.start(pCNT3.duplicate());
|
||||
assertTrue (tm.taskList().size() == 3);
|
||||
@@ -401,11 +416,11 @@ void TaskManagerTest::testCustom()
|
||||
s.str = "";
|
||||
|
||||
CustomTaskObserver<S> tst(s);
|
||||
|
||||
|
||||
tm.addObserver(
|
||||
Observer<CustomTaskObserver<S>, TaskCustomNotification<S> >
|
||||
(tst, &CustomTaskObserver<S>::taskCustom));
|
||||
|
||||
|
||||
AutoPtr<CustomNotificationTask<S> > pCNT4 = new CustomNotificationTask<S>(s);
|
||||
tm.start(pCNT4.duplicate());
|
||||
assertTrue (tm.taskList().size() == 4);
|
||||
@@ -416,7 +431,7 @@ void TaskManagerTest::testCustom()
|
||||
pCNT4->setCustom(s);
|
||||
assertTrue (tst.custom().i == 123);
|
||||
assertTrue (tst.custom().str == "123");
|
||||
|
||||
|
||||
AutoPtr<SimpleTask> pST = new SimpleTask;
|
||||
tm.start(pST.duplicate());
|
||||
assertTrue (tm.taskList().size() == 5);
|
||||
@@ -424,6 +439,7 @@ void TaskManagerTest::testCustom()
|
||||
tm.cancelAll();
|
||||
while (tm.count() > 0) Thread::sleep(50);
|
||||
assertTrue (tm.count() == 0);
|
||||
tm.joinAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -433,13 +449,14 @@ void TaskManagerTest::testMultiTasks()
|
||||
tm.start(new SimpleTask);
|
||||
tm.start(new SimpleTask);
|
||||
tm.start(new SimpleTask);
|
||||
|
||||
|
||||
TaskManager::TaskList list = tm.taskList();
|
||||
assertTrue (list.size() == 3);
|
||||
|
||||
|
||||
tm.cancelAll();
|
||||
while (tm.count() > 0) Thread::sleep(100);
|
||||
assertTrue (tm.count() == 0);
|
||||
tm.joinAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -471,8 +488,9 @@ void TaskManagerTest::testCustomThreadPool()
|
||||
}
|
||||
|
||||
assertTrue (tm.count() == tp.allocated());
|
||||
|
||||
tp.joinAll();
|
||||
|
||||
tm.cancelAll();
|
||||
tm.joinAll();
|
||||
}
|
||||
|
||||
void TaskManagerTest::setUp()
|
||||
|
@@ -31,7 +31,7 @@ namespace
|
||||
TestTask(): Task("TestTask")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void runTask()
|
||||
{
|
||||
_event.wait();
|
||||
@@ -44,12 +44,12 @@ namespace
|
||||
setProgress(1.0);
|
||||
_event.wait();
|
||||
}
|
||||
|
||||
|
||||
void cont()
|
||||
{
|
||||
_event.set();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Event _event;
|
||||
};
|
||||
|
@@ -26,13 +26,13 @@ public:
|
||||
|
||||
TestChannel();
|
||||
~TestChannel();
|
||||
|
||||
|
||||
void log(const Poco::Message& msg);
|
||||
MsgList& list();
|
||||
void clear();
|
||||
const Poco::Message& getLastMessage() const { return _lastMessage; }
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
MsgList _msgList;
|
||||
Poco::Message _lastMessage;
|
||||
};
|
||||
|
@@ -22,11 +22,11 @@ public:
|
||||
PluginA()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~PluginA()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
return "PluginA";
|
||||
@@ -40,11 +40,11 @@ public:
|
||||
PluginB()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~PluginB()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
return "PluginB";
|
||||
@@ -58,11 +58,11 @@ public:
|
||||
PluginC()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~PluginC()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
return "PluginC";
|
||||
@@ -85,7 +85,7 @@ void pocoInitializeLibrary()
|
||||
|
||||
void pocoUninitializeLibrary()
|
||||
{
|
||||
std::cout << "TestLibrary uninitialzing" << std::endl;
|
||||
std::cout << "TestLibrary uninitializing" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -39,7 +39,7 @@ void TextBufferIteratorTest::testEmptyLatin1()
|
||||
const char* text = "";
|
||||
TextBufferIterator it(text, encoding);
|
||||
TextBufferIterator end(it.end());
|
||||
|
||||
|
||||
assertTrue (it == end);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ void TextBufferIteratorTest::testOneLatin1()
|
||||
const char* text = "x";
|
||||
TextBufferIterator it(text, encoding);
|
||||
TextBufferIterator end(it.end());
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it == 'x');
|
||||
++it;
|
||||
@@ -64,7 +64,7 @@ void TextBufferIteratorTest::testLatin1()
|
||||
const char* text = "Latin1";
|
||||
TextBufferIterator it(text, encoding);
|
||||
TextBufferIterator end(it.end());
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 'L');
|
||||
assertTrue (it != end);
|
||||
@@ -78,7 +78,7 @@ void TextBufferIteratorTest::testLatin1()
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == '1');
|
||||
assertTrue (it == end);
|
||||
|
||||
|
||||
const char* empty = "";
|
||||
it = TextBufferIterator(empty, encoding);
|
||||
end = it.end();
|
||||
@@ -92,7 +92,7 @@ void TextBufferIteratorTest::testEmptyUTF8()
|
||||
const char* text = "";
|
||||
TextBufferIterator it(text, encoding);
|
||||
TextBufferIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it == end);
|
||||
}
|
||||
|
||||
@@ -100,25 +100,25 @@ void TextBufferIteratorTest::testEmptyUTF8()
|
||||
void TextBufferIteratorTest::testOneUTF8()
|
||||
{
|
||||
UTF8Encoding encoding;
|
||||
|
||||
|
||||
// 1 byte sequence
|
||||
const char* text = "x";
|
||||
TextBufferIterator it(text, encoding);
|
||||
TextBufferIterator end(it.end());
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it == 'x');
|
||||
++it;
|
||||
assertTrue (it == end);
|
||||
|
||||
|
||||
unsigned char data[Poco::TextEncoding::MAX_SEQUENCE_LENGTH];
|
||||
|
||||
|
||||
// 2 byte sequence
|
||||
int n = encoding.convert(0xab, data, sizeof(data));
|
||||
assertTrue (n == 2);
|
||||
it = TextBufferIterator(reinterpret_cast<const char*>(data), n, encoding);
|
||||
end = it.end();
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0xab);
|
||||
assertTrue (it == end);
|
||||
@@ -128,7 +128,7 @@ void TextBufferIteratorTest::testOneUTF8()
|
||||
assertTrue (n == 3);
|
||||
it = TextBufferIterator(reinterpret_cast<const char*>(data), n, encoding);
|
||||
end = it.end();
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0xabcd);
|
||||
assertTrue (it == end);
|
||||
@@ -138,11 +138,11 @@ void TextBufferIteratorTest::testOneUTF8()
|
||||
assertTrue (n == 4);
|
||||
it = TextBufferIterator(reinterpret_cast<const char*>(data), n, encoding);
|
||||
end = it.end();
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0xabcde);
|
||||
assertTrue (it == end);
|
||||
|
||||
|
||||
// 5 byte sequence - not supported
|
||||
n = encoding.convert(0xabcdef, data, sizeof(data));
|
||||
assertTrue (n == 0);
|
||||
@@ -159,7 +159,7 @@ void TextBufferIteratorTest::testUTF8()
|
||||
const unsigned char text[] = {0x20, 0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce, 0xbc, 0xce, 0xb5, 0x20, 0x00};
|
||||
TextBufferIterator it(reinterpret_cast<const char*>(text), encoding);
|
||||
TextBufferIterator end(it.end());
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0x0020);
|
||||
assertTrue (it != end);
|
||||
@@ -180,11 +180,11 @@ void TextBufferIteratorTest::testUTF8()
|
||||
|
||||
void TextBufferIteratorTest::testUTF8Supplementary()
|
||||
{
|
||||
UTF8Encoding encoding;
|
||||
UTF8Encoding encoding;
|
||||
const unsigned char text[] = {0x41, 0x42, 0xf0, 0x90, 0x82, 0xa4, 0xf0, 0xaf, 0xa6, 0xa0, 0xf0, 0xaf, 0xa8, 0x9d, 0x00};
|
||||
TextBufferIterator it(reinterpret_cast<const char*>(text), encoding);
|
||||
TextBufferIterator end(it.end());
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0x0041);
|
||||
assertTrue (it != end);
|
||||
@@ -201,11 +201,11 @@ void TextBufferIteratorTest::testUTF8Supplementary()
|
||||
|
||||
void TextBufferIteratorTest::testUTF16Supplementary()
|
||||
{
|
||||
UTF16Encoding encoding;
|
||||
UTF16Encoding encoding;
|
||||
const Poco::UInt16 text[] = { 0x0041, 0x0042, 0xD800, 0xDCA4, 0xD87E, 0xDDA0, 0xD87E, 0xDE1D};
|
||||
TextBufferIterator it(reinterpret_cast<const char*>(text), sizeof(text), encoding);
|
||||
TextBufferIterator end(it.end());
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0x0041);
|
||||
assertTrue (it != end);
|
||||
@@ -227,7 +227,7 @@ void TextBufferIteratorTest::testSwap()
|
||||
TextBufferIterator it1(text, encoding);
|
||||
TextBufferIterator it2(text, encoding);
|
||||
TextBufferIterator end(it1.end());
|
||||
|
||||
|
||||
assertTrue (it1 == it2);
|
||||
it2.swap(end);
|
||||
assertTrue (it1 != it2);
|
||||
|
@@ -39,13 +39,13 @@ void TextConverterTest::testIdentityASCII()
|
||||
{
|
||||
ASCIIEncoding encoding;
|
||||
TextConverter converter(encoding, encoding);
|
||||
|
||||
|
||||
std::string empty;
|
||||
std::string result0;
|
||||
int errors = converter.convert(empty, result0);
|
||||
assertTrue (result0 == empty);
|
||||
assertTrue (errors == 0);
|
||||
|
||||
|
||||
std::string fooBar = "foo bar";
|
||||
std::string result1;
|
||||
errors = converter.convert(fooBar, result1);
|
||||
@@ -61,7 +61,7 @@ void TextConverterTest::testIdentityASCII()
|
||||
errors = converter.convert("", 0, result3);
|
||||
assertTrue (result3.empty());
|
||||
assertTrue (errors == 0);
|
||||
|
||||
|
||||
std::string x = "x";
|
||||
std::string result4;
|
||||
errors = converter.convert(x, result4);
|
||||
@@ -79,13 +79,13 @@ void TextConverterTest::testIdentityUTF8()
|
||||
{
|
||||
UTF8Encoding encoding;
|
||||
TextConverter converter(encoding, encoding);
|
||||
|
||||
|
||||
std::string empty;
|
||||
std::string result0;
|
||||
int errors = converter.convert(empty, result0);
|
||||
assertTrue (result0 == empty);
|
||||
assertTrue (errors == 0);
|
||||
|
||||
|
||||
std::string fooBar = "foo bar";
|
||||
std::string result1;
|
||||
errors = converter.convert(fooBar, result1);
|
||||
@@ -101,20 +101,20 @@ void TextConverterTest::testIdentityUTF8()
|
||||
errors = converter.convert("", 0, result3);
|
||||
assertTrue (result3.empty());
|
||||
assertTrue (errors == 0);
|
||||
|
||||
|
||||
const unsigned char greek[] = {0x20, 0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce, 0xbc, 0xce, 0xb5, 0x20, 0x00};
|
||||
std::string text((const char*) greek);
|
||||
|
||||
|
||||
std::string result4;
|
||||
errors = converter.convert(text, result4);
|
||||
assertTrue (result4 == text);
|
||||
assertTrue (errors == 0);
|
||||
|
||||
|
||||
std::string result5;
|
||||
errors = converter.convert((char*) greek, 13, result5);
|
||||
assertTrue (result5 == text);
|
||||
assertTrue (errors == 0);
|
||||
|
||||
|
||||
std::string x = "x";
|
||||
std::string result6;
|
||||
errors = converter.convert(x, result6);
|
||||
@@ -125,13 +125,13 @@ void TextConverterTest::testIdentityUTF8()
|
||||
errors = converter.convert("x", 1, result7);
|
||||
assertTrue (result7 == x);
|
||||
assertTrue (errors == 0);
|
||||
|
||||
|
||||
std::string utfChar((char*) greek + 1, 2);
|
||||
std::string result8;
|
||||
errors = converter.convert(utfChar, result8);
|
||||
assertTrue (result8 == utfChar);
|
||||
assertTrue (errors == 0);
|
||||
|
||||
|
||||
std::string result9;
|
||||
errors = converter.convert((char*) greek + 1, 2, result9);
|
||||
assertTrue (result9 == utfChar);
|
||||
@@ -151,7 +151,7 @@ void TextConverterTest::testUTF8toASCII()
|
||||
int errors = converter.convert(text, result0);
|
||||
assertTrue (result0 == " ????? AB");
|
||||
assertTrue (errors == 0);
|
||||
|
||||
|
||||
std::string result1;
|
||||
errors = converter.convert("abcde", 5, result1);
|
||||
assertTrue (result1 == "abcde");
|
||||
@@ -163,18 +163,18 @@ void TextConverterTest::testLatin1toUTF8()
|
||||
Latin1Encoding latin1Encoding;
|
||||
UTF8Encoding utf8Encoding;
|
||||
TextConverter converter(latin1Encoding, utf8Encoding);
|
||||
|
||||
|
||||
const unsigned char latin1Chars[] = {'g', 252, 'n', 't', 'e', 'r', 0};
|
||||
const unsigned char utf8Chars[] = {'g', 195, 188, 'n', 't', 'e', 'r', 0};
|
||||
std::string latin1Text((const char*) latin1Chars);
|
||||
std::string utf8Text((const char*) utf8Chars);
|
||||
|
||||
|
||||
std::string result0;
|
||||
int errors = converter.convert(latin1Text, result0);
|
||||
assertTrue (result0 == utf8Text);
|
||||
assertTrue (errors == 0);
|
||||
assertEqual((long) result0.size(), 7);
|
||||
|
||||
|
||||
std::string result1;
|
||||
errors = converter.convert(latin1Chars, 6, result1);
|
||||
assertTrue (result1 == utf8Text);
|
||||
@@ -319,7 +319,7 @@ void TextConverterTest::testErrors()
|
||||
|
||||
const unsigned char badChars[] = {'a', 'b', 255, 'c', 254, 0};
|
||||
std::string badText((const char*) badChars);
|
||||
|
||||
|
||||
std::string result;
|
||||
int errors = converter.convert(badText, result);
|
||||
assertTrue (errors == 2);
|
||||
|
@@ -38,10 +38,10 @@ void TextEncodingTest::testTextEncoding()
|
||||
{
|
||||
TextEncoding& utf8 = TextEncoding::byName("utf8");
|
||||
assertTrue (std::string("UTF-8") == utf8.canonicalName());
|
||||
|
||||
|
||||
TextEncoding& latin1 = TextEncoding::byName("latin1");
|
||||
assertTrue (std::string("ISO-8859-1") == latin1.canonicalName());
|
||||
|
||||
|
||||
TextEncoding& latin2 = TextEncoding::byName("latin2");
|
||||
assertTrue (std::string("ISO-8859-2") == latin2.canonicalName());
|
||||
|
||||
@@ -60,7 +60,7 @@ void TextEncodingTest::testTextEncoding()
|
||||
|
||||
TextEncoding& glob = TextEncoding::global();
|
||||
assertTrue (std::string("UTF-8") == glob.canonicalName());
|
||||
|
||||
|
||||
TextEncoding::global(new Latin1Encoding);
|
||||
TextEncoding& glob2 = TextEncoding::global();
|
||||
assertTrue (std::string("ISO-8859-1") == glob2.canonicalName());
|
||||
|
@@ -39,7 +39,7 @@ void TextIteratorTest::testEmptyLatin1()
|
||||
std::string text;
|
||||
TextIterator it(text, encoding);
|
||||
TextIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it == end);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ void TextIteratorTest::testOneLatin1()
|
||||
std::string text("x");
|
||||
TextIterator it(text, encoding);
|
||||
TextIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it == 'x');
|
||||
++it;
|
||||
@@ -64,7 +64,7 @@ void TextIteratorTest::testLatin1()
|
||||
std::string text("Latin1");
|
||||
TextIterator it(text, encoding);
|
||||
TextIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 'L');
|
||||
assertTrue (it != end);
|
||||
@@ -78,7 +78,7 @@ void TextIteratorTest::testLatin1()
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == '1');
|
||||
assertTrue (it == end);
|
||||
|
||||
|
||||
std::string empty;
|
||||
it = TextIterator(empty, encoding);
|
||||
end = TextIterator(empty);
|
||||
@@ -92,7 +92,7 @@ void TextIteratorTest::testEmptyUTF8()
|
||||
std::string text;
|
||||
TextIterator it(text, encoding);
|
||||
TextIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it == end);
|
||||
}
|
||||
|
||||
@@ -100,26 +100,26 @@ void TextIteratorTest::testEmptyUTF8()
|
||||
void TextIteratorTest::testOneUTF8()
|
||||
{
|
||||
UTF8Encoding encoding;
|
||||
|
||||
|
||||
// 1 byte sequence
|
||||
std::string text("x");
|
||||
TextIterator it(text, encoding);
|
||||
TextIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it == 'x');
|
||||
++it;
|
||||
assertTrue (it == end);
|
||||
|
||||
|
||||
unsigned char data[Poco::TextEncoding::MAX_SEQUENCE_LENGTH];
|
||||
|
||||
|
||||
// 2 byte sequence
|
||||
int n = encoding.convert(0xab, data, sizeof(data));
|
||||
assertTrue (n == 2);
|
||||
text.assign((char*) data, n);
|
||||
it = TextIterator(text, encoding);
|
||||
end = TextIterator(text);
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0xab);
|
||||
assertTrue (it == end);
|
||||
@@ -130,7 +130,7 @@ void TextIteratorTest::testOneUTF8()
|
||||
text.assign((char*) data, n);
|
||||
it = TextIterator(text, encoding);
|
||||
end = TextIterator(text);
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0xabcd);
|
||||
assertTrue (it == end);
|
||||
@@ -141,11 +141,11 @@ void TextIteratorTest::testOneUTF8()
|
||||
text.assign((char*) data, n);
|
||||
it = TextIterator(text, encoding);
|
||||
end = TextIterator(text);
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0xabcde);
|
||||
assertTrue (it == end);
|
||||
|
||||
|
||||
// 5 byte sequence - not supported
|
||||
n = encoding.convert(0xabcdef, data, sizeof(data));
|
||||
assertTrue (n == 0);
|
||||
@@ -163,7 +163,7 @@ void TextIteratorTest::testUTF8()
|
||||
std::string text((const char*) greek);
|
||||
TextIterator it(text, encoding);
|
||||
TextIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0x0020);
|
||||
assertTrue (it != end);
|
||||
@@ -184,12 +184,12 @@ void TextIteratorTest::testUTF8()
|
||||
|
||||
void TextIteratorTest::testUTF8Supplementary()
|
||||
{
|
||||
UTF8Encoding encoding;
|
||||
UTF8Encoding encoding;
|
||||
const unsigned char supp[] = {0x41, 0x42, 0xf0, 0x90, 0x82, 0xa4, 0xf0, 0xaf, 0xa6, 0xa0, 0xf0, 0xaf, 0xa8, 0x9d, 0x00};
|
||||
std::string text((const char*) supp);
|
||||
TextIterator it(text, encoding);
|
||||
TextIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0x0041);
|
||||
assertTrue (it != end);
|
||||
@@ -206,12 +206,12 @@ void TextIteratorTest::testUTF8Supplementary()
|
||||
|
||||
void TextIteratorTest::testUTF16Supplementary()
|
||||
{
|
||||
UTF16Encoding encoding;
|
||||
UTF16Encoding encoding;
|
||||
const Poco::UInt16 supp [] = { 0x0041, 0x0042, 0xD800, 0xDCA4, 0xD87E, 0xDDA0, 0xD87E, 0xDE1D, 0x00};
|
||||
std::string text((const char*) supp, 16);
|
||||
TextIterator it(text, encoding);
|
||||
TextIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it != end);
|
||||
assertTrue (*it++ == 0x0041);
|
||||
assertTrue (it != end);
|
||||
@@ -233,7 +233,7 @@ void TextIteratorTest::testSwap()
|
||||
TextIterator it1(text, encoding);
|
||||
TextIterator it2(text, encoding);
|
||||
TextIterator end(text);
|
||||
|
||||
|
||||
assertTrue (it1 == it2);
|
||||
it2.swap(end);
|
||||
assertTrue (it1 != it2);
|
||||
|
@@ -35,12 +35,12 @@ public:
|
||||
++(*_count);
|
||||
_result = *_count;
|
||||
}
|
||||
|
||||
|
||||
int result()
|
||||
{
|
||||
return _result;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
int _n;
|
||||
int _result;
|
||||
@@ -82,7 +82,7 @@ void ThreadLocalTest::testLocality()
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
|
||||
|
||||
assertTrue (r1.result() == 5000);
|
||||
assertTrue (r2.result() == 7500);
|
||||
assertTrue (r3.result() == 6000);
|
||||
|
@@ -35,7 +35,6 @@ ThreadPoolTest::~ThreadPoolTest()
|
||||
void ThreadPoolTest::testThreadPool()
|
||||
{
|
||||
ThreadPool pool(2, 3, 3);
|
||||
pool.setStackSize(1);
|
||||
|
||||
assertTrue (pool.allocated() == 2);
|
||||
assertTrue (pool.used() == 0);
|
||||
@@ -76,7 +75,7 @@ void ThreadPoolTest::testThreadPool()
|
||||
{
|
||||
pool.start(ra);
|
||||
failmsg("thread pool exhausted - must throw exception");
|
||||
}
|
||||
}
|
||||
catch (Poco::NoThreadAvailableException&)
|
||||
{
|
||||
}
|
||||
@@ -84,17 +83,17 @@ void ThreadPoolTest::testThreadPool()
|
||||
{
|
||||
failmsg("wrong exception thrown");
|
||||
}
|
||||
|
||||
|
||||
_event.set(); // go!!!
|
||||
pool.joinAll();
|
||||
|
||||
|
||||
assertTrue (_count == 40000);
|
||||
|
||||
|
||||
assertTrue (pool.allocated() == 4);
|
||||
assertTrue (pool.used() == 0);
|
||||
assertTrue (pool.capacity() == 4);
|
||||
assertTrue (pool.available() == 4);
|
||||
|
||||
|
||||
Thread::sleep(4000);
|
||||
|
||||
pool.collect();
|
||||
@@ -102,7 +101,7 @@ void ThreadPoolTest::testThreadPool()
|
||||
assertTrue (pool.used() == 0);
|
||||
assertTrue (pool.capacity() == 4);
|
||||
assertTrue (pool.available() == 4);
|
||||
|
||||
|
||||
_count = 0;
|
||||
_event.reset();
|
||||
pool.start(ra);
|
||||
@@ -120,7 +119,7 @@ void ThreadPoolTest::testThreadPool()
|
||||
pool.joinAll();
|
||||
|
||||
assertTrue (_count == 20000);
|
||||
|
||||
|
||||
assertTrue (pool.allocated() == 2);
|
||||
assertTrue (pool.used() == 0);
|
||||
assertTrue (pool.capacity() == 4);
|
||||
|
@@ -22,6 +22,7 @@
|
||||
#define __EXTENSIONS__
|
||||
#endif
|
||||
#include <climits>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Thread;
|
||||
@@ -41,7 +42,11 @@ public:
|
||||
{
|
||||
Thread* pThread = Thread::current();
|
||||
if (pThread)
|
||||
{
|
||||
_threadName = pThread->name();
|
||||
auto *pThreadImpl = reinterpret_cast<Poco::ThreadImpl *>(pThread);
|
||||
_osThreadName = pThreadImpl->getOSThreadNameImpl();
|
||||
}
|
||||
_ran = true;
|
||||
_event.wait();
|
||||
}
|
||||
@@ -56,6 +61,11 @@ public:
|
||||
return _threadName;
|
||||
}
|
||||
|
||||
const std::string& osThreadName() const
|
||||
{
|
||||
return _osThreadName;
|
||||
}
|
||||
|
||||
void notify()
|
||||
{
|
||||
_event.set();
|
||||
@@ -71,6 +81,7 @@ public:
|
||||
private:
|
||||
bool _ran;
|
||||
std::string _threadName;
|
||||
std::string _osThreadName;
|
||||
Event _event;
|
||||
};
|
||||
|
||||
@@ -108,7 +119,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
bool _finished;
|
||||
std::atomic<bool> _finished;
|
||||
};
|
||||
|
||||
|
||||
@@ -140,8 +151,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
int _counter;
|
||||
bool _sleepy;
|
||||
std::atomic<int> _counter;
|
||||
std::atomic<bool> _sleepy;
|
||||
};
|
||||
|
||||
|
||||
@@ -168,6 +179,7 @@ void ThreadTest::testThread()
|
||||
assertTrue (!thread.isRunning());
|
||||
assertTrue (r.ran());
|
||||
assertTrue (!r.threadName().empty());
|
||||
assertTrue (!r.osThreadName().empty());
|
||||
}
|
||||
|
||||
|
||||
@@ -180,6 +192,19 @@ void ThreadTest::testNamedThread()
|
||||
thread.join();
|
||||
assertTrue (r.ran());
|
||||
assertTrue (r.threadName() == "MyThread");
|
||||
assertTrue (r.osThreadName() == r.threadName());
|
||||
|
||||
// name len > POCO_MAX_THREAD_NAME_LEN
|
||||
Thread thread2("0123456789aaaaaaaaaa9876543210");
|
||||
MyRunnable r2;
|
||||
thread2.start(r2);
|
||||
r2.notify();
|
||||
thread2.join();
|
||||
assertTrue (r2.ran());
|
||||
assertTrue (r2.osThreadName() == r2.threadName());
|
||||
assertTrue (r2.threadName().length() <= POCO_MAX_THREAD_NAME_LEN);
|
||||
assertTrue (std::string(r2.threadName(), 0, 7) == "0123456");
|
||||
assertTrue (std::string(r2.threadName(), r2.threadName().size() - 7) == "6543210");
|
||||
}
|
||||
|
||||
|
||||
@@ -447,6 +472,22 @@ void ThreadTest::testSleep()
|
||||
}
|
||||
|
||||
|
||||
void ThreadTest::testAffinity()
|
||||
{
|
||||
#if POCO_OS == POCO_OS_LINUX
|
||||
MyRunnable mr;
|
||||
Thread t;
|
||||
t.start(mr);
|
||||
assertTrue (t.setAffinity(0));
|
||||
assertEqual (t.getAffinity(), 0);
|
||||
mr.notify();
|
||||
t.join();
|
||||
#else
|
||||
std::cout << "not implemented";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void ThreadTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -475,6 +516,7 @@ CppUnit::Test* ThreadTest::suite()
|
||||
CppUnit_addTest(pSuite, ThreadTest, testThreadFunctor);
|
||||
CppUnit_addTest(pSuite, ThreadTest, testThreadStackSize);
|
||||
CppUnit_addTest(pSuite, ThreadTest, testSleep);
|
||||
CppUnit_addTest(pSuite, ThreadTest, testAffinity);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -38,6 +38,7 @@ public:
|
||||
void testThreadFunctor();
|
||||
void testThreadStackSize();
|
||||
void testSleep();
|
||||
void testAffinity();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
@@ -23,7 +23,7 @@ using Poco::Timestamp;
|
||||
using Poco::Clock;
|
||||
|
||||
|
||||
namespace
|
||||
namespace
|
||||
{
|
||||
class QTestNotification: public Notification
|
||||
{
|
||||
@@ -70,7 +70,7 @@ void TimedNotificationQueueTest::testDequeue()
|
||||
assertTrue (queue.empty());
|
||||
assertTrue (queue.size() == 0);
|
||||
pNf->release();
|
||||
|
||||
|
||||
Poco::Clock ts1;
|
||||
ts1 += 100000;
|
||||
Poco::Clock ts2;
|
||||
@@ -79,7 +79,7 @@ void TimedNotificationQueueTest::testDequeue()
|
||||
ts3 += 300000;
|
||||
Poco::Clock ts4;
|
||||
ts4 += 400000;
|
||||
|
||||
|
||||
queue.enqueueNotification(new QTestNotification("first"), ts1);
|
||||
queue.enqueueNotification(new QTestNotification("fourth"), ts4);
|
||||
queue.enqueueNotification(new QTestNotification("third"), ts3);
|
||||
@@ -87,7 +87,7 @@ void TimedNotificationQueueTest::testDequeue()
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 4);
|
||||
QTestNotification* pTNf = 0;
|
||||
while (!pTNf)
|
||||
while (!pTNf)
|
||||
{
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.dequeueNotification());
|
||||
}
|
||||
@@ -97,9 +97,9 @@ void TimedNotificationQueueTest::testDequeue()
|
||||
assertTrue (ts1.elapsed() >= 0);
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 3);
|
||||
|
||||
|
||||
pTNf = 0;
|
||||
while (!pTNf)
|
||||
while (!pTNf)
|
||||
{
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.dequeueNotification());
|
||||
}
|
||||
@@ -109,9 +109,9 @@ void TimedNotificationQueueTest::testDequeue()
|
||||
assertTrue (ts2.elapsed() >= 0);
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 2);
|
||||
|
||||
|
||||
pTNf = 0;
|
||||
while (!pTNf)
|
||||
while (!pTNf)
|
||||
{
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.dequeueNotification());
|
||||
}
|
||||
@@ -121,9 +121,9 @@ void TimedNotificationQueueTest::testDequeue()
|
||||
assertTrue (ts3.elapsed() >= 0);
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 1);
|
||||
|
||||
|
||||
pTNf = 0;
|
||||
while (!pTNf)
|
||||
while (!pTNf)
|
||||
{
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.dequeueNotification());
|
||||
}
|
||||
@@ -142,7 +142,7 @@ void TimedNotificationQueueTest::testDequeue()
|
||||
void TimedNotificationQueueTest::testWaitDequeue()
|
||||
{
|
||||
TimedNotificationQueue queue;
|
||||
|
||||
|
||||
Poco::Timestamp ts1;
|
||||
ts1 += 100000;
|
||||
Poco::Timestamp ts2;
|
||||
@@ -151,7 +151,7 @@ void TimedNotificationQueueTest::testWaitDequeue()
|
||||
ts3 += 300000;
|
||||
Poco::Timestamp ts4;
|
||||
ts4 += 400000;
|
||||
|
||||
|
||||
queue.enqueueNotification(new QTestNotification("first"), ts1);
|
||||
queue.enqueueNotification(new QTestNotification("fourth"), ts4);
|
||||
queue.enqueueNotification(new QTestNotification("third"), ts3);
|
||||
@@ -165,7 +165,7 @@ void TimedNotificationQueueTest::testWaitDequeue()
|
||||
assertTrue (ts1.elapsed() >= 0);
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 3);
|
||||
|
||||
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification());
|
||||
assertNotNullPtr(pTNf);
|
||||
assertTrue (pTNf->data() == "second");
|
||||
@@ -173,7 +173,7 @@ void TimedNotificationQueueTest::testWaitDequeue()
|
||||
assertTrue (ts2.elapsed() >= 0);
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 2);
|
||||
|
||||
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification());
|
||||
assertNotNullPtr(pTNf);
|
||||
assertTrue (pTNf->data() == "third");
|
||||
@@ -181,7 +181,7 @@ void TimedNotificationQueueTest::testWaitDequeue()
|
||||
assertTrue (ts3.elapsed() >= 0);
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 1);
|
||||
|
||||
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification());
|
||||
assertNotNullPtr(pTNf);
|
||||
assertTrue (pTNf->data() == "fourth");
|
||||
@@ -195,7 +195,7 @@ void TimedNotificationQueueTest::testWaitDequeue()
|
||||
void TimedNotificationQueueTest::testWaitDequeueTimeout()
|
||||
{
|
||||
TimedNotificationQueue queue;
|
||||
|
||||
|
||||
Poco::Timestamp ts1;
|
||||
ts1 += 200000;
|
||||
Poco::Timestamp ts2;
|
||||
@@ -204,7 +204,7 @@ void TimedNotificationQueueTest::testWaitDequeueTimeout()
|
||||
ts3 += 600000;
|
||||
Poco::Timestamp ts4;
|
||||
ts4 += 800000;
|
||||
|
||||
|
||||
queue.enqueueNotification(new QTestNotification("first"), ts1);
|
||||
queue.enqueueNotification(new QTestNotification("fourth"), ts4);
|
||||
queue.enqueueNotification(new QTestNotification("third"), ts3);
|
||||
@@ -222,7 +222,7 @@ void TimedNotificationQueueTest::testWaitDequeueTimeout()
|
||||
assertTrue (ts1.elapsed() >= 0);
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 3);
|
||||
|
||||
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification(220));
|
||||
assertNotNullPtr(pTNf);
|
||||
assertTrue (pTNf->data() == "second");
|
||||
@@ -230,7 +230,7 @@ void TimedNotificationQueueTest::testWaitDequeueTimeout()
|
||||
assertTrue (ts2.elapsed() >= 0);
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 2);
|
||||
|
||||
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification(220));
|
||||
assertNotNullPtr(pTNf);
|
||||
assertTrue (pTNf->data() == "third");
|
||||
@@ -238,7 +238,7 @@ void TimedNotificationQueueTest::testWaitDequeueTimeout()
|
||||
assertTrue (ts3.elapsed() >= 0);
|
||||
assertTrue (!queue.empty());
|
||||
assertTrue (queue.size() == 1);
|
||||
|
||||
|
||||
pTNf = dynamic_cast<QTestNotification*>(queue.waitDequeueNotification(220));
|
||||
assertNotNullPtr(pTNf);
|
||||
assertTrue (pTNf->data() == "fourth");
|
||||
|
@@ -52,7 +52,7 @@ void TimerTest::testTimer()
|
||||
_event.wait();
|
||||
sw.stop();
|
||||
assertTrue (sw.elapsed() >= 180000 && sw.elapsed() < 250000);
|
||||
t.stop();
|
||||
t.stop();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -38,13 +38,13 @@ void TimespanTest::testConversions()
|
||||
assertTrue (ts.totalMinutes() == 60*24);
|
||||
assertTrue (ts.totalHours() == 24);
|
||||
assertTrue (ts.days() == 1);
|
||||
|
||||
|
||||
assertTrue (ts.microseconds() == 0);
|
||||
assertTrue (ts.milliseconds() == 0);
|
||||
assertTrue (ts.seconds() == 0);
|
||||
assertTrue (ts.minutes() == 0);
|
||||
assertTrue (ts.hours() == 0);
|
||||
|
||||
|
||||
ts.assign(2, 12, 30, 10, 123456);
|
||||
assertTrue (ts.microseconds() == 456);
|
||||
assertTrue (ts.milliseconds() == 123);
|
||||
@@ -70,6 +70,10 @@ void TimespanTest::testConversions()
|
||||
assertTrue (ts.minutes() == 30);
|
||||
assertTrue (ts.hours() == 12);
|
||||
assertTrue (ts.days() == 1);
|
||||
|
||||
ts.assign(std::chrono::minutes(62));
|
||||
assertTrue(ts.hours() == 1);
|
||||
assertTrue(ts.minutes() == 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,21 +82,21 @@ void TimespanTest::testComparisons()
|
||||
Timespan ts1(10000000);
|
||||
Timespan ts2(20000000);
|
||||
Timespan ts3(20000000);
|
||||
|
||||
|
||||
assertTrue (ts1 != ts2);
|
||||
assertTrue (!(ts1 == ts2));
|
||||
assertTrue (ts1 <= ts2);
|
||||
assertTrue (ts1 < ts2);
|
||||
assertTrue (ts2 > ts1);
|
||||
assertTrue (ts2 >= ts1);
|
||||
|
||||
|
||||
assertTrue (ts2 == ts3);
|
||||
assertTrue (!(ts2 != ts3));
|
||||
assertTrue (ts2 >= ts3);
|
||||
assertTrue (ts2 <= ts3);
|
||||
assertTrue (!(ts2 > ts3));
|
||||
assertTrue (!(ts2 < ts3));
|
||||
|
||||
|
||||
assertTrue (ts1 == 10000000);
|
||||
assertTrue (ts1 != 20000000);
|
||||
assertTrue (ts1 <= 10000000);
|
||||
@@ -128,7 +132,7 @@ void TimespanTest::testSwap()
|
||||
{
|
||||
Timespan ts1(10000000);
|
||||
Timespan ts2(50000000);
|
||||
|
||||
|
||||
assertTrue (ts1 < ts2);
|
||||
ts1.swap(ts2);
|
||||
assertTrue (ts2 < ts1);
|
||||
|
@@ -47,26 +47,26 @@ void TimestampTest::testTimestamp()
|
||||
assertTrue (t2 <= t3);
|
||||
Timestamp::TimeDiff d = (t2 - t1);
|
||||
assertTrue (d >= 180000 && d <= 300000);
|
||||
|
||||
|
||||
t1.swap(t2);
|
||||
assertTrue (t1 > t2);
|
||||
t2.swap(t1);
|
||||
|
||||
|
||||
Timestamp::UtcTimeVal tv = t1.utcTime();
|
||||
Timestamp t4 = Timestamp::fromUtcTime(tv);
|
||||
assertTrue (t1 == t4);
|
||||
|
||||
|
||||
Timestamp epoch(0);
|
||||
tv = epoch.utcTime();
|
||||
assertTrue (tv >> 32 == 0x01B21DD2);
|
||||
assertTrue ((tv & 0xFFFFFFFF) == 0x13814000);
|
||||
|
||||
|
||||
Timestamp now;
|
||||
Thread::sleep(201);
|
||||
assertTrue (now.elapsed() >= 200000);
|
||||
assertTrue (now.isElapsed(200000));
|
||||
assertTrue (!now.isElapsed(2000000));
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
{
|
||||
Timestamp now;
|
||||
|
@@ -60,7 +60,7 @@ void TuplesTest::testTuple1()
|
||||
assertTrue (t.length == 1);
|
||||
t.set<0>(-1);
|
||||
assertTrue (t.get<0>() == -1);
|
||||
|
||||
|
||||
Tuple<int> t2(-1);
|
||||
assertTrue (t2.get<0>() == -1);
|
||||
|
||||
@@ -228,7 +228,7 @@ void TuplesTest::testTuple6()
|
||||
{
|
||||
Tuple<std::string, int, bool, float, char, long> aTuple;
|
||||
assertTrue (aTuple.length == 6);
|
||||
Tuple<std::string, int, bool, float, char, long>
|
||||
Tuple<std::string, int, bool, float, char, long>
|
||||
aTuple2("1", 1, true, 3.14f, 'c', 999);
|
||||
assertTrue (aTuple != aTuple2);
|
||||
aTuple = aTuple2;
|
||||
@@ -242,7 +242,7 @@ void TuplesTest::testTuple7()
|
||||
{
|
||||
Tuple<std::string, int, bool, float, char, long, double> aTuple;
|
||||
assertTrue (aTuple.length == 7);
|
||||
Tuple<std::string, int, bool, float, char, long, double>
|
||||
Tuple<std::string, int, bool, float, char, long, double>
|
||||
aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14);
|
||||
assertTrue (aTuple != aTuple2);
|
||||
aTuple = aTuple2;
|
||||
@@ -256,7 +256,7 @@ void TuplesTest::testTuple8()
|
||||
{
|
||||
Tuple<std::string, int, bool, float, char, long, double, short> aTuple;
|
||||
assertTrue (aTuple.length == 8);
|
||||
Tuple<std::string, int, bool, float, char, long, double, short>
|
||||
Tuple<std::string, int, bool, float, char, long, double, short>
|
||||
aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700);
|
||||
assertTrue (aTuple != aTuple2);
|
||||
aTuple = aTuple2;
|
||||
@@ -269,7 +269,7 @@ void TuplesTest::testTuple9()
|
||||
{
|
||||
Tuple<std::string, int, bool, float, char, long, double, short, std::string> aTuple;
|
||||
assertTrue (aTuple.length == 9);
|
||||
Tuple<std::string, int, bool, float, char, long, double, short, std::string>
|
||||
Tuple<std::string, int, bool, float, char, long, double, short, std::string>
|
||||
aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2");
|
||||
assertTrue (aTuple != aTuple2);
|
||||
aTuple = aTuple2;
|
||||
@@ -296,7 +296,7 @@ void TuplesTest::testTuple10()
|
||||
|
||||
void TuplesTest::testTuple11()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
@@ -312,7 +312,7 @@ void TuplesTest::testTuple11()
|
||||
|
||||
void TuplesTest::testTuple12()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
@@ -328,7 +328,7 @@ void TuplesTest::testTuple12()
|
||||
|
||||
void TuplesTest::testTuple13()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int, bool> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
@@ -344,7 +344,7 @@ void TuplesTest::testTuple13()
|
||||
|
||||
void TuplesTest::testTuple14()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int, bool, float> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
@@ -360,7 +360,7 @@ void TuplesTest::testTuple14()
|
||||
|
||||
void TuplesTest::testTuple15()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int, bool, float, char> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
@@ -376,7 +376,7 @@ void TuplesTest::testTuple15()
|
||||
|
||||
void TuplesTest::testTuple16()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int, bool, float, char, long> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
@@ -392,7 +392,7 @@ void TuplesTest::testTuple16()
|
||||
|
||||
void TuplesTest::testTuple17()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int, bool, float, char, long, double> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
@@ -408,7 +408,7 @@ void TuplesTest::testTuple17()
|
||||
|
||||
void TuplesTest::testTuple18()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int, bool, float, char, long, double, short> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
@@ -424,7 +424,7 @@ void TuplesTest::testTuple18()
|
||||
|
||||
void TuplesTest::testTuple19()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int, bool, float, char, long, double, short, std::string> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
@@ -440,12 +440,12 @@ void TuplesTest::testTuple19()
|
||||
|
||||
void TuplesTest::testTuple20()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int, bool, float, char, long, double, short, std::string, int> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 20);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2,
|
||||
"1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2);
|
||||
assertTrue (aTuple != aTuple2);
|
||||
@@ -464,7 +464,7 @@ void TuplesTest::testTuple21()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 21);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5");
|
||||
@@ -486,7 +486,7 @@ void TuplesTest::testTuple22()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 22);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5);
|
||||
@@ -508,7 +508,7 @@ void TuplesTest::testTuple23()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 23);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true);
|
||||
@@ -530,7 +530,7 @@ void TuplesTest::testTuple24()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 24);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f);
|
||||
@@ -552,7 +552,7 @@ void TuplesTest::testTuple25()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 25);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c');
|
||||
@@ -574,7 +574,7 @@ void TuplesTest::testTuple26()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 26);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999);
|
||||
@@ -596,7 +596,7 @@ void TuplesTest::testTuple27()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 27);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14);
|
||||
@@ -618,7 +618,7 @@ void TuplesTest::testTuple28()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 28);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700);
|
||||
@@ -640,7 +640,7 @@ void TuplesTest::testTuple29()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 29);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6");
|
||||
@@ -662,7 +662,7 @@ void TuplesTest::testTuple30()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 30);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6);
|
||||
@@ -685,7 +685,7 @@ void TuplesTest::testTuple31()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 31);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -709,7 +709,7 @@ void TuplesTest::testTuple32()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 32);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -733,7 +733,7 @@ void TuplesTest::testTuple33()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 33);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -757,7 +757,7 @@ void TuplesTest::testTuple34()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 34);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -781,7 +781,7 @@ void TuplesTest::testTuple35()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 35);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -805,7 +805,7 @@ void TuplesTest::testTuple36()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 36);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -829,7 +829,7 @@ void TuplesTest::testTuple37()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 37);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -853,7 +853,7 @@ void TuplesTest::testTuple38()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 38);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -877,7 +877,7 @@ void TuplesTest::testTuple39()
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 39);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -938,7 +938,7 @@ void TuplesTest::testTuple40()
|
||||
assertTrue (aTuple.get<38>() == "");
|
||||
assertTrue (aTuple.get<39>() == 0);
|
||||
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'a', 999, 33.14, 32700, "2", 2,
|
||||
"3", 3, true, 3.14f, 'b', 999, 33.14, 32700, "4", 4,
|
||||
"5", 5, true, 3.14f, 'c', 999, 33.14, 32700, "6", 6,
|
||||
@@ -1063,12 +1063,12 @@ void TuplesTest::testTuple40()
|
||||
|
||||
void TuplesTest::testTupleOrder()
|
||||
{
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
|
||||
std::string, int, bool, float, char, long, double, short, std::string, int> TupleType;
|
||||
|
||||
TupleType aTuple;
|
||||
assertTrue (aTuple.length == 20);
|
||||
|
||||
|
||||
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2);
|
||||
assertTrue (aTuple != aTuple2);
|
||||
aTuple = aTuple2;
|
||||
@@ -1093,7 +1093,7 @@ void TuplesTest::testTupleOrder()
|
||||
assertTrue (tv[2] == aTuple2);
|
||||
|
||||
std::sort(tv.begin(), tv.end());
|
||||
|
||||
|
||||
assertTrue (tv[0] == aTuple);
|
||||
assertTrue (tv[1] == aTuple2);
|
||||
assertTrue (tv[2] == aTuple3);
|
||||
|
@@ -247,7 +247,7 @@ const int i = 0;
|
||||
assertTrue (typeid(TypeGetter<37, TypeVoid>::HeadType) == typeid(Void));
|
||||
assertTrue (typeid(TypeGetter<38, TypeVoid>::HeadType) == typeid(Void));
|
||||
assertTrue (typeid(TypeGetter<39, TypeVoid>::HeadType) == typeid(Void));
|
||||
|
||||
|
||||
|
||||
typedef TypeOneReplacer<TypeVoid, Void, Int8>::HeadType TypeFirstReplacer;
|
||||
assertTrue (typeid(TypeGetter<0, TypeFirstReplacer>::HeadType) == typeid(Int8));
|
||||
|
@@ -35,7 +35,7 @@ namespace
|
||||
StringStreamFactory()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::istream* open(const URI& uri)
|
||||
{
|
||||
return new std::istringstream(uri.toString());
|
||||
@@ -62,12 +62,12 @@ void URIStreamOpenerTest::testStreamOpenerFile()
|
||||
assertTrue (ostr.good());
|
||||
ostr << "Hello, world!" << std::endl;
|
||||
ostr.close();
|
||||
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("file");
|
||||
uri.setPath(Path(path).toString(Path::PATH_UNIX));
|
||||
std::string uriString = uri.toString();
|
||||
|
||||
|
||||
URIStreamOpener opener;
|
||||
std::istream* istr = opener.open(uri);
|
||||
assertTrue (istr != 0);
|
||||
@@ -84,10 +84,10 @@ void URIStreamOpenerTest::testStreamOpenerRelative()
|
||||
assertTrue (ostr.good());
|
||||
ostr << "Hello, world!" << std::endl;
|
||||
ostr.close();
|
||||
|
||||
|
||||
URI uri(Path(path).toString(Path::PATH_UNIX));
|
||||
std::string uriString = uri.toString();
|
||||
|
||||
|
||||
URIStreamOpener opener;
|
||||
std::istream* istr = opener.open(uri);
|
||||
assertTrue (istr != 0);
|
||||
@@ -104,12 +104,12 @@ void URIStreamOpenerTest::testStreamOpenerURI()
|
||||
assertTrue (ostr.good());
|
||||
ostr << "Hello, world!" << std::endl;
|
||||
ostr.close();
|
||||
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("file");
|
||||
uri.setPath(Path(path).toString(Path::PATH_UNIX));
|
||||
std::string uriString = uri.toString();
|
||||
|
||||
|
||||
URIStreamOpener opener;
|
||||
std::istream* istr = opener.open(uriString);
|
||||
assertTrue (istr != 0);
|
||||
@@ -126,16 +126,16 @@ void URIStreamOpenerTest::testStreamOpenerURIResolve()
|
||||
assertTrue (ostr.good());
|
||||
ostr << "Hello, world!" << std::endl;
|
||||
ostr.close();
|
||||
|
||||
|
||||
Path p(path);
|
||||
p.makeAbsolute();
|
||||
Path parent(p.parent());
|
||||
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("file");
|
||||
uri.setPath(parent.toString(Path::PATH_UNIX));
|
||||
std::string uriString = uri.toString();
|
||||
|
||||
|
||||
URIStreamOpener opener;
|
||||
std::istream* istr = opener.open(uriString, p.getFileName());
|
||||
assertTrue (istr != 0);
|
||||
@@ -152,7 +152,7 @@ void URIStreamOpenerTest::testStreamOpenerPath()
|
||||
assertTrue (ostr.good());
|
||||
ostr << "Hello, world!" << std::endl;
|
||||
ostr.close();
|
||||
|
||||
|
||||
URIStreamOpener opener;
|
||||
std::istream* istr = opener.open(path);
|
||||
assertTrue (istr != 0);
|
||||
@@ -169,11 +169,11 @@ void URIStreamOpenerTest::testStreamOpenerPathResolve()
|
||||
assertTrue (ostr.good());
|
||||
ostr << "Hello, world!" << std::endl;
|
||||
ostr.close();
|
||||
|
||||
|
||||
Path p(path);
|
||||
Path parent(p.parent());
|
||||
std::string base = parent.toString();
|
||||
|
||||
|
||||
URIStreamOpener opener;
|
||||
std::istream* istr = opener.open(base, p.getFileName());
|
||||
assertTrue (istr != 0);
|
||||
|
48
vendor/POCO/Foundation/testsuite/src/URITest.cpp
vendored
48
vendor/POCO/Foundation/testsuite/src/URITest.cpp
vendored
@@ -743,6 +743,7 @@ void URITest::testOther()
|
||||
assertTrue (uri.getQuery() == "q=hello%world");
|
||||
assertTrue (uri.getRawQuery() == "q=hello%25world");
|
||||
assertTrue (uri.getFragment() == "frag ment");
|
||||
assertTrue (uri.getRawFragment() == "frag%20ment");
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=hello%25world#frag%20ment");
|
||||
assertTrue (uri.getPathEtc() == "/search?q=hello%25world#frag%20ment");
|
||||
|
||||
@@ -783,8 +784,20 @@ void URITest::testOther()
|
||||
assertTrue (uri.getQuery() == "q=hello+world");
|
||||
assertTrue (uri.getRawQuery() == "q=hello+world");
|
||||
assertTrue (uri.getFragment() == "frag ment");
|
||||
assertTrue (uri.getRawFragment() == "frag%20ment");
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=hello+world#frag%20ment");
|
||||
assertTrue (uri.getPathEtc() == "/search?q=hello+world#frag%20ment");
|
||||
|
||||
uri.setFragment("foo/bar");
|
||||
assertTrue (uri.getFragment() == "foo/bar");
|
||||
assertTrue (uri.getRawFragment() == "foo/bar");
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=hello+world#foo/bar");
|
||||
assertTrue (uri.getPathEtc() == "/search?q=hello+world#foo/bar");
|
||||
uri.setRawFragment("foo%2Fbar");
|
||||
assertTrue (uri.getFragment() == "foo/bar");
|
||||
assertTrue (uri.getRawFragment() == "foo%2Fbar");
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=hello+world#foo%2Fbar");
|
||||
assertTrue (uri.getPathEtc() == "/search?q=hello+world#foo%2Fbar");
|
||||
}
|
||||
|
||||
|
||||
@@ -858,6 +871,40 @@ void URITest::testQueryParameters()
|
||||
}
|
||||
|
||||
|
||||
void URITest::testQueryParametersPlus()
|
||||
{
|
||||
Poco::URI uri("http://google.com/search?q=hello+world&client=safari");
|
||||
URI::QueryParameters params = uri.getQueryParameters(false);
|
||||
assertTrue (params.size() == 2);
|
||||
assertTrue (params[0].first == "q");
|
||||
assertTrue (params[0].second == "hello+world");
|
||||
assertTrue (params[1].first == "client");
|
||||
assertTrue (params[1].second == "safari");
|
||||
|
||||
uri.setQueryParameters(params);
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=hello%2Bworld&client=safari");
|
||||
|
||||
uri = "http://google.com/search?q=&client&";
|
||||
params = uri.getQueryParameters();
|
||||
assertTrue (params.size() == 2);
|
||||
assertTrue (params[0].first == "q");
|
||||
assertTrue (params[0].second == "");
|
||||
assertTrue (params[1].first == "client");
|
||||
assertTrue (params[1].second == "");
|
||||
|
||||
uri.setQueryParameters(params);
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=&client=");
|
||||
|
||||
params[0].second = "foo/bar?";
|
||||
uri.setQueryParameters(params);
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=foo%2Fbar%3F&client=");
|
||||
|
||||
params[0].second = "foo&bar";
|
||||
uri.setQueryParameters(params);
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=foo%26bar&client=");
|
||||
}
|
||||
|
||||
|
||||
void URITest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -883,6 +930,7 @@ CppUnit::Test* URITest::suite()
|
||||
CppUnit_addTest(pSuite, URITest, testOther);
|
||||
CppUnit_addTest(pSuite, URITest, testFromPath);
|
||||
CppUnit_addTest(pSuite, URITest, testQueryParameters);
|
||||
CppUnit_addTest(pSuite, URITest, testQueryParametersPlus);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ public:
|
||||
void testOther();
|
||||
void testFromPath();
|
||||
void testQueryParameters();
|
||||
void testQueryParametersPlus();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user