Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 1 | #include "epoch_base.hpp" |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 2 | #include "types.hpp" |
| 3 | |
| 4 | #include <sdbusplus/bus.hpp> |
| 5 | |
| 6 | #include <gtest/gtest.h> |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace time |
| 11 | { |
| 12 | |
| 13 | class TestEpochBase : public testing::Test |
| 14 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 15 | public: |
| 16 | sdbusplus::bus::bus bus; |
| 17 | EpochBase epochBase; |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 18 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 19 | TestEpochBase() : bus(sdbusplus::bus::new_default()), epochBase(bus, "") |
| 20 | { |
| 21 | // Empty |
| 22 | } |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 23 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 24 | Mode getMode() |
| 25 | { |
| 26 | return epochBase.timeMode; |
| 27 | } |
| 28 | Owner getOwner() |
| 29 | { |
| 30 | return epochBase.timeOwner; |
| 31 | } |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 32 | }; |
| 33 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 34 | TEST_F(TestEpochBase, onModeChange) |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 35 | { |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 36 | epochBase.onModeChanged(Mode::NTP); |
| 37 | EXPECT_EQ(Mode::NTP, getMode()); |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 38 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 39 | epochBase.onModeChanged(Mode::Manual); |
| 40 | EXPECT_EQ(Mode::Manual, getMode()); |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 41 | } |
| 42 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 43 | TEST_F(TestEpochBase, onOwnerChange) |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 44 | { |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 45 | epochBase.onOwnerChanged(Owner::BMC); |
| 46 | EXPECT_EQ(Owner::BMC, getOwner()); |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 47 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 48 | epochBase.onOwnerChanged(Owner::Host); |
| 49 | EXPECT_EQ(Owner::Host, getOwner()); |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 50 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 51 | epochBase.onOwnerChanged(Owner::Split); |
| 52 | EXPECT_EQ(Owner::Split, getOwner()); |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 53 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 54 | epochBase.onOwnerChanged(Owner::Both); |
| 55 | EXPECT_EQ(Owner::Both, getOwner()); |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 56 | } |
| 57 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 58 | } // namespace time |
| 59 | } // namespace phosphor |