blob: 3e3cba8548e6d067badda3b26d88a143368530b2 [file] [log] [blame]
Shawn McCarney66332cd2020-07-13 19:14:18 -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 "error_history.hpp"
17
18#include <cstdint>
19
20#include <gtest/gtest.h>
21
22using namespace phosphor::power::regulators;
23
24TEST(ErrorHistoryTests, Constructor)
25{
26 ErrorHistory history{};
27 EXPECT_EQ(history.count, 0);
28 EXPECT_EQ(history.wasLogged, false);
29}
30
31TEST(ErrorHistoryTests, Clear)
32{
33 ErrorHistory history{};
34 history.count = 23;
35 history.wasLogged = true;
36 history.clear();
37 EXPECT_EQ(history.count, 0);
38 EXPECT_EQ(history.wasLogged, false);
39}
40
41TEST(ErrorHistoryTests, IncrementCount)
42{
43 ErrorHistory history{};
44
45 // Test where count is not near the max
46 EXPECT_EQ(history.count, 0);
47 history.incrementCount();
48 EXPECT_EQ(history.count, 1);
49 history.incrementCount();
50 EXPECT_EQ(history.count, 2);
51
52 // Test where count is near the max. Verify it does not wrap/overflow.
53 history.count = SIZE_MAX - 2;
54 history.incrementCount();
55 EXPECT_EQ(history.count, SIZE_MAX - 1);
56 history.incrementCount();
57 EXPECT_EQ(history.count, SIZE_MAX);
58 history.incrementCount();
59 EXPECT_EQ(history.count, SIZE_MAX);
60}