From 53057c2a3e6a794c350b48aa9a554b0af6229a59 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 6 Feb 2020 21:12:23 +0200 Subject: 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 Reviewed-by: Kieran Bingham Signed-off-by: Kieran Bingham --- test/utils.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/utils.cpp') 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 #include +#include +#include #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 elements = { + "/bin", + "/usr/bin", + "", + "", + }; + + std::string path; + for (const auto &element : elements) + path += (path.empty() ? "" : ":") + element; + + std::vector 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; } }; -- cgit v1.2.1