source/base: Make it possible to get the underlying sd_event_source
diff --git a/src/sdeventplus/source/base.cpp b/src/sdeventplus/source/base.cpp
index 3e164ca..d9dd127 100644
--- a/src/sdeventplus/source/base.cpp
+++ b/src/sdeventplus/source/base.cpp
@@ -45,6 +45,11 @@
}
}
+sd_event_source* Base::get() const
+{
+ return source.get();
+}
+
const Event& Base::get_event() const
{
return event;
diff --git a/src/sdeventplus/source/base.hpp b/src/sdeventplus/source/base.hpp
index f8db620..b6fd47b 100644
--- a/src/sdeventplus/source/base.hpp
+++ b/src/sdeventplus/source/base.hpp
@@ -27,6 +27,7 @@
int prepareCallback();
+ sd_event_source* get() const;
const Event& get_event() const;
const char* get_description() const;
diff --git a/test/source/base.cpp b/test/source/base.cpp
index c9b248f..4894840 100644
--- a/test/source/base.cpp
+++ b/test/source/base.cpp
@@ -64,6 +64,9 @@
EXPECT_CALL(mock, sd_event_source_ref(expected_source))
.WillOnce(Return(expected_source));
BaseImpl source(*event, expected_source);
+ EXPECT_EQ(expected_source, source.get());
+ EXPECT_NE(event.get(), &source.get_event());
+ EXPECT_EQ(expected_event, source.get_event().get());
{
testing::InSequence seq;
@@ -81,6 +84,9 @@
EXPECT_CALL(mock, sd_event_ref(expected_event))
.WillOnce(Return(expected_event));
BaseImpl source(*event, expected_source, std::false_type());
+ EXPECT_EQ(expected_source, source.get());
+ EXPECT_NE(event.get(), &source.get_event());
+ EXPECT_EQ(expected_event, source.get_event().get());
{
testing::InSequence seq;
@@ -98,6 +104,9 @@
EXPECT_CALL(mock, sd_event_ref(expected_event))
.WillOnce(Return(expected_event));
BaseImpl source(*event, nullptr, std::false_type());
+ EXPECT_EQ(nullptr, source.get());
+ EXPECT_NE(event.get(), &source.get_event());
+ EXPECT_EQ(expected_event, source.get_event().get());
EXPECT_CALL(mock, sd_event_source_unref(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr));
@@ -134,12 +143,6 @@
}
};
-TEST_F(BaseMethodTest, GetEvent)
-{
- EXPECT_NE(event.get(), &base->get_event());
- EXPECT_EQ(event->get(), base->get_event().get());
-}
-
TEST_F(BaseMethodTest, GetDescriptionSuccess)
{
const char* expected = "test_desc";