blob: d4342a5c1a3aef96105ded7daef9f8c8e0e86590 [file] [log] [blame]
Manojkiran Eda17a897d2020-09-12 15:31:58 +05301#include <boost/algorithm/string.hpp>
2#include <boost/container/flat_set.hpp>
3#include <dbus_singleton.hpp>
4#include <dbus_utility.hpp>
5
6#include "gmock/gmock.h"
7
8TEST(DbusUtility, getNthStringFromPathGoodTest)
9{
10 std::string path("/0th/1st/2nd/3rd");
11 std::string result;
12 EXPECT_TRUE(dbus::utility::getNthStringFromPath(path, 0, result));
13 EXPECT_EQ(result, "0th");
14 EXPECT_TRUE(dbus::utility::getNthStringFromPath(path, 1, result));
15 EXPECT_EQ(result, "1st");
16 EXPECT_TRUE(dbus::utility::getNthStringFromPath(path, 2, result));
17 EXPECT_EQ(result, "2nd");
18 EXPECT_TRUE(dbus::utility::getNthStringFromPath(path, 3, result));
19 EXPECT_EQ(result, "3rd");
20 EXPECT_FALSE(dbus::utility::getNthStringFromPath(path, 4, result));
21}
22
23TEST(DbusUtility, getNthStringFromPathBadTest)
24{
25 std::string path("////0th///1st//\2nd///3rd?/");
26 std::string result;
27 EXPECT_TRUE(dbus::utility::getNthStringFromPath(path, 0, result));
28 EXPECT_EQ(result, "0th");
29 EXPECT_TRUE(dbus::utility::getNthStringFromPath(path, 1, result));
30 EXPECT_EQ(result, "1st");
31 EXPECT_TRUE(dbus::utility::getNthStringFromPath(path, 2, result));
32 EXPECT_EQ(result, "\2nd");
33 EXPECT_TRUE(dbus::utility::getNthStringFromPath(path, 3, result));
34 EXPECT_EQ(result, "3rd?");
35 EXPECT_FALSE(dbus::utility::getNthStringFromPath(path, -1, result));
36}