blob: a12211d0b00b31d854192a6ce90ed04962538f07 [file] [log] [blame]
Shawn McCarneya2461b32019-10-24 18:53:01 -05001/**
2 * Copyright © 2019 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 */
Shawn McCarney4bf310e2020-03-10 17:48:11 -050016#include "action.hpp"
17#include "configuration.hpp"
18#include "mock_action.hpp"
Shawn McCarneya2461b32019-10-24 18:53:01 -050019#include "rail.hpp"
Shawn McCarney4bf310e2020-03-10 17:48:11 -050020#include "sensor_monitoring.hpp"
21
22#include <memory>
23#include <optional>
24#include <utility>
25#include <vector>
Shawn McCarneya2461b32019-10-24 18:53:01 -050026
27#include <gtest/gtest.h>
28
29using namespace phosphor::power::regulators;
30
31TEST(RailTests, Constructor)
32{
Shawn McCarney4bf310e2020-03-10 17:48:11 -050033 // Test where only required parameters are specified
34 {
35 Rail rail{"vdd0"};
36 EXPECT_EQ(rail.getID(), "vdd0");
37 EXPECT_EQ(rail.getConfiguration(), nullptr);
38 EXPECT_EQ(rail.getSensorMonitoring(), nullptr);
39 }
40
41 // Test where all parameters are specified
42 {
43 // Create Configuration
44 std::optional<double> volts{1.3};
45 std::vector<std::unique_ptr<Action>> actions{};
46 actions.push_back(std::make_unique<MockAction>());
47 actions.push_back(std::make_unique<MockAction>());
48 std::unique_ptr<Configuration> configuration =
49 std::make_unique<Configuration>(volts, std::move(actions));
50
51 // Create SensorMonitoring
52 actions.clear();
53 actions.push_back(std::make_unique<MockAction>());
54 std::unique_ptr<SensorMonitoring> sensorMonitoring =
55 std::make_unique<SensorMonitoring>(std::move(actions));
56
57 // Create Rail
58 Rail rail{"vddr1", std::move(configuration),
59 std::move(sensorMonitoring)};
60 EXPECT_EQ(rail.getID(), "vddr1");
61 EXPECT_NE(rail.getConfiguration(), nullptr);
62 EXPECT_EQ(rail.getConfiguration()->getVolts().has_value(), true);
63 EXPECT_EQ(rail.getConfiguration()->getVolts().value(), 1.3);
64 EXPECT_EQ(rail.getConfiguration()->getActions().size(), 2);
65 EXPECT_NE(rail.getSensorMonitoring(), nullptr);
66 EXPECT_EQ(rail.getSensorMonitoring()->getActions().size(), 1);
67 }
68}
69
70TEST(RailTests, GetConfiguration)
71{
72 // Test where Configuration was not specified in constructor
73 {
74 Rail rail{"vdd0"};
75 EXPECT_EQ(rail.getConfiguration(), nullptr);
76 }
77
78 // Test where Configuration was specified in constructor
79 {
80 // Create Configuration
81 std::optional<double> volts{3.2};
82 std::vector<std::unique_ptr<Action>> actions{};
83 actions.push_back(std::make_unique<MockAction>());
84 std::unique_ptr<Configuration> configuration =
85 std::make_unique<Configuration>(volts, std::move(actions));
86
87 // Create Rail
88 Rail rail{"vddr1", std::move(configuration)};
89 EXPECT_NE(rail.getConfiguration(), nullptr);
90 EXPECT_EQ(rail.getConfiguration()->getVolts().has_value(), true);
91 EXPECT_EQ(rail.getConfiguration()->getVolts().value(), 3.2);
92 EXPECT_EQ(rail.getConfiguration()->getActions().size(), 1);
93 }
Shawn McCarneya2461b32019-10-24 18:53:01 -050094}
95
Shawn McCarney4afb2852019-10-27 18:28:53 -050096TEST(RailTests, GetID)
Shawn McCarneya2461b32019-10-24 18:53:01 -050097{
Shawn McCarney4bf310e2020-03-10 17:48:11 -050098 Rail rail{"vio2"};
Shawn McCarney4afb2852019-10-27 18:28:53 -050099 EXPECT_EQ(rail.getID(), "vio2");
Shawn McCarneya2461b32019-10-24 18:53:01 -0500100}
Shawn McCarney4bf310e2020-03-10 17:48:11 -0500101
102TEST(RailTests, GetSensorMonitoring)
103{
104 // Test where SensorMonitoring was not specified in constructor
105 {
106 Rail rail{"vdd0", nullptr, nullptr};
107 EXPECT_EQ(rail.getSensorMonitoring(), nullptr);
108 }
109
110 // Test where SensorMonitoring was specified in constructor
111 {
112 std::unique_ptr<Configuration> configuration{};
113
114 // Create SensorMonitoring
115 std::vector<std::unique_ptr<Action>> actions{};
116 actions.push_back(std::make_unique<MockAction>());
117 actions.push_back(std::make_unique<MockAction>());
118 std::unique_ptr<SensorMonitoring> sensorMonitoring =
119 std::make_unique<SensorMonitoring>(std::move(actions));
120
121 // Create Rail
122 Rail rail{"vddr1", std::move(configuration),
123 std::move(sensorMonitoring)};
124 EXPECT_NE(rail.getSensorMonitoring(), nullptr);
125 EXPECT_EQ(rail.getSensorMonitoring()->getActions().size(), 2);
126 }
127}