summaryrefslogtreecommitdiffstats
path: root/test/source/base.cpp
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
commit0a816c5d8054dfe3867423aa4303c5cf7b4a92e9 (patch)
tree03e102d017105a0a8c98f2a72f413aff79a90af3 /test/source/base.cpp
parent154a2b3ab755e700a0290307c09b16d68dd52565 (diff)
downloadsdeventplus-0a816c5d8054dfe3867423aa4303c5cf7b4a92e9.tar.gz
sdeventplus-0a816c5d8054dfe3867423aa4303c5cf7b4a92e9.zip
Large refactoring
Diffstat (limited to 'test/source/base.cpp')
-rw-r--r--test/source/base.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/source/base.cpp b/test/source/base.cpp
new file mode 100644
index 0000000..3bf76c0
--- /dev/null
+++ b/test/source/base.cpp
@@ -0,0 +1,59 @@
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <sdeventplus/internal/sdevent.hpp>
+#include <sdeventplus/source/base.hpp>
+#include <sdeventplus/test/sdevent.hpp>
+#include <type_traits>
+
+namespace sdeventplus
+{
+namespace source
+{
+namespace
+{
+
+using testing::Return;
+
+class BaseImpl : public Base
+{
+ public:
+ BaseImpl(sd_event_source* source, internal::SdEvent* sdevent) :
+ Base(source, sdevent)
+ {
+ }
+ BaseImpl(sd_event_source* source, std::false_type,
+ internal::SdEvent* sdevent) :
+ Base(source, std::false_type(), sdevent)
+ {
+ }
+};
+
+class BaseTest : public testing::Test
+{
+ protected:
+ testing::StrictMock<test::SdEventMock> mock;
+ sd_event_source* const expected_source =
+ reinterpret_cast<sd_event_source*>(1234);
+};
+
+TEST_F(BaseTest, NewBaseRef)
+{
+ EXPECT_CALL(mock, sd_event_source_ref(expected_source))
+ .WillOnce(Return(expected_source));
+ BaseImpl source(expected_source, &mock);
+
+ EXPECT_CALL(mock, sd_event_source_unref(expected_source))
+ .WillOnce(Return(nullptr));
+}
+
+TEST_F(BaseTest, NewBaseNoRef)
+{
+ BaseImpl source(expected_source, std::false_type(), &mock);
+
+ EXPECT_CALL(mock, sd_event_source_unref(expected_source))
+ .WillOnce(Return(nullptr));
+}
+
+} // namespace
+} // namespace source
+} // namespace sdeventplus
OpenPOWER on IntegriCloud