RecursiveDirectoryIterator and ListMap

1) Recursive and SortedDirectoryIterator

- added to VS projects
- fixed some style/formatting
- fxed windows tests

2) Added ListMap

Poco::ListMap is a std::mulitimap-like container that preserves
insertion order (needed to prevent Net message headers)
This commit is contained in:
aleks-f
2013-03-10 12:25:47 -05:00
46 changed files with 1120 additions and 130 deletions

View File

@@ -614,6 +614,10 @@
RelativePath=".\src\CoreTestSuite.cpp"
>
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.cpp"
>
</File>
<File
RelativePath=".\src\DynamicFactoryTest.cpp"
>
@@ -626,6 +630,10 @@
RelativePath=".\src\FPETest.cpp"
>
</File>
<File
RelativePath=".\src\ListMapTest.cpp"
>
</File>
<File
RelativePath=".\src\MemoryPoolTest.cpp"
>
@@ -706,6 +714,10 @@
RelativePath=".\src\CoreTestSuite.h"
>
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.h"
>
</File>
<File
RelativePath=".\src\DynamicFactoryTest.h"
>
@@ -718,6 +730,10 @@
RelativePath=".\src\FPETest.h"
>
</File>
<File
RelativePath=".\src\ListMapTest.h"
>
</File>
<File
RelativePath=".\src\MemoryPoolTest.h"
>

View File

@@ -309,11 +309,13 @@
<ClCompile Include="src\ByteOrderTest.cpp" />
<ClCompile Include="src\CoreTest.cpp" />
<ClCompile Include="src\CoreTestSuite.cpp" />
<ClCompile Include="src\DirectoryIteratorsTest.cpp" />
<ClCompile Include="src\DirectoryWatcherTest.cpp" />
<ClCompile Include="src\DynamicFactoryTest.cpp" />
<ClCompile Include="src\FIFOBufferStreamTest.cpp" />
<ClCompile Include="src\FormatTest.cpp" />
<ClCompile Include="src\FPETest.cpp" />
<ClCompile Include="src\ListMapTest.cpp" />
<ClCompile Include="src\MemoryPoolTest.cpp" />
<ClCompile Include="src\NamedTuplesTest.cpp" />
<ClCompile Include="src\NDCTest.cpp" />
@@ -443,11 +445,13 @@
<ClInclude Include="src\ByteOrderTest.h" />
<ClInclude Include="src\CoreTest.h" />
<ClInclude Include="src\CoreTestSuite.h" />
<ClInclude Include="src\DirectoryIteratorsTest.h" />
<ClInclude Include="src\DirectoryWatcherTest.h" />
<ClInclude Include="src\DynamicFactoryTest.h" />
<ClInclude Include="src\FIFOBufferStreamTest.h" />
<ClInclude Include="src\FormatTest.h" />
<ClInclude Include="src\FPETest.h" />
<ClInclude Include="src\ListMapTest.h" />
<ClInclude Include="src\MemoryPoolTest.h" />
<ClInclude Include="src\NamedTuplesTest.h" />
<ClInclude Include="src\NDCTest.h" />

View File

@@ -576,6 +576,12 @@
<ClCompile Include="src\Base32Test.cpp">
<Filter>Streams\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ListMapTest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\DirectoryIteratorsTest.cpp">
<Filter>Filesystem\Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\AnyTest.h">
@@ -971,5 +977,11 @@
<ClInclude Include="src\Base32Test.h">
<Filter>Streams\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ListMapTest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\DirectoryIteratorsTest.h">
<Filter>Filesystem\Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -313,11 +313,13 @@
<ClCompile Include="src\ByteOrderTest.cpp" />
<ClCompile Include="src\CoreTest.cpp" />
<ClCompile Include="src\CoreTestSuite.cpp" />
<ClCompile Include="src\DirectoryIteratorsTest.cpp" />
<ClCompile Include="src\DirectoryWatcherTest.cpp" />
<ClCompile Include="src\DynamicFactoryTest.cpp" />
<ClCompile Include="src\FIFOBufferStreamTest.cpp" />
<ClCompile Include="src\FormatTest.cpp" />
<ClCompile Include="src\FPETest.cpp" />
<ClCompile Include="src\ListMapTest.cpp" />
<ClCompile Include="src\MemoryPoolTest.cpp" />
<ClCompile Include="src\NamedTuplesTest.cpp" />
<ClCompile Include="src\NDCTest.cpp" />
@@ -447,11 +449,13 @@
<ClInclude Include="src\ByteOrderTest.h" />
<ClInclude Include="src\CoreTest.h" />
<ClInclude Include="src\CoreTestSuite.h" />
<ClInclude Include="src\DirectoryIteratorsTest.h" />
<ClInclude Include="src\DirectoryWatcherTest.h" />
<ClInclude Include="src\DynamicFactoryTest.h" />
<ClInclude Include="src\FIFOBufferStreamTest.h" />
<ClInclude Include="src\FormatTest.h" />
<ClInclude Include="src\FPETest.h" />
<ClInclude Include="src\ListMapTest.h" />
<ClInclude Include="src\MemoryPoolTest.h" />
<ClInclude Include="src\NamedTuplesTest.h" />
<ClInclude Include="src\NDCTest.h" />

