Add time Manager to handle property changes callback
1. Implement time::Manager who registers property change signal for time
mode and owner;
2. Add PropertyChangeListner interface to handle the callback;
3. Make EpochBase to implement the interface.
Change-Id: I185580ae37353e1ed82a47e4905fb22e269ac09d
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index bdd258e..b8ea41c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,7 +8,8 @@
test_SOURCES = \
TestEpochBase.cpp \
TestBmcEpoch.cpp \
- TestHostEpoch.cpp
+ TestHostEpoch.cpp \
+ TestManager.cpp
test_LDADD = $(top_builddir)/libtimemanager.la
diff --git a/test/TestBmcEpoch.cpp b/test/TestBmcEpoch.cpp
index da65b3e..2fd55a5 100644
--- a/test/TestBmcEpoch.cpp
+++ b/test/TestBmcEpoch.cpp
@@ -3,6 +3,7 @@
#include "bmc_epoch.hpp"
#include "config.h"
+#include "types.hpp"
namespace phosphor
{
@@ -13,9 +14,6 @@
class TestBmcEpoch : public testing::Test
{
public:
- using Mode = EpochBase::Mode;
- using Owner = EpochBase::Owner;
-
sdbusplus::bus::bus bus;
BmcEpoch bmcEpoch;
diff --git a/test/TestEpochBase.cpp b/test/TestEpochBase.cpp
index c3ca7e1..e4a2b68 100644
--- a/test/TestEpochBase.cpp
+++ b/test/TestEpochBase.cpp
@@ -1,6 +1,7 @@
#include <sdbusplus/bus.hpp>
#include <gtest/gtest.h>
+#include "types.hpp"
#include "epoch_base.hpp"
namespace phosphor
@@ -11,9 +12,6 @@
class TestEpochBase : public testing::Test
{
public:
- using Mode = EpochBase::Mode;
- using Owner = EpochBase::Owner;
-
sdbusplus::bus::bus bus;
EpochBase epochBase;
@@ -24,40 +22,38 @@
// Empty
}
- // Proxies for EpochBase's private members and functions
- Mode convertToMode(const std::string& mode)
+ Mode getMode()
{
- return EpochBase::convertToMode(mode);
+ return epochBase.timeMode;
}
- Owner convertToOwner(const std::string& owner)
+ Owner getOwner()
{
- return EpochBase::convertToOwner(owner);
+ return epochBase.timeOwner;
}
};
-TEST_F(TestEpochBase, convertToMode)
+TEST_F(TestEpochBase, onModeChange)
{
- EXPECT_EQ(Mode::NTP, convertToMode("NTP"));
- EXPECT_EQ(Mode::MANUAL, convertToMode("MANUAL"));
+ epochBase.onModeChanged(Mode::NTP);
+ EXPECT_EQ(Mode::NTP, getMode());
- // All unrecognized strings are mapped to Ntp
- EXPECT_EQ(Mode::NTP, convertToMode(""));
- EXPECT_EQ(Mode::NTP, convertToMode("Manual"));
- EXPECT_EQ(Mode::NTP, convertToMode("whatever"));
+ epochBase.onModeChanged(Mode::MANUAL);
+ EXPECT_EQ(Mode::MANUAL, getMode());
}
-
-TEST_F(TestEpochBase, convertToOwner)
+TEST_F(TestEpochBase, onOwnerChange)
{
- EXPECT_EQ(Owner::BMC, convertToOwner("BMC"));
- EXPECT_EQ(Owner::HOST, convertToOwner("HOST"));
- EXPECT_EQ(Owner::SPLIT, convertToOwner("SPLIT"));
- EXPECT_EQ(Owner::BOTH, convertToOwner("BOTH"));
+ epochBase.onOwnerChanged(Owner::BMC);
+ EXPECT_EQ(Owner::BMC, getOwner());
- // All unrecognized strings are mapped to Bmc
- EXPECT_EQ(Owner::BMC, convertToOwner(""));
- EXPECT_EQ(Owner::BMC, convertToOwner("Split"));
- EXPECT_EQ(Owner::BMC, convertToOwner("xyz"));
+ epochBase.onOwnerChanged(Owner::HOST);
+ EXPECT_EQ(Owner::HOST, getOwner());
+
+ epochBase.onOwnerChanged(Owner::SPLIT);
+ EXPECT_EQ(Owner::SPLIT, getOwner());
+
+ epochBase.onOwnerChanged(Owner::BOTH);
+ EXPECT_EQ(Owner::BOTH, getOwner());
}
}
diff --git a/test/TestHostEpoch.cpp b/test/TestHostEpoch.cpp
index dca8d72..ec8ecf1 100644
--- a/test/TestHostEpoch.cpp
+++ b/test/TestHostEpoch.cpp
@@ -3,6 +3,7 @@
#include "host_epoch.hpp"
#include "config.h"
+#include "types.hpp"
namespace phosphor
{
@@ -15,9 +16,6 @@
class TestHostEpoch : public testing::Test
{
public:
- using Mode = EpochBase::Mode;
- using Owner = EpochBase::Owner;
-
sdbusplus::bus::bus bus;
HostEpoch hostEpoch;
diff --git a/test/TestManager.cpp b/test/TestManager.cpp
new file mode 100644
index 0000000..4d9ae73
--- /dev/null
+++ b/test/TestManager.cpp
@@ -0,0 +1,76 @@
+#include <sdbusplus/bus.hpp>
+#include <gtest/gtest.h>
+
+#include "types.hpp"
+#include "manager.hpp"
+
+namespace phosphor
+{
+namespace time
+{
+
+class TestManager : public testing::Test
+{
+ public:
+ sdbusplus::bus::bus bus;
+ Manager manager;
+
+ TestManager()
+ : bus(sdbusplus::bus::new_default()),
+ manager(bus)
+ {
+ // Empty
+ }
+
+ // Proxies for Manager's private members and functions
+ Mode getTimeMode()
+ {
+ return manager.timeMode;
+ }
+ Owner getTimeOwner()
+ {
+ return manager.timeOwner;
+ }
+ Mode convertToMode(const std::string& mode)
+ {
+ return Manager::convertToMode(mode);
+ }
+ Owner convertToOwner(const std::string& owner)
+ {
+ return Manager::convertToOwner(owner);
+ }
+};
+
+TEST_F(TestManager, empty)
+{
+ EXPECT_EQ(Mode::NTP, getTimeMode());
+ EXPECT_EQ(Owner::BMC, getTimeOwner());
+}
+
+TEST_F(TestManager, convertToMode)
+{
+ EXPECT_EQ(Mode::NTP, convertToMode("NTP"));
+ EXPECT_EQ(Mode::MANUAL, convertToMode("MANUAL"));
+
+ // All unrecognized strings are mapped to Ntp
+ EXPECT_EQ(Mode::NTP, convertToMode(""));
+ EXPECT_EQ(Mode::NTP, convertToMode("Manual"));
+ EXPECT_EQ(Mode::NTP, convertToMode("whatever"));
+}
+
+
+TEST_F(TestManager, convertToOwner)
+{
+ EXPECT_EQ(Owner::BMC, convertToOwner("BMC"));
+ EXPECT_EQ(Owner::HOST, convertToOwner("HOST"));
+ EXPECT_EQ(Owner::SPLIT, convertToOwner("SPLIT"));
+ EXPECT_EQ(Owner::BOTH, convertToOwner("BOTH"));
+
+ // All unrecognized strings are mapped to Bmc
+ EXPECT_EQ(Owner::BMC, convertToOwner(""));
+ EXPECT_EQ(Owner::BMC, convertToOwner("Split"));
+ EXPECT_EQ(Owner::BMC, convertToOwner("xyz"));
+}
+
+}
+}