Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 1 | #include "helpers.hpp" |
| 2 | #include "utils/dbus_path_utils.hpp" |
| 3 | |
| 4 | #include <sdbusplus/exception.hpp> |
| 5 | |
| 6 | #include <gmock/gmock.h> |
| 7 | |
| 8 | using namespace testing; |
| 9 | using sdbusplus::message::object_path; |
| 10 | using utils::pathAppend; |
| 11 | |
| 12 | class TestPathAppend : |
| 13 | public Test, |
| 14 | public WithParamInterface<std::tuple<object_path, std::string, object_path>> |
| 15 | {}; |
| 16 | |
| 17 | INSTANTIATE_TEST_SUITE_P( |
| 18 | _, TestPathAppend, |
| 19 | Values(std::make_tuple(object_path("/Base/Path"), "one", |
| 20 | object_path("/Base/Path/one")), |
| 21 | std::make_tuple(object_path("/Base/Path"), "one/two", |
| 22 | object_path("/Base/Path/one/two")), |
| 23 | std::make_tuple(object_path("/Base/Path"), "one/two/foobar", |
| 24 | object_path("/Base/Path/one/two/foobar")), |
| 25 | std::make_tuple(object_path("/Base/Path/"), "one", |
| 26 | object_path("/Base/Path/one")), |
| 27 | std::make_tuple(object_path("/Base/Path/"), "one/two", |
| 28 | object_path("/Base/Path/one/two")), |
| 29 | std::make_tuple(object_path("/Base/Path/"), "one/two/foobar", |
| 30 | object_path("/Base/Path/one/two/foobar")), |
| 31 | std::make_tuple(object_path("/Base/Path"), "", |
| 32 | object_path("/Base/Path/")))); |
| 33 | |
| 34 | TEST_P(TestPathAppend, pathAppendsCorrectly) |
| 35 | { |
| 36 | auto [basePath, extension, expectedPath] = GetParam(); |
| 37 | EXPECT_EQ(pathAppend(basePath, extension), expectedPath); |
| 38 | } |
| 39 | |
| 40 | class TestPathAppendFail : |
| 41 | public Test, |
| 42 | public WithParamInterface<std::tuple<object_path, std::string>> |
| 43 | {}; |
| 44 | |
| 45 | INSTANTIATE_TEST_SUITE_P( |
| 46 | _, TestPathAppendFail, |
| 47 | Values(std::make_tuple(object_path("/Base/Path"), "/one"), |
| 48 | std::make_tuple(object_path("/Base/Path"), "one/"), |
| 49 | std::make_tuple(object_path("/Base/Path"), "one/two/"), |
| 50 | std::make_tuple(object_path("/Base/Path"), "one//two"), |
| 51 | std::make_tuple(object_path("/Base/Path"), "/"), |
| 52 | std::make_tuple(object_path("/Base/Path"), "//"))); |
| 53 | |
| 54 | TEST_P(TestPathAppendFail, pathAppendsCorrectly) |
| 55 | { |
| 56 | auto [basePath, extension] = GetParam(); |
| 57 | EXPECT_THROW(pathAppend(basePath, extension), |
| 58 | sdbusplus::exception::SdBusError); |
| 59 | } |