1 /**
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 "error_history.hpp"
17 
18 #include <gtest/gtest.h>
19 
20 using namespace phosphor::power::regulators;
21 
TEST(ErrorHistoryTests,ErrorType)22 TEST(ErrorHistoryTests, ErrorType)
23 {
24     EXPECT_EQ(static_cast<int>(ErrorType::internal), 3);
25     EXPECT_EQ(static_cast<int>(ErrorType::numTypes), 8);
26 }
27 
TEST(ErrorHistoryTests,Constructor)28 TEST(ErrorHistoryTests, Constructor)
29 {
30     ErrorHistory history{};
31     EXPECT_FALSE(history.wasLogged(ErrorType::configFile));
32     EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
33     EXPECT_FALSE(history.wasLogged(ErrorType::i2c));
34     EXPECT_FALSE(history.wasLogged(ErrorType::internal));
35     EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
36     EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification));
37     EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultN));
38     EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultNPlus1));
39 }
40 
TEST(ErrorHistoryTests,Clear)41 TEST(ErrorHistoryTests, Clear)
42 {
43     ErrorHistory history{};
44 
45     history.setWasLogged(ErrorType::configFile, true);
46     history.setWasLogged(ErrorType::dbus, true);
47     history.setWasLogged(ErrorType::i2c, true);
48     history.setWasLogged(ErrorType::internal, true);
49     history.setWasLogged(ErrorType::pmbus, true);
50     history.setWasLogged(ErrorType::writeVerification, true);
51     history.setWasLogged(ErrorType::phaseFaultN, true);
52     history.setWasLogged(ErrorType::phaseFaultNPlus1, true);
53 
54     EXPECT_TRUE(history.wasLogged(ErrorType::configFile));
55     EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
56     EXPECT_TRUE(history.wasLogged(ErrorType::i2c));
57     EXPECT_TRUE(history.wasLogged(ErrorType::internal));
58     EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
59     EXPECT_TRUE(history.wasLogged(ErrorType::writeVerification));
60     EXPECT_TRUE(history.wasLogged(ErrorType::phaseFaultN));
61     EXPECT_TRUE(history.wasLogged(ErrorType::phaseFaultNPlus1));
62 
63     history.clear();
64 
65     EXPECT_FALSE(history.wasLogged(ErrorType::configFile));
66     EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
67     EXPECT_FALSE(history.wasLogged(ErrorType::i2c));
68     EXPECT_FALSE(history.wasLogged(ErrorType::internal));
69     EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
70     EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification));
71     EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultN));
72     EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultNPlus1));
73 }
74 
TEST(ErrorHistoryTests,SetWasLogged)75 TEST(ErrorHistoryTests, SetWasLogged)
76 {
77     ErrorHistory history{};
78     EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
79     history.setWasLogged(ErrorType::dbus, true);
80     EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
81     history.setWasLogged(ErrorType::dbus, false);
82     EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
83 }
84 
TEST(ErrorHistoryTests,WasLogged)85 TEST(ErrorHistoryTests, WasLogged)
86 {
87     ErrorHistory history{};
88     EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
89     history.setWasLogged(ErrorType::pmbus, true);
90     EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
91     history.setWasLogged(ErrorType::pmbus, false);
92     EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
93 }
94