blob: b5f33f1c511c42ebcf379041f5362476723c6d95 [file] [log] [blame]
Shawn McCarneyc3991f12020-04-05 13:16:06 -05001/**
2 * Copyright © 2020 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#include "action.hpp"
17#include "chassis.hpp"
18#include "mock_action.hpp"
19#include "rule.hpp"
20#include "system.hpp"
21
22#include <memory>
23#include <utility>
24#include <vector>
25
26#include <gtest/gtest.h>
27
28using namespace phosphor::power::regulators;
29
30TEST(SystemTests, Constructor)
31{
32 // Create Rules
33 std::vector<std::unique_ptr<Rule>> rules{};
34 std::vector<std::unique_ptr<Action>> actions{};
35 actions.emplace_back(std::make_unique<MockAction>());
36 rules.emplace_back(
37 std::make_unique<Rule>("set_voltage_rule", std::move(actions)));
38
39 // Create Chassis
40 std::vector<std::unique_ptr<Chassis>> chassis{};
41 chassis.emplace_back(std::make_unique<Chassis>(1));
42
43 // Create System
44 System system{std::move(rules), std::move(chassis)};
45 EXPECT_EQ(system.getChassis().size(), 1);
46 EXPECT_EQ(system.getChassis()[0]->getNumber(), 1);
47 // TODO: Add tests for IDMap once code to populate it is implemented
48 EXPECT_EQ(system.getRules().size(), 1);
49 EXPECT_EQ(system.getRules()[0]->getID(), "set_voltage_rule");
50}
51
52TEST(SystemTests, GetChassis)
53{
54 // Specify an empty rules vector
55 std::vector<std::unique_ptr<Rule>> rules{};
56
57 // Create Chassis
58 std::vector<std::unique_ptr<Chassis>> chassis{};
59 chassis.emplace_back(std::make_unique<Chassis>(1));
60 chassis.emplace_back(std::make_unique<Chassis>(3));
61
62 // Create System
63 System system{std::move(rules), std::move(chassis)};
64 EXPECT_EQ(system.getChassis().size(), 2);
65 EXPECT_EQ(system.getChassis()[0]->getNumber(), 1);
66 EXPECT_EQ(system.getChassis()[1]->getNumber(), 3);
67}
68
69TEST(SystemTests, GetIDMap)
70{
71 // TODO: Code to build IDMap is not implemented yet
72}
73
74TEST(SystemTests, GetRules)
75{
76 // Create Rules
77 std::vector<std::unique_ptr<Rule>> rules{};
78 std::vector<std::unique_ptr<Action>> actions{};
79 actions.emplace_back(std::make_unique<MockAction>());
80 rules.emplace_back(
81 std::make_unique<Rule>("set_voltage_rule", std::move(actions)));
82 actions.emplace_back(std::make_unique<MockAction>());
83 rules.emplace_back(
84 std::make_unique<Rule>("read_sensors_rule", std::move(actions)));
85
86 // Create Chassis
87 std::vector<std::unique_ptr<Chassis>> chassis{};
88 chassis.emplace_back(std::make_unique<Chassis>(1));
89
90 // Create System
91 System system{std::move(rules), std::move(chassis)};
92 EXPECT_EQ(system.getRules().size(), 2);
93 EXPECT_EQ(system.getRules()[0]->getID(), "set_voltage_rule");
94 EXPECT_EQ(system.getRules()[1]->getID(), "read_sensors_rule");
95}