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