View File

@@ -207,6 +207,9 @@
<ClCompile Include="src\FPETest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ListMapTest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\MemoryPoolTest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
@@ -402,6 +405,9 @@
<ClCompile Include="src\FilesystemTestSuite.cpp">
<Filter>Filesystem\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\DirectoryIteratorsTest.cpp">
<Filter>Filesystem\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\FileTest.cpp">
<Filter>Filesystem\Source Files</Filter>
</ClCompile>
@@ -605,6 +611,9 @@
<ClInclude Include="src\FPETest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ListMapTest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\MemoryPoolTest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
@@ -800,6 +809,9 @@
<ClInclude Include="src\FilesystemTestSuite.h">
<Filter>Filesystem\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\DirectoryIteratorsTest.h">
<Filter>Filesystem\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\FileTest.h">
<Filter>Filesystem\Header Files</Filter>
</ClInclude>

View File

@@ -418,6 +418,9 @@
<File
RelativePath=".\src\CoreTestSuite.cpp">
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.cpp">
</File>
<File
RelativePath=".\src\DynamicFactoryTest.cpp">
</File>
@@ -430,6 +433,9 @@
<File
RelativePath=".\src\FPETest.cpp">
</File>
<File
RelativePath=".\src\ListMapTest.cpp">
</File>
<File
RelativePath=".\src\MemoryPoolTest.cpp">
</File>
@@ -491,6 +497,9 @@
<File
RelativePath=".\src\CoreTestSuite.h">
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.h">
</File>
<File
RelativePath=".\src\DynamicFactoryTest.h">
</File>
@@ -503,6 +512,9 @@
<File
RelativePath=".\src\FPETest.h">
</File>
<File
RelativePath=".\src\ListMapTest.h">
</File>
<File
RelativePath=".\src\MemoryPoolTest.h">
</File>

View File

@@ -583,6 +583,10 @@
RelativePath=".\src\CoreTestSuite.cpp"
>
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.cpp"
>
</File>
<File
RelativePath=".\src\DynamicFactoryTest.cpp"
>
@@ -595,6 +599,10 @@
RelativePath=".\src\FPETest.cpp"
>
</File>
<File
RelativePath=".\src\ListMapTest.cpp"
>
</File>
<File
RelativePath=".\src\MemoryPoolTest.cpp"
>
@@ -675,6 +683,10 @@
RelativePath=".\src\CoreTestSuite.h"
>
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.h"
>
</File>
<File
RelativePath=".\src\DynamicFactoryTest.h"
>
@@ -687,6 +699,10 @@
RelativePath=".\src\FPETest.h"
>
</File>
<File
RelativePath=".\src\ListMapTest.h"
>
</File>
<File
RelativePath=".\src\MemoryPoolTest.h"
>

View File

@@ -565,6 +565,10 @@
RelativePath=".\src\CoreTestSuite.cpp"
>
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.cpp"
>
</File>
<File
RelativePath=".\src\DynamicFactoryTest.cpp"
>
@@ -577,6 +581,10 @@
RelativePath=".\src\FPETest.cpp"
>
</File>
<File
RelativePath=".\src\ListMapTest.cpp"
>
</File>
<File
RelativePath=".\src\MemoryPoolTest.cpp"
>
@@ -657,6 +665,10 @@
RelativePath=".\src\CoreTestSuite.h"
>
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.h"
>
</File>
<File
RelativePath=".\src\DynamicAnyTest.h"
>
@@ -673,6 +685,10 @@
RelativePath=".\src\FPETest.h"
>
</File>
<File
RelativePath=".\src\ListMapTest.h"
>
</File>
<File
RelativePath=".\src\MemoryPoolTest.h"
>

View File

