mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-29 12:45:22 +01:00
added ListMap
ListMap is a map that does not order elements; used in NameValueCollection to prevent reordering of message headers
This commit is contained in:
parent
37f74f919e
commit
a259991568
@ -1010,6 +1010,7 @@
|
||||
<ClInclude Include="include\Poco\FPEnvironment_WIN32.h" />
|
||||
<ClInclude Include="include\Poco\Instantiator.h" />
|
||||
<ClInclude Include="include\Poco\Latin2Encoding.h" />
|
||||
<ClInclude Include="include\Poco\ListMap.h" />
|
||||
<ClInclude Include="include\Poco\MemoryPool.h" />
|
||||
<ClInclude Include="include\Poco\MetaProgramming.h" />
|
||||
<ClInclude Include="include\Poco\NamedTuple.h" />
|
||||
|
@ -1838,6 +1838,9 @@
|
||||
<ClInclude Include="include\Poco\Error.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\ListMap.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="src\pocomsg.rc">
|
||||
|
226
Foundation/include/Poco/ListMap.h
Normal file
226
Foundation/include/Poco/ListMap.h
Normal file
@ -0,0 +1,226 @@
|
||||
//
|
||||
// ListMap.h
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/ListMap.h#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: ListMap
|
||||
//
|
||||
// Definition of the ListMap 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 Foundation_ListMap_INCLUDED
|
||||
#define Foundation_ListMap_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <list>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class Key, class Mapped, class Container = std::list<std::pair<Key, Mapped> > >
|
||||
class ListMap
|
||||
/// This class implements a map in terms of a sequential container.
|
||||
/// The use for this type of associative container is wherever automatic
|
||||
/// ordering of elements is not desirable. Naturally, this container will
|
||||
/// have inferior data retrieval perofrmance and it is not recommended for
|
||||
/// use with large datasets. The main purpose within POCO is for Internet
|
||||
/// messages (email in particular), in order to prevent autmomatic header
|
||||
/// reordering.
|
||||
///
|
||||
/// A ListMap can be used just like a std::map.
|
||||
{
|
||||
public:
|
||||
typedef Key KeyType;
|
||||
typedef Mapped MappedType;
|
||||
typedef Mapped& Reference;
|
||||
typedef const Mapped& ConstReference;
|
||||
typedef Mapped* Pointer;
|
||||
typedef const Mapped* ConstPointer;
|
||||
|
||||
typedef typename Container::value_type ValueType;
|
||||
typedef typename Container::size_type SizeType;
|
||||
typedef typename Container::iterator Iterator;
|
||||
typedef typename Container::const_iterator ConstIterator;
|
||||
|
||||
ListMap()
|
||||
/// Creates an empty ListMap.
|
||||
{
|
||||
}
|
||||
|
||||
ListMap(std::size_t initialReserve):
|
||||
_list(initialReserve)
|
||||
/// Creates the ListMap with room for initialReserve entries.
|
||||
{
|
||||
}
|
||||
|
||||
ListMap& operator = (const ListMap& map)
|
||||
/// Assigns another ListMap.
|
||||
{
|
||||
ListMap tmp(map);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(ListMap& map)
|
||||
/// Swaps the ListMap with another one.
|
||||
{
|
||||
_list.swap(map._list);
|
||||
}
|
||||
|
||||
ConstIterator begin() const
|
||||
{
|
||||
return _list.begin();
|
||||
}
|
||||
|
||||
ConstIterator end() const
|
||||
{
|
||||
return _list.end();
|
||||
}
|
||||
|
||||
Iterator begin()
|
||||
{
|
||||
return _list.begin();
|
||||
}
|
||||
|
||||
Iterator end()
|
||||
{
|
||||
return _list.end();
|
||||
}
|
||||
|
||||
ConstIterator find(const KeyType& key) const
|
||||
{
|
||||
Container::const_iterator it = _list.begin();
|
||||
Container::const_iterator end = _list.end();
|
||||
for(; it != end; ++it)
|
||||
{
|
||||
if (isEqual(it->first, key)) return it;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
Iterator find(const KeyType& key)
|
||||
{
|
||||
Container::iterator it = _list.begin();
|
||||
Container::iterator end = _list.end();
|
||||
for(; it != end; ++it)
|
||||
{
|
||||
if (isEqual(it->first, key)) return it;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
std::pair<Iterator, bool> insert(const ValueType& val)
|
||||
{
|
||||
_list.push_back(val);
|
||||
Iterator it = _list.end();
|
||||
std::pair<Iterator, bool> p(--it, true);
|
||||
return p;
|
||||
}
|
||||
|
||||
void erase(Iterator it)
|
||||
{
|
||||
_list.erase(it);
|
||||
}
|
||||
|
||||
SizeType erase(const KeyType& key)
|
||||
{
|
||||
SizeType count = 0;
|
||||
Iterator it = find(key);
|
||||
while (it != _list.end())
|
||||
{
|
||||
++count;
|
||||
it = _list.erase(it);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
_list.clear();
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
{
|
||||
return _list.size();
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return _list.empty();
|
||||
}
|
||||
|
||||
ConstReference operator [] (const KeyType& key) const
|
||||
{
|
||||
ConstIterator it = find(key);
|
||||
if (it != _list.end())
|
||||
return it->second;
|
||||
else
|
||||
throw NotFoundException();
|
||||
}
|
||||
|
||||
Reference operator [] (const KeyType& key)
|
||||
{
|
||||
Iterator it = find(key);
|
||||
if (it != _list.end())
|
||||
return it->second;
|
||||
else
|
||||
{
|
||||
_list.push_back(ValueType(key, KeyType()));
|
||||
it = find(key);
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T1, typename T2>
|
||||
bool isEqual(T1 val1, T2 val2) const
|
||||
{
|
||||
return val1 == val2;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool isEqual(const std::string& s1, const std::string& s2) const
|
||||
{
|
||||
return Poco::icompare(s1, s2) == 0;
|
||||
}
|
||||
|
||||
Container _list;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_ListMap_INCLUDED
|
@ -312,6 +312,7 @@
|
||||
<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" />
|
||||
@ -445,6 +446,7 @@
|
||||
<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" />
|
||||
|
@ -573,6 +573,9 @@
|
||||
<ClCompile Include="src\FIFOBufferStreamTest.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ListMapTest.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\AnyTest.h">
|
||||
@ -965,5 +968,8 @@
|
||||
<ClInclude Include="src\ArrayTest.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\ListMapTest.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -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;
|
||||
}
|
||||
|
242
Foundation/testsuite/src/ListMapTest.cpp
Normal file
242
Foundation/testsuite/src/ListMapTest.cpp
Normal file
@ -0,0 +1,242 @@
|
||||
//
|
||||
// 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)
|
||||
{
|
||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, i*2));
|
||||
assert (res.first->first == i);
|
||||
assert (res.first->second == i*2);
|
||||
assert (res.second);
|
||||
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);
|
||||
}
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
std::pair<IntMap::Iterator, bool> res = hm.insert(IntMap::ValueType(i, 0));
|
||||
assert (res.first->first == i);
|
||||
assert (res.first->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::testIndex()
|
||||
{
|
||||
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::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, testIndex);
|
||||
|
||||
return pSuite;
|
||||
}
|
64
Foundation/testsuite/src/ListMapTest.h
Normal file
64
Foundation/testsuite/src/ListMapTest.h
Normal file
@ -0,0 +1,64 @@
|
||||
//
|
||||
// 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 testIndex();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // ListMapTest_INCLUDED
|
@ -42,7 +42,7 @@
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/String.h"
|
||||
#include <map>
|
||||
#include "Poco/ListMap.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -59,17 +59,9 @@ class Net_API NameValueCollection
|
||||
/// same name.
|
||||
{
|
||||
public:
|
||||
struct ILT
|
||||
{
|
||||
bool operator() (const std::string& s1, const std::string& s2) const
|
||||
{
|
||||
return Poco::icompare(s1, s2) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::multimap<std::string, std::string, ILT> HeaderMap;
|
||||
typedef HeaderMap::iterator Iterator;
|
||||
typedef HeaderMap::const_iterator ConstIterator;
|
||||
typedef Poco::ListMap<std::string, std::string> HeaderMap;
|
||||
typedef HeaderMap::Iterator Iterator;
|
||||
typedef HeaderMap::ConstIterator ConstIterator;
|
||||
|
||||
NameValueCollection();
|
||||
/// Creates an empty NameValueCollection.
|
||||
|
@ -94,13 +94,13 @@ void NameValueCollection::set(const std::string& name, const std::string& value)
|
||||
if (it != _map.end())
|
||||
it->second = value;
|
||||
else
|
||||
_map.insert(HeaderMap::value_type(name, value));
|
||||
_map.insert(HeaderMap::ValueType(name, value));
|
||||
}
|
||||
|
||||
|
||||
void NameValueCollection::add(const std::string& name, const std::string& value)
|
||||
{
|
||||
_map.insert(HeaderMap::value_type(name, value));
|
||||
_map.insert(HeaderMap::ValueType(name, value));
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,8 +160,8 @@ void HTMLFormTest::testWriteMultipart()
|
||||
"\r\n"
|
||||
"This is an attachment\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"attachment2\"; filename=\"att2.txt\"\r\n"
|
||||
"Content-ID: 1234abcd\r\n"
|
||||
"Content-Disposition: form-data; name=\"attachment2\"; filename=\"att2.txt\"\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"This is another attachment\r\n"
|
||||
|
@ -172,7 +172,8 @@ void HTTPCredentialsTest::testDigestCredentials()
|
||||
HTTPResponse response;
|
||||
response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
creds.authenticate(request, response);
|
||||
assert (request.get("Authorization") == "Digest nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", response=\"40e4889cfbd0e561f71e3107a2863bc4\", uri=\"/digest/\", username=\"user\"");
|
||||
std::string auth = request.get("Authorization");
|
||||
assert (auth == "Digest username=\"user\", nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", uri=\"/digest/\", response=\"40e4889cfbd0e561f71e3107a2863bc4\"");
|
||||
}
|
||||
|
||||
|
||||
@ -244,8 +245,9 @@ void HTTPCredentialsTest::testCredentialsDigest()
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
|
||||
HTTPResponse response;
|
||||
response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
creds.authenticate(request, response);
|
||||
assert (request.get("Authorization") == "Digest nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", response=\"40e4889cfbd0e561f71e3107a2863bc4\", uri=\"/digest/\", username=\"user\"");
|
||||
creds.authenticate(request, response);
|
||||
std::string auth = request.get("Authorization");
|
||||
assert (auth == "Digest username=\"user\", nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", uri=\"/digest/\", response=\"40e4889cfbd0e561f71e3107a2863bc4\"");
|
||||
}
|
||||
|
||||
|
||||
@ -256,7 +258,7 @@ void HTTPCredentialsTest::testProxyCredentialsDigest()
|
||||
HTTPResponse response;
|
||||
response.set("Proxy-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");
|
||||
creds.proxyAuthenticate(request, response);
|
||||
assert (request.get("Proxy-Authorization") == "Digest nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", response=\"40e4889cfbd0e561f71e3107a2863bc4\", uri=\"/digest/\", username=\"user\"");
|
||||
assert (request.get("Proxy-Authorization") == "Digest username=\"user\", nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", uri=\"/digest/\", response=\"40e4889cfbd0e561f71e3107a2863bc4\"");
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +73,7 @@ void HTTPRequestTest::testWrite2()
|
||||
std::ostringstream ostr;
|
||||
request.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "HEAD /index.html HTTP/1.1\r\nConnection: Keep-Alive\r\nHost: localhost\r\nUser-Agent: Poco\r\n\r\n");
|
||||
assert (s == "HEAD /index.html HTTP/1.1\r\nHost: localhost\r\nConnection: Keep-Alive\r\nUser-Agent: Poco\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ void HTTPRequestTest::testWrite3()
|
||||
std::ostringstream ostr;
|
||||
request.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "POST /test.cgi HTTP/1.1\r\nConnection: Close\r\nContent-Length: 100\r\nContent-Type: text/plain\r\nHost: localhost:8000\r\nUser-Agent: Poco\r\n\r\n");
|
||||
assert (s == "POST /test.cgi HTTP/1.1\r\nHost: localhost:8000\r\nConnection: Close\r\nUser-Agent: Poco\r\nContent-Length: 100\r\nContent-Type: text/plain\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,13 +136,13 @@ void MailMessageTest::testWriteQP()
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assert (s ==
|
||||
"CC: Jane Doe <jane.doe@no.where>\r\n"
|
||||
"Content-Transfer-Encoding: quoted-printable\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Transfer-Encoding: quoted-printable\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"CC: Jane Doe <jane.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
@ -172,11 +172,11 @@ void MailMessageTest::testWrite8Bit()
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assert (s ==
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
@ -204,11 +204,11 @@ void MailMessageTest::testWriteBase64()
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assert (s ==
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"SGVsbG8sIHdvcmxkIQ0KVGhpcyBpcyBhIHRlc3QgZm9yIHRoZSBNYWlsTWVzc2FnZSBjbGFz\r\n"
|
||||
@ -244,15 +244,15 @@ void MailMessageTest::testWriteManyRecipients()
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assert (s ==
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"To: John Doe <john.doe@no.where>, Jane Doe <jane.doe@no.where>, \r\n"
|
||||
"\tFrank Foo <walter.foo@no.where>, Bernie Bar <bernie.bar@no.where>, \r\n"
|
||||
"\tJoe Spammer <joe.spammer@no.where>\r\n"
|
||||
"\r\n"
|
||||
"\tFrank Foo <walter.foo@no.where>, Bernie Bar <bernie.bar@no.where>, \r\n"
|
||||
"\tJoe Spammer <joe.spammer@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
@ -279,32 +279,32 @@ void MailMessageTest::testWriteMultiPart()
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
std::string rawMsg(
|
||||
"Content-Type: multipart/mixed; boundary=$\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"Content-Type: multipart/mixed; boundary=$\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"\r\n"
|
||||
"--$\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--$\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"Content-ID: abcd1234\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
"--$--\r\n"
|
||||
);
|
||||
std::string::size_type p1 = s.find('=') + 1;
|
||||
std::string::size_type p2 = s.find('\r');
|
||||
std::string boundary(s, p1, p2 - p1);
|
||||
std::string::size_type p2 = s.rfind("--");
|
||||
std::string::size_type p1 = s.rfind("--", p2 - 1);
|
||||
std::string boundary(s, p1 + 2, p2 - 2 - p1);
|
||||
std::string msg;
|
||||
for (std::string::const_iterator it = rawMsg.begin(); it != rawMsg.end(); ++it)
|
||||
{
|
||||
|
@ -136,16 +136,16 @@ void SMTPClientSessionTest::testSend()
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "DATA");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Transfer-Encoding: quoted-printable");
|
||||
assert (cmd.substr(0, 4) == "Date");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Type: text/plain");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd.substr(0, 4) == "Date");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "From: john.doe@no.where");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Subject: Test Message");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Transfer-Encoding: quoted-printable");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "To: Jane Doe <jane.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Hello");
|
||||
@ -199,20 +199,20 @@ void SMTPClientSessionTest::testSendMultiRecipient()
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "DATA");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "CC: Jack Doe <jack.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Transfer-Encoding: quoted-printable");
|
||||
assert (cmd.substr(0, 4) == "Date");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Type: text/plain");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd.substr(0, 4) == "Date");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "From: john.doe@no.where");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Subject: Test Message");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Transfer-Encoding: quoted-printable");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "To: Jane Doe <jane.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "CC: Jack Doe <jack.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Hello");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "blah blah");
|
||||
@ -269,20 +269,20 @@ void SMTPClientSessionTest::testMultiSeparateRecipient()
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "DATA");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "CC: Jack Doe <jack.doe@no.where>, Joe Doe <joe.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Transfer-Encoding: quoted-printable");
|
||||
assert (cmd.substr(0, 4) == "Date");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Type: text/plain");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd.substr(0, 4) == "Date");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "From: john.doe@no.where");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Subject: Test Message");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Transfer-Encoding: quoted-printable");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "To: Jane Doe <jane.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "CC: Jack Doe <jack.doe@no.where>, Joe Doe <joe.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Hello");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "blah blah");
|
||||
|
Loading…
x
Reference in New Issue
Block a user