summaryrefslogtreecommitdiff
path: root/test/include/dbus_utility_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/include/dbus_utility_test.cpp')
-rw-r--r--test/include/dbus_utility_test.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/include/dbus_utility_test.cpp b/test/include/dbus_utility_test.cpp
new file mode 100644
index 0000000000..71978d01ba
--- /dev/null
+++ b/test/include/dbus_utility_test.cpp
@@ -0,0 +1,48 @@
+#include "dbus_utility.hpp"
+
+#include <string>
+
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
+
+namespace dbus::utility
+{
+namespace
+{
+
+TEST(GetNthStringFromPath, ParsingSucceedsAndReturnsNthArg)
+{
+ std::string path("/0th/1st/2nd/3rd");
+ std::string result;
+ EXPECT_TRUE(getNthStringFromPath(path, 0, result));
+ EXPECT_EQ(result, "0th");
+ EXPECT_TRUE(getNthStringFromPath(path, 1, result));
+ EXPECT_EQ(result, "1st");
+ EXPECT_TRUE(getNthStringFromPath(path, 2, result));
+ EXPECT_EQ(result, "2nd");
+ EXPECT_TRUE(getNthStringFromPath(path, 3, result));
+ EXPECT_EQ(result, "3rd");
+ EXPECT_FALSE(getNthStringFromPath(path, 4, result));
+
+ path = "////0th///1st//\2nd///3rd?/";
+ EXPECT_TRUE(getNthStringFromPath(path, 0, result));
+ EXPECT_EQ(result, "0th");
+ EXPECT_TRUE(getNthStringFromPath(path, 1, result));
+ EXPECT_EQ(result, "1st");
+ EXPECT_TRUE(getNthStringFromPath(path, 2, result));
+ EXPECT_EQ(result, "\2nd");
+ EXPECT_TRUE(getNthStringFromPath(path, 3, result));
+ EXPECT_EQ(result, "3rd?");
+}
+
+TEST(GetNthStringFromPath, InvalidIndexReturnsFalse)
+{
+ std::string path("////0th///1st//\2nd///3rd?/");
+ std::string result;
+ EXPECT_FALSE(getNthStringFromPath(path, -1, result));
+}
+} // namespace
+} // namespace dbus::utility \ No newline at end of file