1 #include "dbus_utility.hpp"
2 
3 #include <string>
4 
5 #include <gtest/gtest.h> // IWYU pragma: keep
6 
7 // IWYU pragma: no_include <gtest/gtest-message.h>
8 // IWYU pragma: no_include <gtest/gtest-test-part.h>
9 // IWYU pragma: no_include "gtest/gtest_pred_impl.h"
10 
11 namespace dbus::utility
12 {
13 namespace
14 {
15 
16 TEST(GetNthStringFromPath, ParsingSucceedsAndReturnsNthArg)
17 {
18     std::string path("/0th/1st/2nd/3rd");
19     std::string result;
20     EXPECT_TRUE(getNthStringFromPath(path, 0, result));
21     EXPECT_EQ(result, "0th");
22     EXPECT_TRUE(getNthStringFromPath(path, 1, result));
23     EXPECT_EQ(result, "1st");
24     EXPECT_TRUE(getNthStringFromPath(path, 2, result));
25     EXPECT_EQ(result, "2nd");
26     EXPECT_TRUE(getNthStringFromPath(path, 3, result));
27     EXPECT_EQ(result, "3rd");
28     EXPECT_FALSE(getNthStringFromPath(path, 4, result));
29 
30     path = "////0th///1st//\2nd///3rd?/";
31     EXPECT_TRUE(getNthStringFromPath(path, 0, result));
32     EXPECT_EQ(result, "0th");
33     EXPECT_TRUE(getNthStringFromPath(path, 1, result));
34     EXPECT_EQ(result, "1st");
35     EXPECT_TRUE(getNthStringFromPath(path, 2, result));
36     EXPECT_EQ(result, "\2nd");
37     EXPECT_TRUE(getNthStringFromPath(path, 3, result));
38     EXPECT_EQ(result, "3rd?");
39 }
40 
41 TEST(GetNthStringFromPath, InvalidIndexReturnsFalse)
42 {
43     std::string path("////0th///1st//\2nd///3rd?/");
44     std::string result;
45     EXPECT_FALSE(getNthStringFromPath(path, -1, result));
46 }
47 } // namespace
48 } // namespace dbus::utility
49