diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-02-06 21:12:23 +0200 |
---|---|---|
committer | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2020-02-13 16:47:56 +0000 |
commit | 53057c2a3e6a794c350b48aa9a554b0af6229a59 (patch) | |
tree | fa273a33dc6fec9676a1b73200fac65e8fba1c78 /test | |
parent | 31a05b70aa4bf792aa7396b3c4a1a40a0e701f3c (diff) |
test: Add a utils::split() test
The test constructs a string by joining substrings, splits it, and
verifies that the original and resulting substrings match.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/utils.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/utils.cpp b/test/utils.cpp index 9fe0d477..db1fbdde 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -7,6 +7,8 @@ #include <iostream> #include <sstream> +#include <string> +#include <vector> #include "test.h" #include "utils.h" @@ -19,6 +21,7 @@ class UtilsTest : public Test protected: int run() { + /* utils::hex() test. */ std::ostringstream os; std::string ref; @@ -46,6 +49,28 @@ protected: return TestFail; } + /* utils::split() test. */ + std::vector<std::string> elements = { + "/bin", + "/usr/bin", + "", + "", + }; + + std::string path; + for (const auto &element : elements) + path += (path.empty() ? "" : ":") + element; + + std::vector<std::string> dirs; + + for (const auto &dir : utils::split(path, ":")) + dirs.push_back(dir); + + if (dirs != elements) { + cerr << "utils::split() test failed" << endl; + return TestFail; + } + return TestPass; } }; |