1 /**
2  * Copyright © 2021 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_environment.hpp"
17 #include "id_map.hpp"
18 #include "log_phase_fault_action.hpp"
19 #include "mock_services.hpp"
20 #include "phase_fault.hpp"
21 
22 #include <gtest/gtest.h>
23 
24 using namespace phosphor::power::regulators;
25 
TEST(LogPhaseFaultActionTests,Constructor)26 TEST(LogPhaseFaultActionTests, Constructor)
27 {
28     LogPhaseFaultAction action{PhaseFaultType::n};
29     EXPECT_EQ(action.getType(), PhaseFaultType::n);
30 }
31 
TEST(LogPhaseFaultActionTests,Execute)32 TEST(LogPhaseFaultActionTests, Execute)
33 {
34     // Test with "n" phase fault type
35     {
36         IDMap idMap{};
37         MockServices services{};
38         ActionEnvironment env{idMap, "", services};
39         EXPECT_EQ(env.getPhaseFaults().size(), 0);
40 
41         LogPhaseFaultAction action{PhaseFaultType::n};
42         EXPECT_EQ(action.execute(env), true);
43 
44         EXPECT_EQ(env.getPhaseFaults().size(), 1);
45         EXPECT_EQ(env.getPhaseFaults().count(PhaseFaultType::n), 1);
46     }
47 
48     // Test with "n+1" phase fault type
49     {
50         IDMap idMap{};
51         MockServices services{};
52         ActionEnvironment env{idMap, "", services};
53         EXPECT_EQ(env.getPhaseFaults().size(), 0);
54 
55         LogPhaseFaultAction action{PhaseFaultType::n_plus_1};
56         EXPECT_EQ(action.execute(env), true);
57 
58         EXPECT_EQ(env.getPhaseFaults().size(), 1);
59         EXPECT_EQ(env.getPhaseFaults().count(PhaseFaultType::n_plus_1), 1);
60     }
61 }
62 
TEST(LogPhaseFaultActionTests,GetType)63 TEST(LogPhaseFaultActionTests, GetType)
64 {
65     LogPhaseFaultAction action{PhaseFaultType::n_plus_1};
66     EXPECT_EQ(action.getType(), PhaseFaultType::n_plus_1);
67 }
68 
TEST(LogPhaseFaultActionTests,ToString)69 TEST(LogPhaseFaultActionTests, ToString)
70 {
71     LogPhaseFaultAction action{PhaseFaultType::n_plus_1};
72     EXPECT_EQ(action.toString(), "log_phase_fault: { type: n+1 }");
73 }
74