fixed GH #1253: ListMap does not maintain insertion order if key already exists

Conflicts:
	Foundation/include/Poco/ListMap.h
This commit is contained in:
Guenter Obiltschnig
2016-04-21 09:24:59 +02:00
parent 13a999de42
commit a8962bb3b3
2 changed files with 37 additions and 0 deletions

View File

@@ -72,6 +72,41 @@ void ListMapTest::testInsert()
} }
void ListMapTest::testInsertOrder()
{
const int N = 1000;
typedef ListMap<std::string, int> StrToIntMap;
StrToIntMap lm;
lm.insert(StrToIntMap::ValueType("foo", 42));
lm.insert(StrToIntMap::ValueType("bar", 43));
StrToIntMap::Iterator it = lm.begin();
assert (it != lm.end() && it->first == "foo" && it->second == 42);
++it;
assert (it != lm.end() && it->first == "bar" && it->second == 43);
++it;
assert (it == lm.end());
lm.insert(StrToIntMap::ValueType("foo", 44));
it = lm.begin();
assert (it != lm.end() && it->first == "foo" && it->second == 42);
++it;
assert (it != lm.end() && it->first == "foo" && it->second == 44);
++it;
assert (it != lm.end() && it->first == "bar" && it->second == 43);
++it;
assert (it == lm.end());
}
void ListMapTest::testErase() void ListMapTest::testErase()
{ {
const int N = 1000; const int N = 1000;
@@ -239,6 +274,7 @@ CppUnit::Test* ListMapTest::suite()
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ListMapTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ListMapTest");
CppUnit_addTest(pSuite, ListMapTest, testInsert); CppUnit_addTest(pSuite, ListMapTest, testInsert);
CppUnit_addTest(pSuite, ListMapTest, testInsertOrder);
CppUnit_addTest(pSuite, ListMapTest, testErase); CppUnit_addTest(pSuite, ListMapTest, testErase);
CppUnit_addTest(pSuite, ListMapTest, testIterator); CppUnit_addTest(pSuite, ListMapTest, testIterator);
CppUnit_addTest(pSuite, ListMapTest, testConstIterator); CppUnit_addTest(pSuite, ListMapTest, testConstIterator);

View File

@@ -27,6 +27,7 @@ public:
~ListMapTest(); ~ListMapTest();
void testInsert(); void testInsert();
void testInsertOrder();
void testErase(); void testErase();
void testIterator(); void testIterator();
void testConstIterator(); void testConstIterator();