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