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 | |
Ed Tanous | 478b7ad | 2024-07-15 19:11:54 -0700 | [diff] [blame^] | 5 | #include <gtest/gtest.h> |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 6 | |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 7 | namespace dbus::utility |
| 8 | { |
| 9 | namespace |
| 10 | { |
| 11 | |
Nan Zhou | 623e533 | 2022-06-21 17:46:37 +0000 | [diff] [blame] | 12 | TEST(GetNthStringFromPath, ParsingSucceedsAndReturnsNthArg) |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 13 | { |
| 14 | std::string path("/0th/1st/2nd/3rd"); |
| 15 | std::string result; |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 16 | EXPECT_TRUE(getNthStringFromPath(path, 0, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 17 | EXPECT_EQ(result, "0th"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 18 | EXPECT_TRUE(getNthStringFromPath(path, 1, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 19 | EXPECT_EQ(result, "1st"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 20 | EXPECT_TRUE(getNthStringFromPath(path, 2, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 21 | EXPECT_EQ(result, "2nd"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 22 | EXPECT_TRUE(getNthStringFromPath(path, 3, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 23 | EXPECT_EQ(result, "3rd"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 24 | EXPECT_FALSE(getNthStringFromPath(path, 4, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 25 | |
Nan Zhou | 623e533 | 2022-06-21 17:46:37 +0000 | [diff] [blame] | 26 | path = "////0th///1st//\2nd///3rd?/"; |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 27 | EXPECT_TRUE(getNthStringFromPath(path, 0, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 28 | EXPECT_EQ(result, "0th"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 29 | EXPECT_TRUE(getNthStringFromPath(path, 1, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 30 | EXPECT_EQ(result, "1st"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 31 | EXPECT_TRUE(getNthStringFromPath(path, 2, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 32 | EXPECT_EQ(result, "\2nd"); |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 33 | EXPECT_TRUE(getNthStringFromPath(path, 3, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 34 | EXPECT_EQ(result, "3rd?"); |
Nan Zhou | 623e533 | 2022-06-21 17:46:37 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | TEST(GetNthStringFromPath, InvalidIndexReturnsFalse) |
| 38 | { |
| 39 | std::string path("////0th///1st//\2nd///3rd?/"); |
| 40 | std::string result; |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 41 | EXPECT_FALSE(getNthStringFromPath(path, -1, result)); |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 42 | } |
Nan Zhou | 5b28cdf | 2022-06-21 17:46:26 +0000 | [diff] [blame] | 43 | } // namespace |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 44 | } // namespace dbus::utility |