diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-03-13 19:59:57 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-04-15 01:07:24 +0300 |
commit | 79ce121b6bd33cc90e0a6645ef7391291792986f (patch) | |
tree | 0fb9e1f297eb62a5ca41f754c0041767c8e9f0bb /test/utils.cpp | |
parent | ebd0cae455ef1605a39b00dec79770f3d52de88f (diff) |
libcamera: utils: Add string join function
Add a utils::join() function to join elements of a container into a
string, with a separator and an optional conversion function if the
elements are not implicitly convertible to std::string.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'test/utils.cpp')
-rw-r--r-- | test/utils.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/test/utils.cpp b/test/utils.cpp index 58816f15..55ce9365 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -10,6 +10,8 @@ #include <string> #include <vector> +#include <libcamera/geometry.h> + #include "test.h" #include "utils.h" @@ -99,7 +101,7 @@ protected: return TestFail; } - /* utils::split() test. */ + /* utils::join() and utils::split() test. */ std::vector<std::string> elements = { "/bin", "/usr/bin", @@ -111,6 +113,11 @@ protected: for (const auto &element : elements) path += (path.empty() ? "" : ":") + element; + if (path != utils::join(elements, ":")) { + cerr << "utils::join() test failed" << endl; + return TestFail; + } + std::vector<std::string> dirs; for (const auto &dir : utils::split(path, ":")) @@ -121,6 +128,17 @@ protected: return TestFail; } + /* utils::join() with conversion function test. */ + std::vector<Size> sizes = { { 0, 0 }, { 100, 100 } }; + s = utils::join(sizes, "/", [](const Size &size) { + return size.toString(); + }); + + if (s != "0x0/100x100") { + cerr << "utils::join() with conversion test failed" << endl; + return TestFail; + } + /* utils::dirname() tests. */ if (TestPass != testDirname()) return TestFail; |