@@ -307,11 +307,13 @@
<ClCompile Include="src\ByteOrderTest.cpp" />
<ClCompile Include="src\CoreTest.cpp" />
<ClCompile Include="src\CoreTestSuite.cpp" />
<ClCompile Include="src\DirectoryIteratorsTest.cpp" />
<ClCompile Include="src\DirectoryWatcherTest.cpp" />
<ClCompile Include="src\DynamicFactoryTest.cpp" />
<ClCompile Include="src\FIFOBufferStreamTest.cpp" />
<ClCompile Include="src\FormatTest.cpp" />
<ClCompile Include="src\FPETest.cpp" />
<ClCompile Include="src\ListMapTest.cpp" />
<ClCompile Include="src\MemoryPoolTest.cpp" />
<ClCompile Include="src\NamedTuplesTest.cpp" />
<ClCompile Include="src\NDCTest.cpp" />
@@ -441,12 +443,14 @@
<ClInclude Include="src\ByteOrderTest.h" />
<ClInclude Include="src\CoreTest.h" />
<ClInclude Include="src\CoreTestSuite.h" />
<ClInclude Include="src\DirectoryIteratorsTest.h" />
<ClInclude Include="src\DirectoryWatcherTest.h" />
<ClInclude Include="src\DynamicAnyTest.h" />
<ClInclude Include="src\DynamicFactoryTest.h" />
<ClInclude Include="src\FIFOBufferStreamTest.h" />
<ClInclude Include="src\FormatTest.h" />
<ClInclude Include="src\FPETest.h" />
<ClInclude Include="src\ListMapTest.h" />
<ClInclude Include="src\MemoryPoolTest.h" />
<ClInclude Include="src\NamedTuplesTest.h" />
<ClInclude Include="src\NDCTest.h" />

View File

@@ -198,6 +198,9 @@
<ClCompile Include="src\CoreTestSuite.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\DirectoryIteratorsTest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\DynamicFactoryTest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
@@ -207,6 +210,9 @@
<ClCompile Include="src\FPETest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ListMapTest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\MemoryPoolTest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
@@ -596,6 +602,9 @@
<ClInclude Include="src\CoreTestSuite.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\DirectoryIteratorsTest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\DynamicAnyTest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
@@ -608,6 +617,9 @@
<ClInclude Include="src\FPETest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ListMapTest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\MemoryPoolTest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>

View File

@@ -313,11 +313,13 @@
<ClCompile Include="src\ByteOrderTest.cpp" />
<ClCompile Include="src\CoreTest.cpp" />
<ClCompile Include="src\CoreTestSuite.cpp" />
<ClCompile Include="src\DirectoryIteratorsTest.cpp" />
<ClCompile Include="src\DirectoryWatcherTest.cpp" />
<ClCompile Include="src\DynamicFactoryTest.cpp" />
<ClCompile Include="src\FIFOBufferStreamTest.cpp" />
<ClCompile Include="src\FormatTest.cpp" />
<ClCompile Include="src\FPETest.cpp" />
<ClCompile Include="src\ListMapTest.cpp" />
<ClCompile Include="src\MemoryPoolTest.cpp" />
<ClCompile Include="src\NamedTuplesTest.cpp" />
<ClCompile Include="src\NDCTest.cpp" />
@@ -447,12 +449,14 @@
<ClInclude Include="src\ByteOrderTest.h" />
<ClInclude Include="src\CoreTest.h" />
<ClInclude Include="src\CoreTestSuite.h" />
<ClInclude Include="src\DirectoryIteratorsTest.h" />
<ClInclude Include="src\DirectoryWatcherTest.h" />
<ClInclude Include="src\DynamicAnyTest.h" />
<ClInclude Include="src\DynamicFactoryTest.h" />
<ClInclude Include="src\FIFOBufferStreamTest.h" />
<ClInclude Include="src\FormatTest.h" />
<ClInclude Include="src\FPETest.h" />
<ClInclude Include="src\ListMapTest.h" />
<ClInclude Include="src\MemoryPoolTest.h" />
<ClInclude Include="src\NamedTuplesTest.h" />
<ClInclude Include="src\NDCTest.h" />

View File

@@ -207,6 +207,9 @@
<ClCompile Include="src\FPETest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\ListMapTest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\MemoryPoolTest.cpp">
<Filter>Core\Source Files</Filter>
</ClCompile>
@@ -402,6 +405,9 @@
<ClCompile Include="src\FilesystemTestSuite.cpp">
<Filter>Filesystem\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\DirectoryIteratorsTest.cpp">
<Filter>Filesystem\Source Files</Filter>
</ClCompile>
<ClCompile Include="src\FileTest.cpp">
<Filter>Filesystem\Source Files</Filter>
</ClCompile>
@@ -608,6 +614,9 @@
<ClInclude Include="src\FPETest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\ListMapTest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\MemoryPoolTest.h">
<Filter>Core\Header Files</Filter>
</ClInclude>
@@ -803,6 +812,9 @@
<ClInclude Include="src\FilesystemTestSuite.h">
<Filter>Filesystem\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\DirectoryIteratorsTest.h">
<Filter>Filesystem\Header Files</Filter>
</ClInclude>
<ClInclude Include="src\FileTest.h">
<Filter>Filesystem\Header Files</Filter>
</ClInclude>

