1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3
4 #include "dbus_utility.hpp"
5 #include "utils/systems_utils.hpp"
6
7 #include <boost/beast/http/status.hpp>
8 #include <boost/system/errc.hpp>
9 #include <nlohmann/json.hpp>
10 #include <sdbusplus/message.hpp>
11
12 #include <string>
13
14 #include <gtest/gtest.h>
15
16 namespace redfish
17 {
18 namespace
19 {
20
TEST(SystemsUtils,IndexMatchingObjectPath)21 TEST(SystemsUtils, IndexMatchingObjectPath)
22 {
23 auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
24
25 std::string objectPath;
26 std::string service;
27
28 const dbus::utility::MapperGetSubTreeResponse subtree = {
29 {"/xyz/openbmc_project/control/host1",
30 {{"xyz.openbmc_project.Settings", {}}}},
31 {"/xyz/openbmc_project/control/host2/policy/TPMEnable",
32 {{"xyz.openbmc_project.Settings", {}}}},
33 {"/xyz/openbmc_project/control/host10/policy/TPMEnable",
34 {{"xyz.openbmc_project.Settings", {}}}},
35 {"/xyz/openbmc_project/control/host999/",
36 {{"xyz.openbmc_project.Settings", {}}}}};
37
38 EXPECT_TRUE(indexMatchingSubTreeMapObjectPath(asyncResp, 1, subtree,
39 objectPath, service));
40 EXPECT_TRUE(indexMatchingSubTreeMapObjectPath(asyncResp, 2, subtree,
41 objectPath, service));
42 EXPECT_TRUE(indexMatchingSubTreeMapObjectPath(asyncResp, 10, subtree,
43 objectPath, service));
44 EXPECT_TRUE(indexMatchingSubTreeMapObjectPath(asyncResp, 999, subtree,
45 objectPath, service));
46 EXPECT_FALSE(indexMatchingSubTreeMapObjectPath(asyncResp, 100, subtree,
47 objectPath, service));
48 EXPECT_FALSE(indexMatchingSubTreeMapObjectPath(asyncResp, 11, subtree,
49 objectPath, service));
50 EXPECT_FALSE(indexMatchingSubTreeMapObjectPath(asyncResp, 0, subtree,
51 objectPath, service));
52
53 indexMatchingSubTreeMapObjectPath(asyncResp, 1, subtree, objectPath,
54 service);
55 EXPECT_EQ(objectPath, "/xyz/openbmc_project/control/host1");
56 EXPECT_EQ(service, "xyz.openbmc_project.Settings");
57
58 indexMatchingSubTreeMapObjectPath(asyncResp, 10, subtree, objectPath,
59 service);
60 EXPECT_EQ(objectPath,
61 "/xyz/openbmc_project/control/host10/policy/TPMEnable");
62
63 indexMatchingSubTreeMapObjectPath(asyncResp, 999, subtree, objectPath,
64 service);
65 EXPECT_EQ(objectPath, "/xyz/openbmc_project/control/host999/");
66 }
67 } // namespace
68 } // namespace redfish
69