summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-06-25 04:23:35 +0300
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-07-09 16:15:12 +0200
commitc58bec935c3adffac9d99b1675a563d7f2e9ae04 (patch)
treeacff6a88cdb591f517ab5f1ba3c44e4827401bc0 /test
parentb5f6a2ce2fae423f40c4bdaf1be43ad5070b3868 (diff)
libcamera: utils: Add map_keys() function
Add a map_keys() function to the utils namespace to extract keys from a map. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> [Niklas: change return type to std::vector instead of std::set] Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'test')
-rw-r--r--test/utils.cpp22
1 files changed, 22 insertions, 0 deletions
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 <iostream>
+#include <map>
#include <sstream>
#include <string>
#include <vector>
@@ -144,6 +145,27 @@ protected:
if (TestPass != testDirname())
return TestFail;
+
+ /* utils::map_keys() test. */
+ const std::map<std::string, unsigned int> map{
+ { "zero", 0 },
+ { "one", 1 },
+ { "two", 2 },
+ };
+ std::vector<std::string> expectedKeys{
+ "zero",
+ "one",
+ "two",
+ };
+
+ std::sort(expectedKeys.begin(), expectedKeys.end());
+
+ const std::vector<std::string> keys = utils::map_keys(map);
+ if (keys != expectedKeys) {
+ cerr << "utils::map_keys() test failed" << endl;
+ return TestFail;
+ }
+
return TestPass;
}
};