source/base: Make it possible to get the prepare callback
diff --git a/src/sdeventplus/source/base.cpp b/src/sdeventplus/source/base.cpp
index d9dd127..684d688 100644
--- a/src/sdeventplus/source/base.cpp
+++ b/src/sdeventplus/source/base.cpp
@@ -99,6 +99,11 @@
prepare = std::move(callback);
}
+const Base::Callback& Base::get_prepare() const
+{
+ return prepare;
+}
+
int Base::get_pending() const
{
int r = event.getSdEvent()->sd_event_source_get_pending(source.get());
diff --git a/src/sdeventplus/source/base.hpp b/src/sdeventplus/source/base.hpp
index b6fd47b..0a8acc1 100644
--- a/src/sdeventplus/source/base.hpp
+++ b/src/sdeventplus/source/base.hpp
@@ -33,6 +33,7 @@
const char* get_description() const;
void set_description(const char* description) const;
void set_prepare(Callback&& callback);
+ const Callback& get_prepare() const;
int get_pending() const;
int64_t get_priority() const;
void set_priority(int64_t priority) const;
diff --git a/test/source/base.cpp b/test/source/base.cpp
index 4894840..4b89d52 100644
--- a/test/source/base.cpp
+++ b/test/source/base.cpp
@@ -67,6 +67,7 @@
EXPECT_EQ(expected_source, source.get());
EXPECT_NE(event.get(), &source.get_event());
EXPECT_EQ(expected_event, source.get_event().get());
+ EXPECT_FALSE(source.get_prepare());
{
testing::InSequence seq;
@@ -87,6 +88,7 @@
EXPECT_EQ(expected_source, source.get());
EXPECT_NE(event.get(), &source.get_event());
EXPECT_EQ(expected_event, source.get_event().get());
+ EXPECT_FALSE(source.get_prepare());
{
testing::InSequence seq;
@@ -107,6 +109,7 @@
EXPECT_EQ(nullptr, source.get());
EXPECT_NE(event.get(), &source.get_event());
EXPECT_EQ(expected_event, source.get_event().get());
+ EXPECT_FALSE(source.get_prepare());
EXPECT_CALL(mock, sd_event_source_unref(nullptr)).WillOnce(Return(nullptr));
EXPECT_CALL(mock, sd_event_unref(expected_event)).WillOnce(Return(nullptr));
@@ -189,6 +192,7 @@
EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
.WillOnce(DoAll(SaveArg<1>(&event_handler), Return(0)));
base->set_prepare(std::move(callback));
+ EXPECT_TRUE(base->get_prepare());
EXPECT_FALSE(callback);
EXPECT_FALSE(completed);
@@ -203,6 +207,7 @@
EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
.WillOnce(DoAll(SaveArg<1>(&event_handler), Return(0)));
base->set_prepare(std::move(callback));
+ EXPECT_TRUE(base->get_prepare());
EXPECT_FALSE(callback);
EXPECT_EQ(-EINVAL, event_handler(nullptr, nullptr));
@@ -224,6 +229,7 @@
EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
.WillOnce(Return(0));
base->set_prepare(std::move(callback));
+ EXPECT_TRUE(base->get_prepare());
EXPECT_FALSE(callback);
EXPECT_EQ(-EBUSY, base->prepareCallback());
}
@@ -234,6 +240,7 @@
EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
.WillOnce(Return(0));
base->set_prepare(std::move(callback));
+ EXPECT_TRUE(base->get_prepare());
EXPECT_FALSE(callback);
EXPECT_EQ(-ENOSYS, base->prepareCallback());
}
@@ -244,6 +251,7 @@
EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
.WillOnce(Return(-EINVAL));
EXPECT_THROW(base->set_prepare(std::move(callback)), SdEventError);
+ EXPECT_FALSE(base->get_prepare());
EXPECT_TRUE(callback);
EXPECT_EQ(-ENOSYS, base->prepareCallback());
}