blob: e4a2b6822a4a3d205426a2634f62d496e6c9cc52 [file] [log] [blame]
Lei YU2f9c0cc2017-01-20 14:02:03 +08001#include <sdbusplus/bus.hpp>
2#include <gtest/gtest.h>
3
Lei YU415b9642017-02-09 11:37:26 +08004#include "types.hpp"
Lei YU2f9c0cc2017-01-20 14:02:03 +08005#include "epoch_base.hpp"
6
7namespace phosphor
8{
9namespace time
10{
11
12class TestEpochBase : public testing::Test
13{
14 public:
Lei YU2f9c0cc2017-01-20 14:02:03 +080015 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 YU415b9642017-02-09 11:37:26 +080025 Mode getMode()
Lei YU2f9c0cc2017-01-20 14:02:03 +080026 {
Lei YU415b9642017-02-09 11:37:26 +080027 return epochBase.timeMode;
Lei YU2f9c0cc2017-01-20 14:02:03 +080028 }
Lei YU415b9642017-02-09 11:37:26 +080029 Owner getOwner()
Lei YU2f9c0cc2017-01-20 14:02:03 +080030 {
Lei YU415b9642017-02-09 11:37:26 +080031 return epochBase.timeOwner;
Lei YU2f9c0cc2017-01-20 14:02:03 +080032 }
33};
34
Lei YU415b9642017-02-09 11:37:26 +080035TEST_F(TestEpochBase, onModeChange)
Lei YU2f9c0cc2017-01-20 14:02:03 +080036{
Lei YU415b9642017-02-09 11:37:26 +080037 epochBase.onModeChanged(Mode::NTP);
38 EXPECT_EQ(Mode::NTP, getMode());
Lei YU2f9c0cc2017-01-20 14:02:03 +080039
Lei YU415b9642017-02-09 11:37:26 +080040 epochBase.onModeChanged(Mode::MANUAL);
41 EXPECT_EQ(Mode::MANUAL, getMode());
Lei YU2f9c0cc2017-01-20 14:02:03 +080042}
43
Lei YU415b9642017-02-09 11:37:26 +080044TEST_F(TestEpochBase, onOwnerChange)
Lei YU2f9c0cc2017-01-20 14:02:03 +080045{
Lei YU415b9642017-02-09 11:37:26 +080046 epochBase.onOwnerChanged(Owner::BMC);
47 EXPECT_EQ(Owner::BMC, getOwner());
Lei YU2f9c0cc2017-01-20 14:02:03 +080048
Lei YU415b9642017-02-09 11:37:26 +080049 epochBase.onOwnerChanged(Owner::HOST);
50 EXPECT_EQ(Owner::HOST, getOwner());
51
52 epochBase.onOwnerChanged(Owner::SPLIT);
53 EXPECT_EQ(Owner::SPLIT, getOwner());
54
55 epochBase.onOwnerChanged(Owner::BOTH);
56 EXPECT_EQ(Owner::BOTH, getOwner());
Lei YU2f9c0cc2017-01-20 14:02:03 +080057}
58
59}
60}