From c58bec935c3adffac9d99b1675a563d7f2e9ae04 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 25 Jun 2020 04:23:35 +0300 Subject: libcamera: utils: Add map_keys() function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a map_keys() function to the utils namespace to extract keys from a map. Signed-off-by: Laurent Pinchart [Niklas: change return type to std::vector instead of std::set] Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- test/utils.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/utils.cpp') diff --git a/test/utils.cpp b/test/utils.cpp index 66b91f12..f482e6a1 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -144,6 +145,27 @@ protected: if (TestPass != testDirname()) return TestFail; + + /* utils::map_keys() test. */ + const std::map map{ + { "zero", 0 }, + { "one", 1 }, + { "two", 2 }, + }; + std::vector expectedKeys{ + "zero", + "one", + "two", + }; + + std::sort(expectedKeys.begin(), expectedKeys.end()); + + const std::vector keys = utils::map_keys(map); + if (keys != expectedKeys) { + cerr << "utils::map_keys() test failed" << endl; + return TestFail; + } + return TestPass; } }; -- cgit v1.2.1