diff options
| author | Lei YU <mine260309@gmail.com> | 2017-01-20 14:02:03 +0800 |
|---|---|---|
| committer | Lei YU <mine260309@gmail.com> | 2017-08-01 10:31:07 +0800 |
| commit | 2f9c0cc25478709f25f449d46ab9836152cf1cd9 (patch) | |
| tree | 6af0f8cee0041350da38ca7b91a85e5b3a520577 /test | |
| parent | 4188567ae87609943489e559ab2067f1cbc76f40 (diff) | |
| download | phosphor-time-manager-2f9c0cc25478709f25f449d46ab9836152cf1cd9.tar.gz phosphor-time-manager-2f9c0cc25478709f25f449d46ab9836152cf1cd9.zip | |
Intialize new phosphor-time-manager
phosphor-time-manager will be refactored to use sdbusplus interfaces.
This is a initial commit that EpochBase is implemented based on dbus
interface xyz/openbmc_project/Time/EpochTime.interface.yaml.
EpochBase is the base class that wraps EpochTime interface, and is
initialized with time mode and owner from settingsd.
An initial unit test case is added.
Change-Id: Ic944b70f63ec3c0329762cc8874f0f57b09ddce3
Signed-off-by: Lei YU <mine260309@gmail.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile.am | 26 | ||||
| -rw-r--r-- | test/TestEpochBase.cpp | 64 |
2 files changed, 90 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..66e1ae5 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,26 @@ +AM_CPPFLAGS = -I${top_srcdir} +check_PROGRAMS = + +TESTS = $(check_PROGRAMS) + +check_PROGRAMS += test + +test_SOURCES = \ + TestEpochBase.cpp + +test_LDADD = $(top_builddir)/libtimemanager.la + +test_CPPFLAGS = $(GTEST_CPPFLAGS) \ + $(AM_CPPFLAGS) + +test_CXXFLAGS = $(PTHREAD_CFLAGS) \ + $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \ + $(SDBUSPLUS_CFLAGS) + +test_LDFLAGS = -lgmock_main \ + -lgmock \ + $(PTHREAD_LIBS) \ + $(OESDK_TESTCASE_FLAGS) + +test_LDFLAGS += $(PHOSPHOR_DBUS_INTERFACES_LIBS) \ + $(SDBUSPLUS_LIBS) diff --git a/test/TestEpochBase.cpp b/test/TestEpochBase.cpp new file mode 100644 index 0000000..c3ca7e1 --- /dev/null +++ b/test/TestEpochBase.cpp @@ -0,0 +1,64 @@ +#include <sdbusplus/bus.hpp> +#include <gtest/gtest.h> + +#include "epoch_base.hpp" + +namespace phosphor +{ +namespace time +{ + +class TestEpochBase : public testing::Test +{ + public: + using Mode = EpochBase::Mode; + using Owner = EpochBase::Owner; + + sdbusplus::bus::bus bus; + EpochBase epochBase; + + TestEpochBase() + : bus(sdbusplus::bus::new_default()), + epochBase(bus, "") + { + // Empty + } + + // Proxies for EpochBase's private members and functions + Mode convertToMode(const std::string& mode) + { + return EpochBase::convertToMode(mode); + } + Owner convertToOwner(const std::string& owner) + { + return EpochBase::convertToOwner(owner); + } +}; + +TEST_F(TestEpochBase, 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(TestEpochBase, 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")); +} + +} +} |

