mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-24 06:04:15 +01:00
Merge remote-tracking branch 'origin/ip-address-soo' into develop
This commit is contained in:
@@ -122,7 +122,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_DEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@@ -152,7 +152,7 @@
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;NDEBUG;_WINDOWS;WINVER=0x0500;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
@@ -185,7 +185,7 @@
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
@@ -214,7 +214,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@@ -240,7 +240,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_DEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@@ -270,7 +270,7 @@
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;NDEBUG;_WINDOWS;WINVER=0x0500;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
@@ -85,7 +85,7 @@
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;WINVER=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_DEBUG;_WINDOWS;WINVER=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@@ -146,7 +146,7 @@
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;WINVER=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;NDEBUG;_WINDOWS;WINVER=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
@@ -180,7 +180,7 @@
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;WINVER=0x0600;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;NDEBUG;_WINDOWS;WINVER=0x0600;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
@@ -211,7 +211,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;WINVER=0x0600;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_DEBUG;_WINDOWS;WINVER=0x0600;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@@ -238,7 +238,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;WINVER=0x0600;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_DEBUG;_WINDOWS;WINVER=0x0600;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@@ -270,7 +270,7 @@
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>..\include;..\..\CppUnit\include;..\..\CppUnit\WinTestRunner\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;WINVER=0x0600;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;NDEBUG;_WINDOWS;WINVER=0x0600;POCO_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||
|
||||
@@ -70,8 +70,170 @@ AnyTest::~AnyTest()
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testDefaultCtor()
|
||||
{
|
||||
const Any value;
|
||||
|
||||
assert (value.empty());
|
||||
assert (0 == AnyCast<int>(&value));
|
||||
assert (value.type() == typeid(void));
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testConvertingCtor()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any value = text;
|
||||
|
||||
assert (!value.empty());
|
||||
assert (value.type() == typeid(std::string));
|
||||
assert (0 == AnyCast<int>(&value));
|
||||
assert (0 != AnyCast<std::string>(&value));
|
||||
assert (AnyCast<std::string>(value) == text);
|
||||
assert (AnyCast<std::string>(&value) != &text);
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testCopyCtor()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any original = text, copy = original;
|
||||
|
||||
assert (!copy.empty());
|
||||
assert (original.type() == copy.type());
|
||||
assert (AnyCast<std::string>(original) == AnyCast<std::string>(copy));
|
||||
assert (text == AnyCast<std::string>(copy));
|
||||
assert (AnyCast<std::string>(&original) != AnyCast<std::string>(©));
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testCopyAssign()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any original = text, copy;
|
||||
Any* assignResult = &(copy = original);
|
||||
|
||||
assert (!copy.empty());
|
||||
assert (original.type() == copy.type());
|
||||
assert (AnyCast<std::string>(original) == AnyCast<std::string>(copy));
|
||||
assert (text == AnyCast<std::string>(copy));
|
||||
assert (AnyCast<std::string>(&original) != AnyCast<std::string>(©));
|
||||
assert (assignResult == ©);
|
||||
|
||||
// test self assignment
|
||||
Any& ref = original;
|
||||
original = ref;
|
||||
assert (AnyCast<std::string>(original) == AnyCast<std::string>(copy));
|
||||
original = original;
|
||||
assert (AnyCast<std::string>(original) == AnyCast<std::string>(copy));
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testConvertingAssign()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any value;
|
||||
Any* assignResult = &(value = text);
|
||||
|
||||
assert (!value.empty());
|
||||
assert (value.type() == typeid(std::string));
|
||||
assert (0 == AnyCast<int>(&value));
|
||||
assert (0 != AnyCast<std::string>(&value));
|
||||
assert (AnyCast<std::string>(value) == text);
|
||||
assert (AnyCast<std::string>(&value) != &text);
|
||||
assert (assignResult == &value);
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testCastToReference()
|
||||
{
|
||||
Any a(137);
|
||||
const Any b(a);
|
||||
|
||||
int& ra = AnyCast<int &>(a);
|
||||
int const& ra_c = AnyCast<int const &>(a);
|
||||
int volatile& ra_v = AnyCast<int volatile &>(a);
|
||||
int const volatile& ra_cv = AnyCast<int const volatile&>(a);
|
||||
|
||||
// cv references to same obj
|
||||
assert (&ra == &ra_c && &ra == &ra_v && &ra == &ra_cv);
|
||||
|
||||
int const & rb_c = AnyCast<int const &>(b);
|
||||
int const volatile & rb_cv = AnyCast<int const volatile &>(b);
|
||||
|
||||
assert (&rb_c == &rb_cv); // cv references to copied const obj
|
||||
assert (&ra != &rb_c); // copies hold different objects
|
||||
|
||||
++ra;
|
||||
int incremented = AnyCast<int>(a);
|
||||
assert (incremented == 138); // increment by reference changes value
|
||||
|
||||
try
|
||||
{
|
||||
AnyCast<char &>(a);
|
||||
failmsg ("AnyCast to incorrect reference type");
|
||||
}
|
||||
catch (BadCastException&) { }
|
||||
|
||||
try
|
||||
{
|
||||
AnyCast<const char &>(b),
|
||||
failmsg ("AnyCast to incorrect const reference type");
|
||||
}
|
||||
catch (BadCastException&) { }
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testBadCast()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any value = text;
|
||||
|
||||
try
|
||||
{
|
||||
AnyCast<const char *>(value);
|
||||
fail ("must throw");
|
||||
}
|
||||
catch (BadCastException&) { }
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testSwap()
|
||||
{
|
||||
std::string text = "test message";
|
||||
Any original = text, swapped;
|
||||
std::string* originalPtr = AnyCast<std::string>(&original);
|
||||
Any* swapResult = &original.swap(swapped);
|
||||
|
||||
assert (original.empty());
|
||||
assert (!swapped.empty());
|
||||
assert (swapped.type() == typeid(std::string));
|
||||
assert (text == AnyCast<std::string>(swapped));
|
||||
assert (0 != originalPtr);
|
||||
#ifdef POCO_NO_SOO // pointers only match when heap-allocated
|
||||
assert (originalPtr == AnyCast<std::string>(&swapped));
|
||||
#endif
|
||||
assert (swapResult == &original);
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testEmptyCopy()
|
||||
{
|
||||
const Any null;
|
||||
Any copied = null, assigned;
|
||||
assigned = null;
|
||||
|
||||
assert (null.empty());
|
||||
assert (copied.empty());
|
||||
assert (assigned.empty());
|
||||
}
|
||||
|
||||
|
||||
void AnyTest::testInt()
|
||||
{
|
||||
Any e;
|
||||
assert (e.empty());
|
||||
|
||||
Any a = 13;
|
||||
assert (a.type() == typeid(int));
|
||||
int* i = AnyCast<int>(&a);
|
||||
@@ -116,8 +278,13 @@ void AnyTest::testVector()
|
||||
Any a = tmp;
|
||||
assert (a.type() == typeid(std::vector<int>));
|
||||
std::vector<int> tmp2 = AnyCast<std::vector<int> >(a);
|
||||
assert (tmp2.size() == 3);
|
||||
const std::vector<int>& vecCRef = RefAnyCast<std::vector<int> >(a);
|
||||
std::vector<int>& vecRef = RefAnyCast<std::vector<int> >(a);
|
||||
|
||||
assert (vecRef[0] == 1);
|
||||
assert (vecRef[1] == 2);
|
||||
assert (vecRef[2] == 3);
|
||||
vecRef[0] = 0;
|
||||
assert (vecRef[0] == vecCRef[0]);
|
||||
}
|
||||
@@ -137,6 +304,15 @@ 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);
|
||||
|
||||
@@ -45,6 +45,16 @@ 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 testInt();
|
||||
void testComplexType();
|
||||
void testVector();
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "Poco/Ascii.h"
|
||||
#include "Poco/BasicEvent.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include "Poco/SmallObjectAllocator.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@@ -64,6 +65,7 @@ using Poco::AtomicCounter;
|
||||
using Poco::Nullable;
|
||||
using Poco::Ascii;
|
||||
using Poco::BasicEvent;
|
||||
using Poco::SmallObjectAllocator;
|
||||
using Poco::delegate;
|
||||
using Poco::NullType;
|
||||
using Poco::InvalidAccessException;
|
||||
@@ -96,6 +98,37 @@ namespace
|
||||
}
|
||||
|
||||
|
||||
class Small
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
struct Parent
|
||||
{
|
||||
Parent() { i = -1; }
|
||||
virtual ~Parent() { i= -2; }
|
||||
|
||||
static int i;
|
||||
};
|
||||
|
||||
|
||||
int Parent::i = 0;
|
||||
|
||||
|
||||
struct Medium : public Parent
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct Large
|
||||
{
|
||||
Large() : i(1), j(2), k(3), l(4) { }
|
||||
long i,j,k;
|
||||
const long l;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// The bugcheck test is normally disabled, as it
|
||||
// causes a break into the debugger.
|
||||
@@ -1031,6 +1064,137 @@ void CoreTest::testAscii()
|
||||
}
|
||||
|
||||
|
||||
void CoreTest::testSmallObjectAllocator()
|
||||
{
|
||||
{
|
||||
SmallObjectAllocator<int> soa1;
|
||||
assert (!soa1.isOnHeap());
|
||||
int& i = soa1.get();
|
||||
i = 42;
|
||||
int j = i;
|
||||
assert (j == 42);
|
||||
int* pi = &i;
|
||||
assert (*pi == 42);
|
||||
*pi = 24;
|
||||
assert (i == 24);
|
||||
SmallObjectAllocator<int> soa2(soa1);
|
||||
assert (soa1.get() == soa2.get());
|
||||
assert (soa2.get() == 24);
|
||||
|
||||
SmallObjectAllocator<int> soa3;
|
||||
soa3 = soa2;
|
||||
assert (soa3.get() == soa2.get());
|
||||
assert (soa3.get() == 24);
|
||||
}
|
||||
{
|
||||
// force heap alloc
|
||||
SmallObjectAllocator<int, 1> soa1;
|
||||
assert (soa1.isOnHeap());
|
||||
int& i = soa1.get();
|
||||
i = 42;
|
||||
int j = i;
|
||||
assert (j == 42);
|
||||
int* pi = &i;
|
||||
assert (*pi == 42);
|
||||
*pi = 24;
|
||||
assert (i == 24);
|
||||
SmallObjectAllocator<int, 1> soa2(soa1);
|
||||
assert (soa1.get() == soa2.get());
|
||||
assert (soa2.get() == 24);
|
||||
|
||||
SmallObjectAllocator<int, 1> soa3;
|
||||
soa3 = soa2;
|
||||
assert (soa3.get() == soa2.get());
|
||||
assert (soa3.get() == 24);
|
||||
}
|
||||
|
||||
SmallObjectAllocator<Small> soa2;
|
||||
assert (!soa2.isOnHeap());
|
||||
|
||||
{
|
||||
assert (Parent::i == 0);
|
||||
SmallObjectAllocator<Medium> soa3;
|
||||
assert (!soa3.isOnHeap());
|
||||
assert (Parent::i == -1);
|
||||
}
|
||||
assert (Parent::i == -2);
|
||||
|
||||
{
|
||||
typedef SmallObjectAllocator<Large, 4> LargeType;
|
||||
LargeType soa4;
|
||||
assert (soa4.isOnHeap());
|
||||
Large large = soa4.get();
|
||||
assert (large.i == 1);
|
||||
assert (large.j == 2);
|
||||
assert (large.k == 3);
|
||||
|
||||
const LargeType soa5;
|
||||
assert (soa5.get().l == 4);
|
||||
}
|
||||
|
||||
Parent::i = 0; // only to make sure subsequent runs don't fail
|
||||
|
||||
SmallObjectAllocator<char*> soa6(2);
|
||||
assert (!soa6.isOnHeap());
|
||||
char* pC2 = soa6.get();
|
||||
pC2[0] = 'x';
|
||||
pC2[1] = '\0';
|
||||
std::string str2(pC2);
|
||||
assert (str2 == "x");
|
||||
|
||||
std::size_t sz = POCO_SMALL_OBJECT_SIZE + 1;
|
||||
Poco::SmallStringAllocator soa7(sz);
|
||||
assert (soa7.isOnHeap());
|
||||
char* pC = soa7.get();
|
||||
char c = '0';
|
||||
int i = 0;
|
||||
|
||||
// test this only for default values
|
||||
if (POCO_SMALL_OBJECT_SIZE == 15)
|
||||
{
|
||||
for (i = 0; i < sz - 1; ++i)
|
||||
pC[i] = c++;
|
||||
pC[i] = '\0';
|
||||
std::string str(pC);
|
||||
assert (str == "0123456789:;<=>");
|
||||
|
||||
Poco::SmallStringAllocator soa7("0123456789:;<=>");
|
||||
assert (str == soa7.get());
|
||||
|
||||
soa7 = "";
|
||||
assert (soa7.get()[0] == '\0');
|
||||
soa7 = "0123456789:;<=>";
|
||||
assert (str == soa7.get());
|
||||
}
|
||||
else if (POCO_SMALL_OBJECT_SIZE == 7)
|
||||
{
|
||||
for (i = 0; i < sz - 1; ++i)
|
||||
pC[i] = c++;
|
||||
pC[i] = '\0';
|
||||
std::string str(pC);
|
||||
assert (str == "0123456");
|
||||
|
||||
Poco::SmallStringAllocator soa7("0123456");
|
||||
assert (str == soa7.get());
|
||||
|
||||
soa7 = "";
|
||||
assert (soa7.get()[0] == '\0');
|
||||
soa7 = "0123456";
|
||||
assert (str == soa7.get());
|
||||
}
|
||||
|
||||
std::string str("0123456789");
|
||||
Poco::SmallObjectAllocator<std::string> soa8(str);
|
||||
assert (!soa8.isOnHeap());
|
||||
assert(soa8.get() == str);
|
||||
|
||||
Poco::SmallObjectAllocator<std::string, 1> soa9;
|
||||
assert (soa9.isOnHeap());
|
||||
soa9 = str;
|
||||
assert(soa9.get() == str);
|
||||
}
|
||||
|
||||
|
||||
void CoreTest::onReadable(bool& b)
|
||||
{
|
||||
if (b) ++_notToReadable;
|
||||
@@ -1074,6 +1238,7 @@ CppUnit::Test* CoreTest::suite()
|
||||
CppUnit_addTest(pSuite, CoreTest, testAtomicCounter);
|
||||
CppUnit_addTest(pSuite, CoreTest, testNullable);
|
||||
CppUnit_addTest(pSuite, CoreTest, testAscii);
|
||||
CppUnit_addTest(pSuite, CoreTest, testSmallObjectAllocator);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public:
|
||||
void testAtomicCounter();
|
||||
void testNullable();
|
||||
void testAscii();
|
||||
void testSmallObjectAllocator();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
Reference in New Issue
Block a user