summaryrefslogtreecommitdiff
path: root/test/redfish-core/include/utils/systems_utils_test.cpp
blob: b2fcebad36db12de7647f37d4622c701c64e5f4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors

#include "dbus_utility.hpp"
#include "utils/systems_utils.hpp"

#include <boost/beast/http/status.hpp>
#include <boost/system/errc.hpp>
#include <nlohmann/json.hpp>
#include <sdbusplus/message.hpp>

#include <string>

#include <gtest/gtest.h>

namespace redfish
{
namespace
{

TEST(SystemsUtils, IndexMatchingObjectPath)
{
    auto asyncResp = std::make_shared<bmcweb::AsyncResp>();

    std::string objectPath;
    std::string service;

    const dbus::utility::MapperGetSubTreeResponse subtree = {
        {"/xyz/openbmc_project/control/host1",
         {{"xyz.openbmc_project.Settings", {}}}},
        {"/xyz/openbmc_project/control/host2/policy/TPMEnable",
         {{"xyz.openbmc_project.Settings", {}}}},
        {"/xyz/openbmc_project/control/host10/policy/TPMEnable",
         {{"xyz.openbmc_project.Settings", {}}}},
        {"/xyz/openbmc_project/control/host999/",
         {{"xyz.openbmc_project.Settings", {}}}}};

    EXPECT_TRUE(indexMatchingSubTreeMapObjectPath(asyncResp, 1, subtree,
                                                  objectPath, service));
    EXPECT_TRUE(indexMatchingSubTreeMapObjectPath(asyncResp, 2, subtree,
                                                  objectPath, service));
    EXPECT_TRUE(indexMatchingSubTreeMapObjectPath(asyncResp, 10, subtree,
                                                  objectPath, service));
    EXPECT_TRUE(indexMatchingSubTreeMapObjectPath(asyncResp, 999, subtree,
                                                  objectPath, service));
    EXPECT_FALSE(indexMatchingSubTreeMapObjectPath(asyncResp, 100, subtree,
                                                   objectPath, service));
    EXPECT_FALSE(indexMatchingSubTreeMapObjectPath(asyncResp, 11, subtree,
                                                   objectPath, service));
    EXPECT_FALSE(indexMatchingSubTreeMapObjectPath(asyncResp, 0, subtree,
                                                   objectPath, service));

    indexMatchingSubTreeMapObjectPath(asyncResp, 1, subtree, objectPath,
                                      service);
    EXPECT_EQ(objectPath, "/xyz/openbmc_project/control/host1");
    EXPECT_EQ(service, "xyz.openbmc_project.Settings");

    indexMatchingSubTreeMapObjectPath(asyncResp, 10, subtree, objectPath,
                                      service);
    EXPECT_EQ(objectPath,
              "/xyz/openbmc_project/control/host10/policy/TPMEnable");

    indexMatchingSubTreeMapObjectPath(asyncResp, 999, subtree, objectPath,
                                      service);
    EXPECT_EQ(objectPath, "/xyz/openbmc_project/control/host999/");
}
} // namespace
} // namespace redfish