diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index 4fd9d24b9..435df3159 100644 --- a/lib/base/dictionary.cpp +++ b/lib/base/dictionary.cpp @@ -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 Dictionary::GetKeys() const { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 25557944a..ba08fa431 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 diff --git a/test/base-dictionary.cpp b/test/base-dictionary.cpp index cd074e1a9..3469be7cd 100644 --- a/test/base-dictionary.cpp +++ b/test/base-dictionary.cpp @@ -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 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 keys = dictionary->GetKeys(); + BOOST_CHECK(std::is_sorted(keys.begin(), keys.end())); +} + BOOST_AUTO_TEST_SUITE_END()