mirror of
https://github.com/Icinga/icinga2.git
synced 2025-06-27 08:54:31 +02:00
Make sure that unnamed items in a dictionary are always in the order they were inserted in.
This commit is contained in:
parent
e0fe2cab14
commit
c04cfb9dac
@ -115,7 +115,7 @@ String Dictionary::Add(const Value& value)
|
|||||||
long index = GetLength();
|
long index = GetLength();
|
||||||
do {
|
do {
|
||||||
stringstream s;
|
stringstream s;
|
||||||
s << "_" << index;
|
s << "_" << std::hex << std::setw(8) << std::setfill('0') << index;
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
key = s.str();
|
key = s.str();
|
||||||
|
@ -53,3 +53,21 @@ BOOST_AUTO_TEST_CASE(unnamed)
|
|||||||
|
|
||||||
BOOST_REQUIRE(distance(dictionary->Begin(), dictionary->End()) == 3);
|
BOOST_REQUIRE(distance(dictionary->Begin(), dictionary->End()) == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(unnamed_order)
|
||||||
|
{
|
||||||
|
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
dictionary->Add(i);
|
||||||
|
|
||||||
|
/* unnamed items are guaranteed to be in whatever order they were
|
||||||
|
* inserted in. */
|
||||||
|
String key;
|
||||||
|
Value value;
|
||||||
|
int i = 0;
|
||||||
|
BOOST_FOREACH(tie(key, value), dictionary) {
|
||||||
|
BOOST_REQUIRE(value == i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user