blob: a4086e1e2e8f4e5f045688ac10f7dc683351c892 [file] [log] [blame]
Shawn McCarneyd3a8aab2020-03-10 10:30:02 -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 "configuration.hpp"
18#include "mock_action.hpp"
19
20#include <memory>
21#include <optional>
22#include <utility>
23#include <vector>
24
25#include <gtest/gtest.h>
26
27using namespace phosphor::power::regulators;
28
29TEST(ConfigurationTests, Constructor)
30{
31 // Test where volts value specified
32 {
33 std::optional<double> volts{1.3};
34
35 std::vector<std::unique_ptr<Action>> actions{};
36 actions.push_back(std::make_unique<MockAction>());
37 actions.push_back(std::make_unique<MockAction>());
38
39 Configuration configuration(volts, std::move(actions));
40 EXPECT_EQ(configuration.getVolts().has_value(), true);
41 EXPECT_EQ(configuration.getVolts().value(), 1.3);
42 EXPECT_EQ(configuration.getActions().size(), 2);
43 }
44
45 // Test where volts value not specified
46 {
47 std::optional<double> volts{};
48
49 std::vector<std::unique_ptr<Action>> actions{};
50 actions.push_back(std::make_unique<MockAction>());
51
52 Configuration configuration(volts, std::move(actions));
53 EXPECT_EQ(configuration.getVolts().has_value(), false);
54 EXPECT_EQ(configuration.getActions().size(), 1);
55 }
56}
57
58TEST(ConfigurationTests, Execute)
59{
60 // TODO: Implement test when execute() function is done
61}
62
63TEST(ConfigurationTests, GetActions)
64{
65 std::optional<double> volts{1.3};
66
67 std::vector<std::unique_ptr<Action>> actions{};
68
69 MockAction* action1 = new MockAction{};
70 actions.push_back(std::unique_ptr<MockAction>{action1});
71
72 MockAction* action2 = new MockAction{};
73 actions.push_back(std::unique_ptr<MockAction>{action2});
74
75 Configuration configuration(volts, std::move(actions));
76 EXPECT_EQ(configuration.getActions().size(), 2);
77 EXPECT_EQ(configuration.getActions()[0].get(), action1);
78 EXPECT_EQ(configuration.getActions()[1].get(), action2);
79}
80
81TEST(ConfigurationTests, GetVolts)
82{
83 // Test where volts value specified
84 {
85 std::optional<double> volts{3.2};
86
87 std::vector<std::unique_ptr<Action>> actions{};
88 actions.push_back(std::make_unique<MockAction>());
89
90 Configuration configuration(volts, std::move(actions));
91 EXPECT_EQ(configuration.getVolts().has_value(), true);
92 EXPECT_EQ(configuration.getVolts().value(), 3.2);
93 }
94
95 // Test where volts value not specified
96 {
97 std::optional<double> volts{};
98
99 std::vector<std::unique_ptr<Action>> actions{};
100 actions.push_back(std::make_unique<MockAction>());
101
102 Configuration configuration(volts, std::move(actions));
103 EXPECT_EQ(configuration.getVolts().has_value(), false);
104 }
105}