166332cd7SShawn McCarney /**
266332cd7SShawn McCarney  * Copyright © 2020 IBM Corporation
366332cd7SShawn McCarney  *
466332cd7SShawn McCarney  * Licensed under the Apache License, Version 2.0 (the "License");
566332cd7SShawn McCarney  * you may not use this file except in compliance with the License.
666332cd7SShawn McCarney  * You may obtain a copy of the License at
766332cd7SShawn McCarney  *
866332cd7SShawn McCarney  *     http://www.apache.org/licenses/LICENSE-2.0
966332cd7SShawn McCarney  *
1066332cd7SShawn McCarney  * Unless required by applicable law or agreed to in writing, software
1166332cd7SShawn McCarney  * distributed under the License is distributed on an "AS IS" BASIS,
1266332cd7SShawn McCarney  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1366332cd7SShawn McCarney  * See the License for the specific language governing permissions and
1466332cd7SShawn McCarney  * limitations under the License.
1566332cd7SShawn McCarney  */
1666332cd7SShawn McCarney #include "error_history.hpp"
1766332cd7SShawn McCarney 
1866332cd7SShawn McCarney #include <gtest/gtest.h>
1966332cd7SShawn McCarney 
2066332cd7SShawn McCarney using namespace phosphor::power::regulators;
2166332cd7SShawn McCarney 
TEST(ErrorHistoryTests,ErrorType)222f1b7ba6SShawn McCarney TEST(ErrorHistoryTests, ErrorType)
232f1b7ba6SShawn McCarney {
242f1b7ba6SShawn McCarney     EXPECT_EQ(static_cast<int>(ErrorType::internal), 3);
25*3f7da6e4SShawn McCarney     EXPECT_EQ(static_cast<int>(ErrorType::numTypes), 8);
262f1b7ba6SShawn McCarney }
272f1b7ba6SShawn McCarney 
TEST(ErrorHistoryTests,Constructor)2866332cd7SShawn McCarney TEST(ErrorHistoryTests, Constructor)
2966332cd7SShawn McCarney {
3066332cd7SShawn McCarney     ErrorHistory history{};
312f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::configFile));
322f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
332f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::i2c));
342f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::internal));
352f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
362f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification));
37*3f7da6e4SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultN));
38*3f7da6e4SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultNPlus1));
3966332cd7SShawn McCarney }
4066332cd7SShawn McCarney 
TEST(ErrorHistoryTests,Clear)4166332cd7SShawn McCarney TEST(ErrorHistoryTests, Clear)
4266332cd7SShawn McCarney {
4366332cd7SShawn McCarney     ErrorHistory history{};
442f1b7ba6SShawn McCarney 
452f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::configFile, true);
462f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::dbus, true);
472f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::i2c, true);
482f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::internal, true);
492f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::pmbus, true);
502f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::writeVerification, true);
51*3f7da6e4SShawn McCarney     history.setWasLogged(ErrorType::phaseFaultN, true);
52*3f7da6e4SShawn McCarney     history.setWasLogged(ErrorType::phaseFaultNPlus1, true);
532f1b7ba6SShawn McCarney 
542f1b7ba6SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::configFile));
552f1b7ba6SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
562f1b7ba6SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::i2c));
572f1b7ba6SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::internal));
582f1b7ba6SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
592f1b7ba6SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::writeVerification));
60*3f7da6e4SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::phaseFaultN));
61*3f7da6e4SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::phaseFaultNPlus1));
622f1b7ba6SShawn McCarney 
6366332cd7SShawn McCarney     history.clear();
642f1b7ba6SShawn McCarney 
652f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::configFile));
662f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
672f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::i2c));
682f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::internal));
692f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
702f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification));
71*3f7da6e4SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultN));
72*3f7da6e4SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultNPlus1));
7366332cd7SShawn McCarney }
7466332cd7SShawn McCarney 
TEST(ErrorHistoryTests,SetWasLogged)752f1b7ba6SShawn McCarney TEST(ErrorHistoryTests, SetWasLogged)
7666332cd7SShawn McCarney {
7766332cd7SShawn McCarney     ErrorHistory history{};
782f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
792f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::dbus, true);
802f1b7ba6SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
812f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::dbus, false);
822f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
832f1b7ba6SShawn McCarney }
8466332cd7SShawn McCarney 
TEST(ErrorHistoryTests,WasLogged)852f1b7ba6SShawn McCarney TEST(ErrorHistoryTests, WasLogged)
862f1b7ba6SShawn McCarney {
872f1b7ba6SShawn McCarney     ErrorHistory history{};
882f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
892f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::pmbus, true);
902f1b7ba6SShawn McCarney     EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
912f1b7ba6SShawn McCarney     history.setWasLogged(ErrorType::pmbus, false);
922f1b7ba6SShawn McCarney     EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
9366332cd7SShawn McCarney }
94