Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 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 | |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 18 | #include <gtest/gtest.h> |
| 19 | |
| 20 | using namespace phosphor::power::regulators; |
| 21 | |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 22 | TEST(ErrorHistoryTests, ErrorType) |
| 23 | { |
| 24 | EXPECT_EQ(static_cast<int>(ErrorType::internal), 3); |
| 25 | EXPECT_EQ(static_cast<int>(ErrorType::numTypes), 6); |
| 26 | } |
| 27 | |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 28 | TEST(ErrorHistoryTests, Constructor) |
| 29 | { |
| 30 | ErrorHistory history{}; |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 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)); |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | TEST(ErrorHistoryTests, Clear) |
| 40 | { |
| 41 | ErrorHistory history{}; |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 42 | |
| 43 | history.setWasLogged(ErrorType::configFile, true); |
| 44 | history.setWasLogged(ErrorType::dbus, true); |
| 45 | history.setWasLogged(ErrorType::i2c, true); |
| 46 | history.setWasLogged(ErrorType::internal, true); |
| 47 | history.setWasLogged(ErrorType::pmbus, true); |
| 48 | history.setWasLogged(ErrorType::writeVerification, true); |
| 49 | |
| 50 | EXPECT_TRUE(history.wasLogged(ErrorType::configFile)); |
| 51 | EXPECT_TRUE(history.wasLogged(ErrorType::dbus)); |
| 52 | EXPECT_TRUE(history.wasLogged(ErrorType::i2c)); |
| 53 | EXPECT_TRUE(history.wasLogged(ErrorType::internal)); |
| 54 | EXPECT_TRUE(history.wasLogged(ErrorType::pmbus)); |
| 55 | EXPECT_TRUE(history.wasLogged(ErrorType::writeVerification)); |
| 56 | |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 57 | history.clear(); |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 58 | |
| 59 | EXPECT_FALSE(history.wasLogged(ErrorType::configFile)); |
| 60 | EXPECT_FALSE(history.wasLogged(ErrorType::dbus)); |
| 61 | EXPECT_FALSE(history.wasLogged(ErrorType::i2c)); |
| 62 | EXPECT_FALSE(history.wasLogged(ErrorType::internal)); |
| 63 | EXPECT_FALSE(history.wasLogged(ErrorType::pmbus)); |
| 64 | EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification)); |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 67 | TEST(ErrorHistoryTests, SetWasLogged) |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 68 | { |
| 69 | ErrorHistory history{}; |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 70 | EXPECT_FALSE(history.wasLogged(ErrorType::dbus)); |
| 71 | history.setWasLogged(ErrorType::dbus, true); |
| 72 | EXPECT_TRUE(history.wasLogged(ErrorType::dbus)); |
| 73 | history.setWasLogged(ErrorType::dbus, false); |
| 74 | EXPECT_FALSE(history.wasLogged(ErrorType::dbus)); |
| 75 | } |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 76 | |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 77 | TEST(ErrorHistoryTests, WasLogged) |
| 78 | { |
| 79 | ErrorHistory history{}; |
| 80 | EXPECT_FALSE(history.wasLogged(ErrorType::pmbus)); |
| 81 | history.setWasLogged(ErrorType::pmbus, true); |
| 82 | EXPECT_TRUE(history.wasLogged(ErrorType::pmbus)); |
| 83 | history.setWasLogged(ErrorType::pmbus, false); |
| 84 | EXPECT_FALSE(history.wasLogged(ErrorType::pmbus)); |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 85 | } |