mirror of https://github.com/Icinga/icinga2.git
Dictionary: Make sure underlaying map is ordered
This commit is contained in:
parent
73e0d6e61b
commit
10bde2075a
|
@ -235,10 +235,10 @@ Object::Ptr Dictionary::Clone() const
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing all keys
|
||||
* Returns an ordered vector containing all keys
|
||||
* which are currently set in this directory.
|
||||
*
|
||||
* @returns an array of key names
|
||||
* @returns an ordered vector of key names
|
||||
*/
|
||||
std::vector<String> Dictionary::GetKeys() const
|
||||
{
|
||||
|
|
|
@ -70,6 +70,7 @@ add_boost_test(base
|
|||
base_dictionary/remove
|
||||
base_dictionary/clone
|
||||
base_dictionary/json
|
||||
base_dictionary/keys_ordered
|
||||
base_fifo/construct
|
||||
base_fifo/io
|
||||
base_json/encode
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "base/dictionary.hpp"
|
||||
#include "base/objectlock.hpp"
|
||||
#include "base/json.hpp"
|
||||
#include "base/string.hpp"
|
||||
#include "base/utility.hpp"
|
||||
#include <BoostTestTargetConfig.h>
|
||||
|
||||
using namespace icinga;
|
||||
|
@ -183,4 +185,16 @@ BOOST_AUTO_TEST_CASE(json)
|
|||
BOOST_CHECK(deserialized->Get("test2") == "hello world");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keys_ordered)
|
||||
{
|
||||
Dictionary::Ptr dictionary = new Dictionary();
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
dictionary->Set(std::to_string(Utility::Random()), Utility::Random());
|
||||
}
|
||||
|
||||
std::vector<String> keys = dictionary->GetKeys();
|
||||
BOOST_CHECK(std::is_sorted(keys.begin(), keys.end()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
Loading…
Reference in New Issue