Nan Zhou | 2f07bde | 2022-06-21 17:46:31 +0000 | [diff] [blame] | 1 | #include "dbus_utility.hpp" |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 2 | |
Nan Zhou | 2f07bde | 2022-06-21 17:46:31 +0000 | [diff] [blame] | 3 | #include <string> |
| 4 | |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 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" |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 10 | |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 11 | namespace dbus::utility |
| 12 | { |
| 13 | namespace |
| 14 | { |
| 15 | |
Nan Zhou | 623e533 | 2022-06-21 17:46:37 +0000 | [diff] [blame] | 16 | TEST(GetNthStringFromPath, ParsingSucceedsAndReturnsNthArg) |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 17 | { |
| 18 | std::string path("/0th/1st/2nd/3rd"); |
| 19 | std::string result; |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 20 | EXPECT_TRUE(getNthStringFromPath(path, 0, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 21 | EXPECT_EQ(result, "0th"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 22 | EXPECT_TRUE(getNthStringFromPath(path, 1, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 23 | EXPECT_EQ(result, "1st"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 24 | EXPECT_TRUE(getNthStringFromPath(path, 2, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 25 | EXPECT_EQ(result, "2nd"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 26 | EXPECT_TRUE(getNthStringFromPath(path, 3, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 27 | EXPECT_EQ(result, "3rd"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 28 | EXPECT_FALSE(getNthStringFromPath(path, 4, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 29 | |
Nan Zhou | 623e533 | 2022-06-21 17:46:37 +0000 | [diff] [blame] | 30 | path = "////0th///1st//\2nd///3rd?/"; |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 31 | EXPECT_TRUE(getNthStringFromPath(path, 0, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 32 | EXPECT_EQ(result, "0th"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 33 | EXPECT_TRUE(getNthStringFromPath(path, 1, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 34 | EXPECT_EQ(result, "1st"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 35 | EXPECT_TRUE(getNthStringFromPath(path, 2, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 36 | EXPECT_EQ(result, "\2nd"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 37 | EXPECT_TRUE(getNthStringFromPath(path, 3, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 38 | EXPECT_EQ(result, "3rd?"); |
Nan Zhou | 623e533 | 2022-06-21 17:46:37 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | TEST(GetNthStringFromPath, InvalidIndexReturnsFalse) |
| 42 | { |
| 43 | std::string path("////0th///1st//\2nd///3rd?/"); |
| 44 | std::string result; |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 45 | EXPECT_FALSE(getNthStringFromPath(path, -1, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 46 | } |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 47 | } // namespace |
| 48 | } // namespace dbus::utility |