1*068f8073SShawn McCarney /**
2*068f8073SShawn McCarney * Copyright © 2025 IBM Corporation
3*068f8073SShawn McCarney *
4*068f8073SShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License");
5*068f8073SShawn McCarney * you may not use this file except in compliance with the License.
6*068f8073SShawn McCarney * You may obtain a copy of the License at
7*068f8073SShawn McCarney *
8*068f8073SShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0
9*068f8073SShawn McCarney *
10*068f8073SShawn McCarney * Unless required by applicable law or agreed to in writing, software
11*068f8073SShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS,
12*068f8073SShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*068f8073SShawn McCarney * See the License for the specific language governing permissions and
14*068f8073SShawn McCarney * limitations under the License.
15*068f8073SShawn McCarney */
16*068f8073SShawn McCarney
17*068f8073SShawn McCarney #include "chassis.hpp"
18*068f8073SShawn McCarney #include "power_sequencer_device.hpp"
19*068f8073SShawn McCarney #include "system.hpp"
20*068f8073SShawn McCarney
21*068f8073SShawn McCarney #include <stddef.h> // for size_t
22*068f8073SShawn McCarney
23*068f8073SShawn McCarney #include <memory>
24*068f8073SShawn McCarney #include <string>
25*068f8073SShawn McCarney #include <utility>
26*068f8073SShawn McCarney #include <vector>
27*068f8073SShawn McCarney
28*068f8073SShawn McCarney #include <gtest/gtest.h>
29*068f8073SShawn McCarney
30*068f8073SShawn McCarney using namespace phosphor::power::sequencer;
31*068f8073SShawn McCarney
32*068f8073SShawn McCarney /**
33*068f8073SShawn McCarney * Creates a Chassis object.
34*068f8073SShawn McCarney *
35*068f8073SShawn McCarney * @param number Chassis number within the system. Must be >= 1.
36*068f8073SShawn McCarney * @param inventoryPath D-Bus inventory path of the chassis
37*068f8073SShawn McCarney * @return Chassis object
38*068f8073SShawn McCarney */
createChassis(size_t number,const std::string & inventoryPath)39*068f8073SShawn McCarney std::unique_ptr<Chassis> createChassis(size_t number,
40*068f8073SShawn McCarney const std::string& inventoryPath)
41*068f8073SShawn McCarney {
42*068f8073SShawn McCarney std::vector<std::unique_ptr<PowerSequencerDevice>> powerSequencers;
43*068f8073SShawn McCarney return std::make_unique<Chassis>(number, inventoryPath,
44*068f8073SShawn McCarney std::move(powerSequencers));
45*068f8073SShawn McCarney }
46*068f8073SShawn McCarney
TEST(SystemTests,Constructor)47*068f8073SShawn McCarney TEST(SystemTests, Constructor)
48*068f8073SShawn McCarney {
49*068f8073SShawn McCarney std::vector<std::unique_ptr<Chassis>> chassis;
50*068f8073SShawn McCarney chassis.emplace_back(
51*068f8073SShawn McCarney createChassis(1, "/xyz/openbmc_project/inventory/system/chassis"));
52*068f8073SShawn McCarney System system{std::move(chassis)};
53*068f8073SShawn McCarney
54*068f8073SShawn McCarney EXPECT_EQ(system.getChassis().size(), 1);
55*068f8073SShawn McCarney EXPECT_EQ(system.getChassis()[0]->getNumber(), 1);
56*068f8073SShawn McCarney EXPECT_EQ(system.getChassis()[0]->getInventoryPath(),
57*068f8073SShawn McCarney "/xyz/openbmc_project/inventory/system/chassis");
58*068f8073SShawn McCarney }
59*068f8073SShawn McCarney
TEST(SystemTests,GetChassis)60*068f8073SShawn McCarney TEST(SystemTests, GetChassis)
61*068f8073SShawn McCarney {
62*068f8073SShawn McCarney std::vector<std::unique_ptr<Chassis>> chassis;
63*068f8073SShawn McCarney chassis.emplace_back(
64*068f8073SShawn McCarney createChassis(1, "/xyz/openbmc_project/inventory/system/chassis1"));
65*068f8073SShawn McCarney chassis.emplace_back(
66*068f8073SShawn McCarney createChassis(3, "/xyz/openbmc_project/inventory/system/chassis_3"));
67*068f8073SShawn McCarney chassis.emplace_back(
68*068f8073SShawn McCarney createChassis(7, "/xyz/openbmc_project/inventory/system/chassis7"));
69*068f8073SShawn McCarney System system{std::move(chassis)};
70*068f8073SShawn McCarney
71*068f8073SShawn McCarney EXPECT_EQ(system.getChassis().size(), 3);
72*068f8073SShawn McCarney EXPECT_EQ(system.getChassis()[0]->getNumber(), 1);
73*068f8073SShawn McCarney EXPECT_EQ(system.getChassis()[0]->getInventoryPath(),
74*068f8073SShawn McCarney "/xyz/openbmc_project/inventory/system/chassis1");
75*068f8073SShawn McCarney EXPECT_EQ(system.getChassis()[1]->getNumber(), 3);
76*068f8073SShawn McCarney EXPECT_EQ(system.getChassis()[1]->getInventoryPath(),
77*068f8073SShawn McCarney "/xyz/openbmc_project/inventory/system/chassis_3");
78*068f8073SShawn McCarney EXPECT_EQ(system.getChassis()[2]->getNumber(), 7);
79*068f8073SShawn McCarney EXPECT_EQ(system.getChassis()[2]->getInventoryPath(),
80*068f8073SShawn McCarney "/xyz/openbmc_project/inventory/system/chassis7");
81*068f8073SShawn McCarney }
82