summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-07-17 14:40:14 -0700
committerWilliam A. Kennington III <wak@google.com>2018-07-17 14:40:14 -0700
commit7597a081dc769aebc223deee0bcad604b670dbe6 (patch)
treec2bb5b5908885ddc5ec6a787c04bd995a1142f2d /test
parentbdc59018d3d85af8c300bf62aecbac9610fd4f66 (diff)
downloadsdeventplus-7597a081dc769aebc223deee0bcad604b670dbe6.tar.gz
sdeventplus-7597a081dc769aebc223deee0bcad604b670dbe6.zip
clock: Add class for future use
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am5
-rw-r--r--test/clock.cpp58
2 files changed, 63 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 1b4ee1e..d1923fa 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -7,6 +7,11 @@ gtest_ldadd = $(SDEVENTPLUS_LIBS) $(GTEST_LIBS) $(GMOCK_LIBS) -lgmock_main
check_PROGRAMS =
TESTS = $(check_PROGRAMS)
+check_PROGRAMS += clock
+clock_SOURCES = clock.cpp
+clock_CPPFLAGS = $(gtest_cppflags)
+clock_LDADD = $(gtest_ldadd)
+
check_PROGRAMS += event
event_SOURCES = event.cpp
event_CPPFLAGS = $(gtest_cppflags)
diff --git a/test/clock.cpp b/test/clock.cpp
new file mode 100644
index 0000000..e004341
--- /dev/null
+++ b/test/clock.cpp
@@ -0,0 +1,58 @@
+#include <cerrno>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <sdeventplus/clock.hpp>
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/exception.hpp>
+#include <sdeventplus/test/sdevent.hpp>
+#include <systemd/sd-event.h>
+#include <type_traits>
+#include <utility>
+
+namespace sdeventplus
+{
+namespace
+{
+
+using testing::DoAll;
+using testing::Return;
+using testing::SetArgPointee;
+
+class ClockTest : public testing::Test
+{
+ protected:
+ testing::StrictMock<test::SdEventMock> mock;
+ sd_event* const expected_event = reinterpret_cast<sd_event*>(1234);
+};
+
+TEST_F(ClockTest, CopyEvent)
+{
+ Event event(expected_event, std::false_type(), &mock);
+
+ EXPECT_CALL(mock, sd_event_ref(expected_event))
+ .WillOnce(Return(expected_event));
+ Clock<ClockId::RealTime> clock(event);
+ EXPECT_CALL(mock, sd_event_now(expected_event, CLOCK_REALTIME, testing::_))
+ .WillOnce(DoAll(SetArgPointee<2>(2000000), Return(0)));
+ EXPECT_EQ(Clock<ClockId::RealTime>::time_point(std::chrono::seconds{2}),
+ clock.now());
+
+ EXPECT_CALL(mock, sd_event_unref(expected_event))
+ .Times(2)
+ .WillRepeatedly(Return(nullptr));
+}
+
+TEST_F(ClockTest, MoveEvent)
+{
+ Event event(expected_event, std::false_type(), &mock);
+
+ Clock<ClockId::Monotonic> clock(std::move(event));
+ EXPECT_CALL(mock, sd_event_now(expected_event, CLOCK_MONOTONIC, testing::_))
+ .WillOnce(Return(-EINVAL));
+ EXPECT_THROW(clock.now(), SdEventError);
+
+ EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr));
+}
+
+} // namespace
+} // namespace sdeventplus
OpenPOWER on IntegriCloud