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