blob: 6c2ec88aac676888b1687cf1a03e02f2cb849a3f [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 YUad143542017-07-25 14:27:07 +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 YUad143542017-07-25 14:27:07 +080049 epochBase.onOwnerChanged(Owner::Host);
50 EXPECT_EQ(Owner::Host, getOwner());
Lei YU415b9642017-02-09 11:37:26 +080051
Lei YUad143542017-07-25 14:27:07 +080052 epochBase.onOwnerChanged(Owner::Split);
53 EXPECT_EQ(Owner::Split, getOwner());
Lei YU415b9642017-02-09 11:37:26 +080054
Lei YUad143542017-07-25 14:27:07 +080055 epochBase.onOwnerChanged(Owner::Both);
56 EXPECT_EQ(Owner::Both, getOwner());
Lei YU2f9c0cc2017-01-20 14:02:03 +080057}
58
59}
60}