View File

@@ -559,6 +559,10 @@
RelativePath=".\src\CoreTestSuite.cpp"
>
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.cpp"
>
</File>
<File
RelativePath=".\src\DynamicFactoryTest.cpp"
>
@@ -571,6 +575,10 @@
RelativePath=".\src\FPETest.cpp"
>
</File>
<File
RelativePath=".\src\ListMapTest.cpp"
>
</File>
<File
RelativePath=".\src\MemoryPoolTest.cpp"
>
@@ -651,6 +659,10 @@
RelativePath=".\src\CoreTestSuite.h"
>
</File>
<File
RelativePath=".\src\DirectoryIteratorsTest.h"
>
</File>
<File
RelativePath=".\src\DynamicAnyTest.h"
>
@@ -667,6 +679,10 @@
RelativePath=".\src\FPETest.h"
>
</File>
<File
RelativePath=".\src\ListMapTest.h"
>
</File>
<File
RelativePath=".\src\MemoryPoolTest.h"
>

View File

@@ -57,6 +57,7 @@
#endif
#include "TypeListTest.h"
#include "ObjectPoolTest.h"
#include "ListMapTest.h"
CppUnit::Test* CoreTestSuite::suite()
@@ -89,6 +90,7 @@ CppUnit::Test* CoreTestSuite::suite()
#endif
pSuite->addTest(TypeListTest::suite());
pSuite->addTest(ObjectPoolTest::suite());
pSuite->addTest(ListMapTest::suite());
return pSuite;
}

View File

