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