diff options
| author | William A. Kennington III <wak@google.com> | 2018-07-17 14:40:14 -0700 |
|---|---|---|
| committer | William A. Kennington III <wak@google.com> | 2018-07-17 14:40:14 -0700 |
| commit | f5285c73c611ec183b26e8153070d0538a06f206 (patch) | |
| tree | c7195c9a8499118fb74027f63e7376417cd3da9d | |
| parent | 4863b96b8e6a6c02397c5ca44ed6ea51b4753286 (diff) | |
| download | sdeventplus-f5285c73c611ec183b26e8153070d0538a06f206.tar.gz sdeventplus-f5285c73c611ec183b26e8153070d0538a06f206.zip | |
source/base: Make it possible to get the prepare callback
| -rw-r--r-- | src/sdeventplus/source/base.cpp | 5 | ||||
| -rw-r--r-- | src/sdeventplus/source/base.hpp | 1 | ||||
| -rw-r--r-- | test/source/base.cpp | 8 |
3 files changed, 14 insertions, 0 deletions
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 @@ void Base::set_prepare(Callback&& callback) 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 @@ class Base 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 @@ TEST_F(BaseTest, NewBaseRef) 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 @@ TEST_F(BaseTest, NewBaseNoRef) 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 @@ TEST_F(BaseTest, NoSource) 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 @@ TEST_F(BaseMethodTest, SetPrepareCallback) 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 @@ TEST_F(BaseMethodTest, SetPrepareCallbackNoUserdata) 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 @@ TEST_F(BaseMethodTest, SetPrepareSystemError) 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 @@ TEST_F(BaseMethodTest, SetPrepareUnknownException) 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 @@ TEST_F(BaseMethodTest, SetPrepareError) 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()); } |