@@ -94,8 +94,8 @@ void DirectoryIteratorsTest::testSortedDirectoryIterator()
assertEquals("2", result[2]);
assertEquals("A", result[3]);
assertEquals("B", result[4]);
assertEquals("a", result[5]);
assertEquals("b", result[6]);
assertEquals("c", result[5]);
assertEquals("d", result[6]);
}
@@ -139,14 +139,8 @@ void DirectoryIteratorsTest::testSiblingsFirstRecursiveDirectoryIterator()
void DirectoryIteratorsTest::setUp()
{
try
{
File d(path());
d.remove(true);
}
catch (...)
{
}
File d(path());
if (d.exists()) d.remove(true);
/*
Build Directory Tree like this:
@@ -156,22 +150,22 @@ void DirectoryIteratorsTest::setUp()
|-- 2
|-- A
|-- B
|-- a
|-- b
|-- c
|-- d
`-- first
|-- 1
|-- 2
|-- A
|-- B
|-- a
|-- b
|-- c
|-- d
`-- second
|-- 1
|-- 2
|-- A
|-- B
|-- a
`-- b
|-- c
`-- d
2 directories, 18 files
*/
@@ -190,12 +184,12 @@ void DirectoryIteratorsTest::createSubdir(Path& p)
{
File d(p);
d.createDirectories();
FileStream f1(p.toString() + "b");
FileStream f1(p.toString() + "d");
FileStream f2(p.toString() + "1");
FileStream f3(p.toString() + "A");
FileStream f4(p.toString() + "2");
FileStream f5(p.toString() + "B");
FileStream f6(p.toString() + "a");
FileStream f6(p.toString() + "c");
}

View File

@@ -0,0 +1,269 @@
//
// ListMapTest.cpp
//
// $Id: //poco/1.4/Foundation/testsuite/src/ListMapTest.cpp#1 $
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "ListMapTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/ListMap.h"
#include "Poco/Exception.h"
#include <map>
using Poco::ListMap;
ListMapTest::ListMapTest(const std::string& name): CppUnit::TestCase(name)
{
}
ListMapTest::~ListMapTest()
{
}
void ListMapTest::testInsert()
{
const int N = 1000;
typedef ListMap<int, int> IntMap;
IntMap hm;
assert (hm.empty());
for (int i = 0; i < N; ++i)
{
IntMap::Iterator res = hm.insert(IntMap::ValueType(i, i*2));
assert (res->first == i);
assert (res->second == i*2);
IntMap::Iterator it = hm.find(i);
assert (it != hm.end());
assert (it->first == i);
assert (it->second == i*2);
assert (hm.size() == i + 1);
}
assert (!hm.empty());
for (int i = 0; i < N; ++i)
{
IntMap::Iterator it = hm.find(i);
assert (it != hm.end());
assert (it->first == i);
assert (it->second == i*2);
}
hm.clear();
for (int i = 0; i < N; ++i)
{
IntMap::Iterator res = hm.insert(IntMap::ValueType(i, 0));
assert (res->first == i);
assert (res->second == 0);
}
}
void ListMapTest::testErase()
{
const int N = 1000;
typedef ListMap<int, int> IntMap;
IntMap hm;
for (int i = 0; i < N; ++i)
{
hm.insert(IntMap::ValueType(i, i*2));
}
assert (hm.size() == N);
for (int i = 0; i < N; i += 2)
{
hm.erase(i);
IntMap::Iterator it = hm.find(i);
assert (it == hm.end());
}
assert (hm.size() == N/2);
for (int i = 0; i < N; i += 2)
{
IntMap::Iterator it = hm.find(i);
assert (it == hm.end());
}
for (int i = 1; i < N; i += 2)
{
IntMap::Iterator it = hm.find(i);
assert (it != hm.end());
assert (it->first == i);
}
for (int i = 0; i < N; i += 2)
{
hm.insert(IntMap::ValueType(i, i*2));
}
for (int i = 0; i < N; ++i)
{
IntMap::Iterator it = hm.find(i);
assert (it != hm.end());
assert (it->first == i);
assert (it->second == i*2);
}
}
void ListMapTest::testIterator()
{
const int N = 1000;
typedef ListMap<int, int> IntMap;
IntMap hm;
for (int i = 0; i < N; ++i)
{
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();
while (it != hm.end())
{
assert (values.find(it->first) == values.end());
values[it->first] = it->second;
++it;
}
assert (values.size() == N);
}
void ListMapTest::testConstIterator()
{
const int N = 1000;
typedef ListMap<int, int> IntMap;
IntMap hm;
for (int i = 0; i < N; ++i)
{
hm.insert(IntMap::ValueType(i, i*2));
}
std::map<int, int> values;
IntMap::ConstIterator it = hm.begin();
while (it != hm.end())
{
assert (values.find(it->first) == values.end());
values[it->first] = it->second;
++it;
}
assert (values.size() == N);
}
void ListMapTest::testIntIndex()
{
typedef ListMap<int, int> IntMap;
IntMap hm;
hm[1] = 2;
hm[2] = 4;
hm[3] = 6;
assert (hm.size() == 3);
assert (hm[1] == 2);
assert (hm[2] == 4);
assert (hm[3] == 6);
try
{
const IntMap& im = hm;
int x = im[4];
fail("no such key - must throw");
}
catch (Poco::NotFoundException&)
{
}
}
void ListMapTest::testStringIndex()
{
typedef ListMap<const char*, std::string> StringMap;
StringMap hm;
hm["index1"] = "value2";
hm["index2"] = "value4";
hm["index3"] = "value6";
assert (hm.size() == 3);
assert (hm["index1"] == "value2");
assert (hm["Index2"] == "value4");
assert (hm["inDeX3"] == "value6");
try
{
const StringMap& im = hm;
std::string x = im["index4"];
fail("no such key - must throw");
}
catch (Poco::NotFoundException&)
{
}
}
void ListMapTest::setUp()
{
}
void ListMapTest::tearDown()
{
}
CppUnit::Test* ListMapTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ListMapTest");
CppUnit_addTest(pSuite, ListMapTest, testInsert);
CppUnit_addTest(pSuite, ListMapTest, testErase);
CppUnit_addTest(pSuite, ListMapTest, testIterator);
CppUnit_addTest(pSuite, ListMapTest, testConstIterator);
CppUnit_addTest(pSuite, ListMapTest, testIntIndex);
CppUnit_addTest(pSuite, ListMapTest, testStringIndex);
return pSuite;
}

View File

@@ -0,0 +1,65 @@
//
// ListMapTest.h
//
// $Id: //poco/1.4/Foundation/testsuite/src/ListMapTest.h#1 $
//
// Definition of the ListMapTest class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef ListMapTest_INCLUDED
#define ListMapTest_INCLUDED
#include "Poco/Foundation.h"
#include "CppUnit/TestCase.h"
class ListMapTest: public CppUnit::TestCase
{
public:
ListMapTest(const std::string& name);
~ListMapTest();
void testInsert();
void testErase();
void testIterator();
void testConstIterator();
void testIntIndex();
void testStringIndex();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // ListMapTest_INCLUDED